|
| 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_simulator (const Simulator<dim> &simulator_object) |
| 40 | + { |
| 41 | + SimulatorAccess<dim>::initialize_simulator(simulator_object); |
| 42 | + |
| 43 | + initial_temperature_manager = |
| 44 | + this->get_initial_temperature_manager_pointer(); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + template <int dim> |
| 50 | + void |
| 51 | + InitialTemperature<dim>::update () |
| 52 | + { |
| 53 | + if (this->convert_output_to_years()) |
| 54 | + prescribed_temperature_indicator_function.set_time(this->get_time() / year_in_seconds); |
| 55 | + else |
| 56 | + prescribed_temperature_indicator_function.set_time(this->get_time()); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + template <int dim> |
| 62 | + void |
| 63 | + InitialTemperature<dim>::declare_parameters (ParameterHandler &prm) |
| 64 | + { |
| 65 | + prm.enter_subsection("Prescribed solution"); |
| 66 | + { |
| 67 | + prm.enter_subsection("Initial temperature"); |
| 68 | + { |
| 69 | + prm.declare_entry("Coordinate system", |
| 70 | + "cartesian", |
| 71 | + Patterns::Selection("cartesian|spherical|depth"), |
| 72 | + "A selection that determines the assumed coordinate " |
| 73 | + "system for the indicator function variables. " |
| 74 | + "Allowed values are `cartesian', `spherical', and `depth'."); |
| 75 | + |
| 76 | + prm.enter_subsection("Indicator function"); |
| 77 | + { |
| 78 | + Functions::ParsedFunction<dim>::declare_parameters(prm, 1); |
| 79 | + } |
| 80 | + prm.leave_subsection(); |
| 81 | + } |
| 82 | + prm.leave_subsection(); |
| 83 | + } |
| 84 | + prm.leave_subsection(); |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + template <int dim> |
| 90 | + void |
| 91 | + InitialTemperature<dim>::parse_parameters (ParameterHandler &prm) |
| 92 | + { |
| 93 | + prm.enter_subsection("Prescribed solution"); |
| 94 | + { |
| 95 | + prm.enter_subsection("Initial temperature"); |
| 96 | + { |
| 97 | + coordinate_system = |
| 98 | + Utilities::Coordinates::string_to_coordinate_system(prm.get("Coordinate system")); |
| 99 | + |
| 100 | + prm.enter_subsection("Indicator function"); |
| 101 | + { |
| 102 | + try |
| 103 | + { |
| 104 | + prescribed_temperature_indicator_function.parse_parameters(prm); |
| 105 | + } |
| 106 | + catch (...) |
| 107 | + { |
| 108 | + std::cerr << "ERROR: FunctionParser failed to parse\n" |
| 109 | + << "\t'Prescribed solution.Initial temperature.Indicator function'\n" |
| 110 | + << "with expression\n" |
| 111 | + << "\t'" << prm.get("Function expression") << "'\n"; |
| 112 | + throw; |
| 113 | + } |
| 114 | + } |
| 115 | + prm.leave_subsection(); |
| 116 | + } |
| 117 | + prm.leave_subsection(); |
| 118 | + } |
| 119 | + prm.leave_subsection(); |
| 120 | + } |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + template <int dim> |
| 125 | + void |
| 126 | + InitialTemperature<dim>::constrain_solution ( |
| 127 | + const typename DoFHandler<dim>::active_cell_iterator &/*cell*/, |
| 128 | + const std::vector<Point<dim>> &positions, |
| 129 | + const std::vector<unsigned int> &component_indices, |
| 130 | + std::vector<bool> &should_be_constrained, |
| 131 | + std::vector<double> &solution) |
| 132 | + { |
| 133 | + |
| 134 | + const unsigned int temperature_index = |
| 135 | + this->introspection().component_indices.temperature; |
| 136 | + |
| 137 | + for (unsigned int q=0; q<positions.size(); ++q) |
| 138 | + { |
| 139 | + if (component_indices[q] != temperature_index) |
| 140 | + continue; |
| 141 | + |
| 142 | + const auto point = |
| 143 | + this->get_geometry_model().cartesian_to_other_coordinates(positions[q], coordinate_system); |
| 144 | + |
| 145 | + const double indicator = |
| 146 | + prescribed_temperature_indicator_function.value(Utilities::convert_array_to_point<dim>(point.get_coordinates()), 0); |
| 147 | + |
| 148 | + if (indicator > 0.5) |
| 149 | + { |
| 150 | + should_be_constrained[q] = true; |
| 151 | + solution[q] = initial_temperature_manager->initial_temperature(positions[q]); |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | +} |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | +// explicit instantiations |
| 161 | +namespace aspect |
| 162 | +{ |
| 163 | + namespace PrescribedSolution |
| 164 | + { |
| 165 | + ASPECT_REGISTER_PRESCRIBED_SOLUTION( |
| 166 | + InitialTemperature, |
| 167 | + "initial temperature", |
| 168 | + "Prescribe the temperature in a selected region using the active " |
| 169 | + "initial temperature model. The selected region is defined through " |
| 170 | + "an indicator function. At locations where the indicator value is greater than 0.5, " |
| 171 | + "the temperature is constrained to the initial temperature evaluated " |
| 172 | + "at that position.") |
| 173 | + } |
| 174 | +} |
0 commit comments