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

[PL] Add MeshPropertyInitialCondition.

parent f0a5dad7
No related branches found
No related tags found
No related merge requests found
...@@ -36,4 +36,34 @@ std::unique_ptr<InitialCondition> createUniformInitialCondition( ...@@ -36,4 +36,34 @@ std::unique_ptr<InitialCondition> createUniformInitialCondition(
new UniformInitialCondition(*value)); new UniformInitialCondition(*value));
} }
std::unique_ptr<InitialCondition> createMeshPropertyInitialCondition(
ConfigTree const& config, MeshLib::Mesh const& mesh)
{
auto field_name = config.get_optional<std::string>("field_name");
if (!field_name)
{
ERR("Could not find required parameter field_name.");
std::abort();
}
DBUG("Using field_name %s", field_name->c_str());
if (!mesh.getProperties().hasPropertyVector(*field_name))
{
ERR("The required property %s does not exists in the mesh.",
field_name->c_str());
std::abort();
}
auto const& property =
mesh.getProperties().template getPropertyVector<double>(*field_name);
if (!property)
{
ERR("The required property %s is not of the requested type.",
field_name->c_str());
std::abort();
}
return std::unique_ptr<InitialCondition>(
new MeshPropertyInitialCondition(*property));
}
} // namespace ProcessLib } // namespace ProcessLib
...@@ -10,10 +10,18 @@ ...@@ -10,10 +10,18 @@
#ifndef PROCESS_LIB_INITIAL_CONDITION_H_ #ifndef PROCESS_LIB_INITIAL_CONDITION_H_
#define PROCESS_LIB_INITIAL_CONDITION_H_ #define PROCESS_LIB_INITIAL_CONDITION_H_
#include <cassert>
#include <boost/property_tree/ptree_fwd.hpp> #include <boost/property_tree/ptree_fwd.hpp>
#include "MeshLib/Node.h" #include "MeshLib/Node.h"
#include "MeshLib/PropertyVector.h" #include "MeshLib/PropertyVector.h"
namespace MeshLib
{
template <typename>
class PropertyVector;
class Mesh;
}
namespace ProcessLib namespace ProcessLib
{ {
/// The InitialCondition is a base class for spatial distributions of values /// The InitialCondition is a base class for spatial distributions of values
...@@ -47,6 +55,30 @@ using ConfigTree = boost::property_tree::ptree; ...@@ -47,6 +55,30 @@ using ConfigTree = boost::property_tree::ptree;
std::unique_ptr<InitialCondition> createUniformInitialCondition( std::unique_ptr<InitialCondition> createUniformInitialCondition(
ConfigTree const& config); ConfigTree const& config);
/// Distribution of values given by a mesh property defined on nodes.
class MeshPropertyInitialCondition : public InitialCondition
{
public:
MeshPropertyInitialCondition(
MeshLib::PropertyVector<double> const& property)
: _property(property)
{
assert(_property.getMeshItemType() == MeshLib::MeshItemType::Node);
}
virtual double getValue(MeshLib::Node const& n) const override
{
return _property[n.getID()];
}
private:
MeshLib::PropertyVector<double> const& _property;
};
/// Construct a MeshPropertyInitialCondition from configuration.
std::unique_ptr<InitialCondition> createMeshPropertyInitialCondition(
ConfigTree const& config, MeshLib::Mesh const& mesh);
} // namespace ProcessLib } // namespace ProcessLib
#endif // PROCESS_LIB_INITIAL_CONDITION_H_ #endif // PROCESS_LIB_INITIAL_CONDITION_H_
...@@ -40,6 +40,11 @@ ProcessVariable::ProcessVariable(ConfigTree const& config, ...@@ -40,6 +40,11 @@ ProcessVariable::ProcessVariable(ConfigTree const& config,
_initial_condition = _initial_condition =
createUniformInitialCondition(ic_config->second); createUniformInitialCondition(ic_config->second);
} }
if (type == "MeshProperty")
{
_initial_condition =
createMeshPropertyInitialCondition(ic_config->second, _mesh);
}
else else
{ {
ERR("Unknown type of the initial condition."); ERR("Unknown type of the initial condition.");
......
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