@@ -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;
0 commit comments