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_string = config.getConfigParameter<std::string>("type");
31
32 if (phase_type_string.empty())
33 {
34 OGS_FATAL("Phase type is a mandatory field and cannot be empty.");
35 }
36
41 auto const phase_type = fromString(phase_type_string);
42
43 // Parsing of optional components.
44 auto components = createComponents(
45 geometry_dimension,
47 config.getConfigSubtreeOptional("components"), parameters,
48 local_coordinate_system, curves);
49
50 // Properties of optional properties.
51 auto properties = createProperties(
52 geometry_dimension,
54 config.getConfigSubtreeOptional("properties"), parameters,
55 local_coordinate_system, curves);
56
57 if (components.empty() && !properties)
58 {
60 "Neither tag <components> nor tag <properties> has been set for "
61 "the phase '{:s}'.",
62 toString(phase_type));
63 }
64
65 return std::make_unique<Phase>(phase_type, std::move(components),
66 std::move(properties));
67}
68} // namespace
69
70namespace MaterialPropertyLib
71{
72std::vector<std::unique_ptr<Phase>> createPhases(
73 int const geometry_dimension,
74 std::optional<BaseLib::ConfigTree> const& config,
75 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
76 ParameterLib::CoordinateSystem const* const local_coordinate_system,
77 std::map<std::string,
78 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
79 curves)
80{
81 if (!config)
82 {
83 return {};
84 }
85
86 std::vector<std::unique_ptr<Phase>> phases;
87
88 for (auto phase_config :
90 config->getConfigSubtreeList("phase"))
91 {
92 auto phase = createPhase(geometry_dimension, phase_config, parameters,
93 local_coordinate_system, curves);
94
95 if (std::find_if(phases.begin(),
96 phases.end(),
97 [phase_type = phase->phaseName](auto const& p)
98 { return p->phaseName == phase_type; }) !=
99 phases.end())
100 {
101 OGS_FATAL("Found duplicates with the same phase name tag '{:s}'.",
102 toString(phase->phaseName));
103 }
104
105 phases.push_back(std::move(phase));
106 }
107
108 return phases;
109}
110} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:19
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)
PhaseName fromString(std::string const &phase_name)
Convert string to phase enum. Throws if invalid phase name.
Definition Phase.cpp:29
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::string_view toString(PhaseName phase_name)
Convert phase enum to its string representation.
Definition Phase.cpp:13
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.