-
Notifications
You must be signed in to change notification settings - Fork 267
Prescribed condition from initial composition #6889
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
Open
lhy11009
wants to merge
1
commit into
geodynamics:main
Choose a base branch
from
lhy11009:prescribe_from_initial_composition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+521
−1
Open
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,5 @@ | ||
| Added: a new instance of 'initial composition' in the prescribed solution plugin system. | ||
| This plugin prescribes compositional fields from the initial composition model within a | ||
| region defined by an indicator function. | ||
| <br> | ||
| (Haoyuan Li, 2026/03/11) | ||
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
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
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,98 @@ | ||
| /* | ||
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Copyright (C) 2015 - 2022 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_composition_h | ||
| #define _aspect_prescribed_solution_initial_composition_h | ||
|
|
||
| #include <aspect/initial_composition/interface.h> | ||
| #include <aspect/prescribed_solution/interface.h> | ||
| #include <aspect/simulator_access.h> | ||
|
|
||
| #include <deal.II/base/parsed_function.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace PrescribedSolution | ||
| { | ||
| /** | ||
| * Prescribe compositional fields using the initial composition model. | ||
| * The region where the constraint applies is determined by an | ||
| * indicator function. | ||
| */ | ||
| template <int dim> | ||
| class InitialComposition | ||
| : public Interface<dim>, | ||
| public SimulatorAccess<dim> | ||
| { | ||
| public: | ||
|
|
||
| InitialComposition (); | ||
|
|
||
| /** | ||
| * Store shared pointer to initial composition manager. | ||
| */ | ||
| void initialize () override; | ||
|
|
||
| /** | ||
| * Update function time. | ||
| */ | ||
| void update () override; | ||
|
|
||
| /** | ||
| * Declare parameters. | ||
| */ | ||
| static void declare_parameters (ParameterHandler &prm); | ||
|
|
||
| /** | ||
| * Parse parameters. | ||
| */ | ||
| void parse_parameters (ParameterHandler &prm) override; | ||
|
|
||
| /** | ||
| * Constrain compositional solution. | ||
| */ | ||
| 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 defining region where composition | ||
| * is prescribed. | ||
| */ | ||
| Functions::ParsedFunction<dim> indicator_function; | ||
|
|
||
| /** | ||
| * Coordinate system used for evaluating indicator. | ||
| */ | ||
| Utilities::Coordinates::CoordinateSystem coordinate_system; | ||
|
|
||
| /** | ||
| * Pointer to initial composition manager. | ||
| */ | ||
| std::shared_ptr<const aspect::InitialComposition::Manager<dim>> initial_composition_manager; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
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,175 @@ | ||
| /* | ||
| Copyright (C) 2011 - 2022 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_composition/interface.h> | ||
| #include <aspect/prescribed_solution/initial_composition.h> | ||
|
|
||
| namespace aspect | ||
| { | ||
| namespace PrescribedSolution | ||
| { | ||
|
|
||
| template <int dim> | ||
| InitialComposition<dim>::InitialComposition () | ||
| : | ||
| indicator_function(1) | ||
| {} | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialComposition<dim>::initialize () | ||
| { | ||
| initial_composition_manager = | ||
| this->get_initial_composition_manager_pointer(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialComposition<dim>::update () | ||
| { | ||
| if (this->convert_output_to_years()) | ||
| indicator_function.set_time(this->get_time() / year_in_seconds); | ||
| else | ||
| indicator_function.set_time(this->get_time()); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialComposition<dim>::constrain_solution (const typename DoFHandler<dim>::active_cell_iterator &, | ||
| const std::vector<Point<dim>> &positions, | ||
| const std::vector<unsigned int> &component_indices, | ||
| std::vector<bool> &should_be_constrained, | ||
| std::vector<double> &solution) | ||
| { | ||
| // Determine the component range corresponding to compositional fields. | ||
| // These component indices are originally mapped from local DoFs and | ||
| // determine which DoFs in the system belong to compositional fields. | ||
| const unsigned int first_comp = | ||
| this->introspection().component_indices.compositional_fields[0]; | ||
|
|
||
| const unsigned int last_comp = | ||
| this->introspection().component_indices.compositional_fields[this->introspection().n_compositional_fields-1]; | ||
|
|
||
| const auto &geometry_model = this->get_geometry_model(); | ||
|
|
||
| for (unsigned int q=0; q<positions.size(); ++q) | ||
| { | ||
| const unsigned int component = component_indices[q]; | ||
|
|
||
| if (component < first_comp || component > last_comp) | ||
| continue; | ||
|
|
||
| const auto point = geometry_model.cartesian_to_other_coordinates( | ||
| positions[q], coordinate_system); | ||
|
|
||
| const double indicator = indicator_function.value( | ||
| Utilities::convert_array_to_point<dim>(point.get_coordinates())); | ||
|
|
||
| if (indicator > 0.5) | ||
| { | ||
| const unsigned int field_index = component - first_comp; | ||
|
|
||
| solution[q] = | ||
| initial_composition_manager->initial_composition( | ||
| positions[q], field_index); | ||
|
|
||
| should_be_constrained[q] = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <int dim> | ||
| void | ||
| InitialComposition<dim>::declare_parameters (ParameterHandler &prm) | ||
| { | ||
| prm.enter_subsection("Prescribed solution"); | ||
| { | ||
| prm.enter_subsection("Initial composition"); | ||
| { | ||
|
|
||
| prm.declare_entry("Coordinate system", | ||
| "cartesian", | ||
| Patterns::Selection("cartesian|spherical|depth"), | ||
| "Coordinate system used for evaluating the indicator function."); | ||
|
|
||
| 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 | ||
| InitialComposition<dim>::parse_parameters (ParameterHandler &prm) | ||
| { | ||
| prm.enter_subsection("Prescribed solution"); | ||
| { | ||
| prm.enter_subsection("Initial composition"); | ||
| { | ||
|
|
||
| coordinate_system = | ||
| Utilities::Coordinates::string_to_coordinate_system( | ||
| prm.get("Coordinate system")); | ||
|
|
||
| prm.enter_subsection("Indicator function"); | ||
| { | ||
| indicator_function.parse_parameters(prm); | ||
| } | ||
| prm.leave_subsection(); | ||
|
|
||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| namespace aspect | ||
| { | ||
| namespace PrescribedSolution | ||
| { | ||
|
|
||
| ASPECT_REGISTER_PRESCRIBED_SOLUTION(InitialComposition, | ||
| "initial composition", | ||
| "Prescribe compositional fields from the initial composition model " | ||
| "within a region defined by an indicator function.") | ||
|
|
||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
tests/prescribed_solution_composition_initial_condition.prm
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
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,41 @@ | ||
| ######################################################### | ||
| # This is modified from the composition_passive.prm | ||
| # parameter file by prescribing the compositional solution | ||
| # from initial compositional fields. | ||
|
|
||
| include $ASPECT_SOURCE_DIR/cookbooks/composition_passive/composition_passive.prm | ||
lhy11009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Modify the original cookbook to end earlier | ||
| set Start time = 0 | ||
| set End time = 1 | ||
| set Use years instead of seconds = false | ||
|
|
||
| # Modify the original cookbook to have coarser meshes | ||
| subsection Mesh refinement | ||
| set Initial adaptive refinement = 0 | ||
| set Initial global refinement = 3 | ||
| set Time steps between mesh refinement = 0 | ||
| end | ||
|
|
||
| # The next section prescribes the composition inside the domain | ||
| # using a spatially and temporally varying function. An indicator | ||
| # function selects the region where the composition is constrained. | ||
| subsection Prescribed solution | ||
| set List of model names = initial composition | ||
| subsection Initial composition | ||
| subsection Indicator function | ||
| set Variable names = x, y | ||
| set Function expression = (x<1) ? 1:0 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| subsection Postprocess | ||
| set List of postprocessors = visualization | ||
|
|
||
| subsection Visualization | ||
| set Interpolate output = false | ||
| set Time between graphical output = 0.1 | ||
| set Output format = gnuplot | ||
| end | ||
| end | ||
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.