| 1 |
// Copyright(C) 1999-2021 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 "CatalystManager.h" |
| 8 |
#include "../cgns/CatalystCGNSMesh.h" |
| 9 |
#include "../exodus/CatalystExodusMesh.h" |
| 10 |
#include "CatalystMeshWriter.h" |
| 11 |
#include "CatalystPythonPaths.h" |
| 12 |
#include "PhactoriParserInterface.h" |
| 13 |
#include "vtkCPInputDataDescription.h" |
| 14 |
#include "vtkCPProcessor.h" |
| 15 |
#include "vtkCPPythonPipeline.h" |
| 16 |
#include "vtkDataObject.h" |
| 17 |
#include "vtkDoubleArray.h" |
| 18 |
#include "vtkFieldData.h" |
| 19 |
#include "vtkIntArray.h" |
| 20 |
#include "vtkMPIController.h" |
| 21 |
#include "vtkMultiProcessController.h" |
| 22 |
#include "vtkProcessModule.h" |
| 23 |
#include "vtkPython.h" |
| 24 |
#include "vtkStringArray.h" |
| 25 |
#include "vtkPartitionedDataSetCollection.h" |
| 26 |
#include <fstream> |
| 27 |
#include <sstream> |
| 28 |
#include <vtksys/SystemInformation.hxx> |
| 29 |
|
| 30 |
namespace Iovs { |
| 31 |
|
| 32 |
CatalystManager::CatalystManager() |
| 33 |
{ |
| 34 |
coProcessor = nullptr; |
| 35 |
catalystOutputIDNumber = 0; |
| 36 |
catalystOutputReferenceCount = 0; |
| 37 |
#ifdef USE_PYTHON_C_API |
| 38 |
initCatalystPythonSystemPaths(); |
| 39 |
#endif |
| 40 |
} |
| 41 |
|
| 42 |
CatalystManager::~CatalystManager() {} |
| 43 |
|
| 44 |
void CatalystManager::initCatalystPythonSystemPaths() |
| 45 |
{ |
| 46 |
Py_Initialize(); |
| 47 |
|
| 48 |
PyObject *sys = PyImport_ImportModule("sys"); |
| 49 |
PyObject *path = PyObject_GetAttrString(sys, "path"); |
| 50 |
|
| 51 |
PyList_Insert(path, 0, PyUnicode_FromString(CATALYST_PYTHON_PARAVIEW_ZIP)); |
| 52 |
PyList_Insert(path, 0, PyUnicode_FromString(CATALYST_PYTHON_VTK_ZIP)); |
| 53 |
|
| 54 |
Py_DECREF(sys); |
| 55 |
Py_DECREF(path); |
| 56 |
} |
| 57 |
|
| 58 |
std::string CatalystManager::getCatalystPluginVersion() { return catalystPluginVersion; } |
| 59 |
|
| 60 |
int CatalystManager::getCatalystOutputIDNumber() { return catalystOutputIDNumber; } |
| 61 |
|
| 62 |
void CatalystManager::initializeIfNeeded() |
| 63 |
{ |
| 64 |
if (!canCoProcess()) { |
| 65 |
coProcessor = vtkCPProcessor::New(); |
| 66 |
coProcessor->Initialize(); |
| 67 |
catalystOutputReferenceCount = 0; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
void CatalystManager::finalizeIfNeeded() |
| 72 |
{ |
| 73 |
if (canCoProcess()) { |
| 74 |
coProcessor->Delete(); |
| 75 |
coProcessor = nullptr; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
bool CatalystManager::canCoProcess() { return coProcessor != nullptr; } |
| 80 |
|
| 81 |
void CatalystManager::incrementOutputCounts() |
| 82 |
{ |
| 83 |
catalystOutputIDNumber++; |
| 84 |
catalystOutputReferenceCount++; |
| 85 |
} |
| 86 |
|
| 87 |
std::unique_ptr<Iovs_exodus::CatalystExodusMeshBase> |
| 88 |
CatalystManager::createCatalystExodusMesh(CatalystExodusMeshInit &cmInit) |
| 89 |
{ |
| 90 |
|
| 91 |
initializeIfNeeded(); |
| 92 |
CatalystPipelineInfo cpi = createCatalystPipelineInfo(cmInit); |
| 93 |
|
| 94 |
Iovs_exodus::CatalystExodusMesh *cem = new Iovs_exodus::CatalystExodusMesh(this, cpi); |
| 95 |
cem->SetUnderscoreVectors(cmInit.underScoreVectors); |
| 96 |
cem->SetApplyDisplacements(cmInit.applyDisplacements); |
| 97 |
|
| 98 |
registerMeshInPipeline(cmInit, cem->getPartitionedDataSetCollection(), cpi); |
| 99 |
|
| 100 |
return std::unique_ptr<Iovs_exodus::CatalystExodusMeshBase>( |
| 101 |
dynamic_cast<Iovs_exodus::CatalystExodusMeshBase *>(cem)); |
| 102 |
} |
| 103 |
|
| 104 |
std::unique_ptr<Iovs_cgns::CatalystCGNSMeshBase> |
| 105 |
CatalystManager::createCatalystCGNSMesh(CatalystMeshInit &cmInit) |
| 106 |
{ |
| 107 |
|
| 108 |
initializeIfNeeded(); |
| 109 |
CatalystPipelineInfo cpi = createCatalystPipelineInfo(cmInit); |
| 110 |
|
| 111 |
Iovs_cgns::CatalystCGNSMesh *cgm = new Iovs_cgns::CatalystCGNSMesh(this, cpi); |
| 112 |
|
| 113 |
registerMeshInPipeline(cmInit, cgm->getPartitionedDataSetCollection(), cpi); |
| 114 |
|
| 115 |
return std::unique_ptr<Iovs_cgns::CatalystCGNSMeshBase>( |
| 116 |
dynamic_cast<Iovs_cgns::CatalystCGNSMeshBase *>(cgm)); |
| 117 |
} |
| 118 |
|
| 119 |
CatalystManager::CatalystPipelineInfo |
| 120 |
CatalystManager::createCatalystPipelineInfo(CatalystMeshInit &cmInit) |
| 121 |
{ |
| 122 |
|
| 123 |
CatalystPipelineInfo cpi; |
| 124 |
cpi.catalystPipelineID = getCatalystPipelineID(cmInit); |
| 125 |
cpi.catalystInputName = cmInit.catalystInputName; |
| 126 |
return cpi; |
| 127 |
} |
| 128 |
|
| 129 |
CatalystManager::CatalystPipelineID |
| 130 |
CatalystManager::getCatalystPipelineID(CatalystMeshInit &cmInit) |
| 131 |
{ |
| 132 |
|
| 133 |
CatalystManager::CatalystPipelineID id = catalystOutputIDNumber; |
| 134 |
bool doIncrementOutputCounts = true; |
| 135 |
|
| 136 |
if (cmInit.enableCatalystMultiInputPipeline) { |
| 137 |
std::string pn = cmInit.catalystMultiInputPipelineName; |
| 138 |
if (multiInputPipelines.find(pn) == multiInputPipelines.end()) { |
| 139 |
multiInputPipelines[pn] = catalystOutputIDNumber; |
| 140 |
} |
| 141 |
else { |
| 142 |
doIncrementOutputCounts = false; |
| 143 |
} |
| 144 |
id = multiInputPipelines[pn]; |
| 145 |
} |
| 146 |
|
| 147 |
if (doIncrementOutputCounts) { |
| 148 |
incrementOutputCounts(); |
| 149 |
} |
| 150 |
return id; |
| 151 |
} |
| 152 |
|
| 153 |
void CatalystManager::registerMeshInPipeline(CatalystMeshInit &cmInit, vtkDataObject *vobj, |
| 154 |
const CatalystPipelineInfo &cpi) |
| 155 |
{ |
| 156 |
|
| 157 |
if (pipelines.find(cpi.catalystPipelineID) == pipelines.end()) { |
| 158 |
initCatalystPipeline(cmInit, vobj, cpi); |
| 159 |
if (cmInit.enableLogging) { |
| 160 |
initCatalystLogging(cpi); |
| 161 |
} |
| 162 |
} |
| 163 |
else { |
| 164 |
addInputToPipeline(vobj, cpi); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
void CatalystManager::initCatalystLogging(const CatalystPipelineInfo &cpi) |
| 169 |
{ |
| 170 |
|
| 171 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 172 |
std::string logFileName = cpi.getLogFileName(); |
| 173 |
|
| 174 |
TimerPair tp = std::make_pair(clock(), clock()); |
| 175 |
vtkDoubleArray *da = vtkDoubleArray::New(); |
| 176 |
da->SetNumberOfComponents(3); |
| 177 |
LoggingPair lp = std::make_pair(tp, da); |
| 178 |
this->logging[id] = lp; |
| 179 |
|
| 180 |
vtkProcessModule *pm = vtkProcessModule::GetProcessModule(); |
| 181 |
vtkMPIController *mpic = vtkMPIController::SafeDownCast(pm->GetGlobalController()); |
| 182 |
if (mpic && mpic->GetNumberOfProcesses() > 1) { |
| 183 |
if (mpic->GetLocalProcessId() == 0) { |
| 184 |
std::ofstream logfile; |
| 185 |
logfile.open(logFileName, ios::out | ios::trunc); |
| 186 |
logfile << "# ELAPSED TIME (S)" |
| 187 |
<< ",PROC MEM USED - MIN (KiB)" |
| 188 |
<< ",PROC MEM USED - MAX (KiB)" |
| 189 |
<< ",PROC MEM USED - AVG (KiB)" |
| 190 |
<< ",HOST MEM USED - MIN (KiB)" |
| 191 |
<< ",HOST MEM USED - MAX (KiB)" |
| 192 |
<< ",HOST MEM USED - AVG (KiB)" |
| 193 |
<< ",TIME SINCE LAST LOG - MIN (S)" |
| 194 |
<< ",TIME SINCE LAST LOG - MAX (S)" |
| 195 |
<< ",TIME SINCE LAST LOG - AVG (S)" |
| 196 |
<< "\n"; |
| 197 |
logfile.close(); |
| 198 |
} |
| 199 |
} |
| 200 |
else { |
| 201 |
std::ofstream logfile; |
| 202 |
logfile.open(logFileName, ios::out | ios::trunc); |
| 203 |
logfile << "# ELAPSED TIME (S)" |
| 204 |
<< ",PROC MEM USED (KiB)" |
| 205 |
<< ",HOST MEM USED (KiB)" |
| 206 |
<< ",TIME SINCE LAST LOG (S)" |
| 207 |
<< "\n"; |
| 208 |
logfile.close(); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
void CatalystManager::initCatalystPipeline(CatalystMeshInit &cmInit, vtkDataObject *vobj, |
| 213 |
const CatalystPipelineInfo &cpi) |
| 214 |
{ |
| 215 |
|
| 216 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 217 |
|
| 218 |
pipelines[id].getPipeline() = |
| 219 |
vtkCPPythonPipeline::CreateAndInitializePipeline(cmInit.catalystPythonFilename.c_str()); |
| 220 |
if (pipelines[id].getPipeline() == nullptr) { |
| 221 |
std::cerr << "Unable to initialize ParaView Catalyst with python script " |
| 222 |
<< cmInit.catalystPythonFilename << std::endl; |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
pipelines[id].getDataDescription() = vtkSmartPointer<vtkCPDataDescription>::New(); |
| 227 |
pipelines[id].getDataDescription()->AddInput(cpi.catalystInputName.c_str()); |
| 228 |
pipelines[id] |
| 229 |
.getDataDescription() |
| 230 |
->GetInputDescriptionByName(cpi.catalystInputName.c_str()) |
| 231 |
->SetGrid(vobj); |
| 232 |
|
| 233 |
pipelines[id].getMeshWriter() = std::make_shared<CatalystMeshWriter>(); |
| 234 |
if (cmInit.writeCatalystMeshOneFile) { |
| 235 |
pipelines[id].getMeshWriter()->setOutputCatalystMeshOneFilePrefix( |
| 236 |
cmInit.catalystMeshOneFilePrefix); |
| 237 |
} |
| 238 |
if (cmInit.writeCatalystMeshFilePerProc) { |
| 239 |
pipelines[id].getMeshWriter()->setOutputCatalystMeshFilePerProcPrefix( |
| 240 |
cmInit.catalystMeshFilePerProcPrefix); |
| 241 |
} |
| 242 |
|
| 243 |
vtkFieldData *fd = vtkFieldData::New(); |
| 244 |
vtkStringArray *sa = vtkStringArray::New(); |
| 245 |
sa->SetName("catalyst_sierra_data"); |
| 246 |
vtkIntArray *ec = vtkIntArray::New(); |
| 247 |
ec->SetName("catalyst_sierra_error_codes"); |
| 248 |
vtkStringArray *em = vtkStringArray::New(); |
| 249 |
em->SetName("catalyst_sierra_error_messages"); |
| 250 |
sa->InsertNextValue(cmInit.catalystBlockJSON); |
| 251 |
sa->InsertNextValue(cmInit.catalystSeparatorCharacter); |
| 252 |
sa->InsertNextValue(cmInit.catalystInputDeckName); |
| 253 |
sa->InsertNextValue(cmInit.restartTag); |
| 254 |
if (cmInit.enableLogging) { |
| 255 |
sa->InsertNextValue("True"); |
| 256 |
} |
| 257 |
else { |
| 258 |
sa->InsertNextValue(""); |
| 259 |
} |
| 260 |
std::stringstream ss; |
| 261 |
ss << cmInit.debugLevel; |
| 262 |
sa->InsertNextValue(ss.str().c_str()); |
| 263 |
ss.clear(); |
| 264 |
sa->InsertNextValue(cmInit.resultsOutputFilename); |
| 265 |
sa->InsertNextValue(cmInit.catalystOutputDirectory); |
| 266 |
|
| 267 |
for (int i = 0; i < cmInit.catalystData.size(); i++) { |
| 268 |
sa->InsertNextValue(cmInit.catalystData[i]); |
| 269 |
} |
| 270 |
|
| 271 |
fd->AddArray(sa); |
| 272 |
fd->AddArray(ec); |
| 273 |
fd->AddArray(em); |
| 274 |
pipelines[id].getDataDescription()->SetUserData(fd); |
| 275 |
|
| 276 |
fd->Delete(); |
| 277 |
sa->Delete(); |
| 278 |
ec->Delete(); |
| 279 |
em->Delete(); |
| 280 |
} |
| 281 |
|
| 282 |
void CatalystManager::addInputToPipeline(vtkDataObject *vobj, const CatalystPipelineInfo &cpi) |
| 283 |
{ |
| 284 |
|
| 285 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 286 |
|
| 287 |
pipelines[id].getDataDescription()->AddInput(cpi.catalystInputName.c_str()); |
| 288 |
pipelines[id] |
| 289 |
.getDataDescription() |
| 290 |
->GetInputDescriptionByName(cpi.catalystInputName.c_str()) |
| 291 |
->SetGrid(vobj); |
| 292 |
} |
| 293 |
|
| 294 |
void CatalystManager::DeletePipeline(const CatalystPipelineInfo &cpi) |
| 295 |
{ |
| 296 |
|
| 297 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 298 |
|
| 299 |
if (pipelines.find(id) != pipelines.end()) { |
| 300 |
if (!pipelines[id].canDeletePipeline()) { |
| 301 |
return; |
| 302 |
} |
| 303 |
pipelines.erase(id); |
| 304 |
} |
| 305 |
|
| 306 |
if (logging.find(id) != logging.end()) { |
| 307 |
logging[id].second->Delete(); |
| 308 |
logging.erase(id); |
| 309 |
} |
| 310 |
|
| 311 |
catalystOutputReferenceCount--; |
| 312 |
finalizeIfNeeded(); |
| 313 |
} |
| 314 |
|
| 315 |
void CatalystManager::PerformCoProcessing(std::vector<int> &error_and_warning_codes, |
| 316 |
std::vector<std::string> &error_and_warning_messages, |
| 317 |
const CatalystPipelineInfo &cpi) |
| 318 |
{ |
| 319 |
|
| 320 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 321 |
|
| 322 |
if (pipelines.find(id) != pipelines.end()) { |
| 323 |
|
| 324 |
if (writeMeshON(cpi)) { |
| 325 |
writeMesh(cpi); |
| 326 |
return; |
| 327 |
} |
| 328 |
|
| 329 |
if (!canCoProcess()) { |
| 330 |
return; |
| 331 |
} |
| 332 |
|
| 333 |
error_and_warning_codes.clear(); |
| 334 |
error_and_warning_messages.clear(); |
| 335 |
|
| 336 |
if (!pipelines[id].canPerformCoProcessing()) { |
| 337 |
return; |
| 338 |
} |
| 339 |
|
| 340 |
vtkCPPythonPipeline *pl = pipelines[id].getPipeline(); |
| 341 |
vtkCPDataDescription *dataDescription = pipelines[id].getDataDescription(); |
| 342 |
coProcessor->AddPipeline(pl); |
| 343 |
coProcessor->CoProcess(dataDescription); |
| 344 |
|
| 345 |
vtkFieldData *fd = pipelines[id].getDataDescription()->GetUserData(); |
| 346 |
vtkIntArray *ec = |
| 347 |
vtkIntArray::SafeDownCast(fd->GetAbstractArray("catalyst_sierra_error_codes")); |
| 348 |
vtkStringArray *em = |
| 349 |
vtkStringArray::SafeDownCast(fd->GetAbstractArray("catalyst_sierra_error_messages")); |
| 350 |
|
| 351 |
if (ec && em && ec->GetNumberOfTuples() > 0 && em->GetNumberOfTuples() > 0 && |
| 352 |
ec->GetNumberOfTuples() == em->GetNumberOfTuples()) { |
| 353 |
|
| 354 |
for (int i = 0; i < ec->GetNumberOfTuples(); i++) { |
| 355 |
error_and_warning_codes.push_back(ec->GetValue(i)); |
| 356 |
error_and_warning_messages.push_back(em->GetValue(i)); |
| 357 |
} |
| 358 |
fd->RemoveArray("catalyst_sierra_error_codes"); |
| 359 |
fd->RemoveArray("catalyst_sierra_error_messages"); |
| 360 |
vtkIntArray *ec = vtkIntArray::New(); |
| 361 |
ec->SetName("catalyst_sierra_error_codes"); |
| 362 |
vtkStringArray *em = vtkStringArray::New(); |
| 363 |
em->SetName("catalyst_sierra_error_messages"); |
| 364 |
fd->AddArray(ec); |
| 365 |
fd->AddArray(em); |
| 366 |
ec->Delete(); |
| 367 |
em->Delete(); |
| 368 |
} |
| 369 |
coProcessor->RemoveAllPipelines(); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
void CatalystManager::SetTimeData(double currentTime, int timeStep, |
| 374 |
const CatalystPipelineInfo &cpi) |
| 375 |
{ |
| 376 |
|
| 377 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 378 |
|
| 379 |
if (pipelines.find(id) != pipelines.end()) { |
| 380 |
if (!pipelines[id].canSetTimeData()) { |
| 381 |
return; |
| 382 |
} |
| 383 |
pipelines[id].getDataDescription()->SetTimeData(currentTime, timeStep); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
void CatalystManager::logMemoryUsageAndTakeTimerReading(const CatalystPipelineInfo &cpi) |
| 388 |
{ |
| 389 |
|
| 390 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 391 |
|
| 392 |
if (this->logging.find(id) != this->logging.end()) { |
| 393 |
vtksys::SystemInformation sysInfo; |
| 394 |
vtkProcessModule *pm = vtkProcessModule::GetProcessModule(); |
| 395 |
vtkMPIController *mpic = vtkMPIController::SafeDownCast(pm->GetGlobalController()); |
| 396 |
double measurements[3]; |
| 397 |
measurements[0] = sysInfo.GetProcMemoryUsed() * (1.0 / 1024.0); // Store in MB |
| 398 |
measurements[1] = sysInfo.GetHostMemoryUsed() * (1.0 / 1024.0); |
| 399 |
clock_t last_time = this->logging[id].first.second; |
| 400 |
measurements[2] = double(clock() - last_time) / (double)CLOCKS_PER_SEC; |
| 401 |
this->logging[id].first.second = clock(); |
| 402 |
this->logging[id].second->InsertNextTuple(measurements); |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
void CatalystManager::WriteToLogFile(const CatalystPipelineInfo &cpi) |
| 407 |
{ |
| 408 |
|
| 409 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 410 |
std::string logFileName = cpi.getLogFileName(); |
| 411 |
|
| 412 |
if (this->logging.find(id) != this->logging.end()) { |
| 413 |
vtkProcessModule *pm = vtkProcessModule::GetProcessModule(); |
| 414 |
vtkMPIController *mpic = vtkMPIController::SafeDownCast(pm->GetGlobalController()); |
| 415 |
vtkDoubleArray *logData = this->logging[id].second; |
| 416 |
clock_t begin_time = this->logging[id].first.first; |
| 417 |
if (mpic && mpic->GetNumberOfProcesses() > 1) { |
| 418 |
vtkDoubleArray *recvBufferMin = vtkDoubleArray::New(); |
| 419 |
vtkDoubleArray *recvBufferMax = vtkDoubleArray::New(); |
| 420 |
vtkDoubleArray *recvBufferSum = vtkDoubleArray::New(); |
| 421 |
if (mpic->GetLocalProcessId() == 0) { |
| 422 |
recvBufferMin->SetNumberOfComponents(3); |
| 423 |
recvBufferMin->SetNumberOfTuples(logData->GetNumberOfTuples()); |
| 424 |
|
| 425 |
recvBufferMax->SetNumberOfComponents(3); |
| 426 |
recvBufferMax->SetNumberOfTuples(logData->GetNumberOfTuples()); |
| 427 |
|
| 428 |
recvBufferSum->SetNumberOfComponents(3); |
| 429 |
recvBufferSum->SetNumberOfTuples(logData->GetNumberOfTuples()); |
| 430 |
} |
| 431 |
|
| 432 |
mpic->Reduce(logData, recvBufferMin, vtkCommunicator::MIN_OP, 0); |
| 433 |
mpic->Reduce(logData, recvBufferMax, vtkCommunicator::MAX_OP, 0); |
| 434 |
mpic->Reduce(logData, recvBufferSum, vtkCommunicator::SUM_OP, 0); |
| 435 |
|
| 436 |
if (mpic->GetLocalProcessId() == 0) { |
| 437 |
std::ofstream logfile; |
| 438 |
logfile.open(logFileName, ios::out | ios::app); |
| 439 |
for (int i = 0; i < logData->GetNumberOfTuples(); i++) { |
| 440 |
double min[3]; |
| 441 |
double max[3]; |
| 442 |
double sum[3]; |
| 443 |
recvBufferMin->GetTuple(i, min); |
| 444 |
recvBufferMax->GetTuple(i, max); |
| 445 |
recvBufferSum->GetTuple(i, sum); |
| 446 |
logfile << double(clock() - begin_time) / (double)CLOCKS_PER_SEC << "," << min[0] << "," |
| 447 |
<< max[0] << "," << sum[0] / (double)mpic->GetNumberOfProcesses() << "," |
| 448 |
<< min[1] << "," << max[1] << "," |
| 449 |
<< sum[1] / (double)mpic->GetNumberOfProcesses() << "," << min[2] << "," |
| 450 |
<< max[2] << "," << sum[2] / (double)mpic->GetNumberOfProcesses() << "\n"; |
| 451 |
} |
| 452 |
logfile.close(); |
| 453 |
} |
| 454 |
recvBufferMin->Delete(); |
| 455 |
recvBufferMax->Delete(); |
| 456 |
recvBufferSum->Delete(); |
| 457 |
} |
| 458 |
else { |
| 459 |
std::ofstream logfile; |
| 460 |
logfile.open(logFileName, ios::out | ios::app); |
| 461 |
for (int i = 0; i < logData->GetNumberOfTuples(); i++) { |
| 462 |
double data[3]; |
| 463 |
logData->GetTuple(i, data); |
| 464 |
logfile << double(clock() - begin_time) / CLOCKS_PER_SEC << "," << data[0] << "," |
| 465 |
<< data[1] << "," << data[2] << "\n"; |
| 466 |
} |
| 467 |
logfile.close(); |
| 468 |
} |
| 469 |
logData->SetNumberOfTuples(0); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
bool CatalystManager::writeMeshON(const CatalystPipelineInfo &cpi) |
| 474 |
{ |
| 475 |
|
| 476 |
bool retVal = false; |
| 477 |
|
| 478 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 479 |
|
| 480 |
if (pipelines.find(id) != pipelines.end()) { |
| 481 |
auto mw = pipelines[id].getMeshWriter(); |
| 482 |
retVal = mw->outputCatalystMeshOneFileON() || mw->outputCatalystMeshFilePerProcON(); |
| 483 |
} |
| 484 |
|
| 485 |
return retVal; |
| 486 |
} |
| 487 |
|
| 488 |
void CatalystManager::writeMesh(const CatalystPipelineInfo &cpi) |
| 489 |
{ |
| 490 |
|
| 491 |
CatalystPipelineID id = cpi.catalystPipelineID; |
| 492 |
|
| 493 |
if (pipelines.find(id) != pipelines.end()) { |
| 494 |
auto mw = pipelines[id].getMeshWriter(); |
| 495 |
vtkDataObject *vobj = pipelines[id] |
| 496 |
.getDataDescription() |
| 497 |
->GetInputDescriptionByName(cpi.catalystInputName.c_str()) |
| 498 |
->GetGrid(); |
| 499 |
int timeStep = pipelines[id].getDataDescription()->GetTimeStep(); |
| 500 |
if (mw->outputCatalystMeshOneFileON()) { |
| 501 |
mw->writeCatalystMeshOneFile(vobj, timeStep); |
| 502 |
} |
| 503 |
if (mw->outputCatalystMeshFilePerProcON()) { |
| 504 |
mw->writeCatalystMeshFilePerProc(vobj, timeStep); |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
void CatalystManager::parsePhactoriFile(const std::string &filepath, ParseResult &pres) |
| 510 |
{ |
| 511 |
|
| 512 |
PhactoriParserInterface::ParseInfo pinfo; |
| 513 |
PhactoriParserInterface::parseFile(filepath, pinfo); |
| 514 |
pres.jsonParseResult = pinfo.jsonParseResult; |
| 515 |
pres.parseFailed = pinfo.parseFailed; |
| 516 |
} |
| 517 |
|
| 518 |
void CatalystManager::parsePhactoriString(const std::string &phactori, ParseResult &pres) |
| 519 |
{ |
| 520 |
|
| 521 |
PhactoriParserInterface::ParseInfo pinfo; |
| 522 |
PhactoriParserInterface::parseString(phactori, pinfo); |
| 523 |
pres.jsonParseResult = pinfo.jsonParseResult; |
| 524 |
pres.parseFailed = pinfo.parseFailed; |
| 525 |
} |
| 526 |
|
| 527 |
extern "C" { |
| 528 |
CatalystManagerBase *CreateCatalystManagerInstance() |
| 529 |
{ |
| 530 |
CatalystManager *p = new CatalystManager(); |
| 531 |
return (CatalystManagerBase *)p; |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
} // namespace Iovs |