Skip to content

Commit 374cac9

Browse files
committed
PETSc
1 parent fd6f9c2 commit 374cac9

File tree

7 files changed

+177
-7
lines changed

7 files changed

+177
-7
lines changed

include/base_interface.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class BaseInterface : public ParameterAcceptor, public SimulatorAccess<dim,space
194194
FEValuesCache<dim,spacedim> &scratch,
195195
CopyData &data) const;
196196

197+
#ifdef DEAL_II_WITH_TRILINOS
197198
/**
198199
* Compute linear operators needed by the problem: - @p system_op
199200
* represents the system matrix associated to the Newton's
@@ -226,6 +227,14 @@ class BaseInterface : public ParameterAcceptor, public SimulatorAccess<dim,space
226227
LinearOperator<LATrilinos::VectorType> &system_op,
227228
LinearOperator<LATrilinos::VectorType> &prec_op,
228229
LinearOperator<LATrilinos::VectorType> &prec_op_finer) const;
230+
#endif //DEAL_II_WITH_TRILINOS
231+
232+
#ifdef DEAL_II_WITH_PETSC
233+
virtual void compute_system_operators(const std::vector<shared_ptr<typename LAPETSc::BlockMatrix> >,
234+
LinearOperator<LAPETSc::VectorType> &system_op,
235+
LinearOperator<LAPETSc::VectorType> &prec_op,
236+
LinearOperator<LAPETSc::VectorType> &prec_op_finer) const;
237+
#endif //DEAL_II_WITH_PETSC
229238

230239
/**
231240
* Compute linear operators needed by the problem. When using

include/lac/lac_initializer.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ScopedLACInitializer
2222
comm(comm)
2323
{};
2424

25+
#ifdef DEAL_II_WITH_TRILINOS
2526
/**
2627
* Initialize a non ghosted TrilinosWrappers::MPI::BlockVector.
2728
*/
@@ -30,14 +31,60 @@ class ScopedLACInitializer
3031
v.reinit(owned, comm, fast);
3132
};
3233

34+
/**
35+
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
36+
*/
37+
void operator() (TrilinosWrappers::BlockSparseMatrix &M, TrilinosWrappers::BlockSparsityPattern &sp, bool fast=false)
38+
{
39+
M.reinit(sp);
40+
};
41+
#endif // DEAL_II_WITH_TRILINOS
42+
43+
#ifdef DEAL_II_WITH_PETSC
44+
/**
45+
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
46+
*/
47+
void operator() (PETScWrappers::MPI::BlockVector &v, bool fast=false)
48+
{
49+
v.reinit(owned, comm);
50+
};
51+
52+
/**
53+
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
54+
*/
55+
void operator() (PETScWrappers::MPI::BlockSparseMatrix &M, dealii::BlockDynamicSparsityPattern &sp, bool fast=false)
56+
{
57+
M.reinit(owned, relevant, sp, comm);
58+
};
59+
#endif // DEAL_II_WITH_PETSC
60+
61+
/**
62+
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
63+
*/
64+
void operator() (BlockSparseMatrix<double > &M, dealii::BlockSparsityPattern &sp, bool fast=false)
65+
{
66+
M.reinit(sp);
67+
};
3368

69+
#ifdef DEAL_II_WITH_TRILINOS
3470
/**
3571
* Initialize a ghosted TrilinosWrappers::MPI::BlockVector.
3672
*/
3773
void ghosted(TrilinosWrappers::MPI::BlockVector &v, bool fast=false)
3874
{
3975
v.reinit(owned, relevant, comm, fast);
4076
};
77+
#endif // DEAL_II_WITH_TRILINOS
78+
79+
#ifdef DEAL_II_WITH_PETSC
80+
/**
81+
* Initialize a ghosted PETScWrappers::MPI::BlockVector.
82+
*/
83+
void ghosted(PETScWrappers::MPI::BlockVector &v, bool fast=false)
84+
{
85+
v.reinit(owned, relevant, comm);
86+
};
87+
#endif // DEAL_II_WITH_PETSC
4188

4289
/**
4390
* Initialize a serial BlockVector<double>.
@@ -58,6 +105,7 @@ class ScopedLACInitializer
58105
(void)fast;
59106
};
60107

108+
#ifdef DEAL_II_WITH_TRILINOS
61109
/**
62110
* Initialize a Trilinos Sparsity Pattern.
63111
*/
@@ -74,6 +122,7 @@ class ScopedLACInitializer
74122
Utilities::MPI::this_mpi_process(comm));
75123
s.compress();
76124
}
125+
#endif // DEAL_II_WITH_TRILINOS
77126

78127
/**
79128
* Initialize a Deal.II Sparsity Pattern.
@@ -93,6 +142,24 @@ class ScopedLACInitializer
93142
s.copy_from(csp);
94143
}
95144

145+
146+
/**
147+
* Initialize a Deal.II Dynamic Sparsity Pattern.
148+
*/
149+
template<int dim, int spacedim>
150+
void operator() (dealii::BlockDynamicSparsityPattern &s,
151+
const DoFHandler<dim, spacedim> &dh,
152+
const ConstraintMatrix &cm,
153+
const Table<2,DoFTools::Coupling> &coupling)
154+
{
155+
s.reinit(dofs_per_block, dofs_per_block);
156+
157+
DoFTools::make_sparsity_pattern (dh,
158+
coupling, s,
159+
cm, false);
160+
s.compress();
161+
}
162+
96163
private:
97164
/**
98165
* Dofs per block.

include/lac/lac_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class LAPETSc
6868
*/
6969
typedef PETScWrappers::MPI::BlockSparseMatrix BlockMatrix;
7070

71-
typedef dealii::BlockSparsityPattern BlockSparsityPattern;
71+
typedef dealii::BlockDynamicSparsityPattern BlockSparsityPattern;
7272
};
7373

7474
#endif // DEAL_II_WITH_PETSC

include/pidomus.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,25 @@ class piDoMUS : public ParameterAcceptor, public SundialsInterface<typename LAC:
216216
LADealII::VectorType &locally_relevant_y_expl,
217217
bool adaptive_refinement);
218218

219-
219+
#ifdef DEAL_II_WITH_TRILINOS
220220
void refine_and_transfer_solutions (LATrilinos::VectorType &y,
221221
LATrilinos::VectorType &y_dot,
222222
LATrilinos::VectorType &y_expl,
223223
LATrilinos::VectorType &locally_relevant_y,
224224
LATrilinos::VectorType &locally_relevant_y_dot,
225225
LATrilinos::VectorType &locally_relevant_y_expl,
226226
bool adaptive_refinement);
227-
227+
#endif //DEAL_II_WITH_TRILINOS
228+
229+
#ifdef DEAL_II_WITH_PETSC
230+
void refine_and_transfer_solutions (LAPETSc::VectorType &y,
231+
LAPETSc::VectorType &y_dot,
232+
LAPETSc::VectorType &y_expl,
233+
LAPETSc::VectorType &distributed_y,
234+
LAPETSc::VectorType &distributed_y_dot,
235+
LAPETSc::VectorType &distributed_y_expl,
236+
bool adaptive_refinement);
237+
#endif //DEAL_II_WITH_PETSC
228238

229239
void set_constrained_dofs_to_zero(typename LAC::VectorType &v) const;
230240

source/base_interface.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ compute_system_operators(const std::vector<shared_ptr<typename LADealII::BlockMa
194194
LinearOperator<typename LADealII::VectorType> &) const
195195
{}
196196

197-
197+
#ifdef DEAL_II_WITH_TRILINOS
198198
template <int dim, int spacedim, typename LAC>
199199
void
200200
BaseInterface<dim,spacedim,LAC>::
@@ -205,7 +205,20 @@ compute_system_operators(const std::vector<shared_ptr<LATrilinos::BlockMatrix> >
205205
{
206206
Assert(false, ExcPureFunctionCalled ());
207207
}
208+
#endif //DEAL_II_WITH_TRILINOS
208209

210+
#ifdef DEAL_II_WITH_PETSC
211+
template <int dim, int spacedim, typename LAC>
212+
void
213+
BaseInterface<dim,spacedim,LAC>::
214+
compute_system_operators(const std::vector<shared_ptr<LAPETSc::BlockMatrix> >,
215+
LinearOperator<LAPETSc::VectorType> &,
216+
LinearOperator<LAPETSc::VectorType> &,
217+
LinearOperator<LAPETSc::VectorType> &) const
218+
{
219+
Assert(false, ExcPureFunctionCalled ());
220+
}
221+
#endif //DEAL_II_WITH_PETSC
209222

210223
template<int dim, int spacedim, typename LAC>
211224
void
@@ -410,10 +423,18 @@ void
410423
BaseInterface<dim,spacedim,LAC>::connect_to_signals() const
411424
{}
412425

426+
#ifdef DEAL_II_WITH_TRILINOS
413427
template class BaseInterface<2, 2, LATrilinos>;
414428
template class BaseInterface<2, 3, LATrilinos>;
415429
template class BaseInterface<3, 3, LATrilinos>;
430+
#endif // DEAL_II_WITH_TRILINOS
416431

417432
template class BaseInterface<2, 2, LADealII>;
418433
template class BaseInterface<2, 3, LADealII>;
419434
template class BaseInterface<3, 3, LADealII>;
435+
436+
#ifdef DEAL_II_WITH_PETSC
437+
template class BaseInterface<2, 2, LAPETSc>;
438+
template class BaseInterface<2, 3, LAPETSc>;
439+
template class BaseInterface<3, 3, LAPETSc>;
440+
#endif // DEAL_II_WITH_PETSC

source/pidomus.cc

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void piDoMUS<dim, spacedim, LAC>::setup_dofs (const bool &first_run)
447447
*dof_handler,
448448
constraints,
449449
interface.get_matrix_coupling(i));
450-
matrices[i]->reinit(*matrix_sparsities[i]);
450+
initializer(*matrices[i], *matrix_sparsities[i]);
451451
}
452452

453453
if (first_run)
@@ -681,6 +681,7 @@ void piDoMUS<dim, spacedim, LAC>::assemble_matrices (const double t,
681681

682682
/* ------------------------ MESH AND GRID ------------------------ */
683683

684+
#ifdef DEAL_II_WITH_TRILINOS
684685
template <int dim, int spacedim, typename LAC>
685686
void piDoMUS<dim, spacedim, LAC>::
686687
refine_and_transfer_solutions(LATrilinos::VectorType &y,
@@ -742,6 +743,56 @@ refine_and_transfer_solutions(LATrilinos::VectorType &y,
742743

743744
signals.end_refine_and_transfer_solutions();
744745
}
746+
#endif //DEAL_II_WITH_TRILINOS
747+
748+
#ifdef DEAL_II_WITH_PETSC
749+
template <int dim, int spacedim, typename LAC>
750+
void piDoMUS<dim, spacedim, LAC>::
751+
refine_and_transfer_solutions(LAPETSc::VectorType &y,
752+
LAPETSc::VectorType &y_dot,
753+
LAPETSc::VectorType &y_expl,
754+
LAPETSc::VectorType &distributed_y,
755+
LAPETSc::VectorType &distributed_y_dot,
756+
LAPETSc::VectorType &distributed_y_expl,
757+
bool adaptive_refinement)
758+
{
759+
distributed_y = y;
760+
distributed_y_dot = y_dot;
761+
distributed_y_expl = y_expl;
762+
763+
parallel::distributed::SolutionTransfer<dim, LAPETSc::VectorType, DoFHandler<dim,spacedim> > sol_tr(*dof_handler);
764+
765+
std::vector<const LAPETSc::VectorType *> old_sols (3);
766+
old_sols[0] = &distributed_y;
767+
old_sols[1] = &distributed_y_dot;
768+
old_sols[2] = &distributed_y_expl;
769+
770+
triangulation->prepare_coarsening_and_refinement();
771+
sol_tr.prepare_for_coarsening_and_refinement (old_sols);
772+
773+
if (adaptive_refinement)
774+
triangulation->execute_coarsening_and_refinement ();
775+
else
776+
triangulation->refine_global (1);
777+
778+
setup_dofs(false);
779+
780+
LAPETSc::VectorType new_sol (y);
781+
LAPETSc::VectorType new_sol_dot (y_dot);
782+
LAPETSc::VectorType new_sol_expl (y_expl);
783+
784+
std::vector<LAPETSc::VectorType *> new_sols (3);
785+
new_sols[0] = &new_sol;
786+
new_sols[1] = &new_sol_dot;
787+
new_sols[2] = &new_sol_expl;
788+
789+
sol_tr.interpolate (new_sols);
790+
791+
y = new_sol;
792+
y_dot = new_sol_dot;
793+
y_expl = new_sol_expl;
794+
}
795+
#endif //DEAL_II_WITH_PETSC
745796

746797
template <int dim, int spacedim, typename LAC>
747798
void piDoMUS<dim, spacedim, LAC>::
@@ -1279,7 +1330,6 @@ piDoMUS<dim, spacedim, LAC>::set_constrained_dofs_to_zero(typename LAC::VectorTy
12791330
}
12801331
}
12811332

1282-
12831333
template <int dim, int spacedim, typename LAC>
12841334
void
12851335
piDoMUS<dim, spacedim, LAC>::get_lumped_mass_matrix(typename LAC::VectorType &dst) const
@@ -1351,11 +1401,18 @@ piDoMUS<dim, spacedim, LAC>::get_lumped_mass_matrix(typename LAC::VectorType &ds
13511401

13521402
}
13531403

1404+
#ifdef DEAL_II_WITH_TRILINOS
13541405
template class piDoMUS<2, 2, LATrilinos>;
13551406
template class piDoMUS<2, 3, LATrilinos>;
13561407
template class piDoMUS<3, 3, LATrilinos>;
1408+
#endif // DEAL_II_WITH_TRILINOS
13571409

13581410
template class piDoMUS<2, 2, LADealII>;
13591411
template class piDoMUS<2, 3, LADealII>;
13601412
template class piDoMUS<3, 3, LADealII>;
13611413

1414+
#ifdef DEAL_II_WITH_PETSC
1415+
template class piDoMUS<2, 2, LAPETSc>;
1416+
template class piDoMUS<2, 3, LAPETSc>;
1417+
template class piDoMUS<3, 3, LAPETSc>;
1418+
#endif // DEAL_II_WITH_PETSC

source/simulator_access.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,18 @@ SimulatorAccess<dim,spacedim,LAC>::get_fe () const
159159
}
160160

161161

162-
162+
#ifdef DEAL_II_WITH_TRILINOS
163163
template class SimulatorAccess<2, 2, LATrilinos>;
164164
template class SimulatorAccess<2, 3, LATrilinos>;
165165
template class SimulatorAccess<3, 3, LATrilinos>;
166+
#endif // DEAL_II_WITH_TRILINOS
166167

167168
template class SimulatorAccess<2, 2, LADealII>;
168169
template class SimulatorAccess<2, 3, LADealII>;
169170
template class SimulatorAccess<3, 3, LADealII>;
170171

172+
#ifdef DEAL_II_WITH_PETSC
173+
template class SimulatorAccess<2, 2, LAPETSc>;
174+
template class SimulatorAccess<2, 3, LAPETSc>;
175+
template class SimulatorAccess<3, 3, LAPETSc>;
176+
#endif // DEAL_II_WITH_PETSC

0 commit comments

Comments
 (0)