OGS 6.2.0-97-g4a610c866
CreateProperty.cpp
Go to the documentation of this file.
1 
14 #include "CreateProperty.h"
15 
16 #include <string>
17 #include <vector>
18 #include "BaseLib/ConfigTree.h"
19 
20 #include "Properties/Properties.h"
21 
22 #include "Component.h"
23 #include "Medium.h"
24 #include "Phase.h"
25 
26 namespace
27 {
28 std::unique_ptr<MaterialPropertyLib::Property> createProperty(
29  BaseLib::ConfigTree const& config)
30 {
31  using namespace MaterialPropertyLib;
32  // Parsing the property type:
34  auto const property_type = config.getConfigParameter<std::string>("type");
35 
36  // If (and only if) the given property type is 'constant', a corresponding
37  // value is needed.
38  if (property_type == "Constant")
39  {
40  std::vector<double> const values =
42  config.getConfigParameter<std::vector<double>>("value");
43 
44  switch (values.size())
45  {
46  case 1:
47  {
48  // scalar
49  PropertyDataType property_value = values[0];
50  return std::make_unique<Constant>(property_value);
51  }
52  case 2:
53  {
54  // Pair
55  PropertyDataType property_value = Pair{values[0], values[1]};
56  return std::make_unique<Constant>(property_value);
57  }
58  case 3:
59  {
60  // Vector
61  PropertyDataType property_value =
62  Vector{values[0], values[1], values[2]};
63  return std::make_unique<Constant>(property_value);
64  }
65  case 4:
66  {
67  // Tensor
68  PropertyDataType property_value =
69  Tensor2d{values[0], values[1], values[2], values[3]};
70  return std::make_unique<Constant>(property_value);
71  }
72  case 6:
73  {
74  // Symmetric Tensor - xx, yy, zz, xy, xz, yz
75  PropertyDataType property_value =
76  SymmTensor{values[0], values[1], values[2],
77  values[3], values[4], values[5]};
78  return std::make_unique<Constant>(property_value);
79  }
80  case 9:
81  {
82  // Tensor
83  PropertyDataType property_value = Tensor{
84  values[0], values[1], values[2], values[3], values[4],
85  values[5], values[6], values[7], values[8]};
86  return std::make_unique<Constant>(property_value);
87  }
88 
89  default:
90  {
91  OGS_FATAL(
92  "Creation of a constant property with %i components is not "
93  "implemented.",
94  values.size());
95  }
96  }
97 
98  PropertyDataType property_value;
99  return std::make_unique<Constant>(property_value);
100  }
101  // Properties can be medium, phase, or component properties.
102  // Some of them require information about the respective material.
103  // Thus, we pass a pointer to the material that requests the property.
104  // In this method, this pointer is realized via typename MaterialType, which
105  // replaces either Medium*, Phase*, or Component*.
106  // Note that most property constructors (only those that request material
107  // pointers) must be overloaded for any type of material.
108 
109  if (property_type == "Linear")
110  {
111  auto const reference_value =
113  config.getConfigParameter<double>("reference_value");
114 
115  auto const& independent_variable_config =
117  config.getConfigSubtree("independent_variable");
118 
119  auto const& variable_name =
121  independent_variable_config.getConfigParameter<std::string>(
122  "variable_name");
123  auto const reference_condition =
125  independent_variable_config.getConfigParameter<double>(
126  "reference_condition");
127  auto const slope =
129  independent_variable_config.getConfigParameter<double>("slope");
130 
133 
135  ivt, reference_condition, slope};
136 
137  return std::make_unique<MaterialPropertyLib::LinearProperty>(
138  reference_value, iv);
139  }
140 
141  if (property_type == "Exponential")
142  {
143  auto const reference_value =
145  config.getConfigParameter<double>("reference_value");
146 
147  auto const& exponent_data_config =
149  config.getConfigSubtree("exponent");
150 
151  auto const& variable_name =
153  exponent_data_config.getConfigParameter<std::string>(
154  "variable_name");
155  auto const reference_condition =
157  exponent_data_config.getConfigParameter<double>(
158  "reference_condition");
159  auto const factor =
161  exponent_data_config.getConfigParameter<double>("factor");
162 
163  MaterialPropertyLib::Variable exp_data_type =
165 
166  MaterialPropertyLib::ExponentData const exp_data{
167  exp_data_type, reference_condition, factor};
168 
169  return std::make_unique<MaterialPropertyLib::ExponentialProperty>(
170  reference_value, exp_data);
171  }
172 
173  /* TODO Additional properties go here, for example:
174  if (boost::iequals(property_type, "BilinearTemperaturePressure"))
175  {
176  return createBilinearTemperaturePressure(config, material_type);
177  }
178  */
179 
180  // If none of the above property types are found, OGS throws an error.
181  OGS_FATAL("The specified component property type '%s' was not recognized",
182  property_type.c_str());
183 }
184 } // namespace
185 
186 namespace MaterialPropertyLib
187 {
188 std::unique_ptr<PropertyArray> createProperties(
189  boost::optional<BaseLib::ConfigTree> const& config)
190 {
191  if (!config)
192  {
193  return nullptr;
194  }
195 
197  auto const& property_configs = config->getConfigSubtreeList("property");
198  if (property_configs.empty())
199  {
200  return nullptr;
201  }
202 
203  auto properties = std::make_unique<PropertyArray>();
204 
205  for (auto property_config : property_configs)
206  {
207  // Parsing the property name:
208  auto const property_name =
210  property_config.getConfigParameter<std::string>("name");
211  // Create a new property based on the configuration subtree:
212  auto property = createProperty(property_config);
213 
214  // Insert the new property at the right position into the components
215  // private PropertyArray:
216  (*properties)[convertStringToProperty(property_name)] =
217  std::move(property);
218  }
219  return properties;
220 }
221 
222 } // namespace MaterialPropertyLib
std::unique_ptr< PropertyArray > createProperties(boost::optional< BaseLib::ConfigTree > const &config)
T getConfigParameter(std::string const &param) const
boost::variant< double, Pair, Vector, Tensor2d, SymmTensor, Tensor, std::string > PropertyDataType
Definition: Property.h:37
std::unique_ptr< MaterialPropertyLib::Property > createProperty(BaseLib::ConfigTree const &config)
std::array< double, 6 > SymmTensor
Definition: VariableType.h:31
PropertyType convertStringToProperty(std::string const &inString)
Definition: PropertyType.h:86
std::array< double, 2 > Pair
Definition: VariableType.h:23
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:150
Variable convertStringToVariable(std::string const &input)
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
std::array< double, 3 > Vector
Definition: VariableType.h:27
std::array< double, 9 > Tensor
Definition: VariableType.h:38
std::array< double, 4 > Tensor2d
Very simple 2d tensor data type for holding tensor components.
Definition: VariableType.h:34