| 313 | //---------------------------------------------------------------------------- |
| 314 | template <dolfinx::scalar T, std::floating_point U> |
| 315 | void 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)) |
nothing calls this directly
no test coverage detected