mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Update 1 for code after code review of PR 4889
This commit is contained in:
@@ -35,45 +35,47 @@ namespace Opm::DamarisOutput
|
||||
|
||||
std::string initDamarisXmlFile(); // Defined in initDamarisXMLFile.cpp, to avoid messing up this file.
|
||||
|
||||
// Initialize Damaris by filling in th XML file and storing it in the chosen directory
|
||||
/**
|
||||
* Initialize Damaris by either reading a file specified by the environment variable FLOW_DAMARIS_XML_FILE or
|
||||
* by filling in th XML file and storing it in the chosen directory
|
||||
*/
|
||||
void
|
||||
initializeDamaris(MPI_Comm comm, int mpiRank, std::map<std::string, std::string>& find_replace_map )
|
||||
{
|
||||
int dam_err_;
|
||||
int dam_err;
|
||||
|
||||
/* Get the name of the Damaris input file from an environment variable if available */
|
||||
const char* cs_damaris_xml_file = getenv("FLOW_DAMARIS_XML_FILE");
|
||||
if (cs_damaris_xml_file != NULL)
|
||||
{
|
||||
std::cout << "INFO: Initializing Damaris from environment variable FLOW_DAMARIS_XML_FILE: "
|
||||
<< cs_damaris_xml_file << std::endl;
|
||||
dam_err_ = damaris_initialize(cs_damaris_xml_file, MPI_COMM_WORLD);
|
||||
if (dam_err_ != DAMARIS_OK) {
|
||||
OpmLog::info(std::string("Initializing Damaris from environment variable FLOW_DAMARIS_XML_FILE: ") + cs_damaris_xml_file);
|
||||
dam_err = damaris_initialize(cs_damaris_xml_file, comm);
|
||||
if (dam_err != DAMARIS_OK) {
|
||||
OpmLog::error(fmt::format("ERORR: damariswriter::initializeDamaris() : ( rank:{}) "
|
||||
"damaris_initialize({}, MPI_COMM_WORLD), Damaris Error: {} ",
|
||||
mpiRank, cs_damaris_xml_file, damaris_error_string(dam_err_) ));
|
||||
"damaris_initialize({}, comm), Damaris Error: {} ",
|
||||
mpiRank, cs_damaris_xml_file, damaris_error_string(dam_err) ));
|
||||
}
|
||||
} else {
|
||||
// Prepare the XML file
|
||||
// Prepare the inbuilt XML file
|
||||
std::string damaris_config_xml = initDamarisXmlFile(); // This is the template for a Damaris XML file
|
||||
damaris::model::ModifyModel myMod = damaris::model::ModifyModel(damaris_config_xml);
|
||||
// The map will make it precise the output directory and FileMode (either FilePerCore or Collective storage)
|
||||
// The map file find all occurences of the string in position 1 and replace it/them with string in position 2
|
||||
// std::map<std::string, std::string> find_replace_map = DamarisKeywords(outputDir, enableDamarisOutputCollective);
|
||||
myMod.RepalceWithRegEx(find_replace_map);
|
||||
|
||||
std::string outputDir = find_replace_map["_PATH_REGEX_"] ;
|
||||
std::string outputDir = find_replace_map["_PATH_REGEX_"];
|
||||
std::string damaris_xml_filename_str = outputDir + "/damaris_config.xml";
|
||||
|
||||
if (mpiRank == 0) {
|
||||
myMod.SaveXMLStringToFile(damaris_xml_filename_str);
|
||||
}
|
||||
std::cout << "INFO: Initializing Damaris using internally built file:" << damaris_xml_filename_str << " (N.B. use FLOW_DAMARIS_XML_FILE to override)" << std::endl;
|
||||
dam_err_ = damaris_initialize(damaris_xml_filename_str.c_str(), comm);
|
||||
if (dam_err_ != DAMARIS_OK) {
|
||||
OpmLog::error(fmt::format("ERORR: damariswriter::initializeDamaris() : ( rank:{}) "
|
||||
"damaris_initialize({}, MPI_COMM_WORLD), Damaris Error: {}. Error via OPM internally built file:",
|
||||
mpiRank, cs_damaris_xml_file, damaris_error_string(dam_err_) ));
|
||||
|
||||
OpmLog::info("Initializing Damaris using internally built file: " + damaris_xml_filename_str + " (N.B. use environment variable FLOW_DAMARIS_XML_FILE to override)");
|
||||
dam_err = damaris_initialize(damaris_xml_filename_str.c_str(), comm);
|
||||
if (dam_err != DAMARIS_OK) {
|
||||
OpmLog::error(fmt::format("damariswriter::initializeDamaris() : ( rank:{}) "
|
||||
"damaris_initialize({}, comm), Damaris Error: {}. Error via OPM internally built file:",
|
||||
mpiRank, cs_damaris_xml_file, damaris_error_string(dam_err) ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user