From 1a71fa9e7edcafca3ac019a9422450b6d2ae22e0 Mon Sep 17 00:00:00 2001 From: Rene Gassmoeller Date: Fri, 9 Jun 2017 14:09:23 -0600 Subject: [PATCH] Add random composition plugin --- doc/modules/changes/20170609_gassmoeller | 1 + .../initial_composition/random_perturbation.h | 89 +++++++++++++++++ .../initial_temperature/random_perturbation.h | 2 +- .../random_perturbation.cc | 95 +++++++++++++++++++ .../random_perturbation.cc | 13 +-- tests/random_composition_perturbation.prm | 69 ++++++++++++++ .../screen-output | 21 ++++ .../statistics | 20 ++++ 8 files changed, 301 insertions(+), 9 deletions(-) create mode 100644 include/aspect/initial_composition/random_perturbation.h create mode 100644 source/initial_composition/random_perturbation.cc create mode 100644 tests/random_composition_perturbation.prm create mode 100644 tests/random_composition_perturbation/screen-output create mode 100644 tests/random_composition_perturbation/statistics diff --git a/doc/modules/changes/20170609_gassmoeller b/doc/modules/changes/20170609_gassmoeller index 2de3a394cd4..0732c8ceb67 100644 --- a/doc/modules/changes/20170609_gassmoeller +++ b/doc/modules/changes/20170609_gassmoeller @@ -1,4 +1,5 @@ New: A new initial temperature condition was added that adds a random noise of user prescribed magnitude to the initial temperature field. +The same type of plugin was added for initial compositions.
(Rene Gassmoeller, 2017/06/19) diff --git a/include/aspect/initial_composition/random_perturbation.h b/include/aspect/initial_composition/random_perturbation.h new file mode 100644 index 00000000000..49dbca0f644 --- /dev/null +++ b/include/aspect/initial_composition/random_perturbation.h @@ -0,0 +1,89 @@ +/* + Copyright (C) 2017 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 doc/COPYING. If not see + . +*/ + + +#ifndef _aspect_initial_composition_random_perturbation_h +#define _aspect_initial_composition_random_perturbation_h + +#include + +DEAL_II_DISABLE_EXTRA_DIAGNOSTICS +#include +DEAL_II_ENABLE_EXTRA_DIAGNOSTICS + +namespace aspect +{ + namespace InitialComposition + { + using namespace dealii; + + /** + * A class that describes a perturbation for the initial composition fields + * for any geometry model or dimension. The perturbation follows + * a random noise of a prescribed magnitude. + * + * @ingroup InitialCompositions + */ + template + class RandomPerturbation : public Interface + { + public: + /** + * Constructor. + */ + RandomPerturbation(); + + /** + * Return the initial temperature as a function of position. + */ + virtual + double initial_composition (const Point &position, + const unsigned int compositional_index) const; + + /** + * 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. + */ + virtual + void + parse_parameters (ParameterHandler &prm); + + + private: + /** + * The maximal magnitude of the random noise. + */ + double magnitude; + + /** + * Random number generator. + */ + mutable boost::mt19937 random_number_generator; + }; + } +} + +#endif diff --git a/include/aspect/initial_temperature/random_perturbation.h b/include/aspect/initial_temperature/random_perturbation.h index 0b88c4b0c8e..28602a7f78d 100644 --- a/include/aspect/initial_temperature/random_perturbation.h +++ b/include/aspect/initial_temperature/random_perturbation.h @@ -36,7 +36,7 @@ namespace aspect /** * A class that describes a perturbation for the initial temperature field - * for any geometry model or dimension in shape. The perturbation follows + * for any geometry model or dimension. The perturbation follows * a random noise of a prescribed magnitude. * * @ingroup InitialTemperatures diff --git a/source/initial_composition/random_perturbation.cc b/source/initial_composition/random_perturbation.cc new file mode 100644 index 00000000000..01a14b88ced --- /dev/null +++ b/source/initial_composition/random_perturbation.cc @@ -0,0 +1,95 @@ +/* + Copyright (C) 2017 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 doc/COPYING. If not see + . +*/ + + +#include + +namespace aspect +{ + namespace InitialComposition + { + template + RandomPerturbation:: + RandomPerturbation () + : + random_number_generator(5432) + { + } + + template + double + RandomPerturbation:: + initial_composition (const Point &/*position*/, + const unsigned int /*compositional_index*/) const + { + // Uniform distribution on the interval [0,1]. This + // will be used to generate random particle locations. + boost::uniform_01 uniform_distribution_01; + + return magnitude * 2.0 * (uniform_distribution_01(random_number_generator) - 0.5); + } + + template + void + RandomPerturbation::declare_parameters (ParameterHandler &prm) + { + prm.enter_subsection ("Initial composition model"); + { + prm.enter_subsection("Random perturbation"); + { + prm.declare_entry ("Magnitude", "1.0", + Patterns::Double (0), + "The magnitude of the random perturbation."); + } + prm.leave_subsection (); + } + prm.leave_subsection (); + } + + + template + void + RandomPerturbation::parse_parameters (ParameterHandler &prm) + { + prm.enter_subsection ("Initial composition model"); + { + prm.enter_subsection("Random perturbation"); + { + magnitude = prm.get_double ("Magnitude"); + } + prm.leave_subsection (); + } + prm.leave_subsection (); + } + } +} + +// explicit instantiations +namespace aspect +{ + namespace InitialComposition + { + ASPECT_REGISTER_INITIAL_COMPOSITION_MODEL(RandomPerturbation, + "random perturbation", + "An initial composition anomaly that perturbs the composition " + "following a random noise with uniform distribution and user " + "specified magnitude.") + } +} diff --git a/source/initial_temperature/random_perturbation.cc b/source/initial_temperature/random_perturbation.cc index b639e202805..103074d2cee 100644 --- a/source/initial_temperature/random_perturbation.cc +++ b/source/initial_temperature/random_perturbation.cc @@ -28,8 +28,8 @@ namespace aspect template RandomPerturbation:: RandomPerturbation () - : - random_number_generator(5432) + : + random_number_generator(5432) { } @@ -87,11 +87,8 @@ namespace aspect { ASPECT_REGISTER_INITIAL_TEMPERATURE_MODEL(RandomPerturbation, "random perturbation", - "An initial temperature field in which the temperature " - "is perturbed following a harmonic function (spherical " - "harmonic or sine depending on geometry and dimension) " - "in lateral and radial direction from an otherwise " - "constant temperature (incompressible model) or adiabatic " - "reference profile (compressible model).") + "An initial tempeature anomaly that perturbs the temperature " + "following a random noise with uniform distribution and user " + "specified magnitude.") } } diff --git a/tests/random_composition_perturbation.prm b/tests/random_composition_perturbation.prm new file mode 100644 index 00000000000..e23c5c681bd --- /dev/null +++ b/tests/random_composition_perturbation.prm @@ -0,0 +1,69 @@ +# Test to check the status of the random initial temperature perturbation +# plugin. + +set End time = 0 + +subsection Boundary temperature model + set List of model names = box +end + + +subsection Gravity model + set Model name = vertical +end + + +subsection Geometry model + set Model name = box + + subsection Box + set X extent = 1 + set Y extent = 1 + end +end + + +subsection Initial temperature model + set List of model names = function + + subsection Function + set Function expression = 0.5 + end +end + +subsection Compositional fields + set Number of fields = 2 +end + +subsection Initial composition model + set List of model names = function, random perturbation + + subsection Random perturbation + set Magnitude = 0.2 + end + + subsection Function + set Function expression = 0.5;0.0 + end +end + + +subsection Material model + set Model name = simpler +end + + +subsection Mesh refinement + set Initial adaptive refinement = 0 + set Initial global refinement = 3 +end + + +subsection Model settings + set Tangential velocity boundary indicators = left, right, bottom, top +end + +subsection Postprocess + set List of postprocessors = composition statistics +end + diff --git a/tests/random_composition_perturbation/screen-output b/tests/random_composition_perturbation/screen-output new file mode 100644 index 00000000000..a8a8dc6da65 --- /dev/null +++ b/tests/random_composition_perturbation/screen-output @@ -0,0 +1,21 @@ + +Number of active cells: 64 (on 4 levels) +Number of degrees of freedom: 1,526 (578+81+289+289+289) + +*** Timestep 0: t=0 years + Solving temperature system... 0 iterations. + Solving C_1 system ... 0 iterations. + Solving C_2 system ... 0 iterations. + Rebuilding Stokes preconditioner... + Solving Stokes system... 2+0 iterations. + + Postprocessing: + Compositions min/max/mass: 0.3001/0.6984/0.4938 // -0.2/0.1996/-0.01184 + +Termination requested by criterion: end time + + ++---------------------------------------------+------------+------------+ ++---------------------------------+-----------+------------+------------+ ++---------------------------------+-----------+------------+------------+ + diff --git a/tests/random_composition_perturbation/statistics b/tests/random_composition_perturbation/statistics new file mode 100644 index 00000000000..992b20ca031 --- /dev/null +++ b/tests/random_composition_perturbation/statistics @@ -0,0 +1,20 @@ +# 1: Time step number +# 2: Time (years) +# 3: Time step size (years) +# 4: Number of mesh cells +# 5: Number of Stokes degrees of freedom +# 6: Number of temperature degrees of freedom +# 7: Number of degrees of freedom for all compositions +# 8: Iterations for temperature solver +# 9: Iterations for composition solver 1 +# 10: Iterations for composition solver 2 +# 11: Iterations for Stokes solver +# 12: Velocity iterations in Stokes preconditioner +# 13: Schur complement iterations in Stokes preconditioner +# 14: Minimal value for composition C_1 +# 15: Maximal value for composition C_1 +# 16: Global mass for composition C_1 +# 17: Minimal value for composition C_2 +# 18: Maximal value for composition C_2 +# 19: Global mass for composition C_2 +0 0.000000000000e+00 0.000000000000e+00 64 659 289 578 0 0 0 2 3 2 3.00090365e-01 6.98414874e-01 4.93781411e-01 -1.99952361e-01 1.99564844e-01 -1.18366501e-02