OGS
CreatePhase.cpp
Go to the documentation of this file.
1
12
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>>& 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 {
48 "Solid",
50 "FrozenLiquid",
52 "AqueousLiquid",
54 "Gas"}};
55
56 if (std::none_of(allowed_phase_types.begin(),
57 allowed_phase_types.end(),
58 [&phase_type](std::string const& type)
59 { return phase_type == type; }))
60 {
61 ERR("Phase type should be one of:");
62 for (auto const& type : allowed_phase_types)
63 {
64 ERR("{:s}", type);
65 }
66 OGS_FATAL("Wrong phase type '{:s}' given.", phase_type);
67 }
68
69 // Parsing of optional components.
70 auto components = createComponents(
71 geometry_dimension,
73 config.getConfigSubtreeOptional("components"), parameters,
74 local_coordinate_system, curves);
75
76 // Properties of optional properties.
77 auto properties = createProperties(
78 geometry_dimension,
80 config.getConfigSubtreeOptional("properties"), parameters,
81 local_coordinate_system, curves);
82
83 if (components.empty() && !properties)
84 {
86 "Neither tag <components> nor tag <properties> has been set for "
87 "the phase '{:s}'.",
88 phase_type);
89 }
90
91 return std::make_unique<Phase>(std::move(phase_type), std::move(components),
92 std::move(properties));
93}
94} // namespace
95
96namespace MaterialPropertyLib
97{
98std::vector<std::unique_ptr<Phase>> createPhases(
99 int const geometry_dimension,
100 std::optional<BaseLib::ConfigTree> const& config,
101 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
102 ParameterLib::CoordinateSystem const* const local_coordinate_system,
103 std::map<std::string,
104 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
105 curves)
106{
107 if (!config)
108 {
109 return {};
110 }
111
112 std::vector<std::unique_ptr<Phase>> phases;
113
114 for (auto phase_config :
116 config->getConfigSubtreeList("phase"))
117 {
118 auto phase = createPhase(geometry_dimension, phase_config, parameters,
119 local_coordinate_system, curves);
120
121 if (std::find_if(phases.begin(),
122 phases.end(),
123 [phase_name = phase->name](auto const& p)
124 { return p->name == phase_name; }) != phases.end())
125 {
126 OGS_FATAL("Found duplicates with the same phase name tag '{:s}'.",
127 phase->name);
128 }
129
130 phases.push_back(std::move(phase));
131 }
132
133 return phases;
134}
135} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
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< Component > > createComponents(int const geometry_dimension, std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters, ParameterLib::CoordinateSystem const *const local_coordinate_system, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
std::unique_ptr< PropertyArray > createProperties(int const geometry_dimension, std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters, ParameterLib::CoordinateSystem const *const local_coordinate_system, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
std::vector< std::unique_ptr< Phase > > createPhases(int const geometry_dimension, std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &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 > > &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.