Skip to content
Snippets Groups Projects
Commit 9ed3eede authored by Karsten Rink's avatar Karsten Rink
Browse files

updating addScalarArrayTimeSeries to current CSV interface

parent 48ba24f6
No related branches found
No related tags found
No related merge requests found
/**
* @file RappbodeTracer.cpp
* @file addScalarArrayTimeSeries.cpp
* @author Karsten Rink
* @date 2015/04/22
* @brief Converts an ERT-CSV-file into a mesh
......@@ -37,33 +37,30 @@
#include "MeshLib/Elements/Element.h"
#include "MeshLib/Elements/Quad.h"
MeshLib::Mesh *createMesh()
MeshLib::Mesh* createMesh()
{
std::string const x_file("utm_x.csv");
std::string const y_file("utm_y.csv");
std::string const z_file("Z.csv");
std::vector<double> x;
int const e1 = FileIO::CsvInterface::readColumn<double>(x_file, '\t', x, 0);
std::vector<double> y;
int const e2 = FileIO::CsvInterface::readColumn<double>(y_file, '\t', y, 0);
std::vector<double> z;
int const e3 = FileIO::CsvInterface::readColumn<double>(z_file, '\t', z, 0);
if (e1 != 0 || e2 != 0 || e3 != 0)
std::pair<int, std::vector<double>> x = FileIO::CsvInterface::readColumn<double>(x_file, '\t', 0);
std::pair<int, std::vector<double>> y = FileIO::CsvInterface::readColumn<double>(y_file, '\t', 0);
std::pair<int, std::vector<double>> z = FileIO::CsvInterface::readColumn<double>(z_file, '\t', 0);
if (x.first != 0 || y.first != 0 || z.first != 0)
return nullptr;
if (x.size() != y.size())
if (x.second.size() != y.second.size())
return nullptr;
std::size_t const n_cols(x.size());
std::size_t const n_rows(z.size());
std::vector<MeshLib::Node *> nodes;
std::size_t const n_cols(x.second.size());
std::size_t const n_rows(z.second.size());
std::vector<MeshLib::Node*> nodes;
nodes.reserve(n_rows * n_cols);
for (std::size_t r = 0; r < n_rows; ++r)
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.second[c], y.second[c], z.second[r], nodes.size()));
std::vector<MeshLib::Element *> elems;
std::vector<MeshLib::Element*> elems;
elems.reserve((n_rows - 1) * (n_cols - 1));
std::vector<std::size_t> mats;
mats.reserve((n_rows - 1) * (n_cols - 1));
......@@ -72,7 +69,7 @@ MeshLib::Mesh *createMesh()
std::size_t base_idx = r * n_cols;
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[1] = nodes[base_idx + c + n_cols];
quad_nodes[2] = nodes[base_idx + c + n_cols + 1];
......@@ -82,7 +79,7 @@ MeshLib::Mesh *createMesh()
}
}
MeshLib::Mesh *mesh = new MeshLib::Mesh("Mesh", nodes, elems);
MeshLib::Mesh* mesh = new MeshLib::Mesh("Mesh", nodes, elems);
auto mat_prop(mesh->getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell));
mat_prop->insert(mat_prop->end(), mats.begin(), mats.end());
......@@ -96,7 +93,7 @@ std::string number2str(std::size_t n)
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);
std::string input;
......@@ -104,7 +101,7 @@ std::string output_question(std::string const &output_name)
return input;
}
bool overwriteFiles(std::string const &output_name)
bool overwriteFiles(std::string const& output_name)
{
if (!BaseLib::IsFileExisting(output_name))
return true;
......@@ -118,22 +115,22 @@ bool overwriteFiles(std::string const &output_name)
return false;
}
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
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
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.",
false, "", "base mesh input");
"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");
cmd.add(mesh_new);
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.",
true, "", "name of mesh 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.",
true, "", "name of mesh output");
cmd.add(mesh_add);
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.",
true, "", "csv input file");
"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");
cmd.add(csv_in);
cmd.parse(argc, argv);
......@@ -152,7 +149,7 @@ int main(int argc, char *argv[])
}
int n_rows = -1;
MeshLib::Mesh *mesh = nullptr;
MeshLib::Mesh* mesh = nullptr;
if (mesh_new.isSet())
{
mesh = MeshLib::IO::VtuInterface::readVTUFile(mesh_new.getValue());
......
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