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

Refactored to use CPM. addEmiDataToMesh compiles.

parent 84fa8d7e
No related branches found
No related tags found
1 merge request!1Refactor for OGS 6.4.0
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.16)
project(VisOgsTools)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/ogs/scripts/cmake/cmake
${CMAKE_SOURCE_DIR}/ogs/scripts/cmake)
include(CompilerSetup)
include(ProjectSetup)
include(${PROJECT_SOURCE_DIR}/cmake/CPM.cmake)
find_package( Qt4 )
add_subdirectory(${CMAKE_SOURCE_DIR}/ogs)
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}
CPMFindPackage(
NAME Boost
VERSION 1.69.0
URL https://boostorg.jfrog.io/artifactory/main/release/1.69.0/source/boost_1_69_0.tar.gz
)
if(Boost_ADDED)
add_library(Boost::boost INTERFACE IMPORTED)
target_include_directories(Boost::boost INTERFACE "${Boost_SOURCE_DIR}")
endif()
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(addScalarArrayTimeSeries)
#add_subdirectory(EmiData2PolyData)
add_subdirectory(ErtData2Mesh)
if (QT4_FOUND)
add_subdirectory(makeBuildings)
endif()
# add_subdirectory(addScalarArrayTimeSeries) add_subdirectory(EmiData2PolyData)
# add_subdirectory(ErtData2Mesh) if (QT4_FOUND) add_subdirectory(makeBuildings)
# endif()
add_executable(addEmiDataToMesh addEmiDataToMesh.cpp)
target_link_libraries(addEmiDataToMesh
logog
BaseLib
FileIO
InSituLib
${VTK_LIBRARIES}
)
ADD_VTK_DEPENDENCY(addEmiDataToMesh)
target_link_libraries(
addEmiDataToMesh
ApplicationsFileIO
BaseLib
MeshLib
tclap
ogs_include
Boost::boost)
set_target_properties(addEmiDataToMesh PROPERTIES FOLDER Utilities)
......@@ -12,56 +12,46 @@
*/
#include <algorithm>
#include <tclap/CmdLine.h>
// TCLAP
#include "tclap/CmdLine.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 "Applications/FileIO/CsvInterface.h"
#include "BaseLib/Logging.h"
#include "GeoLib/AnalyticalGeometry.h"
// MeshLib
#include "GeoLib/Grid.h"
#include "MathLib/GeometricBasics.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
#include "MeshLib/Properties.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);
MathLib::Vector3 const normal(0,0,-1);
MeshLib::Mesh* flat_mesh (MeshLib::projectMeshOntoPlane(mesh, origin, normal));
std::size_t n_elems (flat_mesh->getNElements());
auto nodes = mesh.getNodes();
std::vector<MeshLib::Node *> flat_nodes;
for (auto n : nodes)
{
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<std::size_t> counter(n_elems, 0);
std::vector<MeshLib::Node*> const& nodes (flat_mesh->getNodes());
GeoLib::Grid<MeshLib::Node> grid(nodes.cbegin(), nodes.cend());
GeoLib::Grid<MeshLib::Node> grid(flat_nodes.cbegin(), flat_nodes.cend());
std::size_t const n_points (data_points.size());
for (std::size_t i=0; i<n_points; ++i)
std::size_t const n_points(data_points.size());
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*const node = grid.getNearestPoint(pnt);
std::vector<MeshLib::Element*> const& conn_elems (node->getElements());
std::size_t const n_conn_elems (conn_elems.size());
for (std::size_t j=0; j<n_conn_elems; ++j)
MeshLib::Node const *const node = grid.getNearestPoint(pnt);
std::vector<MeshLib::Element *> const &conn_elems(node->getElements());
std::size_t const n_conn_elems(conn_elems.size());
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]);
counter[idx]++;
break;
......@@ -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)
data[i] /= static_cast<double>(counter[i]);
delete flat_mesh;
for (auto n : flat_nodes)
{
delete n;
}
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*> points2;
std::vector<GeoLib::Point*> points3;
std::vector<GeoLib::Point *> points;
std::vector<GeoLib::Point *> points2;
std::vector<GeoLib::Point *> points3;
std::string file_name = csv_base_name + "_A_" + name_specifier + ".txt";
INFO ("Reading file %s.", file_name.c_str());
int e1 = FileIO::CsvInterface::readPoints(file_name, '\t', points, 1, 2, 3);
INFO("Reading file {:s}.", file_name.c_str());
int e1 = FileIO::CsvInterface::readPoints(file_name, '\t', points, 1, 2, 3);
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);
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);
points.insert(points.end(), points2.begin(), points2.end());
......@@ -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())
{
ERR ("Error reading CSV-file.");
ERR("Error reading CSV-file.");
delete mesh;
std::vector<double> no_data;
return no_data;
......@@ -110,47 +104,41 @@ std::vector<double> addFilesAsArrays(std::string csv_base_name, MeshLib::Mesh *m
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");
// I/O params
TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
"the name of the file the mesh will be written to", true,
"", "file name of output mesh");
"the name of the file the mesh will be written to", true,
"", "file name of output mesh");
cmd.add(mesh_out);
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");
"the name of the file containing the input mesh", true,
"", "file name of input mesh");
cmd.add(mesh_in);
TCLAP::ValueArg<std::string> csv_in("", "csv",
"csv-file containing EMI data to be added as a scalar array.",
true, "", "name of the csv input file");
"csv-file containing EMI data to be added as a scalar array.",
true, "", "name of the csv input file");
cmd.add(csv_in);
cmd.parse(argc, argv);
INFO ("Reading mesh %s.", mesh_in.getValue().c_str());
MeshLib::Mesh* mesh (MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue()));
INFO("Reading mesh {:s}.", mesh_in.getValue().c_str());
MeshLib::Mesh *mesh(MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue()));
if (mesh == nullptr)
{
ERR ("Error reading mesh file.");
ERR("Error reading mesh file.");
return -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;
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;
......@@ -169,26 +157,21 @@ int main (int argc, char* argv[])
if (data.empty())
return -1;
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));
data = addFilesAsArrays(csv_in.getValue(), mesh, "V");
if (data.empty())
return -1;
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));
INFO ("Writing result...");
INFO("Writing result...");
MeshLib::IO::VtuInterface vtu(mesh);
vtu.writeToFile(mesh_out.getValue());
delete mesh;
delete custom_format;
delete logog_cout;
LOGOG_SHUTDOWN();
return 0;
}
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