OGS
CreateSaturationWeightedThermalConductivity.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
5
6#include <boost/mp11.hpp>
7#include <string>
8
9#include "BaseLib/Algorithm.h"
10#include "BaseLib/ConfigTree.h"
13#include "ParameterLib/Utils.h"
15
16namespace
17{
18template <MaterialPropertyLib::MeanType MeanType, int Dim>
19std::unique_ptr<MaterialPropertyLib::Property>
21 std::string name,
22 ParameterLib::Parameter<double> const& dry_thermal_conductivity,
23 ParameterLib::Parameter<double> const& wet_thermal_conductivity)
24{
25 return std::make_unique<
27 Dim>>(
28 std::move(name), dry_thermal_conductivity, wet_thermal_conductivity);
29}
30} // namespace
31
32namespace MaterialPropertyLib
33{
35 int const geometry_dimension,
36 BaseLib::ConfigTree const& config,
37 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters)
38{
40 config.checkConfigParameter("type",
41 "SaturationWeightedThermalConductivity");
42
44 auto property_name = config.peekConfigParameter<std::string>("name");
45
46 DBUG("Create SaturationWeightedThermalConductivity medium property");
47
48 std::string const& dry_thermal_conductivity_parameter_or_value =
50 config.getConfigParameter<std::string>("dry_thermal_conductivity");
51
52 std::string const& wet_thermal_conductivity_parameter_or_value =
54 config.getConfigParameter<std::string>("wet_thermal_conductivity");
55
56 auto& dry_thermal_conductivity =
59 dry_thermal_conductivity_parameter_or_value, parameters,
60 property_name, "dry_inline");
61
62 auto& wet_thermal_conductivity =
65 wet_thermal_conductivity_parameter_or_value, parameters,
66 property_name, "wet_inline");
67
68 std::string const& mean_type_str =
70 config.getConfigParameter<std::string>("mean_type");
71
72 const std::map<std::string, MeanType> mean_type_map{
73 {"arithmetic_linear", MeanType::ARITHMETIC_LINEAR},
74 {"arithmetic_squareroot", MeanType::ARITHMETIC_SQUAREROOT},
75 {"geometric", MeanType::GEOMETRIC}};
76 MeanType const& mean_type = BaseLib::getOrError(
77 mean_type_map, mean_type_str,
78 "Specified mean type for the thermal conductivity could not be found.");
79
80 std::map<
81 std::pair<MeanType, int>,
82 std::unique_ptr<Property> (*)(
83 std::string /*name*/,
84 ParameterLib::Parameter<double> const& /*dry_thermal_conductivity*/,
86 double> const& /*wet_thermal_conductivity*/)>
87 map_dim_and_mean_to_creator;
88
89 // initialize the map
90 {
91 using namespace boost::mp11;
92 using Dims = mp_list<mp_int<1>, mp_int<2>, mp_int<3>>;
93 using Means = mp_list<
94 std::integral_constant<MeanType, MeanType::ARITHMETIC_LINEAR>,
95 std::integral_constant<MeanType, MeanType::ARITHMETIC_SQUAREROOT>,
96 std::integral_constant<MeanType, MeanType::GEOMETRIC>>;
97 using DimsAndMeanTypes =
98 mp_product<mp_list, Dims,
99 Means>; // Cartesian product of Dims and Means.
100
101 mp_for_each<DimsAndMeanTypes>(
102 [&map_dim_and_mean_to_creator]<typename Dim, typename Mean>(
103 mp_list<Dim, Mean>)
104 {
105 map_dim_and_mean_to_creator.emplace(
106 std::pair{Mean::value, Dim::value},
108 Dim::value>);
109 });
110 }
111
112 auto const it = map_dim_and_mean_to_creator.find(
113 std::pair{mean_type, geometry_dimension});
114
115 if (it == map_dim_and_mean_to_creator.end())
116 {
117 OGS_FATAL(
118 "Cannot create a SaturationWeightedThermalConductivity model for "
119 "dimension {} and mean type {}",
120 geometry_dimension, mean_type_str);
121 }
122
123 auto* creator = it->second;
124 return creator(std::move(property_name),
125 dry_thermal_conductivity,
126 wet_thermal_conductivity);
127}
128} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
T peekConfigParameter(std::string const &param) const
T getConfigParameter(std::string const &param) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
Saturation dependent thermal conductivity model for soil.
OGS_NO_DANGLING Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
Definition Algorithm.h:111
std::unique_ptr< Property > createSaturationWeightedThermalConductivity(int const geometry_dimension, BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters)
Parameter< double > & getNamedOrCreateInlineParameter(std::string const &parameter_or_value, std::vector< std::unique_ptr< ParameterBase > > &parameters, std::string const &property_name, std::string const &inline_suffix)
std::unique_ptr< MaterialPropertyLib::Property > createSaturationWeightedThermalConductivity(std::string name, ParameterLib::Parameter< double > const &dry_thermal_conductivity, ParameterLib::Parameter< double > const &wet_thermal_conductivity)