From 0866cbdff16e55a5e5d8c9efcab84fdd04d89d26 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Fri, 17 Sep 2021 14:28:05 +0200
Subject: [PATCH] [MeL] Remove Mesh-internal number of base nodes.

And with it all of the checks and recalculations are obsolete
and removed too.
---
 .../IO/MPI_IO/NodePartitionedMeshReader.cpp   |  3 +-
 MeshLib/Mesh.cpp                              | 49 +------------------
 MeshLib/Mesh.h                                | 18 +------
 .../MeshGenerators/QuadraticMeshGenerator.cpp |  4 +-
 MeshLib/NodePartitionedMesh.h                 |  4 +-
 5 files changed, 7 insertions(+), 71 deletions(-)

diff --git a/MeshLib/IO/MPI_IO/NodePartitionedMeshReader.cpp b/MeshLib/IO/MPI_IO/NodePartitionedMeshReader.cpp
index 44d7c1c65ec..10a4c50e038 100644
--- a/MeshLib/IO/MPI_IO/NodePartitionedMeshReader.cpp
+++ b/MeshLib/IO/MPI_IO/NodePartitionedMeshReader.cpp
@@ -384,8 +384,7 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::newMesh(
     return new MeshLib::NodePartitionedMesh(
         mesh_name, mesh_nodes, glb_node_ids, mesh_elems, properties,
         _mesh_info.global_base_nodes, _mesh_info.global_nodes,
-        _mesh_info.base_nodes, _mesh_info.active_base_nodes,
-        _mesh_info.active_nodes);
+        _mesh_info.active_base_nodes, _mesh_info.active_nodes);
 }
 
 void NodePartitionedMeshReader::setNodes(
diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp
index 44f26b12c64..6db16060a72 100644
--- a/MeshLib/Mesh.cpp
+++ b/MeshLib/Mesh.cpp
@@ -37,8 +37,7 @@ Mesh::Mesh(std::string name,
                nodes,
            std::vector<Element*>
                elements,
-           Properties const& properties,
-           const std::size_t n_base_nodes)
+           Properties const& properties)
     : _id(global_mesh_counter++),
       _mesh_dimension(0),
       _edge_length(std::numeric_limits<double>::max(), 0),
@@ -46,20 +45,10 @@ Mesh::Mesh(std::string name,
       _name(std::move(name)),
       _nodes(std::move(nodes)),
       _elements(std::move(elements)),
-      _n_base_nodes(n_base_nodes),
       _properties(properties)
 {
-    assert(_n_base_nodes <= _nodes.size());
     this->resetNodeIDs();
     this->resetElementIDs();
-    if (_n_base_nodes == 0)
-    {
-        recalculateMaxBaseNodeId();
-    }
-    if (_n_base_nodes == 0 && hasNonlinearElement())
-    {
-        this->checkNonlinearNodeIDs();
-    }
     this->setDimension();
     this->setElementsConnectedToNodes();
     this->setElementNeighbors();
@@ -75,7 +64,6 @@ Mesh::Mesh(const Mesh& mesh)
       _name(mesh.getName()),
       _nodes(mesh.getNumberOfNodes()),
       _elements(mesh.getNumberOfElements()),
-      _n_base_nodes(mesh.getNumberOfBaseNodes()),
       _properties(mesh._properties)
 {
     const std::vector<Node*>& nodes(mesh.getNodes());
@@ -141,19 +129,6 @@ void Mesh::resetNodeIDs()
     }
 }
 
-void Mesh::recalculateMaxBaseNodeId()
-{
-    std::size_t max_basenode_ID = 0;
-    for (Element const* e : _elements)
-    {
-        for (std::size_t i = 0; i < e->getNumberOfBaseNodes(); i++)
-        {
-            max_basenode_ID = std::max(max_basenode_ID, getNodeIndex(*e, i));
-        }
-    }
-    _n_base_nodes = max_basenode_ID + 1;
-}
-
 void Mesh::resetElementIDs()
 {
     const std::size_t nElements(this->_elements.size());
@@ -234,28 +209,6 @@ void Mesh::setElementNeighbors()
     }
 }
 
-void Mesh::checkNonlinearNodeIDs() const
-{
-    for (MeshLib::Element const* e : _elements)
-    {
-        for (unsigned i = e->getNumberOfBaseNodes(); i < e->getNumberOfNodes();
-             i++)
-        {
-            if (getNodeIndex(*e, i) >= getNumberOfBaseNodes())
-            {
-                continue;
-            }
-
-            WARN(
-                "Found a nonlinear node whose ID ({:d}) is smaller than the "
-                "number of base node IDs ({:d}). Some functions may not work "
-                "properly.",
-                getNodeIndex(*e, i), getNumberOfBaseNodes());
-            return;
-        }
-    }
-}
-
 std::size_t Mesh::getNumberOfBaseNodes() const
 {
     return std::count_if(begin(_nodes), end(_nodes),
diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h
index 34ecbaa9f97..2d384ac2185 100644
--- a/MeshLib/Mesh.h
+++ b/MeshLib/Mesh.h
@@ -48,22 +48,15 @@ class Mesh
 public:
     /// Constructor using a mesh name and an array of nodes and elements
     /// @param name          Mesh name.
-    /// @param nodes         A vector of mesh nodes. In case nonlinear nodes are
-    ///                      involved, one should put them after line ones in
-    ///                      the vector and set "n_base_nodes" argument.
+    /// @param nodes         A vector of mesh nodes.
     /// @param elements      An array of mesh elements.
     /// @param properties    Mesh properties.
-    /// @param n_base_nodes  The number of base nodes. This is an optional
-    ///                      parameter for nonlinear case.  If the parameter is
-    ///                      set to zero, we consider there are no nonlinear
-    ///                      nodes.
     Mesh(std::string name,
          std::vector<Node*>
              nodes,
          std::vector<Element*>
              elements,
-         Properties const& properties = Properties(),
-         const std::size_t n_base_nodes = 0);
+         Properties const& properties = Properties());
 
     /// Copy constructor
     Mesh(const Mesh &mesh);
@@ -110,9 +103,6 @@ public:
     /// Resets the IDs of all mesh-nodes to their position in the node vector
     void resetNodeIDs();
 
-    /// Finds the maximum id among all of the base nodes.
-    void recalculateMaxBaseNodeId();
-
     /// Changes the name of the mesh.
     void setName(const std::string &name) { this->_name = name; }
 
@@ -147,9 +137,6 @@ protected:
     /// Note: Using this implementation, an element e can only have neighbors that have the same dimensionality as e.
     void setElementNeighbors();
 
-    /// Check if all the nonlinear nodes are stored at the end of the node vector
-    void checkNonlinearNodeIDs() const;
-
     std::size_t const _id;
     unsigned _mesh_dimension;
     /// The minimal and maximal edge length over all elements in the mesh
@@ -161,7 +148,6 @@ protected:
     std::string _name;
     std::vector<Node*> _nodes;
     std::vector<Element*> _elements;
-    std::size_t _n_base_nodes;
     Properties _properties;
 
     bool _is_axially_symmetric = false;
diff --git a/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp b/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp
index df5d8bd448e..375140ba8d5 100644
--- a/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp
+++ b/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp
@@ -190,8 +190,8 @@ std::unique_ptr<Mesh> createQuadraticOrderMesh(Mesh const& linear_mesh,
     return std::make_unique<MeshLib::Mesh>(
         linear_mesh.getName(), quadratic_mesh_nodes, quadratic_elements,
         linear_mesh.getProperties().excludeCopyProperties(
-            std::vector<MeshLib::MeshItemType>(1, MeshLib::MeshItemType::Node)),
-        linear_mesh.getNumberOfNodes());
+            std::vector<MeshLib::MeshItemType>(1,
+                                               MeshLib::MeshItemType::Node)));
 }
 
 }  // namespace MeshLib
diff --git a/MeshLib/NodePartitionedMesh.h b/MeshLib/NodePartitionedMesh.h
index 6a81cf06cf1..73fc94c3ca8 100644
--- a/MeshLib/NodePartitionedMesh.h
+++ b/MeshLib/NodePartitionedMesh.h
@@ -59,7 +59,6 @@ public:
         \param properties    Mesh property.
         \param n_global_base_nodes Number of the base nodes of the global mesh.
         \param n_global_nodes      Number of all nodes of the global mesh.
-        \param n_base_nodes        Number of the base nodes.
         \param n_active_base_nodes Number of the active base nodes.
         \param n_active_nodes      Number of all active nodes.
     */
@@ -70,10 +69,9 @@ public:
                         Properties properties,
                         const std::size_t n_global_base_nodes,
                         const std::size_t n_global_nodes,
-                        const std::size_t n_base_nodes,
                         const std::size_t n_active_base_nodes,
                         const std::size_t n_active_nodes)
-        : Mesh(name, nodes, elements, properties, n_base_nodes),
+        : Mesh(name, nodes, elements, properties),
           _global_node_ids(glb_node_ids),
           _n_global_base_nodes(n_global_base_nodes),
           _n_global_nodes(n_global_nodes),
-- 
GitLab