Loading...
Searching...
No Matches
DamarisVar.hpp
/*
Copyright 2023 Inria, Bretagne–Atlantique Research Center
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 DAMARISVAR_HPP
#define DAMARISVAR_HPP
#include <cstddef>
#include <string>
#include <vector>
/*
File: DamarisVar.hpp
Author: Joshua Bowden, Inria
Date: 06/02/2023
The DamarisVar class can be used to allocate memory in the Damaris shared
memory region and a user can supply the data required for the variable via the data_ptr_
or data() method. The data will then be directly available on the Damaris server side
(server cores) plugin code. The templated type used should match the one specified
in the Damaris XML file for the variable name, if not an error is raised.
*/
namespace Opm
{
namespace DamarisOutput
{
class DamarisVarXMLAttributes
{
std::string layout_;
std::string mesh_;
std::string type_;
std::string visualizable_;
std::string unit_;
std::string time_varying_;
std::string centering_;
std::string store_;
std::string script_;
std::string select_mem_;
std::string select_file_;
std::string select_subset_;
public:
DamarisVarXMLAttributes();
std::string ReturnXMLForVariable();
};
template <typename T>
class DamarisVar
{
int num_params_;
std::vector<int> param_sizes_;
std::vector<int64_t> positions_;
bool parameters_set_;
std::vector<std::string> param_names_;
std::string variable_name_;
int rank_;
int dam_err_;
bool has_error_;
std::string dam_err_str_;
DamarisVarXMLAttributes xml_attributes_;
T* data_ptr_;
std::size_t current_size_;
public:
DamarisVar(int dims,
const std::vector<std::string>& param_names,
const std::string& variable_name,
int rank);
DamarisVar(int dims,
const std::vector<std::string>& param_names,
const std::vector<int>& param_values,
const std::string& variable_name,
int rank);
~DamarisVar();
void parameterIsSet()
{
parameters_set_ = true;
}
void printError() const;
bool hasError() const
{
return has_error_;
}
T* data()
{
if (parameters_set_ == true) {
return data_ptr_; // This still could be nullptr
} else {
return nullptr;
}
}
const std::string& variable_name() const
{
return variable_name_;
}
std::string returnXMLForVariable();
void setDamarisParameterAndShmem(const std::vector<int>& paramSizeVal)
{
this->setDamarisParameter(paramSizeVal);
this->setPointersToDamarisShmem();
}
std::size_t size()
{
if (parameters_set_ == true) {
return current_size_;
} else {
return 0;
}
}
void setDamarisParameter(const std::vector<int>& paramSizeVal);
void setDamarisPosition(const std::vector<int64_t>& positionsVals);
void setPointersToDamarisShmem();
void commitVariableDamarisShmem();
void clearVariableDamarisShmem();
private:
bool TestType(const std::string& variable_name);
void formatTypeError(const std::string& var_name,
const std::string& type_name1,
const std::string& type_name2);
}; // class DamarisVar
} // namespace DamarisOutput
} // namespace Opm
#endif
Opm::DamarisOutput::DamarisVarXMLAttributes
This class contains the extra elements that need to be part of a Damaris <variable> type.
Definition DamarisVar.hpp:48
Opm::DamarisOutput::DamarisVarXMLAttributes::ReturnXMLForVariable
std::string ReturnXMLForVariable()
Creates the XML representation of the variable from the available strings.
Definition DamarisVar.cpp:45
Opm::DamarisOutput::DamarisVar::size
std::size_t size()
Returns the number of elements in the memory area.
Definition DamarisVar.hpp:291
Opm::DamarisOutput::DamarisVar::returnXMLForVariable
std::string returnXMLForVariable()
Creates the XML representation of the variable from the available strings.
Definition DamarisVar.cpp:141
Opm::DamarisOutput::DamarisVar::data
T * data()
Returns the data pointer to shared memory, or nullptr if it has not been allocated.
Definition DamarisVar.hpp:253
Opm::DamarisOutput::DamarisVar::DamarisVar
DamarisVar(int dims, const std::vector< std::string > &param_names, const std::string &variable_name, int rank)
Constructor - sets private data values and dos not initialise the shared memory area.
Definition DamarisVar.cpp:77
Opm::DamarisOutput::DamarisVar::parameterIsSet
void parameterIsSet()
Allow a user to indicate that the Damaris variable has allocated a size - This method is usefull as a...
Definition DamarisVar.hpp:237
Opm::DamarisOutput::DamarisVar::clearVariableDamarisShmem
void clearVariableDamarisShmem()
Method to release the memory of the data written to the Damaris variable - Indicates that Damaris may...
Definition DamarisVar.cpp:248
Opm::DamarisOutput::DamarisVar::setDamarisPosition
void setDamarisPosition(const std::vector< int64_t > &positionsVals)
Method to set the Damaris position values.
Definition DamarisVar.cpp:188
Opm::DamarisOutput::DamarisVar::commitVariableDamarisShmem
void commitVariableDamarisShmem()
Method to commit the memory of the data written to the Damaris variable - Indicates that we will not ...
Definition DamarisVar.cpp:235
Opm::DamarisOutput::DamarisVar::setDamarisParameterAndShmem
void setDamarisParameterAndShmem(const std::vector< int > &paramSizeVal)
Method to set the Damaris paramater values and set the shmem region data_ptr_.
Definition DamarisVar.hpp:281
Opm::DamarisOutput::DamarisVar::setDamarisParameter
void setDamarisParameter(const std::vector< int > &paramSizeVal)
Method to set the Damaris paramater values.
Definition DamarisVar.cpp:148
Opm::DamarisOutput::DamarisVar::DamarisVar
DamarisVar(int dims, const std::vector< std::string > &param_names, const std::vector< int > &param_values, const std::string &variable_name, int rank)
Constructor - Sets private data values and also initialises the Damaris shared memory area for writin...
Definition DamarisVar.cpp:109
Opm::DamarisOutput::DamarisVar::setPointersToDamarisShmem
void setPointersToDamarisShmem()
Method to set the internal pointer (data_ptr_) to the Damaris shared memory area.
Definition DamarisVar.cpp:209
Opm::DamarisOutput
Below are the Damaris Keywords supported by Damaris to be filled in the built-in XML file.
Definition DamarisWriter.cpp:39
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43