Skip to content

Commit ec34707

Browse files
committed
Prescribed condition from initial composition
1 parent acdb223 commit ec34707

File tree

6 files changed

+521
-1
lines changed

6 files changed

+521
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Added: a new instance of 'initial composition' in the prescribed solution plugin system.
2+
This plugin prescribes compositional fields from the initial composition model within a
3+
region defined by an indicator function.
4+
<br>
5+
(Haoyuan Li, 2026/03/11)

doc/sphinx/parameters/Prescribed_20solution.md

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

12-
**Pattern:** [MultipleSelection initial temperature|temperature function|velocity function ]
12+
**Pattern:** [MultipleSelection initial composition|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 composition&rsquo;: Prescribe compositional fields from the initial composition model within a region defined by an indicator function.
19+
1820
&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.
1921

2022
&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.
2123

2224
&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`.
2325
::::
2426

27+
(parameters:Prescribed_20solution/Initial_20composition)=
28+
## **Subsection:** Prescribed solution / Initial composition
29+
::::{dropdown} __Parameter:__ {ref}`Coordinate system<parameters:Prescribed_20solution/Initial_20composition/Coordinate_20system>`
30+
:name: parameters:Prescribed_20solution/Initial_20composition/Coordinate_20system
31+
**Default value:** cartesian
32+
33+
**Pattern:** [Selection cartesian|spherical|depth ]
34+
35+
**Documentation:** Coordinate system used for evaluating the indicator function.
36+
::::
37+
38+
(parameters:Prescribed_20solution/Initial_20composition/Indicator_20function)=
39+
## **Subsection:** Prescribed solution / Initial composition / Indicator function
40+
::::{dropdown} __Parameter:__ {ref}`Function constants<parameters:Prescribed_20solution/Initial_20composition/Indicator_20function/Function_20constants>`
41+
:name: parameters:Prescribed_20solution/Initial_20composition/Indicator_20function/Function_20constants
42+
**Default value:**
43+
44+
**Pattern:** [Anything]
45+
46+
**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;.
47+
48+
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.)
49+
::::
50+
51+
::::{dropdown} __Parameter:__ {ref}`Function expression<parameters:Prescribed_20solution/Initial_20composition/Indicator_20function/Function_20expression>`
52+
:name: parameters:Prescribed_20solution/Initial_20composition/Indicator_20function/Function_20expression
53+
**Default value:** 0
54+
55+
**Pattern:** [Anything]
56+
57+
**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/.
58+
59+
If the function you are describing represents a vector-valued function with multiple components, then separate the expressions for individual components by a semicolon.
60+
::::
61+
62+
::::{dropdown} __Parameter:__ {ref}`Variable names<parameters:Prescribed_20solution/Initial_20composition/Indicator_20function/Variable_20names>`
63+
:name: parameters:Prescribed_20solution/Initial_20composition/Indicator_20function/Variable_20names
64+
**Default value:** x,y,t
65+
66+
**Pattern:** [Anything]
67+
68+
**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.
69+
::::
70+
2571
(parameters:Prescribed_20solution/Initial_20temperature)=
2672
## **Subsection:** Prescribed solution / Initial temperature
2773
::::{dropdown} __Parameter:__ {ref}`Coordinate system<parameters:Prescribed_20solution/Initial_20temperature/Coordinate_20system>`
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Copyright (C) 2015 - 2022 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_composition_h
22+
#define _aspect_prescribed_solution_initial_composition_h
23+
24+
#include <aspect/initial_composition/interface.h>
25+
#include <aspect/prescribed_solution/interface.h>
26+
#include <aspect/simulator_access.h>
27+
28+
#include <deal.II/base/parsed_function.h>
29+
30+
namespace aspect
31+
{
32+
namespace PrescribedSolution
33+
{
34+
/**
35+
* Prescribe compositional fields using the initial composition model.
36+
* The region where the constraint applies is determined by an
37+
* indicator function.
38+
*/
39+
template <int dim>
40+
class InitialComposition
41+
: public Interface<dim>,
42+
public SimulatorAccess<dim>
43+
{
44+
public:
45+
46+
InitialComposition ();
47+
48+
/**
49+
* Store shared pointer to initial composition manager.
50+
*/
51+
void initialize () override;
52+
53+
/**
54+
* Update function time.
55+
*/
56+
void update () override;
57+
58+
/**
59+
* Declare parameters.
60+
*/
61+
static void declare_parameters (ParameterHandler &prm);
62+
63+
/**
64+
* Parse parameters.
65+
*/
66+
void parse_parameters (ParameterHandler &prm) override;
67+
68+
/**
69+
* Constrain compositional solution.
70+
*/
71+
void constrain_solution (const typename DoFHandler<dim>::active_cell_iterator &cell,
72+
const std::vector<Point<dim>> &positions,
73+
const std::vector<unsigned int> &component_indices,
74+
std::vector<bool> &should_be_constrained,
75+
std::vector<double> &solution) override;
76+
77+
private:
78+
79+
/**
80+
* Indicator function defining region where composition
81+
* is prescribed.
82+
*/
83+
Functions::ParsedFunction<dim> indicator_function;
84+
85+
/**
86+
* Coordinate system used for evaluating indicator.
87+
*/
88+
Utilities::Coordinates::CoordinateSystem coordinate_system;
89+
90+
/**
91+
* Pointer to initial composition manager.
92+
*/
93+
std::shared_ptr<const aspect::InitialComposition::Manager<dim>> initial_composition_manager;
94+
};
95+
}
96+
}
97+
98+
#endif
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
Copyright (C) 2011 - 2022 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+
22+
#include <aspect/initial_composition/interface.h>
23+
#include <aspect/prescribed_solution/initial_composition.h>
24+
25+
namespace aspect
26+
{
27+
namespace PrescribedSolution
28+
{
29+
30+
template <int dim>
31+
InitialComposition<dim>::InitialComposition ()
32+
:
33+
indicator_function(1)
34+
{}
35+
36+
37+
38+
template <int dim>
39+
void
40+
InitialComposition<dim>::initialize ()
41+
{
42+
initial_composition_manager =
43+
this->get_initial_composition_manager_pointer();
44+
}
45+
46+
47+
48+
template <int dim>
49+
void
50+
InitialComposition<dim>::update ()
51+
{
52+
if (this->convert_output_to_years())
53+
indicator_function.set_time(this->get_time() / year_in_seconds);
54+
else
55+
indicator_function.set_time(this->get_time());
56+
}
57+
58+
59+
60+
template <int dim>
61+
void
62+
InitialComposition<dim>::constrain_solution (const typename DoFHandler<dim>::active_cell_iterator &,
63+
const std::vector<Point<dim>> &positions,
64+
const std::vector<unsigned int> &component_indices,
65+
std::vector<bool> &should_be_constrained,
66+
std::vector<double> &solution)
67+
{
68+
// Determine the component range corresponding to compositional fields.
69+
// These component indices are originally mapped from local DoFs and
70+
// determine which DoFs in the system belong to compositional fields.
71+
const unsigned int first_comp =
72+
this->introspection().component_indices.compositional_fields[0];
73+
74+
const unsigned int last_comp =
75+
this->introspection().component_indices.compositional_fields[this->introspection().n_compositional_fields-1];
76+
77+
const auto &geometry_model = this->get_geometry_model();
78+
79+
for (unsigned int q=0; q<positions.size(); ++q)
80+
{
81+
const unsigned int component = component_indices[q];
82+
83+
if (component < first_comp || component > last_comp)
84+
continue;
85+
86+
const auto point = geometry_model.cartesian_to_other_coordinates(
87+
positions[q], coordinate_system);
88+
89+
const double indicator = indicator_function.value(
90+
Utilities::convert_array_to_point<dim>(point.get_coordinates()));
91+
92+
if (indicator > 0.5)
93+
{
94+
const unsigned int field_index = component - first_comp;
95+
96+
solution[q] =
97+
initial_composition_manager->initial_composition(
98+
positions[q], field_index);
99+
100+
should_be_constrained[q] = true;
101+
}
102+
}
103+
}
104+
105+
106+
107+
template <int dim>
108+
void
109+
InitialComposition<dim>::declare_parameters (ParameterHandler &prm)
110+
{
111+
prm.enter_subsection("Prescribed solution");
112+
{
113+
prm.enter_subsection("Initial composition");
114+
{
115+
116+
prm.declare_entry("Coordinate system",
117+
"cartesian",
118+
Patterns::Selection("cartesian|spherical|depth"),
119+
"Coordinate system used for evaluating the indicator function.");
120+
121+
prm.enter_subsection("Indicator function");
122+
{
123+
Functions::ParsedFunction<dim>::declare_parameters(prm,1);
124+
}
125+
prm.leave_subsection();
126+
127+
}
128+
prm.leave_subsection();
129+
}
130+
prm.leave_subsection();
131+
}
132+
133+
134+
135+
template <int dim>
136+
void
137+
InitialComposition<dim>::parse_parameters (ParameterHandler &prm)
138+
{
139+
prm.enter_subsection("Prescribed solution");
140+
{
141+
prm.enter_subsection("Initial composition");
142+
{
143+
144+
coordinate_system =
145+
Utilities::Coordinates::string_to_coordinate_system(
146+
prm.get("Coordinate system"));
147+
148+
prm.enter_subsection("Indicator function");
149+
{
150+
indicator_function.parse_parameters(prm);
151+
}
152+
prm.leave_subsection();
153+
154+
}
155+
prm.leave_subsection();
156+
}
157+
prm.leave_subsection();
158+
}
159+
}
160+
}
161+
162+
163+
164+
namespace aspect
165+
{
166+
namespace PrescribedSolution
167+
{
168+
169+
ASPECT_REGISTER_PRESCRIBED_SOLUTION(InitialComposition,
170+
"initial composition",
171+
"Prescribe compositional fields from the initial composition model "
172+
"within a region defined by an indicator function.")
173+
174+
}
175+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#########################################################
2+
# This is modified from the composition_passive.prm
3+
# parameter file by prescribing the compositional solution
4+
# from initial compositional fields.
5+
6+
include $ASPECT_SOURCE_DIR/cookbooks/composition_passive/composition_passive.prm
7+
8+
# Modify the original cookbook to end earlier
9+
set Start time = 0
10+
set End time = 1
11+
set Use years instead of seconds = false
12+
13+
# Modify the original cookbook to have coarser meshes
14+
subsection Mesh refinement
15+
set Initial adaptive refinement = 0
16+
set Initial global refinement = 3
17+
set Time steps between mesh refinement = 0
18+
end
19+
20+
# The next section prescribes the composition inside the domain
21+
# using a spatially and temporally varying function. An indicator
22+
# function selects the region where the composition is constrained.
23+
subsection Prescribed solution
24+
set List of model names = initial composition
25+
subsection Initial composition
26+
subsection Indicator function
27+
set Variable names = x, y
28+
set Function expression = (x<1) ? 1:0
29+
end
30+
end
31+
end
32+
33+
subsection Postprocess
34+
set List of postprocessors = visualization
35+
36+
subsection Visualization
37+
set Interpolate output = false
38+
set Time between graphical output = 0.1
39+
set Output format = gnuplot
40+
end
41+
end

0 commit comments

Comments
 (0)