From 61f4214ff5215b3a889c43c39a35ac5f1ff76243 Mon Sep 17 00:00:00 2001 From: Rene Gassmoeller Date: Fri, 4 Oct 2024 11:43:13 +0200 Subject: [PATCH] Add asserts and tests for multi interpolation --- source/simulator/initial_conditions.cc | 15 +++ ...particle_multiple_worlds_interpolation.prm | 102 +++++++++++++++ .../screen-output | 20 +++ .../solution/solution-00000.0000.gnuplot | 59 +++++++++ .../statistics | 23 ++++ ...e_multiple_worlds_interpolation_fail_1.prm | 116 ++++++++++++++++++ .../screen-output | 21 ++++ ...e_multiple_worlds_interpolation_fail_2.prm | 116 ++++++++++++++++++ .../screen-output | 19 +++ 9 files changed, 491 insertions(+) create mode 100644 tests/particle_multiple_worlds_interpolation.prm create mode 100644 tests/particle_multiple_worlds_interpolation/screen-output create mode 100644 tests/particle_multiple_worlds_interpolation/solution/solution-00000.0000.gnuplot create mode 100644 tests/particle_multiple_worlds_interpolation/statistics create mode 100644 tests/particle_multiple_worlds_interpolation_fail_1.prm create mode 100644 tests/particle_multiple_worlds_interpolation_fail_1/screen-output create mode 100644 tests/particle_multiple_worlds_interpolation_fail_2.prm create mode 100644 tests/particle_multiple_worlds_interpolation_fail_2/screen-output diff --git a/source/simulator/initial_conditions.cc b/source/simulator/initial_conditions.cc index f5d5227d9bc..5d63861e1eb 100644 --- a/source/simulator/initial_conditions.cc +++ b/source/simulator/initial_conditions.cc @@ -289,6 +289,11 @@ namespace aspect // A property component mask indicating for each particle world which particle properties need to be interpolated std::vector 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 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 &particle_property_manager = particle_worlds[world_index].get_property_manager(); @@ -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 same advection field is mapped to particle properties in different particle worlds. 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); } @@ -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

+0 0 0 0 10065.9 0 0.22855 0.499914 +0.22855 0 0 0 10057.2 0 0.22855 0.499914 +0.4571 0 0 0 10048.5 0 0.68565 0.498829 + +0 0.25 0 -0.00289142 7545.58 0 0.22855 0.499914 +0.22855 0.25 0.0038007 -0.00233646 7541.23 0 0.22855 0.499914 +0.4571 0.25 0.00402964 0.00129196 7536.89 0 0.68565 0.498829 + +0 0.5 0 -0.00505316 5025.24 0 0.22855 0 +0.22855 0.5 5.18286e-18 -0.00338219 5025.24 0 0.22855 0 +0.4571 0.5 3.26626e-19 0.00167668 5025.24 0 0.68565 0 + + +0.4571 0 0 0 10048.5 0 0.68565 0.498829 +0.68565 0 0 0 10043.7 0 0.68565 0.498829 +0.9142 0 0 0 10038.9 0 0.68565 0.498829 + +0.4571 0.25 0.00402964 0.00129196 7536.89 0 0.68565 0.498829 +0.68565 0.25 0.00252913 0.00207449 7534.49 0 0.68565 0.498829 +0.9142 0.25 0 0.00135537 7532.09 0 0.68565 0.498829 + +0.4571 0.5 3.26626e-19 0.00167668 5025.24 0 0.68565 0 +0.68565 0.5 -6.3755e-19 0.00314919 5025.24 0 0.68565 0 +0.9142 0.5 0 0.00263181 5025.24 0 0.68565 0 + + +0 0.5 0 -0.00505316 5025.24 0 0.22855 0 +0.22855 0.5 5.18286e-18 -0.00338219 5025.24 0 0.22855 0 +0.4571 0.5 3.26626e-19 0.00167668 5025.24 0 0.68565 0 + +0 0.75 0 -0.00289142 2504.9 0 0.22855 0 +0.22855 0.75 -0.0038007 -0.00233646 2509.25 0 0.22855 0 +0.4571 0.75 -0.00402964 0.00129196 2513.59 0 0.68565 0 + +0 1 0 0 -15.4369 0 0.22855 0 +0.22855 1 0 0 -6.745 0 0.22855 0 +0.4571 1 0 0 1.94688 0 0.68565 0 + + +0.4571 0.5 3.26626e-19 0.00167668 5025.24 0 0.68565 0 +0.68565 0.5 -6.3755e-19 0.00314919 5025.24 0 0.68565 0 +0.9142 0.5 0 0.00263181 5025.24 0 0.68565 0 + +0.4571 0.75 -0.00402964 0.00129196 2513.59 0 0.68565 0 +0.68565 0.75 -0.00252913 0.00207449 2515.99 0 0.68565 0 +0.9142 0.75 0 0.00135537 2518.39 0 0.68565 0 + +0.4571 1 0 0 1.94688 0 0.68565 0 +0.68565 1 0 0 6.745 0 0.68565 0 +0.9142 1 0 0 11.5431 0 0.68565 0 + + diff --git a/tests/particle_multiple_worlds_interpolation/statistics b/tests/particle_multiple_worlds_interpolation/statistics new file mode 100644 index 00000000000..404be48dc19 --- /dev/null +++ b/tests/particle_multiple_worlds_interpolation/statistics @@ -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 diff --git a/tests/particle_multiple_worlds_interpolation_fail_1.prm b/tests/particle_multiple_worlds_interpolation_fail_1.prm new file mode 100644 index 00000000000..b87454a146b --- /dev/null +++ b/tests/particle_multiple_worlds_interpolation_fail_1.prm @@ -0,0 +1,116 @@ +# Test that we can activate multiple particle worlds and +# interpolate properties from different particle worlds into +# the compositional fields. This test is supposed to fail +# because one of the necessary particle properties does not +# exist in any particle world. +# +# EXPECT FAILURE + +set Dimension = 2 +set End time = 1 +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 + +############### Parameters describing the temperature field +# Note: The temperature plays no role in this model + +subsection Initial temperature model + set Model name = function + + subsection Function + set Function expression = 0 + end +end + +############### Parameters describing the compositional field +# Note: The compositional field is what drives the flow +# in this example + +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 + +############### Parameters describing the discretization + +subsection Mesh refinement + set Initial adaptive refinement = 0 + set Strategy = composition + set Initial global refinement = 4 + set Time steps between mesh refinement = 0 + set Coarsening fraction = 0.05 + set Refinement fraction = 0.3 +end + +############### Parameters describing what to do with the solution + +subsection Postprocess + set List of postprocessors = velocity statistics, composition statistics, particles + + subsection Particles + set Time between data output = 70 + set Data output format = vtu + 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 diff --git a/tests/particle_multiple_worlds_interpolation_fail_1/screen-output b/tests/particle_multiple_worlds_interpolation_fail_1/screen-output new file mode 100644 index 00000000000..1a7fcc6765b --- /dev/null +++ b/tests/particle_multiple_worlds_interpolation_fail_1/screen-output @@ -0,0 +1,21 @@ + +Number of active cells: 256 (on 5 levels) +Number of degrees of freedom: 5,734 (2,178+289+1,089+1,089+1,089) + +*** Timestep 0: t=0 seconds, dt=0 seconds + Skipping temperature solve because RHS is zero. + Advecting particles... done. + Advecting particles... done. + +An error occurred in file in function +(line in output replaced by default.sh script) +The violated condition was: + advection_field_has_been_found[advection_field] == true +Additional information: + An compositional field is marked as advected by particles, but no + particle property exists that is mapped to this compositional field. + Make sure that the particle property exists and is mapped to the + compositional field in the parameter file. + +Stacktrace: +(rest of the output replaced by default.sh script) diff --git a/tests/particle_multiple_worlds_interpolation_fail_2.prm b/tests/particle_multiple_worlds_interpolation_fail_2.prm new file mode 100644 index 00000000000..09ceed3875e --- /dev/null +++ b/tests/particle_multiple_worlds_interpolation_fail_2.prm @@ -0,0 +1,116 @@ +# Test that we can activate multiple particle worlds and +# interpolate properties from different particle worlds into +# the compositional fields. This test is supposed to fail +# because one of the necessary particle properties exists +# in more than one particle world. +# +# EXPECT FAILURE + +set Dimension = 2 +set End time = 1 +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 + +############### Parameters describing the temperature field +# Note: The temperature plays no role in this model + +subsection Initial temperature model + set Model name = function + + subsection Function + set Function expression = 0 + end +end + +############### Parameters describing the compositional field +# Note: The compositional field is what drives the flow +# in this example + +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 + +############### Parameters describing the discretization + +subsection Mesh refinement + set Initial adaptive refinement = 0 + set Strategy = composition + set Initial global refinement = 4 + set Time steps between mesh refinement = 0 + set Coarsening fraction = 0.05 + set Refinement fraction = 0.3 +end + +############### Parameters describing what to do with the solution + +subsection Postprocess + set List of postprocessors = velocity statistics, composition statistics, particles + + subsection Particles + set Time between data output = 70 + set Data output format = vtu + end +end + +subsection Particles + set List of particle properties = function, 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 diff --git a/tests/particle_multiple_worlds_interpolation_fail_2/screen-output b/tests/particle_multiple_worlds_interpolation_fail_2/screen-output new file mode 100644 index 00000000000..ab9fca9bb2f --- /dev/null +++ b/tests/particle_multiple_worlds_interpolation_fail_2/screen-output @@ -0,0 +1,19 @@ + +Number of active cells: 256 (on 5 levels) +Number of degrees of freedom: 5,734 (2,178+289+1,089+1,089+1,089) + +*** Timestep 0: t=0 seconds, dt=0 seconds + Skipping temperature solve because RHS is zero. + Advecting particles... done. + Advecting particles... done. + +An error occurred in file in function +(line in output replaced by default.sh script) +The violated condition was: + advection_field_has_been_found[advection_field] == false +Additional information: + The same advection field is mapped to particle properties in different + particle worlds. This is not supported. + +Stacktrace: +(rest of the output replaced by default.sh script)