Commit 64b82ebb authored by Mark Olesen's avatar Mark Olesen

ENH: added adiosWrite code and tutorials

parent 3a062f94
Pipeline #125 failed with stages
......@@ -22,9 +22,6 @@
# Derived files
lex.yy.c
# Corefiles
core
# Dependency files - anywhere
*.dep
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
. $WM_PROJECT_DIR/wmake/scripts/have_adios2
# -----------------------------------------------------------------------------
if have_adios2
then
adiosFoam/Allwmake
adiosWrite/Allwmake
else
hint_adios2
fi
# -----------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
. $WM_PROJECT_DIR/wmake/scripts/have_adios2
# -----------------------------------------------------------------------------
if have_adios2
then
wmake libso
else
echo "==> skip adiosFoam library"
fi
# -----------------------------------------------------------------------------
adiosFoam.C
core/adiosCore.C
controls/adiosRegionControl.C
read/adiosReader.C
read/adiosReaderCloud.C
read/adiosReaderField.C
write/adiosCoreWrite.C
write/adiosCoreWriteAttr.C
write/adiosCoreWriteVar.C
write/adiosCoreWriteMesh.C
write/adiosCoreWriteField.C
write/adiosCoreWriteCloud.C
time/adiosTime.C
LIB = $(FOAM_LIBBIN)/libadiosFoam
sinclude $(GENERAL_RULES)/ADIOS2
EXE_INC = \
$(PFLAGS) $(PINC) $(ADIOS_FLAGS) \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude
LIB_LIBS = \
$(PLIBS) $(ADIOS_LIBS) \
-lmeshTools \
-lfiniteVolume \
-lfiniteArea \
-llagrangian
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "adiosFoam.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::adiosFoam::defaultDirectory("adiosData");
const Foam::string Foam::adiosFoam::foamAttribute("/openfoam");
const Foam::string Foam::adiosFoam::timeAttribute("/time");
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
Foam::instantList Foam::adiosFoam::findTimes
(
const fileName& directory,
const word& constantName
)
{
// Read directory entries into a list
fileNameList dirEntries(readDir(directory, fileName::FILE, false));
// Initialise instant list
instantList Times(dirEntries.size() + 1);
label nTimes = 0;
// Check for "constant" - not yet useful
bool haveConstant = false;
for (const fileName& dirEntry : dirEntries)
{
if (dirEntry.hasExt("bp") && dirEntry.lessExt() == constantName)
{
Times[nTimes].value() = 0;
Times[nTimes].name() = word(dirEntry);
++nTimes;
haveConstant = true;
break;
}
}
// Read and parse all the entries in the directory
for (const fileName& dirEntry : dirEntries)
{
if (dirEntry.hasExt("bp"))
{
scalar val;
const word dirValue(dirEntry.lessExt());
if (readScalar(dirValue, val))
{
Times[nTimes].value() = val;
Times[nTimes].name() = word(dirEntry);
++nTimes;
}
}
}
// Reset the length of the times list
Times.setSize(nTimes);
if (haveConstant)
{
if (nTimes > 2)
{
std::sort(&Times[1], Times.end(), instant::less());
}
}
else if (nTimes > 1)
{
std::sort(&Times[0], Times.end(), instant::less());
}
return Times;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
Namespace
Foam::adiosFoam
Description
Core routines and definitions for OpenFOAM ADIOS files.
SourceFiles
adiosFoam.C
\*---------------------------------------------------------------------------*/
#ifndef adiosFoam_H
#define adiosFoam_H
#include "fileName.H"
#include "instantList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace adiosFoam
{
/*---------------------------------------------------------------------------*\
Namespace adiosFoam Declaration
\*---------------------------------------------------------------------------*/
//- The default directory name for ADIOS files ("adiosData")
extern const word defaultDirectory;
//- OpenFOAM global attributes within ADIOS file ("/openfoam")
extern const string foamAttribute;
//- OpenFOAM time attributes within ADIOS file ("/time")
extern const string timeAttribute;
//- Search a given directory for ADIOS time files
instantList findTimes
(
const fileName& directory,
const word& constantName = "constant"
);
//- Path name for a region
inline const word& regionPath
(
const word& regionName
)
{
return regionName;
}
//- Extract region name from a variable name (somewhat fragile)
inline word regionOf
(
const fileName& varName
)
{
const auto i = varName.find('/');
return varName.substr(0, i);
}
//- Path name for fields
inline fileName fieldPath
(
const word& regionName,
const fileName& var = fileName::null
)
{
return regionPath(regionName) / "field" / var;
}
//- Path name for meshes
inline fileName meshPath
(
const word& regionName,
const fileName& var = fileName::null
)
{
return regionPath(regionName) / "polyMesh" / var;
}
//- Path name for clouds
inline fileName cloudPath
(
const word& regionName,
const word& cloudName = word::null
)
{
return regionPath(regionName) / "cloud" / cloudName;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace adiosFoam
} // End namespace Foam
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "adiosRegionControl.H"
#include "cloud.H"
#include "fvMesh.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
void Foam::adiosFoam::regionControl::read
(
const fvMesh& mesh,
const dictionary& dict
)
{
resetAll();
name_ = mesh.name(); // ensure absolute consistency
Info<< " Region dict: " << name_ << endl;
const dictionary* writePtr = dict.findDict("write");
const dictionary* ignorePtr = dict.findDict("ignore");
const dictionary& wrtDict = (writePtr ? *writePtr : dictionary::null);
const dictionary& ignDict = (ignorePtr ? *ignorePtr : dictionary::null);
explicitWrite_ = wrtDict.getOrDefault("explicit", false);
requestedFields_.clear();
requestedClouds_.clear();
ignoredFields_.clear();
ignoredClouds_.clear();
if (explicitWrite_)
{
wrtDict.readEntry("fields", requestedFields_);
wrtDict.readEntry("clouds", requestedClouds_);
}
else
{
wrtDict.readIfPresent("fields", requestedFields_);
wrtDict.readIfPresent("clouds", requestedClouds_);
}
ignDict.readIfPresent("fields", ignoredFields_);
ignDict.readIfPresent("clouds", ignoredClouds_);
// Check if the requested fields are actually accessible
DynamicList<word> missing(requestedFields_.size());
for (const wordRe& what : requestedFields_)
{
if (what.isLiteral())
{
if (mesh.foundObject<regIOobject>(what))
{
Info<< " " << what;
}
else
{
missing.append(what);
}
}
}
// Also print the cloud names
for (const auto& name : requestedClouds_)
{
Info<< ' ' << name;
}
Info<< nl << endl;
if (missing.size())
{
WarningInFunction
<< nl
<< missing.size() << " objects not found in database:" << nl
<< " " << flatOutput(missing) << endl;
}
}
void Foam::adiosFoam::regionControl::resetAll()
{
explicitWrite_ = false;
requestedFields_.clear();
requestedClouds_.clear();
ignoredFields_.clear();
ignoredClouds_.clear();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::adiosFoam::regionControl::regionControl()
:
regionControl("")
{}
Foam::adiosFoam::regionControl::regionControl(const word& regionName)
:
name_(regionName),
explicitWrite_(false),
requestedFields_(),
requestedClouds_(),
ignoredFields_(),
ignoredClouds_(),
topoTime_(0),
pointTime_(0),
facesName_(),
pointsName_()
{}
Foam::adiosFoam::regionControl::regionControl
(
const fvMesh& mesh,
const dictionary& dict
)
:
regionControl(mesh.name())
{
read(mesh, dict);
pointTime_ = topoTime_ = mesh.time().timeOutputValue();
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::adiosFoam::regionControl::acceptCloudObject
(
const cloud& c
) const
{
const word& name = c.name();
return
(
// Not explicitly ignored
!ignoredClouds_.match(name)
&&
(
// auto-write or explicitly requested
(autoWrite() && c.writeOpt() == IOobject::AUTO_WRITE)
|| requestedClouds_.match(name)
)
);
}
bool Foam::adiosFoam::regionControl::acceptFieldObject
(
const regIOobject& obj
) const
{
const word& name = obj.name();
return
(
// NO clouds and not explicitly ignored
!isA<cloud>(obj) && !ignoredFields_.match(name)
&&
(
// auto-write or explicitly requested
(autoWrite() && obj.writeOpt() == IOobject::AUTO_WRITE)
|| requestedFields_.match(name)
)
&& !name.endsWith("_0") // ignore _0 fields
);
}
// TODO: handling mesh on input
// void resetPrimitives
// (
// const Xfer<pointField>& points,
// const Xfer<faceList>& faces,
// const Xfer<labelList>& owner,
// const Xfer<labelList>& neighbour,
// const labelList& patchSizes,
// const labelList& patchStarts,
// const bool validBoundary = true
// );
// resetPrimitives(*face,
// Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
// {
// if (debug)
// {
// InfoInFunction << "Updating mesh based on saved data." << endl;
// }
enum Foam::polyMesh::readUpdateState
Foam::adiosFoam::regionControl::updateTimes(const fvMesh& mesh) const
{
const double now = mesh.time().timeOutputValue();
const word pointsInstance = mesh.pointsInstance().name();
const word facesInstance = mesh.facesInstance().name();
polyMesh::readUpdateState state = polyMesh::UNCHANGED;
if (pointsName_ != pointsInstance)
{
state = polyMesh::POINTS_MOVED;
pointsName_ = pointsInstance;
pointTime_ = now;
}
if (facesName_ != facesInstance)
{
state = polyMesh::TOPO_CHANGE;
facesName_ = facesInstance;
topoTime_ = now;
}
return state;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
Class
Foam::adiosFoam::adiosRegionControl
Description
Controls for managing region and cloud writing
SourceFiles
adiosRegionControl.C
\*---------------------------------------------------------------------------*/
#ifndef adiosFoamRegionControl_H
#define adiosFoamRegionControl_H
#include "adiosTime.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class cloud;
class fvMesh;
namespace adiosFoam
{
/*---------------------------------------------------------------------------*\
Class regionControl Declaration
\*---------------------------------------------------------------------------*/
//- Per-region info variables grouped together to be able
//- to create a list of them
class regionControl
{
// Private Data
//- Name of the region
word name_;
//- Normally don't want an explicit-write (want auto-write)
bool explicitWrite_;
//- Names of volume fields to write
wordRes requestedFields_;
//- Names of clouds to write
wordRes requestedClouds_;
//- Names of volume fields to ignore
wordRes ignoredFields_;
//- Names of clouds to ignored
wordRes ignoredClouds_;
// Track changes to mesh status (points/faces)
//- Time of the topology status at the last mesh change
mutable scalar topoTime_;
//- Time of the point status at the last mesh change
mutable scalar pointTime_;
//- Name of the most recent faces instance
mutable word facesName_;
//- Name of the most recent points instance
mutable word pointsName_;
// Private Member Functions
//- Read info for one region from its own dictionary
void read(const fvMesh& mesh, const dictionary& dict);
//- Reset all information
void resetAll();
public:
// Constructors