MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / add_function

Method add_function

cpp/dolfinx/io/xdmf_function.cpp:48–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46//-----------------------------------------------------------------------------
47template <dolfinx::scalar T, std::floating_point U>
48void xdmf_function::add_function(MPI_Comm comm, const fem::Function<T, U>& u,
49 double t, pugi::xml_node& xml_node,
50 hid_t h5_id)
51{
52 spdlog::info("Adding function to node \"{}\"", xml_node.path('/'));
53
54 assert(u.function_space());
55 auto mesh = u.function_space()->mesh();
56 assert(mesh);
57 std::shared_ptr<const fem::FiniteElement<U>> element
58 = u.function_space()->element();
59 assert(element);
60
61 // FIXME: is the below check adequate for detecting a Lagrange
62 // element?
63 // Check that element is Lagrange
64 if (!element->interpolation_ident())
65 {
66 throw std::runtime_error("Only Lagrange functions are supported. "
67 "Interpolate Functions before output.");
68 }
69
70 auto map_c = mesh->topology()->index_map(mesh->topology()->dim());
71 assert(map_c);
72
73 auto map_x = mesh->geometry().index_map();
74 assert(map_x);
75
76 auto dofmap = u.function_space()->dofmap();
77 assert(dofmap);
78 const int bs = dofmap->bs();
79
80 // Pad to 3D if vector/tensor is product of dimensions is smaller than 3**rank
81 // to ensure that we can visualize them correctly in Paraview
82 std::span<const std::size_t> value_shape
83 = u.function_space()->element()->value_shape();
84 int rank = value_shape.size();
85 int num_components = std::reduce(value_shape.begin(), value_shape.end(), 1,
86 std::multiplies{});
87 if (num_components < std::pow(3, rank))
88 num_components = std::pow(3, rank);
89
90 // Get fem::Function data values and shape
91 std::vector<T> data_values;
92 std::span<const T> x = u.x()->array();
93
94 const bool cell_centred
95 = element->space_dimension() / element->block_size() == 1;
96 if (cell_centred)
97 {
98 // Get dof array and pack into array (padded where appropriate)
99 const std::int32_t num_local_cells = map_c->size_local();
100 data_values.resize(num_local_cells * num_components, 0);
101 for (std::int32_t c = 0; c < num_local_cells; ++c)
102 {
103 auto dofs = dofmap->cell_dofs(c);
104 assert(dofs.size() == 1);
105 for (std::size_t i = 0; i < dofs.size(); ++i)

Callers

nothing calls this directly

Calls 15

shape_to_stringFunction · 0.85
transformFunction · 0.85
add_data_itemFunction · 0.85
geometryMethod · 0.80
size_localMethod · 0.80
cmapsMethod · 0.80
basix_elementMethod · 0.80
num_ghostsMethod · 0.80
size_globalMethod · 0.80
function_spaceMethod · 0.45
meshMethod · 0.45
elementMethod · 0.45

Tested by

no test coverage detected