| 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 IOSS_IOVS_CATALYST_MANAGER_H |
| 8 |
#define IOSS_IOVS_CATALYST_MANAGER_H |
| 9 |
|
| 10 |
#include "iocatalyst_export.h" |
| 11 |
#include <Ioss_ParallelUtils.h> |
| 12 |
#include <catalyst.hpp> |
| 13 |
|
| 14 |
namespace Iocatalyst { |
| 15 |
|
| 16 |
class IOCATALYST_EXPORT CatalystManager |
| 17 |
{ |
| 18 |
public: |
| 19 |
using CatalystPipelineID = unsigned int; |
| 20 |
|
| 21 |
enum mState { mInit, mExecute, mFinalize }; |
| 22 |
enum pState { pWaitExecute, pExecute, pFinalize }; |
| 23 |
|
| 24 |
inline static const std::string ARGS = "args"; |
| 25 |
inline static const std::string CATALYST = "catalyst"; |
| 26 |
inline static const std::string CATALYST_BLOCK_PARSE_INPUT_DECK_NAME = |
| 27 |
"CATALYST_BLOCK_PARSE_INPUT_DECK_NAME"; |
| 28 |
inline static const std::string CATALYST_BLOCK_PARSE_JSON_STRING = |
| 29 |
"CATALYST_BLOCK_PARSE_JSON_STRING"; |
| 30 |
inline static const std::string CATALYST_DEBUG_LEVEL = "CATALYST_DEBUG_LEVEL"; |
| 31 |
inline static const std::string CATALYST_ENABLE_LOGGING = "CATALYST_ENABLE_LOGGING"; |
| 32 |
inline static const std::string CATALYST_OUTPUT_DIRECTORY = "CATALYST_OUTPUT_DIRECTORY"; |
| 33 |
inline static const std::string CATALYST_OUTPUT_DEFAULT = "CatalystOutput"; |
| 34 |
inline static const std::string CATALYST_INPUT_NAME = "CATALYST_INPUT_NAME"; |
| 35 |
inline static const std::string CATALYST_INPUT_DEFAULT = "input"; |
| 36 |
inline static const std::string CATALYST_MULTI_INPUT_PIPELINE_NAME = |
| 37 |
"CATALYST_MULTI_INPUT_PIPELINE_NAME"; |
| 38 |
inline static const std::string CATALYST_SCRIPT = "CATALYST_SCRIPT"; |
| 39 |
inline static const std::string CATALYST_SCRIPT_EXTRA_FILE = "CATALYST_SCRIPT_EXTRA_FILE"; |
| 40 |
inline static const std::string CHANNELS = "channels"; |
| 41 |
inline static const std::string CYCLE = "cycle"; |
| 42 |
inline static const std::string DATA = "data"; |
| 43 |
inline static const std::string PHACTORI_JSON_SCRIPT = "PHACTORI_JSON_SCRIPT"; |
| 44 |
inline static const std::string PIPELINES = "pipelines"; |
| 45 |
inline static const std::string FILENAME = "filename"; |
| 46 |
inline static const std::string FS = "/"; |
| 47 |
inline static const std::string IOSS = "ioss"; |
| 48 |
inline static const std::string SCRIPTS = "scripts"; |
| 49 |
inline static const std::string STATE = "state"; |
| 50 |
inline static const std::string TIME = "time"; |
| 51 |
inline static const std::string TIMESTEP = "timestep"; |
| 52 |
inline static const std::string TYPE = "type"; |
| 53 |
|
| 54 |
static CatalystManager &getInstance() |
| 55 |
{ |
| 56 |
static CatalystManager instance; |
| 57 |
return instance; |
| 58 |
} |
| 59 |
|
| 60 |
std::string getCatalystPythonDriverPath() { return "/todo/create/real/path"; } |
| 61 |
|
| 62 |
conduit_cpp::Node getInitializeConduit(); |
| 63 |
|
| 64 |
mState getManagerState() { return managerState; } |
| 65 |
|
| 66 |
pState getPipelineState(CatalystPipelineID id); |
| 67 |
|
| 68 |
void writeToCatalystLogFile(const Ioss::ParallelUtils &putils, |
| 69 |
const Ioss::PropertyManager &props); |
| 70 |
|
| 71 |
struct CatalystProps |
| 72 |
{ |
| 73 |
CatalystProps() |
| 74 |
{ |
| 75 |
catalystPipelineID = 0; |
| 76 |
enableLogging = false; |
| 77 |
debugLevel = 0; |
| 78 |
catalystOutputDirectory = CATALYST_OUTPUT_DEFAULT; |
| 79 |
catalystInputName = CATALYST_INPUT_DEFAULT; |
| 80 |
enableCatalystMultiInputPipeline = false; |
| 81 |
pipelineState = pExecute; |
| 82 |
state = 0; |
| 83 |
time = 0.0; |
| 84 |
} |
| 85 |
|
| 86 |
CatalystPipelineID catalystPipelineID; |
| 87 |
pState pipelineState; |
| 88 |
bool enableCatalystMultiInputPipeline; |
| 89 |
std::string catalystMultiInputPipelineName; |
| 90 |
std::string catalystPythonFilename; |
| 91 |
conduit_cpp::Node data; |
| 92 |
int state; |
| 93 |
double time; |
| 94 |
|
| 95 |
std::string catalystInputName; |
| 96 |
std::string catalystBlockJSON; |
| 97 |
std::string catalystScriptExtraFile; |
| 98 |
std::string catalystInputDeckName; |
| 99 |
std::string catalystOutputDirectory; |
| 100 |
bool enableLogging; |
| 101 |
int debugLevel; |
| 102 |
}; |
| 103 |
|
| 104 |
CatalystPipelineID initialize(const Ioss::PropertyManager &props, |
| 105 |
const Ioss::ParallelUtils &putils); |
| 106 |
void execute(CatalystPipelineID id, int state, double time, conduit_cpp::Node &data); |
| 107 |
void finalize(CatalystPipelineID id); |
| 108 |
void addScriptProps(conduit_cpp::Node &n, const CatalystProps &p); |
| 109 |
void addExecuteProps(conduit_cpp::Node &n, const CatalystProps &p, int state, double time); |
| 110 |
void addExecuteData(conduit_cpp::Node &n, const std::string &channelName, int state, |
| 111 |
double time, conduit_cpp::Node &data); |
| 112 |
CatalystProps &getCatalystProps(CatalystPipelineID id); |
| 113 |
std::string getCatDataPath(const Ioss::PropertyManager &props); |
| 114 |
void setMultiInputWaitState(CatalystPipelineID id, int state, double time, |
| 115 |
conduit_cpp::Node &data); |
| 116 |
bool canExecuteMultiInputScript(CatalystPipelineID id); |
| 117 |
void clearAllMultiInputWaitStates(CatalystPipelineID id); |
| 118 |
void reset() |
| 119 |
{ |
| 120 |
catalystOutputIDNumber = 0; |
| 121 |
catPipes.clear(); |
| 122 |
managerState = mInit; |
| 123 |
} |
| 124 |
|
| 125 |
std::string getCatScriptFnamePath(const CatalystProps &p) |
| 126 |
{ |
| 127 |
return getCatScriptPath(p) + FILENAME; |
| 128 |
} |
| 129 |
|
| 130 |
std::string getCatScriptArgsPath(const CatalystProps &p) { return getCatScriptPath(p) + ARGS; } |
| 131 |
|
| 132 |
std::string getCatScriptPath(const CatalystProps &p) |
| 133 |
{ |
| 134 |
return CATALYST + FS + SCRIPTS + FS + std::to_string(p.catalystPipelineID) + FS; |
| 135 |
} |
| 136 |
|
| 137 |
std::string getCatStatePath() { return CATALYST + FS + STATE + FS; } |
| 138 |
|
| 139 |
std::string getCatChannelsPath() { return CATALYST + FS + CHANNELS + FS; } |
| 140 |
|
| 141 |
private: |
| 142 |
CatalystManager(); |
| 143 |
~CatalystManager(); |
| 144 |
CatalystManager(const CatalystManager &) = delete; |
| 145 |
CatalystManager &operator=(const CatalystManager &) = delete; |
| 146 |
|
| 147 |
void broadCastString(std::string &s, const Ioss::ParallelUtils &putils); |
| 148 |
void broadCastStatusCode(bool &statusCode, const Ioss::ParallelUtils &putils); |
| 149 |
|
| 150 |
void incrementOutputCounts(); |
| 151 |
|
| 152 |
CatalystPipelineID catalystOutputIDNumber; |
| 153 |
std::map<CatalystPipelineID, CatalystProps> catPipes; |
| 154 |
mState managerState; |
| 155 |
}; |
| 156 |
} // namespace Iocatalyst |
| 157 |
|
| 158 |
#endif |