Skip to content
Snippets Groups Projects
Commit e1c71927 authored by wenqing's avatar wenqing
Browse files

[PMesh] Added a mesh partitioning tool as a utility

parent f2f2d30b
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ add_subdirectory(GeoTools) ...@@ -3,6 +3,7 @@ add_subdirectory(GeoTools)
add_subdirectory(MeshGeoTools) add_subdirectory(MeshGeoTools)
add_subdirectory(MeshEdit) add_subdirectory(MeshEdit)
add_subdirectory(ModelPreparation) add_subdirectory(ModelPreparation)
add_subdirectory(PartitionMesh)
add_subdirectory(SimpleMeshCreation) add_subdirectory(SimpleMeshCreation)
if(OGS_BUILD_GUI) if(OGS_BUILD_GUI)
......
include_directories(
${CMAKE_SOURCE_DIR}/Utils/PartitionMesh
${CMAKE_SOURCE_DIR}/BaseLib
${CMAKE_SOURCE_DIR}/FileIO
${CMAKE_SOURCE_DIR}/MeshLib
)
add_executable(partmesh PartitionMesh.cpp MeshPartitioning.h MeshPartitioning.cpp)
set_target_properties(partmesh PROPERTIES FOLDER Utilities)
target_link_libraries(partmesh FileIO)
ADD_VTK_DEPENDENCY(partmesh)
####################
### Installation ###
####################
install(TARGETS partmesh RUNTIME DESTINATION bin COMPONENT ogs_partmesh)
cpack_add_component(ogs_partmesh
DISPLAY_NAME "Mesh partitioning tool"
DESCRIPTION "Mesh partitioning tool."
GROUP Utilities
)
/*!
\file MeshPartitioning.cpp
\date 2016.05
\brief Define the members of class MeshPartitioning
\copyright
Copyright (c) 2012-2016, 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 "MeshPartitioning.h"
#include <fstream>
#include "MeshLib/Elements/Element.h"
namespace MeshLib
{
void MeshPartitioning :: write2METIS(const std::string& file_name)
{
std::ofstream os(file_name.data(), std::ios::trunc);
os << _elements.size() <<" \n";
for (const auto elem : _elements)
{
for (unsigned j=0; j<elem->getNNodes(); j++)
{
os << elem->getNodeIndex(j) + 1 <<" ";
}
os << std::endl;
}
}
void MeshPartitioning :: partitionByNode()
{
}
void MeshPartitioning :: writeNodePartitionedMeshASCII()
{
}
void MeshPartitioning :: writeNodePartitionedMeshBinary()
{
}
} // namespace MeshLib
/*!
\file MeshPartitioning.h
\date 2016.05
\brief Declare a class to perform mesh partitioning
\copyright
Copyright (c) 2012-2016, 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 MESH_PARTITIONING_H_
#define MESH_PARTITIONING_H_
#include <vector>
#include <string>
#include "MeshLib/Mesh.h"
namespace MeshLib
{
/// A subdomain mesh.
class MeshPartitioning : public Mesh
{
public:
/// Copy constructor
MeshPartitioning(const MeshLib::Mesh &mesh) : Mesh(mesh)
{}
/// Write mesh to METIS input file
void write2METIS(const std::string& file_name);
/// Partition by element.
void partitionByElement()
{
/* to be decided */
}
/// Partition by node.
void partitionByNode();
/// Write the partitioned mesh into ASCII files.
void writeNodePartitionedMeshASCII();
/// Write the partitioned mesh into binary files.
void writeNodePartitionedMeshBinary();
private:
};
} // namespace MeshLib
#endif // MESH_PARTITIONING_H_
/*!
\file PartitionMesh.cpp
\date 2016.05
\brief A tool for mesh partitioning.
\copyright
Copyright (c) 2012-2016, 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 "tclap/CmdLine.h"
#include "logog/include/logog.hpp"
#include "LogogSimpleFormatter.h"
#include "BaseLib/FileTools.h"
#include "FileIO/VtkIO/VtuInterface.h"
#include "Legacy/MeshIO.h"
#include "MeshPartitioning.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);
std::string m_str = "Partition a mesh for parallel computing."
"The tasks of this tool are in twofold:\n"
"1. Convert mesh file to the input file of the partitioning tool,\n"
"2. Partition a mesh using the partitioning tool,\n"
"\tcreate the mesh data of each partition,\n"
"\trenumber the node indicies of each partition,\n"
"\tand output the results for parallel computing.";
TCLAP::CmdLine cmd(m_str, ' ', "0.1");
TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
"the name of the file containing the input mesh", true,
"", "file name of input mesh");
TCLAP::SwitchArg ogs2metis_flag("1", "ogs2metis",
"Indicator to convert the ogs mesh file to METIS input file", cmd, false);
cmd.parse(argc, argv);
const std::string ifile_name = mesh_in.getValue();
MeshLib::MeshPartitioning* mesh = dynamic_cast<MeshLib::MeshPartitioning*>
(FileIO::VtuInterface::readVTUFile(ifile_name));
INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());
if ( ogs2metis_flag.getValue() )
{
mesh->write2METIS(BaseLib::dropFileExtension(ifile_name) + ".mesh");
}
else
{
}
delete custom_format;
delete logog_cout;
LOGOG_SHUTDOWN();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment