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