Skip to content

Commit 77cc10e

Browse files
committed
wip
1 parent d6ed5ab commit 77cc10e

File tree

7 files changed

+784
-191
lines changed

7 files changed

+784
-191
lines changed

examples/deal.II/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ IF(NOT ${deal.II_FOUND})
1111
)
1212
ENDIF()
1313

14-
DEAL_II_INITIALIZE_CACHED_VARIABLES()
15-
PROJECT("bps")
14+
FILE(GLOB SOURCE_FILES "*.cc")
1615

17-
DEAL_II_INITIALIZE_CACHED_VARIABLES()
16+
FOREACH ( source_file ${SOURCE_FILES} )
17+
GET_FILENAME_COMPONENT(file_name ${source_file} NAME)
18+
STRING( REPLACE ".cc" "" exec ${file_name} )
1819

19-
ADD_EXECUTABLE(bps bps.cc)
20-
DEAL_II_SETUP_TARGET(bps)
20+
DEAL_II_INITIALIZE_CACHED_VARIABLES()
21+
PROJECT(${exec})
2122

22-
TARGET_INCLUDE_DIRECTORIES(bps PUBLIC ${CEED_DIR}/include)
23-
TARGET_LINK_LIBRARIES(bps ${CEED_DIR}/lib/libceed.so)
23+
DEAL_II_INITIALIZE_CACHED_VARIABLES()
24+
25+
ADD_EXECUTABLE(${exec} ${source_file})
26+
DEAL_II_SETUP_TARGET(${exec})
27+
28+
TARGET_INCLUDE_DIRECTORIES(${exec} PUBLIC ${CEED_DIR}/include)
29+
TARGET_LINK_LIBRARIES(${exec} ${CEED_DIR}/lib/libceed.so)
30+
31+
ENDFOREACH ( source_file ${SOURCE_FILES} )

examples/deal.II/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ make
1515
To run the executable, write:
1616

1717
```
18-
./bps
18+
./bps_cpu
19+
```
20+
21+
```
22+
./bps_kokkos
1923
```
2024

2125
Optional command-line arguments are shown by adding the command-line argument "--help".
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
// include operators
4949
#include "bps.h"
50+
#include "bps-cpu.h"
5051

5152
// Test cases
5253
//TESTARGS(name="BP1") --resource {ceed_resource} --bp BP1 --fe_degree 2 --print_timings 0
@@ -61,7 +62,7 @@ struct Parameters
6162
unsigned int n_global_refinements = 1;
6263
unsigned int fe_degree = 2;
6364
bool print_timings = true;
64-
std::string libCEED_resource = "/cpu/self";
65+
std::string libCEED_resource = "/cpu/self";
6566

6667
bool
6768
parse(int argc, char *argv[])

examples/deal.II/bps-cpu.h

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
// ---------------------------------------------------------------------
2+
//
3+
// Copyright (C) 2023 by the deal.II authors
4+
//
5+
// This file is part of the deal.II library.
6+
//
7+
// The deal.II library is free software; you can use it, redistribute
8+
// it, and/or modify it under the terms of the GNU Lesser General
9+
// Public License as published by the Free Software Foundation; either
10+
// version 2.1 of the License, or (at your option) any later version.
11+
// The full text of the license can be found in the file LICENSE.md at
12+
// the top level directory of deal.II.
13+
//
14+
// Authors: Peter Munch, Martin Kronbichler
15+
//
16+
// ---------------------------------------------------------------------
17+
18+
// deal.II includes
19+
#include <deal.II/dofs/dof_tools.h>
20+
21+
#include <deal.II/fe/mapping.h>
22+
23+
#include <deal.II/lac/la_parallel_vector.h>
24+
25+
#include <deal.II/matrix_free/fe_evaluation.h>
26+
#include <deal.II/matrix_free/matrix_free.h>
27+
#include <deal.II/matrix_free/shape_info.h>
28+
#include <deal.II/matrix_free/tools.h>
29+
30+
// libCEED includes
31+
#include <ceed.h>
32+
#include <ceed/backend.h>
33+
34+
// QFunction source
35+
#include "bps-qfunctions.h"
36+
37+
using namespace dealii;
38+
39+
40+
template <int dim, typename Number>
41+
class OperatorDealii : public OperatorBase<Number>
42+
{
43+
public:
44+
using VectorType = typename OperatorBase<Number>::VectorType;
45+
46+
/**
47+
* Constructor.
48+
*/
49+
OperatorDealii(const Mapping<dim> &mapping,
50+
const DoFHandler<dim> &dof_handler,
51+
const AffineConstraints<Number> &constraints,
52+
const Quadrature<dim> &quadrature,
53+
const BPType &bp)
54+
: mapping(mapping)
55+
, dof_handler(dof_handler)
56+
, constraints(constraints)
57+
, quadrature(quadrature)
58+
, bp(bp)
59+
{
60+
reinit();
61+
}
62+
63+
/**
64+
* Destructor.
65+
*/
66+
~OperatorDealii() = default;
67+
68+
/**
69+
* Initialized internal data structures, particularly, MatrixFree.
70+
*/
71+
void
72+
reinit() override
73+
{
74+
// configure MatrixFree
75+
typename MatrixFree<dim, Number>::AdditionalData additional_data;
76+
additional_data.tasks_parallel_scheme =
77+
MatrixFree<dim, Number>::AdditionalData::TasksParallelScheme::none;
78+
79+
// create MatrixFree
80+
matrix_free.reinit(mapping, dof_handler, constraints, quadrature, additional_data);
81+
}
82+
83+
/**
84+
* Matrix-vector product.
85+
*/
86+
void
87+
vmult(VectorType &dst, const VectorType &src) const override
88+
{
89+
if (dof_handler.get_fe().n_components() == 1)
90+
{
91+
matrix_free.cell_loop(&OperatorDealii::do_cell_integral_range<1>, this, dst, src, true);
92+
}
93+
else
94+
{
95+
AssertThrow(dof_handler.get_fe().n_components() == dim, ExcInternalError());
96+
97+
matrix_free.cell_loop(&OperatorDealii::do_cell_integral_range<dim>, this, dst, src, true);
98+
}
99+
}
100+
101+
/**
102+
* Initialize vector.
103+
*/
104+
void
105+
initialize_dof_vector(VectorType &vec) const override
106+
{
107+
matrix_free.initialize_dof_vector(vec);
108+
}
109+
110+
/**
111+
* Compute inverse of diagonal.
112+
*/
113+
void
114+
compute_inverse_diagonal(VectorType &diagonal) const override
115+
{
116+
this->initialize_dof_vector(diagonal);
117+
118+
if (dof_handler.get_fe().n_components() == 1)
119+
{
120+
MatrixFreeTools::compute_diagonal(matrix_free,
121+
diagonal,
122+
&OperatorDealii::do_cell_integral_local<1>,
123+
this);
124+
}
125+
else
126+
{
127+
AssertThrow(dof_handler.get_fe().n_components() == dim, ExcInternalError());
128+
129+
MatrixFreeTools::compute_diagonal(matrix_free,
130+
diagonal,
131+
&OperatorDealii::do_cell_integral_local<dim>,
132+
this);
133+
}
134+
135+
for (auto &i : diagonal)
136+
i = (std::abs(i) > 1.0e-10) ? (1.0 / i) : 1.0;
137+
}
138+
139+
private:
140+
/**
141+
* Cell integral without vector access.
142+
*/
143+
template <int n_components>
144+
void
145+
do_cell_integral_local(FEEvaluation<dim, -1, 0, n_components, Number> &phi) const
146+
{
147+
if (bp <= BPType::BP2) // mass matrix
148+
{
149+
phi.evaluate(EvaluationFlags::values);
150+
for (const auto q : phi.quadrature_point_indices())
151+
phi.submit_value(phi.get_value(q), q);
152+
phi.integrate(EvaluationFlags::values);
153+
}
154+
else // Poisson operator
155+
{
156+
phi.evaluate(EvaluationFlags::gradients);
157+
for (const auto q : phi.quadrature_point_indices())
158+
phi.submit_gradient(phi.get_gradient(q), q);
159+
phi.integrate(EvaluationFlags::gradients);
160+
}
161+
}
162+
163+
/**
164+
* Cell integral on a range of cells.
165+
*/
166+
template <int n_components>
167+
void
168+
do_cell_integral_range(const MatrixFree<dim, Number> &matrix_free,
169+
VectorType &dst,
170+
const VectorType &src,
171+
const std::pair<unsigned int, unsigned int> &range) const
172+
{
173+
FEEvaluation<dim, -1, 0, n_components, Number> phi(matrix_free, range);
174+
175+
for (unsigned cell = range.first; cell < range.second; ++cell)
176+
{
177+
phi.reinit(cell);
178+
phi.read_dof_values(src); // read source vector
179+
do_cell_integral_local(phi); // cell integral
180+
phi.distribute_local_to_global(dst); // write to destination vector
181+
}
182+
}
183+
184+
/**
185+
* Mapping object passed to the constructor.
186+
*/
187+
const Mapping<dim> &mapping;
188+
189+
/**
190+
* DoFHandler object passed to the constructor.
191+
*/
192+
const DoFHandler<dim> &dof_handler;
193+
194+
/**
195+
* Constraints object passed to the constructor.
196+
*/
197+
const AffineConstraints<Number> &constraints;
198+
199+
/**
200+
* Quadrature rule object passed to the constructor.
201+
*/
202+
const Quadrature<dim> &quadrature;
203+
204+
/**
205+
* Selected BP.
206+
*/
207+
const BPType bp;
208+
209+
/**
210+
* MatrixFree object.
211+
*/
212+
MatrixFree<dim, Number> matrix_free;
213+
};

0 commit comments

Comments
 (0)