Skip to content

Commit

Permalink
Merge pull request #6054 from gassmoeller/test_for_multiple_particle_…
Browse files Browse the repository at this point in the history
…interpolation

Test for multiple particle interpolation
  • Loading branch information
tjhei authored Oct 7, 2024
2 parents c8475b3 + 920201e commit e746ba7
Show file tree
Hide file tree
Showing 11 changed files with 511 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/aspect/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ namespace aspect
* field. See Introspection::polynomial_degree for more information.
*/
unsigned int polynomial_degree(const Introspection<dim> &introspection) const;

/**
* Return a string that describes the field type and the compositional
* variable number and name, if applicable.
*/
std::string
name(const Introspection<dim> &introspection) const;
};

private:
Expand Down
13 changes: 13 additions & 0 deletions source/simulator/helper_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ namespace aspect
}



template <int dim>
std::string
Simulator<dim>::AdvectionField::name(const Introspection<dim> &introspection) const
{
if (this->is_temperature())
return "temperature";
else
return "composition " + std::to_string(compositional_variable) + " (" + introspection.name_for_compositional_index(compositional_variable) + ")";
}



template <int dim>
void Simulator<dim>::write_plugin_graph (std::ostream &out) const
{
Expand Down
15 changes: 15 additions & 0 deletions source/simulator/initial_conditions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ namespace aspect
// A property component mask indicating for each particle world which particle properties need to be interpolated
std::vector<ComponentMask> property_mask;

// Mark for each advection field if it has been found in any particle world. We need to keep track of this to:
// - make sure all fields tracked by particles are found in at least one particle world
// - make sure that we do not interpolate the same field twice from different particle worlds
std::vector<bool> advection_field_has_been_found(advection_fields.size(),false);

for (unsigned int world_index = 0; world_index < particle_worlds.size(); ++world_index)
{
const Particle::Property::Manager<dim> &particle_property_manager = particle_worlds[world_index].get_property_manager();
Expand All @@ -306,9 +311,13 @@ namespace aspect
// If not: assume we find it in another world.
if (particle_property_manager.get_data_info().fieldname_exists(particle_property_and_component.first))
{
Assert (advection_field_has_been_found[advection_field] == false,
ExcMessage("The field " + advection_fields[advection_field].name(introspection) + " is mapped to particle properties in more than one particle world. This is not supported."));

const unsigned int particle_property_index = particle_property_manager.get_data_info().get_position_by_field_name(particle_property_and_component.first)
+ particle_property_and_component.second;

advection_field_has_been_found[advection_field] = true;
particle_property_indices[world_index].push_back({advection_field, particle_property_index});
property_mask[world_index].set(particle_property_index,true);
}
Expand All @@ -326,12 +335,18 @@ namespace aspect
ExcMessage("Can not automatically match particle properties to fields, because there are"
"more fields that are marked as particle advected than particle properties"));

advection_field_has_been_found[advection_field] = true;
particle_property_indices[world_index].push_back({advection_field,particle_property_index});
property_mask[world_index].set(particle_property_index,true);
}
}
}

for (unsigned int advection_field=0; advection_field<advection_fields.size(); ++advection_field)
Assert (advection_field_has_been_found[advection_field] == true,
ExcMessage("The field " + advection_fields[advection_field].name(introspection) + " is marked as advected by particles, but no particle property exists that is mapped to this field. "
"Make sure that the particle property exists and is mapped to the correct field in the parameter file."));

LinearAlgebra::BlockVector particle_solution;

particle_solution.reinit(system_rhs, false);
Expand Down
102 changes: 102 additions & 0 deletions tests/particle_multiple_worlds_interpolation.prm
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Test that we can activate multiple particle worlds and
# interpolate properties from different particle worlds into
# the compositional fields.

set Dimension = 2
set End time = 0
set Use years in output instead of seconds = false
set Number of particle worlds = 2

subsection Geometry model
set Model name = box

subsection Box
set X extent = 0.9142
set Y extent = 1.0000
end
end

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

subsection Material model
set Model name = simple

subsection Simple model
set Reference density = 1010
set Viscosity = 1e2
set Thermal expansion coefficient = 0
set Density differential for compositional field 1 = -10
end
end

subsection Gravity model
set Model name = vertical

subsection Vertical
set Magnitude = 10
end
end

subsection Initial temperature model
set Model name = function

subsection Function
set Function expression = 0
end
end

subsection Compositional fields
set Number of fields = 2
set Names of fields = anomaly, function
set Compositional field methods = particles, particles
set Mapped particle properties = anomaly: function, function: initial anomaly
end

subsection Initial composition model
set Model name = function

subsection Function
set Variable names = x,z
set Function constants = pi=3.1415926
set Function expression = 0.5*(1+tanh((0.2+0.02*cos(pi*x/0.9142)-z)/0.02)); 0.0
end
end

subsection Mesh refinement
set Initial adaptive refinement = 0
set Strategy = composition
set Initial global refinement = 1
set Time steps between mesh refinement = 0
end

subsection Postprocess
set List of postprocessors = velocity statistics, composition statistics, particles, visualization

subsection Visualization
set Output format = gnuplot
end

subsection Particles
set Time between data output = 70
set Data output format =
end
end

subsection Particles
set List of particle properties = initial composition
set Particle generator name = reference cell
end

subsection Particles 2
set List of particle properties = function
set Particle generator name = reference cell

subsection Function
set Variable names = x,z
set Function constants = pi=3.1415926
set Function expression = x
end
end
20 changes: 20 additions & 0 deletions tests/particle_multiple_worlds_interpolation/screen-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Number of active cells: 4 (on 2 levels)
Number of degrees of freedom: 134 (50+9+25+25+25)

*** Timestep 0: t=0 seconds, dt=0 seconds
Skipping temperature solve because RHS is zero.
Advecting particles... done.
Advecting particles... done.
Solving Stokes system... 9+0 iterations.

Postprocessing:
RMS, max velocity: 0.00308 m/s, 0.00465 m/s
Compositions min/max/mass: 0.2285/0.6856/0.4527 // 0/0.4999/0.1902
Number of advected particles 16, 16
Writing graphical output: output-particle_multiple_worlds_interpolation/solution/solution-00000

Termination requested by criterion: end time



Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/particle_multiple_worlds_interpolation/statistics
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 1: Time step number
# 2: Time (seconds)
# 3: Time step size (seconds)
# 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 Stokes solver
# 10: Velocity iterations in Stokes preconditioner
# 11: Schur complement iterations in Stokes preconditioner
# 12: RMS velocity (m/s)
# 13: Max. velocity (m/s)
# 14: Minimal value for composition anomaly
# 15: Maximal value for composition anomaly
# 16: Global mass for composition anomaly
# 17: Minimal value for composition function
# 18: Maximal value for composition function
# 19: Global mass for composition function
# 20: Number of advected particles
# 21: Number of advected particles (World 2)
# 22: Visualization file name
0 0.000000000000e+00 0.000000000000e+00 4 59 25 50 0 8 10 10 3.07552704e-03 4.65482045e-03 2.28550000e-01 6.85650000e-01 4.52704222e-01 0.00000000e+00 4.99913963e-01 1.90184427e-01 16 16 output-particle_multiple_worlds_interpolation/solution/solution-00000
Loading

0 comments on commit e746ba7

Please sign in to comment.