From 4c081c945df75156770389a22f36bc5026067c52 Mon Sep 17 00:00:00 2001
From: Norihiro Watanabe <norihiro.watanabe@ufz.de>
Date: Wed, 4 Jun 2014 17:09:42 +0200
Subject: [PATCH] add a command line tool "generateStructuredMesh"

---
 Utils/SimpleMeshCreation/CMakeLists.txt       | 11 +++
 .../generateStructuredMesh.cpp                | 92 +++++++++++++++++++
 2 files changed, 103 insertions(+)
 create mode 100644 Utils/SimpleMeshCreation/generateStructuredMesh.cpp

diff --git a/Utils/SimpleMeshCreation/CMakeLists.txt b/Utils/SimpleMeshCreation/CMakeLists.txt
index 3127d017eca..7eb838f8bf3 100644
--- a/Utils/SimpleMeshCreation/CMakeLists.txt
+++ b/Utils/SimpleMeshCreation/CMakeLists.txt
@@ -35,3 +35,14 @@ IF(TARGET VtkVis)
 	)
 
 ENDIF() # VtkVis-target is existing
+
+
+ADD_EXECUTABLE( generateStructuredMesh generateStructuredMesh.cpp )
+TARGET_LINK_LIBRARIES( generateStructuredMesh
+	BaseLib
+	FileIO
+	MathLib
+	MeshLib
+)
+SET_TARGET_PROPERTIES(generateStructuredMesh PROPERTIES FOLDER Utilities)
+
diff --git a/Utils/SimpleMeshCreation/generateStructuredMesh.cpp b/Utils/SimpleMeshCreation/generateStructuredMesh.cpp
new file mode 100644
index 00000000000..dff4e9e5e1c
--- /dev/null
+++ b/Utils/SimpleMeshCreation/generateStructuredMesh.cpp
@@ -0,0 +1,92 @@
+/**
+ * @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/LICENSE.txt
+ */
+
+// TCLAP
+#include "tclap/CmdLine.h"
+
+// ThirdParty/logog
+#include "logog/include/logog.hpp"
+
+// BaseLib
+#include "LogogSimpleFormatter.h"
+
+// FileIO
+#include "Legacy/MeshIO.h"
+
+// MeshLib
+#include "Mesh.h"
+#include "Node.h"
+#include "Elements/Element.h"
+#include "MeshEnums.h"
+#include "MeshGenerators/MeshGenerator.h"
+
+
+int main (int argc, char* argv[])
+{
+	LOGOG_INITIALIZE();
+	logog::Cout* logog_cout (new logog::Cout);
+	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
+	logog_cout->SetFormatter(*custom_format);
+
+	TCLAP::CmdLine cmd("Generate a structured mesh.", ' ', "0.1");
+	TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
+	                                      "the name of the file the mesh will be written to", true,
+	                                      "", "file name of output mesh");
+	cmd.add(mesh_out);
+	TCLAP::ValueArg<std::string> eleTypeArg("t", "element-type",
+	                                      "element type to be removed", true, "line", "element type");
+	cmd.add(eleTypeArg);
+	TCLAP::ValueArg<double> lengthArg("l", "length",
+	                                      "length of a domain", true, 10.0, "length of a domain");
+	cmd.add(lengthArg);
+	TCLAP::ValueArg<unsigned> nsubdivArg("n", "nr-subdivision",
+	                                      "the number of subdivision", true, 10, "the number of subdivision");
+	cmd.add(nsubdivArg);
+
+	// parse arguments
+	cmd.parse(argc, argv);
+	const std::string eleTypeName(eleTypeArg.getValue());
+	const MeshElemType eleType = String2MeshElemType(eleTypeName);
+	const double length = lengthArg.getValue();
+	const unsigned n_subdivision = nsubdivArg.getValue();
+
+	// generate a mesh
+	MeshLib::Mesh* mesh = nullptr;
+	switch (eleType)
+	{
+	case MeshElemType::LINE:
+		mesh = MeshLib::MeshGenerator::generateLineMesh(length, n_subdivision);
+		break;
+	case MeshElemType::QUAD:
+		mesh = MeshLib::MeshGenerator::generateRegularQuadMesh(length, n_subdivision);
+		break;
+	case MeshElemType::HEXAHEDRON:
+		mesh = MeshLib::MeshGenerator::generateRegularHexMesh(length, n_subdivision);
+		break;
+	default:
+		ERR("Given element type is not supported.");
+		break;
+	}
+
+	if (mesh)
+	{
+		INFO("Mesh created: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());
+
+		// write into a file
+		FileIO::Legacy::MeshIO meshIO;
+		meshIO.setMesh(mesh);
+		meshIO.writeToFile(mesh_out.getValue());
+	}
+
+	delete custom_format;
+	delete logog_cout;
+	LOGOG_SHUTDOWN();
+
+	return 1;
+}
+
-- 
GitLab