37 !std::filesystem::is_directory(directory)
39 !std::filesystem::exists(directory)
42 std::filesystem::create_directory(directory);
43 logInfo(
"createDirectory(...)",
"created directory " << directory );
45 catch (std::exception exc) {
46 logError(
"createDirectory(...)",
"failed to create directory " << directory );
47 logError(
"createDirectory(...)",
"error message: " << exc.what() );
60 std::vector< convert::data::DataSet > data = reader.getData();
62 int datasetCounter = 0;
63 for (
auto& pp: data) {
64 logInfo(
"inspect",
"dataset #" << datasetCounter );
66 for (
auto& p: pp.getVariables()) {
67 logInfo(
"inspect",
"variable " << p.name );
69 logInfo(
"inspect",
"\tdofs per axis\t\t" << p.dofsPerAxis );
70 logInfo(
"inspect",
"\tunknowns per dof\t" << p.unknowns );
79 std::string result = file;
80 logDebug(
"getFileNameWithoutExtensionAndWithoutPatch(std::string)",
"in=" << result );
81 if ( result.find_last_of(
".")!=std::string::npos ) {
82 result = result.erase(result.find_last_of(
".") );
84 if ( result.find_last_of(
"/")!=std::string::npos ) {
85 result = result.erase(0,result.find_last_of(
"/")+1 );
87 logDebug(
"getFileNameWithoutExtensionAndWithoutPatch(std::string)",
"out=" << result );
95 convert::output::PeanoWriter::Writer* writer =
nullptr;
97 const std::string fileWithCorrectSelector = truncatedFile +
"-" + variable.
name;
105 logError(
"convertFile(...)",
"unknown output format " << format );
109 writer->writeFile( variable, data.getData(variable) );
115void convertFile( std::string filename,
const std::string& outputDirectory,
const std::string& selector,
const std::string& format ) {
122 std::vector< convert::data::DataSet > data = reader.getData();
125 logDebug(
"convertFile(...)",
"read " << filename <<
" and write into " << truncatedFile <<
" in directory " << outputDirectory );
128 logError(
"convertFile(...)",
"data file is empty" );
130 else if (selector==
"all") {
131 #pragma omp parallel for
132 for (
int i=0; i<data.size(); i++) {
133 for (
auto variable: data[i].getVariables()) {
135 outputDirectory, truncatedFile +
"-" + std::to_string(i), format,
141 else if (data[0].hasVariable(selector)) {
142 #pragma omp parallel for
143 for (
int i=0; i<data.size(); i++) {
146 outputDirectory, truncatedFile +
"-" + std::to_string(i), format,
152 logError(
"convertFile(...)",
"data file does not contain any data set with name " << selector );
155 for (
auto& p: data) {
175 return "extract-fine-grid";
177 return "select-value";
179 return "separate-resolutions";
181 return "plot-domain-decomposition";
187void applyFilter( std::string filename, std::string outputDirectory, std::string selector, std::string filterName, std::string targetSelector) {
193 logInfo(
"applyFilter(...)",
"writing file " << truncatedFile );
197 std::vector< convert::data::DataSet > data = reader.getData();
200 logError(
"applyFilter(...)",
"file already contains data set with name " << targetSelector );
202 else if (data[0].hasVariable(selector)) {
203 logInfo(
"applyFilter(...)",
"apply filter to " << data.size() <<
" file(s)" );
207 const int numberOfDataSets = data.size();
208 #pragma omp parallel for
209 for (
int i=0; i<numberOfDataSets; i++) {
210 if (data[i].hasVariable(targetSelector)) {
211 logError(
"applyFilter(...)",
"file already contains data set with name " << targetSelector );
230 std::string rangeToken = filterName.substr( filterName.find(
':')+1 );
231 std::string fromToken = rangeToken.substr( 0, rangeToken.find(
':') );
232 std::string toToken = rangeToken.substr( rangeToken.find(
':')+1 );
234 logDebug(
"applyFilter(...)",
"use range token " << rangeToken <<
" split into " << fromToken <<
" and " << toToken );
238 logError(
"applyFilter(...)",
"unknown filter " << filterName );
241 if (filter!=
nullptr) {
242 filter->apply( data[i], variable, targetSelector );
254 logError(
"applyFilter(...)",
"data file does not contain any data set with name " << selector );
257 for (
auto& p: data) {
263int main(
int argc,
char* argv[]) {
264 std::cout <<
"Peano file format converter/inspector" << std::endl;
265 std::cout <<
"(C) 2018/2019 Dan Tuthill-Jones, Tobias Weinzierl" << std::endl << std::endl;
266 bool validParams =
true;
269 std::cerr <<
"too few arguments" << std::endl;
275 std::string mode = argv[1];
276 if (mode.compare(
"inspect")==0 and argc>=3) {
277 for (
int i=2; i<argc; i++) {
281 else if (mode.compare(
"convert-file")==0 and argc>=5) {
282 std::string selector = argv[ argc-3 ];
283 std::string outputDirectory = argv[ argc-2 ];
284 std::string format = argv[ argc-1 ];
285 for (
int i=2; i<argc-3; i++) {
286 convertFile( argv[i], outputDirectory, selector, format );
289 else if (mode.compare(
"apply-filter")==0 and argc>=7) {
290 std::string selector = argv[ argc-4 ];
291 std::string outputDirectory = argv[ argc-3 ];
292 std::string filter = argv[ argc-2 ];
293 std::string targetSelector = argv[ argc-1 ];
294 for (
int i=2; i<argc-4; i++) {
295 applyFilter( argv[i], outputDirectory, selector, filter, targetSelector);
299 std::cerr <<
"unknown command or invalid number of parameters for particular command" << std::endl;
305 std::cerr << std::endl << std::endl;
306 std::cerr <<
"Usage:";
307 std::cerr <<
"\t./executable inspect InputFile1 [InputFile2 ...] " << std::endl;
308 std::cerr <<
"\t./executable convert-file InputFile1 [InputFile2 ...] Selector OutputFolder Format" << std::endl;
309 std::cerr <<
"\t./executable apply-filter InputFile1 [InputFile2 ...] Selector OutputFolder Filter TargetSelector" << std::endl;
311 std::cerr << std::endl << std::endl;
312 std::cerr <<
"Variants:" << std::endl;
313 std::cerr <<
"\tinspect Inspect which data sets are stored within file (cmp Selector below)" << std::endl;
314 std::cerr <<
"\tconvert-file Convert a single file" << std::endl;
315 std::cerr <<
"\tapply-filter Take a data set from the input file (identified by Selector), apply a filter to" << std::endl;
316 std::cerr <<
"\t this set and add the result to the file with a given TargetSelector name" << std::endl;
318 std::cerr << std::endl << std::endl;
319 std::cerr <<
"Options:" << std::endl;
321 std::cerr <<
"\tSelector Use inspect to see which data sets are stored within your patch file, i.e. which you can select. Pass all to convert all data sets (works only with convert-file)" << std::endl;
323 std::cerr << std::endl << std::endl;
324 std::cerr <<
"Filters:" << std::endl;
325 std::cerr <<
"\t" <<
toString(
Filter::Copy) <<
" Create 1:1 copy of dataset with different name (for debugging)" << std::endl;
327 std::cerr <<
"\t" <<
toString(
Filter::SelectValue) <<
" Extract grid patches that hold values of a certain range. Append :from:to to filter to specify range" << std::endl;
329 std::cerr <<
"\t" <<
toString(
Filter::PlotDomainDecomposition) <<
" Don't plot any data but display which mesh parts are handled by which tree (please use this as first filter if you apply a series of filters)" << std::endl;
331 std::cerr << std::endl << std::endl;
332 std::cerr <<
"Output directory plus filename can be the same as the input file. In this case, the original file is overwritten/augmented with new data" << std::endl;
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
#define logDebug(methodName, logMacroMessageStream)
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
tarch::logging::Log _log("::")
A dataset is a wrapper around one big map.
Represents one variable that is subsequently attached to the patches of a file.
Represent a Peano reader.
virtual void writeFile(const convert::data::Variable &variable, const std::vector< convert::data::PatchData > &data) override
Our writers write only one variable at a time even though the Peano file format can hold multiple var...
void setOutputFile(const std::string &outputLogFileName)
Is redundant, as you could use setLogFormat() instead.
static ChromeTraceFileLogger & getInstance()
static void abort(int errorCode)
A proper abort in an MPI context has to use MPI_Abort.
void inspect(std::string filename)
void convertFile(const std::string &outputDirectory, const std::string &truncatedFile, const std::string &format, convert::data::Variable variable, const convert::data::DataSet &data)
std::string toString(Filter filter)
void createDirectory(const std::string &directory)
const std::string OutputFormatPeano
std::string getFileNameWithoutExtensionAndWithoutPatch(std::string &file)
@ PlotDomainDecomposition
void applyFilter(std::string filename, std::string outputDirectory, std::string selector, std::string filterName, std::string targetSelector)
const std::string OutputFormatVTU