diff --git a/ProcessLib/InitialCondition.cpp b/ProcessLib/InitialCondition.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8e6bd1a75d06b9cc0b2f44a3da5d29b3897c3574 --- /dev/null +++ b/ProcessLib/InitialCondition.cpp @@ -0,0 +1,39 @@ +/** + * \copyright + * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include "InitialCondition.h" + +#include <boost/property_tree/ptree.hpp> +#include <boost/optional.hpp> +#include <logog/include/logog.hpp> + +#include "MathLib/Point3d.h" +#include "MeshLib/Elements/Element.h" +#include "MeshLib/Mesh.h" + +namespace ProcessLib +{ +using ConfigTree = boost::property_tree::ptree; + +std::unique_ptr<InitialCondition> createUniformInitialCondition( + ConfigTree const& config) +{ + auto value = config.get_optional<double>("value"); + if (!value) + { + ERR("Could not find required parameter value."); + std::abort(); + } + DBUG("Using value %g", *value); + + return std::unique_ptr<InitialCondition>( + new UniformInitialCondition(*value)); +} + +} // namespace ProcessLib diff --git a/ProcessLib/InitialCondition.h b/ProcessLib/InitialCondition.h index 02a49728f97de7b07408913d78380ef1258651ff..8833a680b121de2d66d14263a0a922f171913a0a 100644 --- a/ProcessLib/InitialCondition.h +++ b/ProcessLib/InitialCondition.h @@ -10,11 +10,9 @@ #ifndef PROCESS_LIB_INITIAL_CONDITION_H_ #define PROCESS_LIB_INITIAL_CONDITION_H_ -#include <boost/property_tree/ptree.hpp> -#include "logog/include/logog.hpp" - -#include "MeshLib/Mesh.h" +#include <boost/property_tree/ptree_fwd.hpp> #include "MeshLib/Node.h" +#include "MeshLib/PropertyVector.h" namespace ProcessLib { @@ -30,15 +28,9 @@ public: /// Uniform value initial condition class UniformInitialCondition : public InitialCondition { - using ConfigTree = boost::property_tree::ptree; - public: - UniformInitialCondition(ConfigTree const& config) + UniformInitialCondition(double const value) : _value(value) { - DBUG("Constructing Uniform initial condition"); - - _value = config.get<double>("value", 0); - DBUG("Read value %g", _value); } virtual double getValue(MeshLib::Node const&) const override @@ -50,6 +42,11 @@ private: double _value; }; +using ConfigTree = boost::property_tree::ptree; +/// Construct a UniformInitialCondition from configuration. +std::unique_ptr<InitialCondition> createUniformInitialCondition( + ConfigTree const& config); + } // namespace ProcessLib #endif // PROCESS_LIB_INITIAL_CONDITION_H_ diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp index 088623730008a52c6d8d4a48601c2e1b2bb96b25..0c142c02f6d77f6c0617fd98c1b226f4d313618a 100644 --- a/ProcessLib/ProcessVariable.cpp +++ b/ProcessLib/ProcessVariable.cpp @@ -37,8 +37,8 @@ ProcessVariable::ProcessVariable(ConfigTree const& config, config.get<std::string>("initial_condition.type"); if (type == "Uniform") { - _initial_condition.reset( - new UniformInitialCondition(ic_config->second)); + _initial_condition = + createUniformInitialCondition(ic_config->second); } else {