2021-10-22 04:09:12 -05:00
/*
Copyright 2021 Equinor .
This file is part of the Open Porous Media project ( OPM ) .
OPM is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
OPM is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with OPM . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef OPM_DAMARISKEYWORDS_HEADER_INCLUDED
# define OPM_DAMARISKEYWORDS_HEADER_INCLUDED
2024-09-02 05:56:18 -05:00
# include <opm/models/utils/parametersystem.hpp>
2024-06-28 05:17:13 -05:00
# include <opm/simulators/flow/DamarisParameters.hpp>
2023-09-28 05:58:18 -05:00
# include <opm/simulators/utils/ParallelCommunication.hpp>
2023-09-28 04:12:26 -05:00
2024-01-10 07:13:52 -06:00
# include <map>
# include <string>
2024-05-14 14:08:47 -05:00
# include <sstream>
# include <algorithm>
# include <unordered_set>
2023-09-24 15:23:31 -05:00
2021-10-22 04:09:12 -05:00
/*
Below is the std : : map with the keywords that are supported by Damaris .
2022-10-10 07:28:09 -05:00
Most entries in the map below are not critical ( ' static ' ) and will not
2021-10-22 04:09:12 -05:00
be changed . We only allow changing FileMode together with output directory
*/
2024-06-28 05:17:13 -05:00
namespace Opm : : DamarisOutput {
2023-09-23 15:24:11 -05:00
2023-12-08 14:22:55 -06:00
/**
* 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 .
*/
2023-09-28 05:58:18 -05:00
bool FileExists ( const std : : string & filename_in ,
const Parallel : : Communication & comm ) ;
2024-06-28 05:17:13 -05:00
struct DamarisSettings
{
2023-12-12 14:48:17 -06:00
bool enableDamarisOutputCollective_ = true ;
bool saveToDamarisHDF5_ = true ;
// if saveMeshToDamarisHDF5 is true, requires enableDamarisOutputCollective to be false
// (until offsets are are added to mesh data for collective writing)
bool saveMeshToHDF5_ = false ;
std : : string pythonFilename_ ;
std : : string paraviewPythonFilename_ ;
2023-12-13 10:50:05 -06:00
std : : string damarisSimName_ ; // empty and set to "opm-flow-<random-number>" if none provided on command line. Used as prefix to HDF5 filenames
std : : string shmemName_ ; // empty and needs to be unique if multiple simulations are running on the same server/node. Used to name the Damaris shared memory region.
2023-12-12 14:48:17 -06:00
std : : string damarisLogLevel_ = " info " ;
std : : string damarisDaskFile_ = " " ;
2024-05-14 14:08:47 -05:00
// std::string damarisLimitVars_ = "";
2023-12-12 14:48:17 -06:00
int nDamarisCores_ = 1 ; // this is the number of (Damaris server) cores per node
int nDamarisNodes_ = 0 ;
long shmemSizeBytes_ = 536870912 ; // 512 MB
2023-12-13 10:50:05 -06:00
std : : string rand_value_str_ ; // to be added to sheared memory name to make unique
2023-09-28 05:58:18 -05:00
std : : map < std : : string , std : : string >
getKeywords ( const Parallel : : Communication & comm ,
const std : : string & OutputDir ) ;
2023-12-13 10:50:05 -06:00
void SetRandString ( void ) ; // sets the value of rand_value_str_
2023-09-28 05:58:18 -05:00
} ;
/**
2023-12-08 14:22:55 -06:00
* 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 .
2024-05-17 10:36:18 -05:00
*
* N . B . This needs to be called before damaris_init ( )
2023-12-08 14:22:55 -06:00
*/
2023-09-28 05:58:18 -05:00
template < class TypeTag >
2023-09-22 16:23:29 -05:00
std : : map < std : : string , std : : string >
2023-12-08 14:22:55 -06:00
getDamarisKeywords ( const Parallel : : Communication & comm , const std : : string & OutputDir )
2023-09-28 05:58:18 -05:00
{
DamarisSettings settings ;
2024-02-06 04:45:05 -06:00
// 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 opm/simulators/flow/DamarisWriter.hpp and
// defaults are set in opm/simulators/flow/FlowProblemProperties.hpp
2024-07-06 03:22:47 -05:00
settings . enableDamarisOutputCollective_ = Parameters : : Get < Parameters : : DamarisOutputHdfCollective > ( ) ;
settings . saveMeshToHDF5_ = Parameters : : Get < Parameters : : DamarisSaveMeshToHdf > ( ) ;
settings . saveToDamarisHDF5_ = Parameters : : Get < Parameters : : DamarisSaveToHdf > ( ) ;
settings . pythonFilename_ = Parameters : : Get < Parameters : : DamarisPythonScript > ( ) ;
settings . paraviewPythonFilename_ = Parameters : : Get < Parameters : : DamarisPythonParaviewScript > ( ) ;
settings . damarisSimName_ = Parameters : : Get < Parameters : : DamarisSimName > ( ) ;
settings . nDamarisCores_ = Parameters : : Get < Parameters : : DamarisDedicatedCores > ( ) ;
settings . nDamarisNodes_ = Parameters : : Get < Parameters : : DamarisDedicatedNodes > ( ) ;
settings . shmemSizeBytes_ = Parameters : : Get < Parameters : : DamarisSharedMemorySizeBytes > ( ) ;
settings . shmemName_ = Parameters : : Get < Parameters : : DamarisSharedMemoryName > ( ) ;
settings . damarisLogLevel_ = Parameters : : Get < Parameters : : DamarisLogLevel > ( ) ;
settings . damarisDaskFile_ = Parameters : : Get < Parameters : : DamarisDaskFile > ( ) ;
2024-06-28 05:17:13 -05:00
2023-09-28 05:58:18 -05:00
return settings . getKeywords ( comm , OutputDir ) ;
}
2021-10-22 04:09:12 -05:00
2024-05-14 14:08:47 -05:00
template < class TypeTag >
std : : unordered_set < std : : string >
getSetOfIncludedVariables ( void )
{
std : : unordered_set < std : : string > resuset ;
std : : string tstr ;
2024-05-17 10:36:18 -05:00
// The --damaris-limit-variables command line option (defaults to empty string)
2024-07-06 03:22:47 -05:00
std : : string damarisLimitVars = Parameters : : Get < Parameters : : DamarisLimitVariables > ( ) ;
2024-05-14 14:08:47 -05:00
std : : stringstream ss ( damarisLimitVars ) ;
// Use while loop to check the getline() function condition.
while ( std : : getline ( ss , tstr , ' , ' ) ) {
//remove whitespace
std : : string : : iterator end_pos = std : : remove ( tstr . begin ( ) , tstr . end ( ) , ' ' ) ;
tstr . erase ( end_pos , tstr . end ( ) ) ;
2024-05-17 10:36:18 -05:00
// place in set (no duplicates possible in set and no empty string)
if ( tstr ! = " " ) {
resuset . insert ( tstr ) ;
}
2024-05-14 14:08:47 -05:00
}
2024-06-28 05:17:13 -05:00
return resuset ;
2024-05-14 14:08:47 -05:00
}
2021-10-22 04:09:12 -05:00
} // namespace Opm::DamarisOutput
2024-01-10 07:13:52 -06:00
# endif