diff --git a/include/aspect/simulator_signals.h b/include/aspect/simulator_signals.h index dc92a97826f..a68c64a209f 100644 --- a/include/aspect/simulator_signals.h +++ b/include/aspect/simulator_signals.h @@ -27,6 +27,7 @@ #include #include +#include #include @@ -287,6 +288,15 @@ namespace aspect boost::signals2::signal &, aspect::Assemblers::Manager &)> set_assemblers; + + /** + * A signal that is called before the build_patches() function is called during + * the creation of the visualization output. This signal + * allows for registering functions that take a DataOut object and can for example + * be used to select only certain cells of the mesh to be built into patches through + * calling the DataOut member function set_cell_selection(). + */ + boost::signals2::signal &)> pre_data_out_build_patches; }; diff --git a/source/postprocess/visualization.cc b/source/postprocess/visualization.cc index d37b1db18f4..7cacc5a6f15 100644 --- a/source/postprocess/visualization.cc +++ b/source/postprocess/visualization.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1018,6 +1019,8 @@ namespace aspect (output_undeformed_mesh && dynamic_cast*>(&this->get_mapping())) ? (linear_mapping) : (this->get_mapping()); + this->get_signals().pre_data_out_build_patches (data_out); + // Now get everything written for the DataOut case, and record this // in the statistics file std::string solution_file_prefix; diff --git a/tests/pre_data_out_build_patches.cc b/tests/pre_data_out_build_patches.cc new file mode 100644 index 00000000000..69dd5dd1148 --- /dev/null +++ b/tests/pre_data_out_build_patches.cc @@ -0,0 +1,45 @@ +/* + Copyright (C) 2022 by the authors of the ASPECT code. + + This file is part of ASPECT. + + ASPECT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + ASPECT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ASPECT; see the file LICENSE. If not see + . +*/ + +#include +#include + +#include + +namespace aspect +{ + template + void pre_data_out_build_patches (DataOut &) + { + std::cout << "\npre_data_out_build_patches:\n"; + } + + + template + void signal_connector (SimulatorSignals &signals) + { + std::cout << "Connecting signals" << std::endl; + signals.pre_data_out_build_patches.connect (&pre_data_out_build_patches); + } + + + ASPECT_REGISTER_SIGNALS_CONNECTOR(signal_connector<2>, + signal_connector<3>) +} diff --git a/tests/pre_data_out_build_patches.prm b/tests/pre_data_out_build_patches.prm new file mode 100644 index 00000000000..63eab17f78a --- /dev/null +++ b/tests/pre_data_out_build_patches.prm @@ -0,0 +1,72 @@ +# A copy of stokes_solver.prm +# to test the pre_data_out_build_patches signal +# in visualization.cc. + +set Dimension = 2 +set CFL number = 1.0 +set End time = 0.1 +set Start time = 0 +set Adiabatic surface temperature = 0 +set Surface pressure = 0 +set Use years in output instead of seconds = false +set Nonlinear solver scheme = single Advection, single Stokes + +subsection Boundary temperature model + set List of model names = box + set Fixed temperature boundary indicators = 0, 1 +end + +subsection Gravity model + set Model name = vertical +end + +subsection Geometry model + set Model name = box + + subsection Box + set X extent = 1.2 + set Y extent = 1 + set Z extent = 1 + end +end + +subsection Initial temperature model + set Model name = perturbed box +end + +subsection Material model + set Model name = simpler + + subsection Simpler model + set Reference density = 1 + set Reference specific heat = 1250 + set Reference temperature = 1 + set Thermal conductivity = 1e-6 + set Thermal expansion coefficient = 2e-5 + set Viscosity = 1 + end +end + +subsection Mesh refinement + set Initial adaptive refinement = 0 + set Initial global refinement = 5 +end + +subsection Boundary velocity model + set Tangential velocity boundary indicators = 1 + set Zero velocity boundary indicators = 0, 2, 3 +end + +subsection Postprocess + set List of postprocessors = visualization, velocity statistics + + subsection Visualization + set List of output variables = density, viscosity + end +end + +subsection Solver parameters + subsection Stokes solver parameters + set Number of cheap Stokes solver steps = 30 + end +end diff --git a/tests/pre_data_out_build_patches/screen-output b/tests/pre_data_out_build_patches/screen-output new file mode 100644 index 00000000000..f785eaf077f --- /dev/null +++ b/tests/pre_data_out_build_patches/screen-output @@ -0,0 +1,29 @@ + +Loading shared library <./libpre_data_out_build_patches.debug.so> + +Connecting signals +Number of active cells: 1,024 (on 6 levels) +Number of degrees of freedom: 13,764 (8,450+1,089+4,225) + +*** Timestep 0: t=0 seconds, dt=0 seconds + Solving temperature system... 0 iterations. + Rebuilding Stokes preconditioner... + Solving Stokes system... 30+7 iterations. + + Postprocessing: + +pre_data_out_build_patches: + Writing graphical output: output-pre_data_out_build_patches/solution/solution-00000 + RMS, max velocity: 9e-09 m/s, 3.23e-08 m/s + +*** Timestep 1: t=0.1 seconds, dt=0.1 seconds + Solving temperature system... 4 iterations. + Solving Stokes system... 8+0 iterations. + + Postprocessing: + RMS, max velocity: 9e-09 m/s, 3.23e-08 m/s + +Termination requested by criterion: end time + + + diff --git a/tests/pre_data_out_build_patches/statistics b/tests/pre_data_out_build_patches/statistics new file mode 100644 index 00000000000..ded0d29d309 --- /dev/null +++ b/tests/pre_data_out_build_patches/statistics @@ -0,0 +1,15 @@ +# 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: Iterations for temperature solver +# 8: Iterations for Stokes solver +# 9: Velocity iterations in Stokes preconditioner +# 10: Schur complement iterations in Stokes preconditioner +# 11: Visualization file name +# 12: RMS velocity (m/s) +# 13: Max. velocity (m/s) +0 0.000000000000e+00 0.000000000000e+00 1024 9539 4225 0 37 85 38 output-pre_data_out_build_patches/solution/solution-00000 9.00076484e-09 3.23376827e-08 +1 1.000000000000e-01 1.000000000000e-01 1024 9539 4225 4 7 9 9 "" 9.00076831e-09 3.23376980e-08