Loading...
Searching...
No Matches
externalFileSource.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) 2019-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 "externalFileSource.H"
29#include "fam.H"
30#include "faScalarMatrix.H"
34// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace fa
39{
42}
43}
44
45
46// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47
49(
50 const word& sourceName,
51 const word& modelType,
52 const dictionary& dict,
53 const fvMesh& m,
54 const word& defaultAreaName
55)
56:
57 fa::faceSetOption(sourceName, modelType, dict, m, defaultAreaName),
58 fieldName_(dict.get<word>("fieldName")),
59 tableName_(dict.get<word>("tableName")),
60 pExt_
61 (
63 (
64 "pExt",
65 regionMesh().thisDb().time().timeName(),
66 regionMesh().thisDb(),
67 IOobject::NO_READ,
68 IOobject::NO_WRITE,
69 (
70 dict.getOrDefault("store", false)
71 ? IOobject::REGISTER
72 : IOobject::NO_REGISTER
73 )
74 ),
75 regionMesh(),
77 ),
78 curTimeIndex_(-1),
79 mapping_()
80{
81 fieldNames_.resize(1, fieldName_);
82
84
86
88
89 read(dict);
90}
91
92
93// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94
95void Foam::fa::externalFileSource::updateMapping()
96{
97 // Set up mapped values per patch
98 const scalar t = mesh().time().value();
99
100 PtrList<scalarField> patchValues(mapping_.size());
101
102 forAll(mapping_, patchi)
103 {
104 const auto* map = mapping_.get(patchi);
105
106 if (map)
107 {
108 patchValues.set(patchi, map->value(t));
109 }
110 }
111
112 vsm().mapToSurface<scalar>(patchValues, pExt_.field());
113
114 // Zero pressure for non-mapped faces
115 faceSetOption::subsetFilter(pExt_.field());
116}
117
118
120(
121 const areaScalarField& solidMass,
122 faMatrix<scalar>& eqn,
123 const label fieldi
124)
125{
126 if (isActive())
127 {
129 << name() << ": applying source to "
130 << eqn.psi().name() << endl;
131
132 if (curTimeIndex_ != mesh().time().timeIndex())
133 {
134 updateMapping();
135
136 eqn += pExt_/solidMass.internalField();
138 curTimeIndex_ = mesh().time().timeIndex();
139 }
140 }
141}
142
143
145{
147 {
148 // Set up mapping (per-patch) for referenced polyPatches (sorted order)
149 // - size is maxPolyPatch+1
150
151 const labelList& patches = regionMesh().whichPolyPatches();
152
153 mapping_.clear();
154 mapping_.resize(patches.empty() ? 0 : (patches.back()+1));
155
156 for (const label patchi : patches)
157 {
158 const polyPatch& p = mesh_.boundaryMesh()[patchi];
159
160 mapping_.set
161 (
162 patchi,
163 (
164 new PatchFunction1Types::MappedFile<scalar>
165 (
166 p,
167 "uniformValue", // entryName
168 dict,
169 tableName_, // field table name
170 true // face values
171 )
172 )
173 );
174 }
175
176 return true;
177 }
178
179 return false;
180}
181
182
183// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
const Internal & internalField() const noexcept
Return a const-reference to the dimensioned internal field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition IOobject.C:456
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
Patch value mapping from a set of values stored in a file and a set of unstructured points using the ...
Definition MappedFile.H:173
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
label timeIndex() const noexcept
Return the current time index.
Definition TimeStateI.H:43
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A special matrix type and solver, designed for finite area solutions of scalar equations....
Definition faMatrix.H:108
const GeometricField< Type, faPatchField, areaMesh > & psi() const
Definition faMatrix.H:348
Applies sources on a specified field within a specified region by using an external table file.
externalFileSource(const word &sourceName, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Construct from explicit source name and mesh.
virtual bool read(const dictionary &dict)
Read source dictionary.
virtual void addSup(const areaScalarField &rho, faMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to compressible momentum equation.
void subsetFilter(List< Type > &field) const
Zero all non-selected locations within field.
virtual bool isActive()
Is the source active?
faceSetOption(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Construct from components.
Base abstract class for handling finite area options (i.e. faOption).
Definition faOption.H:149
virtual bool read(const dictionary &dict)
Read source dictionary.
const fvMesh & mesh_
Reference to the mesh database.
Definition faOption.H:175
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition faOption.H:190
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
const faMesh & regionMesh() const
Return the region mesh database (demand-driven).
Definition faOptionI.H:37
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
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
volScalarField & p
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
const volSurfaceMapping vsm(aMesh)
Namespace of functions to calculate implicit derivatives returning a matrix. Time derivatives are cal...
auto & name
word timeName
Definition getTimeIndex.H:3
#define DebugInfo
Report an information message using Foam::Info.
Namespace for finite-area.
Definition limitHeight.C:30
Namespace for OpenFOAM.
const dimensionSet dimPressure
List< label > labelList
A List of labels.
Definition List.H:62
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
label timeIndex
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299