OGS
GroupBasedParameter.cpp
Go to the documentation of this file.
1 
11 #include "GroupBasedParameter.h"
12 
13 #include "BaseLib/ConfigTree.h"
14 #include "BaseLib/Error.h"
15 #include "MeshLib/Mesh.h"
16 
17 namespace ParameterLib
18 {
19 std::unique_ptr<ParameterBase> createGroupBasedParameter(
20  std::string const& name, BaseLib::ConfigTree const& config,
21  MeshLib::Mesh const& mesh)
22 {
24  config.checkConfigParameter("type", "Group");
25 
26  // get a property vector of group IDs
27  std::string const group_id_property_name =
29  config.getConfigParameter<std::string>("group_id_property");
30  DBUG("Using group_id_property {:s}", group_id_property_name);
31 
32  auto const& group_id_property =
33  mesh.getProperties().getPropertyVector<int>(group_id_property_name);
34 
35  // parse mapping data
36  using Values = std::vector<double>;
37  std::map<int, Values> vec_index_values;
39  for (auto p : config.getConfigSubtreeList("index_values"))
40  {
42  auto const index = p.getConfigParameter<int>("index");
43  {
45  auto const value = p.getConfigParameterOptional<double>("value");
46 
47  if (value)
48  {
49  Values values(1, *value);
50  vec_index_values.emplace(index, values);
51  continue;
52  }
53  }
54 
55  // Value tag not available; continue with required values tag.
57  Values const values = p.getConfigParameter<Values>("values");
58 
59  if (values.empty())
60  {
61  OGS_FATAL("No value available for constant parameter.");
62  }
63 
64  vec_index_values.emplace(index, values);
65  }
66 
67  // check the input
68  for (auto p : vec_index_values)
69  {
70 #ifndef USE_PETSC // In case of partitioned meshes not all of the material ids
71  // might be available in the particular partition, therefore
72  // the check is omitted.
73  if (std::find(group_id_property->begin(), group_id_property->end(),
74  p.first) == group_id_property->end())
75  {
76  OGS_FATAL(
77  "Specified property index {:d} does not exist in the property "
78  "vector {:s}",
79  p.first, group_id_property_name);
80  }
81 #endif
82 
83  auto const n_values = vec_index_values.begin()->second.size();
84  if (p.second.size() != n_values)
85  {
86  OGS_FATAL(
87  "The length of some values ({:d}) is different from the first "
88  "one ({:d}). The length should be same for all index_values.",
89  p.second.size(), n_values);
90  }
91  }
92 
93  if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Node)
94  {
95  return std::make_unique<
97  name, mesh, *group_id_property, vec_index_values);
98  }
99  if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell)
100  {
101  return std::make_unique<
103  name, mesh, *group_id_property, vec_index_values);
104  }
105 
106  OGS_FATAL("Mesh item type of the specified property is not supported.");
107 }
108 
109 } // namespace ParameterLib
#define OGS_FATAL(...)
Definition: Error.h:26
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
Definition of the Mesh class.
void checkConfigParameter(std::string const &param, T const &value) const
T getConfigParameter(std::string const &param) const
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
Definition: ConfigTree.cpp:169
Properties & getProperties()
Definition: Mesh.h:123
PropertyVector< T > const * getPropertyVector(std::string const &name) const
std::unique_ptr< ParameterBase > createGroupBasedParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)