Skip to content

Commit d26d8d6

Browse files
Update to latest API (#168)
* Updates for latest main * Remove deprecated lines
1 parent 4bf5ddc commit d26d8d6

File tree

4 files changed

+49
-53
lines changed

4 files changed

+49
-53
lines changed

src/cg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void axpy(la::Vector<U>& r, U alpha, const la::Vector<U>& x,
2020
const la::Vector<U>& y)
2121
{
2222
std::transform(x.array().begin(), x.array().end(), y.array().begin(),
23-
r.mutable_array().begin(),
23+
r.array().begin(),
2424
[alpha](auto x, auto y) { return alpha * x + y; });
2525
}
2626

src/cgpoisson_problem.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ cgpoisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order,
7070
common::Timer t2("ZZZ Create boundary conditions");
7171
// Define boundary condition
7272
auto u0 = std::make_shared<fem::Function<T>>(V);
73-
u0->x()->set(0);
73+
std::ranges::fill(u0->x()->array(), 0.0);
7474

7575
// Find facets with bc applied
7676
const int tdim = mesh->topology()->dim();
@@ -147,24 +147,25 @@ cgpoisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order,
147147
// Create la::Vector
148148
la::Vector<T> b(L->function_spaces()[0]->dofmap()->index_map,
149149
L->function_spaces()[0]->dofmap()->index_map_bs());
150-
b.set(0);
150+
std::ranges::fill(b.array(), 0.0);
151+
151152
common::Timer t5("ZZZ Assemble vector");
152153
const std::vector constants_L = fem::pack_constants(*L);
153154
auto coeffs_L = fem::allocate_coefficient_storage(*L);
154155
fem::pack_coefficients(*L, coeffs_L);
155-
fem::assemble_vector<T>(b.mutable_array(), *L, constants_L,
156-
fem::make_coefficients_span(coeffs_L));
156+
fem::assemble_vector(b.array(), *L, std::span<const T>(constants_L),
157+
fem::make_coefficients_span(coeffs_L));
157158

158159
// Apply lifting to account for Dirichlet boundary condition
159160
// b <- b - A * x_bc
160-
bc->set(un->x()->mutable_array(), std::nullopt, -1.0);
161-
fem::assemble_vector(b.mutable_array(), *M);
161+
bc->set(un->x()->array(), std::nullopt, -1.0);
162+
fem::assemble_vector(b.array(), *M);
162163

163164
// Communicate ghost values
164165
b.scatter_rev(std::plus<T>());
165166

166167
// Set BC dofs to zero (effectively zeroes columns of A)
167-
bc->set(b.mutable_array(), std::nullopt, 0.0);
168+
bc->set(b.array(), std::nullopt, 0.0);
168169
b.scatter_fwd();
169170

170171
// Pack coefficients and constants
@@ -185,52 +186,47 @@ cgpoisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order,
185186
int bs = V->dofmap()->bs();
186187
common::Scatterer sct(*idx_map, bs);
187188

188-
std::vector<T> local_buffer(sct.local_buffer_size(), 0);
189-
std::vector<T> remote_buffer(sct.remote_buffer_size(), 0);
190-
191-
common::Scatterer<>::type type;
192-
if (scatterer == "neighbor")
193-
type = common::Scatterer<>::type::neighbor;
194-
if (scatterer == "p2p")
195-
type = common::Scatterer<>::type::p2p;
196-
197-
std::vector<MPI_Request> request = sct.create_request_vector(type);
189+
std::vector<T> local_buffer(sct.local_indices().size(), 0);
190+
std::vector<T> remote_buffer(sct.remote_indices().size(), 0);
198191

199192
// Create function for computing the action of A on x (y = Ax)
200193
auto action = [&](la::Vector<T>& x, la::Vector<T>& y)
201194
{
202195
// Zero y
203-
y.set(0.0);
196+
std::ranges::fill(y.array(), 0.0);
204197

205198
// Update coefficient un (just copy data from x to un)
206-
std::copy(x.array().begin(), x.array().end(),
207-
un->x()->mutable_array().begin());
199+
std::copy(x.array().begin(), x.array().end(), un->x()->array().begin());
208200

209201
// Compute action of A on x
210202
fem::pack_coefficients(*M, coeff);
211-
fem::assemble_vector(y.mutable_array(), *M, std::span<const T>(constants),
203+
fem::assemble_vector(y.array(), *M, std::span<const T>(constants),
212204
fem::make_coefficients_span(coeff));
213205

214206
// Set BC dofs to zero (effectively zeroes rows of A)
215-
bc->set(y.mutable_array(), std::nullopt, 0.0);
207+
bc->set(y.array(), std::nullopt, 0.0);
216208

217209
// Accumuate ghost values
218210
// y.scatter_rev(std::plus<T>());
219211

220212
const std::int32_t local_size = bs * idx_map->size_local();
221213
const std::int32_t num_ghosts = bs * idx_map->num_ghosts();
222-
std::span<T> remote_data(y.mutable_array().data() + local_size,
223-
num_ghosts);
224-
std::span<T> local_data(y.mutable_array().data(), local_size);
225-
sct.scatter_rev_begin<T>(remote_data, remote_buffer, local_buffer,
226-
pack_fn, request, type);
227-
sct.scatter_rev_end<T>(local_buffer, local_data, unpack_fn,
228-
std::plus<T>(), request);
214+
std::span<T> remote_data(y.array().data() + local_size, num_ghosts);
215+
std::span<T> local_data(y.array().data(), local_size);
216+
217+
MPI_Request request = MPI_REQUEST_NULL;
218+
pack_fn(remote_data, sct.remote_indices(), remote_buffer);
219+
sct.scatter_rev_begin(remote_buffer.data(), local_buffer.data(), request);
220+
sct.scatter_end(request);
221+
unpack_fn(local_buffer, sct.local_indices(), local_data, std::plus<T>());
229222

230223
// Update ghost values
231-
sct.scatter_fwd_begin<T>(local_data, local_buffer, remote_buffer, pack_fn,
232-
request, type);
233-
sct.scatter_fwd_end<T>(remote_buffer, remote_data, unpack_fn, request);
224+
request = MPI_REQUEST_NULL;
225+
pack_fn(local_data, sct.local_indices(), local_buffer);
226+
sct.scatter_fwd_begin(local_buffer.data(), remote_buffer.data(), request);
227+
sct.scatter_end(request);
228+
unpack_fn(remote_buffer, sct.remote_indices(), remote_data,
229+
[](auto x, auto y) { return y; });
234230
};
235231

236232
common::Timer tcg;

src/elasticity_problem.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ MatNullSpace build_near_nullspace(const fem::FunctionSpace<double>& V)
4444
std::int32_t length_block = map->size_local() + map->num_ghosts();
4545
for (int k = 0; k < 3; ++k)
4646
{
47-
std::span<T> x = basis[k].mutable_array();
47+
std::span<T> x = basis[k].array();
4848
for (std::int32_t i = 0; i < length_block; ++i)
4949
x[bs * i + k] = 1.0;
5050
}
5151

5252
// Rotations
53-
auto x3 = basis[3].mutable_array();
54-
auto x4 = basis[4].mutable_array();
55-
auto x5 = basis[5].mutable_array();
53+
auto x3 = basis[3].array();
54+
auto x4 = basis[4].array();
55+
auto x5 = basis[5].array();
5656

5757
const std::vector<double> x = V.tabulate_dof_coordinates(false);
5858
const std::int32_t* dofs = V.dofmap()->map().data_handle();
@@ -117,7 +117,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
117117

118118
// Define boundary condition
119119
auto u0 = std::make_shared<fem::Function<T>>(V);
120-
u0->x()->set(0);
120+
std::ranges::fill(u0->x()->array(), 0.0);
121121

122122
const int tdim = mesh->topology()->dim();
123123

@@ -215,18 +215,18 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
215215
// Wrap la::Vector with Petsc Vec
216216
la::Vector<T> b(L->function_spaces()[0]->dofmap()->index_map,
217217
L->function_spaces()[0]->dofmap()->index_map_bs());
218-
b.set(0);
218+
std::ranges::fill(b.array(), 0.0);
219+
219220
common::Timer t3("ZZZ Assemble vector");
220221
const std::vector constants_L = fem::pack_constants(*L);
221222
auto coeffs_L = fem::allocate_coefficient_storage(*L);
222223
fem::pack_coefficients(*L, coeffs_L);
223-
fem::assemble_vector<T>(b.mutable_array(), *L, constants_L,
224-
fem::make_coefficients_span(coeffs_L));
225-
fem::apply_lifting<T, double>(b.mutable_array(), {*a}, {constants_L},
226-
{fem::make_coefficients_span(coeffs_L)},
227-
{{*bc}}, {}, 1.0);
224+
fem::assemble_vector(b.array(), *L, std::span<const T>(constants_L),
225+
fem::make_coefficients_span(coeffs_L));
226+
fem::apply_lifting(b.array(), {*a}, {constants_L},
227+
{fem::make_coefficients_span(coeffs_L)}, {{*bc}}, {}, 1.0);
228228
b.scatter_rev(std::plus<>());
229-
bc->set(b.mutable_array(), std::nullopt);
229+
bc->set(b.array(), std::nullopt);
230230
t3.stop();
231231
t3.flush();
232232

src/poisson_problem.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ poisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
5151
common::Timer t2("ZZZ Create boundary conditions");
5252
// Define boundary condition
5353
auto u0 = std::make_shared<fem::Function<T>>(V);
54-
u0->x()->set(0);
54+
std::ranges::fill(u0->x()->array(), 0.0);
5555

5656
// Find facets with bc applied
5757
const int tdim = mesh->topology()->dim();
@@ -141,18 +141,18 @@ poisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
141141
// Create la::Vector
142142
la::Vector<T> b(L->function_spaces()[0]->dofmap()->index_map,
143143
L->function_spaces()[0]->dofmap()->index_map_bs());
144-
b.set(0);
144+
std::ranges::fill(b.array(), 0.0);
145+
145146
common::Timer t5("ZZZ Assemble vector");
146147
const std::vector constants_L = fem::pack_constants(*L);
147148
auto coeffs_L = fem::allocate_coefficient_storage(*L);
148149
fem::pack_coefficients(*L, coeffs_L);
149-
fem::assemble_vector<T>(b.mutable_array(), *L, constants_L,
150-
fem::make_coefficients_span(coeffs_L));
151-
fem::apply_lifting<T, double>(b.mutable_array(), {*a}, {constants_L},
152-
{fem::make_coefficients_span(coeffs_L)},
153-
{{*bc}}, {}, 1.0);
150+
fem::assemble_vector(b.array(), *L, std::span<const T>(constants_L),
151+
fem::make_coefficients_span(coeffs_L));
152+
fem::apply_lifting(b.array(), {*a}, {constants_L},
153+
{fem::make_coefficients_span(coeffs_L)}, {{*bc}}, {}, 1.0);
154154
b.scatter_rev(std::plus<>());
155-
bc->set(b.mutable_array(), std::nullopt);
155+
bc->set(b.array(), std::nullopt);
156156
t5.stop();
157157
t5.flush();
158158

0 commit comments

Comments
 (0)