diff --git a/ProcessLib/InitialCondition.cpp b/ProcessLib/InitialCondition.cpp index 159736c54a286484fa5edecc3e65a6dd007e5582..2d241f41f8d15b5ab7a641ecdd996bb475efbf29 100644 --- a/ProcessLib/InitialCondition.cpp +++ b/ProcessLib/InitialCondition.cpp @@ -21,7 +21,7 @@ namespace ProcessLib { std::unique_ptr<InitialCondition> createUniformInitialCondition( - BaseLib::ConfigTree const& config) + BaseLib::ConfigTree const& config, int const tuple_size) { config.checkConfParam("type", "Uniform"); @@ -33,7 +33,9 @@ std::unique_ptr<InitialCondition> createUniformInitialCondition( } std::unique_ptr<InitialCondition> createMeshPropertyInitialCondition( - BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh) + BaseLib::ConfigTree const& config, + MeshLib::Mesh const& mesh, + int const tuple_size) { auto field_name = config.getConfParam<std::string>("field_name"); DBUG("Using field_name %s", field_name.c_str()); @@ -53,6 +55,13 @@ std::unique_ptr<InitialCondition> createMeshPropertyInitialCondition( std::abort(); } + if (property->getTupleSize() != tuple_size) + { + ERR("The required property %s has different tuples size %d, " + "expected %d.", + field_name.c_str(), property->getTupleSize(), tuple_size); + std::abort(); + } return std::unique_ptr<InitialCondition>( new MeshPropertyInitialCondition(*property)); } diff --git a/ProcessLib/InitialCondition.h b/ProcessLib/InitialCondition.h index a0a82855115a7032a54ecffb858fa7b68f08cd3a..709ac83d19c5c69858edbfcca3181a65dcb16138 100644 --- a/ProcessLib/InitialCondition.h +++ b/ProcessLib/InitialCondition.h @@ -35,7 +35,7 @@ class InitialCondition { public: virtual ~InitialCondition() = default; - virtual double getValue(MeshLib::Node const&) const = 0; + virtual double getValue(MeshLib::Node const&, int const) const = 0; }; /// Uniform value initial condition @@ -45,8 +45,8 @@ public: UniformInitialCondition(double const value) : _value(value) { } - - virtual double getValue(MeshLib::Node const&) const override + virtual double getValue(MeshLib::Node const&, + int const /* tuple_size */) const override { return _value; } @@ -56,8 +56,10 @@ private: }; /// Construct a UniformInitialCondition from configuration. +/// The initial condition will expect a correct tuple size in the configuration, +/// which should be the same as in the corresponding process variable. std::unique_ptr<InitialCondition> createUniformInitialCondition( - BaseLib::ConfigTree const& config); + BaseLib::ConfigTree const& config, int const tuple_size); /// Distribution of values given by a mesh property defined on nodes. class MeshPropertyInitialCondition : public InitialCondition @@ -70,9 +72,11 @@ public: assert(_property.getMeshItemType() == MeshLib::MeshItemType::Node); } - virtual double getValue(MeshLib::Node const& n) const override + virtual double getValue(MeshLib::Node const& n, + int const component_id) const override { - return _property[n.getID()]; + return _property[n.getID() * _property.getNumberOfComponents() + + component_id]; } private: @@ -80,8 +84,11 @@ private: }; /// Construct a MeshPropertyInitialCondition from configuration. +/// The initial condition will expect a correct tuple size in the configuration, +/// which should be the same as in the corresponding process variable. std::unique_ptr<InitialCondition> createMeshPropertyInitialCondition( - BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); + BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh, + int const tuple_size); } // namespace ProcessLib diff --git a/ProcessLib/Process.h b/ProcessLib/Process.h index 1cf6f8b43789d1f6a7c3f512581e2d0a12c634f4..a5b273b066e803e318f4e32d26085857625059b1 100644 --- a/ProcessLib/Process.h +++ b/ProcessLib/Process.h @@ -179,7 +179,8 @@ private: global_index = 0; #endif _x->set(global_index, - variable.getInitialConditionValue(*_mesh.getNode(i))); + variable.getInitialConditionValue(*_mesh.getNode(i), + component_id)); } } diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp index d873d937d0c4ce1be9ad12a21606332c48750d91..2f4bfaf0d0a6c1b850ebc4ba6708de52e45733aa 100644 --- a/ProcessLib/ProcessVariable.cpp +++ b/ProcessLib/ProcessVariable.cpp @@ -21,8 +21,9 @@ namespace ProcessLib ProcessVariable::ProcessVariable(BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh, GeoLib::GEOObjects const& geometries) - : _name(config.getConfParam<std::string>("name")) - , _mesh(mesh) + : _name(config.getConfParam<std::string>("name")), + _mesh(mesh), + _tuple_size(config.getConfParam<int>("components")) { DBUG("Constructing process variable %s", this->_name.c_str()); @@ -33,12 +34,12 @@ ProcessVariable::ProcessVariable(BaseLib::ConfigTree const& config, if (type == "Uniform") { _initial_condition = - createUniformInitialCondition(*ic_config); + createUniformInitialCondition(*ic_config, _tuple_size); } else if (type == "MeshProperty") { _initial_condition = - createMeshPropertyInitialCondition(*ic_config, _mesh); + createMeshPropertyInitialCondition(*ic_config, _mesh, _tuple_size); } else { diff --git a/ProcessLib/ProcessVariable.h b/ProcessLib/ProcessVariable.h index 65d8bebed18aefbd642f8c1e87acdca2155715b2..8268035611cfef9a67c2f811c16e2ad9a65e66bd 100644 --- a/ProcessLib/ProcessVariable.h +++ b/ProcessLib/ProcessVariable.h @@ -57,6 +57,9 @@ public: /// Returns a mesh on which the process variable is defined. MeshLib::Mesh const& getMesh() const; + /// Returns the tuple size of the process variable. + int getTupleSize() const { return _tuple_size; } + template <typename OutputIterator> void initializeDirichletBCs( OutputIterator output_bcs, @@ -87,14 +90,16 @@ public: } } - double getInitialConditionValue(MeshLib::Node const& n) const + double getInitialConditionValue(MeshLib::Node const& n, + int const component_id) const { - return _initial_condition->getValue(n); + return _initial_condition->getValue(n, component_id); } private: std::string const _name; MeshLib::Mesh const& _mesh; + int _tuple_size; std::unique_ptr<InitialCondition> _initial_condition; std::vector<std::unique_ptr<UniformDirichletBoundaryCondition>> _dirichlet_bc_configs;