Commit 54da8848 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add in ensightWrite function object (issue # 241)

- Currently no writing of clouds.
  Managing restarts needs more thought.
parent b04a6a05
abort/abort.C
codedFunctionObject/codedFunctionObject.C
ensightWrite/ensightWrite.C
removeRegisteredObject/removeRegisteredObject.C
......
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/conversion/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/ODE/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
......@@ -7,6 +9,8 @@ EXE_INC = \
LIB_LIBS = \
-lfiniteVolume \
-lconversion \
-lsampling \
-lfluidThermophysicalModels \
-lcompressibleTransportModels \
-lODE
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 "ensightWrite.H"
#include "Time.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(ensightWrite, 0);
addToRunTimeSelectionTable
(
functionObject,
ensightWrite,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::ensightWrite::uniqWords(wordReList& lst)
{
boolList retain(lst.size());
wordHashSet uniq;
forAll(lst, i)
{
const wordRe& select = lst[i];
retain[i] =
(
select.isPattern()
|| uniq.insert(static_cast<const word&>(select))
);
}
inplaceSubset(retain, lst);
}
int Foam::functionObjects::ensightWrite::process(const word& fieldName)
{
int state = 0;
writeVolField<scalar>(fieldName, state);
writeVolField<vector>(fieldName, state);
writeVolField<sphericalTensor>(fieldName, state);
writeVolField<symmTensor>(fieldName, state);
writeVolField<tensor>(fieldName, state);
return state;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::ensightWrite::ensightWrite
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeOpts_
(
dict.found("format")
? IOstream::formatEnum(dict.lookup("format"))
: runTime.writeFormat()
),
caseOpts_(writeOpts_.format()),
selectFields_(),
dirName_("ensightWrite"),
consecutive_(false)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::ensightWrite::~ensightWrite()
{
if (ensCase_.valid())
{
// finalize case
ensCase().write();
ensCase_.clear();
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::ensightWrite::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
//
// writer options
//
writeOpts_.noPatches
(
dict.lookupOrDefault<Switch>("noPatches", false)
);
writeOpts_.deprecatedOrder
(
dict.lookupOrDefault<Switch>("deprecatedOrder", false)
);
if (dict.found("patches"))
{
wordReList lst(dict.lookup("patches"));
uniqWords(lst);
writeOpts_.patchSelection(lst);
}
if (dict.found("faceZones"))
{
wordReList lst(dict.lookup("faceZones"));
uniqWords(lst);
writeOpts_.faceZoneSelection(lst);
}
//
// case options
//
caseOpts_.width(dict.lookupOrDefault<label>("width", 8));
// remove existing output directory
caseOpts_.overwrite(dict.lookupOrDefault<Switch>("overwrite", false));
//
// other options
//
dict.readIfPresent("directory", dirName_);
consecutive_ = dict.lookupOrDefault<Switch>("consecutive", false);
//
// output fields
//
dict.lookup("fields") >> selectFields_;
uniqWords(selectFields_);
return true;
}
bool Foam::functionObjects::ensightWrite::execute()
{
return true;
}
bool Foam::functionObjects::ensightWrite::write()
{
const Time& t = obr_.time();
if (!ensCase_.valid())
{
// Define sub-directory name to use for EnSight data.
// The path to the ensight directory is at case level only
// - For parallel cases, data only written from master
fileName ensightDir = dirName_;
if (!ensightDir.isAbsolute())
{
ensightDir = t.rootPath()/t.globalCaseName()/ensightDir;
}
ensCase_.reset
(
new ensightCase
(
ensightDir,
t.globalCaseName(),
caseOpts_
)
);
}
if (!ensMesh_.valid())
{
ensMesh_.reset(new ensightMesh(mesh_, writeOpts_));
if (ensMesh_().needsUpdate())
{
ensMesh_().correct();
}
// assume static geometry - need to fix later
autoPtr<ensightGeoFile> os = ensCase_().newGeometry(false);
ensMesh_().write(os);
}
else if (ensMesh_().needsUpdate())
{
// appears to have moved
ensMesh_().correct();
autoPtr<ensightGeoFile> os = ensCase_().newGeometry(true);
ensMesh_().write(os);
}
Log << type() << " " << name() << " write: (";
if (consecutive_)
{
ensCase().nextTime(t.value());
}
else
{
ensCase().setTime(t.value(), t.timeIndex());
}
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
DynamicList<word> missing(selectFields_.size());
DynamicList<word> ignored(selectFields_.size());
// check exact matches first
forAll(selectFields_, i)
{
const wordRe& select = selectFields_[i];
if (!select.isPattern())
{
const word& fieldName = static_cast<const word&>(select);
if (!candidates.erase(fieldName))
{
missing.append(fieldName);
}
else if (process(fieldName) < 1)
{
ignored.append(fieldName);
}
}
}
forAllConstIter(wordHashSet, candidates, iter)
{
process(iter.key());
}
Log << " )" << endl;
if (missing.size())
{
WarningInFunction
<< "Missing field " << missing << endl;
}
if (ignored.size())
{
WarningInFunction
<< "Unprocessed field " << ignored << endl;
}
return true;
}
bool Foam::functionObjects::ensightWrite::end()
{
if (ensCase_.valid())
{
// finalize case
ensCase().write();
ensCase_.clear();
}
return true;
}
void Foam::functionObjects::ensightWrite::updateMesh(const mapPolyMesh& mpm)
{
// fvMeshFunctionObject::updateMesh(mpm);
if (ensMesh_.valid())
{
ensMesh_().expire();
}
}
void Foam::functionObjects::ensightWrite::movePoints(const polyMesh& mpm)
{
// fvMeshFunctionObject::updateMesh(mpm);
if (ensMesh_.valid())
{
ensMesh_().expire();
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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::functionObjects::ensightWrite
Group
grpUtilitiesFunctionObjects
Description
Writes fields in ensight format.
Example of function object specification:
\verbatim
ensight
{
type ensightWrite;
libs ("libutilityFunctionObjects.so");
writeControl writeTime;
writeInterval 1;
format binary;
overwrite true;
width 12;
directory "EnSight";
fields
(
U
p
);
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | Type name: ensightWrite | yes |
fields | Fields to output | yes |
writeControl | Output control | recommended | timeStep
directory | The output directory name | no | "ensightWrite"
overwrite | Remove existing directory | no | false
format | ASCII or binary format | no | same as simulation
width | Mask width for \c data/XXXX | no | 8
noPatches | Suppress writing patches | no | false
patches | Select patches to write | no |
faceZones | Select faceZones to write | no |
deprecatedOrder | Old ordering of volume cells | no | false
consecutive | Consecutive output numbering | no | false
\endtable
Note that if the \c patches entry is an empty list, this will select all
patches and suppress writing the internalMesh.
Consecutive output numbering can be used in conjunction with \c overwrite.
SourceFiles
ensightWrite.C
ensightWriteTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_ensightWrite_H
#define functionObjects_ensightWrite_H
#include "fvMeshFunctionObject.H"
#include "ensightCase.H"
#include "ensightMesh.H"
#include "wordReList.H"
#include "interpolation.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class dictionary;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class ensightWrite Declaration
\*---------------------------------------------------------------------------*/
class ensightWrite
:
public fvMeshFunctionObject
{
// Private data
//- Writer options
ensightMesh::options writeOpts_;
ensightCase::options caseOpts_;
//- Name of fields to process
wordReList selectFields_;
//- Output directory name
fileName dirName_;
//- Consecutive output numbering
bool consecutive_;
//- Ensight case handler
autoPtr<ensightCase> ensCase_;
//- Ensight mesh handler
autoPtr<ensightMesh> ensMesh_;
// Private Member Functions
//- Eliminate duplicate 'word' entries
static void uniqWords(wordReList&);
//- Ensight case handler
ensightCase& ensCase()
{
return ensCase_();
}
//- Ensight mesh handler
ensightMesh& ensMesh()
{
return ensMesh_();
}
//- Apply for the volume field type
template<class Type>
int writeVolField(const word& inputName, int& state);
//- Process by trying to apply for various volume field types.
int process(const word& inputName);
//- Disallow default bitwise copy construct
ensightWrite(const ensightWrite&) = delete;
//- Disallow default bitwise assignment
void operator=(const ensightWrite&) = delete;
public:
//- Runtime type information
TypeName("ensightWrite");
// Constructors
//- Construct from runTime and dictionary.
ensightWrite
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~ensightWrite();
// Member Functions
//- Read the ensightWrite specification
virtual bool read(const dictionary&);
//- Do nothing
virtual bool execute();
//- Write fields
virtual bool write();
//- Execute at the final time-loop, flush case file
virtual bool end();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&);
//- Update for mesh point-motion
virtual void movePoints(const polyMesh&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "ensightWriteTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 "Time.H"
#include "ensightOutput.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
int Foam::functionObjects::ensightWrite::writeVolField
(
const word& inputName,