Update 1 for code after code review of PR 4889

This commit is contained in:
Josh Bowden 2023-12-08 21:22:55 +01:00
parent 0f1d31c88a
commit 54d6db6f35
10 changed files with 476 additions and 457 deletions

View File

@ -595,6 +595,7 @@ if (Damaris_FOUND AND MPI_FOUND)
list (APPEND PUBLIC_HEADER_FILES opm/simulators/utils/DamarisKeywords.hpp)
list (APPEND PUBLIC_HEADER_FILES ebos/damariswriter.hh)
list (APPEND PUBLIC_HEADER_FILES opm/simulators/utils/DamarisVar.hpp)
list (APPEND PUBLIC_HEADER_FILES opm/simulators/utils/GridDataOutput.hpp)
endif()
if(HDF5_FOUND)

View File

@ -92,7 +92,7 @@ struct DamarisDedicatedNodes {
using type = UndefinedProperty;
};
template<class TypeTag, class MyTypeTag>
struct DamarisSharedMemeorySizeBytes {
struct DamarisSharedMemorySizeBytes {
using type = UndefinedProperty;
};
template<class TypeTag, class MyTypeTag>
@ -136,7 +136,9 @@ class DamarisWriter : public EclGenericWriter<GetPropType<TypeTag, Properties::G
using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
using BaseType = EclGenericWriter<Grid,EquilGrid,GridView,ElementMapper,Scalar>;
typedef Opm::DamarisOutput::DamarisVar<int> DamarisVarInt ;
typedef Opm::DamarisOutput::DamarisVar<double> DamarisVarDbl ;
public:
static void registerParameters()
{
@ -166,7 +168,7 @@ public:
EWOMS_REGISTER_PARAM(TypeTag, int, DamarisDedicatedNodes,
"Set the number of dedicated nodes (full nodes) that should be used for Damaris processing (per simulation). \n \
Must divide evenly into the number of simulation nodes.");
EWOMS_REGISTER_PARAM(TypeTag, long, DamarisSharedMemeorySizeBytes,
EWOMS_REGISTER_PARAM(TypeTag, long, DamarisSharedMemorySizeBytes,
"Set the size of the shared memory buffer used for IPC between the simulation and the Damaris resources. \n \
Needs to hold all the variables published, possibly over multiple simulation iterations.");
@ -256,23 +258,23 @@ public:
temp_int64_t[0] = static_cast<int64_t>(this->elements_rank_offsets_[rank_]);
dam_err_ = damaris_set_position("PRESSURE", temp_int64_t);
if (dam_err_ != DAMARIS_OK && rank_ == 0) {
OpmLog::error(fmt::format("ERORR: damariswriter::writeOutput() : ( rank:{})"
"damaris_set_position(PRESSURE, ...), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
OpmLog::error(fmt::format("damariswriter::writeOutput() : ( rank:{})"
"damaris_set_position(PRESSURE, ...), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
}
dam_err_ = damaris_write("PRESSURE", (void*)this->damarisOutputModule_->getPRESSURE_ptr());
if (dam_err_ != DAMARIS_OK) {
OpmLog::error(fmt::format("ERORR: damariswriter::writeOutput() : ( rank:{}) "
"damaris_write(PRESSURE, ...), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
OpmLog::error(fmt::format("damariswriter::writeOutput() : ( rank:{}) "
"damaris_write(PRESSURE, ...), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
}
dam_err_ = damaris_end_iteration();
if (dam_err_ != DAMARIS_OK) {
OpmLog::error(fmt::format("ERORR: damariswriter::writeOutput() : ( rank:{}) "
"damaris_end_iteration(), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
OpmLog::error(fmt::format("damariswriter::writeOutput() : ( rank:{}) "
"damaris_end_iteration(), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
}
}
} // end of ! isSubstep
@ -312,18 +314,23 @@ private:
}
if (dam_err_ != DAMARIS_OK) {
OpmLog::error(fmt::format("ERORR: damariswriter::writeOutput() :"
"( rank:{}) damaris_write(GLOBAL_CELL_INDEX, ...), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
OpmLog::error(fmt::format("damariswriter::writeOutput() :"
"( rank:{}) damaris_write(GLOBAL_CELL_INDEX, ...), Damaris Error: {} ",
rank_, damaris_error_string(dam_err_) ));
}
// 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 vrapper C based Damaris API
// 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 on object deletion - i.e. when the unique_ptr goes out of scope.
std::unique_ptr<Opm::DamarisOutput::DamarisVar<int>> mpi_rank_var(new Opm::DamarisOutput::DamarisVar<int>(1, {std::string("n_elements_local")}, std::string("MPI_RANK"), rank_)) ;
// N.B. we have not set any offset values, so HDF5 collective nad Dask arrays cannot be used.
//auto mpi_rank_var = std::make_unique<Opm::DamarisOutput::DamarisVar<int>>(
// 1, {std::string("n_elements_local")}, std::string("MPI_RANK"), rank_)) ;
// std::unique_ptr<Opm::DamarisOutput::DamarisVar<int>>
std::unique_ptr<DamarisVarInt> mpi_rank_var( new DamarisVarInt(1,
{std::string("n_elements_local")},
std::string("MPI_RANK"), rank_) ) ;
// N.B. we have not set any offset values, so HDF5 collective and Dask arrays cannot be used.
mpi_rank_var->SetDamarisParameterAndShmem( {this->numElements_ } ) ;
int * shmem_mpi_ptr = mpi_rank_var->data_ptr() ;
int* shmem_mpi_ptr = mpi_rank_var->data_ptr() ;
// Fill the created memory area
for (int i = 0 ; i < this->numElements_; i++ )
{
@ -361,8 +368,8 @@ private:
// ToDo: Do we need to check that local ranks are 0 based ?
int temp_int = static_cast<int>(elements_rank_sizes[rank_]);
dam_err_ = damaris_parameter_set("n_elements_local", &temp_int, sizeof(int));
if (dam_err_ != DAMARIS_OK && rank_ == 0) {
OpmLog::error("Damaris library produced an error result for "
if (dam_err_ != DAMARIS_OK) {
OpmLog::error("( rank:" + std::to_string(rank_)+") Damaris library produced an error result for "
"damaris_parameter_set(\"n_elements_local\", &temp_int, sizeof(int));");
}
// Damaris parameters only support int data types. This will limit models to be under size of 2^32-1 elements
@ -370,13 +377,16 @@ private:
if( n_elements_global_max <= std::numeric_limits<int>::max() ) {
temp_int = static_cast<int>(n_elements_global_max);
dam_err_ = damaris_parameter_set("n_elements_total", &temp_int, sizeof(int));
if (dam_err_ != DAMARIS_OK && rank_ == 0) {
OpmLog::error("Damaris library produced an error result for "
if (dam_err_ != DAMARIS_OK) {
OpmLog::error("( rank:" + std::to_string(rank_)+") Damaris library produced an error result for "
"damaris_parameter_set(\"n_elements_total\", &temp_int, sizeof(int));");
}
} else {
OpmLog::error(fmt::format("The size of the global array ({}) is greater than what a Damaris paramater type supports ({}). ", n_elements_global_max, std::numeric_limits<int>::max() ));
assert( n_elements_global_max <= std::numeric_limits<int>::max() ) ;
OpmLog::error(fmt::format("( rank:{} ) The size of the global array ({}) is"
"greater than what a Damaris paramater type supports ({}). ",
rank_, n_elements_global_max, std::numeric_limits<int>::max() ));
// assert( n_elements_global_max <= std::numeric_limits<int>::max() ) ;
OPM_THROW(std::runtime_error, "setupDamarisWritingPars() n_elements_global_max > std::numeric_limits<int>::max() " + std::to_string(dam_err_));
}
// Use damaris_set_position to set the offset in the global size of the array.
@ -384,17 +394,24 @@ private:
int64_t temp_int64_t[1];
temp_int64_t[0] = static_cast<int64_t>(elements_rank_offsets[rank_]);
dam_err_ = damaris_set_position("PRESSURE", temp_int64_t);
if (dam_err_ != DAMARIS_OK && rank_ == 0) {
OpmLog::error("Damaris library produced an error result for "
if (dam_err_ != DAMARIS_OK) {
OpmLog::error("( rank:" + std::to_string(rank_)+") Damaris library produced an error result for "
"damaris_set_position(\"PRESSURE\", temp_int64_t);");
}
dam_err_ = damaris_set_position("GLOBAL_CELL_INDEX", temp_int64_t);
if (dam_err_ != DAMARIS_OK && rank_ == 0) {
OpmLog::error("Damaris library produced an error result for "
if (dam_err_ != DAMARIS_OK) {
OpmLog::error("( rank:" + std::to_string(rank_)+") Damaris library produced an error result for "
"damaris_set_position(\"GLOBAL_CELL_INDEX\", temp_int64_t);");
}
std::unique_ptr<Opm::DamarisOutput::DamarisVar<int>> mpi_rank_var(new Opm::DamarisOutput::DamarisVar<int>(1, {std::string("n_elements_local")}, std::string("MPI_RANK"), rank_)) ;
//auto mpi_rank_var = std::make_unique<Opm::DamarisOutput::DamarisVar<int>>(
// 1, {std::string("n_elements_local")}, std::string("MPI_RANK"), rank_)) ;
// std::unique_ptr<Opm::DamarisOutput::DamarisVar<int>>
// mpi_rank_var(new Opm::DamarisOutput::DamarisVar<int>(1, {std::string("n_elements_local")}, std::string("MPI_RANK"), rank_)) ;
std::unique_ptr<DamarisVarInt> mpi_rank_var( new DamarisVarInt(1,
{std::string("n_elements_local")},
std::string("MPI_RANK"), rank_) ) ;
mpi_rank_var->SetDamarisPosition({*temp_int64_t}) ;
}
@ -455,9 +472,9 @@ private:
// </group>
std::unique_ptr<Opm::DamarisOutput::DamarisVar<int>> var_connectivity(new Opm::DamarisOutput::DamarisVar<int>(1, {std::string("n_connectivity_ph")}, std::string("topologies/topo/elements/connectivity"), rank_)) ;
var_connectivity->SetDamarisParameterAndShmem( { geomData.getNCorners() } ) ;
var_connectivity->SetDamarisParameterAndShmem({ geomData.getNCorners()}) ;
std::unique_ptr<Opm::DamarisOutput::DamarisVar<int>> var_offsets(new Opm::DamarisOutput::DamarisVar<int>(1, {std::string("n_offsets_types_ph")}, std::string("topologies/topo/elements/offsets"), rank_)) ;
var_offsets->SetDamarisParameterAndShmem( { geomData.getNCells() } ) ;
var_offsets->SetDamarisParameterAndShmem({ geomData.getNCells()}) ;
std::unique_ptr<Opm::DamarisOutput::DamarisVar<char>> var_types(new Opm::DamarisOutput::DamarisVar<char>(1, {std::string("n_offsets_types_ph")}, std::string("topologies/topo/elements/types"), rank_)) ;
var_types->ParameterIsSet() ;
var_types->SetPointersToDamarisShmem() ;
@ -468,19 +485,19 @@ private:
i = geomData.writeConnectivity(var_connectivity->data_ptr(), vtkorder) ;
if ( i != geomData.getNCorners())
DUNE_THROW(Dune::IOError, geomData.getError() );
DUNE_THROW(Dune::IOError, geomData.getError());
i = geomData.writeOffsetsCells(var_offsets->data_ptr()) ;
i = geomData.writeOffsetsCells(var_offsets->data_ptr());
if ( i != geomData.getNCells()+1)
DUNE_THROW(Dune::IOError,geomData.getError() );
DUNE_THROW(Dune::IOError,geomData.getError());
i = geomData.writeCellTypes(var_types->data_ptr()) ;
if ( i != geomData.getNCells())
DUNE_THROW(Dune::IOError,geomData.getError() );
DUNE_THROW(Dune::IOError,geomData.getError());
}
catch (std::exception& e)
{
std :: cout << e.what() << std::endl;
OpmLog::error(e.what());
}
}

View File

@ -422,8 +422,8 @@ struct DamarisDedicatedNodes<TypeTag, TTag::EclBaseProblem> {
static constexpr int value = 0;
};
template<class TypeTag>
struct DamarisSharedMemeorySizeBytes<TypeTag, TTag::EclBaseProblem> {
static constexpr long value = 536870912;
struct DamarisSharedMemorySizeBytes<TypeTag, TTag::EclBaseProblem> {
static constexpr long value = 536870912; // 512 MB
};
template<class TypeTag>
struct DamarisLogLevel<TypeTag, TTag::EclBaseProblem> {

View File

@ -240,19 +240,25 @@ void Main::setupDamaris(const std::string& outputDir )
ensureOutputDirExists(outputDir);
}
std::map<std::string, std::string> find_replace_map ;
find_replace_map = Opm::DamarisOutput::DamarisKeywords<PreTypeTag>(EclGenericVanguard::comm(), outputDir);
//const auto find_replace_map;
//const auto find_replace_map = Opm::DamarisOutput::DamarisKeywords<PreTypeTag>(EclGenericVanguard::comm(), outputDir);
std::map<std::string, std::string> find_replace_map;
find_replace_map = Opm::DamarisOutput::getDamarisKeywords<PreTypeTag>(EclGenericVanguard::comm(), outputDir);
// By default EnableDamarisOutputCollective is true so all simulation results will
// be written into one single file for each iteration using Parallel HDF5.
// It set to false, FilePerCore mode is used in Damaris, then simulation results in each
// If set to false, FilePerCore mode is used in Damaris, then simulation results in each
// node are aggregated by dedicated Damaris cores and stored to separate files per Damaris core.
// Irrespective of mode, output is written asynchronously at the end of each timestep.
// Using the ModifyModel class to set the XML file for Damaris.
DamarisOutput::initializeDamaris(EclGenericVanguard::comm(), EclGenericVanguard::comm().rank(), find_replace_map);
DamarisOutput::initializeDamaris(EclGenericVanguard::comm(),
EclGenericVanguard::comm().rank(),
find_replace_map);
int is_client;
MPI_Comm new_comm;
int err = damaris_start(&is_client);
// damaris_start() is where the Damaris Server ranks will block, until damaris_stop()
// is called from the client ranks
int err = damaris_start(&is_client);
isSimulationRank_ = (is_client > 0);
if (isSimulationRank_ && err == DAMARIS_OK) {
damaris_client_comm_get(&new_comm);

View File

@ -344,7 +344,7 @@ private:
}
if (enableDamarisOutput_) {
this->setupDamaris(outputDir);
this->setupDamaris(outputDir); // Damaris server ranks will block here until damaris_stop() is called by client ranks
}
#endif // HAVE_DAMARIS

View File

@ -1,6 +1,7 @@
/*
Copyright 2021 Equinor.
Copyright 2023 Inria.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
@ -48,32 +49,32 @@ bool FileExists(const std::string& filename_in,
{
// From c++17 : std::filesystem::exists(filename_in);
int retint = 0 ;
std::ifstream filestr ;
bool file_exists = false ;
int retint = 0;
std::ifstream filestr;
bool file_exists = false;
if ((filename_in.length() == 0) || (filename_in == "#") ) {
return file_exists ;
return file_exists;
}
if (comm.rank() == 0) {
filestr.open(filename_in);
file_exists = true ;
file_exists = true;
if(filestr.fail()) {
retint = 0 ;
retint = 0;
} else {
retint = 1 ;
filestr.close() ;
retint = 1;
filestr.close();
}
}
comm.broadcast(&retint,1,0);
comm.broadcast(&retint, 1, 0);
if (retint == 1) {
file_exists = true ;
file_exists = true;
}
return (file_exists) ;
return (file_exists);
}
@ -81,51 +82,53 @@ std::map<std::string, std::string>
DamarisSettings::getKeywords([[maybe_unused]] const Parallel::Communication& comm,
const std::string& OutputDir)
{
std::string saveToHDF5_str("MyStore") ;
if (! saveToDamarisHDF5 ) saveToHDF5_str = "#" ;
std::string saveToHDF5_str("MyStore");
if (! saveToDamarisHDF5 ){
saveToHDF5_str = "#";
}
// These strings are used to comment out an XML element if it is not reqired
std::string disablePythonXMLstart("!--") ;
std::string disablePythonXMLfin("--") ;
std::string disableParaviewXMLstart("!--") ;
std::string disableParaviewXMLfin("--") ;
std::string disablePythonXMLstart("!--");
std::string disablePythonXMLfin("--");
std::string disableParaviewXMLstart("!--");
std::string disableParaviewXMLfin("--");
std::string publishToPython_str("#") ; // to be changed to the name of the PyScript XML element
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)) {
publishToPython_str="PythonScript" ; // the name of the PyScript XML element
disablePythonXMLstart.clear() ;
disablePythonXMLfin.clear() ;
publishToPython_str="PythonScript"; // the name of the PyScript XML element
disablePythonXMLstart.clear();
disablePythonXMLfin.clear();
} else {
pythonFilename.clear() ; // set to empty if it does not exist
disablePythonXMLstart = std::string("!--") ;
disablePythonXMLfin = std::string("--") ;
pythonFilename.clear(); // set to empty if it does not exist
disablePythonXMLstart = std::string("!--");
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() ;
pythonFilename.clear();
#endif
#ifdef HAVE_PARAVIEW_ENABLED
// Test if input Paraview Python file exists
if (paraviewPythonFilename != ""){
if (FileExists(paraviewPythonFilename, comm)) {
disableParaviewXMLstart.clear() ;
disableParaviewXMLfin.clear() ;
disableParaviewXMLstart.clear();
disableParaviewXMLfin.clear();
} else {
paraviewPythonFilename.clear() ; // set to empty if it does not exist
disableParaviewXMLstart = std::string("!--") ;
disableParaviewXMLfin = std::string("--") ;
paraviewPythonFilename.clear(); // set to empty if it does not exist
disableParaviewXMLstart = std::string("!--");
disableParaviewXMLfin = std::string("--");
}
}
#else
OpmLog::info(fmt::format("INFO: 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() ;
paraviewPythonFilename.clear();
#endif
// Flag error if both scripts are enabled
@ -133,18 +136,18 @@ DamarisSettings::getKeywords([[maybe_unused]] const Parallel::Communication& com
{
// 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.
std::cerr << "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::endl ;
std::exit(-1) ;
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 damarisOutputCollective_str;
if (enableDamarisOutputCollective) {
damarisOutputCollective_str = "Collective" ;
damarisOutputCollective_str = "Collective";
} else {
damarisOutputCollective_str = "FilePerCore" ;
damarisOutputCollective_str = "FilePerCore";
}
std::string simName_str;
@ -152,7 +155,7 @@ DamarisSettings::getKeywords([[maybe_unused]] const Parallel::Communication& com
// Having a different simulation name is important if multiple simulations
// are running on the same node, as it is used to name the simulations shmem area
// and when one sim finishes it removes its shmem file.
// simName_str = damaris::Environment::GetMagicNumber(comm) ;
// simName_str = damaris::Environment::GetMagicNumber(comm);
if (simName_str.empty()) {
// We will add a random value as GetMagicNumber(comm) requires Damaris v1.9.2
// Seed with a real random value, if available
@ -161,43 +164,43 @@ DamarisSettings::getKeywords([[maybe_unused]] const Parallel::Communication& com
std::default_random_engine e1(r());
std::uniform_int_distribution<int> uniform_dist(0, std::numeric_limits<int>::max());
int rand_int = uniform_dist(e1);
simName_str = "opm-flow-" + std::to_string(rand_int) ;
simName_str = "opm-flow-" + std::to_string(rand_int);
} else {
simName_str = "opm-flow-" + simName_str ;
simName_str = "opm-flow-" + simName_str;
}
} else {
simName_str = damarisSimName ;
simName_str = damarisSimName;
}
if ((nDamarisCores > 0) && (nDamarisNodes > 0))
{
nDamarisNodes = 0 ; // Default is to use Damaris Cores
nDamarisNodes = 0; // Default is to use Damaris Cores
}
std::string nDamarisCores_str;
if ( nDamarisCores != 0 ) {
nDamarisCores_str = std::to_string(nDamarisCores);
} else {
nDamarisCores_str = "0" ;
nDamarisCores_str = "0";
}
std::string nDamarisNodes_str;
if ( nDamarisNodes != 0 ) {
nDamarisNodes_str = std::to_string(nDamarisNodes);
} else {
nDamarisNodes_str = "0" ;
nDamarisNodes_str = "0";
}
std::string shmemSizeBytes_str;
if (shmemSizeBytes != 0) {
shmemSizeBytes_str = std::to_string(shmemSizeBytes);
} else {
shmemSizeBytes_str = "536870912" ;
shmemSizeBytes_str = "536870912"; // 512 MB
}
std::string logLevel_str(damarisLogLevel) ;
std::string logFlush_str("false") ;
std::string logLevel_str(damarisLogLevel);
std::string logFlush_str("false");
if ((logLevel_str == "debug") || (logLevel_str == "trace") ) {
logFlush_str = "true" ;
logFlush_str = "true";
}
std::map<std::string, std::string> damaris_keywords = {

View File

@ -38,28 +38,28 @@
namespace Opm::DamarisOutput
{
/**
* Returns true if the file exists.
* Tests to see if filename string is empty
* or the "#" character and if so returns false.
* Tests for file existance on ranl 0 and
* passes result via MPI to all other ranks.
*/
/**
* Returns true if the file exists.
* Tests to see if filename string is empty
* or the "#" character and if so returns false.
* Tests for file existance on rank 0 and
* passes result via MPI to all other ranks.
*/
bool FileExists(const std::string& filename_in,
const Parallel::Communication& comm);
struct DamarisSettings {
bool enableDamarisOutputCollective = true ;
bool saveToDamarisHDF5 = true ;
bool enableDamarisOutputCollective = true;
bool saveToDamarisHDF5 = true;
std::string pythonFilename;
std::string paraviewPythonFilename;
std::string damarisSimName; // empty defaults to opm-sim-<magic_number>
std::string damarisLogLevel = "info";
std::string damarisDaskFile = "" ;
int nDamarisCores = 1 ;
int nDamarisNodes = 0 ;
long shmemSizeBytes = 536870912 ;
std::string damarisDaskFile = "";
int nDamarisCores = 1;
int nDamarisNodes = 0;
long shmemSizeBytes = 536870912; // 512 MB
std::map<std::string, std::string>
getKeywords(const Parallel::Communication& comm,
@ -67,28 +67,28 @@ struct DamarisSettings {
};
/**
* Creates the map of search strings and repacement strings that will be used to
* modify a templated Damaris XML file which will be used to intialize Damaris.
* This function will access all the OPM flow comand line arguments related to
* Damaris and perform checks and logic so as to create a valid XML file.
* N.B. The created XML file can be overridden using an environment variable
* FLOW_DAMARIS_XML_FILE that points to a Damaris XML file.
*/
* Creates the map of search strings and repacement strings that will be used to
* modify a templated Damaris XML file which will be used to intialize Damaris.
* This function will access all the OPM flow comand line arguments related to
* Damaris and perform checks and logic so as to create a valid XML file.
* N.B. The created XML file can be overridden using an environment variable
* FLOW_DAMARIS_XML_FILE that points to a Damaris XML file.
*/
template<class TypeTag>
std::map<std::string, std::string>
DamarisKeywords(const Parallel::Communication& comm, const std::string& OutputDir)
getDamarisKeywords(const Parallel::Communication& comm, const std::string& OutputDir)
{
DamarisSettings settings;
// Get all of the Damaris keywords (except for --enable-damaris, which is used in simulators/flow/Main.hpp)
// These command line arguments are defined in ebos/damariswriter.hh and defaults are set in ebos/eclproblem_properties.hh
settings.enableDamarisOutputCollective = EWOMS_GET_PARAM(TypeTag, bool, EnableDamarisOutputCollective) ;
settings.enableDamarisOutputCollective = EWOMS_GET_PARAM(TypeTag, bool, EnableDamarisOutputCollective);
settings.saveToDamarisHDF5 = EWOMS_GET_PARAM(TypeTag, bool, DamarisSaveToHdf);
settings.pythonFilename = EWOMS_GET_PARAM(TypeTag, std::string, DamarisPythonScript);
settings.paraviewPythonFilename = EWOMS_GET_PARAM(TypeTag, std::string, DamarisPythonParaviewScript);
settings.damarisSimName = EWOMS_GET_PARAM(TypeTag, std::string, DamarisSimName);
settings.nDamarisCores = EWOMS_GET_PARAM(TypeTag, int, DamarisDedicatedCores);
settings.nDamarisNodes = EWOMS_GET_PARAM(TypeTag, int, DamarisDedicatedNodes);
settings.shmemSizeBytes = EWOMS_GET_PARAM(TypeTag, long, DamarisSharedMemeorySizeBytes);
settings.shmemSizeBytes = EWOMS_GET_PARAM(TypeTag, long, DamarisSharedMemorySizeBytes);
settings.damarisLogLevel = EWOMS_GET_PARAM(TypeTag, std::string, DamarisLogLevel);
settings.damarisDaskFile = EWOMS_GET_PARAM(TypeTag, std::string, DamarisDaskFile);
return settings.getKeywords(comm, OutputDir);

View File

@ -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) ));
}
}
}

View File

@ -47,32 +47,32 @@ namespace Opm
* They are simple string values that may reference other XML elements (and could be checked for existence etc.)
*/
class DamarisVarXMLAttributes {
std::string layout_ ; //!< Reference string to the XML attribute layout being used to describe the shape of the variable. This is a required attribute.
std::string mesh_ ; //!< Reference string to the XML attribute mesh element - the mesh is used to define the spatial layout of data and is used by visualization backends to generate 2D/3D model images
std::string type_ ; //!< Reference string to the XML attribute type of data - "scalar" or "vector" (others tensor maybe). TODO: check if this attribute is used by the Damaris library anywhere.
std::string visualizable_ ; //!< Reference string to the XML attribute property that data can be sent to vis backends - "true" | "false"
std::string unit_ ; //!< Reference string to the XML attribute element denoting unit of the data
std::string time_varying_ ; //!< Reference string to the XML attribute to indicate if data changes over iterations - "true" | "false"
std::string centering_ ; //!< Reference string to the XML attribute to indicate where data aligns on a mesh - "zonal" | "nodal"
std::string store_ ; //!< Reference string to the XML attribute to indicate if data should be passed to I/O store (e.g. to HDF5 plugin)
std::string script_ ; //!< Reference string to the XML attribute to indicate if data should be published as Python NumPy data
std::string select_mem_ ; //!< Reference string to the XML attribute select. The referenced variables data is used as indices to select dat from memory to reorder output in the collective HDF5 data writer (Damaris version 1.8+)
std::string select_file_ ; //!< Reference string to the XML attribute select. The referenced variables data is used as indices to select positions in the dataset file to reorder output in the collective HDF5 data writer (Damaris version 1.8+)
std::string select_subset_ ; //!< Reference string to the XML attribute select. Used to specify the output dataset shape and how much data each rank contributes to it and the global offsets to the ranks data (Damaris version 1.8+)
std::string layout_; //!< Reference string to the XML attribute layout being used to describe the shape of the variable. This is a required attribute.
std::string mesh_; //!< Reference string to the XML attribute mesh element - the mesh is used to define the spatial layout of data and is used by visualization backends to generate 2D/3D model images
std::string type_; //!< Reference string to the XML attribute type of data - "scalar" or "vector" (others tensor maybe). TODO: check if this attribute is used by the Damaris library anywhere.
std::string visualizable_; //!< Reference string to the XML attribute property that data can be sent to vis backends - "true" | "false"
std::string unit_; //!< Reference string to the XML attribute element denoting unit of the data
std::string time_varying_; //!< Reference string to the XML attribute to indicate if data changes over iterations - "true" | "false"
std::string centering_; //!< Reference string to the XML attribute to indicate where data aligns on a mesh - "zonal" | "nodal"
std::string store_; //!< Reference string to the XML attribute to indicate if data should be passed to I/O store (e.g. to HDF5 plugin)
std::string script_; //!< Reference string to the XML attribute to indicate if data should be published as Python NumPy data
std::string select_mem_; //!< Reference string to the XML attribute select. The referenced variables data is used as indices to select dat from memory to reorder output in the collective HDF5 data writer (Damaris version 1.8+)
std::string select_file_; //!< Reference string to the XML attribute select. The referenced variables data is used as indices to select positions in the dataset file to reorder output in the collective HDF5 data writer (Damaris version 1.8+)
std::string select_subset_; //!< Reference string to the XML attribute select. Used to specify the output dataset shape and how much data each rank contributes to it and the global offsets to the ranks data (Damaris version 1.8+)
public:
DamarisVarXMLAttributes(){
// Additional data needed to complete an XML <variable> element
layout_ = "" ;
mesh_ = "" ;
type_ = "scalar" ; // This is probably not needed as vector data is defined using the Layout paramter. Could be useful for cross checking
layout_ = "";
mesh_ = "";
type_ = "scalar"; // This is probably not needed as vector data is defined using the Layout paramter. Could be useful for cross checking
visualizable_ = "false";
unit_ = "" ;
unit_ = "";
time_varying_ = "true";
centering_ = "zonal" ;
store_ = "" ;
script_ = "" ;
select_mem_ = "" ;
centering_ = "zonal";
store_ = "";
script_ = "";
select_mem_ = "";
}
/**
@ -80,41 +80,41 @@ namespace Opm
*/
std::string ReturnXMLForVariable ( void )
{
std::ostringstream var_sstr ;
std::ostringstream var_sstr;
var_sstr << " layout=\"" << this->layout_ << "\"" ;
if (this->mesh_ != "") var_sstr << " mesh=\"" << this->mesh_ << "\"" ;
if (this->type_ != "") var_sstr << " type=\"" << this->type_ << "\"" ;
if (this->visualizable_ != "") var_sstr << " visualizable=\"" << this->visualizable_ << "\"" ;
if (this->unit_ != "") var_sstr << " unit=\"" << this->unit_ << "\"" ;
if (this->time_varying_ != "") var_sstr << " time_varying=\"" << this->time_varying_ << "\"" ;
if (this->centering_ != "") var_sstr << " centering=\"" << this->centering_ << "\"" ;
if (this->store_ != "") var_sstr << " store=\"" << this->store_ << "\"" ;
if (this->script_ != "") var_sstr << " script=\"" << this->script_ << "\"" ;
if (this->select_mem_ != "") var_sstr << " select-mem=\"" << this->select_mem_ << "\"" ;
if (this->select_file_ != "") var_sstr << " select-file=\"" << this->select_file_ << "\"" ;
if (this->select_subset_ != "") var_sstr << " select-subset=\"" << this->select_subset_ << "\"" ;
var_sstr << " layout=\"" << this->layout_ << "\"";
if (this->mesh_ != "") var_sstr << " mesh=\"" << this->mesh_ << "\"";
if (this->type_ != "") var_sstr << " type=\"" << this->type_ << "\"";
if (this->visualizable_ != "") var_sstr << " visualizable=\"" << this->visualizable_ << "\"";
if (this->unit_ != "") var_sstr << " unit=\"" << this->unit_ << "\"";
if (this->time_varying_ != "") var_sstr << " time_varying=\"" << this->time_varying_ << "\"";
if (this->centering_ != "") var_sstr << " centering=\"" << this->centering_ << "\"";
if (this->store_ != "") var_sstr << " store=\"" << this->store_ << "\"";
if (this->script_ != "") var_sstr << " script=\"" << this->script_ << "\"";
if (this->select_mem_ != "") var_sstr << " select-mem=\"" << this->select_mem_ << "\"";
if (this->select_file_ != "") var_sstr << " select-file=\"" << this->select_file_ << "\"";
if (this->select_subset_ != "") var_sstr << " select-subset=\"" << this->select_subset_ << "\"";
return (var_sstr.str()) ;
return (var_sstr.str());
}
} ;
};
class DamarisVarBase {
public:
// DamarisVarBase(int dims, std::vector<std::string>& param_names, std::string& variable_name, int rank=0) = 0 ;
virtual ~DamarisVarBase( void ) {} ;
// DamarisVarBase(int dims, std::vector<std::string>& param_names, std::string& variable_name, int rank=0) = 0;
virtual ~DamarisVarBase( void ) {};
virtual void PrintError ( void ) = 0 ;
virtual bool HasError( void ) = 0 ;
// virtual void SetDamarisParameterAndShmem( std::vector<int>& paramSizeVal ) = 0 ;
virtual void SetDamarisParameterAndShmem( std::vector<int> paramSizeVal ) = 0 ;
virtual void SetDamarisParameter( std::vector<int>& paramSizeVal ) = 0 ;
virtual void SetDamarisPosition( std::vector<int64_t> positionsVals ) = 0 ;
virtual void SetPointersToDamarisShmem( void ) = 0 ;
virtual void CommitVariableDamarisShmem( void ) = 0 ;
virtual void ClearVariableDamarisShmem( void ) = 0 ;
// virtual void * data_ptr( void ) = 0 ;
virtual std::string & variable_name( void ) = 0 ;
virtual void PrintError ( void ) = 0;
virtual bool HasError( void ) = 0;
// virtual void SetDamarisParameterAndShmem( std::vector<int>& paramSizeVal ) = 0;
virtual void SetDamarisParameterAndShmem( std::vector<int> paramSizeVal ) = 0;
virtual void SetDamarisParameter( std::vector<int>& paramSizeVal ) = 0;
virtual void SetDamarisPosition( std::vector<int64_t> positionsVals ) = 0;
virtual void SetPointersToDamarisShmem( void ) = 0;
virtual void CommitVariableDamarisShmem( void ) = 0;
virtual void ClearVariableDamarisShmem( void ) = 0;
// virtual void * data_ptr( void ) = 0;
virtual std::string & variable_name( void ) = 0;
@ -131,38 +131,34 @@ namespace Opm
* // <layout name="mpi_layout" type="int" dimensions="n_elements_mpi_local" comment="MPI elements layout" />
* // <variable name="MPI_RANK" layout="mpi_layout" type="scalar" visualizable="true" mesh="unstructured_mesh" unit="rank" centering="zonal"
* // store="#" time-varying="false" script="_PYTHON_XML_NAME_" comment="The cells MPI rank"/>
* damaris::model::DamarisVar<int> dam_var = new damaris::model::DamarisVar<int>(1, {std::string("n_connectivity_ph")}, std::string("topologies/topo/elements/connectivity"), rank_) ;
* dam_var->SetDamarisParameterAndShmem( { geomData.getNCorners() } ) ;
* damaris::model::DamarisVar<int> dam_var = new damaris::model::DamarisVar<int>(1, {std::string("n_connectivity_ph")}, std::string("topologies/topo/elements/connectivity"), rank_);
* dam_var->SetDamarisParameterAndShmem( { geomData.getNCorners() } );
*
* int * shmem_mpi_ptr = dam_var->data_ptr() ;
* int * shmem_mpi_ptr = dam_var->data_ptr();
* // Fill the created memory area
* for (int i = 0 ; i < ; i++ )
* for (int i = 0; i <; i++ )
* {
* shmem_mpi_ptr[i] = rank_ ;
* shmem_mpi_ptr[i] = rank_;
* }
* delete dam_var ; // this tells Damaris that the shared memory that it supplied is at its disposal. It will print error messages too.
* delete dam_var; // this tells Damaris that the shared memory that it supplied is at its disposal. It will print error messages too.
*
*/
template <typename T>
class DamarisVar :
public DamarisVarBase {
int dims_ ;
int num_params_ ; //!< Each paramater name string will need a value and they are set in SetDamarisParameter()
int * param_sizes_ ; //!< The value for any paramaters that are being used to describe the size of the variables data array
int64_t * positions_ ; //!< The offsets into the array that the data in the Variable starts from for this rank.
int rank_ ; //!< Rank of process - used for error reporting.
bool paramaters_set_ ; //!< set to true after SetDamarisParameter() is call to ensure the variable has correct size for memory allocation in SetPointersToDamarisShmem()
std::vector<std::string> param_names_ ; //!< Contains one paramater name for each paramater that a variable depends on (via it's Layout)
std::string variable_name_ ; //!< Reference string to the XML attribute name of the variable.
int dam_err_ ; //!< Set to != DAMARIS_OK if a Daamris error was returned by a Damaris API function call
bool has_error_ ;
std::ostringstream dam_err_sstr_ ; //!< Use dam_err_sstr.str() to return an error string describing detected error
DamarisVarXMLAttributes xml_attributes_ ; //!< The extra elements that need to be part of a Damaris <variable> type. They are simple string values that may reference other XML elements (and could be checked for existence etc.)
T * data_ptr_ ; //!< This pointer will be mapped to the Damaris shared memory area for the variable in the SetPointersToDamarisShmem() method. The type T will match the Layout type
int dims_;
int num_params_; //!< Each paramater name string will need a value and they are set in SetDamarisParameter()
int * param_sizes_; //!< The value for any paramaters that are being used to describe the size of the variables data array
int64_t * positions_; //!< The offsets into the array that the data in the Variable starts from for this rank.
int rank_; //!< Rank of process - used for error reporting.
bool paramaters_set_; //!< set to true after SetDamarisParameter() is call to ensure the variable has correct size for memory allocation in SetPointersToDamarisShmem()
std::vector<std::string> param_names_; //!< Contains one paramater name for each paramater that a variable depends on (via it's Layout)
std::string variable_name_; //!< Reference string to the XML attribute name of the variable.
int dam_err_; //!< Set to != DAMARIS_OK if a Daamris error was returned by a Damaris API function call
bool has_error_;
std::ostringstream dam_err_sstr_; //!< Use dam_err_sstr.str() to return an error string describing detected error
DamarisVarXMLAttributes xml_attributes_; //!< The extra elements that need to be part of a Damaris <variable> type. They are simple string values that may reference other XML elements (and could be checked for existence etc.)
T * data_ptr_; //!< This pointer will be mapped to the Damaris shared memory area for the variable in the SetPointersToDamarisShmem() method. The type T will match the Layout type
public:
@ -178,24 +174,24 @@ namespace Opm
*
* 1/ The variable's layout needs to be initialised via parameters :
* // Create the DamarisVar object:
* damaris::model::DamarisVar<int> MYVARNAME_2d = new damaris::model::DamarisVar<int>(2, {std::string("my_param_name1"), std::string("my_param_name2")}, std::string("MYVARNAME"), rank_) ;
* damaris::model::DamarisVar<int> MYVARNAME_2d = new damaris::model::DamarisVar<int>(2, {std::string("my_param_name1"), std::string("my_param_name2")}, std::string("MYVARNAME"), rank_);
* // Set the paramter sizes
* MYVARNAME_2d->SetDamarisParameterAndShmem( {25, 100 } } ; // sets the paramaters (here, my_param_name1 == 25 and my_param_name2 == 100)
* MYVARNAME_2d->SetDamarisParameterAndShmem( {25, 100 } }; // sets the paramaters (here, my_param_name1 == 25 and my_param_name2 == 100)
* // Get a pointer to the memeory and use it
* T * mymemory = MYVARNAME_2d->data_ptr() ;
* T * mymemory = MYVARNAME_2d->data_ptr();
* ... write data to mymemory ....
* delete MYVARNAME_2d ;
* delete MYVARNAME_2d;
* or,
* 2/ The variable's layout has been initialised via parameters in another variable (i.e. "my_param_name1" and "my_param_name2" have been previously set in the code)
* // Create the DamarisVar object:
* damaris::model::DamarisVar<int> MYVARNAME_2d = new damaris::model::DamarisVar<int>(2, {std::string("my_param_name1"), std::string("my_param_name2")}, std::string("MYVARNAME"), rank_) ;
* damaris::model::DamarisVar<int> MYVARNAME_2d = new damaris::model::DamarisVar<int>(2, {std::string("my_param_name1"), std::string("my_param_name2")}, std::string("MYVARNAME"), rank_);
* // explicitly state that the paramater values have been set somewhere else in the code previously.
* MYVARNAME_2d->ParameterIsSet() ;
* MYVARNAME_2d->ParameterIsSet();
* MYVARNAME_2d->SetPointersToDamarisShmem()
* // Get a pointer to the memeory and use it
* T * mymemory = MYVARNAME_2d->data_ptr() ;
* T * mymemory = MYVARNAME_2d->data_ptr();
* ... write data to mymemory ....
* delete MYVARNAME_2d ;
* delete MYVARNAME_2d;
*
* /param [IN] dims Used to check that the inputs to SetDamarisPosition() have the same number of values - one value for each dimension
* /param [IN] param_names The name the Damaris paramaters. These names (in typical use) control a Damaris variables size (names are defined in the Damaris XML file).
@ -208,23 +204,23 @@ namespace Opm
variable_name_( variable_name ),
rank_(rank)
{
dam_err_ = DAMARIS_OK ;
dam_err_ = DAMARIS_OK;
assert( param_names_.size() == dims ) ;
assert( dims > 0 ) ;
assert( param_names_.size() == dims );
assert( dims > 0 );
// Check that our template type T matches out Damaris XML <layout> type
if ( !TestType(variable_name) ) {
std::exit(-1) ;
std::exit(-1);
}
num_params_ = param_names_.size() ;
param_sizes_ = new int(num_params_) ;
positions_ = new int64_t(dims) ;
num_params_ = param_names_.size();
param_sizes_ = new int(num_params_);
positions_ = new int64_t(dims);
data_ptr_ = nullptr ;
paramaters_set_ = false ;
has_error_ = false ;
data_ptr_ = nullptr;
paramaters_set_ = false;
has_error_ = false;
}
/**
@ -238,10 +234,10 @@ namespace Opm
* <layout name="my_layout" type="int" dimensions="my_param_name1,my_param_name2" comment="This is a 2D variable" />
* <variable name="MYVARNAME" layout="my_layout" visualizable="true"/>
* // The paramaters are intialized in the constructor code
* damaris::model::DamarisVar<int> MYVARNAME_2d = new damaris::model::DamarisVar<int>(2, {std::string("my_param_name1"), std::string("my_param_name2")}, {100, 25}, std::string("MYVARNAME"), rank_) ;
* T * mymemory = MYVARNAME_2d->data_ptr() ;
* damaris::model::DamarisVar<int> MYVARNAME_2d = new damaris::model::DamarisVar<int>(2, {std::string("my_param_name1"), std::string("my_param_name2")}, {100, 25}, std::string("MYVARNAME"), rank_);
* T * mymemory = MYVARNAME_2d->data_ptr();
* ... write data to mymemory ....
* delete MYVARNAME_2d ;
* delete MYVARNAME_2d;
*
* /param [IN] dims Used to check that the inputs to SetDamarisPosition() have the same number of values - one value for each dimension
* /param [IN] param_names The name the Damaris paramaters. These names (in typical use) control a Damaris variables size (names are defined in the Damaris XML file).
@ -255,37 +251,37 @@ namespace Opm
variable_name_( variable_name ),
rank_(rank)
{
dam_err_ = DAMARIS_OK ;
dam_err_ = DAMARIS_OK;
assert( param_names_.size() == dims ) ;
assert( dims > 0 ) ;
assert( param_names_.size() == dims );
assert( dims > 0 );
// Check that our template type T matches out Damaris XML <layout> type
if ( !TestType(variable_name) ) {
std::exit(-1) ;
std::exit(-1);
}
num_params_ = param_names_.size() ;
param_sizes_ = new int(num_params_) ;
positions_ = new int64_t(dims) ;
num_params_ = param_names_.size();
param_sizes_ = new int(num_params_);
positions_ = new int64_t(dims);
data_ptr_ = nullptr ;
paramaters_set_ = false ;
has_error_ = false ;
data_ptr_ = nullptr;
paramaters_set_ = false;
has_error_ = false;
SetDamarisParameterAndShmem( param_values ) ; // Initialise the memory size in the constructor.
SetDamarisParameterAndShmem( param_values ); // Initialise the memory size in the constructor.
}
~DamarisVar( void ) {
delete [] param_sizes_ ;
delete [] positions_ ;
delete [] param_sizes_;
delete [] positions_;
if (data_ptr_ != nullptr)
{
CommitVariableDamarisShmem() ;
ClearVariableDamarisShmem() ;
CommitVariableDamarisShmem();
ClearVariableDamarisShmem();
}
if (this->HasError())
PrintError() ; // flush out any error messages
PrintError(); // flush out any error messages
}
/**
@ -293,121 +289,121 @@ namespace Opm
*/
bool TestType(std::string variable_name)
{
bool resbool = true ;
bool resbool = true;
// This gets the type of the Damaris XML <variable>'s <layout>
DAMARIS_TYPE_STR vartype ;
dam_err_ = damaris_get_type(variable_name.c_str(), &vartype) ;
DAMARIS_TYPE_STR vartype;
dam_err_ = damaris_get_type(variable_name.c_str(), &vartype);
if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rankDamarisVar::DamarisVar () damaris_get_type(\""
<< variable_name_ << "\", vartype); Damaris error = " << damaris_error_string(dam_err_) << std::endl ;
has_error_ = true ;
return( false ) ;
<< variable_name_ << "\", vartype); Damaris error = " << damaris_error_string(dam_err_) << std::endl;
has_error_ = true;
return( false );
}
T test_id;
const std::type_info& t1 = typeid(test_id) ;
const std::type_info& t1 = typeid(test_id);
if (vartype == DAMARIS_TYPE_DOUBLE)
{
double td = 0.0 ;
const std::type_info& t2 = typeid(td) ;
double td = 0.0;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_FLOAT)
{
float td = 0.0f ;
const std::type_info& t2 = typeid(td) ;
float td = 0.0f;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_CHAR)
{
char td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_UCHAR)
{
unsigned char td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_SHORT)
{
short td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_USHORT)
{
unsigned short td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_INT)
{
int td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_UINT)
{
unsigned int td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_LONG)
{
long td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_ULONG)
{
unsigned long td = 0;
const std::type_info& t2 = typeid(td) ;
const std::type_info& t2 = typeid(td);
if (t1 != t2) {
OutputErrorAndAssert(variable_name, t1.name(), t2.name()) ;
resbool = false ;
OutputErrorAndAssert(variable_name, t1.name(), t2.name());
resbool = false;
}
}
else if (vartype == DAMARIS_TYPE_UNDEFINED)
{
std::cerr << "ERROR rank =" << rank_ << " : DamarisVar::DamarisVar():: \"" << variable_name << "\" has type DAMARIS_TYPE_UNDEFINED"<< std::endl ;
resbool = false ;
std::cerr << "ERROR rank =" << rank_ << " : DamarisVar::DamarisVar():: \"" << variable_name << "\" has type DAMARIS_TYPE_UNDEFINED"<< std::endl;
resbool = false;
}
else
{
std::cerr << "ERROR rank =" << rank_ << " : DamarisVar::DamarisVar():: \"" << variable_name << "\" is not of available type "<< std::endl ;
resbool = false ;
std::cerr << "ERROR rank =" << rank_ << " : DamarisVar::DamarisVar():: \"" << variable_name << "\" is not of available type "<< std::endl;
resbool = false;
}
return resbool ;
return resbool;
}
/**
@ -418,17 +414,17 @@ namespace Opm
*/
void ParameterIsSet()
{
paramaters_set_ = true ;
paramaters_set_ = true;
}
void PrintError ( void )
{
std::cerr << dam_err_sstr_.str() ;
std::cerr << dam_err_sstr_.str();
}
bool HasError( void )
{
return (has_error_) ;
return (has_error_);
}
/**
@ -436,12 +432,12 @@ namespace Opm
*/
T * data_ptr( void )
{
return (data_ptr_) ;
return (data_ptr_);
}
std::string & variable_name( void )
{
return (variable_name_) ;
return (variable_name_);
}
/**
@ -449,13 +445,13 @@ namespace Opm
*/
std::string ReturnXMLForVariable ( void )
{
std::ostringstream var_sstr ;
std::ostringstream var_sstr;
var_sstr << "<variable " << " name=\"" << variable_name_ << "\"" ;
var_sstr << xml_attributes_.ReturnXMLForVariable() ;
var_sstr << " /> " ;
var_sstr << "<variable " << " name=\"" << variable_name_ << "\"";
var_sstr << xml_attributes_.ReturnXMLForVariable();
var_sstr << " /> ";
return var_sstr.str() ;
return var_sstr.str();
}
/**
@ -467,8 +463,8 @@ namespace Opm
*/
void SetDamarisParameterAndShmem( std::vector<int> paramSizeVal )
{
this->SetDamarisParameter( paramSizeVal ) ;
this->SetPointersToDamarisShmem() ;
this->SetDamarisParameter( paramSizeVal );
this->SetPointersToDamarisShmem();
}
/**
@ -480,23 +476,23 @@ namespace Opm
*/
void SetDamarisParameter( std::vector<int>& paramSizeVal )
{
assert(paramSizeVal.size() == num_params_) ;
assert(paramSizeVal.size() == num_params_);
bool resbool = true ;
for (int varnum = 0 ; varnum < num_params_ ; varnum++)
bool resbool = true;
for (int varnum = 0; varnum < num_params_; varnum++)
{
param_sizes_[varnum] = paramSizeVal[varnum] ;
param_sizes_[varnum] = paramSizeVal[varnum];
dam_err_ = damaris_parameter_set(param_names_[varnum].c_str(), &paramSizeVal[varnum], sizeof(int));
if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_parameter_set(\"" << param_names_[varnum]
<< "\", paramSizeVal, sizeof(int)); Damaris error = " << damaris_error_string(dam_err_) << std::endl ;
resbool = false ;
has_error_ = true ;
<< "\", paramSizeVal, sizeof(int)); Damaris error = " << damaris_error_string(dam_err_) << std::endl;
resbool = false;
has_error_ = true;
}
}
if (resbool == true)
paramaters_set_ = true ;
paramaters_set_ = true;
}
/**
@ -509,17 +505,17 @@ namespace Opm
*/
void SetDamarisPosition( std::vector<int64_t> positionsVals )
{
assert(positionsVals.size() == dims_) ;
assert(positionsVals.size() == dims_);
for (int pos_dim = 0 ; pos_dim < dims_ ; pos_dim++)
for (int pos_dim = 0; pos_dim < dims_; pos_dim++)
{
positions_[pos_dim] = positionsVals[pos_dim] ;
positions_[pos_dim] = positionsVals[pos_dim];
}
dam_err_ = damaris_set_position(variable_name_.c_str(), positionsVals.data());
if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_set_position(\""
<< variable_name_ << "\", positionsVals); Damaris error = " << damaris_error_string(dam_err_) << std::endl ;
has_error_ = true ;
<< variable_name_ << "\", positionsVals); Damaris error = " << damaris_error_string(dam_err_) << std::endl;
has_error_ = true;
}
}
@ -534,16 +530,16 @@ namespace Opm
if (paramaters_set_ == true )
{
// Allocate memory in the shared memory section...
dam_err_ = damaris_alloc(variable_name_.c_str(), (void **) &data_ptr_) ;
dam_err_ = damaris_alloc(variable_name_.c_str(), (void **) &data_ptr_);
if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_alloc(\""
<< variable_name_ <<"\", (void **) &ret_ptr)" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl ;
has_error_ = true ;
<< variable_name_ <<"\", (void **) &ret_ptr)" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl;
has_error_ = true;
}
} else {
dam_err_ = -1 ;
dam_err_sstr_ << "ERROR rank =" << rank_ << " : class DamarisVar : SetDamarisParameter() should be called first so as to define the size of the memory block required for variable : " << variable_name_ << std::endl ;
has_error_ = true ;
dam_err_ = -1;
dam_err_sstr_ << "ERROR rank =" << rank_ << " : class DamarisVar : SetDamarisParameter() should be called first so as to define the size of the memory block required for variable : " << variable_name_ << std::endl;
has_error_ = true;
}
}
@ -551,21 +547,21 @@ namespace Opm
{
if (paramaters_set_ == true )
{
T * temp_ptr ;
T * temp_ptr;
// Allocate memory in the shared memory section...
dam_err_ = damaris_alloc(variable_name_.c_str(), (void **) &temp_ptr) ;
dam_err_ = damaris_alloc(variable_name_.c_str(), (void **) &temp_ptr);
if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_alloc(\""
<< variable_name_ <<"\", (void **) &ret_ptr)" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl ;
has_error_ = true ;
<< variable_name_ <<"\", (void **) &ret_ptr)" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl;
has_error_ = true;
}
*ptr_in = temp_ptr ;
data_ptr_ = temp_ptr ;
*ptr_in = temp_ptr;
data_ptr_ = temp_ptr;
} else {
dam_err_ = -1 ;
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : SetDamarisParameter() should be called first so as to define the size of the memory block required for variable : " << variable_name_ << std::endl ;
has_error_ = true ;
dam_err_ = -1;
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : SetDamarisParameter() should be called first so as to define the size of the memory block required for variable : " << variable_name_ << std::endl;
has_error_ = true;
}
}
@ -578,11 +574,11 @@ namespace Opm
void CommitVariableDamarisShmem( void )
{
// Signal to Damaris we are done writing data for this iteration
dam_err_ = damaris_commit (variable_name_.c_str()) ;
dam_err_ = damaris_commit (variable_name_.c_str());
if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_commit(\""
<< variable_name_ <<"\")" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl ;
has_error_ = true ;
<< variable_name_ <<"\")" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl;
has_error_ = true;
}
}
@ -595,21 +591,21 @@ namespace Opm
void ClearVariableDamarisShmem( void )
{
// Signal to Damaris it has complete charge of the memory area
dam_err_ = damaris_clear(variable_name_.c_str()) ;
dam_err_ = damaris_clear(variable_name_.c_str());
if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_clear(\""
<< variable_name_ << "\")" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl ;
has_error_ = true ;
<< variable_name_ << "\")" << ", Damaris error = " << damaris_error_string(dam_err_) << std::endl;
has_error_ = true;
}
data_ptr_ = nullptr ;
data_ptr_ = nullptr;
}
private:
void OutputErrorAndAssert(std::string& var_name, std::string type_name1, std::string type_name2)
{
dam_err_sstr_ << "ERROR rank =" << rank_ << " : DamarisVar::DamarisVar () variable_name_: \"" << var_name
<< "\" The template type of Type of DamarisVar<T> in the code: " << type_name1 << " does not match type in XML (float)" << std::endl ;
PrintError() ;
assert( type_name1 == type_name2 ) ;
<< "\" The template type of Type of DamarisVar<T> in the code: " << type_name1 << " does not match type in XML (float)" << std::endl;
PrintError();
assert( type_name1 == type_name2 );
}
}; // class DamarisVar

View File

@ -19,8 +19,8 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_SIM_MESH_DATA2_HPP
#define OPM_SIM_MESH_DATA2_HPP
#ifndef OPM_GRID_DATA_OUTPUT_HPP
#define OPM_GRID_DATA_OUTPUT_HPP
#include <sstream>
#include <dune/grid/common/rangegenerators.hh>
@ -31,7 +31,7 @@
This data extractor provides the full set of vertices (corresponding to Dune::Partition::all) and then
allows a user to specify Dune sub-partitions to get the references into the vertex array and element
(aka cell) types for the sub-partition. This allows the full set of verticies to be reused for
(aka cell) types for the sub-partition. This allows the full set of vertices to be reused for
visualisation of the various sub-partitions, at the expense of copying all the vertices. Typically
a user is interested in the interiorBoarder elements which make use of the bulk (~80%) of the vertices.
This saves having to renumber the indexes to the vertices for the sub-partitions.
@ -44,30 +44,30 @@
#include <opm/simulators/utils/GridDataOutput.hpp>
// N.B. does not seem to be able to be allocated with new operator.
Opm::GridDataOutput::SimMeshDataAccessor geomData(gridView, Dune::Partition::interior ) ;
Opm::GridDataOutput::SimMeshDataAccessor geomData(gridView, Dune::Partition::interior );
geomData.printGridDetails() ;
geomData.printGridDetails();
// example using seperate x, y and z arrays
int nvert = geomData.getNVertices() ;
double * x_vert = new double[nvert] ;
double * y_vert = new double[nvert] ;
double * z_vert = new double[nvert] ;
geomData.writeGridPoints(x_vert,y_vert,z_vert) ;
int nvert = geomData.getNVertices();
double * x_vert = new double[nvert];
double * y_vert = new double[nvert];
double * z_vert = new double[nvert];
geomData.writeGridPoints(x_vert,y_vert,z_vert);
... do something with vertex data x_vert, y_vert and z_vert ....
free [] x_vert;
free [] y_vert;
free [] z_vert;
delete [] x_vert;
delete [] y_vert;
delete [] z_vert;
// example using AOS
double * xyz_vert_aos = new double[nvert*3] ;
geomData.writeGridPoints_SOA(xyz_vert_aos) ;
double * xyz_vert_aos = new double[nvert*3];
geomData.writeGridPoints_AOS(xyz_vert_aos);
... do something with vertex data xyz_vert_aos....
free [] xyz_vert_aos;
delete [] xyz_vert_aos;
*/
@ -75,9 +75,9 @@
namespace Opm::GridDataOutput
{
/**
* Allows selection of order of verticies in writeConnectivity()
* Allows selection of order of vertices in writeConnectivity()
*/
enum ConnectivityVertexOrder { DUNE = 0 , VTK = 1 } ;
enum ConnectivityVertexOrder { DUNE = 0 , VTK = 1 };
template< class GridView, unsigned int partitions >
class SimMeshDataAccessor {
@ -115,14 +115,9 @@ namespace Opm::GridDataOutput
: gridView_( gridView ),
dunePartition_(dunePartition)
{
dimw_ = GridView::dimension ; // this is an enum
partition_value_ = dunePartition.value ;
countEntities() ;
}
//! destructor
~SimMeshDataAccessor ()
{
dimw_ = GridView::dimension; // this is an enum
partition_value_ = dunePartition.value;
countEntities();
}
/**
@ -136,10 +131,10 @@ namespace Opm::GridDataOutput
{
for (const auto& cit : elements(gridView_, dunePartition_))
{
auto corner_geom = cit.geometry() ;
auto corner_geom = cit.geometry();
if( Dune::VTK::geometryType( corner_geom.type() ) == Dune::VTK::polyhedron )
{
return true ;
return true;
}
}
return false;
@ -154,51 +149,50 @@ namespace Opm::GridDataOutput
void countEntities( )
{
// We include all the vertices for this ranks partition
const auto& vert_partition_it = vertices(gridView_, Dune::Partitions::all);
nvertices_ = std::distance(vert_partition_it.begin(), vert_partition_it.end());
const auto& vert_partition = vertices(gridView_, Dune::Partitions::all);
nvertices_ = std::distance(vert_partition.begin(), vert_partition.end());
const auto& cell_partition_it = elements(gridView_, dunePartition_);
ncells_ = std::distance(cell_partition_it.begin(), cell_partition_it.end());
ncorners_ = 0 ;
for (const auto& cit : cell_partition_it)
const auto& cell_partition = elements(gridView_, dunePartition_);
ncells_ = 0;
ncorners_ = 0;
for (const auto& cit : cell_partition)
{
auto corner_geom = cit.geometry() ;
ncorners_ += corner_geom.corners() ;
auto corner_geom = cit.geometry();
ncorners_ += corner_geom.corners();
++ncells_;
}
}
/**
Write the positions of vertices - directly to the pointers given in paramaters
Write the positions of vertices - directly to the pointers given in parameters
Returns the number of vertices written
*/
template <typename T>
long writeGridPoints( T* x_inout, T* y_inout, T* z_inout )
{
long i = 0 ;
long i = 0;
if (dimw_ == 3) {
for (const auto& vit : vertices(gridView_, Dune::Partitions::all) )
{
// if (i < nvertices_) // As we are templated on the Dune::PartitionSet<partitions>, this cannot change
auto xyz_local = vit.geometry().corner(0); // verticies only have one corner
x_inout[i] = static_cast<T>(xyz_local[0]) ;
y_inout[i] = static_cast<T>(xyz_local[1]) ;
z_inout[i] = static_cast<T>(xyz_local[2]) ;
i++ ;
auto xyz_local = vit.geometry().corner(0); // vertices only have one corner
x_inout[i] = static_cast<T>(xyz_local[0]);
y_inout[i] = static_cast<T>(xyz_local[1]);
z_inout[i] = static_cast<T>(xyz_local[2]);
i++;
}
} else if (dimw_ == 2) {
for (const auto& vit : vertices(gridView_, Dune::Partitions::all) )
{
// if (i < nvertices_) // As we are templated on the Dune::PartitionSet<partitions>, this cannot change
auto xyz_local = vit.geometry().corner(0); // verticies only have one corner
x_inout[i] = static_cast<T>(xyz_local[0]) ;
y_inout[i] = static_cast<T>(xyz_local[1]) ;
{
auto xyz_local = vit.geometry().corner(0); // vertices only have one corner
x_inout[i] = static_cast<T>(xyz_local[0]);
y_inout[i] = static_cast<T>(xyz_local[1]);
z_inout[i] = static_cast<T>(0.0);
i++ ;
i++;
}
}
return i ;
assert(i == nvertices_); // As we are templated on the Dune::PartitionSet<partitions>, this cannot change
return i;
}
/**
@ -209,23 +203,23 @@ namespace Opm::GridDataOutput
template <typename T>
long writeGridPoints_AOS( T* xyz_inout )
{
long i = 0 ;
long i = 0;
if (dimw_ == 3) {
for (const auto& vit : vertices(gridView_, Dune::Partitions::all))
{
auto xyz_local = vit.geometry().corner(0);
xyz_inout[i++] = static_cast<T>(xyz_local[0]) ;
xyz_inout[i++] = static_cast<T>(xyz_local[1]) ;
xyz_inout[i++] = static_cast<T>(xyz_local[2]) ;
xyz_inout[i++] = static_cast<T>(xyz_local[0]);
xyz_inout[i++] = static_cast<T>(xyz_local[1]);
xyz_inout[i++] = static_cast<T>(xyz_local[2]);
}
} else if (dimw_ == 2) {
for (const auto& vit : vertices(gridView_, Dune::Partitions::all))
{
auto xyz_local = vit.geometry().corner(0);
xyz_inout[i++] = static_cast<T>(xyz_local[0]) ;
xyz_inout[i++] = static_cast<T>(xyz_local[1]) ;
xyz_inout[i++] = static_cast<T>(0.0) ;
xyz_inout[i++] = static_cast<T>(xyz_local[0]);
xyz_inout[i++] = static_cast<T>(xyz_local[1]);
xyz_inout[i++] = static_cast<T>(0.0);
}
}
return ( (i) / 3 );
@ -239,35 +233,35 @@ namespace Opm::GridDataOutput
template <typename T>
long writeGridPoints_SOA( T* xyz_inout )
{
long i = 0 ;
long i = 0;
// Get offsets into structure
T * xyz_inout_y = xyz_inout + nvertices_ ;
T * xyz_inout_z = xyz_inout + (2*nvertices_) ;
T* xyz_inout_y = xyz_inout + nvertices_;
T* xyz_inout_z = xyz_inout + (2*nvertices_);
if (dimw_ == 3) {
for (const auto& vit : vertices(gridView_, Dune::Partitions::all))
{
auto xyz_local = vit.geometry().corner(0);
xyz_inout[i] = static_cast<T>(xyz_local[0]) ;
xyz_inout_y[i]= static_cast<T>(xyz_local[1]) ;
xyz_inout_z[i] = static_cast<T>(xyz_local[2]) ;
i++ ;
xyz_inout[i] = static_cast<T>(xyz_local[0]);
xyz_inout_y[i]= static_cast<T>(xyz_local[1]);
xyz_inout_z[i] = static_cast<T>(xyz_local[2]);
i++;
}
} else if (dimw_ == 2) {
for (const auto& vit : vertices(gridView_, Dune::Partitions::all))
{
auto xyz_local = vit.geometry().corner(0);
xyz_inout[i] = static_cast<T>(xyz_local[0]) ;
xyz_inout_y[i]= static_cast<T>(xyz_local[1]) ;
xyz_inout[i] = static_cast<T>(xyz_local[0]);
xyz_inout_y[i]= static_cast<T>(xyz_local[1]);
xyz_inout_z[i] = static_cast<T>(0.0);
i++ ;
i++;
}
}
return (i) ;
return (i);
}
/**
* Write the connectivity array - directly to the pointer given in paramater 1
* Write the connectivity array - directly to the pointer given in parameter 1
Reorders the indecies as selected either in DUNE order or VTK order.
Returns the number of corner indices written.
@ -275,160 +269,160 @@ namespace Opm::GridDataOutput
template <typename I>
long writeConnectivity(I * connectivity_inout, ConnectivityVertexOrder whichOrder)
{
long i = 0 ;
long i = 0;
if ( whichOrder == DUNE ) {
// DUNE order
for (const auto& cit : elements(gridView_, dunePartition_))
{
auto cell_corners = cit.geometry().corners() ;
auto cell_corners = cit.geometry().corners();
for( auto vx = 0; vx < cell_corners; ++ vx )
{
const int vxIdx = gridView_.indexSet().subIndex( cit, vx, 3 );
connectivity_inout[i + vx] = vxIdx ;
connectivity_inout[i + vx] = vxIdx;
}
i += cell_corners ;
i += cell_corners;
}
} else {
// VTK order
for (const auto& cit : elements(gridView_, dunePartition_))
{
auto cell_corners = cit.geometry().corners() ;
auto cell_corners = cit.geometry().corners();
for( auto vx = 0; vx < cell_corners; ++ vx )
{
const int vxIdx = gridView_.indexSet().subIndex( cit, vx, 3 );
int vtkOrder ;
vtkOrder = Dune::VTK::renumber(cit.type(), vx) ;
connectivity_inout[i + vtkOrder] = vxIdx ;
int vtkOrder;
vtkOrder = Dune::VTK::renumber(cit.type(), vx);
connectivity_inout[i + vtkOrder] = vxIdx;
}
i += cell_corners ;
i += cell_corners;
}
}
return (i) ;
return (i);
}
/**
* Write the offsets values - directly to the pointer given in paramater 1
* Write the offsets values - directly to the pointer given in parameter 1
Returns the number of offset values written, which should be 1 greater than ncells_
or -1 if an error was detected
*/
template <typename I>
long writeOffsetsCells( I* offsets_inout )
{
long i = 1 ;
offsets_inout[0] = 0 ;
long i = 1;
offsets_inout[0] = 0;
for (const auto& cit : elements(gridView_, dunePartition_))
{
auto cell_corners = cit.geometry().corners() ;
offsets_inout[i] = offsets_inout[i-1] + cell_corners ;
i++ ;
auto cell_corners = cit.geometry().corners();
offsets_inout[i] = offsets_inout[i-1] + cell_corners;
i++;
}
return (i) ; // This should be 1 greater than ncells_
return (i); // This should be 1 greater than ncells_
}
/**
* Write the Cell types array - directly to the pointer given in paramater 1
* Write the Cell types array - directly to the pointer given in parameter 1
*/
template <typename I>
long writeCellTypes( I* types_inout)
{
int i = 0 ;
int i = 0;
for (const auto& cit : elements(gridView_, dunePartition_))
{
I vtktype = static_cast<I>(Dune::VTK::geometryType(cit.type()));
types_inout[i++] = vtktype ;
types_inout[i++] = vtktype;
}
return (i) ;
return (i);
}
std::string getPartitionTypeString ( )
{
if (this->dunePartition_ == Dune::Partitions::all)
return (std::string("Dune::Partitions::all")) ;
return (std::string("Dune::Partitions::all"));
if (this->dunePartition_ == Dune::Partitions::interior)
return (std::string("Dune::Partitions::interior")) ;
return (std::string("Dune::Partitions::interior"));
if (this->dunePartition_ == Dune::Partitions::interiorBorder)
return (std::string("Dune::Partitions::interiorBorder")) ;
return (std::string("Dune::Partitions::interiorBorder"));
if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlap)
return (std::string("Dune::Partitions::interiorBorderOverlap")) ;
return (std::string("Dune::Partitions::interiorBorderOverlap"));
if (this->dunePartition_ == Dune::Partitions::front)
return (std::string("Dune::Partitions::front")) ;
return (std::string("Dune::Partitions::front"));
if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlapFront)
return (std::string("Dune::Partitions::InteriorBorderOverlapFront")) ;
return (std::string("Dune::Partitions::InteriorBorderOverlapFront"));
if (this->dunePartition_ == Dune::Partitions::border)
return (std::string("Dune::Partitions::border")) ;
return (std::string("Dune::Partitions::border"));
if (this->dunePartition_ == Dune::Partitions::ghost)
return (std::string("Dune::Partitions::ghost")) ;
return (std::string("Dune::Partitions::ghost"));
return (std::string("Unknown Dune::PartitionSet<>")) ;
return (std::string("Unknown Dune::PartitionSet<>"));
}
Dune::PartitionSet<partitions> getPartition ( void )
{
return ( this->dunePartition_ ) ;
return ( this->dunePartition_ );
}
void printGridDetails()
{
std::cout << "Dune Partition = " << partition_value_ << ", " << getPartitionTypeString() << std::endl ;
printNCells() ;
printNVertices() ;
printNCorners() ;
std::cout << "Dune Partition = " << partition_value_ << ", " << getPartitionTypeString() << std::endl;
printNCells();
printNVertices();
printNCorners();
}
void printNCells()
{
std::cout << "ncells = " << ncells_ << std::endl ;
std::cout << "ncells = " << ncells_ << std::endl;
}
void printNVertices()
{
std::cout << "nvertices = " << nvertices_ << std::endl ;
std::cout << "nvertices = " << nvertices_ << std::endl;
}
void printNCorners()
{
std::cout << "ncorners = " << ncorners_ << std::endl ;
std::cout << "ncorners = " << ncorners_ << std::endl;
}
int getNCells()
{
return(ncells_) ;
return(ncells_);
}
int getNVertices()
{
return(nvertices_) ;
return(nvertices_);
}
int getNCorners()
{
return(ncorners_) ;
return(ncorners_);
}
std::string getError()
{
return error_strm_.str() ;
return error_strm_.str();
}
void clearError()
{
error_strm_.str("") ;
error_strm_.str("");
}
bool hasError()
{
if ( error_strm_.str().length() > 0 )
return true ;
return true;
else
return false ;
return false;
}
protected:
GridView gridView_; // the grid
Dune::PartitionSet<partitions> dunePartition_ ;
unsigned int partition_value_ ;
Dune::PartitionSet<partitions> dunePartition_;
unsigned int partition_value_;
/**
Current partition grid information
@ -443,10 +437,10 @@ namespace Opm::GridDataOutput
*/
int ncorners_;
int dimw_ ; // dimensions of the input grid
int dimw_; // dimensions of the input grid
private:
std::stringstream error_strm_ ;
std::stringstream error_strm_;
};