Loading...
Searching...
No Matches
radiometerProbes.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) 2025 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
26\*---------------------------------------------------------------------------*/
27
28#include "radiometerProbes.H"
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
35namespace functionObjects
36{
39}
40}
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
44void Foam::functionObjects::radiometerProbes::writeFileHeader(Ostream& os)
45{
46 const pointField& locs = probeLocations();
47
48 writeCommented(os, "Probe,Location,Normal");
49
50 os << nl;
51 for (label i = 0; i < szProbes_; ++i)
52 {
53 const vector& loc = locs[i];
54 const vector& n = n_[i];
55
56 os << '#' << ' ' << i
57 << ',' << loc.x() << ',' << loc.y() << ',' << loc.z()
58 << ',' << n.x() << ',' << n.y() << ',' << n.z()
59 << nl;
60 }
61
62 os << "# Time";
63 for (int i = 0; i < szProbes_; ++i)
64 {
65 os << ',' << i;
66 }
67 os << endl;
69 writtenHeader_ = true;
70}
71
72
73// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74
76(
77 const word& name,
78 const Time& runTime,
79 const dictionary& dict
80)
81:
84 writeFile(mesh_, name, typeName, dict),
85 dom_(mesh_.lookupObject<radiation::fvDOM>("radiationProperties")),
86 firstIter_(true)
88 read(dict);
89}
90
91
92// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
93
95{
96 if
97 (
98 !(
102 )
103 )
104 {
105 return false;
106 }
107
108
109 // Skip if the radiation model is inactive
110 if (!dom_.radiation())
111 {
113 << "The radiation model is inactive."
114 << "Skipping the function object " << type() << ' ' << name()
115 << endl;
116 return false;
117 }
118
119 Log << type() << ':' << name() << ": read" << nl << nl;
120
121
122 // Probe locations are read by 'internalFieldProbe'
123 szProbes_ = this->size();
124
125 // If/when fvDOM is updated, the 'read' func is assumed to be executed to
126 // update the fvDOM properties
127 nRay_ = dom_.nRay();
128
129 if (!szProbes_ || !nRay_)
130 {
132 << "size(probe locations): " << szProbes_ << nl
133 << "size(rays): " << nRay_ << nl
134 << "The input size of probe locations and rays cannot be zero."
135 << exit(FatalIOError);
136 }
137
138 // Read and check size consistency of probe normals with probe locations
139 dict.readEntry("probeNormals", n_);
140 if (n_.size() != szProbes_)
141 {
143 << "size(probe locations): " << szProbes_ << nl
144 << "size(probe normals): " << n_.size() << nl
145 << "The input size of probe locations and normals must match."
146 << exit(FatalIOError);
147 }
148 n_.normalise();
149
150
151 // Pre-compute and cache inner product of 'n_' and 'dAve_', and 'C_'
152 // This simplification of calculation is valid only if I is non-negative
153 n_dAve_.resize(nRay_);
154 C_.resize(nRay_);
155
156 for (label rayi = 0; rayi < nRay_; ++rayi)
157 {
158 const vector& dAvei = dom_.IRay(rayi).dAve();
159
160 scalarList& n_dAveRay = n_dAve_[rayi];
161 boolList& Cray = C_[rayi];
162
163 n_dAveRay.resize(szProbes_, Zero);
164 Cray.resize(szProbes_, false);
165
166 for (label pi = 0; pi < szProbes_; ++pi)
167 {
168 n_dAveRay[pi] = n_[pi] & dAvei;
169
170 if (n_dAveRay[pi] < 0) // ray entering the probe
171 {
172 Cray[pi] = true;
173 }
174 }
175 }
176
177 qin_.resize(szProbes_);
178
179
181 {
183 }
184
186 {
187 writeFileHeader(file());
188 }
189
190 return true;
191}
192
193
195{
196 // Skip if there is no probe to sample, or the radiation model is inactive
197 if (!szProbes_ || !dom_.radiation() || !shouldCalcThisStep())
198 {
199 return false;
200 }
201
202 Log << type() << ' ' << name() << ": execute" << nl << nl;
203
204 qin_ = Zero; // resized in 'read'
205
206 for (label rayi = 0; rayi < nRay_; ++rayi)
207 {
208 // Radiative intensity field for this ray
209 const volScalarField& I = dom_.IRay(rayi).I();
210
211 // Sample radiative intensity ray at probe locations
212 tmp<scalarField> tIp = internalFieldProbe::sample(I);
213 const scalarField& Ip = tIp.cref();
214
215 const scalarList& n_dAveRay = n_dAve_[rayi];
216 const boolList& Cray = C_[rayi];
217
218 // Add incident radiative heat flux per probe location for each ray
219 for (label pi = 0; pi < szProbes_; ++pi)
220 {
221 if (Cray[pi])
222 {
223 qin_[pi] += Ip[pi]*n_dAveRay[pi];
224 }
226 }
227
228 return true;
229}
230
231
233{
234 // Skip if there is no probe to sample, or the radiation model is inactive
235 if (!szProbes_ || !dom_.radiation() || !shouldCalcThisStep())
236 {
237 return false;
238 }
239
240 Log << type() << ' ' << name() << ": write" << nl << nl;
241
242 if (UPstream::master())
243 {
244 Ostream& os = file();
245
246 os << mesh_.time().timeOutputValue();
247 for (label pi = 0; pi < szProbes_; ++pi)
248 {
249 os << ',' << qin_[pi];
250 }
251 os << endl;
252 }
253
254 firstIter_ = false;
255
256 return true;
257}
258
259
260// ************************************************************************* //
constexpr scalar pi(M_PI)
#define Log
Definition PDRblock.C:28
label n
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition UPstream.H:1714
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector.H:135
const Cmpt & z() const noexcept
Access to the vector z component.
Definition Vector.H:145
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector.H:140
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Abstract base-class for Time/database function objects.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
Probes the incident radiative heat flux, qin, at arbitrary points within a domain.
radiometerProbes(const radiometerProbes &)=delete
No copy construct.
virtual bool execute()
Execute the function object.
virtual bool write()
Write to data files/fields and to streams.
virtual bool read(const dictionary &)
Read the function object settings.
const ObjectType & lookupObject(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
virtual bool read(const dictionary &dict)
Read optional controls.
Base class for writing single files from the function objects.
Definition writeFile.H:113
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
virtual bool read(const dictionary &dict)
Read.
Definition writeFile.C:240
bool writtenHeader_
Flag to identify whether the header has been written.
Definition writeFile.H:157
virtual OFstream & file()
Return access to the file (if only 1).
Definition writeFile.C:270
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition writeFile.C:318
virtual void resetFile(const word &name)
Reset internal file pointer to new file with new name.
Definition writeFile.C:165
virtual bool canWriteHeader() const
Flag to allow writing the header.
Definition writeFile.C:304
virtual bool canResetFile() const
Flag to allow resetting the file.
Definition writeFile.C:298
A utility class for probing field values at specified point locations within an fvMesh.
internalFieldProbe(const fvMesh &mesh, const dictionary &dict)
Construct from Time and dictionary.
tmp< Field< Type > > sample(const VolumeField< Type > &) const
Sample a volume field at all locations.
virtual bool read(const dictionary &)
Read the settings dictionary.
label size() const
Return number of probe locations.
Definition probeModel.H:196
const pointField & probeLocations() const
Return const reference to the probe locations.
Definition probeModel.H:218
Finite Volume Discrete Ordinates Method. Solves the RTE equation for n directions in a participating ...
Definition fvDOM.H:117
A class for managing temporary objects.
Definition tmp.H:75
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
Definition tmpI.H:221
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
engineTime & runTime
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
auto & name
#define WarningInFunction
Report a warning using Foam::Warning.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for radiation modelling.
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
GeometricField< scalar, fvPatchField, volMesh > volScalarField
static const Identity< scalar > I
Definition Identity.H:100
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
List< bool > boolList
A List of bools.
Definition List.H:60
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
List< scalar > scalarList
List of scalar.
Definition scalarList.H:32
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict