From 1f11b5b3c266e8a109ad74d8ccf85e1827cbca8c Mon Sep 17 00:00:00 2001 From: Norihiro Watanabe <norihiro.watanabe@ufz.de> Date: Mon, 26 Sep 2016 14:47:49 +0200 Subject: [PATCH] rename to GroupBasedParameter --- ...xParameter.cpp => GroupBasedParameter.cpp} | 46 +++++++++---------- ...IndexParameter.h => GroupBasedParameter.h} | 15 +++--- ProcessLib/Parameter/Parameter.cpp | 16 +++---- 3 files changed, 39 insertions(+), 38 deletions(-) rename ProcessLib/Parameter/{PropertyIndexParameter.cpp => GroupBasedParameter.cpp} (59%) rename ProcessLib/Parameter/{PropertyIndexParameter.h => GroupBasedParameter.h} (86%) diff --git a/ProcessLib/Parameter/PropertyIndexParameter.cpp b/ProcessLib/Parameter/GroupBasedParameter.cpp similarity index 59% rename from ProcessLib/Parameter/PropertyIndexParameter.cpp rename to ProcessLib/Parameter/GroupBasedParameter.cpp index c42ad192a13..7cca25ecce0 100644 --- a/ProcessLib/Parameter/PropertyIndexParameter.cpp +++ b/ProcessLib/Parameter/GroupBasedParameter.cpp @@ -7,7 +7,7 @@ * */ -#include "PropertyIndexParameter.h" +#include "GroupBasedParameter.h" #include "BaseLib/ConfigTree.h" #include "BaseLib/Error.h" @@ -15,34 +15,34 @@ namespace ProcessLib { -std::unique_ptr<ParameterBase> createPropertyIndexParameter( +std::unique_ptr<ParameterBase> createGroupBasedParameter( BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh) { //! \ogs_file_param{parameter__type} - config.checkConfigParameter("type", "PropertyIndex"); + config.checkConfigParameter("type", "Group"); - // get a property vector - //! \ogs_file_param{parameter_PropertyIndex__property_name} - std::string const property_name = config.getConfigParameter<std::string>("property_name"); - DBUG("Using property_name %s", property_name.c_str()); + // get a property vector of group IDs + //! \ogs_file_param{parameter_Group__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& property_vector = - mesh.getProperties().getPropertyVector<int>(property_name); - if (!property_vector) { - OGS_FATAL("The required property %s does not exist in the given mesh", property_name.c_str()); + auto const& group_id_property = + mesh.getProperties().getPropertyVector<int>(group_id_property_name); + if (!group_id_property) { + OGS_FATAL("The required property %s does not exist in the given mesh", group_id_property_name.c_str()); } // parse mapping data typedef std::vector<double> Values; typedef std::pair<int, Values> Index_Values; std::vector<Index_Values> vec_index_values; - //! \ogs_file_param{parameter_PropertyIndex__index_values} + //! \ogs_file_param{parameter_Group__index_values} for (auto p : config.getConfigSubtreeList("index_values")) { - //! \ogs_file_param{parameter_PropertyIndex__index_values__index} + //! \ogs_file_param{parameter_Group__index_values__index} auto const index = p.getConfigParameter<int>("index"); { - //! \ogs_file_param{parameter_PropertyIndex__index_values__value} + //! \ogs_file_param{parameter_Group__index_values__value} auto const value = p.getConfigParameterOptional<double>("value"); if (value) @@ -54,7 +54,7 @@ std::unique_ptr<ParameterBase> createPropertyIndexParameter( } // Value tag not available; continue with required values tag. - //! \ogs_file_param{parameter_PropertyIndex__index_values__values} + //! \ogs_file_param{parameter_Group__index_values__values} Values const values = p.getConfigParameter<Values>("values"); if (values.empty()) @@ -67,10 +67,10 @@ std::unique_ptr<ParameterBase> createPropertyIndexParameter( unsigned n_values = vec_index_values.front().second.size(); for (auto p : vec_index_values) { - auto itr = std::find(property_vector->begin(), property_vector->end(), p.first); - if (itr == property_vector->end()) + auto itr = std::find(group_id_property->begin(), group_id_property->end(), p.first); + if (itr == group_id_property->end()) OGS_FATAL("Specified property index %d does not exist in the property vector %s", - p.first, property_name.c_str()); + p.first, group_id_property_name.c_str()); if (p.second.size() != n_values) OGS_FATAL("The length of some values (%d) is different from the first one (%d). " @@ -79,17 +79,17 @@ std::unique_ptr<ParameterBase> createPropertyIndexParameter( } // create a mapping table - const int max_index = *std::max_element(property_vector->begin(), property_vector->end()); + const int max_index = *std::max_element(group_id_property->begin(), group_id_property->end()); std::vector<Values> vec_values(max_index + 1); for (auto p : vec_index_values) vec_values[p.first] = p.second; - if (property_vector->getMeshItemType() == MeshLib::MeshItemType::Node) + if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Node) return std::unique_ptr<ParameterBase>( - new PropertyIndexParameter<double, MeshLib::MeshItemType::Node>(*property_vector, vec_values)); - else if (property_vector->getMeshItemType() == MeshLib::MeshItemType::Cell) + new GroupBasedParameter<double, MeshLib::MeshItemType::Node>(*group_id_property, vec_values)); + else if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell) return std::unique_ptr<ParameterBase>( - new PropertyIndexParameter<double, MeshLib::MeshItemType::Cell>(*property_vector, vec_values)); + new GroupBasedParameter<double, MeshLib::MeshItemType::Cell>(*group_id_property, vec_values)); OGS_FATAL("Mesh item type of the specified property is not supported."); } diff --git a/ProcessLib/Parameter/PropertyIndexParameter.h b/ProcessLib/Parameter/GroupBasedParameter.h similarity index 86% rename from ProcessLib/Parameter/PropertyIndexParameter.h rename to ProcessLib/Parameter/GroupBasedParameter.h index 964b5ba416c..70e0ae65a31 100644 --- a/ProcessLib/Parameter/PropertyIndexParameter.h +++ b/ProcessLib/Parameter/GroupBasedParameter.h @@ -7,8 +7,8 @@ * */ -#ifndef PROCESSLIB_PROPERTYINDEXPARAMETER_H_ -#define PROCESSLIB_PROPERTYINDEXPARAMETER_H_ +#ifndef PROCESSLIB_GROUPBASEDPARAMETER_H_ +#define PROCESSLIB_GROUPBASEDPARAMETER_H_ #include "BaseLib/Error.h" #include "MeshLib/PropertyVector.h" @@ -28,7 +28,7 @@ namespace ProcessLib /// 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 PropertyIndexParameter final +struct GroupBasedParameter final : public Parameter<T> { /** @@ -37,8 +37,9 @@ struct PropertyIndexParameter final * @param property a property vector of index for mesh items * @param vec_values a vector of values for each index */ - PropertyIndexParameter(MeshLib::PropertyVector<int> const& property, - std::vector<std::vector<double>> const& vec_values) + GroupBasedParameter( + MeshLib::PropertyVector<int> const& property, + std::vector<std::vector<double>> const& vec_values) : _property_index(property), _vec_values(vec_values) { } @@ -82,9 +83,9 @@ private: }; -std::unique_ptr<ParameterBase> createPropertyIndexParameter( +std::unique_ptr<ParameterBase> createGroupBasedParameter( BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh); } // ProcessLib -#endif // PROCESSLIB_PROPERTYINDEXPARAMETER_H_ +#endif // PROCESSLIB_GROUPBASEDPARAMETER_H_ diff --git a/ProcessLib/Parameter/Parameter.cpp b/ProcessLib/Parameter/Parameter.cpp index 48c0e3199de..4a6f226a2e1 100644 --- a/ProcessLib/Parameter/Parameter.cpp +++ b/ProcessLib/Parameter/Parameter.cpp @@ -13,9 +13,9 @@ #include "ConstantParameter.h" #include "CurveScaledParameter.h" +#include "GroupBasedParameter.h" #include "MeshElementParameter.h" #include "MeshNodeParameter.h" -#include "PropertyIndexParameter.h" namespace ProcessLib { @@ -47,6 +47,13 @@ std::unique_ptr<ParameterBase> createParameter( param->name = name; return param; } + else if (type == "Group") + { + INFO("GroupBasedParameter: %s", name.c_str()); + auto param = createGroupBasedParameter(config, *meshes.front()); + param->name = name; + return param; + } else if (type == "MeshElement") { INFO("MeshElementParameter: %s", name.c_str()); @@ -61,13 +68,6 @@ std::unique_ptr<ParameterBase> createParameter( param->name = name; return param; } - else if (type == "PropertyIndex") - { - INFO("PropertyIndexParameter: %s", name.c_str()); - auto param = createPropertyIndexParameter(config, *meshes.front()); - param->name = name; - return param; - } else { OGS_FATAL("Cannot construct a parameter of given type \'%s\'.", -- GitLab