diff --git a/ProcessLib/Parameter/ConstantParameter.cpp b/ParameterLib/ConstantParameter.cpp similarity index 96% rename from ProcessLib/Parameter/ConstantParameter.cpp rename to ParameterLib/ConstantParameter.cpp index 5ccaab1592aa49d332a435957a832c4de3fa302c..8a296d70523869368d5fc7eea28f9144b2f5a978 100644 --- a/ProcessLib/Parameter/ConstantParameter.cpp +++ b/ParameterLib/ConstantParameter.cpp @@ -8,11 +8,10 @@ */ #include "ConstantParameter.h" -#include <logog/include/logog.hpp> #include "BaseLib/ConfigTree.h" #include "BaseLib/Error.h" -namespace ProcessLib +namespace ParameterLib { std::unique_ptr<ParameterBase> createConstantParameter( std::string const& name, BaseLib::ConfigTree const& config) @@ -62,4 +61,4 @@ std::unique_ptr<ParameterBase> createConstantParameter( return std::make_unique<ConstantParameter<double>>(name, values); } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/ConstantParameter.h b/ParameterLib/ConstantParameter.h similarity index 96% rename from ProcessLib/Parameter/ConstantParameter.h rename to ParameterLib/ConstantParameter.h index 920322fa539f64ce3405a7fde4d19ad3489c2574..ab42c80c341a773978d838aa21417bfec50587bf 100644 --- a/ProcessLib/Parameter/ConstantParameter.h +++ b/ParameterLib/ConstantParameter.h @@ -9,11 +9,9 @@ #pragma once -#include <utility> - #include "Parameter.h" -namespace ProcessLib +namespace ParameterLib { /// Single, constant value parameter. template <typename T> @@ -76,4 +74,4 @@ private: std::unique_ptr<ParameterBase> createConstantParameter( std::string const& name, BaseLib::ConfigTree const& config); -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/CoordinateSystem.cpp b/ParameterLib/CoordinateSystem.cpp similarity index 98% rename from ProcessLib/Parameter/CoordinateSystem.cpp rename to ParameterLib/CoordinateSystem.cpp index 5b14e428e7163589e56e0940b8109e80a8a552bd..3e16da75c729015c3a3d68dff953c25948180588 100644 --- a/ProcessLib/Parameter/CoordinateSystem.cpp +++ b/ParameterLib/CoordinateSystem.cpp @@ -14,7 +14,7 @@ #include "Parameter.h" -namespace ProcessLib +namespace ParameterLib { CoordinateSystem::CoordinateSystem(Parameter<double> const& e0, Parameter<double> const& e1) @@ -116,4 +116,4 @@ Eigen::Matrix<double, 3, 3> CoordinateSystem::transformation<3>( #endif // NDEBUG return t; } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/CoordinateSystem.h b/ParameterLib/CoordinateSystem.h similarity index 95% rename from ProcessLib/Parameter/CoordinateSystem.h rename to ParameterLib/CoordinateSystem.h index 0469cbd4e64a976401eda5040161072852bf734c..91fe860b9bb43407c731ed7f4882186003636a87 100644 --- a/ProcessLib/Parameter/CoordinateSystem.h +++ b/ParameterLib/CoordinateSystem.h @@ -14,14 +14,14 @@ #include <array> #include <vector> -namespace ProcessLib +namespace ParameterLib { template <typename T> struct Parameter; class SpatialPosition; -} +} // namespace ParameterLib -namespace ProcessLib +namespace ParameterLib { struct CoordinateSystem final { @@ -65,4 +65,4 @@ private: std::array<Parameter<double> const*, 3> _base; }; -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/CurveScaledParameter.cpp b/ParameterLib/CurveScaledParameter.cpp similarity index 94% rename from ProcessLib/Parameter/CurveScaledParameter.cpp rename to ParameterLib/CurveScaledParameter.cpp index 0f941c7d7fdc0ed45c1b46d90749fb30b75c9f66..44335e00116da01c202f32ce7aae3ed79a322010 100644 --- a/ProcessLib/Parameter/CurveScaledParameter.cpp +++ b/ParameterLib/CurveScaledParameter.cpp @@ -8,9 +8,9 @@ */ #include "CurveScaledParameter.h" -#include "ProcessLib/Utils/ProcessUtils.h" +#include "Utils.h" -namespace ProcessLib +namespace ParameterLib { std::unique_ptr<ParameterBase> createCurveScaledParameter( std::string const& name, @@ -42,4 +42,4 @@ std::unique_ptr<ParameterBase> createCurveScaledParameter( name, *curve_it->second, referenced_parameter_name); } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/CurveScaledParameter.h b/ParameterLib/CurveScaledParameter.h similarity index 86% rename from ProcessLib/Parameter/CurveScaledParameter.h rename to ParameterLib/CurveScaledParameter.h index 04ed950db4d91c6a42e41fbb30da098e7d8afb6a..e9504e59db92fdb40726a9fd45c3f36da58d50c3 100644 --- a/ProcessLib/Parameter/CurveScaledParameter.h +++ b/ParameterLib/CurveScaledParameter.h @@ -13,12 +13,13 @@ #include <utility> #include "MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h" #include "Parameter.h" -#include "ProcessLib/Utils/ProcessUtils.h" +#include "Utils.h" -namespace ProcessLib +namespace ParameterLib { template <typename T> -struct CurveScaledParameter final : public Parameter<T> { +struct CurveScaledParameter final : public Parameter<T> +{ CurveScaledParameter(std::string const& name_, MathLib::PiecewiseLinearInterpolation const& curve, std::string referenced_parameter_name) @@ -30,8 +31,7 @@ struct CurveScaledParameter final : public Parameter<T> { bool isTimeDependent() const override { return true; } void initialize( - std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& - parameters) override + std::vector<std::unique_ptr<ParameterBase>> const& parameters) override { _parameter = &findParameter<T>(_referenced_parameter_name, parameters, 0); @@ -44,7 +44,7 @@ struct CurveScaledParameter final : public Parameter<T> { } std::vector<T> operator()(double const t, - SpatialPosition const& pos) const override + SpatialPosition const& pos) const override { // No local coordinate transformation here, which might happen twice // otherwise. @@ -77,4 +77,4 @@ std::unique_ptr<ParameterBase> createCurveScaledParameter( std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const& curves); -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/FunctionParameter.cpp b/ParameterLib/FunctionParameter.cpp similarity index 83% rename from ProcessLib/Parameter/FunctionParameter.cpp rename to ParameterLib/FunctionParameter.cpp index 2a943202e54dd6ec8c7eea4f1b3ad0bc39b97a1b..e27062cae04b922edbf358200eb4195b225ce1b2 100644 --- a/ProcessLib/Parameter/FunctionParameter.cpp +++ b/ParameterLib/FunctionParameter.cpp @@ -12,7 +12,7 @@ #include "BaseLib/ConfigTree.h" #include "MeshLib/Mesh.h" -namespace ProcessLib +namespace ParameterLib { std::unique_ptr<ParameterBase> createFunctionParameter( std::string const& name, BaseLib::ConfigTree const& config, @@ -30,8 +30,8 @@ std::unique_ptr<ParameterBase> createFunctionParameter( vec_expressions.emplace_back(expression_str); } - return std::make_unique<FunctionParameter<double>>( - name, mesh, vec_expressions); + return std::make_unique<FunctionParameter<double>>(name, mesh, + vec_expressions); } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/FunctionParameter.h b/ParameterLib/FunctionParameter.h similarity index 92% rename from ProcessLib/Parameter/FunctionParameter.h rename to ParameterLib/FunctionParameter.h index e0e65af60781cf3bd9eadb32865f98e9e4692679..a919b6a54899c4c50d6698baa5cbf9e9605a212e 100644 --- a/ProcessLib/Parameter/FunctionParameter.h +++ b/ParameterLib/FunctionParameter.h @@ -18,11 +18,10 @@ #include "MeshLib/Node.h" #include "Parameter.h" -#include "ProcessLib/Utils/ProcessUtils.h" +#include "Utils.h" -namespace ProcessLib +namespace ParameterLib { - /// A parameter class evaluating functions defined by /// user-provided mathematical expressions. /// @@ -55,14 +54,14 @@ struct FunctionParameter final : public Parameter<T> _symbol_table.create_variable("z"); _vec_expression.resize(_vec_expression_str.size()); - for (unsigned i=0; i<_vec_expression_str.size(); i++) + for (unsigned i = 0; i < _vec_expression_str.size(); i++) { _vec_expression[i].register_symbol_table(_symbol_table); parser_t parser; if (!parser.compile(_vec_expression_str[i], _vec_expression[i])) { OGS_FATAL("Error: %s\tExpression: %s\n", parser.error().c_str(), - _vec_expression_str[i].c_str()); + _vec_expression_str[i].c_str()); } } } @@ -75,7 +74,7 @@ struct FunctionParameter final : public Parameter<T> } std::vector<T> operator()(double const /*t*/, - SpatialPosition const& pos) const override + SpatialPosition const& pos) const override { std::vector<T> cache(getNumberOfComponents()); auto& x = _symbol_table.get_variable("x")->ref(); @@ -120,4 +119,4 @@ std::unique_ptr<ParameterBase> createFunctionParameter( std::string const& name, BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/GroupBasedParameter.cpp b/ParameterLib/GroupBasedParameter.cpp similarity index 92% rename from ProcessLib/Parameter/GroupBasedParameter.cpp rename to ParameterLib/GroupBasedParameter.cpp index e939846c857bb92794305146a3be0f224026f23f..b6d4a3f7247892dc9249d822a214ff0f97e8ef68 100644 --- a/ProcessLib/Parameter/GroupBasedParameter.cpp +++ b/ParameterLib/GroupBasedParameter.cpp @@ -13,7 +13,7 @@ #include "BaseLib/Error.h" #include "MeshLib/Mesh.h" -namespace ProcessLib +namespace ParameterLib { std::unique_ptr<ParameterBase> createGroupBasedParameter( std::string const& name, BaseLib::ConfigTree const& config, @@ -24,7 +24,8 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( // get a property vector of group IDs //! \ogs_file_param{prj__parameters__parameter__Group__group_id_property} - std::string const group_id_property_name = config.getConfigParameter<std::string>("group_id_property"); + std::string const group_id_property_name = + config.getConfigParameter<std::string>("group_id_property"); DBUG("Using group_id_property %s", group_id_property_name.c_str()); auto const& group_id_property = @@ -67,7 +68,8 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( unsigned n_values = vec_index_values.front().second.size(); for (auto p : vec_index_values) { - auto itr = std::find(group_id_property->begin(), group_id_property->end(), p.first); + auto itr = std::find(group_id_property->begin(), + group_id_property->end(), p.first); if (itr == group_id_property->end()) { OGS_FATAL( @@ -111,4 +113,4 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( OGS_FATAL("Mesh item type of the specified property is not supported."); } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/GroupBasedParameter.h b/ParameterLib/GroupBasedParameter.h similarity index 82% rename from ProcessLib/Parameter/GroupBasedParameter.h rename to ParameterLib/GroupBasedParameter.h index a34c57eb563b81b4b3695cb5d1ef7613e16d4933..71d9d979cdfcba3fa5d18f21c107f9771e5059ae 100644 --- a/ProcessLib/Parameter/GroupBasedParameter.h +++ b/ParameterLib/GroupBasedParameter.h @@ -16,21 +16,18 @@ #include "Parameter.h" - namespace MeshLib { template <typename T> class PropertyVector; -} // MeshLib +} // namespace MeshLib -namespace ProcessLib +namespace ParameterLib { - /// A parameter class looking for values from indices in a property vector. /// This class can be used for material ID dependent parameters. template <typename T, MeshLib::MeshItemType MeshItemType> -struct GroupBasedParameter final - : public Parameter<T> +struct GroupBasedParameter final : public Parameter<T> { /** * Constructing from a property vector of index and corresponding values @@ -61,7 +58,7 @@ struct GroupBasedParameter final } std::vector<T> operator()(double const /*t*/, - SpatialPosition const& pos) const override + SpatialPosition const& pos) const override { auto const item_id = getMeshItemID(pos, type<MeshItemType>()); assert(item_id); @@ -81,16 +78,19 @@ struct GroupBasedParameter final } private: - template <MeshLib::MeshItemType ITEM_TYPE> struct type {}; + template <MeshLib::MeshItemType ITEM_TYPE> + struct type + { + }; - static boost::optional<std::size_t> - getMeshItemID(SpatialPosition const& pos, type<MeshLib::MeshItemType::Cell>) + static boost::optional<std::size_t> getMeshItemID( + SpatialPosition const& pos, type<MeshLib::MeshItemType::Cell>) { return pos.getElementID(); } - static boost::optional<std::size_t> - getMeshItemID(SpatialPosition const& pos, type<MeshLib::MeshItemType::Node>) + static boost::optional<std::size_t> getMeshItemID( + SpatialPosition const& pos, type<MeshLib::MeshItemType::Node>) { return pos.getNodeID(); } @@ -104,4 +104,4 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/MeshElementParameter.cpp b/ParameterLib/MeshElementParameter.cpp similarity index 89% rename from ProcessLib/Parameter/MeshElementParameter.cpp rename to ParameterLib/MeshElementParameter.cpp index 8c707397d762ec99737dbcc916871b4eabe2e35f..0968906ca777329eafcbd03ac847778797ff9438 100644 --- a/ProcessLib/Parameter/MeshElementParameter.cpp +++ b/ParameterLib/MeshElementParameter.cpp @@ -11,7 +11,7 @@ #include "BaseLib/ConfigTree.h" #include "MeshLib/Mesh.h" -namespace ProcessLib +namespace ParameterLib { std::unique_ptr<ParameterBase> createMeshElementParameter( std::string const& name, BaseLib::ConfigTree const& config, @@ -20,14 +20,16 @@ std::unique_ptr<ParameterBase> createMeshElementParameter( //! \ogs_file_param{prj__parameters__parameter__type} config.checkConfigParameter("type", "MeshElement"); //! \ogs_file_param{prj__parameters__parameter__MeshElement__field_name} - auto const field_name = config.getConfigParameter<std::string>("field_name"); + auto const field_name = + config.getConfigParameter<std::string>("field_name"); DBUG("Using field_name %s", field_name.c_str()); // TODO other data types than only double auto const& property = mesh.getProperties().getPropertyVector<double>(field_name); - if (property->getMeshItemType() != MeshLib::MeshItemType::Cell) { + if (property->getMeshItemType() != MeshLib::MeshItemType::Cell) + { OGS_FATAL("The mesh property `%s' is not an element property.", field_name.c_str()); } @@ -36,4 +38,4 @@ std::unique_ptr<ParameterBase> createMeshElementParameter( *property); } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/MeshElementParameter.h b/ParameterLib/MeshElementParameter.h similarity index 92% rename from ProcessLib/Parameter/MeshElementParameter.h rename to ParameterLib/MeshElementParameter.h index ac86c05b6e83dc26ae7f2bb836e0418ee9d767fd..a94ab3f1fd078e809b4d7df4de6282b10697b39b 100644 --- a/ProcessLib/Parameter/MeshElementParameter.h +++ b/ParameterLib/MeshElementParameter.h @@ -15,13 +15,14 @@ namespace MeshLib { template <typename T> class PropertyVector; -} // MeshLib +} // namespace MeshLib -namespace ProcessLib +namespace ParameterLib { /// A parameter represented by a mesh property vector. template <typename T> -struct MeshElementParameter final : public Parameter<T> { +struct MeshElementParameter final : public Parameter<T> +{ MeshElementParameter(std::string const& name_, MeshLib::Mesh const& mesh, MeshLib::PropertyVector<T> const& property) @@ -37,7 +38,7 @@ struct MeshElementParameter final : public Parameter<T> { } std::vector<T> operator()(double const /*t*/, - SpatialPosition const& pos) const override + SpatialPosition const& pos) const override { auto const e = pos.getElementID(); if (!e) @@ -90,4 +91,4 @@ std::unique_ptr<ParameterBase> createMeshElementParameter( std::string const& name, BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/MeshNodeParameter.cpp b/ParameterLib/MeshNodeParameter.cpp similarity index 88% rename from ProcessLib/Parameter/MeshNodeParameter.cpp rename to ParameterLib/MeshNodeParameter.cpp index 11b9ecbabe2186d6c82605503bf7ad8560c262ea..6f360a068c85184c34b17bed3fbd712b3d33b8e8 100644 --- a/ProcessLib/Parameter/MeshNodeParameter.cpp +++ b/ParameterLib/MeshNodeParameter.cpp @@ -11,7 +11,7 @@ #include "BaseLib/ConfigTree.h" #include "MeshLib/Mesh.h" -namespace ProcessLib +namespace ParameterLib { std::unique_ptr<ParameterBase> createMeshNodeParameter( std::string const& name, BaseLib::ConfigTree const& config, @@ -20,14 +20,16 @@ std::unique_ptr<ParameterBase> createMeshNodeParameter( //! \ogs_file_param{prj__parameters__parameter__type} config.checkConfigParameter("type", "MeshNode"); //! \ogs_file_param{prj__parameters__parameter__MeshNode__field_name} - auto const field_name = config.getConfigParameter<std::string>("field_name"); + auto const field_name = + config.getConfigParameter<std::string>("field_name"); DBUG("Using field_name %s", field_name.c_str()); // TODO other data types than only double auto const& property = mesh.getProperties().getPropertyVector<double>(field_name); - if (property->getMeshItemType() != MeshLib::MeshItemType::Node) { + if (property->getMeshItemType() != MeshLib::MeshItemType::Node) + { OGS_FATAL("The mesh property `%s' is not a nodal property.", field_name.c_str()); } @@ -35,4 +37,4 @@ std::unique_ptr<ParameterBase> createMeshNodeParameter( return std::make_unique<MeshNodeParameter<double>>(name, mesh, *property); } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/MeshNodeParameter.h b/ParameterLib/MeshNodeParameter.h similarity index 92% rename from ProcessLib/Parameter/MeshNodeParameter.h rename to ParameterLib/MeshNodeParameter.h index 5f5286d98994197af77f937e1be9e5233dea64b3..7bfd7c4e1ad9d0f36339144d88b9a3559430dfd7 100644 --- a/ProcessLib/Parameter/MeshNodeParameter.h +++ b/ParameterLib/MeshNodeParameter.h @@ -19,13 +19,14 @@ namespace MeshLib { template <typename T> class PropertyVector; -} // MeshLib +} // namespace MeshLib -namespace ProcessLib +namespace ParameterLib { /// A parameter represented by a mesh property vector. template <typename T> -struct MeshNodeParameter final : public Parameter<T> { +struct MeshNodeParameter final : public Parameter<T> +{ MeshNodeParameter(std::string const& name_, MeshLib::Mesh const& mesh, MeshLib::PropertyVector<T> const& property) @@ -41,7 +42,7 @@ struct MeshNodeParameter final : public Parameter<T> { } std::vector<T> operator()(double const /*t*/, - SpatialPosition const& pos) const override + SpatialPosition const& pos) const override { auto const n = pos.getNodeID(); if (!n) @@ -94,4 +95,4 @@ std::unique_ptr<ParameterBase> createMeshNodeParameter( std::string const& name, BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/Parameter.cpp b/ParameterLib/Parameter.cpp similarity index 98% rename from ProcessLib/Parameter/Parameter.cpp rename to ParameterLib/Parameter.cpp index 2cddcff1c57459e195d3c1b417d94cf0e8d25c9d..c535765cbc9895f06f7d908c59d72c4ef4bf08fe 100644 --- a/ProcessLib/Parameter/Parameter.cpp +++ b/ParameterLib/Parameter.cpp @@ -18,7 +18,7 @@ #include "MeshElementParameter.h" #include "MeshNodeParameter.h" -namespace ProcessLib +namespace ParameterLib { std::unique_ptr<ParameterBase> createParameter( BaseLib::ConfigTree const& config, @@ -27,7 +27,6 @@ std::unique_ptr<ParameterBase> createParameter( std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const& curves) { - //! \ogs_file_param{prj__parameters__parameter__name} auto const name = config.getConfigParameter<std::string>("name"); //! \ogs_file_param{prj__parameters__parameter__type} @@ -85,4 +84,4 @@ std::unique_ptr<ParameterBase> createParameter( OGS_FATAL("Cannot construct a parameter of given type '%s'.", type.c_str()); } -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/Parameter.h b/ParameterLib/Parameter.h similarity index 94% rename from ProcessLib/Parameter/Parameter.h rename to ParameterLib/Parameter.h index e359ed8f414ae93ed64bffc1946f0deeba32170c..6a6ec97860f56f0c07d79729bc145007977606fb 100644 --- a/ProcessLib/Parameter/Parameter.h +++ b/ParameterLib/Parameter.h @@ -27,19 +27,19 @@ namespace BaseLib { class ConfigTree; -} // BaseLib +} // namespace BaseLib namespace MathLib { class PiecewiseLinearInterpolation; -} // MathLib +} // namespace MathLib namespace MeshLib { class Mesh; -} // MeshLib +} // namespace MeshLib -namespace ProcessLib +namespace ParameterLib { /// Base class for all parameters, not an interface class. This avoids using of /// void* when storing parameters and convenient destruction. @@ -64,8 +64,7 @@ struct ParameterBase /// Parameters might depend on each other; this method allows to set up the /// dependencies between parameters after they have been constructed. virtual void initialize( - std::vector< - std::unique_ptr<ProcessLib::ParameterBase>> const& /*parameters*/) + std::vector<std::unique_ptr<ParameterBase>> const& /*parameters*/) { } @@ -144,13 +143,13 @@ struct Parameter : public ParameterBase ~Parameter() override = default; - //! Returns the number of components this Parameter has at every position and - //! point in time. + //! Returns the number of components this Parameter has at every position + //! and point in time. virtual int getNumberOfComponents() const = 0; //! Returns the parameter value at the given time and position. - virtual std::vector<T> operator()( - double const t, SpatialPosition const& pos) const = 0; + virtual std::vector<T> operator()(double const t, + SpatialPosition const& pos) const = 0; //! Returns a matrix of values for all nodes of the given element. // @@ -198,4 +197,4 @@ std::unique_ptr<ParameterBase> createParameter( std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const& curves); -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ProcessLib/Parameter/SpatialPosition.h b/ParameterLib/SpatialPosition.h similarity index 97% rename from ProcessLib/Parameter/SpatialPosition.h rename to ParameterLib/SpatialPosition.h index 30a87e0973348680a2f3474f699b54845094e2e7..e1d98fea26607fd5a56440fdef548522bf7b1f7e 100644 --- a/ProcessLib/Parameter/SpatialPosition.h +++ b/ParameterLib/SpatialPosition.h @@ -12,7 +12,7 @@ #include <boost/optional.hpp> #include "MathLib/TemplatePoint.h" -namespace ProcessLib +namespace ParameterLib { //! Represents a position in space which can be either one of //! a node, an element, an integration point or a cartesian coordinates triple. @@ -86,4 +86,4 @@ private: boost::optional<MathLib::TemplatePoint<double, 3>> _coordinates; }; -} // namespace ProcessLib +} // namespace ParameterLib diff --git a/ParameterLib/Utils.cpp b/ParameterLib/Utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b903042c5529e78053ce2e656aa1931d04804f01 --- /dev/null +++ b/ParameterLib/Utils.cpp @@ -0,0 +1,33 @@ +/** + * \copyright + * Copyright (c) 2012-2019, 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 "Utils.h" + +namespace ParameterLib +{ +ParameterBase* findParameterByName( + std::string const& parameter_name, + std::vector<std::unique_ptr<ParameterBase>> const& parameters) +{ + // Find corresponding parameter by name. + auto const it = std::find_if( + parameters.cbegin(), parameters.cend(), + [¶meter_name](std::unique_ptr<ParameterBase> const& p) { + return p->name == parameter_name; + }); + + if (it == parameters.end()) + { + return nullptr; + } + + DBUG("Found parameter `%s'.", (*it)->name.c_str()); + return it->get(); +} +} // namespace ParameterLib diff --git a/ParameterLib/Utils.h b/ParameterLib/Utils.h new file mode 100644 index 0000000000000000000000000000000000000000..fd191cdb83e4123f4abdbb058dec1af204a84019 --- /dev/null +++ b/ParameterLib/Utils.h @@ -0,0 +1,127 @@ +/** + * \copyright + * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#pragma once + +#include <vector> +#include "BaseLib/ConfigTree.h" +#include "BaseLib/Error.h" + +#include "Parameter.h" + +namespace ParameterLib +{ +/// Find an optional parameter of specific type for a given name. +/// +/// \tparam ParameterDataType the data type of the parameter +/// \param parameter_name name of the requested parameter +/// \param parameters list of parameters in which it will be searched +ParameterBase* findParameterByName( + std::string const& parameter_name, + std::vector<std::unique_ptr<ParameterBase>> const& parameters); + +/// Find an optional parameter of specific type for a given name. +/// +/// \tparam ParameterDataType the data type of the parameter +/// \param parameter_name name of the requested parameter +/// \param parameters list of parameters in which it will be searched +/// \param num_components the number of components of the parameters or zero if +/// any number is acceptable +/// +/// \see The documentation of the other findParameter() function. +template <typename ParameterDataType> +Parameter<ParameterDataType>* findParameterOptional( + std::string const& parameter_name, + std::vector<std::unique_ptr<ParameterBase>> const& parameters, + int const num_components) +{ + // Find corresponding parameter by name. + ParameterBase* parameter_ptr = + findParameterByName(parameter_name, parameters); + if (parameter_ptr == nullptr) + { + return nullptr; + } + + // Check the type correctness of the found parameter. + auto* const parameter = + dynamic_cast<Parameter<ParameterDataType>*>(parameter_ptr); + if (!parameter) + { + OGS_FATAL("The read parameter `%s' is of incompatible type.", + parameter_name.c_str()); + } + + if (num_components != 0 && + parameter->getNumberOfComponents() != num_components) + { + OGS_FATAL( + "The read parameter `%s' has the wrong number of components (%lu " + "instead of %u).", + parameter_name.c_str(), parameter->getNumberOfComponents(), + num_components); + } + + return parameter; +} + +/// Find a parameter of specific type for a given name. +/// +/// \tparam ParameterDataType the data type of the parameter +/// \param parameter_name name of the requested parameter +/// \param parameters list of parameters in which it will be searched +/// \param num_components the number of components of the parameters or zero if +/// any number is acceptable +/// +/// \see The documentation of the other findParameter() function. +template <typename ParameterDataType> +Parameter<ParameterDataType>& findParameter( + std::string const& parameter_name, + std::vector<std::unique_ptr<ParameterBase>> const& parameters, + int const num_components) +{ + auto* parameter = findParameterOptional<ParameterDataType>( + parameter_name, parameters, num_components); + + if (!parameter) + { + OGS_FATAL( + "Could not find parameter `%s' in the provided parameters list.", + parameter_name.c_str()); + } + return *parameter; +} + +/// Find a parameter of specific type for a name given in the process +/// configuration under the tag. +/// The parameter must have the specified number of components. +/// In the process config a parameter is referenced by a name. For example it +/// will be looking for a parameter named "K" in the list of parameters +/// when the tag is "hydraulic_conductivity": +/// \code +/// <process> +/// ... +/// <hydraulic_conductivity>K</hydraulic_conductivity> +/// </process> +/// \endcode +/// and return a reference to that parameter. Additionally it checks for the +/// type of the found parameter. +template <typename ParameterDataType> +Parameter<ParameterDataType>& findParameter( + BaseLib::ConfigTree const& process_config, std::string const& tag, + std::vector<std::unique_ptr<ParameterBase>> const& parameters, + int const num_components) +{ + // Find parameter name in process config. + //! \ogs_file_special + auto const name = process_config.getConfigParameter<std::string>(tag); + + return findParameter<ParameterDataType>(name, parameters, num_components); +} +} // namespace ParameterLib diff --git a/ProcessLib/Utils/ProcessUtils.cpp b/ProcessLib/Utils/ProcessUtils.cpp index 0ae4befd5ed128620f202b008b063f95506f9ffa..8faaae6b87af161b51fc938a31b8ba21ccfce158 100644 --- a/ProcessLib/Utils/ProcessUtils.cpp +++ b/ProcessLib/Utils/ProcessUtils.cpp @@ -8,7 +8,8 @@ */ #include "ProcessUtils.h" -#include <iterator> + +#include "BaseLib/ConfigTree.h" #include "ProcessLib/ProcessVariable.h" namespace @@ -105,24 +106,4 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables( return vars; } - -ParameterBase* findParameterByName( - std::string const& parameter_name, - std::vector<std::unique_ptr<ParameterBase>> const& parameters) -{ - // Find corresponding parameter by name. - auto const it = std::find_if( - parameters.cbegin(), parameters.cend(), - [¶meter_name](std::unique_ptr<ParameterBase> const& p) { - return p->name == parameter_name; - }); - - if (it == parameters.end()) - { - return nullptr; - } - - DBUG("Found parameter `%s'.", (*it)->name.c_str()); - return it->get(); -} } // namespace ProcessLib diff --git a/ProcessLib/Utils/ProcessUtils.h b/ProcessLib/Utils/ProcessUtils.h index b381837f4c39874e8b93e5439eec46a7e3e24b4d..d98b43aa7ef4d8bdad6539fda221335354f36cc8 100644 --- a/ProcessLib/Utils/ProcessUtils.h +++ b/ProcessLib/Utils/ProcessUtils.h @@ -9,15 +9,20 @@ #pragma once +#include <string> #include <vector> -#include "BaseLib/ConfigTree.h" -#include "BaseLib/Error.h" -#include "ProcessLib/Parameter/Parameter.h" +namespace BaseLib +{ +class ConfigTree; +} namespace ProcessLib { class ProcessVariable; +} +namespace ProcessLib +{ /// Find process variables in \c variables whose names match the settings under /// the given \c tag_names in the \c process_config. /// @@ -47,110 +52,4 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables( BaseLib::ConfigTree const& pv_config, std::string const& tag); -/// Find an optional parameter of specific type for a given name. -/// -/// \tparam ParameterDataType the data type of the parameter -/// \param parameter_name name of the requested parameter -/// \param parameters list of parameters in which it will be searched -ParameterBase* findParameterByName( - std::string const& parameter_name, - std::vector<std::unique_ptr<ParameterBase>> const& parameters); - -/// Find an optional parameter of specific type for a given name. -/// -/// \tparam ParameterDataType the data type of the parameter -/// \param parameter_name name of the requested parameter -/// \param parameters list of parameters in which it will be searched -/// \param num_components the number of components of the parameters or zero if -/// any number is acceptable -/// -/// \see The documentation of the other findParameter() function. -template <typename ParameterDataType> -Parameter<ParameterDataType>* findParameterOptional( - std::string const& parameter_name, - std::vector<std::unique_ptr<ParameterBase>> const& parameters, - int const num_components) -{ - // Find corresponding parameter by name. - ParameterBase* parameter_ptr = - findParameterByName(parameter_name, parameters); - if (parameter_ptr == nullptr) - { - return nullptr; - } - - // Check the type correctness of the found parameter. - auto* const parameter = - dynamic_cast<Parameter<ParameterDataType>*>(parameter_ptr); - if (!parameter) { - OGS_FATAL("The read parameter `%s' is of incompatible type.", - parameter_name.c_str()); - } - - if (num_components != 0 && - parameter->getNumberOfComponents() != num_components) - { - OGS_FATAL( - "The read parameter `%s' has the wrong number of components (%lu " - "instead of %u).", - parameter_name.c_str(), parameter->getNumberOfComponents(), - num_components); - } - - return parameter; -} - -/// Find a parameter of specific type for a given name. -/// -/// \tparam ParameterDataType the data type of the parameter -/// \param parameter_name name of the requested parameter -/// \param parameters list of parameters in which it will be searched -/// \param num_components the number of components of the parameters or zero if -/// any number is acceptable -/// -/// \see The documentation of the other findParameter() function. -template <typename ParameterDataType> -Parameter<ParameterDataType>& findParameter( - std::string const& parameter_name, - std::vector<std::unique_ptr<ParameterBase>> const& parameters, - int const num_components) -{ - auto* parameter = findParameterOptional<ParameterDataType>( - parameter_name, parameters, num_components); - - if (!parameter) - { - OGS_FATAL( - "Could not find parameter `%s' in the provided parameters list.", - parameter_name.c_str()); - } - return *parameter; -} - -/// Find a parameter of specific type for a name given in the process -/// configuration under the tag. -/// The parameter must have the specified number of components. -/// In the process config a parameter is referenced by a name. For example it -/// will be looking for a parameter named "K" in the list of parameters -/// when the tag is "hydraulic_conductivity": -/// \code -/// <process> -/// ... -/// <hydraulic_conductivity>K</hydraulic_conductivity> -/// </process> -/// \endcode -/// and return a reference to that parameter. Additionally it checks for the -/// type of the found parameter. -template <typename ParameterDataType> -Parameter<ParameterDataType>& findParameter( - BaseLib::ConfigTree const& process_config, std::string const& tag, - std::vector<std::unique_ptr<ParameterBase>> const& parameters, - int const num_components) -{ - // Find parameter name in process config. - //! \ogs_file_special - auto const name = process_config.getConfigParameter<std::string>(tag); - - return findParameter<ParameterDataType>(name, parameters, num_components); -} } // namespace ProcessLib diff --git a/Tests/ProcessLib/TestParameter.cpp b/Tests/ParameterLib/Parameter.cpp similarity index 90% rename from Tests/ProcessLib/TestParameter.cpp rename to Tests/ParameterLib/Parameter.cpp index 05cd6e05659d13858f2fce221148adfdc9a08ddc..d9492fcc63f9ae438ed7a5e3df9378f3ab79f86a 100644 --- a/Tests/ProcessLib/TestParameter.cpp +++ b/Tests/ParameterLib/Parameter.cpp @@ -23,10 +23,10 @@ #include "MeshLib/Node.h" #include "MeshLib/PropertyVector.h" -#include "ProcessLib/Parameter/GroupBasedParameter.h" -#include "ProcessLib/Parameter/CurveScaledParameter.h" +#include "ParameterLib/CurveScaledParameter.h" +#include "ParameterLib/GroupBasedParameter.h" -using namespace ProcessLib; +using namespace ParameterLib; std::unique_ptr<Parameter<double>> constructParameterFromString( std::string const& xml, @@ -43,7 +43,7 @@ std::unique_ptr<Parameter<double>> constructParameterFromString( static_cast<Parameter<double>*>(parameter_base.release())); } -struct ProcessLibParameter : public ::testing::Test +struct ParameterLibParameter : public ::testing::Test { void SetUp() override { @@ -53,7 +53,7 @@ struct ProcessLibParameter : public ::testing::Test std::vector<std::unique_ptr<MeshLib::Mesh>> meshes; }; -TEST_F(ProcessLibParameter, GroupBasedParameterElement) +TEST_F(ParameterLibParameter, GroupBasedParameterElement) { std::vector<int> mat_ids({0, 1, 2, 3}); MeshLib::addPropertyToMesh(*meshes[0], "MaterialIDs", @@ -69,7 +69,7 @@ TEST_F(ProcessLibParameter, GroupBasedParameterElement) meshes); double t = 0; - ProcessLib::SpatialPosition x; + ParameterLib::SpatialPosition x; x.setElementID(0); ASSERT_EQ(0.0, (*parameter)(t, x)[0]); x.setElementID(1); @@ -78,10 +78,9 @@ TEST_F(ProcessLibParameter, GroupBasedParameterElement) ASSERT_ANY_THROW((*parameter)(t, x)); x.setElementID(3); ASSERT_EQ(300.0, (*parameter)(t, x)[0]); - } -TEST_F(ProcessLibParameter, GroupBasedParameterNode) +TEST_F(ParameterLibParameter, GroupBasedParameterNode) { std::vector<int> group_ids({0, 1, 2, 3, 4}); MeshLib::addPropertyToMesh(*meshes[0], "PointGroupIDs", @@ -97,7 +96,7 @@ TEST_F(ProcessLibParameter, GroupBasedParameterNode) meshes); double t = 0; - ProcessLib::SpatialPosition x; + ParameterLib::SpatialPosition x; x.setNodeID(0); ASSERT_EQ(0.0, (*parameter)(t, x)[0]); x.setNodeID(1); @@ -150,7 +149,7 @@ bool testNodalValuesOfElement( } // For all elements all nodes have a constant value. -TEST_F(ProcessLibParameter, GetNodalValuesOnElement_constant) +TEST_F(ParameterLibParameter, GetNodalValuesOnElement_constant) { auto const parameter = constructParameterFromString( "<name>parameter</name>" @@ -160,7 +159,7 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_constant) double const t = 0; auto expected_value = [](MeshLib::Element* const /*e*/, - std::size_t const /*local_node_id*/) { + std::size_t const /*local_node_id*/) { return 42.23; }; @@ -168,7 +167,7 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_constant) expected_value, *parameter, t)); } -TEST_F(ProcessLibParameter, GetNodalValuesOnElement_node) +TEST_F(ParameterLibParameter, GetNodalValuesOnElement_node) { std::vector<double> node_ids({0, 1, 2, 3, 4}); MeshLib::addPropertyToMesh(*meshes[0], "NodeIDs", @@ -184,7 +183,7 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_node) // For all elements all nodes have the value of the node id. auto expected_value = [](MeshLib::Element* const e, - std::size_t const local_node_id) { + std::size_t const local_node_id) { return static_cast<double>(e->getNode(local_node_id)->getID()); }; @@ -192,7 +191,7 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_node) expected_value, *parameter, t)); } -TEST_F(ProcessLibParameter, GetNodalValuesOnElement_element) +TEST_F(ParameterLibParameter, GetNodalValuesOnElement_element) { std::vector<double> element_ids({0, 1, 2, 3}); MeshLib::addPropertyToMesh(*meshes[0], "ElementIDs", @@ -216,7 +215,7 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_element) expected_value, *parameter, t)); } -TEST_F(ProcessLibParameter, GetNodalValuesOnElement_curveScaledNode) +TEST_F(ParameterLibParameter, GetNodalValuesOnElement_curveScaledNode) { std::vector<double> node_ids({0, 1, 2, 3, 4}); MeshLib::addPropertyToMesh(*meshes[0], "NodeIDs", @@ -249,7 +248,7 @@ TEST_F(ProcessLibParameter, GetNodalValuesOnElement_curveScaledNode) // For all elements all nodes have the value of the node id times the time. auto expected_value = [&t](MeshLib::Element* const e, - std::size_t const local_node_id) { + std::size_t const local_node_id) { return static_cast<double>(e->getNode(local_node_id)->getID()) * t; };