Fluid structure interaction suite
lac_initializer.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef fsi_lac_initializer_h
17 #define fsi_lac_initializer_h
18 
19 // This includes all types we know of.
20 #include <mpi.h>
21 
22 #include "lac.h"
23 
24 namespace LAC
25 {
31  {
32  public:
34  const std::vector<dealii::types::global_dof_index> &dofs_per_block,
35  const std::vector<dealii::IndexSet> &owned,
36  const std::vector<dealii::IndexSet> &relevant,
37  const MPI_Comm &comm = MPI_COMM_WORLD)
39  , owned(owned)
41  , comm(comm){};
42 
46  void
47  operator()(LATrilinos::BlockVector &v, bool fast = false)
48  {
49  v.reinit(owned, comm, fast);
50  };
51 
52 
56  void
57  ghosted(LATrilinos::BlockVector &v, bool fast = false)
58  {
59  v.reinit(owned, relevant, comm, fast);
60  };
61 
65  void
66  operator()(LAPETSc::BlockVector &v, bool fast = false)
67  {
68  (void)fast;
69  v.reinit(owned, comm);
70  };
71 
72 
76  void
77  ghosted(LAPETSc::BlockVector &v, bool fast = false)
78  {
79  (void)fast;
81  };
82 
86  void
87  operator()(LAdealii::BlockVector &v, bool fast = false)
88  {
89  v.reinit(dofs_per_block, fast);
90  };
91 
92 
96  void
97  ghosted(LAdealii::BlockVector &v, bool fast = false)
98  {
99  v.reinit(dofs_per_block, fast);
100  };
101 
105  template <int dim, int spacedim>
106  void
107  operator()(dealii::TrilinosWrappers::BlockSparsityPattern &s,
108  const dealii::DoFHandler<dim, spacedim> &dh,
109  const dealii::AffineConstraints<double> &cm,
110  const dealii::Table<2, dealii::DoFTools::Coupling> &coupling)
111  {
112  s.reinit(owned, owned, relevant, comm);
114  dh,
115  coupling,
116  s,
117  cm,
118  false,
119  dealii::Utilities::MPI::this_mpi_process(comm));
120  s.compress();
121  }
122 
126  template <int dim, int spacedim>
127  void
128  operator()(dealii::BlockSparsityPattern &s,
129  const dealii::DoFHandler<dim, spacedim> &dh,
130  const dealii::AffineConstraints<double> &cm,
131  const dealii::Table<2, dealii::DoFTools::Coupling> &coupling)
132  {
133  dsp =
134  std::make_unique<dealii::BlockDynamicSparsityPattern>(dofs_per_block,
136 
137  dealii::DoFTools::make_sparsity_pattern(dh, coupling, *dsp, cm, false);
138  dsp->compress();
139  s.copy_from(*dsp);
140  }
141 
145  void
148  {
149  matrix.reinit(sparsity);
150  };
151 
152 
156  void
159  {
160  matrix.reinit(sparsity);
161  };
162 
163 
164 
168  void
171  {
173  matrix.reinit(owned, *dsp, comm);
174  };
175 
176 
177  private:
181  std::unique_ptr<dealii::BlockDynamicSparsityPattern> dsp;
182 
186  const std::vector<dealii::types::global_dof_index> &dofs_per_block;
187 
191  const std::vector<dealii::IndexSet> &owned;
192 
196  const std::vector<dealii::IndexSet> &relevant;
197 
201  const MPI_Comm &comm;
202  };
203 
209  {
210  public:
211  Initializer(const dealii::IndexSet &owned_rows,
212  const dealii::IndexSet &relevant_rows,
213  const MPI_Comm &comm = MPI_COMM_WORLD,
214  const dealii::IndexSet &owned_columns = dealii::IndexSet(),
215  const dealii::IndexSet &relevant_columns = dealii::IndexSet())
218  , comm(comm)
221  relevant_rows){};
222 
226  void
227  operator()(LATrilinos::Vector &v, bool fast = false)
228  {
229  v.reinit(owned_rows, comm, fast);
230  };
231 
232 
236  void
237  ghosted(LATrilinos::Vector &v, bool fast = false)
238  {
239  v.reinit(owned_rows, relevant_rows, comm, fast);
240  };
241 
245  void
246  operator()(LAPETSc::Vector &v, bool fast = false)
247  {
248  (void)fast;
249  v.reinit(owned_rows, comm);
250  };
251 
252 
256  void
257  ghosted(LAPETSc::Vector &v, bool fast = false)
258  {
259  (void)fast;
261  };
262 
266  void
267  operator()(LAdealii::Vector &v, bool fast = false)
268  {
269  v.reinit(owned_rows.size(), fast);
270  };
271 
272 
276  void
277  ghosted(LAdealii::Vector &v, bool fast = false)
278  {
279  v.reinit(owned_rows.size(), fast);
280  };
281 
285  void
286  operator()(dealii::TrilinosWrappers::SparsityPattern &s)
287  {
288  s.reinit(owned_rows, owned_columns, comm);
289  }
290 
294  void
295  operator()(dealii::SparsityPattern &s)
296  {
297  s.reinit(owned_rows.size(), owned_columns.size(), 0);
298  }
299 
303  template <int dim, int spacedim>
304  void
305  operator()(dealii::TrilinosWrappers::SparsityPattern &s,
306  const dealii::DoFHandler<dim, spacedim> &dh,
307  const dealii::AffineConstraints<double> &cm,
308  const dealii::Table<2, dealii::DoFTools::Coupling> &coupling)
309  {
312  dh,
313  coupling,
314  s,
315  cm,
316  false,
317  dealii::Utilities::MPI::this_mpi_process(comm));
318  s.compress();
319  }
320 
324  template <int dim, int spacedim>
325  void
326  operator()(dealii::SparsityPattern &s,
327  const dealii::DoFHandler<dim, spacedim> &dh,
328  const dealii::AffineConstraints<double> &cm,
329  const dealii::Table<2, dealii::DoFTools::Coupling> &coupling)
330  {
331  dsp =
332  std::make_unique<dealii::DynamicSparsityPattern>(owned_rows.size(),
333  owned_columns.size());
334 
335  dealii::DoFTools::make_sparsity_pattern(dh, coupling, *dsp, cm, false);
336  dsp->compress();
337  s.copy_from(*dsp);
338  }
339 
343  void
345  LAdealii::SparseMatrix &matrix)
346  {
347  matrix.reinit(sparsity);
348  };
349 
350 
354  void
356  LATrilinos::SparseMatrix &matrix)
357  {
358  matrix.reinit(sparsity);
359  };
360 
361 
362 
366  void
368  LAPETSc::SparseMatrix &matrix)
369  {
370  matrix.reinit(owned_rows, owned_columns, sparsity, comm);
371  };
372 
373 
374  private:
378  std::unique_ptr<dealii::DynamicSparsityPattern> dsp;
379 
383  const dealii::IndexSet owned_rows;
384  const dealii::IndexSet relevant_rows;
388  const MPI_Comm &comm;
389 
393  const dealii::IndexSet owned_columns;
394  const dealii::IndexSet relevant_columns;
395  };
396 } // namespace LAC
397 #endif
void reinit(const unsigned int n_blocks, const size_type block_size=0, const bool omit_zeroing_entries=false)
size_type size() const
void reinit(const MPI_Comm communicator, const size_type N, const size_type locally_owned_size, const bool omit_zeroing_entries=false)
void reinit(const std::vector< IndexSet > &parallel_partitioning, const MPI_Comm communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
void reinit(const Vector &v, const bool omit_zeroing_entries=false, const bool allow_different_maps=false)
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
General class, used to initialize different types of block vectors, block atrices and block sparsity ...
void operator()(const LAPETSc::BlockSparsityPattern &, LAPETSc::BlockSparseMatrix &matrix)
Initialize a PETSc matrix.
BlockInitializer(const std::vector< types::global_dof_index > &dofs_per_block, const std::vector< IndexSet > &owned, const std::vector< IndexSet > &relevant, const MPI_Comm &comm=MPI_COMM_WORLD)
void operator()(const LABlockSparsityPattern &sparsity, LABlockSparseMatrix &matrix)
Initialize a deal.II matrix.
void operator()(LAPETSc::BlockVector &v, bool fast=false)
Initialize a non ghosted TrilinosWrappers::MPI::BlockVector.
void ghosted(LABlockVector &v, bool fast=false)
Initiale a ghosted BlockVector<double>.
void operator()(BlockSparsityPattern &s, const DoFHandler< dim, spacedim > &dh, const AffineConstraints< double > &cm, const Table< 2, DoFTools::Coupling > &coupling)
Initialize a Deal.II Sparsity Pattern.
void ghosted(LATrilinos::BlockVector &v, bool fast=false)
Initialize a ghosted TrilinosWrappers::MPI::BlockVector.
const MPI_Comm & comm
MPI Communicator.
void operator()(LABlockVector &v, bool fast=false)
Initialize a serial BlockVector<double>.
const std::vector< IndexSet > & relevant
Relevant dofs per block.
void operator()(TrilinosWrappers::BlockSparsityPattern &s, const DoFHandler< dim, spacedim > &dh, const AffineConstraints< double > &cm, const Table< 2, DoFTools::Coupling > &coupling)
Initialize a Trilinos Sparsity Pattern.
const std::vector< types::global_dof_index > & dofs_per_block
Dofs per block.
void operator()(LATrilinos::BlockVector &v, bool fast=false)
Initialize a non ghosted TrilinosWrappers::MPI::BlockVector.
void operator()(const LATrilinos::BlockSparsityPattern &sparsity, LATrilinos::BlockSparseMatrix &matrix)
Initialize a Trilinos matrix.
std::unique_ptr< BlockDynamicSparsityPattern > dsp
The dynamic sparisty pattern.
const std::vector< IndexSet > & owned
Owned dofs per block.
void ghosted(LAPETSc::BlockVector &v, bool fast=false)
Initialize a ghosted TrilinosWrappers::MPI::BlockVector.
General class, used to initialize different types of block vectors, block atrices and block sparsity ...
void ghosted(LATrilinos::Vector &v, bool fast=false)
Initialize a ghosted TrilinosWrappers::MPI::Vector.
std::unique_ptr< DynamicSparsityPattern > dsp
The dynamic sparisty pattern.
const IndexSet relevant_columns
const IndexSet relevant_rows
void operator()(LAVector &v, bool fast=false)
Initialize a serial BlockVector<double>.
void ghosted(LAPETSc::Vector &v, bool fast=false)
Initialize a ghosted TrilinosWrappers::MPI::Vector.
void operator()(LAPETSc::Vector &v, bool fast=false)
Initialize a non ghosted TrilinosWrappers::MPI::Vector.
Initializer(const IndexSet &owned_rows, const IndexSet &relevant_rows, const MPI_Comm &comm=MPI_COMM_WORLD, const IndexSet &owned_columns=IndexSet(), const IndexSet &relevant_columns=IndexSet())
const IndexSet owned_columns
Relevant dofs.
void operator()(LATrilinos::Vector &v, bool fast=false)
Initialize a non ghosted TrilinosWrappers::MPI::BlockVector.
void ghosted(LAVector &v, bool fast=false)
Initiale a ghosted BlockVector<double>.
void operator()(const LAPETSc::SparsityPattern &sparsity, LAPETSc::SparseMatrix &matrix)
Initialize a PETSc matrix.
void operator()(TrilinosWrappers::SparsityPattern &s)
Initialize a Trilinos Sparsity Pattern.
void operator()(SparsityPattern &s)
Initialize a deal.II Sparsity Pattern.
const MPI_Comm & comm
MPI Communicator.
const IndexSet owned_rows
Owned dofs.
void operator()(SparsityPattern &s, const DoFHandler< dim, spacedim > &dh, const AffineConstraints< double > &cm, const Table< 2, DoFTools::Coupling > &coupling)
Initialize a Deal.II Sparsity Pattern.
void operator()(const LATrilinos::SparsityPattern &sparsity, LATrilinos::SparseMatrix &matrix)
Initialize a Trilinos matrix.
void operator()(TrilinosWrappers::SparsityPattern &s, const DoFHandler< dim, spacedim > &dh, const AffineConstraints< double > &cm, const Table< 2, DoFTools::Coupling > &coupling)
Initialize a Trilinos Sparsity Pattern.
void operator()(const LASparsityPattern &sparsity, LASparseMatrix &matrix)
Initialize a deal.II matrix.
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotInitialized()
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
Wrappers for linear algebra classes.
Definition: lac.h:62
SparsityPattern SparsityPattern
Definition: lac.h:99
BlockSparsityPattern BlockSparsityPattern
Definition: lac.h:102
BlockSparsityPattern BlockSparsityPattern
Definition: lac.h:76
SparsityPattern SparsityPattern
Definition: lac.h:75