Skip to content
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

Random initial temperature and compositional plugins #5831

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

KerrMadeleine
Copy link
Contributor

I have revisited the Random initial composition (which also includes random initial temperature) and attempted to test that the random number generator MT19937 produces the same sequence of random numbers given the same seed. The generator random_number_generator is a private member of the Initial temperature class and seeded with the integer 1. Seeding the RNG with a hash which uses the position value of each point to generate a combined hash has been removed as well as the option to randomly seed the random number generator. Still, with the RNG seed fixed to 1, the plug-in produces different initial temperature fields for the same prm file.

This *.prm file is:
'''

Test to check the status of the random initial temperature perturbation

plugin.

set Output directory = output-test-2
set Dimension = 2

subsection Boundary velocity model
set Tangential velocity boundary indicators = left, right, bottom, top
end

subsection Mesh refinement
set Initial global refinement = 1
end

subsection Postprocess
set List of postprocessors = temperature statistics, visualization
subsection Visualization
set Output format = gnuplot
end
end

subsection Material model
set Model name = simpler
end

set End time = 0
subsection Geometry model
set Model name = box
end

subsection Gravity model
set Model name = vertical
end

subsection Initial temperature model
set List of model names = function, random perturbation
subsection Random perturbation
set Magnitude = 0.2
set Use random seed = false
end

subsection Function
set Function expression = 0.5
end

end

subsection Boundary temperature model
set List of model names = box
set Fixed temperature boundary indicators = top, bottom #MCK added

subsection Box #MCK added
set Bottom temperature = 1
set Top temperature = 0
end

end
'''

@KerrMadeleine KerrMadeleine changed the title Random initial temperature : RNG MT19937 does not seed properly Random initial temperature : RNG MT19937 does not seed as expected Jun 6, 2024
@gassmoeller gassmoeller changed the title Random initial temperature : RNG MT19937 does not seed as expected [WIP] Random initial temperature : RNG MT19937 does not seed as expected Jun 6, 2024
@gassmoeller
Copy link
Member

This is an update of #1813 to modern standards and currently just open for discussion

@bangerth
Copy link
Contributor

bangerth commented Jun 7, 2024

When you say " the plug-in produces different initial temperature fields for the same prm file", do you mean "different initial temperature fields from run to tun", or different from what?

@bangerth
Copy link
Contributor

bangerth commented Jun 7, 2024

You've got these warnings and errors:

/home/runner/work/aspect/aspect/include/aspect/initial_composition/random_perturbation.h:90:46: error: expected identifier before numeric constant
   90 |         std::mt19937 random_number_generator(1);
      |                                              ^
/home/runner/work/aspect/aspect/include/aspect/initial_composition/random_perturbation.h:90:46: error: expected ‘,’ or ‘...’ before numeric constant
/home/runner/work/aspect/aspect/include/aspect/initial_composition/random_perturbation.h: In instantiation of ‘class aspect::InitialComposition::RandomPerturbation<2>’:
/home/runner/work/aspect/aspect/source/initial_composition/random_perturbation.cc:121:5:   required from here
/home/runner/work/aspect/aspect/source/initial_composition/random_perturbation.cc:55:5: error: ‘double aspect::InitialComposition::RandomPerturbation<dim>::initial_composition(const dealii::Point<dim>&, unsigned int) const [with int dim = 2]’ can be marked override [-Werror=suggest-override]
   55 |     RandomPerturbation<dim>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/aspect/aspect/source/initial_composition/random_perturbation.cc:100:5: error: ‘void aspect::InitialComposition::RandomPerturbation<dim>::parse_parameters(dealii::ParameterHandler&) [with int dim = 2]’ can be marked override [-Werror=suggest-override]
  100 |     RandomPerturbation<dim>::parse_parameters (ParameterHandler &prm)
      |     ^~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/aspect/aspect/include/aspect/initial_composition/random_perturbation.h: In instantiation of ‘class aspect::InitialComposition::RandomPerturbation<3>’:
/home/runner/work/aspect/aspect/source/initial_composition/random_perturbation.cc:121:5:   required from here
/home/runner/work/aspect/aspect/source/initial_composition/random_perturbation.cc:55:5: error: ‘double aspect::InitialComposition::RandomPerturbation<dim>::initial_composition(const dealii::Point<dim>&, unsigned int) const [with int dim = 3]’ can be marked override [-Werror=suggest-override]
   55 |     RandomPerturbation<dim>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/aspect/aspect/source/initial_composition/random_perturbation.cc:100:5: error: ‘void aspect::InitialComposition::RandomPerturbation<dim>::parse_parameters(dealii::ParameterHandler&) [with int dim = 3]’ can be marked override [-Werror=suggest-override]
  100 |     RandomPerturbation<dim>::parse_parameters (ParameterHandler &prm)
      |     ^~~~~~~~~~~~~~~~~~~~~~~

Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close, I just have some stylistic comments. Let me know when you want me to take another look.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to update the date and add your name here as first author.

Comment on lines +88 to +89
* random composition perturbations. Should return the same
* random numbers every time since it is seeded with one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the sentence, since the behavior depends on the input parameters.

/**
* Return the initial temperature as a function of position.
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this empty line, instead add one before the comment. Also please add documentation for the initialize function above (check the other plugins, you can likely copy the documentation).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also check the initial temperature plugin for the same function


#include <aspect/initial_composition/random_perturbation.h>

// #include <boost/functional/hash.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this header file

else
random_number_generator.seed(9088+my_rank);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our typical code style is to have 3 empty lines between function implementations in the source file (and 1 empty line between function declarations in the header file).

template <int dim>
double
RandomPerturbation<dim>::
initial_composition (const Point<dim> &position, const unsigned int composition_index) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler complains because none of the input parameters are used, do this instead:

Suggested change
initial_composition (const Point<dim> &position, const unsigned int composition_index) const
initial_composition (const Point<dim> &/*position*/, const unsigned int /*composition_index*/) const

#include <aspect/initial_composition/interface.h>
#include <aspect/simulator_access.h>

DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know there is no need for DEAL_II_DISABLE_EXTRA_DIAGNOSTICS anymore and also DEAL_II_ENABLE_EXTRA_DIAGNOSTICS. (keep the include).

*/
template <int dim>
class RandomPerturbation : public Interface<dim>, public aspect::SimulatorAccess<dim>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this empty line

#include <aspect/initial_temperature/interface.h>
#include <aspect/simulator_access.h>

DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

template <int dim>
double
RandomPerturbation<dim>::
initial_temperature (const Point<dim> &position) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above:

Suggested change
initial_temperature (const Point<dim> &position) const
initial_temperature (const Point<dim> &/*position*/) const

@gassmoeller gassmoeller changed the title [WIP] Random initial temperature : RNG MT19937 does not seed as expected Random initial temperature and compositional plugins Jun 7, 2024
Copy link
Contributor

@bangerth bangerth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a comment for @gassmoeller: This scheme is not thread-safe. If VectorTools::interpolate() decides to run on multiple processes, we will end up with non-reproducible random numbers. It doesn't, right now, but I thought it's worthwhile putting this into the record in case someone needs to track down a non-reproducibility at some later point.

@gassmoeller
Copy link
Member

@bangerth You are right of course. However, we never made the last try to produce a thread-safe version work (#1813), because that one produced non-reproducible random number series even on a single process and neither I nor @KerrMadeleine could figure out why. That is why we decided to go with the algorithm that works for the current version of ASPECT and think about thread-safety if it will ever be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants