From 85cf56d2317a70388f53643731f0fa2cce5fd8b8 Mon Sep 17 00:00:00 2001
From: Norihiro Watanabe <norihiro.watanabe@ufz.de>
Date: Thu, 27 Jun 2013 14:28:47 +0200
Subject: [PATCH] Part of: add VecMatOnMeshLib toghether with tests

added by Norihiro Watanabe.
---
 .../VecMeshItems/ComponentDistribution.h      | 82 +++++++++++++++++
 VecMatOnMeshLib/VecMeshItems/MeshItem.h       | 50 +++++++++++
 VecMatOnMeshLib/VecMeshItems/MeshItemType.h   | 35 ++++++++
 VecMatOnMeshLib/VecMeshItems/MeshItems.h      | 88 +++++++++++++++++++
 4 files changed, 255 insertions(+)
 create mode 100644 VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h
 create mode 100644 VecMatOnMeshLib/VecMeshItems/MeshItem.h
 create mode 100644 VecMatOnMeshLib/VecMeshItems/MeshItemType.h
 create mode 100644 VecMatOnMeshLib/VecMeshItems/MeshItems.h

diff --git a/VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h b/VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h
new file mode 100644
index 00000000000..3d8e5ee8339
--- /dev/null
+++ b/VecMatOnMeshLib/VecMeshItems/ComponentDistribution.h
@@ -0,0 +1,82 @@
+/**
+ * \file
+ * \author Norihiro Watanabe
+ * \date   2013-04-16
+ * \brief
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#ifndef COMPONENTDISTRIBUTION_H_
+#define COMPONENTDISTRIBUTION_H_
+
+#include <vector>
+#include <numeric>
+
+#include "MeshItems.h"
+
+namespace VecMatOnMeshLib
+{
+
+/**
+ * Distribution information of a single data component
+ *
+ * This class contains information about on which mesh items a data component is
+ * assigned.
+ */
+class ComponentDistribution
+{
+public:
+
+    /**
+     * constructor for a single mesh use
+     *
+     * This data component is distributed over the given mesh items in a single mesh
+     * @param mesh_items
+     */
+    explicit ComponentDistribution(const MeshItems* mesh_items)
+    {
+        _mesh_items.push_back(mesh_items);
+        _n_total_items = mesh_items->getNTotalItems();
+    }
+
+    /**
+     * constructor for multiple-mesh use
+     *
+     * This data component is distributed over the given mesh items in multiple meshes
+     * @param vec_mesh_items   a vector of MeshItems
+     */
+    explicit ComponentDistribution(const std::vector<MeshItems*> &vec_mesh_items)
+    : _mesh_items(vec_mesh_items.begin(), vec_mesh_items.end())
+    {
+        _n_total_items = std::accumulate(vec_mesh_items.begin(), vec_mesh_items.end(),
+                                            0u,
+                                            [](std::size_t sum, const MeshItems* items)
+                                            {
+                                                return sum+items->getNTotalItems();
+                                            }
+                                           );
+    }
+
+    /// return the total number of mesh items (in all meshes) where this component is assigned
+    std::size_t getNMeshItems() const { return _n_total_items; }
+
+    /// return the number of related meshes
+    unsigned getNMeshes() const { return _mesh_items.size(); }
+
+    /// return MeshItems
+    const MeshItems& getMeshItems(std::size_t mesh_index) const { return *_mesh_items[mesh_index]; }
+
+private:
+    std::vector<const MeshItems*> _mesh_items;
+    std::size_t _n_total_items;
+};
+
+}
+
+#endif /* COMPONENTDISTRIBUTION_H_ */
diff --git a/VecMatOnMeshLib/VecMeshItems/MeshItem.h b/VecMatOnMeshLib/VecMeshItems/MeshItem.h
new file mode 100644
index 00000000000..b04b5c4f798
--- /dev/null
+++ b/VecMatOnMeshLib/VecMeshItems/MeshItem.h
@@ -0,0 +1,50 @@
+/**
+ * \file
+ * \author Norihiro Watanabe
+ * \date   2013-04-16
+ * \brief
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+
+#ifndef MESHITEM_H_
+#define MESHITEM_H_
+
+#include "MeshItemType.h"
+
+namespace VecMatOnMeshLib
+{
+
+/**
+ * Mesh item data
+ *
+ * This data are used in VectorComposition
+ */
+struct MeshItem
+{
+    std::size_t          mesh_id;
+    MeshItemType::type   item_type;
+    std::size_t          item_id;
+
+    MeshItem(std::size_t meshid, MeshItemType::type itemtype, std::size_t itemid)
+    : mesh_id(meshid), item_type(itemtype), item_id(itemid){};
+};
+
+inline bool operator<(const MeshItem& left, const MeshItem& right)
+{
+    if (left.mesh_id != right.mesh_id) return left.mesh_id < right.mesh_id;
+    if (left.item_type != right.item_type) return left.item_type < right.item_type;
+    return left.item_id < right.item_id;
+}
+
+
+}
+
+
+#endif /* MESHITEM_H_ */
diff --git a/VecMatOnMeshLib/VecMeshItems/MeshItemType.h b/VecMatOnMeshLib/VecMeshItems/MeshItemType.h
new file mode 100644
index 00000000000..42d5c9983b7
--- /dev/null
+++ b/VecMatOnMeshLib/VecMeshItems/MeshItemType.h
@@ -0,0 +1,35 @@
+/**
+ * \file
+ * \author Norihiro Watanabe
+ * \date   2013-04-16
+ * \brief
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+
+#ifndef MESHITEMTYPE_H_
+#define MESHITEMTYPE_H_
+
+namespace VecMatOnMeshLib
+{
+
+struct MeshItemType
+{
+    enum type
+    {
+        Node,
+        Edge,
+        Face,
+        Cell
+    };
+};
+
+}
+
+#endif /* MESHITEMTYPE_H_ */
diff --git a/VecMatOnMeshLib/VecMeshItems/MeshItems.h b/VecMatOnMeshLib/VecMeshItems/MeshItems.h
new file mode 100644
index 00000000000..01bc9e0b972
--- /dev/null
+++ b/VecMatOnMeshLib/VecMeshItems/MeshItems.h
@@ -0,0 +1,88 @@
+/**
+ * \file
+ * \author Norihiro Watanabe
+ * \date   2013-04-16
+ * \brief
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+
+#ifndef MESHITEMS_H_
+#define MESHITEMS_H_
+
+#include <vector>
+#include <algorithm>
+
+#include "MeshLib/Mesh.h"
+#include "MeshLib/Node.h"
+#include "MeshLib/Elements/Element.h"
+
+
+namespace VecMatOnMeshLib
+{
+
+/**
+ * Collection of mesh items from a single mesh (nodes and elements are currently supported)
+ *
+ * Remark: At the moment, this class is only used to return the total number of mesh items
+ *         on which data are assigned.
+ */
+class MeshItems
+{
+public:
+    /// construct from nodes
+    MeshItems(const MeshLib::Mesh* msh, std::vector<MeshLib::Node*> const& vec_items)
+    : _msh(msh), _nodes(&vec_items), _eles(nullptr)
+    {}
+
+    /// construct from elements
+    MeshItems(const MeshLib::Mesh* msh, std::vector<MeshLib::Element*> const& vec_items)
+    : _msh(msh), _nodes(nullptr), _eles(&vec_items)
+    {}
+
+    /// construct from both nodes and elements
+    MeshItems(const MeshLib::Mesh* msh,
+                std::vector<MeshLib::Node*> const& vec_nodes, std::vector<MeshLib::Element*> const& vec_eles)
+    : _msh(msh), _nodes(&vec_nodes), _eles(&vec_eles)
+    {}
+
+    ~MeshItems() {};
+
+    /// return the total number of mesh items
+    std::size_t getNTotalItems() const { return getNNodes() + getNElements(); }
+
+    /// return this mesh ID
+    std::size_t getMeshID() const { return _msh->getID(); }
+
+    /// return the number of registered nodes
+    std::size_t getNNodes() const { return (_nodes==nullptr) ? 0 : _nodes->size(); }
+
+    /// return the number of registered elements
+    std::size_t getNElements() const { return (_eles==nullptr) ? 0 : _eles->size(); }
+
+
+//    const MeshLib::Node* getNode(std::size_t index) const { return (_nodes==nullptr) ? nullptr : (*_nodes)[index]; }
+
+//    const MeshLib::Element* getElement(std::size_t index) const { return (_eles==nullptr) ? nullptr : (*_eles)[index]; }
+
+//    bool has(const MeshLib::Node &item) const { return (std::count(_nodes->begin(), _nodes->end(), &item)>0); }
+
+//    bool has(const MeshLib::Element &item) const { return (std::count(_eles->begin(), _eles->end(), &item)>0); }
+
+
+private:
+    const MeshLib::Mesh* _msh;
+    std::vector<MeshLib::Node*> const* _nodes;
+    std::vector<MeshLib::Element*> const* _eles;
+
+};
+
+}
+
+#endif /* MESHITEMS_H_ */
-- 
GitLab