Commit c972a375 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Updates to set and surface writers

- New boundaryData surface writer
- Moved templated code into separate files
- Output filenames written to functionObjectState dictionary
- Ensight surface writer now supports a 'collate times' option [mattijs]
- Nastran surface writer updated based on user feedback
parent 636673b7
......@@ -50,6 +50,7 @@ $(surfWriters)/proxy/proxySurfaceWriter.C
$(surfWriters)/raw/rawSurfaceWriter.C
$(surfWriters)/starcd/starcdSurfaceWriter.C
$(surfWriters)/vtk/vtkSurfaceWriter.C
$(surfWriters)/boundaryData/boundaryDataSurfaceWriter.C
graphField/writePatchGraph.C
graphField/writeCellGraph.C
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -136,8 +136,8 @@ Foam::sampledSets::sampledSets
const bool loadFromFiles
)
:
functionObjectState(obr, name),
PtrList<sampledSet>(),
name_(name),
mesh_(refCast<const fvMesh>(obr)),
loadFromFiles_(loadFromFiles),
outputPath_(fileName::null),
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -36,6 +36,7 @@ SourceFiles
#ifndef sampledSets_H
#define sampledSets_H
#include "functionObjectState.H"
#include "sampledSet.H"
#include "volFieldsFwd.H"
#include "meshSearch.H"
......@@ -59,6 +60,7 @@ class fvMesh;
class sampledSets
:
public functionObjectState,
public PtrList<sampledSet>
{
// Private classes
......@@ -153,10 +155,6 @@ class sampledSets
// Private data
//- Name of this set of sets,
// Also used as the name of the sampledSets directory.
word name_;
//- Const reference to fvMesh
const fvMesh& mesh_;
......@@ -273,12 +271,6 @@ public:
// Member Functions
//- Return name of the set of probes
virtual const word& name() const
{
return name_;
}
//- Set verbosity level
void verbose(const bool verbosity = true);
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -155,6 +155,14 @@ void Foam::sampledSets::writeSampleFile
valueSets,
ofs
);
forAll(masterFields, fieldi)
{
dictionary propsDict;
propsDict.add("file", fName);
const word& fieldName = masterFields[fieldi].name();
setProperty(fieldName, propsDict);
}
}
else
{
......@@ -226,10 +234,7 @@ void Foam::sampledSets::combineSampledValues
template<class Type>
void Foam::sampledSets::sampleAndWrite
(
fieldGroup<Type>& fields
)
void Foam::sampledSets::sampleAndWrite(fieldGroup<Type>& fields)
{
if (fields.size())
{
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -49,7 +49,7 @@ void Foam::sampledSurfaces::writeGeometry() const
// Write to time directory under outputPath_
// Skip surface without faces (eg, a failed cut-plane)
const fileName outputDir = outputPath_/mesh_.time().timeName();
const fileName outputDir = outputPath_/obr_.time().timeName();
forAll(*this, surfI)
{
......@@ -92,9 +92,9 @@ Foam::sampledSurfaces::sampledSurfaces
const bool loadFromFiles
)
:
functionObjectState(obr, name),
PtrList<sampledSurface>(),
name_(name),
mesh_(refCast<const fvMesh>(obr)),
obr_(obr),
loadFromFiles_(loadFromFiles),
outputPath_(fileName::null),
fieldSelection_(),
......@@ -102,13 +102,19 @@ Foam::sampledSurfaces::sampledSurfaces
mergeList_(),
formatter_(NULL)
{
// Only active if a fvMesh is available
if (setActive<fvMesh>())
{
read(dict);
}
if (Pstream::parRun())
{
outputPath_ = mesh_.time().path()/".."/"postProcessing"/name_;
outputPath_ = obr_.time().path()/".."/"postProcessing"/name_;
}
else
{
outputPath_ = mesh_.time().path()/"postProcessing"/name_;
outputPath_ = obr_.time().path()/"postProcessing"/name_;
}
read(dict);
......@@ -161,11 +167,11 @@ void Foam::sampledSurfaces::write()
if (debug)
{
Pout<< "Creating directory "
<< outputPath_/mesh_.time().timeName() << nl << endl;
<< outputPath_/obr_.time().timeName() << nl << endl;
}
mkDir(outputPath_/mesh_.time().timeName());
mkDir(outputPath_/obr_.time().timeName());
}
// Write geometry first if required,
......@@ -175,7 +181,7 @@ void Foam::sampledSurfaces::write()
writeGeometry();
}
const IOobjectList objects(mesh_, mesh_.time().timeName());
const IOobjectList objects(obr_, obr_.time().timeName());
sampleAndWrite<volScalarField>(objects);
sampleAndWrite<volVectorField>(objects);
......@@ -211,10 +217,12 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
dict.subOrEmptyDict("formatOptions").subOrEmptyDict(writeType)
);
const fvMesh& mesh = refCast<const fvMesh>(obr_);
PtrList<sampledSurface> newList
(
dict.lookup("surfaces"),
sampledSurface::iNew(mesh_)
sampledSurface::iNew(mesh)
);
transfer(newList);
......@@ -334,8 +342,10 @@ bool Foam::sampledSurfaces::update()
return updated;
}
const fvMesh& mesh = refCast<const fvMesh>(obr_);
// Dimension as fraction of mesh bounding box
scalar mergeDim = mergeTol_ * mesh_.bounds().mag();
scalar mergeDim = mergeTol_*mesh.bounds().mag();
if (Pstream::master() && debug)
{
......@@ -374,4 +384,18 @@ bool Foam::sampledSurfaces::update()
}
Foam::scalar Foam::sampledSurfaces::mergeTol()
{
return mergeTol_;
}
Foam::scalar Foam::sampledSurfaces::mergeTol(const scalar tol)
{
scalar oldTol = mergeTol_;
mergeTol_ = tol;
return oldTol;
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -37,6 +37,7 @@ SourceFiles
#ifndef sampledSurfaces_H
#define sampledSurfaces_H
#include "functionObjectState.H"
#include "sampledSurface.H"
#include "surfaceWriter.H"
#include "volFieldsFwd.H"
......@@ -58,6 +59,7 @@ class dictionary;
class sampledSurfaces
:
public functionObjectState,
public PtrList<sampledSurface>
{
// Private classes
......@@ -92,12 +94,8 @@ class sampledSurfaces
// Private data
//- Name of this set of surfaces,
// Also used as the name of the sampledSurfaces directory.
const word name_;
//- Const reference to fvMesh
const fvMesh& mesh_;
//- Const reference to database
const objectRegistry& obr_;
//- Load fields from files (not from objectRegistry)
const bool loadFromFiles_;
......@@ -238,6 +236,12 @@ public:
//- Update for changes of mesh due to readUpdate - expires the surfaces
virtual void readUpdate(const polyMesh::readUpdateState state);
//- Get merge tolerance
static scalar mergeTol();
//- Set tolerance (and return old tolerance)
static scalar mergeTol(const scalar);
};
......
......@@ -37,7 +37,7 @@ Foam::label Foam::sampledSurfaces::classifyFields()
if (loadFromFiles_)
{
// Check files for a particular time
IOobjectList objects(mesh_, mesh_.time().timeName());
IOobjectList objects(obr_, obr_.time().timeName());
wordList allFields = objects.sortedNames();
forAll(fieldSelection_, i)
......@@ -59,7 +59,7 @@ Foam::label Foam::sampledSurfaces::classifyFields()
else
{
// Check currently available fields
wordList allFields = mesh_.sortedNames();
wordList allFields = obr_.sortedNames();
labelList indices = findStrings(fieldSelection_, allFields);
forAll(fieldSelection_, i)
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -72,7 +72,7 @@ void Foam::sampledSurfaces::writeSurface
// skip surface without faces (eg, a failed cut-plane)
if (mergeList_[surfI].faces.size())
{
formatter_->write
fileName fName = formatter_->write
(
outputDir,
s.name(),
......@@ -82,6 +82,10 @@ void Foam::sampledSurfaces::writeSurface
allValues,
s.interpolate()
);
dictionary propsDict;
propsDict.add("file", fName);
setProperty(fieldName, propsDict);
}
}
}
......@@ -91,7 +95,7 @@ void Foam::sampledSurfaces::writeSurface
// skip surface without faces (eg, a failed cut-plane)
if (s.faces().size())
{
formatter_->write
fileName fName = formatter_->write
(
outputDir,
s.name(),
......@@ -101,6 +105,10 @@ void Foam::sampledSurfaces::writeSurface
values,
s.interpolate()
);
dictionary propsDict;
propsDict.add("file", fName);
setProperty(fieldName, propsDict);
}
}
}
......@@ -153,7 +161,7 @@ void Foam::sampledSurfaces::sampleAndWrite
const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
)
{
const word& fieldName = sField.name();
const word& fieldName = sField.name();
const fileName outputDir = outputPath_/sField.time().timeName();
forAll(*this, surfI)
......@@ -169,6 +177,8 @@ template<class GeoField>
void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects)
{
wordList names;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
if (loadFromFiles_)
{
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
......@@ -176,7 +186,7 @@ void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects)
}
else
{
names = mesh_.thisDb().names<GeoField>();
names = mesh.thisDb().names<GeoField>();
}
labelList nameIDs(findStrings(fieldSelection_, names));
......@@ -199,11 +209,11 @@ void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects)
IOobject
(
fieldName,
mesh_.time().timeName(),
mesh_,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ
),
mesh_
mesh
);
sampleAndWrite(fld);
......@@ -212,7 +222,7 @@ void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects)
{
sampleAndWrite
(
mesh_.thisDb().lookupObject<GeoField>(fieldName)
mesh.thisDb().lookupObject<GeoField>(fieldName)
);
}
}
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ 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 "boundaryDataSurfaceWriter.H"
#include "makeSurfaceWriterMethods.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeSurfaceWriterType(boundaryDataSurfaceWriter);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundaryDataSurfaceWriter::boundaryDataSurfaceWriter()
:
surfaceWriter()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::boundaryDataSurfaceWriter::~boundaryDataSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fileName Foam::boundaryDataSurfaceWriter::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose
) const
{
const fileName baseDir(outputDir.path()/surfaceName);
const fileName timeName(outputDir.name());
// Construct dummy time to use as an objectRegistry
const fileName caseDir(getEnv("FOAM_CASE"));
Time dummyTime
(
caseDir.path(), //rootPath,
caseDir.name(), //caseName,
"system", //systemName,
"constant", //constantName,
false //enableFunctionObjects
);
// Write points
if (verbose)
{
Info<< "Writing points to " << baseDir/"points" << endl;
}
pointIOField pts
(
IOobject
(
baseDir/"points",
dummyTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
points
);
{
// Do like regIOobject::writeObject but don't do instance() adaptation
// since this would write to e.g. 0/ instead of postProcessing/
// Try opening an OFstream for object
mkDir(pts.path());
OFstream os(pts.objectPath());
pts.writeHeader(os);
pts.writeData(os);
pts.writeEndDivider(os);
}
return baseDir;
}
// create write methods
defineSurfaceWriterWriteFields(Foam::boundaryDataSurfaceWriter);
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ 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::boundaryDataSurfaceWriter
Description
A surfaceWriter for outputting to a form useable for the
timeVaryingMapped boundary condition. This reads the data from
constant/boundaryData/<patch>
Typical way of working:
- use a sampledSurface of type 'patch' (to sample a patch):
surfaces
{
type surfaces;
surfaceFormat boundaryData;
fields ( p );
surfaces
(
outlet
{
type patch;
patches (outlet);
interpolate false;
}
);
- write using this writer.
- move postProcessing/surfaces/outlet to constant/boundaryData/outlet
in your destination case.
- use a timeVaryingMappedFixedValue bc to read&interpolate
the profile:
type timeVaryingMappedFixedValue;
setAverage false; // do not use read average
offset 0; // do not apply offset to values
Note:
- with 'interpolate false' the data is on the face centres of the
patch. Take care that a 2D geometry will only have a single row
of face centres so might not provide a valid triangulation
(this is what timeVaryingMappedFixedValue uses to do interpolation)
(Alternatively use timeVaryingMappedFixedValue with mapMethod 'nearest')
SourceFiles
boundaryDataSurfaceWriter.C
\*---------------------------------------------------------------------------*/
#ifndef boundaryDataSurfaceWriter_H
#define boundaryDataSurfaceWriter_H
#include "surfaceWriter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class boundaryDataSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/
class boundaryDataSurfaceWriter
:
public surfaceWriter