Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/base_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,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 @@ -226,6 +227,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
37 changes: 36 additions & 1 deletion include/interfaces/poisson_problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ class PoissonProblem : public PDESystemInterface<dim,spacedim, PoissonProblem<di
LinearOperator<LATrilinos::VectorType> &,
LinearOperator<LATrilinos::VectorType> &) const;

void compute_system_operators(const std::vector<shared_ptr<LAPETSc::BlockMatrix> >,
LinearOperator<LAPETSc::VectorType> &,
LinearOperator<LAPETSc::VectorType> &,
LinearOperator<LAPETSc::VectorType> &) const;

private:
mutable shared_ptr<TrilinosWrappers::PreconditionJacobi> preconditioner;

mutable shared_ptr<PETScWrappers::PreconditionJacobi> PETSc_preconditioner;
};

template <int dim, int spacedim, typename LAC>
Expand Down Expand Up @@ -120,4 +125,34 @@ PoissonProblem<dim,spacedim,LAC>::compute_system_operators(const std::vector<sha
});
}

template <int dim, int spacedim, typename LAC>
void
PoissonProblem<dim,spacedim,LAC>::compute_system_operators(const std::vector<shared_ptr<LAPETSc::BlockMatrix> > matrices,
LinearOperator<LAPETSc::VectorType> &system_op,
LinearOperator<LAPETSc::VectorType> &prec_op,
LinearOperator<LAPETSc::VectorType> &) const
{

PETSc_preconditioner.reset (new PETScWrappers::PreconditionJacobi());
PETSc_preconditioner->initialize(matrices[0]->block(0,0));
//
auto A = linear_operator<LAPETSc::VectorType::BlockType>( matrices[0]->block(0,0) );
//
// LinearOperator<LAPETSc::VectorType::BlockType> P_inv;
//
auto Id = identity_operator(A.reinit_range_vector); //linear_operator<LAPETSc::VectorType::BlockType>(matrices[0]->block(0,0), *PETSc_preconditioner);
//
// auto P00 = P_inv;
//
// // ASSEMBLE THE PROBLEM:
system_op = block_operator<1, 1, LAPETSc::VectorType>({{
{{ A }}
}
});

prec_op = block_operator<1, 1, LAPETSc::VectorType>({{
{{ Id }} ,
}
});
}
#endif
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 @@ -216,15 +216,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 @@ -194,7 +194,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 @@ -205,7 +205,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 @@ -410,10 +423,18 @@ void
BaseInterface<dim,spacedim,LAC>::connect_to_signals() const
{}

#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
61 changes: 59 additions & 2 deletions source/pidomus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,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 @@ -681,6 +681,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 @@ -742,6 +743,56 @@ refine_and_transfer_solutions(LATrilinos::VectorType &y,

signals.end_refine_and_transfer_solutions();
}
#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 @@ -1279,7 +1330,6 @@ piDoMUS<dim, spacedim, LAC>::set_constrained_dofs_to_zero(typename LAC::VectorTy
}
}


template <int dim, int spacedim, typename LAC>
void
piDoMUS<dim, spacedim, LAC>::get_lumped_mass_matrix(typename LAC::VectorType &dst) const
Expand Down Expand Up @@ -1351,11 +1401,18 @@ piDoMUS<dim, spacedim, LAC>::get_lumped_mass_matrix(typename LAC::VectorType &ds

}

#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 @@ -159,12 +159,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
Loading