Skip to content

Commit acdb223

Browse files
authored
Merge pull request #6888 from lhy11009/prescribed_solution_initial_temperature
Prescribed solution initial temperature
2 parents 6aaafd0 + c3e58ca commit acdb223

File tree

7 files changed

+504
-2
lines changed

7 files changed

+504
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Added: a new instance of 'initial temperature' in the prescribed solution plugin system.
2+
<br>
3+
(Haoyuan Li, 2025/12/30)

doc/sphinx/parameters/Material_20model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Viscous stress may also be limited by a non-linear stress limiter that has a for
200200

201201
The value for the components of this formula and additional parameters are read from the parameter file in subsection &rsquo;Material model/Visco Plastic&rsquo;.
202202

203-
&lsquo;viscoelastic&rsquo;: An implementation of a simple linear viscoelastic rheology that only includes the deviatoric components of elasticity. Specifically, the viscoelastic rheology only takes into account the elastic shear strength (e.g., shear modulus), while the tensile and volumetric strength (e.g., Young&rsquo;s and bulk modulus) are not considered. The model is incompressible and allows specifying an arbitrary number of compositional fields, where each field represents a different rock type or component of the viscoelastic stress tensor. The stress tensor in 2d and 3d, respectively, contains 3 or 6 components. The compositional fields representing these components must be named and listed in a very specific format, which is designed to minimize mislabeling stress tensor components as distinct &rsquo;compositional rock types&rsquo; (or vice versa). For 2d models, the first six compositional fields must be labeled &rsquo;stress\_xx&rsquo;, &rsquo;stress\_yy&rsquo; and &rsquo;stress\_xy&rsquo;, &rsquo;stress\_xx\_old&rsquo;, &rsquo;stress\_yy\_old&rsquo; and &rsquo;stress\_xy\_old&rsquo;, In 3d, the first twelve compositional fields must be labeled &rsquo;stress\_xx&rsquo;, &rsquo;stress\_yy&rsquo;, &rsquo;stress\_zz&rsquo;, &rsquo;stress\_xy&rsquo;, &rsquo;stress\_xz&rsquo;, &rsquo;stress\_yz&rsquo;, &rsquo;stress\_xx\_old&rsquo;, &rsquo;stress\_yy\_old&rsquo;, &rsquo;stress\_zz\_old&rsquo;, &rsquo;stress\_xy\_old&rsquo;, &rsquo;stress\_xz\_old&rsquo;, &rsquo;stress\_yz\_old&rsquo;.
203+
&lsquo;viscoelastic&rsquo;: An implementation of a simple linear viscoelastic rheology that only includes the deviatoric components of elasticity. Specifically, the viscoelastic rheology only takes into account the elastic shear strength (e.g., shear modulus), while the tensile and volumetric strength (e.g., Young&rsquo;s and bulk modulus) are not considered. The model is incompressible and allows specifying an arbitrary number of compositional fields, where each field represents a different rock type or component of the viscoelastic stress tensor. The stress tensor in 2d and 3d, respectively, contains 3 or 6 components. The compositional fields representing these components must be named and listed in a very specific format, which is designed to minimize mislabeling stress tensor components as distinct &rsquo;compositional rock types&rsquo; (or vice versa). For 2d models, the first six compositional fields of type stress must be labeled &rsquo;ve\_stress\_xx&rsquo;, &rsquo;ve\_stress\_yy&rsquo; and &rsquo;ve\_stress\_xy&rsquo;, &rsquo;ve\_stress\_xx\_old&rsquo;, &rsquo;ve\_stress\_yy\_old&rsquo; and &rsquo;ve\_stress\_xy\_old&rsquo;, In 3d, the first twelve compositional fields of type stress must be labeled &rsquo;ve\_stress\_xx&rsquo;, &rsquo;ve\_stress\_yy&rsquo;, &rsquo;ve\_stress\_zz&rsquo;, &rsquo;ve\_stress\_xy&rsquo;, &rsquo;ve\_stress\_xz&rsquo;, &rsquo;ve\_stress\_yz&rsquo;, &rsquo;ve\_stress\_xx\_old&rsquo;, &rsquo;ve\_stress\_yy\_old&rsquo;, &rsquo;ve\_stress\_zz\_old&rsquo;, &rsquo;ve\_stress\_xy\_old&rsquo;, &rsquo;ve\_stress\_xz\_old&rsquo;, &rsquo;ve\_stress\_yz\_old&rsquo;.
204204

205205
Expanding the model to include non-linear viscous flow (e.g., diffusion/dislocation creep) and plasticity would produce a constitutive relationship commonly referred to as partial elastoviscoplastic (e.g., pEVP) in the geodynamics community. While extensively discussed and applied within the geodynamics literature, notable references include: Moresi et al. (2003), J. Comp. Phys., v. 184, p. 476-497. Gerya and Yuen (2007), Phys. Earth. Planet. Inter., v. 163, p. 83-105. Gerya (2010), Introduction to Numerical Geodynamic Modeling. Kaus (2010), Tectonophysics, v. 484, p. 36-47. Choi et al. (2013), J. Geophys. Res., v. 118, p. 2429-2444. Keller et al. (2013), Geophys. J. Int., v. 195, p. 1406-1442.
206206

doc/sphinx/parameters/Prescribed_20solution.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,63 @@
99
:name: parameters:Prescribed_20solution/List_20of_20model_20names
1010
**Default value:**
1111

12-
**Pattern:** [MultipleSelection temperature function|velocity function ]
12+
**Pattern:** [MultipleSelection initial temperature|temperature function|velocity function ]
1313

1414
**Documentation:** A comma-separated list of prescribed solution models that will be used to compute the solution in certain regions. These plugins are loaded in the order given, and are combined via the operators listed in &rsquo;List of model operators&rsquo;.
1515

1616
The following prescribed solution models are available:
1717

18+
&lsquo;initial temperature&rsquo;: Prescribe the temperature in a selected region using the active initial temperature model. The selected region is defined through an indicator function. At locations where the indicator value is greater than 0.5, the temperature is constrained to the initial temperature evaluated at that position.
19+
1820
&lsquo;temperature function&rsquo;: Prescribe the temperature in terms of an explicit formula. The format of these functions follows the syntax understood by the muparser library.
1921

2022
&lsquo;velocity function&rsquo;: Prescribe the velocity in terms of an explicit formula. The format of these functions follows the syntax understood by the muparser library, see {ref}`sec:run-aspect:parameters-overview:muparser-format`.
2123
::::
2224

25+
(parameters:Prescribed_20solution/Initial_20temperature)=
26+
## **Subsection:** Prescribed solution / Initial temperature
27+
::::{dropdown} __Parameter:__ {ref}`Coordinate system<parameters:Prescribed_20solution/Initial_20temperature/Coordinate_20system>`
28+
:name: parameters:Prescribed_20solution/Initial_20temperature/Coordinate_20system
29+
**Default value:** cartesian
30+
31+
**Pattern:** [Selection cartesian|spherical|depth ]
32+
33+
**Documentation:** A selection that determines the assumed coordinate system for the indicator function variables. Allowed values are &lsquo;cartesian&rsquo;, &lsquo;spherical&rsquo;, and &lsquo;depth&rsquo;.
34+
::::
35+
36+
(parameters:Prescribed_20solution/Initial_20temperature/Indicator_20function)=
37+
## **Subsection:** Prescribed solution / Initial temperature / Indicator function
38+
::::{dropdown} __Parameter:__ {ref}`Function constants<parameters:Prescribed_20solution/Initial_20temperature/Indicator_20function/Function_20constants>`
39+
:name: parameters:Prescribed_20solution/Initial_20temperature/Indicator_20function/Function_20constants
40+
**Default value:**
41+
42+
**Pattern:** [Anything]
43+
44+
**Documentation:** Sometimes it is convenient to use symbolic constants in the expression that describes the function, rather than having to use its numeric value everywhere the constant appears. These values can be defined using this parameter, in the form &lsquo;var1=value1, var2=value2, ...&rsquo;.
45+
46+
A typical example would be to set this runtime parameter to &lsquo;pi=3.1415926536&rsquo; and then use &lsquo;pi&rsquo; in the expression of the actual formula. (That said, for convenience this class actually defines both &lsquo;pi&rsquo; and &lsquo;Pi&rsquo; by default, but you get the idea.)
47+
::::
48+
49+
::::{dropdown} __Parameter:__ {ref}`Function expression<parameters:Prescribed_20solution/Initial_20temperature/Indicator_20function/Function_20expression>`
50+
:name: parameters:Prescribed_20solution/Initial_20temperature/Indicator_20function/Function_20expression
51+
**Default value:** 0
52+
53+
**Pattern:** [Anything]
54+
55+
**Documentation:** The formula that denotes the function you want to evaluate for particular values of the independent variables. This expression may contain any of the usual operations such as addition or multiplication, as well as all of the common functions such as &lsquo;sin&rsquo; or &lsquo;cos&rsquo;. In addition, it may contain expressions like &lsquo;if(x>0, 1, -1)&rsquo; where the expression evaluates to the second argument if the first argument is true, and to the third argument otherwise. For a full overview of possible expressions accepted see the documentation of the muparser library at http://muparser.beltoforion.de/.
56+
57+
If the function you are describing represents a vector-valued function with multiple components, then separate the expressions for individual components by a semicolon.
58+
::::
59+
60+
::::{dropdown} __Parameter:__ {ref}`Variable names<parameters:Prescribed_20solution/Initial_20temperature/Indicator_20function/Variable_20names>`
61+
:name: parameters:Prescribed_20solution/Initial_20temperature/Indicator_20function/Variable_20names
62+
**Default value:** x,y,t
63+
64+
**Pattern:** [Anything]
65+
66+
**Documentation:** The names of the variables as they will be used in the function, separated by commas. By default, the names of variables at which the function will be evaluated are &lsquo;x&rsquo; (in 1d), &lsquo;x,y&rsquo; (in 2d) or &lsquo;x,y,z&rsquo; (in 3d) for spatial coordinates and &lsquo;t&rsquo; for time. You can then use these variable names in your function expression and they will be replaced by the values of these variables at which the function is currently evaluated. However, you can also choose a different set of names for the independent variables at which to evaluate your function expression. For example, if you work in spherical coordinates, you may wish to set this input parameter to &lsquo;r,phi,theta,t&rsquo; and then use these variable names in your function expression.
67+
::::
68+
2369
(parameters:Prescribed_20solution/Temperature_20function)=
2470
## **Subsection:** Prescribed solution / Temperature function
2571
::::{dropdown} __Parameter:__ {ref}`Coordinate system<parameters:Prescribed_20solution/Temperature_20function/Coordinate_20system>`
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Copyright (C) 2011 - 2026 by the authors of the ASPECT code.
3+
4+
This file is part of ASPECT.
5+
6+
ASPECT is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation; either version 2, or (at your option)
9+
any later version.
10+
11+
ASPECT is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with ASPECT; see the file LICENSE. If not see
18+
<http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#ifndef _aspect_prescribed_solution_initial_temperature_h
22+
#define _aspect_prescribed_solution_initial_temperature_h
23+
24+
#include <aspect/initial_temperature/interface.h>
25+
#include <aspect/prescribed_solution/interface.h>
26+
#include <aspect/simulator_access.h>
27+
#include <deal.II/base/parsed_function.h>
28+
29+
namespace aspect
30+
{
31+
namespace PrescribedSolution
32+
{
33+
/**
34+
* A class that prescribes temperature in a selected region using
35+
* the value returned by the active initial temperature model.
36+
*
37+
* The region is selected through an indicator function. Where the
38+
* indicator is greater than 0.5, the temperature is constrained
39+
* to the initial temperature value evaluated at that position.
40+
*
41+
* @ingroup PrescribedSolution
42+
*/
43+
template <int dim>
44+
class InitialTemperature
45+
: public Interface<dim>,
46+
public SimulatorAccess<dim>
47+
{
48+
public:
49+
/**
50+
* Constructor.
51+
*/
52+
InitialTemperature ();
53+
54+
/**
55+
* Store a shared pointer to the initial temperature manager so the
56+
* plugin can safely access it after initialization.
57+
*/
58+
void initialize () override;
59+
60+
/**
61+
* Update the current time in the indicator function.
62+
*/
63+
void update () override;
64+
65+
/**
66+
* Declare the parameters this class takes through input files.
67+
*/
68+
static void declare_parameters (ParameterHandler &prm);
69+
70+
/**
71+
* Read the parameters this class declares from the parameter file.
72+
*/
73+
void parse_parameters (ParameterHandler &prm) override;
74+
75+
/**
76+
* Decide and assign cell-wise constraints for temperature DoFs.
77+
*/
78+
void constrain_solution (
79+
const typename DoFHandler<dim>::active_cell_iterator &cell,
80+
const std::vector<Point<dim>> &positions,
81+
const std::vector<unsigned int> &component_indices,
82+
std::vector<bool> &should_be_constrained,
83+
std::vector<double> &solution) override;
84+
85+
private:
86+
/**
87+
* Indicator function for selecting where the temperature should
88+
* be prescribed.
89+
*/
90+
Functions::ParsedFunction<dim> prescribed_temperature_indicator_function;
91+
92+
/**
93+
* The coordinate representation used to evaluate the indicator
94+
* function. Possible choices are cartesian, spherical, and depth.
95+
*/
96+
Utilities::Coordinates::CoordinateSystem coordinate_system;
97+
98+
/**
99+
* Shared pointer to the initial temperature manager. We keep this
100+
* alive because the simulator may release its own pointer after
101+
* initialization.
102+
*/
103+
std::shared_ptr<const aspect::InitialTemperature::Manager<dim>> initial_temperature_manager;
104+
};
105+
}
106+
}
107+
108+
#endif
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
Copyright (C) 2011 - 2026 by the authors of the ASPECT code.
3+
4+
This file is part of ASPECT.
5+
6+
ASPECT is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation; either version 2, or (at your option)
9+
any later version.
10+
11+
ASPECT is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with ASPECT; see the file LICENSE. If not see
18+
<http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include <aspect/initial_temperature/interface.h>
22+
#include <aspect/prescribed_solution/initial_temperature.h>
23+
#include <aspect/geometry_model/interface.h>
24+
25+
namespace aspect
26+
{
27+
namespace PrescribedSolution
28+
{
29+
template <int dim>
30+
InitialTemperature<dim>::InitialTemperature ()
31+
:
32+
prescribed_temperature_indicator_function(1)
33+
{}
34+
35+
36+
37+
template <int dim>
38+
void
39+
InitialTemperature<dim>::initialize ()
40+
{
41+
initial_temperature_manager =
42+
this->get_initial_temperature_manager_pointer();
43+
}
44+
45+
46+
47+
template <int dim>
48+
void
49+
InitialTemperature<dim>::update ()
50+
{
51+
if (this->convert_output_to_years())
52+
prescribed_temperature_indicator_function.set_time(this->get_time() / year_in_seconds);
53+
else
54+
prescribed_temperature_indicator_function.set_time(this->get_time());
55+
}
56+
57+
58+
59+
template <int dim>
60+
void
61+
InitialTemperature<dim>::constrain_solution (const typename DoFHandler<dim>::active_cell_iterator &/*cell*/,
62+
const std::vector<Point<dim>> &positions,
63+
const std::vector<unsigned int> &component_indices,
64+
std::vector<bool> &should_be_constrained,
65+
std::vector<double> &solution)
66+
{
67+
68+
const unsigned int temperature_index =
69+
this->introspection().component_indices.temperature;
70+
71+
for (unsigned int q=0; q<positions.size(); ++q)
72+
{
73+
if (component_indices[q] != temperature_index)
74+
continue;
75+
76+
const auto point =
77+
this->get_geometry_model().cartesian_to_other_coordinates(positions[q], coordinate_system);
78+
79+
const double indicator =
80+
prescribed_temperature_indicator_function.value(Utilities::convert_array_to_point<dim>(point.get_coordinates()), 0);
81+
82+
if (indicator > 0.5)
83+
{
84+
should_be_constrained[q] = true;
85+
solution[q] = initial_temperature_manager->initial_temperature(positions[q]);
86+
}
87+
}
88+
}
89+
90+
91+
92+
template <int dim>
93+
void
94+
InitialTemperature<dim>::declare_parameters (ParameterHandler &prm)
95+
{
96+
prm.enter_subsection("Prescribed solution");
97+
{
98+
prm.enter_subsection("Initial temperature");
99+
{
100+
prm.declare_entry("Coordinate system",
101+
"cartesian",
102+
Patterns::Selection("cartesian|spherical|depth"),
103+
"A selection that determines the assumed coordinate "
104+
"system for the indicator function variables. "
105+
"Allowed values are `cartesian', `spherical', and `depth'.");
106+
107+
prm.enter_subsection("Indicator function");
108+
{
109+
Functions::ParsedFunction<dim>::declare_parameters(prm, 1);
110+
}
111+
prm.leave_subsection();
112+
}
113+
prm.leave_subsection();
114+
}
115+
prm.leave_subsection();
116+
}
117+
118+
119+
120+
template <int dim>
121+
void
122+
InitialTemperature<dim>::parse_parameters (ParameterHandler &prm)
123+
{
124+
prm.enter_subsection("Prescribed solution");
125+
{
126+
prm.enter_subsection("Initial temperature");
127+
{
128+
coordinate_system =
129+
Utilities::Coordinates::string_to_coordinate_system(prm.get("Coordinate system"));
130+
131+
prm.enter_subsection("Indicator function");
132+
{
133+
try
134+
{
135+
prescribed_temperature_indicator_function.parse_parameters(prm);
136+
}
137+
catch (...)
138+
{
139+
std::cerr << "ERROR: FunctionParser failed to parse\n"
140+
<< "\t'Prescribed solution.Initial temperature.Indicator function'\n"
141+
<< "with expression\n"
142+
<< "\t'" << prm.get("Function expression") << "'\n";
143+
throw;
144+
}
145+
}
146+
prm.leave_subsection();
147+
}
148+
prm.leave_subsection();
149+
}
150+
prm.leave_subsection();
151+
}
152+
}
153+
}
154+
155+
156+
157+
// explicit instantiations
158+
namespace aspect
159+
{
160+
namespace PrescribedSolution
161+
{
162+
ASPECT_REGISTER_PRESCRIBED_SOLUTION(InitialTemperature,
163+
"initial temperature",
164+
"Prescribe the temperature in a selected region using the active "
165+
"initial temperature model. The selected region is defined through "
166+
"an indicator function. At locations where the indicator value is greater than 0.5, "
167+
"the temperature is constrained to the initial temperature evaluated "
168+
"at that position.")
169+
}
170+
}

0 commit comments

Comments
 (0)