ENH: sampledSets - enable writer construction from dictionary

Users can now include additional controls via a new formatOptions dictionary.
This commit is contained in:
Andrew Heather
2021-11-11 13:44:49 +00:00
committed by Mark Olesen
parent e5267bf81d
commit 98c25d163a
23 changed files with 186 additions and 62 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,6 +40,13 @@ Foam::csvSetWriter<Type>::csvSetWriter()
{}
template<class Type>
Foam::csvSetWriter<Type>::csvSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -74,9 +75,12 @@ public:
// Constructors
//- Construct null
//- Default construct
csvSetWriter();
//- Construct with dictionary
explicit csvSetWriter(const dictionary& dict);
//- Destructor
virtual ~csvSetWriter() = default;

View File

@ -42,6 +42,13 @@ Foam::ensightSetWriter<Type>::ensightSetWriter()
{}
template<class Type>
Foam::ensightSetWriter<Type>::ensightSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -61,9 +62,12 @@ public:
// Constructors
//- Construct null
//- Default construct
ensightSetWriter();
//- Construct with dictionary
explicit ensightSetWriter(const dictionary& dict);
//- Destructor
virtual ~ensightSetWriter() = default;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -42,6 +42,13 @@ Foam::gnuplotSetWriter<Type>::gnuplotSetWriter()
{}
template<class Type>
Foam::gnuplotSetWriter<Type>::gnuplotSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,7 +53,6 @@ class gnuplotSetWriter
:
public writer<Type>
{
public:
//- Runtime type information
@ -61,9 +61,12 @@ public:
// Constructors
//- Construct null
//- Default construct
gnuplotSetWriter();
//- Construct with dictionary
explicit gnuplotSetWriter(const dictionary& dict);
//- Destructor
virtual ~gnuplotSetWriter() = default;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,7 +32,6 @@ License
#include "fileName.H"
#include "OFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
@ -53,6 +53,13 @@ Foam::jplotSetWriter<Type>::jplotSetWriter()
{}
template<class Type>
Foam::jplotSetWriter<Type>::jplotSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -65,9 +66,12 @@ public:
// Constructors
//- Construct null
//- Default construct
jplotSetWriter();
//- Construct with dictionary
explicit jplotSetWriter(const dictionary& dict);
//- Destructor
virtual ~jplotSetWriter() = default;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,6 +39,13 @@ Foam::nastranSetWriter<Type>::nastranSetWriter()
{}
template<class Type>
Foam::nastranSetWriter<Type>::nastranSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -56,13 +56,6 @@ class nastranSetWriter
:
public writer<Type>
{
public:
//- File field formats
using fieldFormat = Foam::fileFormats::NASCore::fieldFormat;
private:
// Private Member Functions
//- Write the formatted keyword to the output stream
@ -75,15 +68,22 @@ private:
public:
//- File field formats
using fieldFormat = Foam::fileFormats::NASCore::fieldFormat;
//- Runtime type information
TypeName("nastran");
// Constructors
//- Construct null
//- Default construct
nastranSetWriter();
//- Construct with dictionary
explicit nastranSetWriter(const dictionary& dict);
//- Destructor
virtual ~nastranSetWriter() = default;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,6 +40,13 @@ Foam::rawSetWriter<Type>::rawSetWriter()
{}
template<class Type>
Foam::rawSetWriter<Type>::rawSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,7 +53,6 @@ class rawSetWriter
:
public writer<Type>
{
public:
//- Runtime type information
@ -61,9 +61,12 @@ public:
// Constructors
//- Construct null
//- Default construct
rawSetWriter();
//- Construct with dictionary
explicit rawSetWriter(const dictionary& dict);
//- Destructor
virtual ~rawSetWriter() = default;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -42,6 +42,13 @@ Foam::vtkSetWriter<Type>::vtkSetWriter()
{}
template<class Type>
Foam::vtkSetWriter<Type>::vtkSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -55,7 +56,6 @@ class vtkSetWriter
:
public writer<Type>
{
public:
//- Runtime type information
@ -64,9 +64,12 @@ public:
// Constructors
//- Construct null
//- Default construct
vtkSetWriter();
//- Construct with dictionary
explicit vtkSetWriter(const dictionary& dict);
//- Destructor
virtual ~vtkSetWriter() = default;

View File

@ -31,7 +31,7 @@ License
#include "OFstream.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::writer<Type>> Foam::writer<Type>::New
@ -55,6 +55,29 @@ Foam::autoPtr<Foam::writer<Type>> Foam::writer<Type>::New
}
template<class Type>
Foam::autoPtr<Foam::writer<Type>> Foam::writer<Type>::New
(
const word& writeType,
const dictionary& formatOptions
)
{
auto ctorPtr = dictConstructorTable(writeType);
if (!ctorPtr)
{
FatalErrorInLookup
(
"writer",
writeType,
*dictConstructorTablePtr_
) << exit(FatalError);
}
return autoPtr<writer<Type>>(ctorPtr(formatOptions));
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
@ -143,10 +166,8 @@ Foam::writer<Type>::writer()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::writer<Type>::~writer()
Foam::writer<Type>::writer(const dictionary& dict)
{}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,7 +71,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class coordSet;
/*---------------------------------------------------------------------------*\
@ -80,7 +81,6 @@ class coordSet;
template<class Type>
class writer
{
protected:
//- Generates filename from coordSet and sampled fields
@ -123,21 +123,42 @@ public:
()
);
declareRunTimeSelectionTable
(
autoPtr,
writer,
dict,
(
const dictionary& formatOptions
),
(formatOptions)
);
// Selectors
//- Return a reference to the selected writer
static autoPtr<writer> New(const word& writeFormat);
//- Return a reference to the selected writer
static autoPtr<writer> New
(
const word& writeFormat,
const dictionary& formatOptions
);
// Constructors
//- Construct null
//- Default construct
writer();
//- Construct with dictionary
explicit writer(const dictionary& dict);
//- Destructor
virtual ~writer() = 0;
virtual ~writer() = default;
// Member Functions

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,7 +37,8 @@ namespace Foam
#define defineSetWriterType(dataType) \
defineNamedTemplateTypeNameAndDebug(writer<dataType >, 0); \
defineTemplatedRunTimeSelectionTable(writer, word, dataType);
defineTemplatedRunTimeSelectionTable(writer, word, dataType); \
defineTemplatedRunTimeSelectionTable(writer, dict, dataType);
defineSetWriterType(scalar);
defineSetWriterType(vector);

View File

@ -61,7 +61,11 @@ SourceFiles
addTemplatedToRunTimeSelectionTable \
( \
writer, typeWriter, dataType, word \
)
); \
addTemplatedToRunTimeSelectionTable \
( \
writer, typeWriter, dataType, dict \
);
// Define type info for scalar, vector etc. instantiations

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,6 +41,13 @@ Foam::xmgraceSetWriter<Type>::xmgraceSetWriter()
{}
template<class Type>
Foam::xmgraceSetWriter<Type>::xmgraceSetWriter(const dictionary& dict)
:
writer<Type>(dict)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,7 +53,6 @@ class xmgraceSetWriter
:
public writer<Type>
{
public:
//- Runtime type information
@ -61,9 +61,12 @@ public:
// Constructors
//- Construct null
//- Default construct
xmgraceSetWriter();
//- Construct with dictionary
explicit xmgraceSetWriter(const dictionary& dict);
//- Destructor
virtual ~xmgraceSetWriter() = default;

View File

@ -97,7 +97,8 @@ Foam::sampledSets::sampledSets
outputPath_(fileName::null),
searchEngine_(mesh_),
interpolationScheme_(word::null),
writeFormat_(word::null)
writeFormat_(word::null),
writeFormatOptions_(dict.subOrEmptyDict("formatOptions"))
{
outputPath_ =
(
@ -106,7 +107,7 @@ Foam::sampledSets::sampledSets
if (mesh_.name() != polyMesh::defaultRegion)
{
outputPath_ = outputPath_/mesh_.name();
outputPath_ /= mesh_.name();
}
outputPath_.clean(); // Remove unneeded ".."
@ -130,7 +131,8 @@ Foam::sampledSets::sampledSets
outputPath_(fileName::null),
searchEngine_(mesh_),
interpolationScheme_(word::null),
writeFormat_(word::null)
writeFormat_(word::null),
writeFormatOptions_(dict.subOrEmptyDict("formatOptions"))
{
outputPath_ =
(
@ -139,7 +141,7 @@ Foam::sampledSets::sampledSets
if (mesh_.name() != polyMesh::defaultRegion)
{
outputPath_ = outputPath_/mesh_.name();
outputPath_ /= mesh_.name();
}
outputPath_.clean(); // Remove unneeded ".."

View File

@ -53,7 +53,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
class Time;
class objectRegistry;
class dictionary;
@ -68,7 +68,7 @@ class sampledSets
public functionObjects::regionFunctionObject,
public PtrList<sampledSet>
{
// Private classes
// Private Classes
//- Class used for grouping field types
template<class Type>
@ -82,18 +82,7 @@ class sampledSets
autoPtr<writer<Type>> formatter;
//- Construct null
fieldGroup()
:
DynamicList<word>(0),
formatter(nullptr)
{}
//- Construct for a particular format
fieldGroup(const word& writeFormat)
:
DynamicList<word>(0),
formatter(writer<Type>::New(writeFormat))
{}
fieldGroup() = default;
//- Reset format and field list
void clear()
@ -102,10 +91,9 @@ class sampledSets
formatter.clear();
}
//- Assign a new formatter
void operator=(const word& writeFormat)
void setFormatter(const word& writeFormat, const dictionary& dict)
{
formatter = writer<Type>::New(writeFormat);
formatter = writer<Type>::New(writeFormat, dict);
}
};
@ -151,13 +139,13 @@ class sampledSets
};
// Static data members
// Static Data Members
//- Output verbosity
static bool verbose_;
// Private data
// Private Data
//- Const reference to fvMesh
const fvMesh& mesh_;
@ -175,7 +163,7 @@ class sampledSets
meshSearch searchEngine_;
// Read from dictonary
// Read from dictionary
//- Names of fields to sample
wordRes fieldSelection_;
@ -186,8 +174,11 @@ class sampledSets
//- Output format to use
word writeFormat_;
//- Dictionary containing writer options
dictionary writeFormatOptions_;
// Categorized scalar/vector/tensor fields
// Categorized scalar/vector/tensor fields
fieldGroup<scalar> scalarFields_;
fieldGroup<vector> vectorFields_;
@ -196,7 +187,7 @@ class sampledSets
fieldGroup<tensor> tensorFields_;
// Merging structures
// Merging structures
PtrList<coordSet> masterSampledSets_;
labelListList indexSets_;
@ -211,7 +202,7 @@ class sampledSets
label classifyFields();
//- Combine points from all processors. Sort by curveDist and produce
// index list. Valid result only on master processor.
//- index list. Valid result only on master processor.
void combineSampledSets
(
PtrList<coordSet>& masterSampledSets,

View File

@ -231,7 +231,7 @@ void Foam::sampledSets::sampleAndWrite(fieldGroup<Type>& fields)
// Create or use existing writer
if (!fields.formatter)
{
fields = writeFormat_;
fields.setFormatter(writeFormat_, writeFormatOptions_);
}
// Storage for interpolated values