From 496bb2c0097282e3454fb9f4e5f6bfd29e075260 Mon Sep 17 00:00:00 2001 From: "Dmitry Yu. Naumov" <github@naumov.de> Date: Tue, 1 Sep 2015 23:07:00 +0000 Subject: [PATCH] [PL] Add MeshPropertyInitialCondition. --- ProcessLib/InitialCondition.cpp | 30 ++++++++++++++++++++++++++++++ ProcessLib/InitialCondition.h | 32 ++++++++++++++++++++++++++++++++ ProcessLib/ProcessVariable.cpp | 5 +++++ 3 files changed, 67 insertions(+) diff --git a/ProcessLib/InitialCondition.cpp b/ProcessLib/InitialCondition.cpp index 8e6bd1a75d0..8725c4f35f4 100644 --- a/ProcessLib/InitialCondition.cpp +++ b/ProcessLib/InitialCondition.cpp @@ -36,4 +36,34 @@ std::unique_ptr<InitialCondition> createUniformInitialCondition( 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 diff --git a/ProcessLib/InitialCondition.h b/ProcessLib/InitialCondition.h index 8833a680b12..e7d6f7d9407 100644 --- a/ProcessLib/InitialCondition.h +++ b/ProcessLib/InitialCondition.h @@ -10,10 +10,18 @@ #ifndef PROCESS_LIB_INITIAL_CONDITION_H_ #define PROCESS_LIB_INITIAL_CONDITION_H_ +#include <cassert> #include <boost/property_tree/ptree_fwd.hpp> #include "MeshLib/Node.h" #include "MeshLib/PropertyVector.h" +namespace MeshLib +{ +template <typename> +class PropertyVector; +class Mesh; +} + namespace ProcessLib { /// The InitialCondition is a base class for spatial distributions of values @@ -47,6 +55,30 @@ using ConfigTree = boost::property_tree::ptree; std::unique_ptr<InitialCondition> createUniformInitialCondition( 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 #endif // PROCESS_LIB_INITIAL_CONDITION_H_ diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp index 0c142c02f6d..3ae34ecd007 100644 --- a/ProcessLib/ProcessVariable.cpp +++ b/ProcessLib/ProcessVariable.cpp @@ -40,6 +40,11 @@ ProcessVariable::ProcessVariable(ConfigTree const& config, _initial_condition = createUniformInitialCondition(ic_config->second); } + if (type == "MeshProperty") + { + _initial_condition = + createMeshPropertyInitialCondition(ic_config->second, _mesh); + } else { ERR("Unknown type of the initial condition."); -- GitLab