Skip to content

Commit

Permalink
Catalyst API 2
Browse files Browse the repository at this point in the history
Added tests to Catalyst manager to inspect IOSS
properties passed into the data and handle them
like the Catalyst API 1 database.
  • Loading branch information
tjotaha committed Oct 30, 2023
1 parent 72f5394 commit ceca6fe
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,132 @@
//
// See packages/seacas/LICENSE for details

#include <catalyst/Iocatalyst_CatalystLogging.h>
#include <catalyst/Iocatalyst_CatalystManager.h>
#include <fstream>

namespace Iocatalyst {

CatalystManager::CatalystManager() {}
CatalystManager::CatalystManager() { catalystOutputIDNumber = 0; }

CatalystManager::~CatalystManager() {}

void CatalystManager::writeToCatalystLogFile(const Ioss::ParallelUtils &putils,
const Ioss::PropertyManager &props) {}
const Ioss::PropertyManager &props)
{
if (putils.parallel_rank() == 0) {
CatalystLogging catLog = CatalystLogging();
catLog.setProperties(&props);
if (catLog.isCatalystLoggingON()) {
catLog.writeToLogFile();
}
}
putils.barrier();
}

CatalystManager::CatalystProps
CatalystManager::registerDatabase(const Ioss::PropertyManager &props,
const Ioss::ParallelUtils &putils)
{
CatalystManager::CatalystProps catalystProps;
catalystProps.catalystPipelineID = catalystOutputIDNumber;
incrementOutputCounts();

if (props.exists("CATALYST_BLOCK_PARSE_JSON_STRING")) {
catalystProps.catalystBlockJSON = props.get("CATALYST_BLOCK_PARSE_JSON_STRING").get_string();
}
else if (props.exists("PHACTORI_JSON_SCRIPT")) {
bool readOkay = false;
std::string phactoriJSONFilePath = props.get("PHACTORI_JSON_SCRIPT").get_string();
if (putils.parallel_rank() == 0) {
std::ifstream f(phactoriJSONFilePath);
if (f) {
std::ostringstream ss;
ss << f.rdbuf();
catalystProps.catalystBlockJSON = ss.str();
readOkay = true;
}
}
this->broadCastStatusCode(readOkay, putils);
if (!readOkay) {
std::ostringstream errmsg;
errmsg << "Unable to read input file: " << phactoriJSONFilePath << "\n";
IOSS_ERROR(errmsg);
}
else {
this->broadCastString(catalystProps.catalystBlockJSON, putils);
}
}

if (props.exists("CATALYST_SCRIPT")) {
catalystProps.catalystPythonFilename = props.get("CATALYST_SCRIPT").get_string();
}
else {
catalystProps.catalystPythonFilename = this->getCatalystPythonDriverPath();
}

if (props.exists("CATALYST_SCRIPT_EXTRA_FILE")) {
catalystProps.catalystScriptExtraFile = props.get("CATALYST_SCRIPT_EXTRA_FILE").get_string();
}

if (props.exists("CATALYST_BLOCK_PARSE_INPUT_DECK_NAME")) {
catalystProps.catalystInputDeckName =
props.get("CATALYST_BLOCK_PARSE_INPUT_DECK_NAME").get_string();
}

if (props.exists("CATALYST_ENABLE_LOGGING")) {
catalystProps.enableLogging = props.get("CATALYST_ENABLE_LOGGING").get_int();
}

if (props.exists("CATALYST_DEBUG_LEVEL")) {
catalystProps.debugLevel = props.get("CATALYST_DEBUG_LEVEL").get_int();
}

if (props.exists("CATALYST_OUTPUT_DIRECTORY")) {
catalystProps.catalystOutputDirectory = props.get("CATALYST_OUTPUT_DIRECTORY").get_string();
}

if (props.exists("CATALYST_INPUT_NAME")) {
catalystProps.catalystInputName = props.get("CATALYST_INPUT_NAME").get_string();
}

if (props.exists("CATALYST_MULTI_INPUT_PIPELINE_NAME")) {
catalystProps.enableCatalystMultiInputPipeline = true;
catalystProps.catalystMultiInputPipelineName =
props.get("CATALYST_MULTI_INPUT_PIPELINE_NAME").get_string();
}

return catalystProps;
}

void CatalystManager::incrementOutputCounts() { catalystOutputIDNumber++; }

void CatalystManager::broadCastString(IOSS_MAYBE_UNUSED std::string &s,
IOSS_MAYBE_UNUSED const Ioss::ParallelUtils &putils)
{
IOSS_PAR_UNUSED(s);
IOSS_PAR_UNUSED(dbinfo);
#ifdef SEACAS_HAVE_MPI
int size = s.size();
putils.broadcast(size);
if (putils.parallel_rank() != 0) {
s.resize(size);
}
putils.broadcast(s);
#endif
}

void CatalystManager::broadCastStatusCode(IOSS_MAYBE_UNUSED bool &statusCode,
IOSS_MAYBE_UNUSED const Ioss::ParallelUtils &putils)
{
IOSS_PAR_UNUSED(statusCode);
IOSS_PAR_UNUSED(dbinfo);
#ifdef SEACAS_HAVE_MPI

int code = statusCode;
putils.broadcast(code);
statusCode = code;
#endif
}

} // namespace Iocatalyst
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,60 @@ namespace Iocatalyst {
class IOCATALYST_EXPORT CatalystManager
{
public:
using CatalystPipelineID = unsigned int;
inline static const std::string CATALYST_OUTPUT_DIRECTORY = "CatalystOutput";
inline static const std::string CATALYST_INPUT_NAME = "input";

static CatalystManager &getInstance()
{
static CatalystManager instance;
return instance;
}

std::string getCatalystPythonDriverPath() { return "/todo/create/real/path"; }

void writeToCatalystLogFile(const Ioss::ParallelUtils &putils,
const Ioss::PropertyManager &props);

struct CatalystProps
{
CatalystProps()
{
catalystPipelineID = 0;
enableLogging = false;
debugLevel = 0;
catalystOutputDirectory = CATALYST_OUTPUT_DIRECTORY;
catalystInputName = CATALYST_INPUT_NAME;
enableCatalystMultiInputPipeline = false;
}
CatalystPipelineID catalystPipelineID;
std::string catalystBlockJSON;
std::string catalystPythonFilename;
std::string catalystScriptExtraFile;
std::string catalystInputDeckName;
bool enableLogging;
int debugLevel;
std::string catalystOutputDirectory;
std::string catalystInputName;
bool enableCatalystMultiInputPipeline;
std::string catalystMultiInputPipelineName;
};

CatalystProps registerDatabase(const Ioss::PropertyManager &props,
const Ioss::ParallelUtils &putils);

private:
CatalystManager();
~CatalystManager();
CatalystManager(const CatalystManager &) = delete;
CatalystManager &operator=(const CatalystManager &) = delete;

void broadCastString(std::string &s, const Ioss::ParallelUtils &putils);
void broadCastStatusCode(bool &statusCode, const Ioss::ParallelUtils &putils);

void incrementOutputCounts();

CatalystPipelineID catalystOutputIDNumber;
};
} // namespace Iocatalyst

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

#include <Ioss_Compare.h>
#include <Ioss_DatabaseIO.h>
#include <Ioss_ElementBlock.h>
#include <Ioss_IOFactory.h>
#include <Ioss_MeshCopyOptions.h>
#include <Ioss_NodeBlock.h>
#include <Ioss_ElementBlock.h>
#include <Ioss_StructuredBlock.h>
#include <catalyst_tests/Iocatalyst_DatabaseIOTest.h>
#include <catalyst/Iocatalyst_DatabaseIO.h>
#include <catalyst_tests/Iocatalyst_DatabaseIOTest.h>

Iocatalyst_DatabaseIOTest::Iocatalyst_DatabaseIOTest()
{
Expand All @@ -31,17 +31,18 @@ bool Iocatalyst_DatabaseIOTest::regionsAreEqual(const std::string &fileName,
const std::string &iossDatabaseType)
{
Ioss::PropertyManager dbProps;
auto inputFileName = fileName;
auto inputCatalystFileName = catFileName;
Ioss::ParallelUtils pu;
int numRanks = pu.parallel_size();
int rank = pu.parallel_rank();
if(iossDatabaseType == EXODUS_DATABASE_TYPE && numRanks > 1) {
auto inputFileName = fileName;
auto inputCatalystFileName = catFileName;
Ioss::ParallelUtils pu;
int numRanks = pu.parallel_size();
int rank = pu.parallel_rank();
if (iossDatabaseType == EXODUS_DATABASE_TYPE && numRanks > 1) {
inputFileName += "." + std::to_string(numRanks) + "." + std::to_string(rank);
inputCatalystFileName += "." + std::to_string(numRanks) + "." + std::to_string(rank);
inputCatalystFileName += "." + std::to_string(numRanks) + "." + std::to_string(rank);
}
Ioss::DatabaseIO *dbi = Ioss::IOFactory::create(iossDatabaseType, inputFileName, Ioss::READ_RESTART,
Ioss::ParallelUtils::comm_self(), dbProps);
Ioss::DatabaseIO *dbi =
Ioss::IOFactory::create(iossDatabaseType, inputFileName, Ioss::READ_RESTART,
Ioss::ParallelUtils::comm_self(), dbProps);
if (dbi == nullptr || !dbi->ok(true)) {
return false;
}
Expand Down Expand Up @@ -102,7 +103,7 @@ void Iocatalyst_DatabaseIOTest::checkZeroCopyFields(Iocatalyst::BlockMeshSet::IO
return;
}

Ioss::Region cir(cdbi);
Ioss::Region cir(cdbi);
Iocatalyst::DatabaseIO::RegionContainer rc;
rc.push_back(&cir);
checkEntityContainerZeroCopyFields(rc);
Expand Down
Loading

0 comments on commit ceca6fe

Please sign in to comment.