OGS 6.1.0-1721-g6382411ad
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 
21 #include "CreateComponent.h"
22 #include "CreateProperty.h"
23 #include "Phase.h"
24 
25 namespace
26 {
27 std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
28  BaseLib::ConfigTree const& config)
29 {
30  using namespace MaterialPropertyLib;
31 
33  auto&& phase_type = config.getConfigParameter<std::string>("type");
34 
35  if (phase_type.empty())
36  {
37  OGS_FATAL("Phase type is a mandatory field and cannot be empty.");
38  }
39 
40  std::array<std::string, 4> const allowed_phase_types = {
41  {"Solid", "AqueousLiquid", "NonAqueousLiquid", "Gas"}};
42 
43  if (std::none_of(allowed_phase_types.begin(),
44  allowed_phase_types.end(),
45  [&phase_type](std::string const& type) {
46  return phase_type == type;
47  }))
48  {
49  ERR("Phase type should be one of:");
50  for (auto const type : allowed_phase_types)
51  {
52  ERR(type.c_str());
53  }
54  OGS_FATAL("Wrong phase type '%s' given.", phase_type.c_str());
55  }
56 
57  // Parsing of optional components.
58  auto components =
60  createComponents(config.getConfigSubtreeOptional("components"));
61 
62  // Properties of optional properties.
63  auto properties =
65  createProperties(config.getConfigSubtreeOptional("properties"));
66 
67  if (components.empty() && !properties)
68  {
69  OGS_FATAL(
70  "Neither tag <components> nor tag <properties> has been set for "
71  "the phase '%s'.",
72  phase_type.c_str());
73  }
74 
75  return std::make_unique<Phase>(
76  std::move(phase_type), std::move(components), std::move(properties));
77 }
78 }
79 
80 namespace MaterialPropertyLib
81 {
82 std::vector<std::unique_ptr<Phase>> createPhases(
83  boost::optional<BaseLib::ConfigTree> const& config)
84 {
85  if (!config)
86  {
87  return {};
88  }
89 
90  std::vector<std::unique_ptr<Phase>> phases;
91 
92  std::set<std::string> phase_names;
93 
95  for (auto phase_config : config->getConfigSubtreeList("phase"))
96  {
97  auto phase = createPhase(phase_config);
98  bool new_insertion = false;
99  std::tie(std::ignore, new_insertion) =
100  phase_names.insert(phase->name());
101 
102  if (!new_insertion)
103  {
104  OGS_FATAL("Found duplicates with the same phase name tag '%s'.",
105  phase->name().c_str());
106  }
107 
108  phases.push_back(std::move(phase));
109  }
110  return phases;
111 }
112 } // namespace MaterialPropertyLib
std::unique_ptr< PropertyArray > createProperties(boost::optional< BaseLib::ConfigTree > const &config)
std::vector< std::unique_ptr< Component > > createComponents(boost::optional< BaseLib::ConfigTree > const &config)
std::vector< std::unique_ptr< Phase > > createPhases(boost::optional< BaseLib::ConfigTree > const &config)
Definition: CreatePhase.cpp:82
std::unique_ptr< MaterialPropertyLib::Phase > createPhase(BaseLib::ConfigTree const &config)
Definition: CreatePhase.cpp:27
T getConfigParameter(std::string const &param) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:156