Skip to content

Commit

Permalink
Add template parameter for fe_degree
Browse files Browse the repository at this point in the history
  • Loading branch information
David Schneider committed Oct 26, 2022
1 parent d7bdb0f commit d449647
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 196 deletions.
206 changes: 15 additions & 191 deletions include/heat_transfer/cuda_laplace_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace Heat_Transfer
fe_eval.distribute_local_to_global(dst);
}

template <int dim, typename number>
template <int dim, int fe_degree, typename number>
class CUDALaplaceOperator
{
public:
Expand Down Expand Up @@ -176,19 +176,18 @@ namespace Heat_Transfer



template <int dim, typename number>
CUDALaplaceOperator<dim, number>::CUDALaplaceOperator()
template <int dim, int fe_degree, typename number>
CUDALaplaceOperator<dim, fe_degree, number>::CUDALaplaceOperator()
{}



template <int dim, typename number>
template <int dim, int fe_degree, typename number>
void
CUDALaplaceOperator<dim, number>::initialize(
CUDALaplaceOperator<dim, fe_degree, number>::initialize(
const DoFHandler<dim> &dof_handler,
AffineConstraints<double> &constraints)
{
const int fe_degree = 1;
MappingQ<dim> mapping(fe_degree);
typename CUDAWrappers::MatrixFree<dim, number>::AdditionalData
additional_data;
Expand All @@ -212,21 +211,21 @@ namespace Heat_Transfer
}


template <int dim, typename number>
template <int dim, int fe_degree, typename number>
void
CUDALaplaceOperator<dim, number>::set_delta_t(double dt)
CUDALaplaceOperator<dim, fe_degree, number>::set_delta_t(double dt)
{
delta_t = dt;
}


template <int dim, typename number>
template <int dim, int fe_degree, typename number>
void
CUDALaplaceOperator<dim, number>::vmult(VectorType &dst,
const VectorType &src) const
CUDALaplaceOperator<dim, fe_degree, number>::vmult(
VectorType &dst,
const VectorType &src) const
{
dst = 0.;
const int fe_degree = 1;
dst = 0.;
LocalLaplaceOperator<dim, fe_degree> local_operator(coef.get_values(),
delta_t);
mf_data.cell_loop(local_operator, src, dst);
Expand All @@ -236,188 +235,13 @@ namespace Heat_Transfer
}


template <int dim, typename number>
template <int dim, int fe_degree, typename number>
void
CUDALaplaceOperator<dim, number>::initialize_dof_vector(VectorType &vec) const
CUDALaplaceOperator<dim, fe_degree, number>::initialize_dof_vector(
VectorType &vec) const
{
mf_data.initialize_dof_vector(vec);
}


/**
* Partial template specialization for CUDA
*/
// template <int dim, typename number>
// class LaplaceOperator<dim, number, MemorySpace::CUDA>
// : public MatrixFreeOperators::
// Base<dim, LinearAlgebra::distributed::Vector<number,
// MemorySpace::CUDA>>
// {
// public:
// using FECellIntegrator =
// FECellIntegrators<dim, 1, number, VectorizedArray<number>>;
// using FEFaceIntegrator =
// FEFaceIntegrators<dim, 1, number, VectorizedArray<number>>;
// using VectorType =
// LinearAlgebra::distributed::Vector<number, MemorySpace::CUDA>;

// LaplaceOperator();

// void
// clear() override;

// void
// evaluate_coefficient(const Coefficient<dim> &coefficient_function);

// void
// set_delta_t(const double delta_t_)
// {
// delta_t = delta_t_;
// }

// virtual void
// compute_diagonal() override;

// private:
// virtual void
// apply_add(VectorType &dst, const VectorType &src) const override;

// void
// local_apply(const MatrixFree<dim, number> &data,
// VectorType &dst,
// const VectorType &src,
// const std::pair<unsigned int, unsigned int> &cell_range)
// const;

// void
// do_operation_on_cell(FECellIntegrator &phi) const;

// Table<2, VectorizedArray<number>> coefficient;
// LinearAlgebra::CUDAWrappers::Vector<double> coef;
// double delta_t = 0;
// };



// template <int dim, typename number>
// LaplaceOperator<dim, number, MemorySpace::CUDA>::LaplaceOperator()
// : MatrixFreeOperators::Base<dim, VectorType>()
// {}



// template <int dim, typename number>
// void
// LaplaceOperator<dim, number, MemorySpace::CUDA>::clear()
// {
// coefficient.reinit(0, 0);
// MatrixFreeOperators::Base<dim, VectorType>::clear();
// }



// template <int dim, typename number>
// void
// LaplaceOperator<dim, number, MemorySpace::CUDA>::evaluate_coefficient(
// const Coefficient<dim> &coefficient_function)
// {
// const unsigned int n_cells = this->data->n_cell_batches();
// FECellIntegrator phi(*this->data);

// coefficient.reinit(n_cells, phi.n_q_points);
// for (unsigned int cell = 0; cell < n_cells; ++cell)
// {
// phi.reinit(cell);
// for (unsigned int q = 0; q < phi.n_q_points; ++q)
// coefficient(cell, q) =
// coefficient_function.value(phi.quadrature_point(q), 0);
// }
// }



// template <int dim, typename number>
// void
// LaplaceOperator<dim, number, MemorySpace::CUDA>::local_apply(
// const MatrixFree<dim, number> &data,
// VectorType &dst,
// const VectorType &src,
// const std::pair<unsigned int, unsigned int> &cell_range) const
// {
// FECellIntegrator phi(data);

// for (unsigned int cell = cell_range.first; cell < cell_range.second;
// ++cell)
// {
// AssertDimension(coefficient.size(0), data.n_cell_batches());
// AssertDimension(coefficient.size(1), phi.n_q_points);

// phi.reinit(cell);
// phi.read_dof_values(src);
// do_operation_on_cell(phi);
// phi.distribute_local_to_global(dst);
// }
// }



// template <int dim, typename number>
// void
// LaplaceOperator<dim, number, MemorySpace::CUDA>::apply_add(
// VectorType &dst,
// const VectorType &src) const
// {
// this->data->cell_loop(&LaplaceOperator::local_apply, this, dst, src);
// }



// template <int dim, typename number>
// void
// LaplaceOperator<dim, number, MemorySpace::CUDA>::compute_diagonal()
// {
// this->inverse_diagonal_entries.reset(new DiagonalMatrix<VectorType>());
// VectorType &inverse_diagonal =
// this->inverse_diagonal_entries->get_vector();
// this->data->initialize_dof_vector(inverse_diagonal);

// MatrixFreeTools::compute_diagonal(*(this->data),
// inverse_diagonal,
// &LaplaceOperator::do_operation_on_cell,
// this);

// this->set_constrained_entries_to_one(inverse_diagonal);

// for (unsigned int i = 0; i < inverse_diagonal.locally_owned_size(); ++i)
// {
// Assert(inverse_diagonal.local_element(i) > 0.,
// ExcMessage("No diagonal entry in a positive definite operator
// "
// "should be zero"));
// inverse_diagonal.local_element(i) =
// 1. / inverse_diagonal.local_element(i);
// }
// }



// template <int dim, typename number>
// void
// LaplaceOperator<dim, number, MemorySpace::CUDA>::do_operation_on_cell(
// FECellIntegrator &phi) const
// {
// Assert(delta_t > 0, ExcNotInitialized());
// const unsigned int cell = phi.get_current_cell_index();
// phi.evaluate(EvaluationFlags::values | EvaluationFlags::gradients);
// for (unsigned int q = 0; q < phi.n_q_points; ++q)
// {
// phi.submit_value(phi.get_value(q), q);
// phi.submit_gradient(coefficient(cell, q) * delta_t *
// phi.get_gradient(q),
// q);
// }
// phi.integrate(EvaluationFlags::values | EvaluationFlags::gradients);
// }
} // namespace Heat_Transfer

#endif
10 changes: 5 additions & 5 deletions include/heat_transfer/heat_transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace Heat_Transfer
}
template <int dim>
double
Coefficient<dim>::value(const Point<dim> & p,
Coefficient<dim>::value(const Point<dim> &p,
const unsigned int component) const
{
return value<double>(p, component);
Expand Down Expand Up @@ -142,7 +142,7 @@ namespace Heat_Transfer
*/
double
compute_error(
const Function<dim> & function,
const Function<dim> &function,
const LinearAlgebra::distributed::Vector<double> &solution) const;
/**
* @brief output_results Output the generated results.
Expand Down Expand Up @@ -187,7 +187,7 @@ namespace Heat_Transfer
Adapter::Adapter<dim, 1, VectorType, VectorizedArray<double>>>
precice_adapter;

std::unique_ptr<CUDALaplaceOperator<dim, double>> cuda_operator;
std::unique_ptr<CUDALaplaceOperator<dim, 1, double>> cuda_operator;

ConditionalOStream pcout;
mutable TimerOutput timer;
Expand Down Expand Up @@ -298,7 +298,7 @@ namespace Heat_Transfer
system_matrix.evaluate_coefficient(Coefficient<dim>());
system_matrix.set_delta_t(time.get_delta_t());

cuda_operator.reset(new CUDALaplaceOperator<dim, double>());
cuda_operator.reset(new CUDALaplaceOperator<dim, 1, double>());
cuda_operator->initialize(dof_handler, constraints);
cuda_operator->set_delta_t(time.get_delta_t());

Expand Down Expand Up @@ -643,7 +643,7 @@ namespace Heat_Transfer
template <int dim, typename MemorySpace>
double
LaplaceProblem<dim, MemorySpace>::compute_error(
const Function<dim> & function,
const Function<dim> &function,
const LinearAlgebra::distributed::Vector<double> &solution) const
{
TimerOutput::Scope t(timer, "compute errors");
Expand Down

0 comments on commit d449647

Please sign in to comment.