OGS 6.2.1-97-g73d1aeda3
CreatePhase.cpp
Go to the documentation of this file.
1 
14 #include "CreatePhase.h"
15 
16 #include <set>
17 #include <string>
18 
19 #include "BaseLib/ConfigTree.h"
20 #include "ParameterLib/Parameter.h"
21 
22 #include "CreateComponent.h"
23 #include "CreateProperty.h"
24 #include "Phase.h"
25 
26 namespace
27 {
28 std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
29  BaseLib::ConfigTree const& config,
30  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
31 {
32  using namespace MaterialPropertyLib;
33 
35  auto&& phase_type = config.getConfigParameter<std::string>("type");
36 
37  if (phase_type.empty())
38  {
39  OGS_FATAL("Phase type is a mandatory field and cannot be empty.");
40  }
41 
42  std::array<std::string, 4> const allowed_phase_types = {
43  {"Solid", "AqueousLiquid", "NonAqueousLiquid", "Gas"}};
44 
45  if (std::none_of(allowed_phase_types.begin(),
46  allowed_phase_types.end(),
47  [&phase_type](std::string const& type) {
48  return phase_type == type;
49  }))
50  {
51  ERR("Phase type should be one of:");
52  for (auto const type : allowed_phase_types)
53  {
54  ERR(type.c_str());
55  }
56  OGS_FATAL("Wrong phase type '%s' given.", phase_type.c_str());
57  }
58 
59  // Parsing of optional components.
60  auto components =
62  createComponents(config.getConfigSubtreeOptional("components"),
63  parameters);
64 
65  // Properties of optional properties.
66  auto properties =
68  createProperties(config.getConfigSubtreeOptional("properties"),
69  parameters);
70 
71  if (components.empty() && !properties)
72  {
73  OGS_FATAL(
74  "Neither tag <components> nor tag <properties> has been set for "
75  "the phase '%s'.",
76  phase_type.c_str());
77  }
78 
79  return std::make_unique<Phase>(
80  std::move(phase_type), std::move(components), std::move(properties));
81 }
82 } // namespace
83 
84 namespace MaterialPropertyLib
85 {
86 std::vector<std::unique_ptr<Phase>> createPhases(
87  boost::optional<BaseLib::ConfigTree> const& config,
88  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
89 {
90  if (!config)
91  {
92  return {};
93  }
94 
95  std::vector<std::unique_ptr<Phase>> phases;
96 
97  for (auto phase_config :
99  config->getConfigSubtreeList("phase"))
100  {
101  auto phase = createPhase(phase_config, parameters);
102 
103  if (std::find_if(phases.begin(),
104  phases.end(),
105  [phase_name = phase->name()](auto const& p) {
106  return p->name() == phase_name;
107  }) != phases.end())
108  {
109  OGS_FATAL("Found duplicates with the same phase name tag '%s'.",
110  phase->name().c_str());
111  }
112 
113  phases.push_back(std::move(phase));
114  }
115 
116  return phases;
117 }
118 } // namespace MaterialPropertyLib
std::vector< std::unique_ptr< Component > > createComponents(boost::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters)
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::vector< std::unique_ptr< Phase > > createPhases(boost::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters)
Definition: CreatePhase.cpp:86
std::unique_ptr< MaterialPropertyLib::Phase > createPhase(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters)
Definition: CreatePhase.cpp:28
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:160