| 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 |
#ifndef __CATALYST_MANAGER_H |
| 8 |
#define __CATALYST_MANAGER_H |
| 9 |
|
| 10 |
#include "vtkCPDataDescription.h" |
| 11 |
#include <map> |
| 12 |
#include <time.h> |
| 13 |
#include <visualization/utils/CatalystManagerBase.h> |
| 14 |
#include <vtkSmartPointer.h> |
| 15 |
|
| 16 |
class coProcessor; |
| 17 |
class vtkDoubleArray; |
| 18 |
class vtkCPPythonPipeline; |
| 19 |
class vtkCPProcessor; |
| 20 |
class vtkDataObject; |
| 21 |
|
| 22 |
namespace Iovs { |
| 23 |
|
| 24 |
class CatalystMeshWriter; |
| 25 |
|
| 26 |
class CatalystManager : public CatalystManagerBase |
| 27 |
{ |
| 28 |
|
| 29 |
public: |
| 30 |
const std::string catalystPluginVersion = "2.0.0"; |
| 31 |
using CatalystPipelineID = unsigned int; |
| 32 |
using CatalystInputName = std::string; |
| 33 |
using CatalystMultiInputPipelineName = std::string; |
| 34 |
|
| 35 |
CatalystManager(); |
| 36 |
~CatalystManager(); |
| 37 |
|
| 38 |
void parsePhactoriFile(const std::string &filepath, ParseResult &pres); |
| 39 |
|
| 40 |
void parsePhactoriString(const std::string &phactori, ParseResult &pres); |
| 41 |
|
| 42 |
std::string getCatalystPluginVersion(); |
| 43 |
|
| 44 |
std::unique_ptr<Iovs_exodus::CatalystExodusMeshBase> |
| 45 |
createCatalystExodusMesh(CatalystExodusMeshInit &cmInit); |
| 46 |
|
| 47 |
std::unique_ptr<Iovs_cgns::CatalystCGNSMeshBase> |
| 48 |
createCatalystCGNSMesh(CatalystMeshInit &cmInit); |
| 49 |
|
| 50 |
int getCatalystOutputIDNumber(); |
| 51 |
|
| 52 |
struct CatalystPipelineInfo |
| 53 |
{ |
| 54 |
CatalystPipelineID catalystPipelineID; |
| 55 |
CatalystInputName catalystInputName; |
| 56 |
std::string getLogFileName() const |
| 57 |
{ |
| 58 |
return catalystInputName + "_" + std::to_string(catalystPipelineID) + "_catalyst.log"; |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
// Description: |
| 63 |
// Deletes pipeline with name results_output_filename and any associated |
| 64 |
// logging data. |
| 65 |
void DeletePipeline(const CatalystPipelineInfo &cpi); |
| 66 |
|
| 67 |
// Description: |
| 68 |
// Calls the ParaView Catalyst pipeline to run co-processing for this time iteration. |
| 69 |
void PerformCoProcessing(std::vector<int> &error_and_warning_codes, |
| 70 |
std::vector<std::string> &error_and_warning_messages, |
| 71 |
const CatalystPipelineInfo &cpi); |
| 72 |
|
| 73 |
// Description: |
| 74 |
// Sets time data for this ParaView Catalyst co-processing iteration. |
| 75 |
// currentTime is the current Ioss simulation time and timeStep is |
| 76 |
// the current time iteration count. |
| 77 |
void SetTimeData(double currentTime, int timeStep, const CatalystPipelineInfo &cpi); |
| 78 |
|
| 79 |
// Description: |
| 80 |
// Collects memory usage information from all processors and |
| 81 |
// writes the min, max, and mean to the log file. Also writes the |
| 82 |
// min, max, and mean of the elapsed time since this method was |
| 83 |
// last called. |
| 84 |
void logMemoryUsageAndTakeTimerReading(const CatalystPipelineInfo &cpi); |
| 85 |
|
| 86 |
void WriteToLogFile(const CatalystPipelineInfo &cpi); |
| 87 |
|
| 88 |
private: |
| 89 |
void initCatalystPythonSystemPaths(); |
| 90 |
|
| 91 |
class CatalystPipelineState |
| 92 |
{ |
| 93 |
public: |
| 94 |
CatalystPipelineState() |
| 95 |
{ |
| 96 |
performCoProcessingCount = 0; |
| 97 |
deletePipelineCount = 0; |
| 98 |
setTimeDataCount = 0; |
| 99 |
} |
| 100 |
|
| 101 |
vtkSmartPointer<vtkCPPythonPipeline> &getPipeline() { return pipeline; } |
| 102 |
|
| 103 |
vtkSmartPointer<vtkCPDataDescription> &getDataDescription() { return dataDescription; } |
| 104 |
|
| 105 |
std::shared_ptr<CatalystMeshWriter> &getMeshWriter() { return meshWriter; } |
| 106 |
|
| 107 |
bool canPerformCoProcessing() { return canDoOperation(performCoProcessingCount); } |
| 108 |
|
| 109 |
bool canDeletePipeline() { return canDoOperation(deletePipelineCount); } |
| 110 |
|
| 111 |
bool canSetTimeData() { return canDoOperation(setTimeDataCount); } |
| 112 |
|
| 113 |
private: |
| 114 |
bool canDoOperation(unsigned int &operationCount) |
| 115 |
{ |
| 116 |
bool retVal = true; |
| 117 |
operationCount++; |
| 118 |
if (operationCount == getNumberOfInputs()) { |
| 119 |
operationCount = 0; |
| 120 |
} |
| 121 |
else { |
| 122 |
retVal = false; |
| 123 |
} |
| 124 |
return retVal; |
| 125 |
} |
| 126 |
|
| 127 |
unsigned int getNumberOfInputs() |
| 128 |
{ |
| 129 |
unsigned int retVal = 0; |
| 130 |
if (getDataDescription() != nullptr) { |
| 131 |
retVal = getDataDescription()->GetNumberOfInputDescriptions(); |
| 132 |
} |
| 133 |
return retVal; |
| 134 |
} |
| 135 |
|
| 136 |
unsigned int performCoProcessingCount; |
| 137 |
unsigned int deletePipelineCount; |
| 138 |
unsigned int setTimeDataCount; |
| 139 |
vtkSmartPointer<vtkCPPythonPipeline> pipeline; |
| 140 |
vtkSmartPointer<vtkCPDataDescription> dataDescription; |
| 141 |
std::shared_ptr<CatalystMeshWriter> meshWriter; |
| 142 |
}; |
| 143 |
|
| 144 |
typedef std::pair<clock_t, clock_t> TimerPair; |
| 145 |
typedef std::pair<TimerPair, vtkDoubleArray *> LoggingPair; |
| 146 |
|
| 147 |
CatalystManager(const CatalystManager &) = delete; |
| 148 |
CatalystManager &operator=(const CatalystManager &) = delete; |
| 149 |
|
| 150 |
void initializeIfNeeded(); |
| 151 |
void finalizeIfNeeded(); |
| 152 |
bool canCoProcess(); |
| 153 |
void incrementOutputCounts(); |
| 154 |
bool writeMeshON(const CatalystPipelineInfo &cpi); |
| 155 |
void writeMesh(const CatalystPipelineInfo &cpi); |
| 156 |
CatalystPipelineID getCatalystPipelineID(CatalystMeshInit &cmInit); |
| 157 |
|
| 158 |
void initCatalystLogging(const CatalystPipelineInfo &cpi); |
| 159 |
void initCatalystPipeline(CatalystMeshInit &cmInit, vtkDataObject *vobj, |
| 160 |
const CatalystPipelineInfo &cpi); |
| 161 |
void addInputToPipeline(vtkDataObject *vobj, const CatalystPipelineInfo &cpi); |
| 162 |
CatalystPipelineInfo createCatalystPipelineInfo(CatalystMeshInit &cmInit); |
| 163 |
void registerMeshInPipeline(CatalystMeshInit &cmInit, vtkDataObject *vobj, |
| 164 |
const CatalystPipelineInfo &cpi); |
| 165 |
|
| 166 |
CatalystPipelineID catalystOutputIDNumber; |
| 167 |
CatalystPipelineID catalystOutputReferenceCount; |
| 168 |
vtkCPProcessor *coProcessor; |
| 169 |
std::map<CatalystPipelineID, CatalystPipelineState> pipelines; |
| 170 |
std::map<CatalystPipelineID, LoggingPair> logging; |
| 171 |
std::map<CatalystMultiInputPipelineName, CatalystPipelineID> multiInputPipelines; |
| 172 |
}; |
| 173 |
|
| 174 |
extern "C" { |
| 175 |
CatalystManagerBase *CreateCatalystManagerInstance(); |
| 176 |
} |
| 177 |
|
| 178 |
} // namespace Iovs |
| 179 |
|
| 180 |
#endif /* __CATALYST_MANAGER_H */ |