Commit 8e4ad9fd authored by mark's avatar mark

ENH: rationalize and reduce the number of write methods.

- Old code covered almost everything. Now we just have a few categories:

  Attributes
  ~~~~~~~~~~
      Put: int, scalar, string, arrays of the same

  Variables
  ~~~~~~~~~
      - Put ONE label (eg, nCells).
        Write as global array with offset according to the procI.

      - Put List<T>
        Write as local data of the underlying cmptType.
        Tag dimensions as size * nComponents.

      - define stream (bytes)
      - write  stream data (bytes)
parent e49810e3
......@@ -4,6 +4,7 @@ adiosTime.C
adiosCore.C
adiosCoreWrite.C
adiosCoreWriteAttr.C
adiosCoreWriteVar.C
adiosCoreWriteMesh.C
adiosCoreWriteField.C
......
This diff is collapsed.
This diff is collapsed.
......@@ -37,7 +37,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::adiosCoreWrite::defineAttribute
void Foam::adiosCoreWrite::putAttribute
(
const char* attrName,
const char* varName,
......@@ -56,18 +56,18 @@ void Foam::adiosCoreWrite::defineAttribute
}
void Foam::adiosCoreWrite::defineAttribute
void Foam::adiosCoreWrite::putAttribute
(
const char* attrName,
const string& varName,
const string& value
)
{
defineAttribute(attrName, varName.c_str(), value);
putAttribute(attrName, varName.c_str(), value);
}
void Foam::adiosCoreWrite::defineIntAttribute
void Foam::adiosCoreWrite::putIntAttribute
(
const char* attrName,
const char* varName,
......@@ -88,18 +88,18 @@ void Foam::adiosCoreWrite::defineIntAttribute
}
void Foam::adiosCoreWrite::defineIntAttribute
void Foam::adiosCoreWrite::putIntAttribute
(
const char* attrName,
const string& varName,
const int value
)
{
defineIntAttribute(attrName, varName.c_str(), value);
putIntAttribute(attrName, varName.c_str(), value);
}
void Foam::adiosCoreWrite::defineScalarAttribute
void Foam::adiosCoreWrite::putScalarAttribute
(
const char* attrName,
const char* varName,
......@@ -120,18 +120,18 @@ void Foam::adiosCoreWrite::defineScalarAttribute
}
void Foam::adiosCoreWrite::defineScalarAttribute
void Foam::adiosCoreWrite::putScalarAttribute
(
const char* attrName,
const string& varName,
const double value
)
{
defineScalarAttribute(attrName, varName.c_str(), value);
putScalarAttribute(attrName, varName.c_str(), value);
}
bool Foam::adiosCoreWrite::defineListAttribute
bool Foam::adiosCoreWrite::putListAttribute
(
const char* attrName,
const string& varName,
......@@ -148,7 +148,7 @@ bool Foam::adiosCoreWrite::defineListAttribute
groupID_,
attrName,
varName.c_str(),
adios_integer,
adiosTraits<int>::adiosType,
list.size(),
list.cdata()
);
......@@ -157,7 +157,7 @@ bool Foam::adiosCoreWrite::defineListAttribute
}
bool Foam::adiosCoreWrite::defineListAttribute
bool Foam::adiosCoreWrite::putListAttribute
(
const char* attrName,
const string& varName,
......@@ -174,7 +174,7 @@ bool Foam::adiosCoreWrite::defineListAttribute
groupID_,
attrName,
varName.c_str(),
adios_double,
adiosTraits<double>::adiosType,
list.size(),
list.cdata()
);
......@@ -183,19 +183,13 @@ bool Foam::adiosCoreWrite::defineListAttribute
}
bool Foam::adiosCoreWrite::defineListAttribute
bool Foam::adiosCoreWrite::putListAttribute
(
const char* attrName,
const string& varName,
const wordList& list
const CStringList& cstrings
)
{
CStringList cstrings;
if (!list.empty())
{
cstrings.reset(list);
}
if (cstrings.size())
{
adios_define_attribute_byvalue
......@@ -215,11 +209,11 @@ bool Foam::adiosCoreWrite::defineListAttribute
}
bool Foam::adiosCoreWrite::defineListAttribute
bool Foam::adiosCoreWrite::putListAttribute
(
const char* attrName,
const string& varName,
const stringList& list
const wordList& list
)
{
CStringList cstrings;
......@@ -228,26 +222,28 @@ bool Foam::adiosCoreWrite::defineListAttribute
cstrings.reset(list);
}
if (cstrings.size())
{
adios_define_attribute_byvalue
(
groupID_,
attrName,
varName.c_str(),
adios_string_array,
cstrings.size(),
cstrings.strings()
);
return putListAttribute(attrName, varName, cstrings);
}
return true;
bool Foam::adiosCoreWrite::putListAttribute
(
const char* attrName,
const string& varName,
const stringList& list
)
{
CStringList cstrings;
if (!list.empty())
{
cstrings.reset(list);
}
return false;
return putListAttribute(attrName, varName, cstrings);
}
bool Foam::adiosCoreWrite::defineDimensionsAttribute
bool Foam::adiosCoreWrite::putDimensionsAttribute
(
const string& varName,
const dimensionSet& dims
......@@ -259,7 +255,7 @@ bool Foam::adiosCoreWrite::defineDimensionsAttribute
units[i] = dims[i];
}
return defineListAttribute("dimensions", varName, units);
return putListAttribute("dimensions", varName, units);
}
......
......@@ -26,10 +26,9 @@ License
#include "adiosCoreWrite.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
void Foam::adiosCoreWrite::definePatchAttributes(const polyMesh& mesh)
void Foam::adiosCoreWrite::putPatchAttributes(const polyMesh& mesh)
{
if (Pstream::master())
{
......@@ -59,9 +58,9 @@ void Foam::adiosCoreWrite::definePatchAttributes(const polyMesh& mesh)
const fileName varPath = adiosCore::regionPath(mesh.name());
defineIntAttribute("nPatches", varPath, nPatches);
defineListAttribute("patch-names", varPath, pNames);
defineListAttribute("patch-types", varPath, pTypes);
putIntAttribute("nPatches", varPath, nPatches);
putListAttribute("patch-names", varPath, pNames);
putListAttribute("patch-types", varPath, pTypes);
}
}
......@@ -72,11 +71,8 @@ void Foam::adiosCoreWrite::writeMeshPoints(const polyMesh& mesh)
// polyMesh/nPoints (summary)
// polyMesh/points: 2D array (N points x 3 coordinates)
defineIntVariable(varPath/"nPoints");
defineVectorVariable(varPath/"points", mesh.nPoints());
writeIntVariable(varPath/"nPoints", mesh.nPoints());
writeVariable(varPath/"points", mesh.points());
putLabelVariable(varPath/"nPoints", mesh.nPoints());
putListVariable(varPath/"points", mesh.points());
}
......@@ -84,55 +80,27 @@ void Foam::adiosCoreWrite::writeMeshFaces(const polyMesh& mesh)
{
const fileName varPath = adiosCore::meshPath(mesh.name());
defineIntVariable(varPath/"nCells"); // polyMesh/nCells
defineIntVariable(varPath/"nFaces"); // polyMesh/nFaces
defineIntVariable(varPath/"nInternalFaces"); // polyMesh/nInternalFaces
writeIntVariable(varPath/"nCells", mesh.nCells());
writeIntVariable(varPath/"nFaces", mesh.nFaces());
writeIntVariable(varPath/"nInternalFaces", mesh.nInternalFaces());
// polyMesh/nCells
// polyMesh/nFaces
// polyMesh/nInternalFaces
const fileName facesPath = varPath/"faces";
putLabelVariable(varPath/"nCells", mesh.nCells());
putLabelVariable(varPath/"nFaces", mesh.nFaces());
putLabelVariable(varPath/"nInternalFaces", mesh.nInternalFaces());
// polyMesh/faces - save in compact form
// need transcription for output
{
const faceList& faces = mesh.faces();
// indices = nFaces+1
label count = faces.size()+1;
const fileName facesPath = varPath/"faces";
defineIntVariable(facesPath/"indices", count);
// count size for compact format
count = 0;
forAll(faces, faceI)
{
count += faces[faceI].size();
}
// polyMesh/faces - save in compact form
// for this we use two separate lists
defineIntVariable(facesPath/"content", count);
}
// this is not particularly elegant, but should be stable
// polyMesh/faces - save in compact form
// for this we use two separate lists
{
const faceList& faces = mesh.faces();
const label nFaces = faces.size();
// this is not particularly elegant, but should be stable
List<label> start(nFaces+1);
// Use transfer buffer to avoid reallocations
// UList<label> start
// (
// reinterpret_cast<label*>(transferBuffer().data()),
// transferBuffer().capacity() / sizeof(label)
// );
// Use transfer buffer to avoid reallocations
// Pout<< "indices " << start.size() << endl;
// calculate start as per CompactIOList.C:
start[0] = 0;
forAll(faces, faceI)
......@@ -151,20 +119,10 @@ void Foam::adiosCoreWrite::writeMeshFaces(const polyMesh& mesh)
}
}
writeVariable(facesPath/"indices", start);
putListVariable(facesPath/"indices", start);
// this is not particularly elegant, but should be stable
List<label> elems(start[start.size()-1]);
// Use transfer buffer to avoid reallocations
// UList<label> elems
// (
// reinterpret_cast<label*>(transferBuffer().data()),
// transferBuffer().capacity() / sizeof(label)
// );
// Pout<< "size: " << elems.size() << endl;
// calculate content as per CompactIOList.C:
label elemI = 0;
forAll(faces, faceI)
......@@ -177,59 +135,18 @@ void Foam::adiosCoreWrite::writeMeshFaces(const polyMesh& mesh)
}
}
writeVariable(facesPath/"content", elems);
putListVariable(facesPath/"content", elems);
}
// polyMesh/owner - direct write
defineIntVariable(varPath/"owner", mesh.faceOwner().size());
writeVariable(varPath/"owner", mesh.faceOwner());
putListVariable(varPath/"owner", mesh.faceOwner());
// polyMesh/neighbour - direct write
defineIntVariable(varPath/"neighbour", mesh.faceNeighbour().size());
writeVariable(varPath/"neighbour", mesh.faceNeighbour());
putListVariable(varPath/"neighbour", mesh.faceNeighbour());
// polyMesh/boundary - byte-stream
writeStreamVariable(varPath/"boundary", mesh.boundaryMesh());
// processor addressing types
//
// polyMesh/boundaryProcAddressing
// polyMesh/cellProcAddressing
// polyMesh/faceProcAddressing
// polyMesh/pointProcAddressing
//
// save directly as polyMesh/addressing/boundary, ...
{
const fileName addrPath = varPath/"procAddressing";
const FixedList<word, 4> addressingTypes
{
"boundary", "cell", "face", "point"
};
const word facesInst = mesh.facesInstance();
for (const word& category : addressingTypes)
{
// label fields
labelIOList list
(
IOobject
(
category + "ProcAddressing",
facesInst,
polyMesh::meshSubDir,
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
);
// polyMesh/addressing/ - direct write
defineIntVariable(addrPath/category, list.size());
writeVariable(addrPath/category, list);
}
}
}
......@@ -273,9 +190,8 @@ void Foam::adiosCoreWrite::writeMeshAddressing(const polyMesh& mesh)
)
);
// polyMesh/procAddressing/ - direct write
defineIntVariable(addrPath/category, list.size());
writeVariable(addrPath/category, list);
// polyMesh/procAddressing/XXX - direct write
putListVariable(addrPath/category, list);
}
}
......
......@@ -25,26 +25,22 @@ License
#include "adiosCoreWrite.H"
#include "pTraits.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "OBufStream.H"
#include "IOstream.H"
#include "IOstreams.H"
#include "Ostream.H"
#include "processorFvPatch.H"
#include "processorPointPatch.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
template<class Type>
int64_t Foam::adiosCoreWrite::defineListVariable
int64_t Foam::adiosCoreWrite::putListVariable
(
const string& name,
const UList<Type>& list
)
{
typedef typename pTraits<Type>::cmptType cmptType;
const string local =
(
pTraits<Type>::nComponents > 1
......@@ -57,36 +53,18 @@ int64_t Foam::adiosCoreWrite::defineListVariable
groupID_,
name.c_str(), // name
nullptr, // path (deprecated)
adiosTraits<typename pTraits<Type>::cmptType>::adiosType, // data-type
adiosTraits<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());
// adios_set_transform(varid, transform);
adios_write_byid(fileID_, varid, list.cdata());
}
else
{
......@@ -100,46 +78,17 @@ int64_t Foam::adiosCoreWrite::writeListVariable
}
template<class Type>
int64_t Foam::adiosCoreWrite::defineFieldVariable
(
const string& name,
size_t count
)
{
const string local =
(
pTraits<Type>::nComponents > 1
? Foam::name(count) + "," + Foam::name(pTraits<Type>::nComponents)
: Foam::name(count)
);
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::writeStreamVariable
(
const fileName& varName,
const string& name,
const Type& obj
)
{
OutputCounter counter(adiosCore::strFormat);
counter << obj;
int64_t varid = defineStreamVariable(varName, counter.size());
int64_t varid = defineStreamVariable(name, counter.size());
// Use transfer buffer to avoid too many reallocations
// - Needs some rework to cleanup or for byte-alignment?
......@@ -149,7 +98,7 @@ int64_t Foam::adiosCoreWrite::writeStreamVariable
os << obj;
// Do the actual write (as stream)
writeVariable(varName, transferBuffer());
writeGenericVariable(varid, transferBuffer().cdata());
return varid;
}
......@@ -177,8 +126,8 @@ int64_t Foam::adiosCoreWrite::writeGeometricField
if (Pstream::master())
{
// Attributes are global - only passed via the master
defineAttribute("class", varName, field.type());
defineDimensionsAttribute(varName, field.dimensions());
putAttribute("class", varName, field.type());
putDimensionsAttribute(varName, field.dimensions());
}
// "internalField" as primitive field
......@@ -207,7 +156,7 @@ int64_t Foam::adiosCoreWrite::writeGeometricField
}
pTypes.setSize(nPatches);
defineListAttribute("patch-types", varName, pTypes);
putListAttribute("patch-types", varName, pTypes);
}
// "boundaryField" as byte stream, but need adapter for dictionary format
......@@ -240,8 +189,8 @@ int64_t Foam::adiosCoreWrite::writeInternalField
if (Pstream::master())
{
// Attributes are global - only passed via the master
defineAttribute("class", varName, field.type());
defineDimensionsAttribute(varName, field.dimensions());
putAttribute("class", varName, field.type());
putDimensionsAttribute(varName, field.dimensions());
}
return writeField(varName, field);
......@@ -256,18 +205,7 @@ int64_t Foam::adiosCoreWrite::writeField
const DimensionedField<Type, GeoMesh>& field
)
{
int64_t varid = defineFieldVariable<Type>
(
varName/local,
size_t(field.size())
);
writeVariable
(
varName/local,
field.field()
);
return varid;
return putListVariable(varName/local, field.field());
}
......@@ -294,8 +232,7 @@ void Foam::adiosCoreWrite::writeMeshZones
const zone& zn = zones[zonei];
const word& zoneName = zn.name();
defineIntVariable(zonePath/zoneName, zn.size());
writeVariable(zonePath/zoneName, zn);
putListVariable(zonePath/zoneName, zn);
}
}
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int64_t Foam::adiosCoreWrite::defineGenericVariable
(
const string& name,
enum ADIOS_DATATYPES type,
const string& local,
const string& global,
const string& offsets
)
{
int64_t varid = adios_define_var
(
groupID_,
name.c_str(), // name
nullptr, // path (deprecated)
type, // data-type
local.c_str(), // local dimensions
global.c_str(), // global dimensions
offsets.c_str() // local offsets
);
vars_.insert(name, varid);
return varid;
}
void Foam::adiosCoreWrite::writeGenericVariable
(
const int64_t varid,
const void* value
)
{
if (fileID_)
{
adios_write_byid(fileID_, varid, value);
}
else
{
WarningInFunction
<< "Attempting to write adios variable "
<< "without an open adios file"
<< endl;
}
}
void Foam::adiosCoreWrite::writeGenericVariable
(
const string& name,
const void* value
)
{
// could also check that variable has been defined
// vars_.found(name);
if (fileID_)
{
adios_write(fileID_, name.c_str(), value);
}
else
{
WarningInFunction
<< "Attempting to write adios variable "
<< name << " without an open adios file"
<< endl;
}
}
int64_t Foam::adiosCoreWrite::putLabelVariable
(
const string& name,
const label value
)
{
int64_t varid = adios_define_var
(
groupID_,
name.c_str(), // name
nullptr, // path (deprecated)
adiosTraits<label>::adiosType, // data-type
"1", // local dimensions
Foam::name(Pstream::nProcs()).c_str(), // global 1D array of this info
Foam::name(Pstream::myProcNo()).c_str() // offsets of this process into array
);
vars_.insert(name, varid);
if (fileID_)
{
adios_write_byid(fileID_, varid, &value);
}
else
{
WarningInFunction
<< "Attempting to write adios variable \""
<< name << "\" without an open adios file"
<< endl;
}
return varid;
}
int64_t Foam::adiosCoreWrite::defineStreamVariable
(
const string& name,
size_t count
)
{
// Use unsigned byte for raw storage
int64_t varid = adios_define_var
(
groupID_,
name.c_str(), // name
nullptr, // path (deprecated)
adios_unsigned_byte, // data-type
Foam::name(count).c_str(), // local dimensions
nullptr, // global dimensions
nullptr // local offsets
);
vars_.insert(name, varid);
return varid;
}
// ************************************************************************* //
......@@ -21,14 +21,11 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::Scalar
InClass
Foam::adiosTraits
Description