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

Add a signal before building patches for visualization output #5787

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/aspect/simulator_signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <aspect/parameters.h>

#include <deal.II/base/parameter_handler.h>
#include <deal.II/numerics/data_out.h>

#include <boost/signals2.hpp>

Expand Down Expand Up @@ -287,6 +288,15 @@ namespace aspect
boost::signals2::signal<void (const SimulatorAccess<dim> &,
aspect::Assemblers::Manager<dim> &)>
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<void (DataOut<dim> &)> pre_data_out_build_patches;
Comment on lines +292 to +299
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one way. I assume you want to use this to let the called function attach itself to the DataOut? Why not have a signal that returns a function object selecting individual cells that can then directly be attached to DoFHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As just discussed, we tried to keep the signal as general as possible as other things could be done with DataOut.

};


Expand Down
3 changes: 3 additions & 0 deletions source/postprocess/visualization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <aspect/global.h>
#include <aspect/utilities.h>
#include <aspect/simulator_access.h>
#include <aspect/simulator.h>
#include <aspect/geometry_model/interface.h>
#include <aspect/mesh_deformation/interface.h>
#include <deal.II/fe/mapping_q1_eulerian.h>
Expand Down Expand Up @@ -1018,6 +1019,8 @@ namespace aspect
(output_undeformed_mesh && dynamic_cast<const MappingQ1Eulerian<dim, LinearAlgebra::Vector>*>(&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;
Expand Down
45 changes: 45 additions & 0 deletions tests/pre_data_out_build_patches.cc
Original file line number Diff line number Diff line change
@@ -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
<http://www.gnu.org/licenses/>.
*/

#include <aspect/simulator_signals.h>
#include <aspect/simulator_access.h>

#include <iostream>

namespace aspect
{
template <int dim>
void pre_data_out_build_patches (DataOut<dim> &)
{
std::cout << "\npre_data_out_build_patches:\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this output is not triggered or am I wrong? Are you generating graphical output in every step?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is triggered. The test output I committed is still from the test I copied from. But you can see that "npre_data_out_build_patches:" is printed by the tester. See attached figure. I'll update with the results from the tester.
Screenshot 2024-06-05 at 16 58 25

}


template <int dim>
void signal_connector (SimulatorSignals<dim> &signals)
{
std::cout << "Connecting signals" << std::endl;
signals.pre_data_out_build_patches.connect (&pre_data_out_build_patches<dim>);
}


ASPECT_REGISTER_SIGNALS_CONNECTOR(signal_connector<2>,
signal_connector<3>)
}
72 changes: 72 additions & 0 deletions tests/pre_data_out_build_patches.prm
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions tests/pre_data_out_build_patches/screen-output
Original file line number Diff line number Diff line change
@@ -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



15 changes: 15 additions & 0 deletions tests/pre_data_out_build_patches/statistics
Original file line number Diff line number Diff line change
@@ -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