| 1 |
// Copyright(C) 1999-2023 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include "IossApplication.h" |
| 8 |
#include "CatalystPluginPaths.h" |
| 9 |
#include "Ionit_Initializer.h" |
| 10 |
#include "IossRegionReport.h" |
| 11 |
#include "Ioss_CopyDatabase.h" |
| 12 |
#include "Ioss_DatabaseIO.h" |
| 13 |
#include "Ioss_FileInfo.h" |
| 14 |
#include "Ioss_IOFactory.h" |
| 15 |
#include "Ioss_MeshCopyOptions.h" |
| 16 |
#include "Ioss_Region.h" |
| 17 |
#include "Ioss_Utils.h" |
| 18 |
#include <cstdlib> |
| 19 |
#include <fstream> |
| 20 |
#include <iomanip> |
| 21 |
#include <iostream> |
| 22 |
#include <mpi.h> |
| 23 |
#include <random> |
| 24 |
#include <unistd.h> |
| 25 |
std::random_device myrd9; // only used once to initialise (seed) engine |
| 26 |
std::mt19937 rng(myrd9()); // random-number engine used (Mersenne-Twister in this case) |
| 27 |
std::uniform_int_distribution<int> myuni9(0, 1000000000); // guaranteed unbiased |
| 28 |
|
| 29 |
IossApplication::IossApplication() |
| 30 |
{ |
| 31 |
initialize(); |
| 32 |
setenv("CATALYST_ADAPTER_INSTALL_DIR", CATALYST_PLUGIN_BUILD_DIR, false); |
| 33 |
std::string pluginLibPath = |
| 34 |
std::string(CATALYST_PLUGIN_BUILD_DIR) + std::string("/") + CATALYST_PLUGIN_DYNAMIC_LIBRARY; |
| 35 |
setenv("CATALYST_PLUGIN", pluginLibPath.c_str(), false); |
| 36 |
} |
| 37 |
|
| 38 |
IossApplication::IossApplication(int argc, char **argv) |
| 39 |
{ |
| 40 |
initializeMPI(argc, argv); |
| 41 |
initialize(); |
| 42 |
processCommandLine(argc, argv); |
| 43 |
setenv("CATALYST_ADAPTER_INSTALL_DIR", CATALYST_PLUGIN_INSTALL_DIR, false); |
| 44 |
} |
| 45 |
|
| 46 |
void IossApplication::initialize() |
| 47 |
{ |
| 48 |
myRank = 0; |
| 49 |
numRanks = 1; |
| 50 |
printIOSSReport = false; |
| 51 |
copyDatabase = false; |
| 52 |
writeCatalystMeshOneFile = false; |
| 53 |
writeCatalystMeshFilePerProc = false; |
| 54 |
usePhactoriInputScript = false; |
| 55 |
usePhactoriInputJSON = false; |
| 56 |
useParaViewExportedScript = false; |
| 57 |
phactoriInputScriptFilePath = ""; |
| 58 |
phactoriInputJSONFilePath = ""; |
| 59 |
paraViewExportedScriptFilePath = ""; |
| 60 |
catalystStartTimeStep = 0; |
| 61 |
useCatalystStartTimeStep = false; |
| 62 |
catalystStopTimeStep = 0; |
| 63 |
useCatalystStopTimeStep = false; |
| 64 |
forceCGNSOutput = false; |
| 65 |
forceExodusOutput = false; |
| 66 |
useIOSSInputDBType = false; |
| 67 |
hasCommandLineArguments = false; |
| 68 |
applicationExitCode = EXIT_SUCCESS; |
| 69 |
additionalProperties = nullptr; |
| 70 |
sendMultipleGridsToTheSamePipeline = true; |
| 71 |
initMPIRankAndSize(); |
| 72 |
} |
| 73 |
|
| 74 |
IossApplication::~IossApplication() |
| 75 |
{ |
| 76 |
int ii; |
| 77 |
int numRegions = inputIOSSRegion.size(); |
| 78 |
for (ii = 0; ii < numRegions; ii++) { |
| 79 |
if (inputIOSSRegion[ii] != nullptr) { |
| 80 |
delete inputIOSSRegion[ii]; |
| 81 |
inputIOSSRegion[ii] = nullptr; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
void IossApplication::runApplication() |
| 87 |
{ |
| 88 |
checkForOnlyOneCatalystOutputPath(); |
| 89 |
checkForOnlyOneCatalystOutputType(); |
| 90 |
Ioss::Init::Initializer io; |
| 91 |
openInputIOSSDatabases(); |
| 92 |
|
| 93 |
if (printIOSSRegionReportON()) { |
| 94 |
printIOSSRegionReportsForRank(); |
| 95 |
} |
| 96 |
|
| 97 |
if (outputCopyOfInputDatabaseON()) { |
| 98 |
copyInputIOSSDatabaseOnRank(); |
| 99 |
} |
| 100 |
|
| 101 |
callCatalystIOSSDatabaseOnRank(); |
| 102 |
sync(); |
| 103 |
|
| 104 |
exitApplicationSuccess(); |
| 105 |
} |
| 106 |
|
| 107 |
int IossApplication::getApplicationExitCode() { return applicationExitCode; } |
| 108 |
|
| 109 |
int IossApplication::getMyRank() { return myRank; } |
| 110 |
|
| 111 |
int IossApplication::getNumRanks() { return numRanks; } |
| 112 |
|
| 113 |
bool IossApplication::isRankZero() { return myRank == 0; } |
| 114 |
|
| 115 |
bool IossApplication::isSerial() { return numRanks == 1; } |
| 116 |
|
| 117 |
void IossApplication::initializeMPI(int argc, char **argv) { MPI_Init(&argc, &argv); } |
| 118 |
|
| 119 |
void IossApplication::initMPIRankAndSize() |
| 120 |
{ |
| 121 |
Ioss::ParallelUtils pu{}; |
| 122 |
myRank = pu.parallel_rank(); |
| 123 |
numRanks = pu.parallel_size(); |
| 124 |
} |
| 125 |
|
| 126 |
void IossApplication::finalizeMPI() { MPI_Finalize(); } |
| 127 |
|
| 128 |
void IossApplication::processCommandLine(int argc, char **argv) |
| 129 |
{ |
| 130 |
hasCommandLineArguments = true; |
| 131 |
|
| 132 |
int c; |
| 133 |
char *cvalue = NULL; |
| 134 |
while ((c = getopt(argc, argv, "a:b:cd:e:hi:mnp:rs:")) != -1) { |
| 135 |
char *cvalue = nullptr; |
| 136 |
switch (c) { |
| 137 |
case 'a': |
| 138 |
cvalue = optarg; |
| 139 |
setCatalystStartTimeStep(atoi(cvalue)); |
| 140 |
break; |
| 141 |
case 'b': |
| 142 |
cvalue = optarg; |
| 143 |
setCatalystStopTimeStep(atoi(cvalue)); |
| 144 |
break; |
| 145 |
case 'c': copyDatabase = true; break; |
| 146 |
case 'd': |
| 147 |
cvalue = optarg; |
| 148 |
setForceExodusOutput(true); |
| 149 |
setIOSSInputDBType(cvalue); |
| 150 |
break; |
| 151 |
case 'e': |
| 152 |
cvalue = optarg; |
| 153 |
setForceCGNSOutput(true); |
| 154 |
setIOSSInputDBType(cvalue); |
| 155 |
break; |
| 156 |
case 'h': |
| 157 |
printUsageMessage(); |
| 158 |
exitApplicationSuccess(); |
| 159 |
break; |
| 160 |
case 'i': |
| 161 |
cvalue = optarg; |
| 162 |
addPhactoriInputJSON(cvalue); |
| 163 |
break; |
| 164 |
case 'm': setOutputCatalystMeshOneFile(true); break; |
| 165 |
case 'n': setOutputCatalystMeshFilePerProc(true); break; |
| 166 |
case 'p': |
| 167 |
cvalue = optarg; |
| 168 |
setPhactoriInputScript(cvalue); |
| 169 |
break; |
| 170 |
case 'r': printIOSSReport = true; break; |
| 171 |
case 's': |
| 172 |
cvalue = optarg; |
| 173 |
setParaViewExportedScript(cvalue); |
| 174 |
break; |
| 175 |
case '?': |
| 176 |
printErrorMessage("Unknown command line option -" + std::string(1, c) + "\n"); |
| 177 |
printUsageMessage(); |
| 178 |
exitApplicationFailure(); |
| 179 |
break; |
| 180 |
default: |
| 181 |
printUsageMessage(); |
| 182 |
exitApplicationFailure(); |
| 183 |
break; |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
if (optind == argc) { |
| 188 |
printErrorMessage("No input filename given on command line"); |
| 189 |
printUsageMessage(); |
| 190 |
exitApplicationFailure(); |
| 191 |
} |
| 192 |
else if (optind != argc - 1) { |
| 193 |
printErrorMessage("Expected one argument for input filename. " + |
| 194 |
std::string("Got multiple arguments.")); |
| 195 |
printUsageMessage(); |
| 196 |
exitApplicationFailure(); |
| 197 |
} |
| 198 |
else { |
| 199 |
// fileName = argv[optind]; |
| 200 |
addFileName(argv[optind]); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
void IossApplication::getStartStopTimeSteps(int numTimeSteps, int &startTimeStep, int &stopTimeStep) |
| 205 |
{ |
| 206 |
|
| 207 |
if (useCatalystStartTimeStepON()) { |
| 208 |
startTimeStep = getCatalystStartTimeStep(); |
| 209 |
if (startTimeStep < 1 || startTimeStep > numTimeSteps) { |
| 210 |
printErrorMessage("Start time-step out of range"); |
| 211 |
exitApplicationFailure(); |
| 212 |
} |
| 213 |
} |
| 214 |
else { |
| 215 |
startTimeStep = 1; |
| 216 |
} |
| 217 |
|
| 218 |
if (useCatalystStopTimeStepON()) { |
| 219 |
stopTimeStep = getCatalystStopTimeStep(); |
| 220 |
if (stopTimeStep < 1 || stopTimeStep > numTimeSteps) { |
| 221 |
printErrorMessage("Stop time-step out of range"); |
| 222 |
exitApplicationFailure(); |
| 223 |
} |
| 224 |
} |
| 225 |
else { |
| 226 |
stopTimeStep = numTimeSteps; |
| 227 |
} |
| 228 |
|
| 229 |
if (startTimeStep > stopTimeStep) { |
| 230 |
printErrorMessage("Start time-step > stop time-step."); |
| 231 |
exitApplicationFailure(); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
void IossApplication::checkForOnlyOneCatalystOutputPath() |
| 236 |
{ |
| 237 |
|
| 238 |
int numTimesCatalystCalled = 0; |
| 239 |
if (usePhactoriInputScriptON()) { |
| 240 |
numTimesCatalystCalled++; |
| 241 |
} |
| 242 |
if (usePhactoriInputJSONON()) { |
| 243 |
numTimesCatalystCalled++; |
| 244 |
} |
| 245 |
if (outputCatalystMeshOneFileON()) { |
| 246 |
numTimesCatalystCalled++; |
| 247 |
} |
| 248 |
if (outputCatalystMeshFilePerProcON()) { |
| 249 |
numTimesCatalystCalled++; |
| 250 |
} |
| 251 |
if (useParaViewExportedScriptON()) { |
| 252 |
numTimesCatalystCalled++; |
| 253 |
} |
| 254 |
|
| 255 |
if (numTimesCatalystCalled > 1) { |
| 256 |
printErrorMessage("Catalyst called with more than one option."); |
| 257 |
printUsageMessage(); |
| 258 |
exitApplicationFailure(); |
| 259 |
} |
| 260 |
|
| 261 |
if (numTimesCatalystCalled == 1 && (printIOSSRegionReportON() || outputCopyOfInputDatabaseON())) { |
| 262 |
printErrorMessage("Catalyst called with report output."); |
| 263 |
printUsageMessage(); |
| 264 |
exitApplicationFailure(); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
void IossApplication::checkForOnlyOneCatalystOutputType() |
| 269 |
{ |
| 270 |
if (forceCGNSOutputON() && forceExodusOutputON()) { |
| 271 |
printErrorMessage("Both CGNS and Exodus Catalyst output requested."); |
| 272 |
printUsageMessage(); |
| 273 |
exitApplicationFailure(); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
int IossApplication::getNumberOfFileNames() { return fileName.size(); } |
| 278 |
|
| 279 |
std::string &IossApplication::getFileName(int ndx) |
| 280 |
{ |
| 281 |
if (ndx >= fileName.size()) { |
| 282 |
printErrorMessage("getFileName called with ndx too large."); |
| 283 |
printUsageMessage(); |
| 284 |
exitApplicationFailure(); |
| 285 |
} |
| 286 |
return fileName[ndx]; |
| 287 |
} |
| 288 |
|
| 289 |
void IossApplication::addFileName(const std::string &name) { fileName.push_back(name); } |
| 290 |
|
| 291 |
bool IossApplication::printIOSSRegionReportON() { return printIOSSReport; } |
| 292 |
|
| 293 |
void IossApplication::setPrintIOSSRegionReport(bool status) { printIOSSReport = status; } |
| 294 |
|
| 295 |
bool IossApplication::outputCopyOfInputDatabaseON() { return copyDatabase; } |
| 296 |
|
| 297 |
void IossApplication::setOutputCopyOfInputDatabase(bool status) { copyDatabase = status; } |
| 298 |
|
| 299 |
bool IossApplication::outputCatalystMeshOneFileON() { return writeCatalystMeshOneFile; } |
| 300 |
|
| 301 |
void IossApplication::setOutputCatalystMeshOneFile(bool status) |
| 302 |
{ |
| 303 |
writeCatalystMeshOneFile = status; |
| 304 |
} |
| 305 |
|
| 306 |
bool IossApplication::outputCatalystMeshFilePerProcON() { return writeCatalystMeshFilePerProc; } |
| 307 |
|
| 308 |
void IossApplication::setOutputCatalystMeshFilePerProc(bool status) |
| 309 |
{ |
| 310 |
writeCatalystMeshFilePerProc = status; |
| 311 |
} |
| 312 |
|
| 313 |
bool IossApplication::usePhactoriInputScriptON() { return usePhactoriInputScript; } |
| 314 |
|
| 315 |
std::string IossApplication::getPhactoriInputScript() { return phactoriInputScriptFilePath; } |
| 316 |
|
| 317 |
void IossApplication::setPhactoriInputScript(const std::string &scriptFilePath) |
| 318 |
{ |
| 319 |
phactoriInputScriptFilePath = scriptFilePath; |
| 320 |
usePhactoriInputScript = true; |
| 321 |
} |
| 322 |
|
| 323 |
bool IossApplication::usePhactoriInputJSONON() { return usePhactoriInputJSON; } |
| 324 |
|
| 325 |
int IossApplication::getNumberOfPhactoriInputJSONs() { return phctriInptJSONFilePathList.size(); } |
| 326 |
|
| 327 |
std::string IossApplication::getPhactoriInputJSON(int ndx) |
| 328 |
{ |
| 329 |
if (ndx >= phctriInptJSONFilePathList.size()) { |
| 330 |
printErrorMessage("phctriInptJSONFilePathList called with ndx too large."); |
| 331 |
printUsageMessage(); |
| 332 |
exitApplicationFailure(); |
| 333 |
} |
| 334 |
return phctriInptJSONFilePathList[ndx]; |
| 335 |
} |
| 336 |
|
| 337 |
void IossApplication::addPhactoriInputJSON(const std::string &jsonFilePath) |
| 338 |
{ |
| 339 |
phctriInptJSONFilePathList.push_back(jsonFilePath); |
| 340 |
usePhactoriInputJSON = true; |
| 341 |
} |
| 342 |
|
| 343 |
bool IossApplication::useParaViewExportedScriptON() { return useParaViewExportedScript; } |
| 344 |
|
| 345 |
std::string IossApplication::getParaViewExportedScript() { return paraViewExportedScriptFilePath; } |
| 346 |
|
| 347 |
void IossApplication::setParaViewExportedScript(const std::string &exportedScriptFilePath) |
| 348 |
{ |
| 349 |
paraViewExportedScriptFilePath = exportedScriptFilePath; |
| 350 |
useParaViewExportedScript = true; |
| 351 |
} |
| 352 |
|
| 353 |
bool IossApplication::useCatalystStartTimeStepON() { return useCatalystStartTimeStep; } |
| 354 |
|
| 355 |
int IossApplication::getCatalystStartTimeStep() { return catalystStartTimeStep; } |
| 356 |
|
| 357 |
void IossApplication::setCatalystStartTimeStep(int timeStep) |
| 358 |
{ |
| 359 |
catalystStartTimeStep = timeStep; |
| 360 |
useCatalystStartTimeStep = true; |
| 361 |
} |
| 362 |
|
| 363 |
bool IossApplication::useCatalystStopTimeStepON() { return useCatalystStopTimeStep; } |
| 364 |
|
| 365 |
int IossApplication::getCatalystStopTimeStep() { return catalystStopTimeStep; } |
| 366 |
|
| 367 |
void IossApplication::setCatalystStopTimeStep(int timeStep) |
| 368 |
{ |
| 369 |
catalystStopTimeStep = timeStep; |
| 370 |
useCatalystStopTimeStep = true; |
| 371 |
} |
| 372 |
|
| 373 |
bool IossApplication::forceCGNSOutputON() { return forceCGNSOutput; } |
| 374 |
|
| 375 |
void IossApplication::setForceCGNSOutput(bool status) { forceCGNSOutput = status; } |
| 376 |
|
| 377 |
bool IossApplication::forceExodusOutputON() { return forceExodusOutput; } |
| 378 |
|
| 379 |
void IossApplication::setForceExodusOutput(bool status) { forceExodusOutput = status; } |
| 380 |
|
| 381 |
bool IossApplication::useIOSSInputDBTypeON() { return useIOSSInputDBType; } |
| 382 |
|
| 383 |
std::string IossApplication::getIOSSInputDBType() { return iossInputDBType; } |
| 384 |
|
| 385 |
bool IossApplication::sendMultipleGridsToTheSamePipelineON() |
| 386 |
{ |
| 387 |
return sendMultipleGridsToTheSamePipeline; |
| 388 |
} |
| 389 |
|
| 390 |
void IossApplication::setSendMultipleGridsToTheSamePipeline(bool onOffFlag) |
| 391 |
{ |
| 392 |
sendMultipleGridsToTheSamePipeline = onOffFlag; |
| 393 |
} |
| 394 |
|
| 395 |
void IossApplication::setIOSSInputDBType(const std::string &dbType) |
| 396 |
{ |
| 397 |
iossInputDBType = dbType; |
| 398 |
useIOSSInputDBType = true; |
| 399 |
} |
| 400 |
|
| 401 |
void IossApplication::printUsageMessage() |
| 402 |
{ |
| 403 |
std::string um = "\nUSAGE\n\n" + applicationName; |
| 404 |
|
| 405 |
um += " [OPTIONS] [OUTPUT OPTIONS] <FILE>\n\n"; |
| 406 |
|
| 407 |
um += "DESCRIPTION\n\n"; |
| 408 |
um += "Read input file(s) and write to ParaView Catalyst using IOSS"; |
| 409 |
|
| 410 |
um += "\n\nOPTIONS\n\n"; |
| 411 |
|
| 412 |
um += "-a <n> call Catalyst starting at time-step n (starts at 1).\n\n"; |
| 413 |
|
| 414 |
um += "-b <n> call Catalyst stopping at time-step n.\n\n"; |
| 415 |
|
| 416 |
um += "[-d | -e] <db_type> Force IOSS input database type to db_type\n"; |
| 417 |
um += " -d for catalyst_exodus output or -e for catalyst_cgns output\n\n"; |
| 418 |
|
| 419 |
um += "-h print usage message and exit program\n\n"; |
| 420 |
|
| 421 |
um += "OUTPUT OPTIONS\n\n"; |
| 422 |
um += " [-cr | -m | -n | -i <file> | -p <file> | -s <file>]\n\n"; |
| 423 |
|
| 424 |
um += "-c copy input file(s) to one file per processor with output \n"; |
| 425 |
um += " filename(s) prefix " + copyOutputDatabaseName + "\n\n"; |
| 426 |
|
| 427 |
um += "-i <file> run Catalyst with Phactori input JSON given in <file>."; |
| 428 |
um += "\n\n"; |
| 429 |
|
| 430 |
um += "-m output Catalyst mesh representation of input file(s)\n"; |
| 431 |
um += " each time-step to a single file for all processors with output\n"; |
| 432 |
um += " filename " + outputCatalystMeshFileName + "_time_<n>.vtm"; |
| 433 |
um += "\n\n"; |
| 434 |
|
| 435 |
um += "-n output Catalyst mesh representation of input file(s)\n"; |
| 436 |
um += " each time-step to a file for each processor with output\n"; |
| 437 |
um += " filename " + outputCatalystMeshFileName; |
| 438 |
um += "_proc_<p>_time_<n>.vtm\n\n"; |
| 439 |
|
| 440 |
um += "-p <file> run Catalyst with Phactori input command syntax given\n"; |
| 441 |
um += " in <file>\n\n"; |
| 442 |
|
| 443 |
um += "-r print IOSS region report for input file(s) to one file\n"; |
| 444 |
um += " per processor with output filename(s) prefix "; |
| 445 |
um += iossReportFileName + "\n\n"; |
| 446 |
|
| 447 |
um += "-s <file> run Catalyst with a ParaView exported Python script\n"; |
| 448 |
um += " given in <file>"; |
| 449 |
|
| 450 |
um += "\n\nEXAMPLES\n\n"; |
| 451 |
|
| 452 |
um += "mpiexec -np 1 " + applicationName + " -h\n"; |
| 453 |
um += " Print usage message and exit program."; |
| 454 |
um += "\n\n"; |
| 455 |
|
| 456 |
um += "mpiexec -np 4 " + applicationName + " -c -r <FILE>\n"; |
| 457 |
um += " Output copy of input mesh and IOSS region report."; |
| 458 |
um += "\n\n"; |
| 459 |
|
| 460 |
um += "mpiexec -np 4 " + applicationName + " <FILE>\n"; |
| 461 |
um += " Run Catalyst with default Phactori JSON script to produce\n"; |
| 462 |
um += " eight axis aligned external camera images of the input mesh."; |
| 463 |
um += "\n\n"; |
| 464 |
|
| 465 |
um += "mpiexec -np 4 " + applicationName + " -m <FILE>\n"; |
| 466 |
um += " Output mesh representation for Catalyst.\n\n"; |
| 467 |
|
| 468 |
um += "mpiexec -np 4 " + applicationName + " -i file.json <FILE>\n"; |
| 469 |
um += " Run Catalyst with Phactori JSON input from file.json.\n\n"; |
| 470 |
|
| 471 |
um += "mpiexec -np 4 " + applicationName + " -p file.txt <FILE>\n"; |
| 472 |
um += " Run Catalyst with Phactori command syntax input from file.txt."; |
| 473 |
um += "\n\n"; |
| 474 |
|
| 475 |
um += "mpiexec -np 4 " + applicationName + " -s file.py <FILE>\n"; |
| 476 |
um += " Run Catalyst with ParaView exported Python script in file.py."; |
| 477 |
|
| 478 |
um += "\n\nFILE\n\n"; |
| 479 |
um += "Exodus or CGNS input file name for a single file\n\n"; |
| 480 |
um += " (file_name.ex2 or file_name.cgns)\n\n"; |
| 481 |
|
| 482 |
um += "Exodus or CGNS file name prefix for multiple files\n\n"; |
| 483 |
um += " (file_name.cgns for file_name.cgns.2.0, file_name.cgns.2.1)\n"; |
| 484 |
um += " (file_name.ex2 for file_name.ex2.2.0, file_name.ex2.2.1)\n\n"; |
| 485 |
printMessage(um); |
| 486 |
} |
| 487 |
|
| 488 |
void IossApplication::exitApplicationSuccess() |
| 489 |
{ |
| 490 |
applicationExitCode = EXIT_SUCCESS; |
| 491 |
if (hasCommandLineArguments) { |
| 492 |
exitApplication(); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
void IossApplication::exitApplicationFailure() |
| 497 |
{ |
| 498 |
applicationExitCode = EXIT_FAILURE; |
| 499 |
if (hasCommandLineArguments) { |
| 500 |
exitApplication(); |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
void IossApplication::exitApplication() |
| 505 |
{ |
| 506 |
finalizeMPI(); |
| 507 |
std::exit(getApplicationExitCode()); |
| 508 |
} |
| 509 |
|
| 510 |
void IossApplication::printMessage(const std::string &message) |
| 511 |
{ |
| 512 |
if (isRankZero()) { |
| 513 |
std::cout << message; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
void IossApplication::printErrorMessage(const std::string &message) |
| 518 |
{ |
| 519 |
if (isRankZero()) { |
| 520 |
std::cerr << "\nERROR: " << message << "\n"; |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
void IossApplication::printIOSSRegionReportsForRank() |
| 525 |
{ |
| 526 |
std::string fn = iossReportFileName + "." + std::to_string(getNumRanks()) + "." + |
| 527 |
std::to_string(getMyRank()) + ".txt"; |
| 528 |
std::ofstream ofs(fn, std::ofstream::out); |
| 529 |
Ioss::Region *region; |
| 530 |
|
| 531 |
int ii; |
| 532 |
int numRegions = getNumberOfInputIOSSRegions(); |
| 533 |
|
| 534 |
for (ii = 0; ii < numRegions; ii++) { |
| 535 |
region = getInputIOSSRegion(ii); |
| 536 |
|
| 537 |
ofs << "begin region report for region with index " << std::to_string(ii) << "\n"; |
| 538 |
ofs << ioss_region_report::region_report(*region) << "\n"; |
| 539 |
auto state_count = region->get_property("state_count").get_int(); |
| 540 |
for (auto state = 1; state <= state_count; ++state) { |
| 541 |
region->begin_state(state); |
| 542 |
ofs << ioss_region_report::region_report(*region) << "\n"; |
| 543 |
region->end_state(state); |
| 544 |
} |
| 545 |
ofs << "end region report for region with index " << std::to_string(ii) << "\n"; |
| 546 |
} |
| 547 |
|
| 548 |
ofs.close(); |
| 549 |
} |
| 550 |
|
| 551 |
std::string IossApplication::getParallelFileName(int ndx) |
| 552 |
{ |
| 553 |
if (isSerial()) { |
| 554 |
return getFileName(ndx); |
| 555 |
} |
| 556 |
|
| 557 |
std::stringstream nameStream; |
| 558 |
const int numZeroes = std::ceil(log10(double(getNumRanks()))); |
| 559 |
|
| 560 |
nameStream << getFileName(ndx) << "." << getNumRanks() << "." << std::setfill('0') |
| 561 |
<< std::setw(numZeroes) << getMyRank(); |
| 562 |
|
| 563 |
return nameStream.str(); |
| 564 |
} |
| 565 |
|
| 566 |
bool IossApplication::decomposedMeshExists(int ndx) |
| 567 |
{ |
| 568 |
int status = 0; |
| 569 |
|
| 570 |
if (isRankZero()) { |
| 571 |
std::string parallelFilename = getParallelFileName(ndx); |
| 572 |
std::ifstream fstream(parallelFilename); |
| 573 |
if (fstream.good()) { |
| 574 |
status = 1; |
| 575 |
} |
| 576 |
if (fstream.is_open()) { |
| 577 |
fstream.close(); |
| 578 |
} |
| 579 |
} |
| 580 |
Ioss::ParallelUtils pu{}; |
| 581 |
pu.broadcast(status); |
| 582 |
return status == 1; |
| 583 |
} |
| 584 |
|
| 585 |
int IossApplication::getNumberOfInputIOSSRegions() { return inputIOSSRegion.size(); } |
| 586 |
|
| 587 |
Ioss::Region *IossApplication::getInputIOSSRegion(int ndx) |
| 588 |
{ |
| 589 |
if (ndx >= inputIOSSRegion.size()) { |
| 590 |
printErrorMessage("getInputIOSSRegion called with ndx too large."); |
| 591 |
printUsageMessage(); |
| 592 |
} |
| 593 |
return inputIOSSRegion[ndx]; |
| 594 |
} |
| 595 |
|
| 596 |
void IossApplication::openInputIOSSDatabase(int ndx) |
| 597 |
{ |
| 598 |
Ioss::PropertyManager inputProperties; |
| 599 |
if (decomposedMeshExists(ndx)) { |
| 600 |
inputProperties.add(Ioss::Property("DECOMPOSITION_METHOD", "external")); |
| 601 |
} |
| 602 |
else { |
| 603 |
inputProperties.add(Ioss::Property("DECOMPOSITION_METHOD", "rib")); |
| 604 |
} |
| 605 |
|
| 606 |
Ioss::DatabaseIO *dbi = |
| 607 |
Ioss::IOFactory::create(getIOSSDatabaseType(ndx), getFileName(ndx), Ioss::READ_RESTART, |
| 608 |
Ioss::ParallelUtils::comm_world(), inputProperties); |
| 609 |
if (dbi == nullptr || !dbi->ok(true)) { |
| 610 |
printErrorMessage("Unable to open input file(s) " + getFileName(ndx)); |
| 611 |
exitApplicationFailure(); |
| 612 |
} |
| 613 |
inputIOSSRegion.push_back(new Ioss::Region(dbi)); |
| 614 |
} |
| 615 |
|
| 616 |
void IossApplication::openInputIOSSDatabases() |
| 617 |
{ |
| 618 |
int numInputIossDatabases = getNumberOfFileNames(); |
| 619 |
int ii; |
| 620 |
for (ii = 0; ii < numInputIossDatabases; ii++) { |
| 621 |
openInputIOSSDatabase(ii); |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
std::string IossApplication::getPhactoriDefaultJSON() |
| 626 |
{ |
| 627 |
char const *phactoriDefaultJSON = R"pd({ |
| 628 |
"camera blocks":{}, |
| 629 |
"representation blocks": {}, |
| 630 |
"operation blocks": {}, |
| 631 |
"imageset blocks": {}, |
| 632 |
"scatter plot blocks": {}, |
| 633 |
"plot over time blocks": {}, |
| 634 |
"marker blocks": {} |
| 635 |
})pd"; |
| 636 |
return phactoriDefaultJSON; |
| 637 |
} |
| 638 |
|
| 639 |
void IossApplication::copyInputIOSSDatabaseOnRank() |
| 640 |
{ |
| 641 |
std::string fn = copyOutputDatabaseName + "." + getFileSuffix(0); |
| 642 |
Ioss::PropertyManager outputProperties; |
| 643 |
outputProperties.add(Ioss::Property("COMPOSE_RESULTS", "NO")); |
| 644 |
Ioss::DatabaseIO *dbo = |
| 645 |
Ioss::IOFactory::create(getIOSSDatabaseType(0), fn, Ioss::WRITE_RESULTS, |
| 646 |
Ioss::ParallelUtils::comm_world(), outputProperties); |
| 647 |
if (dbo == nullptr || !dbo->ok(true)) { |
| 648 |
printErrorMessage("Unable to open output file(s) " + fn); |
| 649 |
exitApplicationFailure(); |
| 650 |
} |
| 651 |
|
| 652 |
Ioss::Region *inputRegion = getInputIOSSRegion(0); |
| 653 |
Ioss::Region *outputRegion = new Ioss::Region(dbo, inputRegion->name()); |
| 654 |
|
| 655 |
auto state_count = inputRegion->get_property("state_count").get_int(); |
| 656 |
double min_time = inputRegion->get_state_time(1); |
| 657 |
double max_time = inputRegion->get_state_time(state_count); |
| 658 |
Ioss::MeshCopyOptions copyOptions; |
| 659 |
copyOptions.data_storage_type = 1; |
| 660 |
copyOptions.minimum_time = min_time; |
| 661 |
copyOptions.maximum_time = max_time; |
| 662 |
Ioss::copy_database(*inputRegion, *outputRegion, copyOptions); |
| 663 |
|
| 664 |
delete outputRegion; |
| 665 |
} |
| 666 |
|
| 667 |
void IossApplication::callCatalystIOSSDatabaseOnRank() |
| 668 |
{ |
| 669 |
if (getNumberOfInputIOSSRegions() < 2) { |
| 670 |
callCatalystIOSSDatabaseOnRankOneGrid(); |
| 671 |
} |
| 672 |
else { |
| 673 |
if (this->sendMultipleGridsToTheSamePipelineON()) { |
| 674 |
callCatalystIOSSDatabaseOnRankMultiGrid(true); |
| 675 |
} |
| 676 |
else { |
| 677 |
callCatalystIOSSDatabaseOnRankMultiGrid(false); |
| 678 |
} |
| 679 |
} |
| 680 |
} |
| 681 |
|
| 682 |
const char *gGridInputNames[5] = {"input", "inputB", "inputC", "inputD", "inputE"}; |
| 683 |
|
| 684 |
void IossApplication::callCatalystIOSSDatabaseOnRankMultiGrid(bool sendAllGridsToOnePipeline) |
| 685 |
{ |
| 686 |
// create all the ioss database instances |
| 687 |
// create the output region for each grid (one on each database) |
| 688 |
// for each timestep |
| 689 |
// call copy_database for each timestep for each database |
| 690 |
|
| 691 |
// assuming we can't share the property manager for now |
| 692 |
int numInputRegions = getNumberOfInputIOSSRegions(); |
| 693 |
std::vector<Ioss::PropertyManager *> outputProps; |
| 694 |
std::vector<Ioss::DatabaseIO *> outputDbs; |
| 695 |
std::vector<Ioss::Region *> outputRegions; |
| 696 |
int ii; |
| 697 |
|
| 698 |
printMessage("IossApplication::callCatalystIOSSDatabaseOnRankMultiGrid entered\n"); |
| 699 |
std::cerr << "IossApplication::callCatalystIOSSDatabaseOnRankMultiGrid entered2\n"; |
| 700 |
// create a Ioss::DatabaseIO instance for each grid |
| 701 |
char mytmpnm[256]; |
| 702 |
int imyRandomInt = myuni9(rng); |
| 703 |
snprintf(mytmpnm, 256, "catalyst_%d", imyRandomInt); |
| 704 |
|
| 705 |
for (ii = 0; ii < numInputRegions; ii++) { |
| 706 |
Ioss::PropertyManager *newProps = new (Ioss::PropertyManager); |
| 707 |
SetUpDefaultProperties(newProps); |
| 708 |
if (sendAllGridsToOnePipeline) { |
| 709 |
newProps->add(Ioss::Property("CATALYST_MULTI_INPUT_PIPELINE_NAME", "multipipe1")); |
| 710 |
} |
| 711 |
newProps->add(Ioss::Property("CATALYST_INPUT_NAME", gGridInputNames[ii % 5])); |
| 712 |
if (getNumberOfPhactoriInputJSONs() > 1) { |
| 713 |
printMessage("getNumberOfPhactoriInputJSONs() > 1\n"); |
| 714 |
printMessage(getPhactoriInputJSON(ii) + "\n"); |
| 715 |
newProps->add(Ioss::Property("PHACTORI_JSON_SCRIPT", getPhactoriInputJSON(ii))); |
| 716 |
} |
| 717 |
outputProps.push_back(newProps); |
| 718 |
Ioss::DatabaseIO *newDbo = |
| 719 |
Ioss::IOFactory::create(getCatalystDatabaseType(ii), mytmpnm, Ioss::WRITE_RESULTS, |
| 720 |
Ioss::ParallelUtils::comm_world(), *newProps); |
| 721 |
outputDbs.push_back(newDbo); |
| 722 |
} |
| 723 |
// create an output Ioss::Region instance for each grid |
| 724 |
for (ii = 0; ii < numInputRegions; ii++) { |
| 725 |
Ioss::Region *inputRegion = getInputIOSSRegion(ii); |
| 726 |
Ioss::Region *outputRegion = new Ioss::Region(outputDbs[ii], inputRegion->name()); |
| 727 |
outputRegions.push_back(outputRegion); |
| 728 |
} |
| 729 |
|
| 730 |
// use the minimum number of steps from all regions as the overall number of steps |
| 731 |
auto state_count = getInputIOSSRegion(0)->get_property("state_count").get_int(); |
| 732 |
for (ii = 1; ii < numInputRegions; ii++) { |
| 733 |
int oneRegionNumStates = getInputIOSSRegion(ii)->get_property("state_count").get_int(); |
| 734 |
if (oneRegionNumStates < state_count) { |
| 735 |
state_count = oneRegionNumStates; |
| 736 |
} |
| 737 |
} |
| 738 |
int startTimeStep; |
| 739 |
int stopTimeStep; |
| 740 |
getStartStopTimeSteps(state_count, startTimeStep, stopTimeStep); |
| 741 |
|
| 742 |
// right now, copy_database can't be called repeatedly with different |
| 743 |
// timesteps because it tries to create the Node block (and other stuff) |
| 744 |
// each time. So we are only doing one timestep for testing at this point. |
| 745 |
// startTimeStep = stopTimeStep; |
| 746 |
|
| 747 |
// for each timestep, call copy_database (one timestep) for each output |
| 748 |
// database |
| 749 |
int currentTimeStep; |
| 750 |
for (currentTimeStep = startTimeStep; currentTimeStep <= stopTimeStep; currentTimeStep++) { |
| 751 |
for (ii = 0; ii < numInputRegions; ii++) { |
| 752 |
Ioss::Region *inputRegion = getInputIOSSRegion(ii); |
| 753 |
Ioss::Region *outputRegion = outputRegions[ii]; |
| 754 |
int thisRegionCurrentTimeStep = currentTimeStep; |
| 755 |
int thisRegionStateCount = getInputIOSSRegion(ii)->get_property("state_count").get_int(); |
| 756 |
if (thisRegionCurrentTimeStep > thisRegionStateCount) { |
| 757 |
thisRegionCurrentTimeStep = thisRegionStateCount; |
| 758 |
} |
| 759 |
double min_time = inputRegion->get_state_time(thisRegionCurrentTimeStep); |
| 760 |
double max_time = inputRegion->get_state_time(thisRegionCurrentTimeStep); |
| 761 |
|
| 762 |
Ioss::MeshCopyOptions copyOptions; |
| 763 |
copyOptions.data_storage_type = 1; |
| 764 |
copyOptions.minimum_time = min_time; |
| 765 |
copyOptions.maximum_time = max_time; |
| 766 |
// Ioss::copy_database(*inputRegion, *outputRegion, copyOptions); |
| 767 |
bool defineFlag; |
| 768 |
if (currentTimeStep == startTimeStep) { |
| 769 |
defineFlag = true; |
| 770 |
} |
| 771 |
else { |
| 772 |
defineFlag = false; |
| 773 |
} |
| 774 |
printf("region, ts1, ts2, time: %d, %d, %d, %f\n", ii, currentTimeStep, |
| 775 |
thisRegionCurrentTimeStep, (float)max_time); |
| 776 |
printf("defineFlag: %d\n", (int)defineFlag); |
| 777 |
copyOptions.define_geometry = defineFlag; |
| 778 |
Ioss::copy_database(*inputRegion, *outputRegion, copyOptions); |
| 779 |
} |
| 780 |
} |
| 781 |
for (ii = 0; ii < numInputRegions; ii++) { |
| 782 |
Ioss::Region *outputRegion = outputRegions[ii]; |
| 783 |
delete outputRegion; |
| 784 |
} |
| 785 |
} |
| 786 |
|
| 787 |
void IossApplication::SetUpDefaultProperties(Ioss::PropertyManager *outputProperties) |
| 788 |
{ |
| 789 |
if (usePhactoriInputScriptON()) { |
| 790 |
outputProperties->add(Ioss::Property("PHACTORI_INPUT_SYNTAX_SCRIPT", getPhactoriInputScript())); |
| 791 |
} |
| 792 |
else if (usePhactoriInputJSONON()) { |
| 793 |
printMessage("SetUpDefaultProperties, usePhactoriInputJSONON true\n"); |
| 794 |
if (getNumberOfPhactoriInputJSONs() == 1) { |
| 795 |
printMessage("1 entry: " + getPhactoriInputJSON(0) + "\n"); |
| 796 |
outputProperties->add(Ioss::Property("PHACTORI_JSON_SCRIPT", getPhactoriInputJSON(0))); |
| 797 |
} |
| 798 |
} |
| 799 |
else if (useParaViewExportedScriptON()) { |
| 800 |
outputProperties->add(Ioss::Property("CATALYST_SCRIPT", getParaViewExportedScript())); |
| 801 |
} |
| 802 |
else if (outputCatalystMeshOneFileON()) { |
| 803 |
outputProperties->add( |
| 804 |
Ioss::Property("WRITE_CATALYST_MESH_ONE_FILE_WITH_PREFIX", outputCatalystMeshFileName)); |
| 805 |
} |
| 806 |
else if (outputCatalystMeshFilePerProcON()) { |
| 807 |
outputProperties->add(Ioss::Property("WRITE_CATALYST_MESH_FILE_PER_PROC_WITH_PREFIX", |
| 808 |
outputCatalystMeshFileName)); |
| 809 |
} |
| 810 |
else { |
| 811 |
outputProperties->add( |
| 812 |
Ioss::Property("CATALYST_BLOCK_PARSE_JSON_STRING", getPhactoriDefaultJSON())); |
| 813 |
} |
| 814 |
|
| 815 |
outputProperties->add(Ioss::Property("CATALYST_BLOCK_PARSE_INPUT_DECK_NAME", applicationName)); |
| 816 |
addAdditionalProperties(outputProperties); |
| 817 |
} |
| 818 |
|
| 819 |
void IossApplication::callCatalystIOSSDatabaseOnRankOneGrid() |
| 820 |
{ |
| 821 |
Ioss::PropertyManager outputProperties; |
| 822 |
|
| 823 |
SetUpDefaultProperties(&outputProperties); |
| 824 |
|
| 825 |
Ioss::DatabaseIO *dbo = |
| 826 |
Ioss::IOFactory::create(getCatalystDatabaseType(0), "catalyst", Ioss::WRITE_RESULTS, |
| 827 |
Ioss::ParallelUtils::comm_world(), outputProperties); |
| 828 |
if (dbo == nullptr || !dbo->ok(true)) { |
| 829 |
printErrorMessage("Unable to open catalyst database"); |
| 830 |
exitApplicationFailure(); |
| 831 |
} |
| 832 |
|
| 833 |
Ioss::Region *inputRegion = getInputIOSSRegion(0); |
| 834 |
Ioss::Region *outputRegion = new Ioss::Region(dbo, inputRegion->name()); |
| 835 |
|
| 836 |
auto state_count = inputRegion->get_property("state_count").get_int(); |
| 837 |
|
| 838 |
int startTimeStep; |
| 839 |
int stopTimeStep; |
| 840 |
getStartStopTimeSteps(state_count, startTimeStep, stopTimeStep); |
| 841 |
|
| 842 |
double min_time = inputRegion->get_state_time(startTimeStep); |
| 843 |
double max_time = inputRegion->get_state_time(stopTimeStep); |
| 844 |
|
| 845 |
Ioss::MeshCopyOptions copyOptions; |
| 846 |
copyOptions.data_storage_type = 1; |
| 847 |
copyOptions.minimum_time = min_time; |
| 848 |
copyOptions.maximum_time = max_time; |
| 849 |
Ioss::copy_database(*inputRegion, *outputRegion, copyOptions); |
| 850 |
|
| 851 |
delete outputRegion; |
| 852 |
} |
| 853 |
|
| 854 |
std::string IossApplication::getIOSSDatabaseType(int ndx) |
| 855 |
{ |
| 856 |
std::string retVal = getIOSSDatabaseTypeFromFile(ndx); |
| 857 |
if (useIOSSInputDBTypeON()) { |
| 858 |
retVal = getIOSSInputDBType(); |
| 859 |
} |
| 860 |
return retVal; |
| 861 |
} |
| 862 |
|
| 863 |
std::string IossApplication::getIOSSDatabaseTypeFromFile(int ndx) |
| 864 |
{ |
| 865 |
if (ndx >= fileName.size()) { |
| 866 |
printErrorMessage("getIOSSDatabaseTypeFromFile called with ndx too large."); |
| 867 |
printUsageMessage(); |
| 868 |
exitApplicationFailure(); |
| 869 |
} |
| 870 |
Ioss::FileInfo file(fileName[ndx]); |
| 871 |
auto extension = file.extension(); |
| 872 |
if (extension == "e" || extension == "g" || extension == "gen" || extension == "exo") { |
| 873 |
return "exodus"; |
| 874 |
} |
| 875 |
else if (extension == "cgns") { |
| 876 |
return "cgns"; |
| 877 |
} |
| 878 |
else { |
| 879 |
return "exodus"; |
| 880 |
} |
| 881 |
} |
| 882 |
|
| 883 |
std::string IossApplication::getFileSuffix(int ndx) |
| 884 |
{ |
| 885 |
std::string dbType = getIOSSDatabaseType(ndx); |
| 886 |
if (dbType == "exodus") { |
| 887 |
return "ex2"; |
| 888 |
} |
| 889 |
else if (dbType == "cgns") { |
| 890 |
return "cgns"; |
| 891 |
} |
| 892 |
else { |
| 893 |
return dbType; |
| 894 |
} |
| 895 |
} |
| 896 |
|
| 897 |
std::string IossApplication::getCatalystDatabaseType(int ndx) |
| 898 |
{ |
| 899 |
std::string retVal = "catalyst_exodus"; |
| 900 |
if (!forceExodusOutputON()) { |
| 901 |
if (getIOSSDatabaseType(ndx) == "cgns") { |
| 902 |
retVal = "catalyst_cgns"; |
| 903 |
} |
| 904 |
if (forceCGNSOutputON()) { |
| 905 |
retVal = "catalyst_cgns"; |
| 906 |
} |
| 907 |
} |
| 908 |
return retVal; |
| 909 |
} |
| 910 |
|
| 911 |
void IossApplication::setAdditionalProperties(Ioss::PropertyManager *additionalProperties) |
| 912 |
{ |
| 913 |
this->additionalProperties = additionalProperties; |
| 914 |
} |
| 915 |
|
| 916 |
Ioss::PropertyManager *IossApplication::getAdditionalProperties() { return additionalProperties; } |
| 917 |
|
| 918 |
void IossApplication::addAdditionalProperties(Ioss::PropertyManager *outputProperties) |
| 919 |
{ |
| 920 |
if (additionalProperties) { |
| 921 |
|
| 922 |
Ioss::NameList nlist; |
| 923 |
additionalProperties->describe(&nlist); |
| 924 |
for (auto &name : nlist) { |
| 925 |
outputProperties->add(additionalProperties->get(name)); |
| 926 |
} |
| 927 |
} |
| 928 |
} |