ENH: -exclude-fields, -no-fields options for foamToEnsight, foamToVTK

- additional verbosity option for conversions

- ignore old `-finite-area` option and always convert available
  finiteArea mesh/fields unless `-no-finite-area` is specified (#2374)

ENH: simplify point offset handling for ensight output

- extend writing to include compact face/cell lists
This commit is contained in:
Mark Olesen
2022-03-07 15:15:21 +01:00
parent 730ce92b68
commit c4d4becbac
28 changed files with 642 additions and 240 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -26,27 +26,37 @@ forAll(meshes, regioni)
{
const auto& mesh = meshes[regioni];
IOobjectList objects(mesh, timeDirs.last().name());
IOobjectList objects(0);
if (!fieldPatterns.empty())
if (doConvertFields)
{
objects.filterObjects(fieldPatterns);
}
objects = IOobjectList(mesh, timeDirs.last().name());
// Remove "*_0" restart fields
objects.prune_0();
if (fieldSelector && !fieldSelector().empty())
{
objects.filterObjects(fieldSelector());
}
if (!doPointValues)
{
// Prune point fields if disabled
objects.filterClasses
(
[](const word& clsName)
{
return fieldTypes::point.found(clsName);
},
true // prune
);
if (fieldSelector && !fieldSelector().empty())
{
objects.filterObjects(fieldSelector());
}
// Remove "*_0" restart fields
objects.prune_0();
if (!doPointValues)
{
// Prune point fields if disabled
objects.filterClasses
(
[](const word& clsName)
{
return fieldTypes::point.found(clsName);
},
true // prune
);
}
}
wordList objectNames(objects.sortedNames());

View File

@ -55,6 +55,7 @@ PtrList<ensightFaMesh> ensightMeshesFa(regionNames.size());
regioni,
new ensightMesh(mesh, writeOpts)
);
ensightMeshes[regioni].verbose(optVerbose);
// New ensight case file, initialize header etc.
ensightCases.set
@ -87,6 +88,7 @@ PtrList<ensightFaMesh> ensightMeshesFa(regionNames.size());
regioni,
new ensightFaMesh(meshesFa[regioni])
);
ensightMeshesFa[regioni].verbose(optVerbose);
}
}
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -108,11 +108,11 @@ Usage
-patches '( front \".*back\" )'
\endverbatim
- \par -excludePatches NAME | LIST
- \par -exclude-patches NAME | LIST
Exclude single or multiple patches (name or regex) from writing.
For example,
\verbatim
-excludePatches '( inlet_1 inlet_2 "proc.*" )'
-exclude-patches '( inlet_1 inlet_2 "proc.*" )'
\endverbatim
\*---------------------------------------------------------------------------*/
@ -170,6 +170,8 @@ int main(int argc, char *argv[])
argList::setAdvanced("decomposeParDict");
argList::setAdvanced("noFunctionObjects");
argList::addVerboseOption("Additional verbosity");
#include "addAllRegionOptions.H"
argList::addBoolOption
@ -259,10 +261,15 @@ int main(int argc, char *argv[])
// );
argList::addBoolOption
(
"finite-area",
"Write finite area fields",
"no-finite-area",
"Suppress output of finite-area mesh/fields",
true // mark as an advanced option
);
argList::ignoreOptionCompat
(
{"finite-area", 2112}, // use -no-finite-area to disable
false // bool option, no argument
);
argList::addOption
(
@ -273,12 +280,14 @@ int main(int argc, char *argv[])
);
argList::addOption
(
"excludePatches",
"exclude-patches",
"wordRes",
"Exclude single or multiple patches from writing\n"
"Eg, 'outlet' or '( inlet \".*Wall\" )'"
, true // mark as an advanced option
);
argList::addOptionCompat("exclude-patches", {"excludePatches", 2112});
argList::addOption
(
"faceZones",
@ -293,6 +302,19 @@ int main(int argc, char *argv[])
"Specify single or multiple fields to write (all by default)\n"
"Eg, 'T' or '( \"U.*\" )'"
);
argList::addOption
(
"exclude-fields",
"wordRes",
"Exclude single or multiple fields",
true // mark as an advanced option
);
argList::addBoolOption
(
"no-fields",
"Suppress conversion of fields"
);
argList::addOption
(
"cellZones",
@ -315,11 +337,12 @@ int main(int argc, char *argv[])
: IOstreamOption::BINARY
);
const int optVerbose = args.verbose();
const bool doBoundary = !args.found("no-boundary");
const bool doInternal = !args.found("no-internal");
const bool doCellZones = !args.found("no-cellZones");
const bool doLagrangian = !args.found("no-lagrangian");
const bool doFiniteArea = args.found("finite-area");
const bool doFiniteArea = !args.found("no-finite-area");
const bool doPointValues = !args.found("no-point-data");
const bool nearCellValue = args.found("nearCellValue") && doBoundary;
@ -360,13 +383,14 @@ int main(int argc, char *argv[])
writeOpts.useInternalMesh(doInternal);
writeOpts.useCellZones(doCellZones);
// Patch selection/deselection
if (args.found("patches"))
{
writeOpts.patchSelection(args.getList<wordRe>("patches"));
}
if (args.found("excludePatches"))
if (args.found("exclude-patches"))
{
writeOpts.patchExclude(args.getList<wordRe>("excludePatches"));
writeOpts.patchExclude(args.getList<wordRe>("exclude-patches"));
}
if (args.found("faceZones"))
@ -381,8 +405,35 @@ int main(int argc, char *argv[])
// Report the setup
writeOpts.print(Info);
wordRes fieldPatterns;
args.readListIfPresent<wordRe>("fields", fieldPatterns);
// Field selection/deselection
wordRes includedFields, excludedFields;
autoPtr<wordRes::filter> fieldSelector(nullptr);
const bool doConvertFields = !args.found("no-fields");
if (doConvertFields)
{
bool resetFilter = false;
if (args.readListIfPresent<wordRe>("fields", includedFields))
{
resetFilter = true;
Info<< "Including fields "
<< flatOutput(includedFields) << nl << endl;
}
if (args.readListIfPresent<wordRe>("exclude-fields", excludedFields))
{
resetFilter = true;
Info<< "Excluding fields "
<< flatOutput(excludedFields) << nl << endl;
}
if (resetFilter)
{
fieldSelector =
autoPtr<wordRes::filter>::New(includedFields, excludedFields);
}
}
else if (doConvertFields)
{
Info<< "Field conversion disabled with the '-no-fields' option" << nl;
}
// ------------------------------------------------------------------------
@ -525,7 +576,6 @@ int main(int argc, char *argv[])
// Objects at this time
IOobjectList objects(mesh, runTime.timeName());
// Restrict to objects that are available for all times
objects.filterObjects
(
availableRegionObjectNames[regioni]

View File

@ -81,20 +81,16 @@ tmp<GeoField> getField
//- Convert an internal field to zero-gradient volume field
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
makeZeroGradientField
tmp<VolumeField<Type>> makeZeroGradientField
(
const tmp
<
typename GeometricField<Type, fvPatchField, volMesh>::Internal
>& tdf
const tmp<VolumeInternalField<Type>>& tdf
)
{
if (tdf)
{
auto& df = tdf.ref();
auto tfield = GeometricField<Type, fvPatchField, volMesh>::New
auto tfield = VolumeField<Type>::New
(
df.name(),
df.mesh(),
@ -119,17 +115,16 @@ makeZeroGradientField
//- Convert a volume field to zero-gradient volume field
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
makeZeroGradientField
tmp<VolumeField<Type>> makeZeroGradientField
(
const tmp<GeometricField<Type, fvPatchField, volMesh>>& tdf
const tmp<VolumeField<Type>>& tdf
)
{
if (tdf)
{
auto& df = tdf.ref();
auto tfield = GeometricField<Type, fvPatchField, volMesh>::New
auto tfield = VolumeField<Type>::New
(
df.name(),
df.mesh(),

View File

@ -34,7 +34,7 @@ bool writeAreaField
(
ensightCase& ensCase,
const ensightFaMesh& ensMesh,
const tmp<GeometricField<Type, faPatchField, areaMesh>>& tfield
const tmp<AreaField<Type>>& tfield
)
{
if (!tfield)
@ -66,13 +66,13 @@ label writeAreaFields
const IOobjectList& objects
)
{
typedef GeometricField<Type, faPatchField, areaMesh> GeoField;
typedef AreaField<Type> FieldType;
const faMesh& mesh = ensMesh.mesh();
label count = 0;
for (const word& fieldName : objects.sortedNames<GeoField>())
for (const word& fieldName : objects.sortedNames<FieldType>())
{
if
(
@ -80,7 +80,7 @@ label writeAreaFields
(
ensCase,
ensMesh,
getField<GeoField>(objects.findObject(fieldName), mesh)
getField<FieldType>(objects.findObject(fieldName), mesh)
)
)
{

View File

@ -33,7 +33,7 @@ bool writeDimField
(
ensightCase& ensCase,
const ensightMesh& ensMesh,
const tmp<DimensionedField<Type, volMesh>>& tdf
const tmp<VolumeInternalField<Type>>& tdf
)
{
if (!tdf)
@ -63,17 +63,13 @@ label writeDimFields
const IOobjectList& objects
)
{
typedef typename
GeometricField
<
Type, fvPatchField, volMesh
>::Internal DimField;
typedef VolumeInternalField<Type> FieldType;
const fvMesh& mesh = dynamicCast<const fvMesh>(ensMesh.mesh());
label count = 0;
for (const word& fieldName : objects.sortedNames<DimField>())
for (const word& fieldName : objects.sortedNames<FieldType>())
{
if
(
@ -81,7 +77,7 @@ label writeDimFields
(
ensCase,
ensMesh,
getField<DimField>(objects.findObject(fieldName), mesh)
getField<FieldType>(objects.findObject(fieldName), mesh)
)
)
{

View File

@ -35,7 +35,7 @@ bool writePointField
(
ensightCase& ensCase,
const ensightMesh& ensMesh,
const tmp<GeometricField<Type, pointPatchField, pointMesh>>& tfield
const tmp<PointField<Type>>& tfield
)
{
if (!tfield)
@ -68,13 +68,13 @@ label writePointFields
const IOobjectList& objects
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> GeoField;
typedef PointField<Type> FieldType;
const pointMesh& ptMesh = pointMesh::New(ensMesh.mesh());
label count = 0;
for (const word& fieldName : objects.sortedNames<GeoField>())
for (const word& fieldName : objects.sortedNames<FieldType>())
{
if
(
@ -82,7 +82,7 @@ label writePointFields
(
ensCase,
ensMesh,
getField<GeoField>(ptMesh, objects, fieldName)
getField<FieldType>(ptMesh, objects, fieldName)
)
)
{

View File

@ -34,7 +34,7 @@ bool writeVolField
(
ensightCase& ensCase,
const ensightMesh& ensMesh,
const tmp<GeometricField<Type, fvPatchField, volMesh>>& tfield,
const tmp<VolumeField<Type>>& tfield,
const bool nearCellValue = false
)
{
@ -86,13 +86,13 @@ label writeVolFields
const bool nearCellValue = false
)
{
typedef GeometricField<Type, fvPatchField, volMesh> GeoField;
typedef VolumeField<Type> FieldType;
const fvMesh& mesh = dynamicCast<const fvMesh>(ensMesh.mesh());
label count = 0;
for (const word& fieldName : objects.sortedNames<GeoField>())
for (const word& fieldName : objects.sortedNames<FieldType>())
{
if
(
@ -100,7 +100,7 @@ label writeVolFields
(
ensCase,
ensMesh,
getField<GeoField>(objects.findObject(fieldName), mesh),
getField<FieldType>(objects.findObject(fieldName), mesh),
nearCellValue
)
)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,7 +52,6 @@ if (doLagrangian)
// Consistent order
Foam::sort(cloudNames);
for (const word& cloudName : cloudNames)
{
IOobjectList cloudObjs(mesh, runTime.timeName(), cloudPrefix/cloudName);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -43,12 +43,7 @@ Description
{
if (nSurfaceScalarField == -1)
{
sScalars = readFields<surfaceScalarField>
(
meshProxy,
objects,
selectedFields
);
sScalars = readFields<surfaceScalarField>(meshProxy, objects);
reportFields::print(" surfScalar :", Info, sScalars);
nSurfaceScalarField = sScalars.size();
@ -60,12 +55,7 @@ Description
if (nSurfaceVectorField == -1)
{
sVectors = readFields<surfaceVectorField>
(
meshProxy,
objects,
selectedFields
);
sVectors = readFields<surfaceVectorField>(meshProxy, objects);
reportFields::print(" surfVector :", Info, sVectors);
nSurfaceVectorField = sVectors.size();
@ -155,12 +145,7 @@ Description
{
if (nSurfaceScalarField == -1)
{
sScalars = readFields<surfaceScalarField>
(
meshProxy,
objects,
selectedFields
);
sScalars = readFields<surfaceScalarField>(meshProxy, objects);
nSurfaceScalarField = sScalars.size();
reportFields::print(" surfScalar :", Info, sScalars);
@ -172,12 +157,7 @@ Description
if (nSurfaceVectorField == -1)
{
sVectors = readFields<surfaceVectorField>
(
meshProxy,
objects,
selectedFields
);
sVectors = readFields<surfaceVectorField>(meshProxy, objects);
nSurfaceVectorField = sVectors.size();
reportFields::print(" surfVector :", Info, sVectors);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -48,7 +48,7 @@ Description
: 0
);
const label nPointFields =
label nPointFields =
(
doPointValues
? objects.count(stringListOps::foundOp<word>(fieldTypes::point))
@ -82,11 +82,6 @@ Description
if (doInternal)
{
if (doPointValues)
{
pInterp.reset(new volPointInterpolation(mesh));
}
if (vtuMeshCells.empty())
{
// Use the appropriate mesh (baseMesh or subMesh)
@ -119,6 +114,11 @@ Description
internalWriter->writeTimeValue(mesh.time().value());
internalWriter->writeGeometry();
if (doPointValues)
{
pInterp.reset(new volPointInterpolation(mesh));
}
}
@ -132,7 +132,7 @@ Description
labelList patchIds;
if (doBoundary)
{
patchIds = getSelectedPatches(patches, includePatches, excludePatches);
patchIds = getSelectedPatches(patches, patchSelector);
}
if (oneBoundary && patchIds.size())

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -112,11 +112,11 @@ Usage
-patches '( front \".*back\" )'
\endverbatim
- \par -excludePatches NAME | LIST
- \par -exclude-patches NAME | LIST
Exclude single or multiple patches (name or regex) from writing.
For example,
\verbatim
-excludePatches '( inlet_1 inlet_2 "proc.*")'
-exclude-patches '( inlet_1 inlet_2 "proc.*")'
\endverbatim
Note
@ -169,22 +169,28 @@ Note
labelList getSelectedPatches
(
const polyBoundaryMesh& patches,
const wordRes& allow,
const wordRes& deny
const autoPtr<wordRes::filter>& patchSelector
)
{
// Name-based selection
labelList indices
(
stringListOps::findMatching
(
patches,
allow,
deny,
nameOp<polyPatch>()
)
);
labelList indices;
if (patchSelector && !patchSelector().empty())
{
// Name-based selection
indices =
(
stringListOps::findMatching
(
patches,
patchSelector(),
nameOp<polyPatch>()
)
);
}
else
{
indices = identity(patches.size());
}
// Remove undesirable patches
@ -264,6 +270,8 @@ int main(int argc, char *argv[])
argList::setAdvanced("decomposeParDict");
argList::setAdvanced("noFunctionObjects");
argList::addVerboseOption("Additional verbosity");
argList::addBoolOption
(
"ascii",
@ -328,7 +336,6 @@ int main(int argc, char *argv[])
"Eg, 'cells' or '( slice \"mfp-.*\" )'.",
true // mark as an advanced option
);
argList::addOption
(
"fields",
@ -336,6 +343,18 @@ int main(int argc, char *argv[])
"Specify single or multiple fields to write (all by default)\n"
"Eg, 'T' or '(p T U \"alpha.*\")'"
);
argList::addOption
(
"exclude-fields",
"wordRes",
"Exclude single or multiple fields",
true // mark as an advanced option
);
argList::addBoolOption
(
"no-fields",
"Suppress conversion of fields"
);
argList::addBoolOption
(
@ -351,11 +370,21 @@ int main(int argc, char *argv[])
);
argList::addBoolOption
(
"finite-area",
"Write finite area fields",
"no-finite-area",
"Suppress output of finite-area mesh/fields",
true // mark as an advanced option
);
argList::addOptionCompat("finite-area", {"finiteAreaFields", 2012});
argList::ignoreOptionCompat
(
{"finite-area", 2112}, // use -no-finite-area to disable
false // bool option, no argument
);
argList::ignoreOptionCompat
(
{"finiteAreaFields", 2012}, // use -no-finite-area to disable
false // bool option, no argument
);
argList::addBoolOption
(
"nearCellValue",
@ -418,12 +447,14 @@ int main(int argc, char *argv[])
);
argList::addOption
(
"excludePatches",
"exclude-patches",
"wordRes",
"Exclude single or multiple patches from writing\n"
"Eg, 'outlet' or '( inlet \".*Wall\" )'",
true // mark as an advanced option
);
argList::addOptionCompat("exclude-patches", {"excludePatches", 2112});
argList::ignoreOptionCompat
(
{"noFaceZones", 1806}, // faceZones are only enabled on demand
@ -453,13 +484,13 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
/// const int optVerbose = args.verbose();
const bool decomposePoly = args.found("poly-decomp");
const bool doBoundary = !args.found("no-boundary");
const bool doInternal = !args.found("no-internal");
const bool doLagrangian = !args.found("no-lagrangian");
const bool doFiniteArea = args.found("finite-area");
const bool doFiniteArea = !args.found("no-finite-area");
const bool doSurfaceFields = args.found("surfaceFields");
const bool oneBoundary = args.found("one-boundary") && doBoundary;
const bool nearCellValue = args.found("nearCellValue") && doBoundary;
@ -494,7 +525,7 @@ int main(int argc, char *argv[])
<< nl << endl;
}
const bool doPointValues = !args.found("no-point-data");
bool doPointValues = !args.found("no-point-data");
if (!doPointValues)
{
Info<< "Point fields and interpolated point data"
@ -521,25 +552,74 @@ int main(int argc, char *argv[])
Info<< "Writing mesh ids (cell, patch, proc) requested" << nl;
}
wordRes includePatches, excludePatches;
// Patch selection/deselection
wordRes includedPatches, excludedPatches;
autoPtr<wordRes::filter> patchSelector(nullptr);
if (doBoundary)
{
if (args.readListIfPresent<wordRe>("patches", includePatches))
bool resetFilter = false;
if (args.readListIfPresent<wordRe>("patches", includedPatches))
{
Info<< "Including patches " << flatOutput(includePatches)
<< nl << endl;
resetFilter = true;
Info<< "Including patches "
<< flatOutput(includedPatches) << nl << endl;
}
if (args.readListIfPresent<wordRe>("excludePatches", excludePatches))
if (args.readListIfPresent<wordRe>("exclude-patches", excludedPatches))
{
Info<< "Excluding patches " << flatOutput(excludePatches)
<< nl << endl;
resetFilter = true;
Info<< "Excluding patches "
<< flatOutput(excludedPatches) << nl << endl;
}
if (resetFilter)
{
patchSelector =
autoPtr<wordRes::filter>::New(includedPatches, excludedPatches);
}
}
// Can be specified as empty (ie, no fields)
wordRes selectedFields;
const bool useFieldFilter =
args.readListIfPresent<wordRe>("fields", selectedFields);
// Field selection/deselection
wordRes includedFields, excludedFields;
autoPtr<wordRes::filter> fieldSelector(nullptr);
bool doConvertFields = !args.found("no-fields");
if (doConvertFields)
{
bool resetFilter = false;
if (args.readListIfPresent<wordRe>("fields", includedFields))
{
Info<< "Including fields "
<< flatOutput(includedFields) << nl << endl;
resetFilter = !includedFields.empty();
if (includedFields.empty())
{
// Compat: Can be specified as empty (ie, no fields)
// Same as "block everything"
doConvertFields = false;
Info<< "Field conversion disabled by '-fields ()' option" << nl
<< "Should use -no-fields instead" << endl;
}
}
if (args.readListIfPresent<wordRe>("exclude-fields", excludedFields))
{
resetFilter = true;
Info<< "Excluding fields "
<< flatOutput(excludedFields) << nl << endl;
}
if (resetFilter && doConvertFields)
{
fieldSelector =
autoPtr<wordRes::filter>::New(includedFields, excludedFields);
}
}
else if (doConvertFields)
{
Info<< "Field conversion disabled with the '-no-fields' option" << nl;
}
// Non-mandatory
const wordRes selectedFaceZones(args.getList<wordRe>("faceZones", false));
@ -709,28 +789,34 @@ int main(int argc, char *argv[])
}
}
// Search for list of objects for this time
IOobjectList objects(meshProxy.baseMesh(), runTime.timeName());
IOobjectList objects(0);
if (useFieldFilter)
if (doConvertFields)
{
objects.filterObjects(selectedFields);
}
// List of objects for this time
objects =
IOobjectList(meshProxy.baseMesh(), runTime.timeName());
// Prune restart fields
objects.prune_0();
if (fieldSelector && !fieldSelector().empty())
{
objects.filterObjects(fieldSelector());
}
if (!doPointValues)
{
// Prune point fields if disabled
objects.filterClasses
(
[](const word& clsName)
{
return fieldTypes::point.found(clsName);
},
true // prune
);
// Remove "*_0" restart fields
objects.prune_0();
if (!doPointValues)
{
// Prune point fields if disabled
objects.filterClasses
(
[](const word& clsName)
{
return fieldTypes::point.found(clsName);
},
true // prune
);
}
}
if (processorFieldsOnly)

View File

@ -94,19 +94,13 @@ template<class GeoField>
Foam::PtrList<const GeoField> Foam::readFields
(
const typename GeoField::Mesh& mesh,
const IOobjectList& objects,
const wordRes& selection
const IOobjectList& objects
)
{
const bool syncPar = true;
// Available fields of type GeoField, sorted order
const wordList fieldNames =
(
selection.empty()
? objects.sortedNames<GeoField>()
: objects.sortedNames<GeoField>(selection)
);
const wordList fieldNames(objects.sortedNames<GeoField>());
// Construct the fields
PtrList<const GeoField> fields(fieldNames.size());
@ -133,19 +127,13 @@ template<class GeoField>
Foam::PtrList<const GeoField> Foam::readFields
(
const fvMeshSubsetProxy& proxy,
const IOobjectList& objects,
const wordRes& selection
const IOobjectList& objects
)
{
const bool syncPar = true;
// Available fields of type GeoField, sorted order
const wordList fieldNames =
(
selection.empty()
? objects.sortedNames<GeoField>()
: objects.sortedNames<GeoField>(selection)
);
const wordList fieldNames(objects.sortedNames<GeoField>());
// Construct the fields
PtrList<const GeoField> fields(fieldNames.size());

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef readFields_H
#define readFields_H
#ifndef Foam_readFields_H
#define Foam_readFields_H
#include "fvMeshSubsetProxy.H"
#include "IOobjectList.H"
@ -94,8 +94,7 @@ template<class GeoField>
PtrList<const GeoField> readFields
(
const typename GeoField::Mesh& mesh,
const IOobjectList& objects,
const wordRes& selection
const IOobjectList& objects
);
@ -104,8 +103,7 @@ template<class GeoField>
PtrList<const GeoField> readFields
(
const fvMeshSubsetProxy& proxy,
const IOobjectList& objects,
const wordRes& selection
const IOobjectList& objects
);

View File

@ -110,7 +110,8 @@ Foam::ensightMesh::ensightMesh
:
options_(new options(opts)),
mesh_(mesh),
needsUpdate_(true)
needsUpdate_(true),
verbose_(0)
{
if (!option().lazy())
{
@ -121,6 +122,20 @@ Foam::ensightMesh::ensightMesh
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int Foam::ensightMesh::verbose() const noexcept
{
return verbose_;
}
int Foam::ensightMesh::verbose(const int level) noexcept
{
int old(verbose_);
verbose_ = level;
return old;
}
void Foam::ensightMesh::correct()
{
clear();
@ -214,6 +229,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
}
}
@ -235,6 +254,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
}
else
{
@ -253,6 +276,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
}
}
@ -345,7 +372,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
if (!part.total())
{
boundaryParts_.erase(patchId);
@ -379,7 +409,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
if (!part.total())
{
faceZoneParts_.erase(zoneId);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -57,8 +57,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef ensightMesh_H
#define ensightMesh_H
#ifndef Foam_ensightMesh_H
#define Foam_ensightMesh_H
#include "Map.H"
#include "ensightCells.H"
@ -114,6 +114,9 @@ private:
//- Track if it needs an update
mutable bool needsUpdate_;
//- Output verbosity level
int verbose_;
// Private Member Functions
@ -143,6 +146,14 @@ public:
// Member Functions
//- Output verbosity level
int verbose() const noexcept;
//- Change the output verbosity level.
// \return old level
int verbose(const int level) noexcept;
// Access
//- Reference to the underlying polyMesh

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,7 +26,6 @@ License
\*---------------------------------------------------------------------------*/
#include "ensightOutput.H"
#include "cell.H"
#include "cellShape.H"
#include "face.H"
@ -133,20 +132,29 @@ Foam::labelList Foam::ensightOutput::Detail::getPolysNPointsPerFace
}
void Foam::ensightOutput::writeFaceList
void Foam::ensightOutput::Detail::writeLabelListList
(
ensightGeoFile& os,
const UList<face>& faces
const labelUList& offsets,
const labelUList& values,
const label pointOffset
)
{
for (const face& f : faces)
{
for (const label labi : f)
{
os.write(labi + 1);
}
const label off = (pointOffset + 1); // 1-based for Ensight
os.newline();
const label nLists = (offsets.size() - 1);
for (label i = 0; i < nLists; ++i)
{
const labelUList list
(
values.slice(offsets[i], (offsets[i+i] - offsets[i]))
);
for (const label pointi : list)
{
os.write(pointi + off);
}
os.newline(); // One list (cell/faces) per line (ASCII)
}
}
@ -154,40 +162,119 @@ void Foam::ensightOutput::writeFaceList
void Foam::ensightOutput::writeFaceList
(
ensightGeoFile& os,
const UIndirectList<face>& faces
const UList<face>& faces,
const label pointOffset
)
{
for (const face& f : faces)
{
for (const label labi : f)
{
os.write(labi + 1);
}
ensightOutput::Detail::writeLabelListList(os, faces, pointOffset);
}
os.newline();
}
void Foam::ensightOutput::writeFaceList
(
ensightGeoFile& os,
const UIndirectList<face>& faces,
const label pointOffset
)
{
ensightOutput::Detail::writeLabelListList(os, faces, pointOffset);
}
void Foam::ensightOutput::writeFaceList
(
ensightGeoFile& os,
const CompactListList<label>& faces,
const label pointOffset
)
{
ensightOutput::Detail::writeLabelListList(os, faces, pointOffset);
}
void Foam::ensightOutput::writeCellShapes
(
ensightGeoFile& os,
const UList<cellShape>& shapes
const UList<cellShape>& shapes,
const label pointOffset
)
{
for (const cellShape& cellPoints : shapes)
ensightOutput::Detail::writeLabelListList(os, shapes, pointOffset);
}
Foam::CompactListList<Foam::label>
Foam::ensightOutput::Detail::getPolysFacePoints
(
const polyMesh& mesh,
const labelUList& addr,
const labelList& pointMap
)
{
const cellList& meshCells = mesh.cells();
const faceList& meshFaces = mesh.faces();
const labelList& owner = mesh.faceOwner();
// The caller should have already checked for possible overflow,
// so can skip that here.
// but still need the sizing for allocations
label nFaces = 0, nPoints = 0;
for (const label cellId : addr)
{
// Convert global -> local index
// (note: Ensight indices start with 1)
nFaces += meshCells[cellId].size();
// In ASCII, write one cell per line
for (const label pointi : cellPoints)
for (const label faceId : meshCells[cellId])
{
os.write(pointi + 1);
nPoints += meshFaces[faceId].size();
}
os.newline();
}
CompactListList<label> compact(nFaces, nPoints);
labelList& offsets = compact.offsets();
labelList& verts = compact.values();
// Restart counts
nFaces = nPoints = 0;
for (const label cellId : addr)
{
for (const label faceId : meshCells[cellId])
{
const face& f = meshFaces[faceId];
offsets[nFaces++] = nPoints;
if (faceId < owner.size() && owner[faceId] != cellId)
{
// The neighbour of an internal face
// - handle like face::reverseFace()
verts[nPoints++] = pointMap[f[0]];
for (label pti = f.size()-1; pti > 0; --pti)
{
verts[nPoints++] = pointMap[f[pti]];
}
}
else
{
for (const label pointi : f)
{
verts[nPoints++] = pointMap[pointi];
}
}
}
}
// Finally
if (nFaces)
{
offsets[nFaces] = nPoints;
}
return compact;
}
@ -203,6 +290,8 @@ void Foam::ensightOutput::writePolysPoints
const faceList& meshFaces = mesh.faces();
const labelList& owner = mesh.faceOwner();
const label off = (1); // 1-based for Ensight
for (const label cellId : addr)
{
for (const label faceId : meshCells[cellId])
@ -214,21 +303,21 @@ void Foam::ensightOutput::writePolysPoints
// The neighbour of an internal face
// - write as face::reverseFace()
os.write(pointMap[f[0]] + 1);
os.write(pointMap[f[0]] + off);
for (label pti = f.size()-1; pti > 0; --pti)
{
os.write(pointMap[f[pti]] + 1);
os.write(pointMap[f[pti]] + off);
}
}
else
{
for (const label pointi : f)
{
os.write(pointMap[pointi] + 1);
os.write(pointMap[pointi] + off);
}
}
os.newline();
os.newline(); // One face per line (ASCII)
}
}
}
@ -243,6 +332,8 @@ void Foam::ensightOutput::writePolysPoints
const labelUList& owner
)
{
const label off = (1); // 1-based for Ensight
for (const label cellId : addr)
{
for (const label faceId : meshCells[cellId])
@ -254,21 +345,21 @@ void Foam::ensightOutput::writePolysPoints
// The neighbour of an internal face
// - write as face::reverseFace()
os.write(f[0] + 1);
os.write(f[0] + off);
for (label pti = f.size()-1; pti > 0; --pti)
{
os.write(f[pti] + 1);
os.write(f[pti] + off);
}
}
else
{
for (const label pointi : f)
{
os.write(pointi + 1);
os.write(pointi + off);
}
}
os.newline();
os.newline(); // One face per line (ASCII)
}
}
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef ensightOutput_H
#define ensightOutput_H
#ifndef Foam_ensightOutput_H
#define Foam_ensightOutput_H
#include "ensightFile.H"
#include "ensightGeoFile.H"
@ -50,6 +50,7 @@ SourceFiles
#include "ListOps.H"
#include "ListListOps.H"
#include "IndirectList.H"
#include "CompactListList.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -127,21 +128,32 @@ namespace ensightOutput
void writeFaceList
(
ensightGeoFile& os,
const UList<face>& faces
const UList<face>& faces,
const label pointOffset = 0 //!< Additional point offset for each face
);
//- Write list of faces
//- Write list of faces (indirect addressing)
void writeFaceList
(
ensightGeoFile& os,
const UIndirectList<face>& faces
const UIndirectList<face>& faces,
const label pointOffset = 0 //!< Additional point offset for each face
);
//- Write list of faces (stored in compact form)
void writeFaceList
(
ensightGeoFile& os,
const CompactListList<label>& faces,
const label pointOffset = 0 //!< Additional point offset for each face
);
//- Write cell connectivity via cell shapes
void writeCellShapes
(
ensightGeoFile& os,
const UList<cellShape>& shapes
const UList<cellShape>& shapes,
const label pointOffset = 0 //!< Additional point offset
);
@ -260,6 +272,35 @@ labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr);
//- The number of points for each face of the poly elements
labelList getPolysNPointsPerFace(const polyMesh& mesh, const labelUList& addr);
//- Generate 0-based point ids for each poly element face
// The returned CompactListList is divided per output face
CompactListList<label> getPolysFacePoints
(
const polyMesh& mesh,
const labelUList& addr, //!< Cell ids to write
const labelList& pointMap //!< Point map to use
);
//- Write CompactListList<label> by components
void writeLabelListList
(
ensightGeoFile& os,
const labelUList& offsets,
const labelUList& values,
const label pointOffset
);
//- Write a list of faces or cell shapes with one-entity per line
template<class LabelListListType>
void writeLabelListList
(
ensightGeoFile& os,
const LabelListListType& listOfLists,
const label pointOffset
);
//- Copy specified field component into a scalar buffer
//- works for various lists types. Must be adequately sized before calling

View File

@ -31,6 +31,27 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class LabelListListType>
void Foam::ensightOutput::Detail::writeLabelListList
(
ensightGeoFile& os,
const LabelListListType& listOfLists,
const label pointOffset
)
{
const label off = (pointOffset + 1); // 1-based for Ensight
forAll(listOfLists, listi)
{
for (const label pointi : listOfLists[listi])
{
os.write(pointi + off);
}
os.newline(); // One list (cell/faces) per line (ASCII)
}
}
template<template<typename> class FieldContainer, class Type>
void Foam::ensightOutput::Detail::copyComponent
(

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,8 +32,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef ensightCells_H
#define ensightCells_H
#ifndef Foam_ensightCells_H
#define Foam_ensightCells_H
#include "ensightPart.H"
#include "FixedList.H"
@ -47,6 +47,7 @@ namespace Foam
// Forward Declarations
class bitSet;
class polyMesh;
template<class T> class InfoProxy;
/*---------------------------------------------------------------------------*\
Class ensightCells Declaration
@ -161,7 +162,6 @@ public:
virtual ~ensightCells() = default;
// Member Functions
// Access
@ -245,6 +245,10 @@ public:
// Output
//- Return info proxy
InfoProxy<ensightCells> info() const { return *this; }
//- Globally unique mesh points. Required when writing point fields.
label uniqueMeshPoints
(
@ -268,6 +272,10 @@ public:
};
template<>
Ostream& operator<<(Ostream&, const InfoProxy<ensightCells>&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -106,7 +106,7 @@ Foam::label Foam::ensightCells::meshPointMapppings
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
}
else
{
@ -125,7 +125,7 @@ Foam::label Foam::ensightCells::meshPointMapppings
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
meshPointMap.clear();

View File

@ -27,6 +27,7 @@ License
#include "ensightCells.H"
#include "ensightOutput.H"
#include "InfoProxy.H"
#include "polyMesh.H"
#include "globalIndex.H"
#include "globalMeshData.H"
@ -326,4 +327,30 @@ void Foam::ensightCells::write
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<ensightCells>& ip
)
{
const ensightCells& part = ip.t_;
os << part.name().c_str();
for (label typei=0; typei < ensightCells::nTypes; ++typei)
{
const auto etype = ensightCells::elemType(typei);
os << ' ' << ensightCells::elemNames[etype]
<< ':' << part.total(etype);
}
os << nl;
return os;
}
// ************************************************************************* //

View File

@ -49,8 +49,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef ensightFaces_H
#define ensightFaces_H
#ifndef Foam_ensightFaces_H
#define Foam_ensightFaces_H
#include "ensightPart.H"
#include "face.H"
@ -64,6 +64,7 @@ namespace Foam
// Forward Declarations
class polyMesh;
template<class T> class InfoProxy;
/*---------------------------------------------------------------------------*\
Class ensightFaces Declaration
@ -243,6 +244,10 @@ public:
// Output
//- Return info proxy
InfoProxy<ensightFaces> info() const { return *this; }
//- Globally unique mesh points.
//- Required when writing point fields.
label uniqueMeshPoints
@ -266,6 +271,10 @@ public:
};
template<>
Ostream& operator<<(Ostream&, const InfoProxy<ensightFaces>&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -76,7 +76,7 @@ Foam::label Foam::ensightFaces::uniqueMeshPoints
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
}
else
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +27,7 @@ License
#include "ensightFaces.H"
#include "ensightOutput.H"
#include "InfoProxy.H"
#include "polyMesh.H"
#include "globalIndex.H"
#include "globalMeshData.H"
@ -78,7 +78,7 @@ void Foam::ensightFaces::write
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
}
else
{
@ -135,4 +135,30 @@ void Foam::ensightFaces::write
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<ensightFaces>& ip
)
{
const ensightFaces& part = ip.t_;
os << part.name().c_str();
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
{
const auto etype = ensightFaces::elemType(typei);
os << ' ' << ensightFaces::elemNames[etype]
<< ':' << part.total(etype);
}
os << nl;
return os;
}
// ************************************************************************* //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -53,7 +53,8 @@ Foam::ensightFaMesh::ensightFaMesh
)
:
mesh_(mesh),
needsUpdate_(true)
needsUpdate_(true),
verbose_(0)
{
// Lazy?
if (true)
@ -65,6 +66,20 @@ Foam::ensightFaMesh::ensightFaMesh
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int Foam::ensightFaMesh::verbose() const noexcept
{
return verbose_;
}
int Foam::ensightFaMesh::verbose(const int level) noexcept
{
int old(verbose_);
verbose_ = level;
return old;
}
void Foam::ensightFaMesh::correct()
{
clear();
@ -87,6 +102,11 @@ void Foam::ensightFaMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
// if (!part.total())
// {
// areaParts_.erase(areaId);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -41,8 +41,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef fa_ensightMesh_H
#define fa_ensightMesh_H
#ifndef Foam_fa_ensightMesh_H
#define Foam_fa_ensightMesh_H
#include "ensightFaces.H"
@ -73,6 +73,9 @@ class ensightFaMesh
//- Track if it needs an update
mutable bool needsUpdate_;
//- Output verbosity level
int verbose_;
// Private Member Functions
@ -99,6 +102,14 @@ public:
// Member Functions
//- Output verbosity level
int verbose() const noexcept;
//- Change the output verbosity level.
// \return old level
int verbose(const int level) noexcept;
// Access
//- Reference to the underlying faMesh