334 void eval(std::span<const geometry_type>
x, std::array<std::size_t, 2> xshape,
336 std::array<std::size_t, 2> ushape,
double tol,
int maxit)
const
341 assert(
x.size() == xshape[0] * xshape[1]);
342 assert(u.size() == ushape[0] * ushape[1]);
347 if (xshape[0] != cells.size())
349 throw std::invalid_argument(
350 "Number of points and number of cells must be equal.");
353 if (xshape[0] != ushape[0])
355 throw std::invalid_argument(
356 "Length of array for Function values must be the "
357 "same as the number of points.");
361 assert(_function_space);
362 auto mesh = _function_space->mesh();
364 const std::size_t gdim =
mesh->geometry().dim();
365 const std::size_t tdim =
mesh->topology()->dim();
366 auto map =
mesh->topology()->index_map(tdim);
370 =
mesh->geometry().cmaps().front();
373 auto x_dofmap =
mesh->geometry().dofmaps().front();
374 const std::size_t num_dofs_g = cmap.
dim();
375 auto x_g =
mesh->geometry().x();
378 auto element = _function_space->element();
380 const int bs_element = element->block_size();
381 const std::size_t reference_value_size = element->reference_value_size();
385 const std::size_t value_size = element->physical_base_value_size();
386 const std::size_t space_dimension = element->space_dimension() / bs_element;
390 const int num_sub_elements = element->num_sub_elements();
391 if (num_sub_elements > 1 and num_sub_elements != bs_element)
393 throw std::invalid_argument(
"Function::eval is not supported for mixed "
394 "elements. Extract subspaces.");
398 std::vector<value_type> coefficients(space_dimension * bs_element);
401 std::shared_ptr<const DofMap> dofmap = _function_space->dofmap();
403 const int bs_dof = dofmap->bs();
405 std::span<const std::uint32_t> cell_info;
406 if (element->needs_dof_transformations())
408 mesh->topology_mutable()->create_cell_permutations();
409 cell_info = std::span(
mesh->topology()->get_cell_permutation_info());
412 std::vector<geometry_type> coord_dofs_b(num_dofs_g * gdim);
413 impl::mdspan_t<geometry_type, 2> coord_dofs(coord_dofs_b.data(), num_dofs_g,
415 std::vector<geometry_type> xp_b(1 * gdim);
416 impl::mdspan_t<geometry_type, 2> xp(xp_b.data(), 1, gdim);
419 std::ranges::fill(u, 0);
420 std::span<const value_type> _v = _x->array();
424 std::array<std::size_t, 4> phi0_shape = cmap.
tabulate_shape(1, 1);
425 std::vector<geometry_type> phi0_b(std::reduce(
426 phi0_shape.begin(), phi0_shape.end(), 1, std::multiplies{}));
427 impl::mdspan_t<const geometry_type, 4> phi0(phi0_b.data(), phi0_shape);
428 cmap.
tabulate(1, std::vector<geometry_type>(tdim), {1, tdim}, phi0_b);
430 = md::submdspan(phi0, std::pair(1, tdim + 1), 0, md::full_extent, 0);
435 std::vector<geometry_type> phi_b(
436 std::reduce(phi_shape.begin(), phi_shape.end(), 1, std::multiplies{}));
437 impl::mdspan_t<const geometry_type, 4> phi(phi_b.data(), phi_shape);
439 = md::submdspan(phi, std::pair(1, tdim + 1), 0, md::full_extent, 0);
442 std::vector<geometry_type> Xb(xshape[0] * tdim);
443 impl::mdspan_t<geometry_type, 2> X(Xb.data(), xshape[0], tdim);
446 std::vector<geometry_type> J_b(xshape[0] * gdim * tdim);
447 impl::mdspan_t<geometry_type, 3> J(J_b.data(), xshape[0], gdim, tdim);
448 std::vector<geometry_type> K_b(xshape[0] * tdim * gdim);
449 impl::mdspan_t<geometry_type, 3> K(K_b.data(), xshape[0], tdim, gdim);
450 std::vector<geometry_type> detJ(xshape[0]);
451 std::vector<geometry_type> det_scratch(2 * gdim * tdim);
454 std::vector<geometry_type> pull_back_scratch(
458 for (
auto cell_it = cells.begin(); cell_it != cells.end(); ++cell_it)
465 auto x_dofs = md::submdspan(x_dofmap, *cell_it, md::full_extent);
466 assert(x_dofs.size() == num_dofs_g);
467 for (std::size_t i = 0; i < num_dofs_g; ++i)
469 const int pos = 3 * x_dofs[i];
470 for (std::size_t j = 0; j < gdim; ++j)
471 coord_dofs(i, j) = x_g[pos + j];
474 std::size_t p = std::ranges::distance(cells.begin(), cell_it);
475 for (std::size_t j = 0; j < gdim; ++j)
476 xp(0, j) =
x[p * xshape[1] + j];
478 auto _J = md::submdspan(J, p, md::full_extent, md::full_extent);
479 auto _K = md::submdspan(K, p, md::full_extent, md::full_extent);
481 std::array<geometry_type, 3> Xpb{0, 0, 0};
482 md::mdspan<geometry_type, md::extents<std::size_t, 1, md::dynamic_extent>>
483 Xp(Xpb.data(), 1, tdim);
491 std::array<geometry_type, 3> x0{0, 0, 0};
492 for (std::size_t i = 0; i < coord_dofs.extent(1); ++i)
493 x0[i] += coord_dofs(0, i);
504 cmap.
tabulate(1, std::span(Xpb.data(), tdim), {1, tdim}, phi_b);
513 for (std::size_t j = 0; j < X.extent(1); ++j)
518 std::vector<geometry_type> basis_derivatives_reference_values_b(
519 1 * xshape[0] * space_dimension * reference_value_size);
520 impl::mdspan_t<const geometry_type, 4> basis_derivatives_reference_values(
521 basis_derivatives_reference_values_b.data(), 1, xshape[0],
522 space_dimension, reference_value_size);
523 std::vector<geometry_type> basis_values_b(space_dimension * value_size);
524 impl::mdspan_t<geometry_type, 2> basis_values(basis_values_b.data(),
525 space_dimension, value_size);
528 element->tabulate(basis_derivatives_reference_values_b, Xb,
529 {X.extent(0), X.extent(1)}, 0);
531 using xu_t = impl::mdspan_t<geometry_type, 2>;
532 using xU_t = impl::mdspan_t<const geometry_type, 2>;
533 using xJ_t = impl::mdspan_t<const geometry_type, 2>;
534 using xK_t = impl::mdspan_t<const geometry_type, 2>;
536 = element->basix_element().template map_fn<xu_t, xU_t, xJ_t, xK_t>();
539 auto apply_dof_transformation
540 = element->template dof_transformation_fn<geometry_type>(
546 if (element->symmetric())
548 while (matrix_size * matrix_size < (
int)ushape[1])
552 const std::size_t num_basis_values = space_dimension * reference_value_size;
553 for (
auto cell_it = cells.begin(); cell_it != cells.end(); ++cell_it)
560 std::size_t p = std::ranges::distance(cells.begin(), cell_it);
561 if (apply_dof_transformation)
563 apply_dof_transformation(
564 std::span(basis_derivatives_reference_values_b.data()
565 + p * num_basis_values,
567 cell_info, *cell_it, reference_value_size);
571 auto _U = md::submdspan(basis_derivatives_reference_values, 0, p,
572 md::full_extent, md::full_extent);
573 auto _J = md::submdspan(J, p, md::full_extent, md::full_extent);
574 auto _K = md::submdspan(K, p, md::full_extent, md::full_extent);
575 push_forward_fn(basis_values, _U, _J, detJ[p], _K);
579 std::span<const std::int32_t> dofs = dofmap->cell_dofs(*cell_it);
580 for (std::size_t i = 0; i < dofs.size(); ++i)
581 for (
int k = 0; k < bs_dof; ++k)
582 coefficients[bs_dof * i + k] = _v[bs_dof * dofs[i] + k];
584 if (element->symmetric())
589 for (
int k = 0; k < bs_element; ++k)
591 if (k - rowstart > row)
596 for (std::size_t i = 0; i < space_dimension; ++i)
598 for (std::size_t j = 0; j < value_size; ++j)
601 + (j * bs_element + row * matrix_size + k - rowstart)]
602 += coefficients[bs_element * i + k] * basis_values(i, j);
603 if (k - rowstart != row)
606 + (j * bs_element + row + matrix_size * (k - rowstart))]
607 += coefficients[bs_element * i + k] * basis_values(i, j);
616 for (
int k = 0; k < bs_element; ++k)
618 for (std::size_t i = 0; i < space_dimension; ++i)
620 for (std::size_t j = 0; j < value_size; ++j)
622 u[p * ushape[1] + (j * bs_element + k)]
623 += coefficients[bs_element * i + k] * basis_values(i, j);