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

addScalarArrayTimeSeries compiles.

parent df9c66e0
No related branches found
No related tags found
1 merge request!1Refactor for OGS 6.4.0
...@@ -3,36 +3,39 @@ project(VisOgsTools) ...@@ -3,36 +3,39 @@ project(VisOgsTools)
include(${PROJECT_SOURCE_DIR}/cmake/CPM.cmake) include(${PROJECT_SOURCE_DIR}/cmake/CPM.cmake)
CPMFindPackage( cpmfindpackage(
NAME Boost NAME
VERSION 1.69.0 Boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.69.0/source/boost_1_69_0.tar.gz 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) if(Boost_ADDED)
add_library(Boost::boost INTERFACE IMPORTED) add_library(Boost::boost INTERFACE IMPORTED)
target_include_directories(Boost::boost INTERFACE "${Boost_SOURCE_DIR}") target_include_directories(Boost::boost INTERFACE "${Boost_SOURCE_DIR}")
endif() endif()
CPMAddPackage( cpmaddpackage(
NAME tclap NAME
GITHUB_REPOSITORY ufz/tclap tclap
VERSION 1.2.4 GITHUB_REPOSITORY
GIT_TAG 098dd0fe07a31618f3c2a9f8727bb01c8c5d61e2 ufz/tclap
DOWNLOAD_ONLY YES VERSION
) 1.2.4
GIT_TAG
098dd0fe07a31618f3c2a9f8727bb01c8c5d61e2
DOWNLOAD_ONLY
YES)
if(tclap_ADDED) if(tclap_ADDED)
add_library(tclap INTERFACE IMPORTED) add_library(tclap INTERFACE IMPORTED)
target_include_directories( target_include_directories(tclap SYSTEM INTERFACE ${tclap_SOURCE_DIR}/include)
tclap SYSTEM INTERFACE ${tclap_SOURCE_DIR}/include
)
endif() endif()
CPMAddPackage( cpmaddpackage(
"https://gitlab.opengeosys.org/ogs/ogs.git#98aeeb379ac87cc88fb71d111bcb946e2db4c16f@6.4.0-dev" "https://gitlab.opengeosys.org/ogs/ogs.git#98aeeb379ac87cc88fb71d111bcb946e2db4c16f@6.4.0-dev"
) )
if(ogs_ADDED) if(ogs_ADDED)
add_library(ogs_include INTERFACE IMPORTED) add_library(ogs_include INTERFACE IMPORTED)
target_include_directories( target_include_directories(ogs_include SYSTEM INTERFACE ${ogs_SOURCE_DIR}/)
ogs_include SYSTEM INTERFACE ${ogs_SOURCE_DIR}/
)
endif() endif()
# find_package(Qt4) # find_package(Qt4)
...@@ -43,6 +46,6 @@ endif() ...@@ -43,6 +46,6 @@ endif()
# ${CONAN_INCLUDE_DIRS} ) # ${CONAN_INCLUDE_DIRS} )
add_subdirectory(addEmiDataToMesh) add_subdirectory(addEmiDataToMesh)
# add_subdirectory(addScalarArrayTimeSeries) add_subdirectory(EmiData2PolyData) add_subdirectory(addScalarArrayTimeSeries)
# add_subdirectory(ErtData2Mesh) if (QT4_FOUND) add_subdirectory(makeBuildings) # add_subdirectory(EmiData2PolyData) add_subdirectory(ErtData2Mesh) if
# endif() # (QT4_FOUND) add_subdirectory(makeBuildings) endif()
add_executable(addEmiDataToMesh addEmiDataToMesh.cpp) add_executable(addEmiDataToMesh addEmiDataToMesh.cpp)
target_link_libraries( target_link_libraries(addEmiDataToMesh ApplicationsFileIO BaseLib MeshLib tclap
addEmiDataToMesh ogs_include)
ApplicationsFileIO
BaseLib
MeshLib
tclap
ogs_include
Boost::boost)
set_target_properties(addEmiDataToMesh PROPERTIES FOLDER Utilities) set_target_properties(addEmiDataToMesh PROPERTIES FOLDER Utilities)
add_executable(addScalarArrayTimeSeries addScalarArrayTimeSeries.cpp) add_executable(addScalarArrayTimeSeries addScalarArrayTimeSeries.cpp)
target_link_libraries(addScalarArrayTimeSeries target_link_libraries(addScalarArrayTimeSeries ApplicationsFileIO BaseLib
logog MeshLib tclap ogs_include)
BaseLib
FileIO
InSituLib
${VTK_LIBRARIES}
)
ADD_VTK_DEPENDENCY(addScalarArrayTimeSeries)
set_target_properties(addScalarArrayTimeSeries PROPERTIES FOLDER Utilities) set_target_properties(addScalarArrayTimeSeries PROPERTIES FOLDER Utilities)
...@@ -17,17 +17,13 @@ ...@@ -17,17 +17,13 @@
// TCLAP // TCLAP
#include "tclap/CmdLine.h" #include "tclap/CmdLine.h"
// ThirdParty/logog
#include "logog/include/logog.hpp"
// BaseLib // BaseLib
#include "BaseLib/LogogSimpleFormatter.h"
#include "BaseLib/FileTools.h" #include "BaseLib/FileTools.h"
// FileIO // FileIO
#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "FileIO/CsvInterface.h" #include "Applications/FileIO/CsvInterface.h"
#include "GeoLib/IO/AsciiRasterInterface.h" #include "Applications/FileIO/AsciiRasterInterface.h"
// GeoLib // GeoLib
#include "GeoLib/Point.h" #include "GeoLib/Point.h"
...@@ -41,11 +37,11 @@ ...@@ -41,11 +37,11 @@
#include "MeshLib/Elements/Element.h" #include "MeshLib/Elements/Element.h"
#include "MeshLib/Elements/Quad.h" #include "MeshLib/Elements/Quad.h"
MeshLib::Mesh* createMesh() MeshLib::Mesh *createMesh()
{ {
std::string const x_file ("utm_x.csv"); std::string const x_file("utm_x.csv");
std::string const y_file ("utm_y.csv"); std::string const y_file("utm_y.csv");
std::string const z_file ("Z.csv"); std::string const z_file("Z.csv");
std::vector<double> x; std::vector<double> x;
int const e1 = FileIO::CsvInterface::readColumn<double>(x_file, '\t', x, 0); int const e1 = FileIO::CsvInterface::readColumn<double>(x_file, '\t', x, 0);
std::vector<double> y; std::vector<double> y;
...@@ -53,30 +49,30 @@ MeshLib::Mesh* createMesh() ...@@ -53,30 +49,30 @@ MeshLib::Mesh* createMesh()
std::vector<double> z; std::vector<double> z;
int const e3 = FileIO::CsvInterface::readColumn<double>(z_file, '\t', z, 0); int const e3 = FileIO::CsvInterface::readColumn<double>(z_file, '\t', z, 0);
if (e1!=0 || e2!=0 || e3!=0) if (e1 != 0 || e2 != 0 || e3 != 0)
return nullptr; return nullptr;
if (x.size() != y.size()) if (x.size() != y.size())
return nullptr; return nullptr;
std::size_t const n_cols (x.size()); std::size_t const n_cols(x.size());
std::size_t const n_rows (z.size()); std::size_t const n_rows(z.size());
std::vector<MeshLib::Node*> nodes; std::vector<MeshLib::Node *> nodes;
nodes.reserve(n_rows*n_cols); nodes.reserve(n_rows * n_cols);
for (std::size_t r=0; r<n_rows; ++r) for (std::size_t r = 0; r < n_rows; ++r)
for (std::size_t c=0; c<n_cols; ++c) for (std::size_t c = 0; c < n_cols; ++c)
nodes.push_back(new MeshLib::Node(x[c], y[c], z[r], nodes.size())); nodes.push_back(new MeshLib::Node(x[c], y[c], z[r], nodes.size()));
std::vector<MeshLib::Element*> elems; std::vector<MeshLib::Element *> elems;
elems.reserve((n_rows-1)*(n_cols-1)); elems.reserve((n_rows - 1) * (n_cols - 1));
std::vector<std::size_t> mats; std::vector<std::size_t> mats;
mats.reserve((n_rows-1)*(n_cols-1)); mats.reserve((n_rows - 1) * (n_cols - 1));
for (std::size_t r=0; r<n_rows-2; ++r) for (std::size_t r = 0; r < n_rows - 2; ++r)
{ {
std::size_t base_idx = r*n_cols; std::size_t base_idx = r * n_cols;
for (std::size_t c=0; c<n_cols-1; ++c) for (std::size_t c = 0; c < n_cols - 1; ++c)
{ {
std::array<MeshLib::Node*, 4> quad_nodes; std::array<MeshLib::Node *, 4> quad_nodes;
quad_nodes[0] = nodes[base_idx + c]; quad_nodes[0] = nodes[base_idx + c];
quad_nodes[1] = nodes[base_idx + c + n_cols]; quad_nodes[1] = nodes[base_idx + c + n_cols];
quad_nodes[2] = nodes[base_idx + c + n_cols + 1]; quad_nodes[2] = nodes[base_idx + c + n_cols + 1];
...@@ -86,8 +82,8 @@ MeshLib::Mesh* createMesh() ...@@ -86,8 +82,8 @@ MeshLib::Mesh* createMesh()
} }
} }
MeshLib::Mesh* mesh = new MeshLib::Mesh("Mesh", nodes, elems); MeshLib::Mesh *mesh = new MeshLib::Mesh("Mesh", nodes, elems);
boost::optional<std::vector<int>&> mat_prop (mesh->getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell)); auto mat_prop(mesh->getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell));
mat_prop->insert(mat_prop->end(), mats.begin(), mats.end()); mat_prop->insert(mat_prop->end(), mats.begin(), mats.end());
return mesh; return mesh;
...@@ -100,49 +96,44 @@ std::string number2str(std::size_t n) ...@@ -100,49 +96,44 @@ std::string number2str(std::size_t n)
return convert.str(); return convert.str();
} }
std::string output_question(std::string const& output_name) std::string output_question(std::string const &output_name)
{ {
WARN ("Output file %s already exists. Overwrite? (y/n)", output_name); WARN("Output file {:s} already exists. Overwrite? (y/n)", output_name);
std::string input; std::string input;
std::cin >> input; std::cin >> input;
return input; return input;
} }
bool overwriteFiles(std::string const& output_name) bool overwriteFiles(std::string const &output_name)
{ {
if (!BaseLib::IsFileExisting(output_name)) if (!BaseLib::IsFileExisting(output_name))
return true; return true;
std::string input (""); std::string input("");
while (input != "y" && input != "Y" && input != "n" && input != "N") while (input != "y" && input != "Y" && input != "n" && input != "N")
input = output_question(output_name); input = output_question(output_name);
if (input == "y" || input == "Y") if (input == "y" || input == "Y")
return true; return true;
return false; return false;
} }
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("Adds a scalar array time series from a csv-file to an existing mesh or a time series of meshes.", ' ', "0.1"); TCLAP::CmdLine cmd("Adds a scalar array time series from a csv-file to an existing mesh or a time series of meshes.", ' ', "0.1");
// I/O params // I/O params
TCLAP::ValueArg<std::string> mesh_new("b", "base", TCLAP::ValueArg<std::string> mesh_new("b", "base",
"Use this if a time series of vtu-files should be created based on a single vtu-file. If a time series *is* already existing, this parameter need not be set.", "Use this if a time series of vtu-files should be created based on a single vtu-file. If a time series *is* already existing, this parameter need not be set.",
false, "", "base mesh input"); false, "", "base mesh input");
cmd.add(mesh_new); cmd.add(mesh_new);
TCLAP::ValueArg<std::string> mesh_add("t", "output", TCLAP::ValueArg<std::string> mesh_add("t", "output",
"This is the base name of the output files, e.g. \'output\' will result in files called \'output0.vtu\', \'output1.vtu\', etc. If a time series is already existing, a new array will simply be added to each time step.", "This is the base name of the output files, e.g. \'output\' will result in files called \'output0.vtu\', \'output1.vtu\', etc. If a time series is already existing, a new array will simply be added to each time step.",
true, "", "name of mesh output"); true, "", "name of mesh output");
cmd.add(mesh_add); cmd.add(mesh_add);
TCLAP::ValueArg<std::string> csv_in("i", "csv", TCLAP::ValueArg<std::string> csv_in("i", "csv",
"CSV-file containing the input information for the scalar arrays. It is assumed that all timesteps are in one file with an empty line between timesteps and with one value per grid cell per time step.", "CSV-file containing the input information for the scalar arrays. It is assumed that all timesteps are in one file with an empty line between timesteps and with one value per grid cell per time step.",
true, "", "csv input file"); true, "", "csv input file");
cmd.add(csv_in); cmd.add(csv_in);
cmd.parse(argc, argv); cmd.parse(argc, argv);
...@@ -150,18 +141,18 @@ int main (int argc, char* argv[]) ...@@ -150,18 +141,18 @@ int main (int argc, char* argv[])
if (!csv_in.isSet()) if (!csv_in.isSet())
{ {
ERR ("Name of csv-file is missing."); ERR("Name of csv-file is missing.");
return -5; return -5;
} }
if (!mesh_add.isSet()) if (!mesh_add.isSet())
{ {
ERR ("Base name of output files is missing."); ERR("Base name of output files is missing.");
return -4; return -4;
} }
int n_rows = -1; int n_rows = -1;
MeshLib::Mesh* mesh = nullptr; MeshLib::Mesh *mesh = nullptr;
if (mesh_new.isSet()) if (mesh_new.isSet())
{ {
mesh = MeshLib::IO::VtuInterface::readVTUFile(mesh_new.getValue()); mesh = MeshLib::IO::VtuInterface::readVTUFile(mesh_new.getValue());
...@@ -170,14 +161,14 @@ int main (int argc, char* argv[]) ...@@ -170,14 +161,14 @@ int main (int argc, char* argv[])
return -1; return -1;
} }
boost::optional<MeshLib::PropertyVector<int>&> materials (mesh->getProperties().getPropertyVector<int>("MaterialIDs")); auto materials(mesh->getProperties().getPropertyVector<int>("MaterialIDs"));
n_rows = (*std::max_element(materials->cbegin(), materials->cend())) + 1; n_rows = (*std::max_element(materials->cbegin(), materials->cend())) + 1;
} }
std::ifstream in( csv_in.getValue().c_str() ); std::ifstream in(csv_in.getValue().c_str());
if (!in.is_open()) if (!in.is_open())
{ {
ERR ("Could not open CSV file."); ERR("Could not open CSV file.");
return -2; return -2;
} }
...@@ -185,46 +176,46 @@ int main (int argc, char* argv[]) ...@@ -185,46 +176,46 @@ int main (int argc, char* argv[])
std::string line; std::string line;
std::size_t file_counter(0); std::size_t file_counter(0);
bool overwrite (false); bool overwrite(false);
while (getline(in, line)) while (getline(in, line))
{ {
if (!mesh_new.isSet()) if (!mesh_new.isSet())
{ {
mesh = MeshLib::IO::VtuInterface::readVTUFile(mesh_add.getValue() + number2str(file_counter) + ".vtu"); mesh = MeshLib::IO::VtuInterface::readVTUFile(mesh_add.getValue() + number2str(file_counter) + ".vtu");
if (mesh==nullptr) if (mesh == nullptr)
{ {
ERR("No base mesh given and no mesh for time step %d found.", file_counter); ERR("No base mesh given and no mesh for time step {:d} found.", file_counter);
return -6; return -6;
} }
boost::optional<MeshLib::PropertyVector<int>&> materials (mesh->getProperties().getPropertyVector<int>("MaterialIDs")); auto materials(mesh->getProperties().getPropertyVector<int>("MaterialIDs"));
n_rows = (*std::max_element(materials->cbegin(), materials->cend())) + 1; n_rows = (*std::max_element(materials->cbegin(), materials->cend())) + 1;
} }
std::string const prop_name(BaseLib::extractBaseNameWithoutExtension(csv_in.getValue())); std::string const prop_name(BaseLib::extractBaseNameWithoutExtension(csv_in.getValue()));
boost::optional<MeshLib::PropertyVector<double>&> prop (mesh->getProperties().createNewPropertyVector<double>(prop_name, MeshLib::MeshItemType::Cell)); auto prop(mesh->getProperties().createNewPropertyVector<double>(prop_name, MeshLib::MeshItemType::Cell));
prop->resize(mesh->getNNodes(), 0); prop->resize(mesh->getNumberOfNodes(), 0);
for (int i=0; i<=n_rows; ++i) for (int i = 0; i <= n_rows; ++i)
{ {
std::list<std::string> fields = BaseLib::splitString(line, ','); std::list<std::string> fields = BaseLib::splitString(line, ',');
int const n_cols (fields.size()); int const n_cols(fields.size());
if (n_cols != (mesh->getNElements() / n_rows) + 1) if (n_cols != (mesh->getNumberOfElements() / n_rows) + 1)
return -3; return -3;
int idx_cnt(i * (n_cols-1)); int idx_cnt(i * (n_cols - 1));
auto it = fields.cbegin(); auto it = fields.cbegin();
it++; it++;
for (; it != fields.cend(); ++it) for (; it != fields.cend(); ++it)
{ {
if ((*it).compare("NaN") == 0) if ((*it).compare("NaN") == 0)
(*prop)[idx_cnt++] = nan_value; (*prop)[idx_cnt++] = nan_value;
else else
(*prop)[idx_cnt++] = std::stod(*it); (*prop)[idx_cnt++] = std::stod(*it);
} }
getline(in, line); getline(in, line);
} }
INFO ("Writing result #%d...", file_counter); INFO("Writing result #{:d}...", file_counter);
std::string output_name (mesh_add.getValue() + number2str(file_counter) + ".vtu"); std::string output_name(mesh_add.getValue() + number2str(file_counter) + ".vtu");
if (overwrite == false) if (overwrite == false)
{ {
overwrite = overwriteFiles(output_name); overwrite = overwriteFiles(output_name);
...@@ -235,19 +226,13 @@ int main (int argc, char* argv[]) ...@@ -235,19 +226,13 @@ int main (int argc, char* argv[])
MeshLib::IO::VtuInterface vtu(mesh); MeshLib::IO::VtuInterface vtu(mesh);
vtu.writeToFile(output_name); vtu.writeToFile(output_name);
file_counter++; file_counter++;
getline(in, line); getline(in, line);
if (!line.empty()) if (!line.empty())
ERR("something is wrong here."); ERR("something is wrong here.");
} }
//delete mesh; //delete mesh;
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