diff --git a/include/aspect/free_surface.h b/include/aspect/free_surface.h index 35d9379cd1c..03b10506e61 100644 --- a/include/aspect/free_surface.h +++ b/include/aspect/free_surface.h @@ -77,6 +77,12 @@ namespace aspect */ void execute(); + /** + * Called by Simulator::set_assemblers() to allow the FreeSurfaceHandler + * to register its assembler. + */ + void set_assemblers(); + /** * Allocates and sets up the members of the FreeSurfaceHandler. This * is called by Simulator::setup_dofs() diff --git a/include/aspect/simulator/assemblers/interface.h b/include/aspect/simulator/assemblers/interface.h index 0c0a82eae5a..1ace50077a9 100644 --- a/include/aspect/simulator/assemblers/interface.h +++ b/include/aspect/simulator/assemblers/interface.h @@ -587,6 +587,12 @@ namespace aspect class Manager { public: + + /** + * Reset the state of the manager and remove all Assemblers. + */ + void reset (); + /** * A vector of pointers containing all assemblers for the Stokes preconditioner. * These assemblers are called once per cell. diff --git a/source/simulator/assemblers/interface.cc b/source/simulator/assemblers/interface.cc index d9d6afb5c8c..18bb522a898 100644 --- a/source/simulator/assemblers/interface.cc +++ b/source/simulator/assemblers/interface.cc @@ -487,6 +487,16 @@ namespace aspect } + template + void Manager::reset () + { + stokes_preconditioner.clear(); + stokes_system.clear(); + stokes_system_on_boundary_face.clear(); + advection_system.clear(); + advection_system_on_boundary_face.clear(); + advection_system_on_interior_face.clear(); + } template Manager::Properties::Properties () diff --git a/source/simulator/assembly.cc b/source/simulator/assembly.cc index fe8573601e0..1f44b179dba 100644 --- a/source/simulator/assembly.cc +++ b/source/simulator/assembly.cc @@ -123,10 +123,12 @@ namespace aspect Simulator:: set_assemblers () { + // first let the manager delete all existing assemblers: + assemblers->reset(); + assemblers->advection_system_assembler_properties.resize(1+introspection.n_compositional_fields); assemblers->advection_system_assembler_on_face_properties.resize(1+introspection.n_compositional_fields); - if (parameters.include_melt_transport) { aspect::Assemblers::MeltStokesPreconditioner *preconditioner = new aspect::Assemblers::MeltStokesPreconditioner(); @@ -359,7 +361,11 @@ namespace aspect } } - // allow other assemblers to add themselves or modify the existing ones by firing the signal + // Let the free surface add its assembler: + if (parameters.free_surface_enabled) + free_surface->set_assemblers(); + + // Finally allow other assemblers to add themselves or modify the existing ones by firing the signal this->signals.set_assemblers(*this, *assemblers); // ensure that all assembler objects have access to the SimulatorAccess diff --git a/source/simulator/free_surface.cc b/source/simulator/free_surface.cc index 903819e2172..65922ddffcd 100644 --- a/source/simulator/free_surface.cc +++ b/source/simulator/free_surface.cc @@ -134,7 +134,23 @@ namespace aspect free_surface_dof_handler (sim.triangulation) { parse_parameters(prm); + } + + template + FreeSurfaceHandler::~FreeSurfaceHandler () + { + // Free the Simulator's mapping object, otherwise + // when the FreeSurfaceHandler gets destroyed, + // the mapping's reference to the mesh displacement + // vector will be invalid. + sim.mapping.reset(); + } + + + template + void FreeSurfaceHandler::set_assemblers() + { aspect::Assemblers::ApplyStabilization *surface_stabilization = new aspect::Assemblers::ApplyStabilization(); @@ -153,16 +169,6 @@ namespace aspect update_JxW_values); } - template - FreeSurfaceHandler::~FreeSurfaceHandler () - { - // Free the Simulator's mapping object, otherwise - // when the FreeSurfaceHandler gets destroyed, - // the mapping's reference to the mesh displacement - // vector will be invalid. - sim.mapping.reset(); - } - template void FreeSurfaceHandler::declare_parameters(ParameterHandler &prm) { diff --git a/source/simulator/solver_schemes.cc b/source/simulator/solver_schemes.cc index 586f6a4aa60..8056e2ca0a6 100644 --- a/source/simulator/solver_schemes.cc +++ b/source/simulator/solver_schemes.cc @@ -528,7 +528,6 @@ namespace aspect if (nonlinear_iteration <= 1) { - assemblers.reset (new internal::Assembly::AssemblerLists()); set_assemblers(); compute_current_constraints (); }