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

[PMesh] Done some changes according to Dima's suggestion and removed one unused cmd arguement

parent 15e9e7c2
No related branches found
No related tags found
No related merge requests found
###
add_executable(partmesh PartitionMesh.cpp MeshPartitioning.h MeshPartitioning.cpp)
set_target_properties(partmesh PROPERTIES FOLDER Utilities)
target_link_libraries(partmesh FileIO)
if(UTILS_PARTMESH_BUILD_WITH_METIS) if(UTILS_PARTMESH_BUILD_WITH_METIS)
include_directories(${METIS_PATH}/libmetis) include_directories(${METIS_PATH}/libmetis)
include_directories(${METIS_PATH}/programs) include_directories(${METIS_PATH}/programs)
...@@ -11,13 +16,7 @@ if(UTILS_PARTMESH_BUILD_WITH_METIS) ...@@ -11,13 +16,7 @@ if(UTILS_PARTMESH_BUILD_WITH_METIS)
) )
ADD_LIBRARY(METIS_Lib STATIC ${METIS_SOURCES} ) ADD_LIBRARY(METIS_Lib STATIC ${METIS_SOURCES} )
add_executable(partmesh PartitionMesh.cpp MeshPartitioning.h MeshPartitioning.cpp) target_link_libraries(partmesh METIS_Lib metis)
set_target_properties(partmesh PROPERTIES FOLDER Utilities)
target_link_libraries(partmesh FileIO METIS_Lib metis)
else()
add_executable(partmesh PartitionMesh.cpp MeshPartitioning.h MeshPartitioning.cpp)
set_target_properties(partmesh PROPERTIES FOLDER Utilities)
target_link_libraries(partmesh FileIO)
endif() endif()
ADD_VTK_DEPENDENCY(partmesh) ADD_VTK_DEPENDENCY(partmesh)
......
...@@ -50,7 +50,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -50,7 +50,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
std::ifstream npart_in(fname_parts.data()); std::ifstream npart_in(fname_parts.data());
if (!npart_in.is_open()) if (!npart_in.is_open())
{ {
ERR("Error: cannot open file %s. It may not exist !", fname_parts.data()); ERR("Error: cannot open file %s. It may not exist! ", fname_parts.data());
abort(); abort();
} }
...@@ -68,7 +68,6 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -68,7 +68,6 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
npart_in.close(); npart_in.close();
//TEST std::remove(fname_parts.c_str()); //TEST std::remove(fname_parts.c_str());
// -- Open files for output // -- Open files for output
// //
// for ASCII output // for ASCII output
...@@ -119,10 +118,10 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -119,10 +118,10 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
os_subd.setf(std::ios::scientific); os_subd.setf(std::ios::scientific);
} }
MyInt global_node_id_offset = 0; PetscInt global_node_id_offset = 0;
std::vector<bool> nodes_part_reserved; std::vector<bool> nodes_part_reserved;
nodes_part_reserved.reserve(nnodes); nodes_part_reserved.reserve(nnodes);
std::vector<MyInt> node_global_ids; std::vector<PetscInt> node_global_ids;
node_global_ids.reserve(nnodes); node_global_ids.reserve(nnodes);
for (std::size_t i=0; i<nnodes; i++) for (std::size_t i=0; i<nnodes; i++)
{ {
...@@ -137,8 +136,8 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -137,8 +136,8 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
std::vector<std::size_t> partition_end_node_id(npartitions); std::vector<std::size_t> partition_end_node_id(npartitions);
std::vector<std::size_t> end_non_ghost_node_id(npartitions); std::vector<std::size_t> end_non_ghost_node_id(npartitions);
const MyInt num_headers = 14; const PetscInt num_headers = 14;
MyInt head[num_headers]; PetscInt head[num_headers];
// node rank offset // node rank offset
head[10] = 0; head[10] = 0;
// element rank offset // element rank offset
...@@ -176,9 +175,9 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -176,9 +175,9 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
std::vector< std::vector<unsigned> > std::vector< std::vector<unsigned> >
elems_non_ghost_nodes_local_ids(_elements.size()); elems_non_ghost_nodes_local_ids(_elements.size());
const MyInt num_non_ghost_nodes = end_non_ghost_node_id[ipart] const PetscInt num_non_ghost_nodes = end_non_ghost_node_id[ipart]
- partition_start_node_id[ipart]; - partition_start_node_id[ipart];
for (MyInt i=0; i<num_non_ghost_nodes; i++) for (PetscInt i=0; i<num_non_ghost_nodes; i++)
{ {
const unsigned node_id = partition_nodes[ i + partition_start_node_id[ipart] ]->getID(); const unsigned node_id = partition_nodes[ i + partition_start_node_id[ipart] ]->getID();
...@@ -249,7 +248,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -249,7 +248,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
partition_end_node_id[ipart] = partition_nodes.size(); partition_end_node_id[ipart] = partition_nodes.size();
// Renumber // Renumber
MyInt local_id = 0; PetscInt local_id = 0;
std::vector<unsigned> nodes_local_ids_partition; std::vector<unsigned> nodes_local_ids_partition;
nodes_local_ids_partition.reserve(nnodes); nodes_local_ids_partition.reserve(nnodes);
...@@ -276,15 +275,15 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -276,15 +275,15 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
} }
// Count the number of integer variables used to define non-ghost elements // Count the number of integer variables used to define non-ghost elements
const MyInt num_non_ghost_elems = partition_regular_elements.size(); const PetscInt num_non_ghost_elems = partition_regular_elements.size();
MyInt nmb_element_idxs = 3 * num_non_ghost_elems; PetscInt nmb_element_idxs = 3 * num_non_ghost_elems;
for (MyInt j=0; j<num_non_ghost_elems; j++) for (PetscInt j=0; j<num_non_ghost_elems; j++)
{ {
nmb_element_idxs += partition_regular_elements[j]->getNNodes(); nmb_element_idxs += partition_regular_elements[j]->getNNodes();
} }
const MyInt num_ghost_elems = partition_ghost_elements.size(); const PetscInt num_ghost_elems = partition_ghost_elements.size();
MyInt nmb_element_idxs_g = 3 * num_ghost_elems; PetscInt nmb_element_idxs_g = 3 * num_ghost_elems;
for (MyInt j=0; j<num_ghost_elems; j++) for (PetscInt j=0; j<num_ghost_elems; j++)
{ {
nmb_element_idxs_g += partition_ghost_elements[j]->getNNodes(); nmb_element_idxs_g += partition_ghost_elements[j]->getNNodes();
} }
...@@ -292,19 +291,19 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -292,19 +291,19 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
std::string ipart_str = std::to_string(ipart); std::string ipart_str = std::to_string(ipart);
// Number of active elements // Number of active elements
const MyInt offset_e = num_non_ghost_elems + nmb_element_idxs; const PetscInt offset_e = num_non_ghost_elems + nmb_element_idxs;
const MyInt offset_e_g = num_ghost_elems + nmb_element_idxs_g; const PetscInt offset_e_g = num_ghost_elems + nmb_element_idxs_g;
// Reserved for nodes for high order interpolation // Reserved for nodes for high order interpolation
const MyInt num_non_ghost_nodes_extra = 0; const PetscInt num_non_ghost_nodes_extra = 0;
const MyInt num_nodes_linear_element = partition_end_node_id[ipart] const PetscInt num_nodes_linear_element = partition_end_node_id[ipart]
- partition_start_node_id[ipart]; - partition_start_node_id[ipart];
const MyInt num_nodes_quadratic_element = 0; const PetscInt num_nodes_quadratic_element = 0;
const MyInt num_nodes_global_mesh = nnodes; const PetscInt num_nodes_global_mesh = nnodes;
// Reserved for nodes for high order interpolation // Reserved for nodes for high order interpolation
const MyInt num_nodes_global_mesh_extra = nnodes; const PetscInt num_nodes_global_mesh_extra = nnodes;
// Write configuration data and elements of this partition // Write configuration data and elements of this partition
head[0] = num_nodes_linear_element + num_nodes_quadratic_element; head[0] = num_nodes_linear_element + num_nodes_quadratic_element;
...@@ -319,35 +318,35 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -319,35 +318,35 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
head[9] = nmb_element_idxs_g; head[9] = nmb_element_idxs_g;
if (output_binary) if (output_binary)
{ {
fwrite(head, 1, num_headers * sizeof(MyInt), of_bin_cfg); fwrite(head, 1, num_headers * sizeof(PetscInt), of_bin_cfg);
head[10] += head[0] * sizeof(NodeStruct); head[10] += head[0] * sizeof(NodeStruct);
head[11] += offset_e * sizeof(MyInt); head[11] += offset_e * sizeof(PetscInt);
head[12] += offset_e_g * sizeof(MyInt); head[12] += offset_e_g * sizeof(PetscInt);
// Write non-ghost elements // Write non-ghost elements
std::vector<MyInt> ele_info(offset_e); std::vector<PetscInt> ele_info(offset_e);
MyInt counter = num_non_ghost_elems; PetscInt counter = num_non_ghost_elems;
for (MyInt j = 0; j < num_non_ghost_elems; j++) for (PetscInt j = 0; j < num_non_ghost_elems; j++)
{ {
ele_info[j] = counter; ele_info[j] = counter;
getElementIntegerVariables(*partition_regular_elements[j], nodes_local_ids_partition, getElementIntegerVariables(*partition_regular_elements[j], nodes_local_ids_partition,
ele_info, counter); ele_info, counter);
} }
fwrite(&ele_info[0], 1, (offset_e) * sizeof(MyInt), of_bin_ele); fwrite(&ele_info[0], 1, (offset_e) * sizeof(PetscInt), of_bin_ele);
// Write ghost elements // Write ghost elements
ele_info.resize(offset_e_g); ele_info.resize(offset_e_g);
counter = num_ghost_elems; counter = num_ghost_elems;
for (MyInt j = 0; j < num_ghost_elems; j++) for (PetscInt j = 0; j < num_ghost_elems; j++)
{ {
ele_info[j] = counter; ele_info[j] = counter;
getElementIntegerVariables(*partition_ghost_elements[j], nodes_local_ids_partition, getElementIntegerVariables(*partition_ghost_elements[j], nodes_local_ids_partition,
ele_info, counter); ele_info, counter);
} }
fwrite(&ele_info[0], 1, (offset_e_g) * sizeof(MyInt), of_bin_ele_g); fwrite(&ele_info[0], 1, (offset_e_g) * sizeof(PetscInt), of_bin_ele_g);
} }
else else
{ {
...@@ -462,16 +461,16 @@ ElementType MeshPartitioning::getElementType(const Element& elem) ...@@ -462,16 +461,16 @@ ElementType MeshPartitioning::getElementType(const Element& elem)
void MeshPartitioning::getElementIntegerVariables(const Element& elem, void MeshPartitioning::getElementIntegerVariables(const Element& elem,
const std::vector<unsigned>& local_node_ids, const std::vector<unsigned>& local_node_ids,
std::vector<MyInt>& elem_info, std::vector<PetscInt>& elem_info,
MyInt& counter) PetscInt& counter)
{ {
unsigned mat_id = 0; // Materical ID to be set from the mesh data unsigned mat_id = 0; // Materical ID to be set from the mesh data
const MyInt nn = elem.getNNodes();; const PetscInt nn = elem.getNNodes();;
elem_info[counter++] = mat_id; elem_info[counter++] = mat_id;
elem_info[counter++] = static_cast<unsigned>(getElementType(elem)) + 1; elem_info[counter++] = static_cast<unsigned>(getElementType(elem)) + 1;
elem_info[counter++] = nn; elem_info[counter++] = nn;
for(MyInt i=0; i<nn; i++) for(PetscInt i=0; i<nn; i++)
{ {
elem_info[counter++] = local_node_ids[elem.getNodeIndex(i)]; elem_info[counter++] = local_node_ids[elem.getNodeIndex(i)];
} }
......
...@@ -29,7 +29,7 @@ enum class ElementType : unsigned {LINE2, QUAD4, HEX8, TRI3, TET4, PRISM6, PYRAM ...@@ -29,7 +29,7 @@ enum class ElementType : unsigned {LINE2, QUAD4, HEX8, TRI3, TET4, PRISM6, PYRAM
/// A subdomain mesh. /// A subdomain mesh.
class MeshPartitioning : public Mesh class MeshPartitioning : public Mesh
{ {
typedef long MyInt; // for PetscInt typedef long PetscInt;
public: public:
/// Copy constructor /// Copy constructor
MeshPartitioning(const MeshLib::Mesh &mesh) : Mesh(mesh) MeshPartitioning(const MeshLib::Mesh &mesh) : Mesh(mesh)
...@@ -60,8 +60,8 @@ class MeshPartitioning : public Mesh ...@@ -60,8 +60,8 @@ class MeshPartitioning : public Mesh
*/ */
void getElementIntegerVariables(const Element& elem, void getElementIntegerVariables(const Element& elem,
const std::vector<unsigned>& local_node_ids, const std::vector<unsigned>& local_node_ids,
std::vector<MyInt>& elem_info, std::vector<PetscInt>& elem_info,
MyInt& counter); PetscInt& counter);
/*! /*!
\brief Write local indicies of element nodes to a ASCII file \brief Write local indicies of element nodes to a ASCII file
...@@ -74,7 +74,7 @@ class MeshPartitioning : public Mesh ...@@ -74,7 +74,7 @@ class MeshPartitioning : public Mesh
struct NodeStruct struct NodeStruct
{ {
MyInt id; PetscInt id;
double x; double x;
double y; double y;
double z; double z;
......
...@@ -14,15 +14,13 @@ ...@@ -14,15 +14,13 @@
#include "tclap/CmdLine.h" #include "tclap/CmdLine.h"
#include "logog/include/logog.hpp"
#ifdef BUILD_WITH_METIS #ifdef BUILD_WITH_METIS
extern "C" { extern "C" {
#include "metis_main.h" #include "metis_main.h"
} }
#endif #endif
#include "BaseLib/LogogSimpleFormatter.h" #include "Applications/ApplicationsLib/LogogSetup.h"
#include "BaseLib/FileTools.h" #include "BaseLib/FileTools.h"
#include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/readMeshFromFile.h"
...@@ -35,10 +33,7 @@ extern "C" { ...@@ -35,10 +33,7 @@ extern "C" {
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
LOGOG_INITIALIZE(); ApplicationsLib::LogogSetup logog_setup;
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." std::string m_str = "Partition a mesh for parallel computing."
"The tasks of this tool are in twofold:\n" "The tasks of this tool are in twofold:\n"
...@@ -63,8 +58,6 @@ int main (int argc, char* argv[]) ...@@ -63,8 +58,6 @@ int main (int argc, char* argv[])
cmd.add(asci_flag); cmd.add(asci_flag);
TCLAP::SwitchArg elem_part_flag("e","element_wise","Enable element wise partitioing.", false); TCLAP::SwitchArg elem_part_flag("e","element_wise","Enable element wise partitioing.", false);
cmd.add(elem_part_flag); cmd.add(elem_part_flag);
TCLAP::SwitchArg output_part_flag("o","output_parititon","Enable output partitions.", false);
cmd.add(output_part_flag);
cmd.parse(argc, argv); cmd.parse(argc, argv);
...@@ -130,9 +123,5 @@ int main (int argc, char* argv[]) ...@@ -130,9 +123,5 @@ int main (int argc, char* argv[])
INFO( "Total runtime: %g s.\n", run_timer.elapsed() ); INFO( "Total runtime: %g s.\n", run_timer.elapsed() );
INFO( "Total CPU time: %g s.\n", CPU_timer.elapsed() ); INFO( "Total CPU time: %g s.\n", CPU_timer.elapsed() );
delete custom_format;
delete logog_cout;
LOGOG_SHUTDOWN();
return 0; 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