From d44964720366131a1a4d527287f46e79fd277030 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Wed, 26 Oct 2022 13:26:03 +0200 Subject: [PATCH] Add template parameter for fe_degree --- include/heat_transfer/cuda_laplace_operator.h | 206 ++---------------- include/heat_transfer/heat_transfer.h | 10 +- 2 files changed, 20 insertions(+), 196 deletions(-) diff --git a/include/heat_transfer/cuda_laplace_operator.h b/include/heat_transfer/cuda_laplace_operator.h index ccae218..db99d49 100644 --- a/include/heat_transfer/cuda_laplace_operator.h +++ b/include/heat_transfer/cuda_laplace_operator.h @@ -145,7 +145,7 @@ namespace Heat_Transfer fe_eval.distribute_local_to_global(dst); } - template + template class CUDALaplaceOperator { public: @@ -176,19 +176,18 @@ namespace Heat_Transfer - template - CUDALaplaceOperator::CUDALaplaceOperator() + template + CUDALaplaceOperator::CUDALaplaceOperator() {} - template + template void - CUDALaplaceOperator::initialize( + CUDALaplaceOperator::initialize( const DoFHandler &dof_handler, AffineConstraints &constraints) { - const int fe_degree = 1; MappingQ mapping(fe_degree); typename CUDAWrappers::MatrixFree::AdditionalData additional_data; @@ -212,21 +211,21 @@ namespace Heat_Transfer } - template + template void - CUDALaplaceOperator::set_delta_t(double dt) + CUDALaplaceOperator::set_delta_t(double dt) { delta_t = dt; } - template + template void - CUDALaplaceOperator::vmult(VectorType &dst, - const VectorType &src) const + CUDALaplaceOperator::vmult( + VectorType &dst, + const VectorType &src) const { - dst = 0.; - const int fe_degree = 1; + dst = 0.; LocalLaplaceOperator local_operator(coef.get_values(), delta_t); mf_data.cell_loop(local_operator, src, dst); @@ -236,188 +235,13 @@ namespace Heat_Transfer } - template + template void - CUDALaplaceOperator::initialize_dof_vector(VectorType &vec) const + CUDALaplaceOperator::initialize_dof_vector( + VectorType &vec) const { mf_data.initialize_dof_vector(vec); } - - - /** - * Partial template specialization for CUDA - */ - // template - // class LaplaceOperator - // : public MatrixFreeOperators:: - // Base> - // { - // public: - // using FECellIntegrator = - // FECellIntegrators>; - // using FEFaceIntegrator = - // FEFaceIntegrators>; - // using VectorType = - // LinearAlgebra::distributed::Vector; - - // LaplaceOperator(); - - // void - // clear() override; - - // void - // evaluate_coefficient(const Coefficient &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 &data, - // VectorType &dst, - // const VectorType &src, - // const std::pair &cell_range) - // const; - - // void - // do_operation_on_cell(FECellIntegrator &phi) const; - - // Table<2, VectorizedArray> coefficient; - // LinearAlgebra::CUDAWrappers::Vector coef; - // double delta_t = 0; - // }; - - - - // template - // LaplaceOperator::LaplaceOperator() - // : MatrixFreeOperators::Base() - // {} - - - - // template - // void - // LaplaceOperator::clear() - // { - // coefficient.reinit(0, 0); - // MatrixFreeOperators::Base::clear(); - // } - - - - // template - // void - // LaplaceOperator::evaluate_coefficient( - // const Coefficient &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 - // void - // LaplaceOperator::local_apply( - // const MatrixFree &data, - // VectorType &dst, - // const VectorType &src, - // const std::pair &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 - // void - // LaplaceOperator::apply_add( - // VectorType &dst, - // const VectorType &src) const - // { - // this->data->cell_loop(&LaplaceOperator::local_apply, this, dst, src); - // } - - - - // template - // void - // LaplaceOperator::compute_diagonal() - // { - // this->inverse_diagonal_entries.reset(new DiagonalMatrix()); - // 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 - // void - // LaplaceOperator::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 \ No newline at end of file diff --git a/include/heat_transfer/heat_transfer.h b/include/heat_transfer/heat_transfer.h index ebc220b..e24443d 100644 --- a/include/heat_transfer/heat_transfer.h +++ b/include/heat_transfer/heat_transfer.h @@ -73,7 +73,7 @@ namespace Heat_Transfer } template double - Coefficient::value(const Point & p, + Coefficient::value(const Point &p, const unsigned int component) const { return value(p, component); @@ -142,7 +142,7 @@ namespace Heat_Transfer */ double compute_error( - const Function & function, + const Function &function, const LinearAlgebra::distributed::Vector &solution) const; /** * @brief output_results Output the generated results. @@ -187,7 +187,7 @@ namespace Heat_Transfer Adapter::Adapter>> precice_adapter; - std::unique_ptr> cuda_operator; + std::unique_ptr> cuda_operator; ConditionalOStream pcout; mutable TimerOutput timer; @@ -298,7 +298,7 @@ namespace Heat_Transfer system_matrix.evaluate_coefficient(Coefficient()); system_matrix.set_delta_t(time.get_delta_t()); - cuda_operator.reset(new CUDALaplaceOperator()); + cuda_operator.reset(new CUDALaplaceOperator()); cuda_operator->initialize(dof_handler, constraints); cuda_operator->set_delta_t(time.get_delta_t()); @@ -643,7 +643,7 @@ namespace Heat_Transfer template double LaplaceProblem::compute_error( - const Function & function, + const Function &function, const LinearAlgebra::distributed::Vector &solution) const { TimerOutput::Scope t(timer, "compute errors");