OGS
CreatePhase.cpp
Go to the documentation of this file.
1
13#include "CreatePhase.h"
14
15#include <set>
16#include <string>
17
18#include "BaseLib/ConfigTree.h"
19#include "CreateComponent.h"
20#include "CreateProperty.h"
23#include "Phase.h"
24
25namespace
26{
27std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
28 int const geometry_dimension,
29 BaseLib::ConfigTree const& config,
30 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
31 ParameterLib::CoordinateSystem const* const local_coordinate_system,
32 std::map<std::string,
33 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
34 curves)
35{
36 using namespace MaterialPropertyLib;
37
39 auto&& phase_type = config.getConfigParameter<std::string>("type");
40
41 if (phase_type.empty())
42 {
43 OGS_FATAL("Phase type is a mandatory field and cannot be empty.");
44 }
45
46 std::array<std::string, 5> const allowed_phase_types = {
47 {"Solid", "FrozenLiquid", "AqueousLiquid", "NonAqueousLiquid", "Gas"}};
48
49 if (std::none_of(allowed_phase_types.begin(),
50 allowed_phase_types.end(),
51 [&phase_type](std::string const& type)
52 { return phase_type == type; }))
53 {
54 ERR("Phase type should be one of:");
55 for (auto const& type : allowed_phase_types)
56 {
57 ERR("{:s}", type);
58 }
59 OGS_FATAL("Wrong phase type '{:s}' given.", phase_type);
60 }
61
62 // Parsing of optional components.
63 auto components = createComponents(
64 geometry_dimension,
66 config.getConfigSubtreeOptional("components"), parameters,
67 local_coordinate_system, curves);
68
69 // Properties of optional properties.
70 auto properties = createProperties(
71 geometry_dimension,
73 config.getConfigSubtreeOptional("properties"), parameters,
74 local_coordinate_system, curves);
75
76 if (components.empty() && !properties)
77 {
79 "Neither tag <components> nor tag <properties> has been set for "
80 "the phase '{:s}'.",
81 phase_type);
82 }
83
84 return std::make_unique<Phase>(std::move(phase_type), std::move(components),
85 std::move(properties));
86}
87} // namespace
88
89namespace MaterialPropertyLib
90{
91std::vector<std::unique_ptr<Phase>> createPhases(
92 int const geometry_dimension,
93 std::optional<BaseLib::ConfigTree> const& config,
94 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
95 ParameterLib::CoordinateSystem const* const local_coordinate_system,
96 std::map<std::string,
97 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
98 curves)
99{
100 if (!config)
101 {
102 return {};
103 }
104
105 std::vector<std::unique_ptr<Phase>> phases;
106
107 for (auto phase_config :
109 config->getConfigSubtreeList("phase"))
110 {
111 auto phase = createPhase(geometry_dimension, phase_config, parameters,
112 local_coordinate_system, curves);
113
114 if (std::find_if(phases.begin(),
115 phases.end(),
116 [phase_name = phase->name](auto const& p)
117 { return p->name == phase_name; }) != phases.end())
118 {
119 OGS_FATAL("Found duplicates with the same phase name tag '{:s}'.",
120 phase->name);
121 }
122
123 phases.push_back(std::move(phase));
124 }
125
126 return phases;
127}
128} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Definition of the PiecewiseLinearInterpolation class.
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
T getConfigParameter(std::string const &param) const
std::vector< std::unique_ptr< Phase > > createPhases(int const geometry_dimension, std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, ParameterLib::CoordinateSystem const *const local_coordinate_system, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
std::unique_ptr< MaterialPropertyLib::Phase > createPhase(int const geometry_dimension, BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, ParameterLib::CoordinateSystem const *const local_coordinate_system, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
A local coordinate system used for tensor transformations.