mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-01-11 17:01:55 -06:00
Other small additions from github comments and removal of compile time logic that checks for ParaView and Python - makes code more readable and alows use of Damaris libraries with differing compiled in backends to be swapped without need for recompiling opm-simulators
This commit is contained in:
parent
2744614f9c
commit
7fc6cc0430
@ -42,8 +42,7 @@ int setPosition(const char* field, int rank, int64_t pos)
|
||||
{
|
||||
int dam_err = damaris_set_position(field, &pos);
|
||||
if (dam_err != DAMARIS_OK) {
|
||||
// OpmLog::error only prints from rank 0
|
||||
OpmLog::error(fmt::format("damariswriter::setPosition() : ( rank:{}) "
|
||||
OpmLog::warning(fmt::format("damariswriter::setPosition() : ( rank:{}) "
|
||||
"damaris_set_position({}, ...), Damaris Error: {} ",
|
||||
rank, field, damaris_error_string(dam_err)));
|
||||
}
|
||||
@ -55,8 +54,7 @@ int setParameter(const char* field, int rank, int value)
|
||||
{
|
||||
int dam_err = damaris_parameter_set(field, &value, sizeof(int));
|
||||
if (dam_err != DAMARIS_OK) {
|
||||
// OpmLog::error only prints from rank 0
|
||||
OpmLog::error(fmt::format("damariswriter::setParameter() (rank:{}) "
|
||||
OpmLog::warning(fmt::format("damariswriter::setParameter() (rank:{}) "
|
||||
"damaris_parameter_set(\"{}\",...)", rank, field));
|
||||
}
|
||||
|
||||
@ -67,8 +65,7 @@ int write(const char* field, int rank, const void* data)
|
||||
{
|
||||
int dam_err = damaris_write(field, data);
|
||||
if (dam_err != DAMARIS_OK) {
|
||||
// OpmLog::error only prints from rank 0
|
||||
OpmLog::error(fmt::format("damariswriter::write() : ( rank:{}) "
|
||||
OpmLog::warning(fmt::format("damariswriter::write() : ( rank:{}) "
|
||||
"damaris_write({}, ...), Damaris Error: {} ",
|
||||
rank, field, damaris_error_string(dam_err)));
|
||||
}
|
||||
@ -80,7 +77,7 @@ int endIteration(int rank)
|
||||
{
|
||||
int dam_err = damaris_end_iteration();
|
||||
if (dam_err != DAMARIS_OK) {
|
||||
OpmLog::error(fmt::format("damariswriter::endIteration() : ( rank:{}) "
|
||||
OpmLog::warning(fmt::format("damariswriter::endIteration() : ( rank:{}) "
|
||||
"damaris_end_iteration(), Damaris Error: {} ",
|
||||
rank, damaris_error_string(dam_err)));
|
||||
}
|
||||
|
@ -291,10 +291,6 @@ public:
|
||||
|
||||
// It does not seem I can test for what type of data is present (double or int)
|
||||
// in the std::variant within the data::CellData, so I will use a try catch block.
|
||||
// Although, only MPI_RANK and GLOBAL_CELL_INDEX are set as integer types (in the
|
||||
// XML file) so it is a moot point.
|
||||
// We could use damaris_get_type() to check what the type is specified as
|
||||
// within the Damaris XML file
|
||||
try {
|
||||
if (dataCol.data<double>().size() >= this->numElements_) {
|
||||
dam_err_ = DamarisOutput::write(name.c_str(), rank_,
|
||||
@ -304,7 +300,7 @@ public:
|
||||
}
|
||||
}
|
||||
catch (std::bad_variant_access const& ex) {
|
||||
// Not a std::vector<double>
|
||||
// Not a std::vector<double>, must be a std::vector<int>
|
||||
if (dataCol.data<int>().size() >= this->numElements_) {
|
||||
dam_err_ = DamarisOutput::write(name.c_str(), rank_,
|
||||
dataCol.data<int>().data()) ;
|
||||
@ -363,11 +359,13 @@ private:
|
||||
void setGlobalIndexForDamaris ()
|
||||
{
|
||||
// Use damaris_set_position to set the offset in the global size of the array.
|
||||
// This is used so that output functionality (e.g. HDF5Store) knows global offsets of the data of the ranks
|
||||
// setPosition("PRESSURE", comm.rank(), elements_rank_offsets_[comm.rank()]);
|
||||
// This is used so that output functionality (e.g. HDF5Store) knows the global offsets of
|
||||
// the data of the ranks data.
|
||||
dam_err_ = DamarisOutput::setPosition("GLOBAL_CELL_INDEX", rank_, elements_rank_offsets_[rank_]);
|
||||
|
||||
// Set the size of the MPI variable
|
||||
// This is an example of writing to the Damaris shared memory directly (i.e. we allocate the
|
||||
// variable directly in the shared memory region and do not use damaris_write() to copy data there.
|
||||
// The shared memory is given back to Damaris when the DamarisVarInt goes out of scope.
|
||||
// N.B. MPI_RANK is only saved to HDF5 if --damaris-save-mesh-to-hdf=true is specified
|
||||
DamarisVarInt mpi_rank_var(1, {"n_elements_local"}, "MPI_RANK", rank_);
|
||||
mpi_rank_var.setDamarisPosition({static_cast<int64_t>(elements_rank_offsets_[rank_])});
|
||||
@ -385,12 +383,6 @@ private:
|
||||
dam_err_ = DamarisOutput::write("GLOBAL_CELL_INDEX", rank_, local_to_global_filled.data());
|
||||
}
|
||||
|
||||
// This is an example of writing to the Damaris shared memory directly (i.e. not using
|
||||
// damaris_write() to copy data there)
|
||||
// We will add the MPI rank value directly into shared memory using the DamarisVar
|
||||
// wrapper of the C based Damaris API.
|
||||
// The shared memory is given back to Damaris when the DamarisVarInt goes out of scope.
|
||||
// DamarisVarInt mpi_rank_var_test(1, {"n_elements_local"}, "MPI_RANK", rank_);
|
||||
mpi_rank_var.setDamarisParameterAndShmem( {this->numElements_ } ) ;
|
||||
// Fill the created memory area
|
||||
std::fill(mpi_rank_var.data(), mpi_rank_var.data() + numElements_, rank_);
|
||||
|
@ -55,7 +55,7 @@ bool FileExists(const std::string& filename_in,
|
||||
{
|
||||
// From c++17 : std::filesystem::exists(filename_in);
|
||||
|
||||
int retint = 0;
|
||||
int retint = 1;
|
||||
std::ifstream filestr;
|
||||
bool file_exists = false;
|
||||
|
||||
@ -65,7 +65,6 @@ bool FileExists(const std::string& filename_in,
|
||||
|
||||
if (comm.rank() == 0) {
|
||||
filestr.open(filename_in);
|
||||
file_exists = true;
|
||||
if(filestr.fail()) {
|
||||
retint = 0;
|
||||
} else {
|
||||
@ -75,9 +74,10 @@ bool FileExists(const std::string& filename_in,
|
||||
}
|
||||
|
||||
comm.broadcast(&retint, 1, 0);
|
||||
|
||||
if (retint == 1) {
|
||||
file_exists = true;
|
||||
} else {
|
||||
file_exists = false;
|
||||
}
|
||||
|
||||
return (file_exists);
|
||||
@ -86,7 +86,6 @@ bool FileExists(const std::string& filename_in,
|
||||
void DamarisSettings::SetRandString(void)
|
||||
{
|
||||
// rand_value_str_ = damaris::Environment::GetMagicNumber(comm); // requires Damaris >= v1.9.2
|
||||
|
||||
// We will create a random value.
|
||||
// Seed with a real random value, if available
|
||||
std::random_device r;
|
||||
@ -117,7 +116,7 @@ DamarisSettings::getKeywords([[maybe_unused]] const Parallel::Communication& com
|
||||
std::string disableParaviewXMLfin("--");
|
||||
|
||||
std::string publishToPython_str("#"); // to be changed to the name of the PyScript XML element
|
||||
#ifdef HAVE_PYTHON_ENABLED
|
||||
|
||||
// Test if input Python file exists and set the name of the script for <variable ... script="" > )XML elements
|
||||
if (pythonFilename_ != ""){
|
||||
if (FileExists(pythonFilename_, comm)) {
|
||||
@ -130,13 +129,7 @@ DamarisSettings::getKeywords([[maybe_unused]] const Parallel::Communication& com
|
||||
disablePythonXMLfin = std::string("--");
|
||||
}
|
||||
}
|
||||
#else
|
||||
OpmLog::info(fmt::format("INFO: Opm::DamarisOutput::DamarisKeywords() : Python is not enabled in the Damaris library. "
|
||||
"The commandline --damaris-python-script={} will be set to empty string", pythonFilename_));
|
||||
pythonFilename_.clear();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PARAVIEW_ENABLED
|
||||
// Test if input Paraview Python file exists
|
||||
if (paraviewPythonFilename_ != ""){
|
||||
if (FileExists(paraviewPythonFilename_, comm)) {
|
||||
@ -148,25 +141,20 @@ DamarisSettings::getKeywords([[maybe_unused]] const Parallel::Communication& com
|
||||
disableParaviewXMLfin = std::string("--");
|
||||
}
|
||||
}
|
||||
#else
|
||||
OpmLog::info(fmt::format("Opm::DamarisOutput::DamarisKeywords() : Paraview is not enabled in the Damaris library. "
|
||||
"The commandline --damaris-python-paraview-script={} will be set to empty string",
|
||||
paraviewPythonFilename_));
|
||||
paraviewPythonFilename_.clear();
|
||||
#endif
|
||||
|
||||
// Flag error if both scripts are enabled
|
||||
if ((pythonFilename_.size() > 0) && (paraviewPythonFilename_.size() > 0) )
|
||||
{
|
||||
// A work around of this issue is to remove the Paraview mpi4py library (use print(inspect.getfile(mpi4py)))
|
||||
// and then possibly not use mpi4py in the Paraview script code. OR try to install paraview mpi4py with headers.
|
||||
// The Python script will issue: ERROR: Initialiazation via BOOST_PYTHON_MODULE(server) failed at import_mpi4py()
|
||||
OPM_THROW(std::runtime_error, "ERROR: Both the Python (--damaris-python-script command line argument) and Paraview Python "
|
||||
"(--damaris-python-paraview-script command line argument) scripts are valid, however only one "
|
||||
"type of analysis is supported in a single simulation (due to Paraview installing mpi4py library "
|
||||
"locally and without header files). "
|
||||
"Please choose one or the other method of analysis for now. Exiting." );
|
||||
}
|
||||
|
||||
|
||||
std::string saveMeshToHDF5_str("#");
|
||||
if (saveMeshToHDF5_ == true) {
|
||||
enableDamarisOutputCollective_ = false ;
|
||||
|
@ -125,7 +125,6 @@ getSetOfIncludedVariables(void)
|
||||
// Use while loop to check the getline() function condition.
|
||||
while (std::getline(ss, tstr, ',')) {
|
||||
//remove whitespace
|
||||
// tstr.erase(std::remove_if(tstr.begin(), tstr.end(), ::isspace), tstr.end());
|
||||
std::string::iterator end_pos = std::remove(tstr.begin(), tstr.end(), ' ');
|
||||
tstr.erase(end_pos, tstr.end());
|
||||
// place in set (no duplicates possible in set and no empty string)
|
||||
|
Loading…
Reference in New Issue
Block a user