-
Notifications
You must be signed in to change notification settings - Fork 268
Prescribed solution initial temperature #6888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gassmoeller
merged 1 commit into
geodynamics:main
from
lhy11009:prescribed_solution_initial_temperature
Mar 17, 2026
+504
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Added: a new instance of 'initial temperature' in the prescribed solution plugin system. | ||
| <br> | ||
| (Haoyuan Li, 2025/12/30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
include/aspect/prescribed_solution/initial_temperature.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| Copyright (C) 2011 - 2026 by the authors of the ASPECT code. | ||
|
|
||
| This file is part of ASPECT. | ||
|
|
||
| ASPECT is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2, or (at your option) | ||
| any later version. | ||
|
|
||
| ASPECT is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with ASPECT; see the file LICENSE. If not see | ||
| <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #ifndef _aspect_prescribed_solution_initial_temperature_h | ||
| #define _aspect_prescribed_solution_initial_temperature_h | ||
|
|
||
| #include <aspect/initial_temperature/interface.h> | ||
| #include <aspect/prescribed_solution/interface.h> | ||
| #include <aspect/simulator_access.h> | ||
| #include <deal.II/base/parsed_function.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace PrescribedSolution | ||
| { | ||
| /** | ||
| * A class that prescribes temperature in a selected region using | ||
| * the value returned by the active initial temperature model. | ||
| * | ||
| * The region is selected through an indicator function. Where the | ||
| * indicator is greater than 0.5, the temperature is constrained | ||
| * to the initial temperature value evaluated at that position. | ||
| * | ||
| * @ingroup PrescribedSolution | ||
| */ | ||
| template <int dim> | ||
| class InitialTemperature | ||
| : public Interface<dim>, | ||
| public SimulatorAccess<dim> | ||
| { | ||
| public: | ||
| /** | ||
| * Constructor. | ||
| */ | ||
| InitialTemperature (); | ||
|
|
||
| /** | ||
| * Store a shared pointer to the initial temperature manager so the | ||
| * plugin can safely access it after initialization. | ||
| */ | ||
| void initialize () override; | ||
|
|
||
| /** | ||
| * Update the current time in the indicator function. | ||
| */ | ||
| void update () override; | ||
|
|
||
| /** | ||
| * Declare the parameters this class takes through input files. | ||
| */ | ||
| static void declare_parameters (ParameterHandler &prm); | ||
|
|
||
| /** | ||
| * Read the parameters this class declares from the parameter file. | ||
| */ | ||
| void parse_parameters (ParameterHandler &prm) override; | ||
|
|
||
| /** | ||
| * Decide and assign cell-wise constraints for temperature DoFs. | ||
| */ | ||
| void constrain_solution ( | ||
| const typename DoFHandler<dim>::active_cell_iterator &cell, | ||
| const std::vector<Point<dim>> &positions, | ||
| const std::vector<unsigned int> &component_indices, | ||
| std::vector<bool> &should_be_constrained, | ||
| std::vector<double> &solution) override; | ||
|
|
||
| private: | ||
| /** | ||
| * Indicator function for selecting where the temperature should | ||
| * be prescribed. | ||
| */ | ||
| Functions::ParsedFunction<dim> prescribed_temperature_indicator_function; | ||
|
|
||
| /** | ||
| * The coordinate representation used to evaluate the indicator | ||
| * function. Possible choices are cartesian, spherical, and depth. | ||
| */ | ||
| Utilities::Coordinates::CoordinateSystem coordinate_system; | ||
|
|
||
| /** | ||
| * Shared pointer to the initial temperature manager. We keep this | ||
| * alive because the simulator may release its own pointer after | ||
| * initialization. | ||
| */ | ||
| std::shared_ptr<const aspect::InitialTemperature::Manager<dim>> initial_temperature_manager; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /* | ||
| Copyright (C) 2011 - 2026 by the authors of the ASPECT code. | ||
|
|
||
| This file is part of ASPECT. | ||
|
|
||
| ASPECT is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2, or (at your option) | ||
| any later version. | ||
|
|
||
| ASPECT is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with ASPECT; see the file LICENSE. If not see | ||
| <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include <aspect/initial_temperature/interface.h> | ||
| #include <aspect/prescribed_solution/initial_temperature.h> | ||
| #include <aspect/geometry_model/interface.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace PrescribedSolution | ||
| { | ||
| template <int dim> | ||
| InitialTemperature<dim>::InitialTemperature () | ||
| : | ||
| prescribed_temperature_indicator_function(1) | ||
| {} | ||
|
|
||
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialTemperature<dim>::initialize () | ||
| { | ||
| initial_temperature_manager = | ||
| this->get_initial_temperature_manager_pointer(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialTemperature<dim>::update () | ||
| { | ||
| if (this->convert_output_to_years()) | ||
| prescribed_temperature_indicator_function.set_time(this->get_time() / year_in_seconds); | ||
| else | ||
| prescribed_temperature_indicator_function.set_time(this->get_time()); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialTemperature<dim>::constrain_solution (const typename DoFHandler<dim>::active_cell_iterator &/*cell*/, | ||
| const std::vector<Point<dim>> &positions, | ||
| const std::vector<unsigned int> &component_indices, | ||
| std::vector<bool> &should_be_constrained, | ||
| std::vector<double> &solution) | ||
| { | ||
|
|
||
| const unsigned int temperature_index = | ||
| this->introspection().component_indices.temperature; | ||
|
|
||
| for (unsigned int q=0; q<positions.size(); ++q) | ||
| { | ||
| if (component_indices[q] != temperature_index) | ||
| continue; | ||
|
|
||
| const auto point = | ||
| this->get_geometry_model().cartesian_to_other_coordinates(positions[q], coordinate_system); | ||
|
|
||
| const double indicator = | ||
| prescribed_temperature_indicator_function.value(Utilities::convert_array_to_point<dim>(point.get_coordinates()), 0); | ||
|
|
||
| if (indicator > 0.5) | ||
| { | ||
| should_be_constrained[q] = true; | ||
| solution[q] = initial_temperature_manager->initial_temperature(positions[q]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void | ||
| InitialTemperature<dim>::declare_parameters (ParameterHandler &prm) | ||
| { | ||
| prm.enter_subsection("Prescribed solution"); | ||
| { | ||
| prm.enter_subsection("Initial temperature"); | ||
| { | ||
| prm.declare_entry("Coordinate system", | ||
| "cartesian", | ||
| Patterns::Selection("cartesian|spherical|depth"), | ||
| "A selection that determines the assumed coordinate " | ||
| "system for the indicator function variables. " | ||
| "Allowed values are `cartesian', `spherical', and `depth'."); | ||
|
|
||
| prm.enter_subsection("Indicator function"); | ||
| { | ||
| Functions::ParsedFunction<dim>::declare_parameters(prm, 1); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialTemperature<dim>::parse_parameters (ParameterHandler &prm) | ||
| { | ||
| prm.enter_subsection("Prescribed solution"); | ||
| { | ||
| prm.enter_subsection("Initial temperature"); | ||
| { | ||
| coordinate_system = | ||
| Utilities::Coordinates::string_to_coordinate_system(prm.get("Coordinate system")); | ||
|
|
||
| prm.enter_subsection("Indicator function"); | ||
| { | ||
| try | ||
| { | ||
| prescribed_temperature_indicator_function.parse_parameters(prm); | ||
| } | ||
| catch (...) | ||
| { | ||
| std::cerr << "ERROR: FunctionParser failed to parse\n" | ||
| << "\t'Prescribed solution.Initial temperature.Indicator function'\n" | ||
| << "with expression\n" | ||
| << "\t'" << prm.get("Function expression") << "'\n"; | ||
| throw; | ||
| } | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // explicit instantiations | ||
| namespace aspect | ||
| { | ||
| namespace PrescribedSolution | ||
| { | ||
| ASPECT_REGISTER_PRESCRIBED_SOLUTION(InitialTemperature, | ||
| "initial temperature", | ||
| "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.") | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.