Skip to content

Commit

Permalink
Merge pull request #5253 from bangerth/fix-nans
Browse files Browse the repository at this point in the history
Do not leave NaN values in output vectors.
  • Loading branch information
tjhei committed Jul 11, 2023
2 parents 333c281 + 3b5106e commit 938a026
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
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
17 changes: 17 additions & 0 deletions tests/composition_active_nans.prm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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

include $ASPECT_SOURCE_DIR/tests/composition_active.prm

set End time = 0.1

subsection Postprocess
subsection Visualization
set List of output variables = density, artificial viscosity
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


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

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

0 comments on commit 938a026

Please sign in to comment.