Skip to content
Snippets Groups Projects
Commit f91fa3e0 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[PL] Add tuple size to ProcessVariable.

parent af34837b
No related branches found
No related tags found
No related merge requests found
......@@ -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));
}
......
......@@ -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
......
......@@ -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));
}
}
......
......@@ -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
{
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment