Skip to content

Commit 2ac3b92

Browse files
authored
Merge pull request #6100 from RanpengLi/crash-if-out-of-range
Crash when look up table does not cover the range
2 parents 74fbe92 + 4e01911 commit 2ac3b92

File tree

13 files changed

+174
-168
lines changed

13 files changed

+174
-168
lines changed
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Changed: The entropy reader throws when the range of the provided look-up table
2+
does not fully cover the entropy-pressure range in the model.
3+
<br>
4+
(Ranpeng Li, 2025/01/10)

include/aspect/structured_data.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ namespace aspect
191191
* @param component The index (starting at 0) of the data column to be
192192
* returned. The index is therefore less than the number of data
193193
* columns in the data file (or specified in the constructor).
194+
* @param crash_if_not_in_range If set to true, the function will throw
195+
* when the requested position is outside the range of the coordinates
196+
* provided by the data file.
194197
*/
195198
double
196199
get_data(const Point<dim> &position,
197-
const unsigned int component) const;
200+
const unsigned int component,
201+
const bool crash_if_not_in_range = false) const;
198202

199203
/**
200204
* Returns the gradient of the function based on the bilinear

source/material_model/utilities.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ namespace aspect
837837
EntropyReader::temperature(const double entropy,
838838
const double pressure) const
839839
{
840-
const double temperature = material_lookup->get_data({entropy,pressure}, 0);
840+
const double temperature = material_lookup->get_data({entropy,pressure}, 0, true);
841841
return temperature;
842842
}
843843

source/structured_data.cc

+30-1
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,38 @@ namespace aspect
862862
template <int dim>
863863
double
864864
StructuredDataLookup<dim>::get_data(const Point<dim> &position,
865-
const unsigned int component) const
865+
const unsigned int component,
866+
const bool crash_if_not_in_range) const
866867
{
867868
Assert(component<n_components, ExcMessage("Invalid component index"));
869+
870+
if (crash_if_not_in_range)
871+
{
872+
const std::vector<double> &x_coordinates = get_interpolation_point_coordinates(0);
873+
874+
AssertThrow (position[0] >= x_coordinates[0] && position[0] <= x_coordinates[x_coordinates.size()-1],
875+
ExcMessage("The requested position "
876+
+ std::to_string(position[0])
877+
+ " is outside the range of the data (minimum value = "
878+
+ std::to_string(x_coordinates[0])
879+
+ " , maximum value = "
880+
+ std::to_string(x_coordinates[x_coordinates.size()-1])
881+
+ ")."
882+
));
883+
884+
const std::vector<double> &y_coordinates = get_interpolation_point_coordinates(1);
885+
886+
AssertThrow (position[1] >= y_coordinates[0] && position[1] <= y_coordinates[y_coordinates.size()-1],
887+
ExcMessage("The requested position "
888+
+ std::to_string(position[1])
889+
+ " is outside the range of the data (minimum value = "
890+
+ std::to_string(y_coordinates[0])
891+
+ " , maximum value = "
892+
+ std::to_string(y_coordinates[y_coordinates.size()-1])
893+
+ ")."
894+
));
895+
}
896+
868897
return data[component]->value(position);
869898
}
870899

tests/entropy_initial_lookup.prm

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set Dimension = 2
55
set Use years in output instead of seconds = true
66
set End time = 0
77
set Nonlinear solver scheme = iterated Advection and Stokes
8-
set Surface pressure = 0
8+
set Surface pressure = 25000
99
set Adiabatic surface temperature = 1600.0
1010

1111
subsection Formulation

tests/entropy_initial_lookup/screen-output

+18-18
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,56 @@ Number of degrees of freedom: 3,217 (1,206+202+603+603+603)
1010
Solving entropy system ... 3 iterations.
1111
Copying properties into prescribed compositional field density_field... done.
1212
Solving Stokes system (GMG)... 1000+3 iterations.
13-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 0.000495634, 4.77467e-10, 0, 5.9652
14-
Relative nonlinear residual (total system) after nonlinear iteration 1: 5.9652
13+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 0.000495626, 4.77402e-10, 0, 5.96521
14+
Relative nonlinear residual (total system) after nonlinear iteration 1: 5.96521
1515

1616
Copying properties into prescribed temperature field... done.
1717
Solving temperature system... 3 iterations.
1818
Solving entropy system ... 3 iterations.
1919
Copying properties into prescribed compositional field density_field... done.
20-
Solving Stokes system (GMG)... 600+0 iterations.
21-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 8.51534e-10, 5.64728e-10, 0, 0.0685014
22-
Relative nonlinear residual (total system) after nonlinear iteration 2: 0.0685014
20+
Solving Stokes system (GMG)... 676+0 iterations.
21+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 8.51395e-10, 5.64621e-10, 0, 0.0685012
22+
Relative nonlinear residual (total system) after nonlinear iteration 2: 0.0685012
2323

2424
Copying properties into prescribed temperature field... done.
2525
Solving temperature system... 3 iterations.
2626
Solving entropy system ... 3 iterations.
2727
Copying properties into prescribed compositional field density_field... done.
28-
Solving Stokes system (GMG)... 500+0 iterations.
29-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.01722e-09, 4.2244e-10, 0, 0.0168383
30-
Relative nonlinear residual (total system) after nonlinear iteration 3: 0.0168383
28+
Solving Stokes system (GMG)... 550+0 iterations.
29+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.01699e-09, 4.22363e-10, 0, 0.0168382
30+
Relative nonlinear residual (total system) after nonlinear iteration 3: 0.0168382
3131

3232
Copying properties into prescribed temperature field... done.
3333
Solving temperature system... 3 iterations.
3434
Solving entropy system ... 3 iterations.
3535
Copying properties into prescribed compositional field density_field... done.
36-
Solving Stokes system (GMG)... 286+0 iterations.
37-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 7.51013e-10, 3.95146e-10, 0, 0.00246445
36+
Solving Stokes system (GMG)... 245+0 iterations.
37+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 7.509e-10, 3.95043e-10, 0, 0.00246445
3838
Relative nonlinear residual (total system) after nonlinear iteration 4: 0.00246445
3939

4040
Copying properties into prescribed temperature field... done.
4141
Solving temperature system... 3 iterations.
4242
Solving entropy system ... 2 iterations.
4343
Copying properties into prescribed compositional field density_field... done.
44-
Solving Stokes system (GMG)... 194+0 iterations.
45-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 7.21895e-10, 4.19474e-10, 0, 0.000253486
46-
Relative nonlinear residual (total system) after nonlinear iteration 5: 0.000253486
44+
Solving Stokes system (GMG)... 190+0 iterations.
45+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 7.21723e-10, 4.19413e-10, 0, 0.00025346
46+
Relative nonlinear residual (total system) after nonlinear iteration 5: 0.00025346
4747

4848
Copying properties into prescribed temperature field... done.
4949
Solving temperature system... 3 iterations.
5050
Solving entropy system ... 3 iterations.
5151
Copying properties into prescribed compositional field density_field... done.
5252
Solving Stokes system (GMG)... 76+0 iterations.
53-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 7.79118e-10, 3.18101e-10, 0, 2.03324e-05
54-
Relative nonlinear residual (total system) after nonlinear iteration 6: 2.03324e-05
53+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 7.79017e-10, 3.17962e-10, 0, 2.03204e-05
54+
Relative nonlinear residual (total system) after nonlinear iteration 6: 2.03204e-05
5555

5656
Copying properties into prescribed temperature field... done.
5757
Solving temperature system... 3 iterations.
5858
Solving entropy system ... 3 iterations.
5959
Copying properties into prescribed compositional field density_field... done.
60-
Solving Stokes system (GMG)... 55+0 iterations.
61-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 5.78613e-10, 3.56974e-10, 0, 1.35817e-06
62-
Relative nonlinear residual (total system) after nonlinear iteration 7: 1.35817e-06
60+
Solving Stokes system (GMG)... 56+0 iterations.
61+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 5.78371e-10, 3.56725e-10, 0, 1.35606e-06
62+
Relative nonlinear residual (total system) after nonlinear iteration 7: 1.35606e-06
6363

6464

6565
Postprocessing:
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 1: Time step number
2+
# 2: Time (years)
3+
# 3: Time step size (years)
4+
# 4: Number of mesh cells
5+
# 5: Number of Stokes degrees of freedom
6+
# 6: Number of temperature degrees of freedom
7+
# 7: Number of degrees of freedom for all compositions
8+
# 8: Number of nonlinear iterations
9+
# 9: Iterations for temperature solver
10+
# 10: Iterations for composition solver 1
11+
# 11: Iterations for composition solver 2
12+
# 12: Iterations for Stokes solver
13+
# 13: Velocity iterations in Stokes preconditioner
14+
# 14: Schur complement iterations in Stokes preconditioner
15+
# 15: Visualization file name
16+
# 16: RMS velocity (m/year)
17+
# 17: Max. velocity (m/year)
18+
# 18: Minimal temperature (K)
19+
# 19: Average temperature (K)
20+
# 20: Maximal temperature (K)
21+
# 21: Average nondimensional temperature (K)
22+
# 22: Outward mass flux through boundary with indicator 0 ("left") (kg/yr)
23+
# 23: Outward mass flux through boundary with indicator 1 ("right") (kg/yr)
24+
# 24: Outward mass flux through boundary with indicator 2 ("bottom") (kg/yr)
25+
# 25: Outward mass flux through boundary with indicator 3 ("top") (kg/yr)
26+
# 26: Minimal value for composition entropy
27+
# 27: Maximal value for composition entropy
28+
# 28: Global mass for composition entropy
29+
# 29: Minimal value for composition density_field
30+
# 30: Maximal value for composition density_field
31+
# 31: Global mass for composition density_field
32+
0 0.000000000000e+00 0.000000000000e+00 100 1408 603 1206 7 25 20 4294967289 2790 3108 2827 output-entropy_initial_lookup/solution/solution-00000 7.88044505e-03 9.98412057e-03 1.59574424e+03 1.60014975e+03 1.60309788e+03 1.16764184e-03 0.00000000e+00 0.00000000e+00 4.08138251e+05 -4.08137893e+05 2.19666723e+03 2.53347698e+03 3.95671887e+13 3.13952225e+03 4.77911946e+03 6.90810628e+13

tests/entropy_initial_lookup_wb.prm

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set End time = 0
88
set Output directory = output_3
99
set Timing output frequency = 10
1010
set Pressure normalization = surface
11-
set Surface pressure = 0
11+
set Surface pressure = 25000
1212
set Adiabatic surface temperature = 1573.0
1313
set Resume computation = false
1414
set Nonlinear solver scheme = iterated Advection and Stokes

tests/entropy_initial_lookup_wb/screen-output

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,36 @@ Number of degrees of freedom: 47,413 (18,018+2,368+9,009+9,009+9,009)
3939
Solving entropy system ... 0 iterations.
4040
Copying properties into prescribed compositional field density_field... done.
4141
Solving Stokes system (GMG)... 33+0 iterations.
42-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.60794e-16, 1.69272e-16, 0, 0.00433026
43-
Relative nonlinear residual (total system) after nonlinear iteration 1: 0.00433026
42+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.5721e-16, 1.61845e-16, 0, 0.00433027
43+
Relative nonlinear residual (total system) after nonlinear iteration 1: 0.00433027
4444

4545
Solving temperature system... 0 iterations.
4646
Solving entropy system ... 0 iterations.
4747
Copying properties into prescribed compositional field density_field... done.
4848
Solving Stokes system (GMG)... 28+0 iterations.
49-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.60794e-16, 1.69272e-16, 0, 0.00148712
50-
Relative nonlinear residual (total system) after nonlinear iteration 2: 0.00148712
49+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.5721e-16, 1.61845e-16, 0, 0.00148713
50+
Relative nonlinear residual (total system) after nonlinear iteration 2: 0.00148713
5151

5252
Solving temperature system... 0 iterations.
5353
Solving entropy system ... 0 iterations.
5454
Copying properties into prescribed compositional field density_field... done.
5555
Solving Stokes system (GMG)... 23+0 iterations.
56-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.60794e-16, 1.69272e-16, 0, 6.99073e-05
57-
Relative nonlinear residual (total system) after nonlinear iteration 3: 6.99073e-05
56+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.5721e-16, 1.61845e-16, 0, 6.99077e-05
57+
Relative nonlinear residual (total system) after nonlinear iteration 3: 6.99077e-05
5858

5959
Solving temperature system... 0 iterations.
6060
Solving entropy system ... 0 iterations.
6161
Copying properties into prescribed compositional field density_field... done.
6262
Solving Stokes system (GMG)... 18+0 iterations.
63-
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.60794e-16, 1.69272e-16, 0, 5.0992e-06
64-
Relative nonlinear residual (total system) after nonlinear iteration 4: 5.0992e-06
63+
Relative nonlinear residuals (temperature, compositional fields, Stokes system): 1.5721e-16, 1.61845e-16, 0, 5.09921e-06
64+
Relative nonlinear residual (total system) after nonlinear iteration 4: 5.09921e-06
6565

6666

6767
Postprocessing:
6868
Writing graphical output: output-entropy_initial_lookup_wb/solution/solution-00003
6969
RMS, max velocity: 0.0138 m/year, 0.124 m/year
7070
Temperature min/avg/max: 273 K, 2184 K, 3500 K
71-
Mass fluxes through boundary parts: 0.004614 kg/yr, 0.06578 kg/yr, 0 kg/yr, 2.212e-08 kg/yr
71+
Mass fluxes through boundary parts: 0.004614 kg/yr, 0.06577 kg/yr, 0 kg/yr, 2.203e-08 kg/yr
7272
Compositions min/max/mass: 577.9/2758/1.089e+17 // 3228/5592/1.939e+17
7373

7474
Termination requested by criterion: end time
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 1: Time step number
2+
# 2: Time (years)
3+
# 3: Time step size (years)
4+
# 4: Number of mesh cells
5+
# 5: Number of Stokes degrees of freedom
6+
# 6: Number of temperature degrees of freedom
7+
# 7: Number of degrees of freedom for all compositions
8+
# 8: Number of nonlinear iterations
9+
# 9: Visualization file name
10+
# 10: RMS velocity (m/year)
11+
# 11: Max. velocity (m/year)
12+
# 12: Minimal temperature (K)
13+
# 13: Average temperature (K)
14+
# 14: Maximal temperature (K)
15+
# 15: Average nondimensional temperature (K)
16+
# 16: Outward mass flux through boundary with indicator 0 ("bottom") (kg/yr)
17+
# 17: Outward mass flux through boundary with indicator 1 ("top") (kg/yr)
18+
# 18: Outward mass flux through boundary with indicator 2 ("west") (kg/yr)
19+
# 19: Outward mass flux through boundary with indicator 3 ("east") (kg/yr)
20+
# 20: Minimal value for composition entropy
21+
# 21: Maximal value for composition entropy
22+
# 22: Global mass for composition entropy
23+
# 23: Minimal value for composition density_field
24+
# 24: Maximal value for composition density_field
25+
# 25: Global mass for composition density_field
26+
# 26: Iterations for temperature solver
27+
# 27: Iterations for composition solver 1
28+
# 28: Iterations for composition solver 2
29+
# 29: Iterations for Stokes solver
30+
# 30: Velocity iterations in Stokes preconditioner
31+
# 31: Schur complement iterations in Stokes preconditioner
32+
0 0.000000000000e+00 0.000000000000e+00 384 3739 1649 3298 0 output-entropy_initial_lookup_wb/solution/solution-00000 0.00000000e+00 0.00000000e+00 2.73000000e+02 2.17080114e+03 3.50000000e+03 5.88100755e-01 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 5.77925312e+02 2.75762818e+03 1.07732840e+17 0.00000000e+00 0.00000000e+00 0.00000000e+00 0 0 0 0 0 0
33+
0 0.000000000000e+00 0.000000000000e+00 684 7217 3189 6378 0 output-entropy_initial_lookup_wb/solution/solution-00001 0.00000000e+00 0.00000000e+00 2.73000000e+02 2.18276710e+03 3.50000000e+03 5.91808832e-01 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 5.77925312e+02 2.75762818e+03 1.08621269e+17 0.00000000e+00 0.00000000e+00 0.00000000e+00 0 0 0 0 0 0
34+
0 0.000000000000e+00 0.000000000000e+00 1023 10982 4851 9702 0 output-entropy_initial_lookup_wb/solution/solution-00002 0.00000000e+00 0.00000000e+00 2.73000000e+02 2.18453715e+03 3.50000000e+03 5.92357344e-01 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 5.77925312e+02 2.75762818e+03 1.08867722e+17 0.00000000e+00 0.00000000e+00 0.00000000e+00 0 0 0 0 0 0
35+
0 0.000000000000e+00 0.000000000000e+00 1950 20386 9009 18018 4 output-entropy_initial_lookup_wb/solution/solution-00003 1.37687774e-02 1.23769331e-01 2.73000000e+02 2.18434812e+03 3.50000000e+03 5.92298767e-01 4.61392016e-03 6.57718010e-02 0.00000000e+00 2.21121666e-08 5.77925312e+02 2.75762818e+03 1.08896595e+17 3.22822228e+03 5.59177718e+03 1.93948135e+17 0 0 4294967292 98 106 106

tests/entropy_plasticity.prm

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ subsection Initial composition model
108108
set Coordinate system = spherical
109109
set Variable names = r,phi
110110
set Function expression = 2535.08 + 10 * sin(2*phi)*sin(pi*(r-6371000)/2890000) - 1878.618 * erfc((6371000-r)/(2*sqrt(1.152e-6*5e7*31557600))) + \
111-
486.368 * max(erfc((r-3481000)/(2*sqrt(1.152e-6*5e8*31557600))), exp(-((phi - 3/4*pi)^2)/(2*(1/35*pi)^2) - ((r-3481000)^2)/(2*400000^2)) );0
111+
100 * max(erfc((r-3481000)/(2*sqrt(1.152e-6*5e8*31557600))), exp(-((phi - 3/4*pi)^2)/(2*(1/35*pi)^2) - ((r-3481000)^2)/(2*400000^2)) );0
112112

113113
#set Function expression = 2687.748 + 10 * sin(2*phi)*sin(pi*(r-6371000)/2890000) - 2031.286 * erfc((6371000-r)/(2*sqrt(1.152e-6*5e7*31557600))) + 333.7 * erfc((r-3481000)/(2*sqrt(1.152e-6*5e8*31557600)));0
114114
end

0 commit comments

Comments
 (0)