Loading...
Searching...
No Matches
smoothSurfaceData.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Application
27 smoothSurfaceData
28
29Description
30 Pre-processing, filtering of surface field data.
31 Currently this is just used to test filter settings
32 (for MappedFile) and only generates vtk output, which can be
33 easily loaded in ParaView.
34
35\*---------------------------------------------------------------------------*/
36
37#include "argList.H"
38#include "Time.H"
39#include "clockTime.H"
40#include "primitiveFields.H"
41#include "surfaceReader.H"
42#include "surfaceWriter.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48using namespace Foam;
49
50
51// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52
53int main(int argc, char *argv[])
54{
56 (
57 "Testing, pre-processing, filtering of surface field data"
58 );
59
62
63 argList::addArgument("input", "The input surface file");
64
65 argList::addOption("radius", "m", "Specify filter radius [metres]");
66 argList::addOption("sweeps", "N", "Number of median filter stages");
68 (
69 "field",
70 "name",
71 "Field <scalar> to process (default: T)"
72 );
73
75 (
76 "read-format",
77 "type",
78 "Input format (default: ensight)"
79 );
80
81 argList args(argc, argv);
82 // #include "setRootCase.H"
83
84 const int optVerbose = args.verbose();
85
86 const word readFileType
87 (
88 args.getOrDefault<word>("read-format", "ensight")
89 );
90
91 // Constant radius searching
92 label filterSweeps_(1);
93 scalar filterRadius_(0);
94 args.readIfPresent("sweeps", filterSweeps_);
95 args.readIfPresent("radius", filterRadius_);
96
97 Info<< nl
98 << "Filter: radius=" << filterRadius_
99 << " sweeps=" << filterSweeps_ << endl;
100
101 // Simple sanity check
102 if ((filterSweeps_ < 1) || (filterRadius_ <= VSMALL))
103 {
104 Info<< nl << "Nothing to do. Exiting..." << nl << endl;
105 return 0;
106 }
107
108 word fieldName("T");
109 args.readIfPresent("field", fieldName);
110
111
112 const fileName importName = args.get<fileName>(1);
113
114 auto readerPtr_ = surfaceReader::New(readFileType, importName);
115
116 auto& reader = readerPtr_();
117
118 const label fieldIndex = reader.fieldNames(0).find(fieldName);
119 if (fieldIndex == -1)
120 {
122 << "Unable to find field name: " << fieldName
123 << " in list of available fields: " << reader.fieldNames(0)
124 << exit(FatalError);
125 }
126
127 clockTime timing;
128
129 const meshedSurface& geom = reader.geometry(0);
130
131 Info<< nl << "Read " << geom.nFaces() << " faces and "
132 << geom.nPoints() << " points in "
133 << timing.timeIncrement() << "s" << endl;
134
136
137 PatchFunction1Types::FilterField::debug = optVerbose;
138
139 fieldFilter.reset(geom, filterRadius_);
140
141 Info<< nl << "Built weights/addressing "
142 << timing.timeIncrement() << "s" << endl;
143
144 Info<< nl << "Processing " << reader.times().size() << " times" << nl;
145
146 const instantList times(reader.times());
147
148 forAll(times, timeIndex)
149 {
150 tmp<scalarField> tfield
151 (
152 reader.field(timeIndex, fieldIndex, pTraits<scalar>::zero)
153 );
154
155 tfield = fieldFilter.evaluate(tfield, filterSweeps_);
156
158 (
159 geom.points(),
160 geom,
161 word::printf("filtered_%06d", timeIndex)
162 );
163
164 writer.piece(geom.points(), geom);
165
166 writer.writeGeometry();
167 writer.beginCellData();
168 writer.writeCellData(fieldName, tfield());
169 }
170
171 Info<< nl << "Smoothing/writing "
172 << timing.timeIncrement() << "s" << endl;
173
174 Info<< nl << "End\n" << endl;
175
176 return 0;
177}
178
179
180// ************************************************************************* //
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
The FilterField helper class provides a multi-sweep median filter for a Field of data associated with...
tmp< Field< Type > > evaluate(const tmp< Field< Type > > &tinput, const label nSweeps) const
Return the median smoothed field.
void reset()
Reset to unweighted (pass-through).
label nPoints() const
Number of points supporting patch faces.
label nFaces() const noexcept
Number of faces in the patch.
const Field< point_type > & points() const noexcept
Return reference to global points.
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
Definition argList.C:535
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void noCheckProcessorDirectories()
Disable checking of processor directories.
Definition argList.C:619
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition argList.C:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Starts timing and returns elapsed time from start. Uses std::chrono::high_resolution_clock for better...
Definition clockTime.H:59
double timeIncrement() const
The time [seconds] since the last call to elapsedTime(), timeIncrement() or resetTime(),...
Definition clockTimeI.H:59
A class for handling file names.
Definition fileName.H:75
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
static autoPtr< surfaceReader > New(const word &readType, const fileName &fName, const dictionary &options=dictionary())
Return a reference to the selected surfaceReader.
A class for managing temporary objects.
Definition tmp.H:75
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
A class for handling words, derived from Foam::string.
Definition word.H:66
static word printf(const char *fmt, const PrimitiveType &val)
Use a printf-style formatter for a primitive.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
Definition instantList.H:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
MeshedSurface< face > meshedSurface
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
label timeIndex
Specialisations of Field<T> for scalar, vector and tensor.
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299