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

Function write_function

cpp/dolfinx/io/VTKFile.cpp:315–703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313//----------------------------------------------------------------------------
314template <dolfinx::scalar T, std::floating_point U>
315void write_function(
316 const std::vector<std::reference_wrapper<const fem::Function<T, U>>>& u,
317 double time, pugi::xml_document* xml_doc,
318 const std::filesystem::path& filename)
319{
320 if (!xml_doc)
321 throw std::runtime_error("VTKFile has been closed");
322 if (u.empty())
323 return;
324
325 // Extract the first function space with pointwise data. If no
326 // pointwise functions, take first FunctionSpace.
327 auto V0 = u.front().get().function_space();
328 assert(V0);
329 for (auto& v : u)
330 {
331 auto V = v.get().function_space();
332 assert(V);
333 if (!impl::is_cellwise(*V->element()))
334 {
335 V0 = V;
336 break;
337 }
338 }
339
340 // Check compatibility for all functions
341 auto mesh0 = V0->mesh();
342 assert(mesh0);
343 auto element0 = V0->element();
344 for (auto& v : u)
345 {
346 auto V = v.get().function_space();
347 assert(V);
348
349 // Check that functions share common mesh
350 assert(V->mesh());
351 if (V->mesh() != mesh0)
352 {
353 throw std::runtime_error(
354 "All Functions written to VTK file must share the same Mesh.");
355 }
356
357 // Check that v isn't a sub-function
358 if (!V->component().empty())
359 throw std::runtime_error("Cannot write sub-Functions to VTK file.");
360
361 auto e = V->element();
362 assert(e);
363
364 // Check that element uses point evaluations
365 if (!e->interpolation_ident())
366 {
367 throw std::runtime_error("Only Lagrange functions are supported. "
368 "Interpolate Functions before output.");
369 }
370
371 // Check that pointwise elements are the same (up to the block size)
372 if (!impl::is_cellwise(*e))

Callers

nothing calls this directly

Calls 15

is_cellwiseFunction · 0.85
get_counterFunction · 0.85
vtk_mesh_from_spaceFunction · 0.85
add_dataFunction · 0.85
add_pvtu_meshFunction · 0.85
geometryMethod · 0.80
input_global_indicesMethod · 0.80
size_localMethod · 0.80
set_valueMethod · 0.80
num_ghostsMethod · 0.80
function_spaceMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected