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-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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"
33 
34 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace fa
39 {
40  defineTypeNameAndDebug(externalFileSource, 0);
41  addToRunTimeSelectionTable(option, externalFileSource, dictionary);
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 )
55 :
56  fa::faceSetOption(sourceName, modelType, dict, m),
57  fieldName_(dict.get<word>("fieldName")),
58  tableName_(dict.get<word>("tableName")),
59  pExt_
60  (
61  IOobject
62  (
63  "pExt",
64  regionMesh().thisDb().time().timeName(),
65  regionMesh().thisDb(),
66  IOobject::NO_READ,
67  IOobject::NO_WRITE,
68  (
69  dict.getOrDefault("store", false)
70  ? IOobject::REGISTER
71  : IOobject::NO_REGISTER
72  )
73  ),
74  regionMesh(),
76  ),
77  curTimeIndex_(-1),
78  mapping_()
79 {
80  fieldNames_.resize(1, fieldName_);
81 
85 
87 
88  read(dict);
89 }
90 
91 
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 
94 void Foam::fa::externalFileSource::updateMapping()
95 {
96  // Set up mapped values per patch
97  const scalar t = mesh().time().value();
98 
99  PtrList<scalarField> patchValues(mapping_.size());
100 
101  forAll(mapping_, patchi)
102  {
103  const auto* map = mapping_.get(patchi);
104 
105  if (map)
106  {
107  patchValues.set(patchi, map->value(t));
108  }
109  }
110 
111  vsm().mapToSurface<scalar>(patchValues, pExt_.field());
113  // Zero pressure for non-mapped faces
114  faceSetOption::subsetFilter(pExt_.field());
115 }
116 
117 
119 (
120  const areaScalarField& solidMass,
121  faMatrix<scalar>& eqn,
122  const label fieldi
123 )
124 {
125  if (isActive())
126  {
127  DebugInfo
128  << name() << ": applying source to "
129  << eqn.psi().name() << endl;
130 
131  if (curTimeIndex_ != mesh().time().timeIndex())
132  {
133  updateMapping();
134 
135  eqn += pExt_/solidMass.internalField();
137  curTimeIndex_ = mesh().time().timeIndex();
138  }
139  }
140 }
141 
142 
143 bool Foam::fa::externalFileSource::read(const dictionary& dict)
144 {
145  if (fa::option::read(dict))
146  {
147  // Set up mapping (per-patch) for referenced polyPatches (sorted order)
148  // - size is maxPolyPatch+1
149 
150  const labelList& patches = regionMesh().whichPolyPatches();
151 
152  mapping_.clear();
153  mapping_.resize(patches.empty() ? 0 : (patches.back()+1));
154 
155  for (const label patchi : patches)
156  {
157  const polyPatch& p = mesh_.boundaryMesh()[patchi];
158 
159  mapping_.set
160  (
161  patchi,
162  (
163  new PatchFunction1Types::MappedFile<scalar>
164  (
165  p,
166  "uniformValue", // entryName
167  dict,
168  tableName_, // field table name
169  true // face values
170  )
171  )
172  );
173  }
174 
175  return true;
176  }
177 
178  return false;
179 }
180 
181 
182 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
addToRunTimeSelectionTable(option, limitHeight, dictionary)
dictionary dict
Namespace of functions to calculate implicit derivatives returning a matrix. Time derivatives are cal...
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: faOption.H:171
const volSurfaceMapping vsm(aMesh)
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
const Internal & internalField() const noexcept
Return a const-reference to the dimensioned internal field.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual void addSup(const areaScalarField &rho, faMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to compressible momentum equation.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
defineTypeNameAndDebug(limitHeight, 0)
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:47
const dimensionSet dimPressure
#define DebugInfo
Report an information message using Foam::Info.
virtual bool read(const dictionary &dict)
Read source dictionary.
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: faOption.C:38
externalFileSource(const word &sourceName, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from explicit source name and mesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const polyBoundaryMesh & patches
A special matrix type and solver, designed for finite area solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: faMatricesFwd.H:37
void subsetFilter(List< Type > &field) const
Zero all non-selected locations within field.
const GeometricField< Type, faPatchField, areaMesh > & psi() const
Definition: faMatrix.H:352
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:24
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127