Skip to content

Commit

Permalink
Add random noise initial temperature plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gassmoeller committed Jun 14, 2017
1 parent 6817984 commit 3ec0d83
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/modules/changes/20170609_gassmoeller
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
New: A new initial temperature condition was added that adds a random
noise of user prescribed magnitude to the initial temperature field.
<br>
(Rene Gassmoeller, 2017/06/19)
90 changes: 90 additions & 0 deletions include/aspect/initial_temperature/random_perturbation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
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_temperature_random_perturbation_h
#define _aspect_initial_temperature_random_perturbation_h

#include <aspect/initial_temperature/interface.h>

DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#include <boost/random.hpp>
DEAL_II_ENABLE_EXTRA_DIAGNOSTICS

namespace aspect
{
namespace InitialTemperature
{
using namespace dealii;

/**
* A class that describes a perturbation for the initial temperature field
* for any geometry model or dimension in shape. The perturbation follows
* a random noise of a prescribed magnitude.
*
* @ingroup InitialTemperatures
*/
template <int dim>
class RandomPerturbation : public Interface<dim>
{
public:
/**
* Constructor.
*/
RandomPerturbation();

/**
* Return the initial temperature as a function of position.
*/
virtual
double initial_temperature (const Point<dim> &position) 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
97 changes: 97 additions & 0 deletions source/initial_temperature/random_perturbation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
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_temperature/random_perturbation.h>

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

template <int dim>
double
RandomPerturbation<dim>::
initial_temperature (const Point<dim> &/*position*/) 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 temperature 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 temperature model");
{
prm.enter_subsection("Random perturbation");
{
magnitude = prm.get_double ("Magnitude");
}
prm.leave_subsection ();
}
prm.leave_subsection ();
}
}
}

// explicit instantiations
namespace aspect
{
namespace InitialTemperature
{
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).")
}
}
57 changes: 57 additions & 0 deletions tests/random_temperature_perturbation.prm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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, random perturbation

subsection Random perturbation
set Magnitude = 0.2
end

subsection Function
set Function expression = 0.5
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 = temperature statistics
end

19 changes: 19 additions & 0 deletions tests/random_temperature_perturbation/screen-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

Number of active cells: 64 (on 4 levels)
Number of degrees of freedom: 948 (578+81+289)

*** Timestep 0: t=0 years
Solving temperature system... 0 iterations.
Rebuilding Stokes preconditioner...
Solving Stokes system... 17+0 iterations.

Postprocessing:
Temperature min/avg/max: 0.3001 K, 0.5056 K, 0.6973 K

Termination requested by criterion: end time


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

14 changes: 14 additions & 0 deletions tests/random_temperature_perturbation/statistics
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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: Iterations for temperature solver
# 8: Iterations for Stokes solver
# 9: Velocity iterations in Stokes preconditioner
# 10: Schur complement iterations in Stokes preconditioner
# 11: Minimal temperature (K)
# 12: Average temperature (K)
# 13: Maximal temperature (K)
0 0.000000000000e+00 0.000000000000e+00 64 659 289 0 17 18 17 3.00129639e-01 5.05619087e-01 6.97305210e-01

0 comments on commit 3ec0d83

Please sign in to comment.