Skip to content

Commit

Permalink
PETSc
Browse files Browse the repository at this point in the history
  • Loading branch information
ESeNonFossiIo committed Mar 25, 2016
1 parent 6639a95 commit 6f1aa38
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 6 deletions.
9 changes: 9 additions & 0 deletions include/base_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class BaseInterface : public ParameterAcceptor, public SimulatorAccess<dim,space
FEValuesCache<dim,spacedim> &scratch,
CopyData &data) const;

#ifdef DEAL_II_WITH_TRILINOS
/**
* Compute linear operators needed by the problem: - @p system_op
* represents the system matrix associated to the Newton's
Expand Down Expand Up @@ -208,6 +209,14 @@ class BaseInterface : public ParameterAcceptor, public SimulatorAccess<dim,space
LinearOperator<LATrilinos::VectorType> &system_op,
LinearOperator<LATrilinos::VectorType> &prec_op,
LinearOperator<LATrilinos::VectorType> &prec_op_finer) const;
#endif //DEAL_II_WITH_TRILINOS

#ifdef DEAL_II_WITH_PETSC
virtual void compute_system_operators(const std::vector<shared_ptr<typename LAPETSc::BlockMatrix> >,
LinearOperator<LAPETSc::VectorType> &system_op,
LinearOperator<LAPETSc::VectorType> &prec_op,
LinearOperator<LAPETSc::VectorType> &prec_op_finer) const;
#endif //DEAL_II_WITH_PETSC

/**
* Compute linear operators needed by the problem. When using
Expand Down
67 changes: 67 additions & 0 deletions include/lac/lac_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ScopedLACInitializer
comm(comm)
{};

#ifdef DEAL_II_WITH_TRILINOS
/**
* Initialize a non ghosted TrilinosWrappers::MPI::BlockVector.
*/
Expand All @@ -30,14 +31,60 @@ class ScopedLACInitializer
v.reinit(owned, comm, fast);
};

/**
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
*/
void operator() (TrilinosWrappers::BlockSparseMatrix &M, TrilinosWrappers::BlockSparsityPattern &sp, bool fast=false)
{
M.reinit(sp);
};
#endif // DEAL_II_WITH_TRILINOS

#ifdef DEAL_II_WITH_PETSC
/**
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
*/
void operator() (PETScWrappers::MPI::BlockVector &v, bool fast=false)
{
v.reinit(owned, comm);
};

/**
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
*/
void operator() (PETScWrappers::MPI::BlockSparseMatrix &M, dealii::BlockDynamicSparsityPattern &sp, bool fast=false)
{
M.reinit(owned, relevant, sp, comm);
};
#endif // DEAL_II_WITH_PETSC

/**
* Initialize a non ghosted PETScWrappers::MPI::BlockVector.
*/
void operator() (BlockSparseMatrix<double > &M, dealii::BlockSparsityPattern &sp, bool fast=false)
{
M.reinit(sp);
};

#ifdef DEAL_II_WITH_TRILINOS
/**
* Initialize a ghosted TrilinosWrappers::MPI::BlockVector.
*/
void ghosted(TrilinosWrappers::MPI::BlockVector &v, bool fast=false)
{
v.reinit(owned, relevant, comm, fast);
};
#endif // DEAL_II_WITH_TRILINOS

#ifdef DEAL_II_WITH_PETSC
/**
* Initialize a ghosted PETScWrappers::MPI::BlockVector.
*/
void ghosted(PETScWrappers::MPI::BlockVector &v, bool fast=false)
{
v.reinit(owned, relevant, comm);
};
#endif // DEAL_II_WITH_PETSC

/**
* Initialize a serial BlockVector<double>.
Expand All @@ -58,6 +105,7 @@ class ScopedLACInitializer
(void)fast;
};

#ifdef DEAL_II_WITH_TRILINOS
/**
* Initialize a Trilinos Sparsity Pattern.
*/
Expand All @@ -74,6 +122,7 @@ class ScopedLACInitializer
Utilities::MPI::this_mpi_process(comm));
s.compress();
}
#endif // DEAL_II_WITH_TRILINOS

/**
* Initialize a Deal.II Sparsity Pattern.
Expand All @@ -93,6 +142,24 @@ class ScopedLACInitializer
s.copy_from(csp);
}


/**
* Initialize a Deal.II Dynamic Sparsity Pattern.
*/
template<int dim, int spacedim>
void operator() (dealii::BlockDynamicSparsityPattern &s,
const DoFHandler<dim, spacedim> &dh,
const ConstraintMatrix &cm,
const Table<2,DoFTools::Coupling> &coupling)
{
s.reinit(dofs_per_block, dofs_per_block);

DoFTools::make_sparsity_pattern (dh,
coupling, s,
cm, false);
s.compress();
}

private:
/**
* Dofs per block.
Expand Down
2 changes: 1 addition & 1 deletion include/lac/lac_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class LAPETSc
*/
typedef PETScWrappers::MPI::BlockSparseMatrix BlockMatrix;

typedef dealii::BlockSparsityPattern BlockSparsityPattern;
typedef dealii::BlockDynamicSparsityPattern BlockSparsityPattern;
};

#endif // DEAL_II_WITH_PETSC
Expand Down
14 changes: 12 additions & 2 deletions include/pidomus.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,25 @@ class piDoMUS : public ParameterAcceptor, public SundialsInterface<typename LAC:
LADealII::VectorType &locally_relevant_y_expl,
bool adaptive_refinement);


#ifdef DEAL_II_WITH_TRILINOS
void refine_and_transfer_solutions (LATrilinos::VectorType &y,
LATrilinos::VectorType &y_dot,
LATrilinos::VectorType &y_expl,
LATrilinos::VectorType &locally_relevant_y,
LATrilinos::VectorType &locally_relevant_y_dot,
LATrilinos::VectorType &locally_relevant_y_expl,
bool adaptive_refinement);

#endif //DEAL_II_WITH_TRILINOS

#ifdef DEAL_II_WITH_PETSC
void refine_and_transfer_solutions (LAPETSc::VectorType &y,
LAPETSc::VectorType &y_dot,
LAPETSc::VectorType &y_expl,
LAPETSc::VectorType &distributed_y,
LAPETSc::VectorType &distributed_y_dot,
LAPETSc::VectorType &distributed_y_expl,
bool adaptive_refinement);
#endif //DEAL_II_WITH_PETSC

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

Expand Down
23 changes: 22 additions & 1 deletion source/base_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ compute_system_operators(const std::vector<shared_ptr<typename LADealII::BlockMa
LinearOperator<typename LADealII::VectorType> &) const
{}


#ifdef DEAL_II_WITH_TRILINOS
template <int dim, int spacedim, typename LAC>
void
BaseInterface<dim,spacedim,LAC>::
Expand All @@ -213,7 +213,20 @@ compute_system_operators(const std::vector<shared_ptr<LATrilinos::BlockMatrix> >
{
Assert(false, ExcPureFunctionCalled ());
}
#endif //DEAL_II_WITH_TRILINOS

#ifdef DEAL_II_WITH_PETSC
template <int dim, int spacedim, typename LAC>
void
BaseInterface<dim,spacedim,LAC>::
compute_system_operators(const std::vector<shared_ptr<LAPETSc::BlockMatrix> >,
LinearOperator<LAPETSc::VectorType> &,
LinearOperator<LAPETSc::VectorType> &,
LinearOperator<LAPETSc::VectorType> &) const
{
Assert(false, ExcPureFunctionCalled ());
}
#endif //DEAL_II_WITH_PETSC

template<int dim, int spacedim, typename LAC>
void
Expand Down Expand Up @@ -404,10 +417,18 @@ output_solution (const unsigned int &current_cycle,

}

#ifdef DEAL_II_WITH_TRILINOS
template class BaseInterface<2, 2, LATrilinos>;
template class BaseInterface<2, 3, LATrilinos>;
template class BaseInterface<3, 3, LATrilinos>;
#endif // DEAL_II_WITH_TRILINOS

template class BaseInterface<2, 2, LADealII>;
template class BaseInterface<2, 3, LADealII>;
template class BaseInterface<3, 3, LADealII>;

#ifdef DEAL_II_WITH_PETSC
template class BaseInterface<2, 2, LAPETSc>;
template class BaseInterface<2, 3, LAPETSc>;
template class BaseInterface<3, 3, LAPETSc>;
#endif // DEAL_II_WITH_PETSC
60 changes: 59 additions & 1 deletion source/pidomus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void piDoMUS<dim, spacedim, LAC>::setup_dofs (const bool &first_run)
*dof_handler,
constraints,
interface.get_matrix_coupling(i));
matrices[i]->reinit(*matrix_sparsities[i]);
initializer(*matrices[i], *matrix_sparsities[i]);
}

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

/* ------------------------ MESH AND GRID ------------------------ */

#ifdef DEAL_II_WITH_TRILINOS
template <int dim, int spacedim, typename LAC>
void piDoMUS<dim, spacedim, LAC>::
refine_and_transfer_solutions(LATrilinos::VectorType &y,
Expand Down Expand Up @@ -732,6 +733,56 @@ refine_and_transfer_solutions(LATrilinos::VectorType &y,
locally_relevant_y_expl = y_expl;

}
#endif //DEAL_II_WITH_TRILINOS

#ifdef DEAL_II_WITH_PETSC
template <int dim, int spacedim, typename LAC>
void piDoMUS<dim, spacedim, LAC>::
refine_and_transfer_solutions(LAPETSc::VectorType &y,
LAPETSc::VectorType &y_dot,
LAPETSc::VectorType &y_expl,
LAPETSc::VectorType &distributed_y,
LAPETSc::VectorType &distributed_y_dot,
LAPETSc::VectorType &distributed_y_expl,
bool adaptive_refinement)
{
distributed_y = y;
distributed_y_dot = y_dot;
distributed_y_expl = y_expl;

parallel::distributed::SolutionTransfer<dim, LAPETSc::VectorType, DoFHandler<dim,spacedim> > sol_tr(*dof_handler);

std::vector<const LAPETSc::VectorType *> old_sols (3);
old_sols[0] = &distributed_y;
old_sols[1] = &distributed_y_dot;
old_sols[2] = &distributed_y_expl;

triangulation->prepare_coarsening_and_refinement();
sol_tr.prepare_for_coarsening_and_refinement (old_sols);

if (adaptive_refinement)
triangulation->execute_coarsening_and_refinement ();
else
triangulation->refine_global (1);

setup_dofs(false);

LAPETSc::VectorType new_sol (y);
LAPETSc::VectorType new_sol_dot (y_dot);
LAPETSc::VectorType new_sol_expl (y_expl);

std::vector<LAPETSc::VectorType *> new_sols (3);
new_sols[0] = &new_sol;
new_sols[1] = &new_sol_dot;
new_sols[2] = &new_sol_expl;

sol_tr.interpolate (new_sols);

y = new_sol;
y_dot = new_sol_dot;
y_expl = new_sol_expl;
}
#endif //DEAL_II_WITH_PETSC

template <int dim, int spacedim, typename LAC>
void piDoMUS<dim, spacedim, LAC>::
Expand Down Expand Up @@ -1208,11 +1259,18 @@ piDoMUS<dim, spacedim, LAC>::set_constrained_dofs_to_zero(typename LAC::VectorTy
}
}

#ifdef DEAL_II_WITH_TRILINOS
template class piDoMUS<2, 2, LATrilinos>;
template class piDoMUS<2, 3, LATrilinos>;
template class piDoMUS<3, 3, LATrilinos>;
#endif // DEAL_II_WITH_TRILINOS

template class piDoMUS<2, 2, LADealII>;
template class piDoMUS<2, 3, LADealII>;
template class piDoMUS<3, 3, LADealII>;

#ifdef DEAL_II_WITH_PETSC
template class piDoMUS<2, 2, LAPETSc>;
template class piDoMUS<2, 3, LAPETSc>;
template class piDoMUS<3, 3, LAPETSc>;
#endif // DEAL_II_WITH_PETSC
8 changes: 7 additions & 1 deletion source/simulator_access.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,18 @@ SimulatorAccess<dim,spacedim,LAC>::get_fe () const
}



#ifdef DEAL_II_WITH_TRILINOS
template class SimulatorAccess<2, 2, LATrilinos>;
template class SimulatorAccess<2, 3, LATrilinos>;
template class SimulatorAccess<3, 3, LATrilinos>;
#endif // DEAL_II_WITH_TRILINOS

template class SimulatorAccess<2, 2, LADealII>;
template class SimulatorAccess<2, 3, LADealII>;
template class SimulatorAccess<3, 3, LADealII>;

#ifdef DEAL_II_WITH_PETSC
template class SimulatorAccess<2, 2, LAPETSc>;
template class SimulatorAccess<2, 3, LAPETSc>;
template class SimulatorAccess<3, 3, LAPETSc>;
#endif // DEAL_II_WITH_PETSC

0 comments on commit 6f1aa38

Please sign in to comment.