Skip to content

Commit 6f1aa38

Browse files
committed
PETSc
1 parent 6639a95 commit 6f1aa38

File tree

7 files changed

+177
-6
lines changed

7 files changed

+177
-6
lines changed

include/base_interface.h

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

179+
#ifdef DEAL_II_WITH_TRILINOS
179180
/**
180181
* Compute linear operators needed by the problem: - @p system_op
181182
* represents the system matrix associated to the Newton's
@@ -208,6 +209,14 @@ class BaseInterface : public ParameterAcceptor, public SimulatorAccess<dim,space
208209
LinearOperator<LATrilinos::VectorType> &system_op,
209210
LinearOperator<LATrilinos::VectorType> &prec_op,
210211
LinearOperator<LATrilinos::VectorType> &prec_op_finer) const;
212+
#endif //DEAL_II_WITH_TRILINOS
213+
214+
#ifdef DEAL_II_WITH_PETSC
215+
virtual void compute_system_operators(const std::vector<shared_ptr<typename LAPETSc::BlockMatrix> >,
216+
LinearOperator<LAPETSc::VectorType> &system_op,
217+
LinearOperator<LAPETSc::VectorType> &prec_op,
218+
LinearOperator<LAPETSc::VectorType> &prec_op_finer) const;
219+
#endif //DEAL_II_WITH_PETSC
211220

212221
/**
213222
* 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
@@ -203,15 +203,25 @@ class piDoMUS : public ParameterAcceptor, public SundialsInterface<typename LAC:
203203
LADealII::VectorType &locally_relevant_y_expl,
204204
bool adaptive_refinement);
205205

206-
206+
#ifdef DEAL_II_WITH_TRILINOS
207207
void refine_and_transfer_solutions (LATrilinos::VectorType &y,
208208
LATrilinos::VectorType &y_dot,
209209
LATrilinos::VectorType &y_expl,
210210
LATrilinos::VectorType &locally_relevant_y,
211211
LATrilinos::VectorType &locally_relevant_y_dot,
212212
LATrilinos::VectorType &locally_relevant_y_expl,
213213
bool adaptive_refinement);
214-
214+
#endif //DEAL_II_WITH_TRILINOS
215+
216+
#ifdef DEAL_II_WITH_PETSC
217+
void refine_and_transfer_solutions (LAPETSc::VectorType &y,
218+
LAPETSc::VectorType &y_dot,
219+
LAPETSc::VectorType &y_expl,
220+
LAPETSc::VectorType &distributed_y,
221+
LAPETSc::VectorType &distributed_y_dot,
222+
LAPETSc::VectorType &distributed_y_expl,
223+
bool adaptive_refinement);
224+
#endif //DEAL_II_WITH_PETSC
215225

216226
void set_constrained_dofs_to_zero(typename LAC::VectorType &v) const;
217227

source/base_interface.cc

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

205-
205+
#ifdef DEAL_II_WITH_TRILINOS
206206
template <int dim, int spacedim, typename LAC>
207207
void
208208
BaseInterface<dim,spacedim,LAC>::
@@ -213,7 +213,20 @@ compute_system_operators(const std::vector<shared_ptr<LATrilinos::BlockMatrix> >
213213
{
214214
Assert(false, ExcPureFunctionCalled ());
215215
}
216+
#endif //DEAL_II_WITH_TRILINOS
216217

218+
#ifdef DEAL_II_WITH_PETSC
219+
template <int dim, int spacedim, typename LAC>
220+
void
221+
BaseInterface<dim,spacedim,LAC>::
222+
compute_system_operators(const std::vector<shared_ptr<LAPETSc::BlockMatrix> >,
223+
LinearOperator<LAPETSc::VectorType> &,
224+
LinearOperator<LAPETSc::VectorType> &,
225+
LinearOperator<LAPETSc::VectorType> &) const
226+
{
227+
Assert(false, ExcPureFunctionCalled ());
228+
}
229+
#endif //DEAL_II_WITH_PETSC
217230

218231
template<int dim, int spacedim, typename LAC>
219232
void
@@ -404,10 +417,18 @@ output_solution (const unsigned int &current_cycle,
404417

405418
}
406419

420+
#ifdef DEAL_II_WITH_TRILINOS
407421
template class BaseInterface<2, 2, LATrilinos>;
408422
template class BaseInterface<2, 3, LATrilinos>;
409423
template class BaseInterface<3, 3, LATrilinos>;
424+
#endif // DEAL_II_WITH_TRILINOS
410425

411426
template class BaseInterface<2, 2, LADealII>;
412427
template class BaseInterface<2, 3, LADealII>;
413428
template class BaseInterface<3, 3, LADealII>;
429+
430+
#ifdef DEAL_II_WITH_PETSC
431+
template class BaseInterface<2, 2, LAPETSc>;
432+
template class BaseInterface<2, 3, LAPETSc>;
433+
template class BaseInterface<3, 3, LAPETSc>;
434+
#endif // DEAL_II_WITH_PETSC

source/pidomus.cc

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void piDoMUS<dim, spacedim, LAC>::setup_dofs (const bool &first_run)
457457
*dof_handler,
458458
constraints,
459459
interface.get_matrix_coupling(i));
460-
matrices[i]->reinit(*matrix_sparsities[i]);
460+
initializer(*matrices[i], *matrix_sparsities[i]);
461461
}
462462

463463
if (first_run)
@@ -680,6 +680,7 @@ void piDoMUS<dim, spacedim, LAC>::assemble_matrices (const double t,
680680

681681
/* ------------------------ MESH AND GRID ------------------------ */
682682

683+
#ifdef DEAL_II_WITH_TRILINOS
683684
template <int dim, int spacedim, typename LAC>
684685
void piDoMUS<dim, spacedim, LAC>::
685686
refine_and_transfer_solutions(LATrilinos::VectorType &y,
@@ -732,6 +733,56 @@ refine_and_transfer_solutions(LATrilinos::VectorType &y,
732733
locally_relevant_y_expl = y_expl;
733734

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

736787
template <int dim, int spacedim, typename LAC>
737788
void piDoMUS<dim, spacedim, LAC>::
@@ -1208,11 +1259,18 @@ piDoMUS<dim, spacedim, LAC>::set_constrained_dofs_to_zero(typename LAC::VectorTy
12081259
}
12091260
}
12101261

1262+
#ifdef DEAL_II_WITH_TRILINOS
12111263
template class piDoMUS<2, 2, LATrilinos>;
12121264
template class piDoMUS<2, 3, LATrilinos>;
12131265
template class piDoMUS<3, 3, LATrilinos>;
1266+
#endif // DEAL_II_WITH_TRILINOS
12141267

12151268
template class piDoMUS<2, 2, LADealII>;
12161269
template class piDoMUS<2, 3, LADealII>;
12171270
template class piDoMUS<3, 3, LADealII>;
12181271

1272+
#ifdef DEAL_II_WITH_PETSC
1273+
template class piDoMUS<2, 2, LAPETSc>;
1274+
template class piDoMUS<2, 3, LAPETSc>;
1275+
template class piDoMUS<3, 3, LAPETSc>;
1276+
#endif // DEAL_II_WITH_PETSC

source/simulator_access.cc

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

151151

152-
152+
#ifdef DEAL_II_WITH_TRILINOS
153153
template class SimulatorAccess<2, 2, LATrilinos>;
154154
template class SimulatorAccess<2, 3, LATrilinos>;
155155
template class SimulatorAccess<3, 3, LATrilinos>;
156+
#endif // DEAL_II_WITH_TRILINOS
156157

157158
template class SimulatorAccess<2, 2, LADealII>;
158159
template class SimulatorAccess<2, 3, LADealII>;
159160
template class SimulatorAccess<3, 3, LADealII>;
160161

162+
#ifdef DEAL_II_WITH_PETSC
163+
template class SimulatorAccess<2, 2, LAPETSc>;
164+
template class SimulatorAccess<2, 3, LAPETSc>;
165+
template class SimulatorAccess<3, 3, LAPETSc>;
166+
#endif // DEAL_II_WITH_PETSC

0 commit comments

Comments
 (0)