From c34e417e2394566dbf6649364693b968eb693ee5 Mon Sep 17 00:00:00 2001
From: Norihiro Watanabe <norihiro.watanabe@ufz.de>
Date: Fri, 29 Aug 2014 17:24:01 +0200
Subject: [PATCH] add a function to search connected element ids

---
 MeshLib/MeshSearcher.cpp | 34 ++++++++++++++++++++++++++++++++++
 MeshLib/MeshSearcher.h   | 31 +++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100644 MeshLib/MeshSearcher.cpp
 create mode 100644 MeshLib/MeshSearcher.h

diff --git a/MeshLib/MeshSearcher.cpp b/MeshLib/MeshSearcher.cpp
new file mode 100644
index 00000000000..23923d626ab
--- /dev/null
+++ b/MeshLib/MeshSearcher.cpp
@@ -0,0 +1,34 @@
+/**
+ * \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
+ *
+ */
+
+#include "MeshSearcher.h"
+
+#include "Mesh.h"
+#include "Node.h"
+#include "Elements/Element.h"
+
+namespace MeshLib
+{
+
+std::vector<std::size_t> getConnectedElements(MeshLib::Mesh const& msh, const std::vector<std::size_t> &nodes)
+{
+	std::vector<std::size_t> connected_elements;
+	for (auto* e : msh.getElements()) {
+		for (std::size_t j=0; j<e->getNNodes(); j++) {
+			if (std::find(nodes.begin(), nodes.end(), e->getNodeIndex(j))!=nodes.end()) {
+				connected_elements.push_back(e->getID());
+				break;
+			}
+		}
+	}
+	return connected_elements;
+}
+
+} // end namespace MeshLib
+
diff --git a/MeshLib/MeshSearcher.h b/MeshLib/MeshSearcher.h
new file mode 100644
index 00000000000..cf3c26eeb99
--- /dev/null
+++ b/MeshLib/MeshSearcher.h
@@ -0,0 +1,31 @@
+/**
+ * \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 MESHSEARCHER_H_
+#define MESHSEARCHER_H_
+
+#include <vector>
+
+
+namespace MeshLib
+{
+// forward declarations
+class Mesh;
+
+/**
+ * get a list of elements connected to given nodes
+ * @param msh       a mesh object
+ * @param node_ids  a vector of mesh node ids
+ * @return a vector of element ids which connect to the given nodes
+ */
+std::vector<std::size_t> getConnectedElementIDs(MeshLib::Mesh const& msh, const std::vector<std::size_t> &node_ids);
+
+} // end namespace MeshLib
+
+#endif //MESHSEARCHER_H_
-- 
GitLab