From c5c12285b5ee21f9fedf4b34e567129259dea637 Mon Sep 17 00:00:00 2001 From: IgorBaratta Date: Wed, 1 Nov 2023 12:42:27 +0000 Subject: [PATCH 1/2] remove print statements --- cpp/dolfinx/io/xdmf_function.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cpp/dolfinx/io/xdmf_function.cpp b/cpp/dolfinx/io/xdmf_function.cpp index 37a0ac3585b..bb65a2cc43f 100644 --- a/cpp/dolfinx/io/xdmf_function.cpp +++ b/cpp/dolfinx/io/xdmf_function.cpp @@ -24,21 +24,20 @@ using namespace dolfinx::io; namespace { -/// Convert a value_rank to the XDMF string description (Scalar, Vector, +/// Convert a shape to the XDMF string description (Scalar, Vector, /// Tensor). -std::string rank_to_string(int value_rank) +std::string shape_to_string(std::span shape) { - switch (value_rank) - { - case 0: + if (shape.size() == 0) + return "Scalar"; + else if (shape.size() == 1 and shape[0] == 1) return "Scalar"; - case 1: + else if (shape.size() == 1) return "Vector"; - case 2: + else if (shape.size() == 2) return "Tensor"; - default: - throw std::runtime_error("Range Error"); - } + else + throw std::runtime_error("Unsupported value shape"); } } // namespace @@ -53,7 +52,8 @@ void xdmf_function::add_function(MPI_Comm comm, const fem::Function& u, assert(u.function_space()); auto mesh = u.function_space()->mesh(); assert(mesh); - auto element = u.function_space()->element(); + std::shared_ptr> element + = u.function_space()->element(); assert(element); // FIXME: is the below check adequate for detecting a Lagrange @@ -75,8 +75,9 @@ void xdmf_function::add_function(MPI_Comm comm, const fem::Function& u, assert(dofmap); const int bs = dofmap->bs(); - int rank = element->value_shape().size(); - int num_components = std::pow(3, rank); + std::span value_shape = element->value_shape(); + int num_components = std::reduce(value_shape.begin(), value_shape.end(), 1, + std::multiplies{}); // Get fem::Function data values and shape std::vector data_values; @@ -174,7 +175,8 @@ void xdmf_function::add_function(MPI_Comm comm, const fem::Function& u, pugi::xml_node attr_node = xml_node.append_child("Attribute"); assert(attr_node); attr_node.append_attribute("Name") = attr_name.c_str(); - attr_node.append_attribute("AttributeType") = rank_to_string(rank).c_str(); + attr_node.append_attribute("AttributeType") + = shape_to_string(value_shape).c_str(); attr_node.append_attribute("Center") = cell_centred ? "Cell" : "Node"; std::span> u; From 422bfa6f845763dc51372d8be073a4900967c098 Mon Sep 17 00:00:00 2001 From: Igor Baratta Date: Thu, 2 Nov 2023 11:40:17 +0000 Subject: [PATCH 2/2] Update cpp/dolfinx/io/xdmf_function.cpp Co-authored-by: Garth N. Wells --- cpp/dolfinx/io/xdmf_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/dolfinx/io/xdmf_function.cpp b/cpp/dolfinx/io/xdmf_function.cpp index bb65a2cc43f..b3f9a6b5cfc 100644 --- a/cpp/dolfinx/io/xdmf_function.cpp +++ b/cpp/dolfinx/io/xdmf_function.cpp @@ -28,7 +28,7 @@ namespace /// Tensor). std::string shape_to_string(std::span shape) { - if (shape.size() == 0) + if (shape.empty()) return "Scalar"; else if (shape.size() == 1 and shape[0] == 1) return "Scalar";