Skip to content

Commit

Permalink
Add random composition plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gassmoeller committed Jun 14, 2017
1 parent 3ec0d83 commit 1a71fa9
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/modules/changes/20170609_gassmoeller
Original file line number Diff line number Diff line change
@@ -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.
<br>
(Rene Gassmoeller, 2017/06/19)
89 changes: 89 additions & 0 deletions include/aspect/initial_composition/random_perturbation.h
Original file line number Diff line number Diff line change
@@ -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
<http://www.gnu.org/licenses/>.
*/


#ifndef _aspect_initial_composition_random_perturbation_h
#define _aspect_initial_composition_random_perturbation_h

#include <aspect/initial_composition/interface.h>

DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#include <boost/random.hpp>
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 <int dim>
class RandomPerturbation : public Interface<dim>
{
public:
/**
* Constructor.
*/
RandomPerturbation();

/**
* Return the initial temperature as a function of position.
*/
virtual
double initial_composition (const Point<dim> &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
2 changes: 1 addition & 1 deletion include/aspect/initial_temperature/random_perturbation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 95 additions & 0 deletions source/initial_composition/random_perturbation.cc
Original file line number Diff line number Diff line change
@@ -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
<http://www.gnu.org/licenses/>.
*/


#include <aspect/initial_composition/random_perturbation.h>

namespace aspect
{
namespace InitialComposition
{
template <int dim>
RandomPerturbation<dim>::
RandomPerturbation ()
:
random_number_generator(5432)
{
}

template <int dim>
double
RandomPerturbation<dim>::
initial_composition (const Point<dim> &/*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<double> uniform_distribution_01;

return magnitude * 2.0 * (uniform_distribution_01(random_number_generator) - 0.5);
}

template <int dim>
void
RandomPerturbation<dim>::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 <int dim>
void
RandomPerturbation<dim>::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.")
}
}
13 changes: 5 additions & 8 deletions source/initial_temperature/random_perturbation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace aspect
template <int dim>
RandomPerturbation<dim>::
RandomPerturbation ()
:
random_number_generator(5432)
:
random_number_generator(5432)
{
}

Expand Down Expand Up @@ -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.")
}
}
69 changes: 69 additions & 0 deletions tests/random_composition_perturbation.prm
Original file line number Diff line number Diff line change
@@ -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

21 changes: 21 additions & 0 deletions tests/random_composition_perturbation/screen-output
Original file line number Diff line number Diff line change
@@ -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


+---------------------------------------------+------------+------------+
+---------------------------------+-----------+------------+------------+
+---------------------------------+-----------+------------+------------+

20 changes: 20 additions & 0 deletions tests/random_composition_perturbation/statistics
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1a71fa9

Please sign in to comment.