DOLFINx
DOLFINx C++ interface
Loading...
Searching...
No Matches
Function.h
1// Copyright (C) 2003-2022 Anders Logg, Garth N. Wells and Massimiliano Leoni
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include "DofMap.h"
10#include "FiniteElement.h"
11#include "FunctionSpace.h"
12#include "interpolate.h"
13#include <concepts>
14#include <dolfinx/common/IndexMap.h>
15#include <dolfinx/common/types.h>
16#include <dolfinx/la/Vector.h>
17#include <dolfinx/mesh/Geometry.h>
18#include <dolfinx/mesh/Mesh.h>
19#include <dolfinx/mesh/Topology.h>
20#include <functional>
21#include <memory>
22#include <numeric>
23#include <span>
24#include <string>
25#include <utility>
26#include <vector>
27
28namespace dolfinx::fem
29{
30template <dolfinx::scalar T, std::floating_point U>
31class Expression;
32
42template <dolfinx::scalar T,
43 std::floating_point U = dolfinx::scalar_value_type_t<T>>
45{
46public:
49 using value_type = T;
51 using geometry_type = U;
52
55 explicit Function(std::shared_ptr<const FunctionSpace<geometry_type>> V)
56 : _function_space(V),
57 _x(std::make_shared<la::Vector<value_type>>(
58 V->dofmap()->index_map, V->dofmap()->index_map_bs()))
59 {
60 if (!V->component().empty())
61 {
62 throw std::runtime_error("Cannot create Function from subspace. Consider "
63 "collapsing the function space");
64 }
65 }
66
75 Function(std::shared_ptr<const FunctionSpace<geometry_type>> V,
76 std::shared_ptr<la::Vector<value_type>> x)
77 : _function_space(V), _x(x)
78 {
79 // We do not check for a subspace since this constructor is used for
80 // creating subfunctions
81
82 // Assertion uses '<=' to deal with sub-functions
83 assert(V->dofmap());
84 assert(V->dofmap()->index_map->size_global() * V->dofmap()->index_map_bs()
85 <= _x->bs() * _x->index_map()->size_global());
86 }
87
88 // Copy constructor
89 Function(const Function& v) = delete;
90
92 Function(Function&& v) = default;
93
95 ~Function() = default;
96
98 Function& operator=(Function&& v) = default;
99
100 // Assignment
101 Function& operator=(const Function& v) = delete;
102
106 Function sub(int i) const
107 {
108 auto sub_space = std::make_shared<FunctionSpace<geometry_type>>(
109 _function_space->sub({i}));
110 assert(sub_space);
111 return Function(sub_space, _x);
112 }
113
118 {
119 // Create new collapsed FunctionSpace
120 auto [V, map] = _function_space->collapse();
121
122 // Create new vector
123 auto x = std::make_shared<la::Vector<value_type>>(
124 V.dofmap()->index_map, V.dofmap()->index_map_bs());
125
126 // Copy values into new vector
127 std::span<const value_type> x_old = _x->array();
128 std::span<value_type> x_new = x->mutable_array();
129 for (std::size_t i = 0; i < map.size(); ++i)
130 {
131 assert((int)i < x_new.size());
132 assert(map[i] < x_old.size());
133 x_new[i] = x_old[map[i]];
134 }
135
136 return Function(
137 std::make_shared<FunctionSpace<geometry_type>>(std::move(V)), x);
138 }
139
142 std::shared_ptr<const FunctionSpace<geometry_type>> function_space() const
143 {
144 return _function_space;
145 }
146
148 std::shared_ptr<const la::Vector<value_type>> x() const { return _x; }
149
151 std::shared_ptr<la::Vector<value_type>> x() { return _x; }
152
161 std::span<const std::int32_t> cells,
162 const std::tuple<std::span<const std::int32_t>,
163 std::span<const std::int32_t>,
164 std::span<const geometry_type>,
165 std::span<const std::int32_t>>& nmm_interpolation_data
166 = {})
167 {
168 fem::interpolate(*this, v, cells, nmm_interpolation_data);
169 }
170
178 const std::tuple<std::span<const std::int32_t>,
179 std::span<const std::int32_t>,
180 std::span<const geometry_type>,
181 std::span<const std::int32_t>>& nmm_interpolation_data
182 = {})
183 {
184 assert(_function_space);
185 assert(_function_space->mesh());
186 int tdim = _function_space->mesh()->topology()->dim();
187 auto cell_map = _function_space->mesh()->topology()->index_map(tdim);
188 assert(cell_map);
189 std::int32_t num_cells = cell_map->size_local() + cell_map->num_ghosts();
190 std::vector<std::int32_t> cells(num_cells, 0);
191 std::iota(cells.begin(), cells.end(), 0);
192 interpolate(v, cells, nmm_interpolation_data);
193 }
194
199 const std::function<
200 std::pair<std::vector<value_type>, std::vector<std::size_t>>(
201 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
202 const geometry_type,
203 MDSPAN_IMPL_STANDARD_NAMESPACE::extents<
204 std::size_t, 3,
205 MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent>>)>& f,
206 std::span<const std::int32_t> cells)
207 {
208 assert(_function_space);
209 assert(_function_space->element());
210 assert(_function_space->mesh());
211 const std::vector<geometry_type> x
212 = fem::interpolation_coords<geometry_type>(
213 *_function_space->element(), _function_space->mesh()->geometry(),
214 cells);
215 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
216 const geometry_type,
217 MDSPAN_IMPL_STANDARD_NAMESPACE::extents<
218 std::size_t, 3, MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent>>
219 _x(x.data(), 3, x.size() / 3);
220
221 const auto [fx, fshape] = f(_x);
222 assert(fshape.size() <= 2);
223 if (int vs = _function_space->value_size(); vs == 1 and fshape.size() == 1)
224 {
225 // Check for scalar-valued functions
226 if (fshape.front() != x.size() / 3)
227 throw std::runtime_error("Data returned by callable has wrong length");
228 }
229 else
230 {
231 // Check for vector/tensor value
232 if (fshape.size() != 2)
233 throw std::runtime_error("Expected 2D array of data");
234
235 if (fshape[0] != vs)
236 {
237 throw std::runtime_error(
238 "Data returned by callable has wrong shape(0) size");
239 }
240
241 if (fshape[1] != x.size() / 3)
242 {
243 throw std::runtime_error(
244 "Data returned by callable has wrong shape(1) size");
245 }
246 }
247
248 std::array<std::size_t, 2> _fshape;
249 if (fshape.size() == 1)
250 _fshape = {1, fshape[0]};
251 else
252 _fshape = {fshape[0], fshape[1]};
253
254 fem::interpolate(*this, std::span<const value_type>(fx.data(), fx.size()),
255 _fshape, cells);
256 }
257
260 void
261 interpolate(const std::function<
262 std::pair<std::vector<value_type>, std::vector<std::size_t>>(
263 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
264 const geometry_type,
265 MDSPAN_IMPL_STANDARD_NAMESPACE::extents<
266 std::size_t, 3,
267 MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent>>)>& f)
268 {
269 assert(_function_space);
270 assert(_function_space->mesh());
271 const int tdim = _function_space->mesh()->topology()->dim();
272 auto cell_map = _function_space->mesh()->topology()->index_map(tdim);
273 assert(cell_map);
274 std::int32_t num_cells = cell_map->size_local() + cell_map->num_ghosts();
275 std::vector<std::int32_t> cells(num_cells, 0);
276 std::iota(cells.begin(), cells.end(), 0);
277 interpolate(f, cells);
278 }
279
287 std::span<const std::int32_t> cells)
288 {
289 // Check that spaces are compatible
290 assert(_function_space);
291 assert(_function_space->element());
292 std::size_t value_size = e.value_size();
293 if (e.argument_function_space())
294 throw std::runtime_error("Cannot interpolate Expression with Argument");
295
296 if (value_size != _function_space->value_size())
297 {
298 throw std::runtime_error(
299 "Function value size not equal to Expression value size");
300 }
301
302 {
303 // Compatibility check
304 auto [X0, shape0] = e.X();
305 auto [X1, shape1] = _function_space->element()->interpolation_points();
306 if (shape0 != shape1)
307 {
308 throw std::runtime_error(
309 "Function element interpolation points has different shape to "
310 "Expression interpolation points");
311 }
312
313 for (std::size_t i = 0; i < X0.size(); ++i)
314 {
315 if (std::abs(X0[i] - X1[i]) > 1.0e-10)
316 {
317 throw std::runtime_error("Function element interpolation points not "
318 "equal to Expression interpolation points");
319 }
320 }
321 }
322
323 // Array to hold evaluated Expression
324 std::size_t num_cells = cells.size();
325 std::size_t num_points = e.X().second[0];
326 std::vector<value_type> fdata(num_cells * num_points * value_size);
327 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
328 const value_type,
329 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 3>>
330 f(fdata.data(), num_cells, num_points, value_size);
331
332 // Evaluate Expression at points
333 assert(_function_space->mesh());
334 e.eval(*_function_space->mesh(), cells, fdata,
335 {num_cells, num_points * value_size});
336
337 // Reshape evaluated data to fit interpolate
338 // Expression returns matrix of shape (num_cells, num_points *
339 // value_size), i.e. xyzxyz ordering of dof values per cell per
340 // point. The interpolation uses xxyyzz input, ordered for all
341 // points of each cell, i.e. (value_size, num_cells*num_points)
342 std::vector<value_type> fdata1(num_cells * num_points * value_size);
343 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
344 value_type, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 3>>
345 f1(fdata1.data(), value_size, num_cells, num_points);
346 for (std::size_t i = 0; i < f.extent(0); ++i)
347 for (std::size_t j = 0; j < f.extent(1); ++j)
348 for (std::size_t k = 0; k < f.extent(2); ++k)
349 f1(k, i, j) = f(i, j, k);
350
351 // Interpolate values into appropriate space
352 fem::interpolate(*this,
353 std::span<const value_type>(fdata1.data(), fdata1.size()),
354 {value_size, num_cells * num_points}, cells);
355 }
356
360 {
361 assert(_function_space);
362 assert(_function_space->mesh());
363 const int tdim = _function_space->mesh()->topology()->dim();
364 auto cell_map = _function_space->mesh()->topology()->index_map(tdim);
365 assert(cell_map);
366 std::int32_t num_cells = cell_map->size_local() + cell_map->num_ghosts();
367 std::vector<std::int32_t> cells(num_cells, 0);
368 std::iota(cells.begin(), cells.end(), 0);
369 interpolate(e, cells);
370 }
371
384 void eval(std::span<const geometry_type> x, std::array<std::size_t, 2> xshape,
385 std::span<const std::int32_t> cells, std::span<value_type> u,
386 std::array<std::size_t, 2> ushape) const
387 {
388 if (cells.empty())
389 return;
390
391 assert(x.size() == xshape[0] * xshape[1]);
392 assert(u.size() == ushape[0] * ushape[1]);
393
394 // TODO: This could be easily made more efficient by exploiting points
395 // being ordered by the cell to which they belong.
396
397 if (xshape[0] != cells.size())
398 {
399 throw std::runtime_error(
400 "Number of points and number of cells must be equal.");
401 }
402
403 if (xshape[0] != ushape[0])
404 {
405 throw std::runtime_error(
406 "Length of array for Function values must be the "
407 "same as the number of points.");
408 }
409
410 // Get mesh
411 assert(_function_space);
412 auto mesh = _function_space->mesh();
413 assert(mesh);
414 const std::size_t gdim = mesh->geometry().dim();
415 const std::size_t tdim = mesh->topology()->dim();
416 auto map = mesh->topology()->index_map(tdim);
417
418 // Get coordinate map
419 const CoordinateElement<geometry_type>& cmap = mesh->geometry().cmap();
420
421 // Get geometry data
422 auto x_dofmap = mesh->geometry().dofmap();
423 const std::size_t num_dofs_g = cmap.dim();
424 auto x_g = mesh->geometry().x();
425
426 // Get element
427 auto element = _function_space->element();
428 assert(element);
429 const int bs_element = element->block_size();
430 const std::size_t reference_value_size
431 = element->reference_value_size() / bs_element;
432 const std::size_t value_size = _function_space->value_size() / bs_element;
433 const std::size_t space_dimension = element->space_dimension() / bs_element;
434
435 // If the space has sub elements, concatenate the evaluations on the
436 // sub elements
437 const int num_sub_elements = element->num_sub_elements();
438 if (num_sub_elements > 1 and num_sub_elements != bs_element)
439 {
440 throw std::runtime_error("Function::eval is not supported for mixed "
441 "elements. Extract subspaces.");
442 }
443
444 // Create work vector for expansion coefficients
445 std::vector<value_type> coefficients(space_dimension * bs_element);
446
447 // Get dofmap
448 std::shared_ptr<const DofMap> dofmap = _function_space->dofmap();
449 assert(dofmap);
450 const int bs_dof = dofmap->bs();
451
452 std::span<const std::uint32_t> cell_info;
453 if (element->needs_dof_transformations())
454 {
455 mesh->topology_mutable()->create_entity_permutations();
456 cell_info = std::span(mesh->topology()->get_cell_permutation_info());
457 }
458
459 std::vector<geometry_type> coord_dofs_b(num_dofs_g * gdim);
460 impl::mdspan_t<geometry_type, 2> coord_dofs(coord_dofs_b.data(), num_dofs_g,
461 gdim);
462 std::vector<geometry_type> xp_b(1 * gdim);
463 impl::mdspan_t<geometry_type, 2> xp(xp_b.data(), 1, gdim);
464
465 // Loop over points
466 std::fill(u.data(), u.data() + u.size(), 0.0);
467 std::span<const value_type> _v = _x->array();
468
469 // Evaluate geometry basis at point (0, 0, 0) on the reference cell.
470 // Used in affine case.
471 std::array<std::size_t, 4> phi0_shape = cmap.tabulate_shape(1, 1);
472 std::vector<geometry_type> phi0_b(std::reduce(
473 phi0_shape.begin(), phi0_shape.end(), 1, std::multiplies{}));
474 impl::mdspan_t<const geometry_type, 4> phi0(phi0_b.data(), phi0_shape);
475 cmap.tabulate(1, std::vector<geometry_type>(tdim), {1, tdim}, phi0_b);
476 auto dphi0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
477 phi0, std::pair(1, tdim + 1), 0,
478 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
479
480 // Data structure for evaluating geometry basis at specific points.
481 // Used in non-affine case.
482 std::array<std::size_t, 4> phi_shape = cmap.tabulate_shape(1, 1);
483 std::vector<geometry_type> phi_b(
484 std::reduce(phi_shape.begin(), phi_shape.end(), 1, std::multiplies{}));
485 impl::mdspan_t<const geometry_type, 4> phi(phi_b.data(), phi_shape);
486 auto dphi = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
487 phi, std::pair(1, tdim + 1), 0,
488 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
489
490 // Reference coordinates for each point
491 std::vector<geometry_type> Xb(xshape[0] * tdim);
492 impl::mdspan_t<geometry_type, 2> X(Xb.data(), xshape[0], tdim);
493
494 // Geometry data at each point
495 std::vector<geometry_type> J_b(xshape[0] * gdim * tdim);
496 impl::mdspan_t<geometry_type, 3> J(J_b.data(), xshape[0], gdim, tdim);
497 std::vector<geometry_type> K_b(xshape[0] * tdim * gdim);
498 impl::mdspan_t<geometry_type, 3> K(K_b.data(), xshape[0], tdim, gdim);
499 std::vector<geometry_type> detJ(xshape[0]);
500 std::vector<geometry_type> det_scratch(2 * gdim * tdim);
501
502 // Prepare geometry data in each cell
503 for (std::size_t p = 0; p < cells.size(); ++p)
504 {
505 const int cell_index = cells[p];
506
507 // Skip negative cell indices
508 if (cell_index < 0)
509 continue;
510
511 // Get cell geometry (coordinate dofs)
512 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
513 x_dofmap, cell_index, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
514 assert(x_dofs.size() == num_dofs_g);
515 for (std::size_t i = 0; i < num_dofs_g; ++i)
516 {
517 const int pos = 3 * x_dofs[i];
518 for (std::size_t j = 0; j < gdim; ++j)
519 coord_dofs(i, j) = x_g[pos + j];
520 }
521
522 for (std::size_t j = 0; j < gdim; ++j)
523 xp(0, j) = x[p * xshape[1] + j];
524
525 auto _J = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
526 J, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
527 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
528 auto _K = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
529 K, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
530 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
531
532 std::array<geometry_type, 3> Xpb = {0, 0, 0};
533 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
535 MDSPAN_IMPL_STANDARD_NAMESPACE::extents<
536 std::size_t, 1, MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent>>
537 Xp(Xpb.data(), 1, tdim);
538
539 // Compute reference coordinates X, and J, detJ and K
540 if (cmap.is_affine())
541 {
543 _J);
545 std::array<geometry_type, 3> x0 = {0, 0, 0};
546 for (std::size_t i = 0; i < coord_dofs.extent(1); ++i)
547 x0[i] += coord_dofs(0, i);
549 detJ[p]
551 _J, det_scratch);
552 }
553 else
554 {
555 // Pull-back physical point xp to reference coordinate Xp
556 cmap.pull_back_nonaffine(Xp, xp, coord_dofs);
557
558 cmap.tabulate(1, std::span(Xpb.data(), tdim), {1, tdim}, phi_b);
560 _J);
562 detJ[p]
564 _J, det_scratch);
565 }
566
567 for (std::size_t j = 0; j < X.extent(1); ++j)
568 X(p, j) = Xpb[j];
569 }
570
571 // Prepare basis function data structures
572 std::vector<geometry_type> basis_derivatives_reference_values_b(
573 1 * xshape[0] * space_dimension * reference_value_size);
574 impl::mdspan_t<const geometry_type, 4> basis_derivatives_reference_values(
575 basis_derivatives_reference_values_b.data(), 1, xshape[0],
576 space_dimension, reference_value_size);
577 std::vector<geometry_type> basis_values_b(space_dimension * value_size);
578 impl::mdspan_t<geometry_type, 2> basis_values(basis_values_b.data(),
579 space_dimension, value_size);
580
581 // Compute basis on reference element
582 element->tabulate(basis_derivatives_reference_values_b, Xb,
583 {X.extent(0), X.extent(1)}, 0);
584
585 using xu_t = impl::mdspan_t<geometry_type, 2>;
586 using xU_t = impl::mdspan_t<const geometry_type, 2>;
587 using xJ_t = impl::mdspan_t<const geometry_type, 2>;
588 using xK_t = impl::mdspan_t<const geometry_type, 2>;
589 auto push_forward_fn
590 = element->basix_element().template map_fn<xu_t, xU_t, xJ_t, xK_t>();
591
592 auto apply_dof_transformation
593 = element
594 ->template get_pre_dof_transformation_function<geometry_type>();
595 const std::size_t num_basis_values = space_dimension * reference_value_size;
596
597 for (std::size_t p = 0; p < cells.size(); ++p)
598 {
599 const int cell_index = cells[p];
600
601 // Skip negative cell indices
602 if (cell_index < 0)
603 continue;
604
605 // Permute the reference values to account for the cell's
606 // orientation
607 apply_dof_transformation(
608 std::span(basis_derivatives_reference_values_b.data()
609 + p * num_basis_values,
610 num_basis_values),
611 cell_info, cell_index, reference_value_size);
612
613 {
614 auto _U = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
615 basis_derivatives_reference_values, 0, p,
616 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
617 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
618 auto _J = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
619 J, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
620 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
621 auto _K = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
622 K, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
623 MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
624 push_forward_fn(basis_values, _U, _J, detJ[p], _K);
625 }
626
627 // Get degrees of freedom for current cell
628 std::span<const std::int32_t> dofs = dofmap->cell_dofs(cell_index);
629 for (std::size_t i = 0; i < dofs.size(); ++i)
630 for (int k = 0; k < bs_dof; ++k)
631 coefficients[bs_dof * i + k] = _v[bs_dof * dofs[i] + k];
632
633 // Compute expansion
634 for (int k = 0; k < bs_element; ++k)
635 {
636 for (std::size_t i = 0; i < space_dimension; ++i)
637 {
638 for (std::size_t j = 0; j < value_size; ++j)
639 {
640 u[p * ushape[1] + (j * bs_element + k)]
641 += coefficients[bs_element * i + k] * basis_values(i, j);
642 }
643 }
644 }
645 }
646 }
647
649 std::string name = "u";
650
651private:
652 // The function space
653 std::shared_ptr<const FunctionSpace<geometry_type>> _function_space;
654
655 // The vector of expansion coefficients (local)
656 std::shared_ptr<la::Vector<value_type>> _x;
657};
658
659} // namespace dolfinx::fem
Degree-of-freedom map representations and tools.
A CoordinateElement manages coordinate mappings for isoparametric cells.
Definition CoordinateElement.h:38
static void compute_jacobian(const U &dphi, const V &cell_geometry, W &&J)
Compute Jacobian for a cell with given geometry using the basis functions and first order derivatives...
Definition CoordinateElement.h:105
static void pull_back_affine(U &&X, const V &K, const std::array< T, 3 > &x0, const W &x)
Compute reference coordinates X for physical coordinates x for an affine map. For the affine case,...
Definition CoordinateElement.h:188
void tabulate(int nd, std::span< const T > X, std::array< std::size_t, 2 > shape, std::span< T > basis) const
Evaluate basis values and derivatives at set of points.
Definition CoordinateElement.cpp:53
static void compute_jacobian_inverse(const U &J, V &&K)
Compute the inverse of the Jacobian.
Definition CoordinateElement.h:114
std::array< std::size_t, 4 > tabulate_shape(std::size_t nd, std::size_t num_points) const
Shape of array to fill when calling tabulate.
Definition CoordinateElement.cpp:46
int dim() const
The dimension of the coordinate element space.
Definition CoordinateElement.cpp:193
void pull_back_nonaffine(mdspan2_t< T > X, mdspan2_t< const T > x, mdspan2_t< const T > cell_geometry, double tol=1.0e-6, int maxit=15) const
Compute reference coordinates X for physical coordinates x for a non-affine map.
Definition CoordinateElement.cpp:70
bool is_affine() const noexcept
Check is geometry map is affine.
Definition CoordinateElement.h:242
static double compute_jacobian_determinant(const U &J, std::span< typename U::value_type > w)
Compute the determinant of the Jacobian.
Definition CoordinateElement.h:131
Represents a mathematical expression evaluated at a pre-defined set of points on the reference cell.
Definition Expression.h:41
This class represents a finite element function space defined by a mesh, a finite element,...
Definition FunctionSpace.h:34
This class represents a function in a finite element function space , given by.
Definition Function.h:45
U geometry_type
Geometry type of the Mesh that the Function is defined on.
Definition Function.h:51
std::shared_ptr< const FunctionSpace< geometry_type > > function_space() const
Access the function space.
Definition Function.h:142
void interpolate(const std::function< std::pair< std::vector< value_type >, std::vector< std::size_t > >(MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const geometry_type, MDSPAN_IMPL_STANDARD_NAMESPACE::extents< std::size_t, 3, MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent > >)> &f)
Interpolate an expression function on the whole domain.
Definition Function.h:261
void interpolate(const Function< value_type, geometry_type > &v, std::span< const std::int32_t > cells, const std::tuple< std::span< const std::int32_t >, std::span< const std::int32_t >, std::span< const geometry_type >, std::span< const std::int32_t > > &nmm_interpolation_data={})
Interpolate a provided Function.
Definition Function.h:159
void interpolate(const Function< value_type, geometry_type > &v, const std::tuple< std::span< const std::int32_t >, std::span< const std::int32_t >, std::span< const geometry_type >, std::span< const std::int32_t > > &nmm_interpolation_data={})
Interpolate a provided Function.
Definition Function.h:176
Function(std::shared_ptr< const FunctionSpace< geometry_type > > V)
Create function on given function space.
Definition Function.h:55
void interpolate(const Expression< value_type, geometry_type > &e, std::span< const std::int32_t > cells)
Interpolate an Expression (based on UFL)
Definition Function.h:286
Function collapse() const
Collapse a subfunction (view into a Function) to a stand-alone Function.
Definition Function.h:117
Function sub(int i) const
Extract a sub-function (a view into the Function).
Definition Function.h:106
std::string name
Name.
Definition Function.h:649
std::shared_ptr< la::Vector< value_type > > x()
Underlying vector.
Definition Function.h:151
void interpolate(const Expression< value_type, geometry_type > &e)
Interpolate an Expression (based on UFL) on all cells.
Definition Function.h:359
~Function()=default
Destructor.
void interpolate(const std::function< std::pair< std::vector< value_type >, std::vector< std::size_t > >(MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const geometry_type, MDSPAN_IMPL_STANDARD_NAMESPACE::extents< std::size_t, 3, MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent > >)> &f, std::span< const std::int32_t > cells)
Interpolate an expression function on a list of cells.
Definition Function.h:198
void eval(std::span< const geometry_type > x, std::array< std::size_t, 2 > xshape, std::span< const std::int32_t > cells, std::span< value_type > u, std::array< std::size_t, 2 > ushape) const
Evaluate the Function at points.
Definition Function.h:384
Function(Function &&v)=default
Move constructor.
std::shared_ptr< const la::Vector< value_type > > x() const
Underlying vector.
Definition Function.h:148
Function & operator=(Function &&v)=default
Move assignment.
Function(std::shared_ptr< const FunctionSpace< geometry_type > > V, std::shared_ptr< la::Vector< value_type > > x)
Create function on given function space with a given vector.
Definition Function.h:75
T value_type
Field type for the Function, e.g. double, std::complex<float>, etc.
Definition Function.h:49
Distributed vector.
Definition Vector.h:31
This concept is used to constrain the a template type to floating point real or complex types....
Definition types.h:20
Finite element method functionality.
Definition assemble_matrix_impl.h:26
void interpolate(Function< T, U > &u, std::span< const T > f, std::array< std::size_t, 2 > fshape, std::span< const std::int32_t > cells)
Interpolate an expression f(x) in a finite element space.
Definition interpolate.h:727