|
| 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 | +} |
0 commit comments