OGS 6.1.0-1721-g6382411ad
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 6:
66  {
67  // Symmetric Tensor - xx, yy, zz, xy, xz, yz
68  PropertyDataType property_value =
69  SymmTensor{values[0], values[1], values[2],
70  values[3], values[4], values[5]};
71  return std::make_unique<Constant>(property_value);
72  }
73  case 9:
74  {
75  // Tensor
76  PropertyDataType property_value = Tensor{
77  values[0], values[1], values[2], values[3], values[4],
78  values[5], values[6], values[7], values[8]};
79  return std::make_unique<Constant>(property_value);
80  }
81 
82  default:
83  {
84  OGS_FATAL(
85  "Creation of a constant property with %i components is not "
86  "implemented.",
87  values.size());
88  }
89  }
90 
91  PropertyDataType property_value;
92  return std::make_unique<Constant>(property_value);
93  }
94  // Properties can be medium, phase, or component properties.
95  // Some of them require information about the respective material.
96  // Thus, we pass a pointer to the material that requests the property.
97  // In this method, this pointer is realized via typename MaterialType, which
98  // replaces either Medium*, Phase*, or Component*.
99  // Note that most property constructors (only those that request material
100  // pointers) must be overloaded for any type of material.
101 
102  /* TODO Additional properties go here, for example:
103  if (boost::iequals(property_type, "BilinearTemperaturePressure"))
104  {
105  return createBilinearTemperaturePressure(config, material_type);
106  }
107  */
108 
109  // If none of the above property types are found, OGS throws an error.
110  OGS_FATAL("The specified component property type '%s' was not recognized",
111  property_type.c_str());
112 }
113 } // namespace
114 
115 namespace MaterialPropertyLib
116 {
117 std::unique_ptr<PropertyArray> createProperties(
118  boost::optional<BaseLib::ConfigTree> const& config)
119 {
120  if (!config)
121  {
122  return nullptr;
123  }
124 
126  auto const& property_configs = config->getConfigSubtreeList("property");
127  if (property_configs.empty())
128  {
129  return nullptr;
130  }
131 
132  auto properties = std::make_unique<PropertyArray>();
133 
134  for (auto property_config : property_configs)
135  {
136  // Parsing the property name:
137  auto const property_name =
139  property_config.getConfigParameter<std::string>("name");
140  // Create a new property based on the configuration subtree:
141  auto property = createProperty(property_config);
142 
143  // Insert the new property at the right position into the components
144  // private PropertyArray:
145  (*properties)[convertStringToProperty(property_name)] =
146  std::move(property);
147  }
148  return properties;
149 }
150 
151 } // namespace MaterialPropertyLib
std::unique_ptr< PropertyArray > createProperties(boost::optional< BaseLib::ConfigTree > const &config)
boost::variant< double, Pair, Vector, SymmTensor, Tensor, std::string > PropertyDataType
Definition: Property.h:37
T getConfigParameter(std::string const &param) const
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:83
std::array< double, 2 > Pair
Definition: VariableType.h:23
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
std::array< double, 3 > Vector
Definition: VariableType.h:27
std::array< double, 9 > Tensor
Definition: VariableType.h:35