Skip to content

Commit 8e26375

Browse files
committed
More DofMapBase APIs
Also, set n components to 0 for DofObjects for the reduced "system"
1 parent f38bbfb commit 8e26375

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

include/base/dof_map.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,7 @@ class DofMap : public DofMapBase,
661661
return (this->has_blocked_representation() ? this->n_variables() : 1);
662662
}
663663

664-
/**
665-
* \returns The total number of degrees of freedom in the problem.
666-
*/
667-
dof_id_type n_dofs() const { return _n_dfs; }
664+
dof_id_type n_dofs() const override { return _n_dfs; }
668665

669666
/**
670667
* \returns The total number of degrees of freedom for a particular
@@ -682,10 +679,7 @@ class DofMap : public DofMapBase,
682679
*/
683680
dof_id_type n_SCALAR_dofs() const { return _n_SCALAR_dofs; }
684681

685-
/**
686-
* \returns The number of degrees of freedom on this processor.
687-
*/
688-
dof_id_type n_local_dofs () const
682+
dof_id_type n_local_dofs () const override
689683
{ return this->n_dofs_on_processor (this->processor_id()); }
690684

691685
/**

include/base/dof_map_base.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ class DofMapBase
7474
virtual void dof_indices(const Node * const node,
7575
std::vector<dof_id_type> & di,
7676
const unsigned int vn) const = 0;
77+
/**
78+
* \returns The total number of degrees of freedom in the problem.
79+
*/
80+
virtual dof_id_type n_dofs() const = 0;
81+
82+
/**
83+
* \returns The number of degrees of freedom on this processor.
84+
*/
85+
virtual dof_id_type n_local_dofs() const = 0;
7786
};
7887

7988
}

include/numerics/static_condensation.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef Eigen::VectorXd EigenVector;
6464
class StaticCondensation : public PetscMatrixShellMatrix<Number>, public DofMapBase
6565
{
6666
public:
67-
StaticCondensation(const MeshBase & mesh, const System & system, const DofMap & dof_map);
67+
StaticCondensation(const MeshBase & mesh, System & system, const DofMap & dof_map);
6868
virtual ~StaticCondensation();
6969

7070
//
@@ -191,10 +191,6 @@ class StaticCondensation : public PetscMatrixShellMatrix<Number>, public DofMapB
191191

192192
virtual const Variable & variable(const unsigned int c) const override;
193193

194-
virtual dof_id_type first_dof() const override { return this->row_start(); }
195-
196-
virtual dof_id_type end_dof() const override { return this->row_stop(); }
197-
198194
virtual void dof_indices(const Elem * const elem,
199195
std::vector<dof_id_type> & di,
200196
const unsigned int vn,
@@ -204,11 +200,21 @@ class StaticCondensation : public PetscMatrixShellMatrix<Number>, public DofMapB
204200
std::vector<dof_id_type> & di,
205201
const unsigned int vn) const override;
206202

203+
virtual dof_id_type first_dof() const override;
204+
virtual dof_id_type end_dof() const override;
205+
virtual dof_id_type n_dofs() const override;
206+
virtual dof_id_type n_local_dofs() const override;
207+
207208
/**
208209
* @returns The reduced system linear solver
209210
*/
210211
LinearSolver<Number> & reduced_system_solver();
211212

213+
/*
214+
* @returns The dummyish reduced system
215+
*/
216+
const System & reduced_system() const;
217+
212218
private:
213219
/**
214220
* Retrieves the degree of freedom values from \p global_vector corresponding to \p
@@ -279,7 +285,7 @@ class StaticCondensation : public PetscMatrixShellMatrix<Number>, public DofMapB
279285
std::vector<dof_id_type> _local_uncondensed_dofs;
280286

281287
const MeshBase & _mesh;
282-
const System & _system;
288+
System & _system;
283289
const DofMap & _dof_map;
284290

285291
/// global sparse matrix for the uncondensed degrees of freedom
@@ -318,6 +324,9 @@ class StaticCondensation : public PetscMatrixShellMatrix<Number>, public DofMapB
318324

319325
/// The variables in the reduced system
320326
std::vector<Variable> _reduced_vars;
327+
328+
/// A dummyish system to help with DofObjects
329+
System * _reduced_system;
321330
};
322331

323332
inline const SparseMatrix<Number> & StaticCondensation::get_condensed_mat() const
@@ -337,6 +346,12 @@ inline LinearSolver<Number> & StaticCondensation::reduced_system_solver()
337346
return *_reduced_solver;
338347
}
339348

349+
inline const System & StaticCondensation::reduced_system() const
350+
{
351+
libmesh_assert(_reduced_system);
352+
return *_reduced_system;
353+
}
354+
340355
}
341356

342357
#else

src/numerics/static_condensation.C

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
#include "libmesh/elem.h"
2525
#include "libmesh/int_range.h"
2626
#include "libmesh/numeric_vector.h"
27-
#include "libmesh/petsc_matrix_base.h"
2827
#include "libmesh/linear_solver.h"
2928
#include "libmesh/static_condensation_preconditioner.h"
3029
#include "libmesh/system.h"
3130
#include "libmesh/petsc_matrix.h"
31+
#include "libmesh/equation_systems.h"
3232
#include "timpi/parallel_sync.h"
3333
#include <unordered_set>
3434

3535
namespace libMesh
3636
{
3737
StaticCondensation::StaticCondensation(const MeshBase & mesh,
38-
const System & system,
38+
System & system,
3939
const DofMap & dof_map)
4040
: PetscMatrixShellMatrix<Number>(dof_map.comm()),
4141
_mesh(mesh),
@@ -384,6 +384,20 @@ void StaticCondensation::init()
384384
// Build ghosted full solution vector. Note that this is, in general, *not equal* to the system
385385
// solution, e.g. this may correspond to the solution for the Newton *update*
386386
_ghosted_full_sol = _system.current_local_solution->clone();
387+
388+
// Prevent querying Nodes for dof indices
389+
std::vector<unsigned int> nvpg(_reduced_vars.size());
390+
for (auto & elem : nvpg)
391+
elem = 1;
392+
393+
_reduced_system = &_system.get_equation_systems().add_system("Basic", "reduced");
394+
_reduced_system->init();
395+
for (auto * const nd : _mesh.active_node_ptr_range())
396+
{
397+
nd->set_n_vars_per_group(_reduced_system->number(), nvpg);
398+
for (const auto g : index_range(nvpg))
399+
nd->set_n_comp_group(_reduced_system->number(), g, 0);
400+
}
387401
_sc_is_initialized = true;
388402
}
389403

@@ -673,6 +687,14 @@ void StaticCondensation::dof_indices(const Node * const,
673687
"StaticCondensation dof indices are only meant to be queried with elements, not nodes");
674688
}
675689

690+
dof_id_type StaticCondensation::first_dof() const { return _reduced_sys_mat->row_start(); }
691+
692+
dof_id_type StaticCondensation::end_dof() const { return _reduced_sys_mat->row_stop(); }
693+
694+
dof_id_type StaticCondensation::n_dofs() const { return _reduced_sys_mat->m(); }
695+
696+
dof_id_type StaticCondensation::n_local_dofs() const { return _reduced_sys_mat->local_m(); }
697+
676698
}
677699
#else
678700

0 commit comments

Comments
 (0)