From ce83e0b96b61c36d1a41b8069a6524a0d9dd3c4e Mon Sep 17 00:00:00 2001 From: Bernd Flemisch <bernd@iws.uni-stuttgart.de> Date: Wed, 31 Oct 2018 15:59:39 +0100 Subject: [PATCH] [io] use static std::arrays instead of std::vectors --- dumux/porousmediumflow/2pnc/iofields.hh | 6 ++- dumux/porousmediumflow/3p3c/iofields.hh | 38 ++++++++++--------- dumux/porousmediumflow/3pwateroil/iofields.hh | 38 ++++++++++--------- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/dumux/porousmediumflow/2pnc/iofields.hh b/dumux/porousmediumflow/2pnc/iofields.hh index c04b981105..aee9f5cc23 100644 --- a/dumux/porousmediumflow/2pnc/iofields.hh +++ b/dumux/porousmediumflow/2pnc/iofields.hh @@ -77,6 +77,8 @@ public: static std::string primaryVariableName(int pvIdx, int state) { using Indices = typename ModelTraits::Indices; + static constexpr auto numStates = 3; + using StringVec = std::array<std::string, numStates>; int idxSecComps; if (state == Indices::firstPhaseOnly @@ -89,14 +91,14 @@ public: return ModelTraits::useMoles() ? IOName::moleFraction<FluidSystem>(idxSecComps, pvIdx) : IOName::massFraction<FluidSystem>(idxSecComps, pvIdx); - const std::vector<std::string> p0s1SwitchedPvNames = { + static const StringVec p0s1SwitchedPvNames = { ModelTraits::useMoles() ? IOName::moleFraction<FluidSystem>(FluidSystem::phase0Idx, FluidSystem::comp1Idx) : IOName::massFraction<FluidSystem>(FluidSystem::phase0Idx, FluidSystem::comp1Idx), ModelTraits::useMoles() ? IOName::moleFraction<FluidSystem>(FluidSystem::phase1Idx, FluidSystem::comp0Idx) : IOName::massFraction<FluidSystem>(FluidSystem::phase1Idx, FluidSystem::comp0Idx), IOName::saturation<FluidSystem>(FluidSystem::phase1Idx)}; - const std::vector<std::string> p1s0SwitchedPvNames = { + static const StringVec p1s0SwitchedPvNames = { ModelTraits::useMoles() ? IOName::moleFraction<FluidSystem>(FluidSystem::phase0Idx, FluidSystem::comp1Idx) : IOName::massFraction<FluidSystem>(FluidSystem::phase0Idx, FluidSystem::comp1Idx), ModelTraits::useMoles() ? IOName::moleFraction<FluidSystem>(FluidSystem::phase1Idx, FluidSystem::comp0Idx) diff --git a/dumux/porousmediumflow/3p3c/iofields.hh b/dumux/porousmediumflow/3p3c/iofields.hh index 5f0b3206ac..9b24517a1e 100644 --- a/dumux/porousmediumflow/3p3c/iofields.hh +++ b/dumux/porousmediumflow/3p3c/iofields.hh @@ -75,49 +75,51 @@ public: static std::string primaryVariableName(int pvIdx, int state) { using Indices = typename ModelTraits::Indices; + static constexpr auto numEq = ModelTraits::numEq(); + using StringVec = std::array<std::string, numEq>; switch (state) { case Indices::threePhases: { - const std::vector<std::string> s1 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), - IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; + static const StringVec s1 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), + IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; return s1[pvIdx]; } case Indices::wPhaseOnly: { - const std::vector<std::string> s2 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx)}; + static const StringVec s2 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx)}; return s2[pvIdx]; } case Indices::gnPhaseOnly: { - const std::vector<std::string> s3 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx), - IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; + static const StringVec s3 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx), + IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; return s3[pvIdx]; } case Indices::wnPhaseOnly: { - const std::vector<std::string> s4 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx), - IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; + static const StringVec s4 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx), + IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; return s4[pvIdx]; } case Indices::gPhaseOnly: { - const std::vector<std::string> s5 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; + static const StringVec s5 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; return s5[pvIdx]; } case Indices::wgPhaseOnly: { - const std::vector<std::string> s6 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; + static const StringVec s6 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; return s6[pvIdx]; } } diff --git a/dumux/porousmediumflow/3pwateroil/iofields.hh b/dumux/porousmediumflow/3pwateroil/iofields.hh index 90ed23fe99..1da1f5382e 100644 --- a/dumux/porousmediumflow/3pwateroil/iofields.hh +++ b/dumux/porousmediumflow/3pwateroil/iofields.hh @@ -81,49 +81,51 @@ public: static std::string primaryVariableName(int pvIdx, int state) { using Indices = typename ModelTraits::Indices; + static constexpr auto numEq = ModelTraits::numEq(); + using StringVec = std::array<std::string, numEq>; switch (state) { case Indices::threePhases: { - const std::vector<std::string> s1 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), - IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; + static const StringVec s1 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), + IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; return s1[pvIdx]; } case Indices::wPhaseOnly: { - const std::vector<std::string> s2 = {IOName::pressure<FluidSystem>(FluidSystem::wPhaseIdx), - IOName::temperature(), - IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx)}; + static const StringVec s2 = {IOName::pressure<FluidSystem>(FluidSystem::wPhaseIdx), + IOName::temperature(), + IOName::moleFraction<FluidSystem>(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx)}; return s2[pvIdx]; } case Indices::gnPhaseOnly: { - const std::vector<std::string> s3 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::nPhaseIdx, FluidSystem::wCompIdx)}; + static const StringVec s3 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::nPhaseIdx, FluidSystem::wCompIdx)}; return s3[pvIdx]; } case Indices::wnPhaseOnly: { - const std::vector<std::string> s4 = {IOName::pressure<FluidSystem>(FluidSystem::wPhaseIdx), - IOName::temperature(), - IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; + static const StringVec s4 = {IOName::pressure<FluidSystem>(FluidSystem::wPhaseIdx), + IOName::temperature(), + IOName::saturation<FluidSystem>(FluidSystem::nPhaseIdx)}; return s4[pvIdx]; } case Indices::gPhaseOnly: { - const std::vector<std::string> s5 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::temperature(), - IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; + static const StringVec s5 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::temperature(), + IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; return s5[pvIdx]; } case Indices::wgPhaseOnly: { - const std::vector<std::string> s6 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), - IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), - IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; + static const StringVec s6 = {IOName::pressure<FluidSystem>(FluidSystem::gPhaseIdx), + IOName::saturation<FluidSystem>(FluidSystem::wPhaseIdx), + IOName::moleFraction<FluidSystem>(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx)}; return s6[pvIdx]; } } -- GitLab