diff --git a/ProcessLib/ConstantParameter.cpp b/ProcessLib/ConstantParameter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b536a2589f8ef758c2fad07656618d5f32b11a2f --- /dev/null +++ b/ProcessLib/ConstantParameter.cpp @@ -0,0 +1,28 @@ +/** + * \copyright + * Copyright (c) 2012-2016, 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 "ConstantParameter.h" +#include <logog/include/logog.hpp> +#include "BaseLib/ConfigTree.h" + +namespace ProcessLib +{ +std::unique_ptr<ParameterBase> createConstantParameter( + BaseLib::ConfigTree const& config) +{ + //! \ogs_file_param{parameter__type} + config.checkConfigParameter("type", "Constant"); + //! \ogs_file_param{parameter__Constant__value} + auto value = config.getConfigParameter<double>("value"); + DBUG("Using value %g", value); + + return std::unique_ptr<ParameterBase>(new ConstantParameter<double>(value)); +} + +} // ProcessLib diff --git a/ProcessLib/ConstantParameter.h b/ProcessLib/ConstantParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..4cb66a19d8808fa847cb9a6c2793dbc35e2957d9 --- /dev/null +++ b/ProcessLib/ConstantParameter.h @@ -0,0 +1,36 @@ +/** + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef PROCESSLIB_CONSTANTPARAMETER_H +#define PROCESSLIB_CONSTANTPARAMETER_H + +#include "Parameter.h" + +namespace ProcessLib +{ +/// Single, constant value parameter. +template <typename T> +struct ConstantParameter final : public Parameter<T> { + ConstantParameter(T const& value) : _value{{value}} {} + std::vector<T> const& getTuple( + double const /*t*/, SpatialPosition const& /*pos*/) const override + { + return _value; + } + +private: + std::vector<T> _value; +}; + +std::unique_ptr<ParameterBase> createConstantParameter( + BaseLib::ConfigTree const& config); + +} // ProcessLib + +#endif // PROCESSLIB_CONSTANTPARAMETER_H diff --git a/ProcessLib/MeshElementParameter.cpp b/ProcessLib/MeshElementParameter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f05dab9a44f650428386a4fcdd4c33d102c7ee15 --- /dev/null +++ b/ProcessLib/MeshElementParameter.cpp @@ -0,0 +1,43 @@ +/** + * \copyright + * Copyright (c) 2012-2016, 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 "MeshElementParameter.h" +#include "BaseLib/ConfigTree.h" +#include "BaseLib/Error.h" +#include "MeshLib/Mesh.h" + +namespace ProcessLib +{ +std::unique_ptr<ParameterBase> createMeshElementParameter( + BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh) +{ + //! \ogs_file_param{parameter__type} + config.checkConfigParameter("type", "MeshProperty"); + //! \ogs_file_param{parameter__MeshProperty__field_name} + auto field_name = config.getConfigParameter<std::string>("field_name"); + DBUG("Using field_name %s", field_name.c_str()); + + if (!mesh.getProperties().hasPropertyVector(field_name)) { + OGS_FATAL("The required property %s does not exists in the mesh.", + field_name.c_str()); + } + + // TODO other data types than only double + auto const& property = + mesh.getProperties().template getPropertyVector<double>(field_name); + if (!property) { + OGS_FATAL("The required property %s is not of the requested type.", + field_name.c_str()); + } + + return std::unique_ptr<ParameterBase>( + new MeshElementParameter<double>(*property)); +} + +} // ProcessLib diff --git a/ProcessLib/MeshElementParameter.h b/ProcessLib/MeshElementParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..bb4f8d6ded38a8e96fc53617d4103560f7ba2650 --- /dev/null +++ b/ProcessLib/MeshElementParameter.h @@ -0,0 +1,51 @@ +/** + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef PROCESSLIB_MESHELEMENTPARAMETER_H +#define PROCESSLIB_MESHELEMENTPARAMETER_H + +#include "Parameter.h" + +namespace MeshLib +{ +template <typename T> +class PropertyVector; +} // MeshLib + +namespace ProcessLib +{ +/// A parameter represented by a mesh property vector. +template <typename T> +struct MeshElementParameter final : public Parameter<T> { + MeshElementParameter(MeshLib::PropertyVector<T> const& property) + : _property(property) + { + } + + std::vector<T> const& getTuple(double const /*t*/, + SpatialPosition const& pos) const override + { + auto const e = pos.getElementID(); + assert(e); + _cache.front() = _property[*e]; + return _cache; + } + +private: + MeshLib::PropertyVector<T> const& _property; + // TODO multi-component + mutable std::vector<double> _cache = std::vector<double>(1); +}; + +std::unique_ptr<ParameterBase> createMeshElementParameter( + BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); + +} // ProcessLib + +#endif // PROCESSLIB_MESHELEMENTPARAMETER_H diff --git a/ProcessLib/Parameter.cpp b/ProcessLib/Parameter.cpp index 681b1454c51e12b47e93c1499805860370434cc2..48b217a50ac27b0f80c88472f2d02ec2abf0a278 100644 --- a/ProcessLib/Parameter.cpp +++ b/ProcessLib/Parameter.cpp @@ -8,50 +8,44 @@ */ #include "Parameter.h" - -#include <boost/optional.hpp> -#include <logog/include/logog.hpp> - +#include "BaseLib/ConfigTree.h" #include "BaseLib/Error.h" -#include "MeshLib/Elements/Element.h" + +#include "ConstantParameter.h" +#include "MeshElementParameter.h" namespace ProcessLib { -std::unique_ptr<ParameterBase> createConstParameter( - BaseLib::ConfigTree const& config) -{ - //! \ogs_file_param{parameter__type} - config.checkConfigParameter("type", "Constant"); - //! \ogs_file_param{parameter__Constant__value} - auto value = config.getConfigParameter<double>("value"); - DBUG("Using value %g", value); - - return std::unique_ptr<ParameterBase>(new ConstParameter<double>(value)); -} -std::unique_ptr<ParameterBase> createMeshPropertyParameter( - BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh) +std::unique_ptr<ParameterBase> createParameter( + BaseLib::ConfigTree const& config, std::vector<MeshLib::Mesh*> const& meshes) { + + //! \ogs_file_param{parameter__name} + auto name = config.getConfigParameter<std::string>("name"); //! \ogs_file_param{parameter__type} - config.checkConfigParameter("type", "MeshProperty"); - //! \ogs_file_param{parameter__MeshProperty__field_name} - auto field_name = config.getConfigParameter<std::string>("field_name"); - DBUG("Using field_name %s", field_name.c_str()); + auto type = config.peekConfigParameter<std::string>("type"); - if (!mesh.getProperties().hasPropertyVector(field_name)) + // Create parameter based on the provided type. + if (type == "Constant") { - OGS_FATAL("The required property %s does not exists in the mesh.", - field_name.c_str()); + INFO("ConstantParameter: %s", name.c_str()); + auto param = createConstantParameter(config); + param->name = name; + return param; } - auto const& property = - mesh.getProperties().template getPropertyVector<double>(field_name); - if (!property) + else if (type == "MeshElement") { - OGS_FATAL("The required property %s is not of the requested type.", - field_name.c_str()); + INFO("MeshElementParameter: %s", name.c_str()); + auto param = createMeshElementParameter(config, *meshes.front()); + param->name = name; + return param; + } + else + { + OGS_FATAL("Cannot construct property of given type \'%s\'.", + type.c_str()); } - - return std::unique_ptr<ParameterBase>( - new MeshElementParameter<double>(*property)); } -} // namespace ProcessLib + +} // ProcessLib diff --git a/ProcessLib/Parameter.h b/ProcessLib/Parameter.h index 1e1745f6260db4344bfe49b7f77d2dde03343ad7..7a464b58763d6d51f3b6d93a0cf8f031e0baf9c6 100644 --- a/ProcessLib/Parameter.h +++ b/ProcessLib/Parameter.h @@ -11,19 +11,18 @@ #define PROCESS_LIB_PARAMETER_H_ #include <memory> - -#include <logog/include/logog.hpp> -#include <boost/optional.hpp> - -#include "BaseLib/ConfigTree.h" -#include "MeshLib/Elements/Element.h" +#include <vector> #include "SpatialPosition.h" +namespace BaseLib +{ +class ConfigTree; +} // BaseLib + namespace MeshLib { -template <typename T> -class PropertyVector; -} +class Mesh; +} // MeshLib namespace ProcessLib { @@ -47,48 +46,9 @@ struct Parameter : public ParameterBase double const t, SpatialPosition const& pos) const = 0; }; -/// Single, constant value parameter. -template <typename T> -struct ConstParameter final : public Parameter<T> { - ConstParameter(T const& value) : _value{{value}} {} - std::vector<T> const& getTuple( - double const /*t*/, SpatialPosition const& /*pos*/) const override - { - return _value; - } - -private: - std::vector<T> _value; -}; - -std::unique_ptr<ParameterBase> createConstParameter(BaseLib::ConfigTree const& config); - -/// A parameter represented by a mesh property vector. -template <typename T> -struct MeshElementParameter final - : public Parameter<T> -{ - MeshElementParameter(MeshLib::PropertyVector<T> const& property) - : _property(property) - { - } - - std::vector<T> const& getTuple( - double const /*t*/, SpatialPosition const& pos) const override - { - auto const e = pos.getElementID(); - assert(e); - _cache.front() = _property[*e]; - return _cache; - } - -private: - MeshLib::PropertyVector<T> const& _property; - // TODO multi-component - mutable std::vector<double> _cache = std::vector<double>(1); -}; - -std::unique_ptr<ParameterBase> createMeshPropertyParameter(BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); +std::unique_ptr<ParameterBase> createParameter( + BaseLib::ConfigTree const& config, + const std::vector<MeshLib::Mesh*>& meshes); } // namespace ProcessLib