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

Do not leave NaN values in output vectors. #5253

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/modules/changes/20230710_bangerth
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed:
When using the 'artificial viscosity' visualization postprocessor in parallel,
we used to put NaNs into the output vector (for ghost and artificial
cells) that then triggered floating point exceptions. This is now fixed.
<br>
(Wolfgang Bangerth, 2023/07/10)
13 changes: 13 additions & 0 deletions source/postprocess/visualization/artificial_viscosity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ namespace aspect
return_value ("artificial_viscosity",
new Vector<float>(this->get_triangulation().n_active_cells()));
this->get_artificial_viscosity(*return_value.second);

// The function we call above sets the artificial viscosity to
// signaling_nan on all artificial cells and, possibly, ghost cells.
// This runs into trouble in DataOut that wants to copy this vector
// from Vector<float> to Vector<double>, and the conversion trips
// up over the NaNs, causing a floating point exception.
//
// To avoid this, strip out the NaNs and instead set these values
// to zero -- we won't be outputting these values anyway.
for (const auto &cell : this->get_triangulation().active_cell_iterators())
if (cell->is_locally_owned() == false)
(*return_value.second)[cell->active_cell_index()] = 0;

return return_value;
}
}
Expand Down
132 changes: 132 additions & 0 deletions tests/composition_active_nans.prm
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# When using the 'artificial viscosity' viz postprocessor in parallel,
# we used to put NaNs into the output vector (for ghost and artificial
# cells) that then triggered floating point exceptions. Check that
# this no longer happens. For this, all we need to do is get past the
# first time we create graphical output.

# MPI: 2

set Dimension = 2
set Start time = 0
set End time = 0.1
set Use years in output instead of seconds = false



subsection Geometry model
set Model name = box

subsection Box
set X extent = 2
set Y extent = 1
end
end


# The parameters below this comment were created by the update script
# as replacement for the old 'Model settings' subsection. They can be
# safely merged with any existing subsections with the same name.

subsection Boundary temperature model
set Fixed temperature boundary indicators = 2, 3
end

subsection Boundary velocity model
set Tangential velocity boundary indicators = 0, 1, 2
end

subsection Boundary velocity model
set Prescribed velocity boundary indicators = 3: function
end

subsection Heating model
set List of model names = shear heating
end

subsection Boundary temperature model
set List of model names = box

subsection Box
set Bottom temperature = 1
set Top temperature = 0
end
end


subsection Boundary velocity model
subsection Function
set Variable names = x,z,t
set Function constants = pi=3.1415926
set Function expression = if(x>1+sin(0.5*pi*t), 1, -1); 0
end
end


subsection Gravity model
set Model name = vertical
end


subsection Initial temperature model
set Model name = function

subsection Function
set Variable names = x,z
set Function expression = (1-z)
end
end


# Compared to the passive material model, we here make
# the density composition dependent by letting it depend
# linearly on the value of the first compositional field.
subsection Material model
set Model name = simple

subsection Simple model
set Thermal conductivity = 1e-6
set Thermal expansion coefficient = 0.01
set Viscosity = 1
set Reference density = 1
set Reference temperature = 0
set Density differential for compositional field 1 = 100
end
end


subsection Mesh refinement
set Initial adaptive refinement = 0
set Initial global refinement = 3
set Time steps between mesh refinement = 0
end


subsection Postprocess
set List of postprocessors = visualization, temperature statistics, composition statistics

subsection Visualization
set Interpolate output = false
set List of output variables = density, artificial viscosity
set Time between graphical output = 0.1
end
end


# This is the new part: We declare that there will
# be two compositional fields that will be
# advected along. Their initial conditions are given by
# a function that is one for the lowermost 0.2 height
# units of the domain and zero otherwise in the first case,
# and one in the top most 0.2 height units in the latter.
subsection Compositional fields
set Number of fields = 2
end

subsection Initial composition model
set Model name = function

subsection Function
set Variable names = x,y
set Function expression = if(y<0.2, 1, 0) ; if(y>0.8, 1, 0)
end
end
52 changes: 52 additions & 0 deletions tests/composition_active_nans/screen-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Number of active cells: 64 (on 4 levels)
Number of degrees of freedom: 1,526 (578+81+289+289+289)

*** Timestep 0: t=0 seconds, dt=0 seconds
Solving temperature system... 0 iterations.
Solving C_1 system ... 0 iterations.
Solving C_2 system ... 0 iterations.
Rebuilding Stokes preconditioner...
Solving Stokes system... 17+0 iterations.

Postprocessing:
Writing graphical output: output-composition_active_nans/solution/solution-00000
Temperature min/avg/max: 0 K, 0.5 K, 1 K
Compositions min/max/mass: 0/1/0.4583 // 0/1/0.4583

*** Timestep 1: t=0.0625 seconds, dt=0.0625 seconds
Solving temperature system... 10 iterations.
Solving C_1 system ... 11 iterations.
Solving C_2 system ... 12 iterations.
Rebuilding Stokes preconditioner...
Solving Stokes system... 14+0 iterations.

Postprocessing:
Temperature min/avg/max: 0 K, 0.5013 K, 1 K
Compositions min/max/mass: -0.006514/1.046/0.4591 // -0.01597/1.028/0.4583

*** Timestep 2: t=0.1 seconds, dt=0.0375 seconds
Solving temperature system... 10 iterations.
Solving C_1 system ... 12 iterations.
Solving C_2 system ... 12 iterations.
Rebuilding Stokes preconditioner...
Solving Stokes system... 17+0 iterations.

Postprocessing:
Writing graphical output: output-composition_active_nans/solution/solution-00001
Temperature min/avg/max: 0 K, 0.5021 K, 1 K
Compositions min/max/mass: -0.008189/1.059/0.4595 // -0.02059/1.033/0.4583

Termination requested by criterion: end time


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

-----------------------------------------------------------------------------
-----------------------------------------------------------------------------