Skip to content
Snippets Groups Projects
Commit e49810e3 authored by mark's avatar mark
Browse files

STYLE: move attributes to separate file

parent 3c10ac3e
Branches
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ adiosTime.C ...@@ -3,6 +3,7 @@ adiosTime.C
adiosCore.C adiosCore.C
adiosCoreWrite.C adiosCoreWrite.C
adiosCoreWriteAttr.C
adiosCoreWriteMesh.C adiosCoreWriteMesh.C
adiosCoreWriteField.C adiosCoreWriteField.C
......
...@@ -617,265 +617,31 @@ int64_t Foam::adiosCoreWrite::defineVectorVariable ...@@ -617,265 +617,31 @@ int64_t Foam::adiosCoreWrite::defineVectorVariable
} }
void Foam::adiosCoreWrite::defineAttribute
(
const char* attrName,
const char* varName,
const string& value
)
{
adios_define_attribute
(
groupID_,
attrName,
varName,
adios_string,
value.c_str(),
nullptr
);
}
void Foam::adiosCoreWrite::defineAttribute
(
const char* attrName,
const string& varName,
const string& value
)
{
defineAttribute(attrName, varName.c_str(), value);
}
void Foam::adiosCoreWrite::defineIntAttribute
(
const char* attrName,
const char* varName,
const int value
)
{
int intval = value;
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName,
adios_integer,
1,
&intval
);
}
void Foam::adiosCoreWrite::defineIntAttribute
(
const char* attrName,
const string& varName,
const int value
)
{
defineIntAttribute(attrName, varName.c_str(), value);
}
void Foam::adiosCoreWrite::defineScalarAttribute
(
const char* attrName,
const char* varName,
const double value
)
{
double fltval = value;
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName,
adios_double,
1,
&fltval
);
}
void Foam::adiosCoreWrite::defineScalarAttribute
(
const char* attrName,
const string& varName,
const double value
)
{
defineScalarAttribute(attrName, varName.c_str(), value);
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const UList<int>& list
)
{
if (list.empty())
{
return false;
}
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_integer,
list.size(),
list.cdata()
);
return true;
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const UList<double>& list
)
{
if (list.empty())
{
return false;
}
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_double,
list.size(),
list.cdata()
);
return true;
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const wordList& list
)
{
CStringList cstrings;
if (!list.empty())
{
cstrings.reset(list);
}
if (cstrings.size())
{
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_string_array,
cstrings.size(),
cstrings.strings()
);
return true;
}
return false;
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const stringList& list
)
{
CStringList cstrings;
if (!list.empty())
{
cstrings.reset(list);
}
if (cstrings.size())
{
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_string_array,
cstrings.size(),
cstrings.strings()
);
return true;
}
return false;
}
bool Foam::adiosCoreWrite::defineDimensionsAttribute
(
const string& varName,
const dimensionSet& dims
)
{
scalarList units(dimensionSet::nDimensions);
forAll(units, i)
{
units[i] = dims[i];
}
return defineListAttribute("dimensions", varName, units);
}
void Foam::adiosCoreWrite::writeVariable void Foam::adiosCoreWrite::writeVariable
( (
const char* name, const string& name,
const void* value const void* value
) )
{ {
const char* cname = name.c_str();
// could also check that variable has been defined // could also check that variable has been defined
// vars_.found(name); // vars_.found(cname);
if (fileID_) if (fileID_)
{ {
adios_write(fileID_, name, value); adios_write(fileID_, cname, value);
} }
else else
{ {
WarningInFunction WarningInFunction
<< "Attempting to write adios variable \"" << "Attempting to write adios variable "
<< name << "\" without an open adios file" << name << " without an open adios file"
<< endl; << endl;
} }
} }
void Foam::adiosCoreWrite::writeVariable
(
const string& name,
const void* value
)
{
writeVariable(name.c_str(), value);
}
void Foam::adiosCoreWrite::writeIntVariable void Foam::adiosCoreWrite::writeIntVariable
( (
const char* name, const char* name,
......
...@@ -231,6 +231,97 @@ protected: ...@@ -231,6 +231,97 @@ protected:
// General adios handling // General adios handling
// Attributes
//- Define a string attribute
void defineAttribute
(
const char* attrName,
const char* varName,
const string& value
);
//- Define a string attribute
void defineAttribute
(
const char* attrName,
const string& varName,
const string& value
);
//- Define an int attribute
void defineIntAttribute
(
const char* attrName,
const char* varName,
const int value
);
//- Define an int attribute
void defineIntAttribute
(
const char* attrName,
const string& varName,
const int value
);
//- Define a double attribute
void defineScalarAttribute
(
const char* attrName,
const char* varName,
const double value
);
//- Define a double attribute
void defineScalarAttribute
(
const char* attrName,
const string& varName,
const double value
);
//- Define an array attribute of integer values
bool defineListAttribute
(
const char* attrName,
const string& varName,
const UList<int>& list
);
//- Define an array attribute of double values
bool defineListAttribute
(
const char* attrName,
const string& varName,
const UList<double>& list
);
//- Define an array attribute of strings
bool defineListAttribute
(
const char* attrName,
const string& varName,
const wordList& list
);
//- Define an array attribute of strings
bool defineListAttribute
(
const char* attrName,
const string& varName,
const stringList& list
);
//- Define an "dimensions" attribute (an array of doubles).
bool defineDimensionsAttribute
(
const string& varName,
const dimensionSet& dims
);
//- Generic define a variable, return adios Id. //- Generic define a variable, return adios Id.
int64_t defineVariable int64_t defineVariable
( (
...@@ -322,100 +413,13 @@ protected: ...@@ -322,100 +413,13 @@ protected:
template<class Type> template<class Type>
int64_t defineFieldVariable(const string& name, size_t count); int64_t defineFieldVariable(const string& name, size_t count);
//- Define a list variable with size elements and nCmpt components.
//- Define a string attribute // Return adios Id.
void defineAttribute template<class T>
( int64_t defineListVariable
const char* attrName,
const char* varName,
const string& value
);
//- Define a string attribute
void defineAttribute
(
const char* attrName,
const string& varName,
const string& value
);
//- Define an int attribute
void defineIntAttribute
(
const char* attrName,
const char* varName,
const int value
);
//- Define an int attribute
void defineIntAttribute
(
const char* attrName,
const string& varName,
const int value
);
//- Define a double attribute
void defineScalarAttribute
(
const char* attrName,
const char* varName,
const double value
);
//- Define a double attribute
void defineScalarAttribute
(
const char* attrName,
const string& varName,
const double value
);
//- Define an array attribute of integer values
bool defineListAttribute
(
const char* attrName,
const string& varName,
const UList<int>& list
);
//- Define an array attribute of double values
bool defineListAttribute
(
const char* attrName,
const string& varName,
const UList<double>& list
);
//- Define an array attribute of strings
bool defineListAttribute
(
const char* attrName,
const string& varName,
const wordList& list
);
//- Define an array attribute of strings
bool defineListAttribute
(
const char* attrName,
const string& varName,
const stringList& list
);
//- Define an "dimensions" attribute (an array of doubles).
bool defineDimensionsAttribute
(
const string& varName,
const dimensionSet& dims
);
//- Write a variable
void writeVariable
( (
const char* name, const string& name,
const void* value const UList<T>& list
); );
//- Write a variable //- Write a variable
...@@ -427,14 +431,11 @@ protected: ...@@ -427,14 +431,11 @@ protected:
//- Write a variable from the list contents //- Write a variable from the list contents
template<class T> template<class T>
inline void writeVariable inline int64_t writeListVariable
( (
const char* name, const string& name,
const UList<T>& list const UList<T>& list
) );
{
writeVariable(name, list.cdata());
}
//- Write a variable from the list contents //- Write a variable from the list contents
template<class T> template<class T>
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 Norbert Podhorszki
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM 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.
OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "adiosCoreWrite.H"
#include "adiosTime.H"
#include "foamVersion.H"
#include "endian.H"
#include "OSspecific.H"
// some internal pre-processor stringifications
#undef STRINGIFY
#undef TO_STRING
#define STRINGIFY(x) #x
#define TO_STRING(x) STRINGIFY(x)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::adiosCoreWrite::defineAttribute
(
const char* attrName,
const char* varName,
const string& value
)
{
adios_define_attribute
(
groupID_,
attrName,
varName,
adios_string,
value.c_str(),
nullptr
);
}
void Foam::adiosCoreWrite::defineAttribute
(
const char* attrName,
const string& varName,
const string& value
)
{
defineAttribute(attrName, varName.c_str(), value);
}
void Foam::adiosCoreWrite::defineIntAttribute
(
const char* attrName,
const char* varName,
const int value
)
{
int intval = value;
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName,
adios_integer,
1,
&intval
);
}
void Foam::adiosCoreWrite::defineIntAttribute
(
const char* attrName,
const string& varName,
const int value
)
{
defineIntAttribute(attrName, varName.c_str(), value);
}
void Foam::adiosCoreWrite::defineScalarAttribute
(
const char* attrName,
const char* varName,
const double value
)
{
double fltval = value;
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName,
adios_double,
1,
&fltval
);
}
void Foam::adiosCoreWrite::defineScalarAttribute
(
const char* attrName,
const string& varName,
const double value
)
{
defineScalarAttribute(attrName, varName.c_str(), value);
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const UList<int>& list
)
{
if (list.empty())
{
return false;
}
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_integer,
list.size(),
list.cdata()
);
return true;
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const UList<double>& list
)
{
if (list.empty())
{
return false;
}
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_double,
list.size(),
list.cdata()
);
return true;
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const wordList& list
)
{
CStringList cstrings;
if (!list.empty())
{
cstrings.reset(list);
}
if (cstrings.size())
{
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_string_array,
cstrings.size(),
cstrings.strings()
);
return true;
}
return false;
}
bool Foam::adiosCoreWrite::defineListAttribute
(
const char* attrName,
const string& varName,
const stringList& list
)
{
CStringList cstrings;
if (!list.empty())
{
cstrings.reset(list);
}
if (cstrings.size())
{
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_string_array,
cstrings.size(),
cstrings.strings()
);
return true;
}
return false;
}
bool Foam::adiosCoreWrite::defineDimensionsAttribute
(
const string& varName,
const dimensionSet& dims
)
{
scalarList units(dimensionSet::nDimensions);
forAll(units, i)
{
units[i] = dims[i];
}
return defineListAttribute("dimensions", varName, units);
}
// ************************************************************************* //
...@@ -38,6 +38,68 @@ License ...@@ -38,6 +38,68 @@ License
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
template<class Type>
int64_t Foam::adiosCoreWrite::defineListVariable
(
const string& name,
const UList<Type>& list
)
{
const string local =
(
pTraits<Type>::nComponents > 1
? Foam::name(list.size()) + "," + Foam::name(pTraits<Type>::nComponents)
: Foam::name(list.size())
);
int64_t varid = adios_define_var
(
groupID_,
name.c_str(), // name
nullptr, // path (deprecated)
adiosTraits<typename pTraits<Type>::cmptType>::adiosType, // data-type
local.c_str(), // local dimensions
nullptr, // global dimensions
nullptr // local offsets
);
vars_.insert(name, varid);
return varid;
}
template<class Type>
int64_t Foam::adiosCoreWrite::writeListVariable
(
const string& name,
const UList<Type>& list
)
{
const char* cname = name.c_str();
// could also check that variable has been defined
// vars_.found(cname);
int64_t varid = 0;
// defineListVariable<Type>(name, list);
if (fileID_)
{
varid = adios_write(fileID_, cname, list.cdata());
}
else
{
WarningInFunction
<< "Attempting to write adios variable "
<< name << " without an open adios file"
<< endl;
}
return varid;
}
template<class Type> template<class Type>
int64_t Foam::adiosCoreWrite::defineFieldVariable int64_t Foam::adiosCoreWrite::defineFieldVariable
( (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment