Skip to content
Snippets Groups Projects
Commit 69e4f46d authored by wenqing's avatar wenqing Committed by Dmitri Naumov
Browse files

CMake changes to include PETSc and its tests.

parent e2eed988
No related branches found
No related tags found
No related merge requests found
......@@ -156,11 +156,17 @@ IF( OGS_BUILD_TESTS AND NOT IS_SUBPROJECT )
MESSAGE(FATAL_ERROR "CMAKE 2.8.11 or higher is required to build the tests!")
ENDIF()
ADD_SUBDIRECTORY( Tests )
ADD_SUBDIRECTORY( SimpleTests/MatrixTests EXCLUDE_FROM_ALL )
ADD_SUBDIRECTORY( SimpleTests/MeshTests EXCLUDE_FROM_ALL )
IF(NOT MSVC AND BLAS_FOUND AND LAPACK_FOUND)
ADD_SUBDIRECTORY( SimpleTests/SolverTests EXCLUDE_FROM_ALL )
ENDIF()
IF(OGS_USE_MPI)
ADD_SUBDIRECTORY( SimpleTests/MeshTests/MPI )
ELSE(OGS_USE_MPI)
ADD_SUBDIRECTORY( SimpleTests/MatrixTests EXCLUDE_FROM_ALL )
ADD_SUBDIRECTORY( SimpleTests/MeshTests EXCLUDE_FROM_ALL )
IF(NOT MSVC AND BLAS_FOUND AND LAPACK_FOUND)
ADD_SUBDIRECTORY( SimpleTests/SolverTests EXCLUDE_FROM_ALL )
ENDIF()
ENDIF(OGS_USE_MPI)
# Create a target 'data', which downloads all referenced data sets into the build tree
# This has to be defined after all tests are defined
ExternalData_Add_Target(data)
......
......@@ -39,6 +39,12 @@ IF (QT4_FOUND)
SET ( SOURCES ${SOURCES} ${SOURCES_QT_XML})
ENDIF (QT4_FOUND)
# It could be used for other MPI based DDC approach in future.
IF(OGS_USE_PETSC)
GET_SOURCE_FILES(SOURCES_MPI_IO MPI_IO)
SET (SOURCES ${SOURCES} ${SOURCES_MPI_IO})
ENDIF()
# Create the library
ADD_LIBRARY(FileIO STATIC ${SOURCES})
......
INCLUDE_DIRECTORIES(
.
${CMAKE_SOURCE_DIR}/BaseLib/
${CMAKE_SOURCE_DIR}/FileIO/
${CMAKE_SOURCE_DIR}/MeshLib/
)
# Create the executable
ADD_EXECUTABLE( test_node_partitioned_mesh
NodePartitionedMeshTester.cpp
)
TARGET_LINK_LIBRARIES ( test_node_partitioned_mesh
MeshLib
FileIO
BaseLib
logog
${ADDITIONAL_LIBS}
${BOOST_LIBRARIES}
)
IF (OGS_USE_PETSC)
TARGET_LINK_LIBRARIES( test_node_partitioned_mesh ${PETSC_LIBRARIES})
ENDIF (OGS_USE_PETSC)
IF (OGS_USE_MPI)
TARGET_LINK_LIBRARIES( test_node_partitioned_mesh ${MPI_CXX_LIBRARIES})
ENDIF ()
set(FilePath "DATA{${ExternalData_SOURCE_ROOT}/NodePartitionedMesh/ASCII/,REGEX:.*}")
set(MPITestParameters -np 3 "${PROJECT_BINARY_DIR}/bin/test_node_partitioned_mesh" "${FilePath}/mesh_3d")
ExternalData_Add_Test(
data
NAME NodePartitionedMeshTestASCII
COMMAND "mpirun" ${MPITestParameters}
)
set(FilePath "DATA{${ExternalData_SOURCE_ROOT}/NodePartitionedMesh/Binary/,REGEX:.*}")
set(MPITestParameters -np 3 "${PROJECT_BINARY_DIR}/bin/test_node_partitioned_mesh" "${FilePath}/mesh_3d")
ExternalData_Add_Test(
data
NAME NodePartitionedMeshTestBinary
COMMAND "mpirun" ${MPITestParameters}
)
/*!
\file NodePartitionedMeshTester.cpp
\author Wenqing Wang
\date 2014.11
\brief Test class readNodePartitionedMesh to read node-wise partitioned mesh with MPI functions.
\copyright
Copyright (c) 2012-2014, 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 <iomanip>
#include <fstream>
#include <string>
#include <mpi.h>
#ifdef USE_PETSC
#include <petscksp.h>
#endif
#include "logog/include/logog.hpp"
#include "BaseLib/LogogCustomCout.h"
#include "BaseLib/TemplateLogogFormatterSuppressedGCC.h"
#include "FileIO/MPI_IO/NodePartitionedMeshReader.h"
#include "MeshLib/Node.h"
#include "MeshLib/Elements/Element.h"
using namespace MeshLib;
using namespace FileIO;
int main(int argc, char *argv[])
{
LOGOG_INITIALIZE();
{
MPI_Init(&argc, &argv);
#ifdef USE_PETSC
char help[] = "ogs6 with PETSc \n";
PetscInitialize(&argc, &argv, nullptr, help);
#endif
BaseLib::LogogCustomCout out(1);
BaseLib::TemplateLogogFormatterSuppressedGCC<TOPIC_LEVEL_FLAG | TOPIC_FILE_NAME_FLAG | TOPIC_LINE_NUMBER_FLAG> custom_format;
out.SetFormatter(custom_format);
const std::string file_name = argv[1];
NodePartitionedMeshReader read_pmesh;
NodePartitionedMesh *mesh = read_pmesh.read(MPI_COMM_WORLD, file_name);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
const std::string rank_str = std::to_string(rank);
const std::string ofile_name = file_name + "_partition_" + rank_str + ".msh";
std::ofstream os(ofile_name.data(), std::ios::trunc);
// Output nodes
os.setf(std::ios::scientific, std::ios::floatfield);
std::setprecision(10);
const size_t nn = mesh->getNNodes();
for(size_t i=0; i<nn; i++)
{
const double *x = mesh->getNode(i)->getCoords();
os << mesh->getNode(i)->getID() << " "
<< std::setw(14) << x[0] << " " << x[1] << " "<< x[2] << "\n";
}
os.flush();
// Output elements
const size_t ne = mesh->getNElements();
for(size_t i=0; i<ne; i++)
{
const Element *elem = mesh->getElement(i);
Node* const* ele_nodes = elem->getNodes();
for(unsigned j=0; j<elem->getNNodes(); j++)
{
os << ele_nodes[j]->getID() << " ";
}
os << "\n";
}
os.flush();
delete mesh;
#ifdef USE_PETSC
PetscFinalize();
#endif
MPI_Finalize();
} // make sure no logog objects exist when LOGOG_SHUTDOWN() is called.
LOGOG_SHUTDOWN();
}
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