Skip to content
Snippets Groups Projects
Verified Commit 7469e974 authored by Lars Bilke's avatar Lars Bilke
Browse files

Refactored to use CPM. addEmiDataToMesh compiles.

parent 568d0a2d
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 3.16)
project(VisOgsTools) project(VisOgsTools)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} include(${PROJECT_SOURCE_DIR}/cmake/CPM.cmake)
${CMAKE_SOURCE_DIR}/ogs/scripts/cmake/cmake
${CMAKE_SOURCE_DIR}/ogs/scripts/cmake)
include(CompilerSetup)
include(ProjectSetup)
find_package( Qt4 ) CPMFindPackage(
add_subdirectory(${CMAKE_SOURCE_DIR}/ogs) NAME Boost
VERSION 1.69.0
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) URL https://boostorg.jfrog.io/artifactory/main/release/1.69.0/source/boost_1_69_0.tar.gz
include_directories( )
${CMAKE_SOURCE_DIR}/ogs if(Boost_ADDED)
${CMAKE_SOURCE_DIR}/ogs/ThirdParty add_library(Boost::boost INTERFACE IMPORTED)
${CMAKE_SOURCE_DIR}/ogs/ThirdParty/tclap/include target_include_directories(Boost::boost INTERFACE "${Boost_SOURCE_DIR}")
${Boost_INCLUDE_DIRS} endif()
${CONAN_INCLUDE_DIRS} CPMAddPackage(
NAME tclap
GITHUB_REPOSITORY ufz/tclap
VERSION 1.2.4
GIT_TAG 098dd0fe07a31618f3c2a9f8727bb01c8c5d61e2
DOWNLOAD_ONLY YES
)
if(tclap_ADDED)
add_library(tclap INTERFACE IMPORTED)
target_include_directories(
tclap SYSTEM INTERFACE ${tclap_SOURCE_DIR}/include
)
endif()
CPMAddPackage(
"https://gitlab.opengeosys.org/ogs/ogs.git#98aeeb379ac87cc88fb71d111bcb946e2db4c16f@6.4.0-dev"
) )
if(ogs_ADDED)
add_library(ogs_include INTERFACE IMPORTED)
target_include_directories(
ogs_include SYSTEM INTERFACE ${ogs_SOURCE_DIR}/
)
endif()
# find_package(Qt4)
# include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) include_directories(
# ${CMAKE_SOURCE_DIR}/ogs ${CMAKE_SOURCE_DIR}/ogs/ThirdParty
# ${CMAKE_SOURCE_DIR}/ogs/ThirdParty/tclap/include ${Boost_INCLUDE_DIRS}
# ${CONAN_INCLUDE_DIRS} )
add_subdirectory(addEmiDataToMesh) add_subdirectory(addEmiDataToMesh)
add_subdirectory(addScalarArrayTimeSeries) # add_subdirectory(addScalarArrayTimeSeries) add_subdirectory(EmiData2PolyData)
#add_subdirectory(EmiData2PolyData) # add_subdirectory(ErtData2Mesh) if (QT4_FOUND) add_subdirectory(makeBuildings)
add_subdirectory(ErtData2Mesh) # endif()
if (QT4_FOUND)
add_subdirectory(makeBuildings)
endif()
add_executable(addEmiDataToMesh addEmiDataToMesh.cpp) add_executable(addEmiDataToMesh addEmiDataToMesh.cpp)
target_link_libraries(addEmiDataToMesh target_link_libraries(
logog addEmiDataToMesh
BaseLib ApplicationsFileIO
FileIO BaseLib
InSituLib MeshLib
${VTK_LIBRARIES} tclap
) ogs_include
ADD_VTK_DEPENDENCY(addEmiDataToMesh) Boost::boost)
set_target_properties(addEmiDataToMesh PROPERTIES FOLDER Utilities) set_target_properties(addEmiDataToMesh PROPERTIES FOLDER Utilities)
...@@ -12,56 +12,46 @@ ...@@ -12,56 +12,46 @@
*/ */
#include <algorithm> #include <algorithm>
#include <tclap/CmdLine.h>
// TCLAP #include "Applications/FileIO/CsvInterface.h"
#include "tclap/CmdLine.h" #include "BaseLib/Logging.h"
// ThirdParty/logog
#include "logog/include/logog.hpp"
// BaseLib
#include "BaseLib/LogogSimpleFormatter.h"
// FileIO
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "FileIO/CsvInterface.h"
// GeoLib
#include "GeoLib/Grid.h"
#include "GeoLib/AnalyticalGeometry.h" #include "GeoLib/AnalyticalGeometry.h"
#include "GeoLib/Grid.h"
// MeshLib #include "MathLib/GeometricBasics.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
#include "MeshLib/Node.h" #include "MeshLib/Node.h"
#include "MeshLib/Properties.h" #include "MeshLib/Properties.h"
#include "MeshLib/PropertyVector.h" #include "MeshLib/PropertyVector.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/MeshEditing/projectMeshOntoPlane.h"
std::vector<double> getDataFromCSV(MeshLib::Mesh const& mesh, std::vector<GeoLib::Point*> data_points) std::vector<double> getDataFromCSV(MeshLib::Mesh const &mesh, std::vector<GeoLib::Point *> data_points)
{ {
GeoLib::Point const origin(0, 0, 0); auto nodes = mesh.getNodes();
MathLib::Vector3 const normal(0,0,-1); std::vector<MeshLib::Node *> flat_nodes;
MeshLib::Mesh* flat_mesh (MeshLib::projectMeshOntoPlane(mesh, origin, normal)); for (auto n : nodes)
std::size_t n_elems (flat_mesh->getNElements()); {
flat_nodes.emplace_back(new MeshLib::Node((*n)[0], (*n)[1], 0));
}
std::size_t n_elems(mesh.getNumberOfElements());
std::vector<double> data(n_elems, 0.0); std::vector<double> data(n_elems, 0.0);
std::vector<std::size_t> counter(n_elems, 0); std::vector<std::size_t> counter(n_elems, 0);
std::vector<MeshLib::Node*> const& nodes (flat_mesh->getNodes()); GeoLib::Grid<MeshLib::Node> grid(flat_nodes.cbegin(), flat_nodes.cend());
GeoLib::Grid<MeshLib::Node> grid(nodes.cbegin(), nodes.cend());
std::size_t const n_points (data_points.size()); std::size_t const n_points(data_points.size());
for (std::size_t i=0; i<n_points; ++i) for (std::size_t i = 0; i < n_points; ++i)
{ {
MeshLib::Node const pnt((*data_points[i])[0], (*data_points[i])[1], 0.0); MeshLib::Node const pnt((*data_points[i])[0], (*data_points[i])[1], 0.0);
MeshLib::Node const*const node = grid.getNearestPoint(pnt); MeshLib::Node const *const node = grid.getNearestPoint(pnt);
std::vector<MeshLib::Element*> const& conn_elems (node->getElements()); std::vector<MeshLib::Element *> const &conn_elems(node->getElements());
std::size_t const n_conn_elems (conn_elems.size()); std::size_t const n_conn_elems(conn_elems.size());
for (std::size_t j=0; j<n_conn_elems; ++j) for (std::size_t j = 0; j < n_conn_elems; ++j)
{ {
if (GeoLib::gaussPointInTriangle(pnt, *conn_elems[j]->getNode(0), *conn_elems[j]->getNode(1), *conn_elems[j]->getNode(2))) if (MathLib::gaussPointInTriangle(pnt, *conn_elems[j]->getNode(0), *conn_elems[j]->getNode(1), *conn_elems[j]->getNode(2)))
{ {
std::size_t const idx (conn_elems[j]->getID()); std::size_t const idx(conn_elems[j]->getID());
data[idx] += ((*data_points[i])[2]); data[idx] += ((*data_points[i])[2]);
counter[idx]++; counter[idx]++;
break; break;
...@@ -69,28 +59,32 @@ std::vector<double> getDataFromCSV(MeshLib::Mesh const& mesh, std::vector<GeoLib ...@@ -69,28 +59,32 @@ std::vector<double> getDataFromCSV(MeshLib::Mesh const& mesh, std::vector<GeoLib
} }
} }
for (std::size_t i=0; i<n_elems; ++i) for (std::size_t i = 0; i < n_elems; ++i)
if (counter[i] > 0) if (counter[i] > 0)
data[i] /= static_cast<double>(counter[i]); data[i] /= static_cast<double>(counter[i]);
delete flat_mesh; for (auto n : flat_nodes)
{
delete n;
}
return data; return data;
} }
std::vector<double> addFilesAsArrays(std::string csv_base_name, MeshLib::Mesh *mesh, std::string const& name_specifier) std::vector<double> addFilesAsArrays(std::string csv_base_name, MeshLib::Mesh *mesh, std::string const &name_specifier)
{ {
std::vector<GeoLib::Point*> points; std::vector<GeoLib::Point *> points;
std::vector<GeoLib::Point*> points2; std::vector<GeoLib::Point *> points2;
std::vector<GeoLib::Point*> points3; std::vector<GeoLib::Point *> points3;
std::string file_name = csv_base_name + "_A_" + name_specifier + ".txt"; std::string file_name = csv_base_name + "_A_" + name_specifier + ".txt";
INFO ("Reading file %s.", file_name.c_str()); INFO("Reading file {:s}.", file_name.c_str());
int e1 = FileIO::CsvInterface::readPoints(file_name, '\t', points, 1, 2, 3); int e1 = FileIO::CsvInterface::readPoints(file_name, '\t', points, 1, 2, 3);
file_name = csv_base_name + "_B_" + name_specifier + ".txt"; file_name = csv_base_name + "_B_" + name_specifier + ".txt";
INFO ("Reading file %s.", file_name.c_str()); INFO("Reading file {:s}.", file_name.c_str());
int e2 = FileIO::CsvInterface::readPoints(file_name, '\t', points2, 1, 2, 3); int e2 = FileIO::CsvInterface::readPoints(file_name, '\t', points2, 1, 2, 3);
file_name = csv_base_name + "_C_" + name_specifier + ".txt"; file_name = csv_base_name + "_C_" + name_specifier + ".txt";
INFO ("Reading file %s.", file_name.c_str()); INFO("Reading file {:s}.", file_name.c_str());
int e3 = FileIO::CsvInterface::readPoints(file_name, '\t', points3, 1, 2, 3); int e3 = FileIO::CsvInterface::readPoints(file_name, '\t', points3, 1, 2, 3);
points.insert(points.end(), points2.begin(), points2.end()); points.insert(points.end(), points2.begin(), points2.end());
...@@ -98,7 +92,7 @@ std::vector<double> addFilesAsArrays(std::string csv_base_name, MeshLib::Mesh *m ...@@ -98,7 +92,7 @@ std::vector<double> addFilesAsArrays(std::string csv_base_name, MeshLib::Mesh *m
if (e1 < 0 || e2 < 0 || e3 < 0 || points.empty()) if (e1 < 0 || e2 < 0 || e3 < 0 || points.empty())
{ {
ERR ("Error reading CSV-file."); ERR("Error reading CSV-file.");
delete mesh; delete mesh;
std::vector<double> no_data; std::vector<double> no_data;
return no_data; return no_data;
...@@ -110,47 +104,41 @@ std::vector<double> addFilesAsArrays(std::string csv_base_name, MeshLib::Mesh *m ...@@ -110,47 +104,41 @@ std::vector<double> addFilesAsArrays(std::string csv_base_name, MeshLib::Mesh *m
return data; return data;
} }
int main(int argc, char *argv[])
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("Add EMI data as a scalar cell array to a 2d mesh.", ' ', "0.1"); TCLAP::CmdLine cmd("Add EMI data as a scalar cell array to a 2d mesh.", ' ', "0.1");
// I/O params // I/O params
TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
"the name of the file the mesh will be written to", true, "the name of the file the mesh will be written to", true,
"", "file name of output mesh"); "", "file name of output mesh");
cmd.add(mesh_out); cmd.add(mesh_out);
TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
"the name of the file containing the input mesh", true, "the name of the file containing the input mesh", true,
"", "file name of input mesh"); "", "file name of input mesh");
cmd.add(mesh_in); cmd.add(mesh_in);
TCLAP::ValueArg<std::string> csv_in("", "csv", TCLAP::ValueArg<std::string> csv_in("", "csv",
"csv-file containing EMI data to be added as a scalar array.", "csv-file containing EMI data to be added as a scalar array.",
true, "", "name of the csv input file"); true, "", "name of the csv input file");
cmd.add(csv_in); cmd.add(csv_in);
cmd.parse(argc, argv); cmd.parse(argc, argv);
INFO ("Reading mesh %s.", mesh_in.getValue().c_str()); INFO("Reading mesh {:s}.", mesh_in.getValue().c_str());
MeshLib::Mesh* mesh (MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue())); MeshLib::Mesh *mesh(MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue()));
if (mesh == nullptr) if (mesh == nullptr)
{ {
ERR ("Error reading mesh file."); ERR("Error reading mesh file.");
return -2; return -2;
} }
if (mesh->getDimension() != 2) if (mesh->getDimension() != 2)
{ {
ERR ("This utility can handle only 2d meshes at this point."); ERR("This utility can handle only 2d meshes at this point.");
delete mesh; delete mesh;
return -3; return -3;
} }
INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements());
/* /*
std::vector<GeoLib::Point*> points; std::vector<GeoLib::Point*> points;
...@@ -169,26 +157,21 @@ int main (int argc, char* argv[]) ...@@ -169,26 +157,21 @@ int main (int argc, char* argv[])
if (data.empty()) if (data.empty())
return -1; return -1;
std::string const h_prop_name("TM_DD_H"); std::string const h_prop_name("TM_DD_H");
boost::optional< MeshLib::PropertyVector<double>&> h_vector = mesh->getProperties().createNewPropertyVector<double>(h_prop_name, MeshLib::MeshItemType::Cell); auto h_vector = mesh->getProperties().createNewPropertyVector<double>(h_prop_name, MeshLib::MeshItemType::Cell);
std::copy(data.cbegin(), data.cend(), std::back_inserter(*h_vector)); std::copy(data.cbegin(), data.cend(), std::back_inserter(*h_vector));
data = addFilesAsArrays(csv_in.getValue(), mesh, "V"); data = addFilesAsArrays(csv_in.getValue(), mesh, "V");
if (data.empty()) if (data.empty())
return -1; return -1;
std::string const v_prop_name("TM_DD_V"); std::string const v_prop_name("TM_DD_V");
boost::optional< MeshLib::PropertyVector<double>&> v_vector = mesh->getProperties().createNewPropertyVector<double>(v_prop_name, MeshLib::MeshItemType::Cell); auto v_vector = mesh->getProperties().createNewPropertyVector<double>(v_prop_name, MeshLib::MeshItemType::Cell);
std::copy(data.cbegin(), data.cend(), std::back_inserter(*v_vector)); std::copy(data.cbegin(), data.cend(), std::back_inserter(*v_vector));
INFO ("Writing result..."); INFO("Writing result...");
MeshLib::IO::VtuInterface vtu(mesh); MeshLib::IO::VtuInterface vtu(mesh);
vtu.writeToFile(mesh_out.getValue()); vtu.writeToFile(mesh_out.getValue());
delete mesh; delete mesh;
delete custom_format;
delete logog_cout;
LOGOG_SHUTDOWN();
return 0; return 0;
} }
cmake/CPM.cmake 0 → 100644
set(CPM_DOWNLOAD_VERSION 0.32.2)
if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()
include(${CPM_DOWNLOAD_LOCATION})
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