Skip to content

Commit

Permalink
Allow requesting static condensation from code
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayad committed Sep 24, 2024
1 parent 375e071 commit 0b22214
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 20 deletions.
11 changes: 2 additions & 9 deletions examples/miscellaneous/miscellaneous_ex16/miscellaneous_ex16.C
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,8 @@ Real exact_solution(const Real x, const Real y, const Real z = 0.);
int
main(int argc, char ** argv)
{
std::vector<char *> mod_argv(argv, argv + argc);
const char * sc_arg = "--Poisson2-static-condensation";
mod_argv.push_back(new char[std::strlen(sc_arg) + 1]);
std::strcpy(mod_argv.back(), sc_arg);

// Initialize libraries, like in example 2.
LibMeshInit init(argc + 1, mod_argv.data());
LibMeshInit init(argc, argv);

// This example requires a linear solver package.
libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
Expand Down Expand Up @@ -154,6 +149,7 @@ main(int argc, char ** argv)
auto & sc_sys = equation_systems.add_system<LinearImplicitSystem>("Poisson2");
sc_sys.add_variable("u", SECOND);
sc_sys.attach_assemble_function(assemble_poisson);
sc_sys.create_static_condensation();

// Initialize the data structures for the equation system.
equation_systems.init();
Expand Down Expand Up @@ -183,9 +179,6 @@ main(int argc, char ** argv)

#endif // #ifdef LIBMESH_HAVE_VTK

for (const auto i : make_range(argc, argc + 1))
delete[] mod_argv[i];

// All done.
return 0;
}
Expand Down
10 changes: 7 additions & 3 deletions include/systems/implicit_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,13 @@ class ImplicitSystem : public ExplicitSystem
mutable std::unique_ptr<LinearSolver<Number>> linear_solver;

/**
* Retrieve the static condensation class. Errors if the user has not
* requested it on the command line, so calls to this should be guarded by
* checking \p has_static_condensation()
* Request that static condensation be performed for this system
*/
virtual void create_static_condensation();

/**
* Retrieve the static condensation class. Errors if \p create_static_condensation() has not been
* called prior, so calls to this should be guarded by checking \p has_static_condensation()
*/
StaticCondensation & get_static_condensation();

Expand Down
2 changes: 2 additions & 0 deletions include/systems/linear_implicit_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ class LinearImplicitSystem : public ImplicitSystem
*/
ShellMatrix<Number> * get_shell_matrix() { return _shell_matrix; }

virtual void create_static_condensation() override;

protected:

/**
Expand Down
1 change: 1 addition & 0 deletions include/systems/nonlinear_implicit_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class NonlinearImplicitSystem : public ImplicitSystem
*/
unsigned get_current_nonlinear_iteration_number() const;

virtual void create_static_condensation() override;

protected:

Expand Down
17 changes: 11 additions & 6 deletions src/systems/implicit_system.C
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ ImplicitSystem::ImplicitSystem (EquationSystems & es,
_sc (nullptr)
{
if (libMesh::on_command_line("--" + name_in + "-static-condensation"))
{
auto sc = std::make_unique<StaticCondensation>(this->get_mesh(), *this, this->get_dof_map());
_sc = sc.get();
matrix = &(this->add_matrix ("System Matrix", std::move(sc)));
this->get_dof_map().add_static_condensation(*_sc);
}
this->create_static_condensation();
}

ImplicitSystem::~ImplicitSystem () = default;



void ImplicitSystem::create_static_condensation ()
{
auto sc = std::make_unique<StaticCondensation>(this->get_mesh(), *this, this->get_dof_map());
_sc = sc.get();
matrix = &(this->add_matrix ("System Matrix", std::move(sc)));
this->get_dof_map().add_static_condensation(*_sc);
}



void ImplicitSystem::clear ()
{
// clear the parent data
Expand Down
10 changes: 8 additions & 2 deletions src/systems/linear_implicit_system.C
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ LinearImplicitSystem::LinearImplicitSystem (EquationSystems & es,
// going to keep using it basically the way we did before it was
// moved.
linear_solver = LinearSolver<Number>::build(es.comm());
if (_sc)
linear_solver->attach_preconditioner(&_sc->get_preconditioner());
}


Expand All @@ -59,6 +57,14 @@ LinearImplicitSystem::~LinearImplicitSystem () = default;



void LinearImplicitSystem::create_static_condensation()
{
Parent::create_static_condensation();
linear_solver->attach_preconditioner(&_sc->get_preconditioner());
}



void LinearImplicitSystem::clear ()
{
// clear the linear solver
Expand Down
8 changes: 8 additions & 0 deletions src/systems/nonlinear_implicit_system.C
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ NonlinearImplicitSystem::~NonlinearImplicitSystem () = default;



void NonlinearImplicitSystem::create_static_condensation()
{
Parent::create_static_condensation();
nonlinear_solver->attach_preconditioner(&_sc->get_preconditioner());
}



void NonlinearImplicitSystem::clear ()
{
// clear the nonlinear solver
Expand Down

0 comments on commit 0b22214

Please sign in to comment.