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