Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor part mesh tool #2159

Merged
merged 33 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6990775
Clang-format node-wise mesh partitioner and CLI.
endJunction Jul 6, 2018
17484c6
NWMP; Fix typo in comment.
endJunction Jul 8, 2018
0101659
Extract writeMETIS().
endJunction Jul 6, 2018
bb69a92
Extract readMetisData().
endJunction Jul 6, 2018
7ed8ce8
[T] Add partmesh complex test case input files.
endJunction Jul 9, 2018
a58f132
[T] partmesh ascii expected output.
endJunction Jul 9, 2018
2c8ad39
[T] partmesh binary expected output
endJunction Jul 9, 2018
13eb89b
[App/U] Add output directory option to partmesh.
endJunction Jul 9, 2018
564038b
[T] partmesh ctests for binary and ascii.
endJunction Jul 9, 2018
aba0e71
NWMP: Extract writeNodesBinary();
endJunction Jul 6, 2018
83819bf
NWMP; Fix splitOffHigherOrderNode() function name.
endJunction Jul 6, 2018
09e3604
NWMP; Simplify splitOffHigherOrderNode().
endJunction Jul 6, 2018
c626caa
NWMP; Extract getNumberOfIntVariablesOfElements().
endJunction Jul 6, 2018
403caa7
NWMP; Move out getElementIntegerVariables().
endJunction Jul 7, 2018
b0157a7
[BL] FileTools; Add createBinaryFile with check.
endJunction Jul 7, 2018
eed0523
NWMP; Use ofstream for binary output.
endJunction Jul 7, 2018
42e0d09
[NWMP] Extract writeElementsBinary().
endJunction Jul 7, 2018
836b5ce
NWMP: Extract writeConfigDataBinary().
endJunction Jul 7, 2018
bc0da8c
NWMP; Rewrite binary config output.
endJunction Jul 7, 2018
089b604
NWMP; Extract write and property related functions
endJunction Jul 8, 2018
a65ebb7
NWMP; Refactor copying of property vector values.
endJunction Jul 9, 2018
65c8422
NWMP; Extract Partition::numberOfMeshItems.
endJunction Jul 9, 2018
ff69e62
[BL] Change cast type in writeValueBinary.
endJunction Jul 9, 2018
77983b4
[MeL] Add toString(MeshItemType) conversion.
endJunction Jul 9, 2018
185aff6
NWMP; Refactor writeNode/CellPropertiesBinary.
endJunction Jul 9, 2018
5fc3d3c
NWMP; Rename applyToPropertyVectors().
endJunction Jul 10, 2018
8fcb6f4
PM; Remove code for 1-partition.
endJunction Jul 11, 2018
781a263
PM; Add ticks around metis call input filename.
endJunction Jul 11, 2018
f4917ae
[BL] Remove fct. because of missing compiler supp.
endJunction Jul 11, 2018
06fa93f
[jenkins] Unset CC=mpicc and CXX=mpicxx in envinf1
endJunction Jul 11, 2018
243ecbd
Always build metis if utils are enabled.
endJunction Jul 11, 2018
6db77bf
Add ctest-* dependencies if utils are build.
endJunction Jul 11, 2018
5df7f9b
PM; Add mpmetis as cmake dependency of partmesh.
endJunction Jul 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Applications/Utils/ModelPreparation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ target_link_libraries(createNeumannBc
${OGS_VTK_REQUIRED_LIBS}
)

if(OGS_BUILD_METIS)
add_subdirectory(PartitionMesh)
endif()
add_subdirectory(PartitionMesh)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_executable(partmesh PartitionMesh.cpp NodeWiseMeshPartitioner.h NodeWiseMeshPartitioner.cpp)
add_executable(partmesh PartitionMesh.cpp Metis.cpp NodeWiseMeshPartitioner.cpp)

set_target_properties(partmesh PROPERTIES FOLDER Utilities)
target_link_libraries(partmesh MeshLib)
add_dependencies(partmesh mpmetis)

####################
### Installation ###
Expand Down
99 changes: 99 additions & 0 deletions Applications/Utils/ModelPreparation/PartitionMesh/Metis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* \file
*
* \copyright
* Copyright (c) 2012-2018, 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 <iostream>

#include "BaseLib/Error.h"
#include "MeshLib/Elements/Element.h"

namespace ApplicationUtils
{
void writeMETIS(std::vector<MeshLib::Element*> const& elements,
const std::string& file_name)
{
std::ofstream os(file_name, std::ios::trunc);
if (!os.is_open())
{
OGS_FATAL("Error: cannot open file %s.", file_name.data());
}

if (!os.good())
{
OGS_FATAL("Error: Cannot write in file %s.", file_name.data());
}

os << elements.size() << " \n";
for (const auto* elem : elements)
{
os << elem->getNodeIndex(0) + 1;
for (unsigned j = 1; j < elem->getNumberOfNodes(); j++)
{
os << " " << elem->getNodeIndex(j) + 1;
}
os << "\n";
}
}

std::vector<std::size_t> readMetisData(const std::string& file_name_base,
long const number_of_partitions,
std::size_t const number_of_nodes)
{
const std::string npartitions_str = std::to_string(number_of_partitions);

// Read partitioned mesh data from METIS
const std::string fname_parts =
file_name_base + ".mesh.npart." + npartitions_str;

std::ifstream npart_in(fname_parts);
if (!npart_in.is_open())
{
OGS_FATAL(
"Error: cannot open file %s. It may not exist!\n"
"Run mpmetis beforehand or use option -m",
fname_parts.data());
}

std::vector<std::size_t> partition_ids(number_of_nodes);


std::size_t counter = 0;
while (!npart_in.eof())
{
npart_in >> partition_ids[counter++] >> std::ws;
if (counter == number_of_nodes)
{
break;
}
}

if (npart_in.bad())
{
OGS_FATAL("Error while reading file %s.", fname_parts.data());
}

if (counter != number_of_nodes)
{
OGS_FATAL("Error: data in %s are less than expected.",
fname_parts.data());
}

return partition_ids;
}

void removeMetisPartitioningFiles(std::string const& file_name_base,
long const number_of_partitions)
{
const std::string npartitions_str = std::to_string(number_of_partitions);

std::remove((file_name_base + ".mesh.npart." + npartitions_str).c_str());
std::remove((file_name_base + ".mesh.epart." + npartitions_str).c_str());
}
} // namespace ApplicationUtils
44 changes: 44 additions & 0 deletions Applications/Utils/ModelPreparation/PartitionMesh/Metis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* \file
*
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/

#pragma once

#include <string>
#include <vector>

namespace MeshLib
{
class Element;
}

namespace ApplicationUtils
{
/// Write elements as METIS graph file
/// \param elements The mesh elements.
/// \param file_name File name with an extension of mesh.
void writeMETIS(std::vector<MeshLib::Element*> const& elements,
const std::string& file_name);

/// Read metis data
/// \param file_name_base The prefix of the filename.
/// \param number_of_partitions The number is used to compose the full filename
/// and forms the postfix.
/// \param number_of_nodes Expected/required number of nodes to be read.
std::vector<std::size_t> readMetisData(const std::string& file_name_base,
long number_of_partitions,
std::size_t number_of_nodes);

/// Removes the F.mesh.npart.P and F.mesh.epart.P files, where F is file name
/// base and P is the number of partitions.
void removeMetisPartitioningFiles(std::string const& file_name_base,
long number_of_partitions);

} // namespace ApplicationUtils
Loading