interRegionModel.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "interRegionModel.H"
27 #include "fvModels.H"
28 #include "matchingCellsToCells.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace fv
35 {
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 void Foam::fv::interRegionModel::readCoeffs()
44 {
45  master_ = coeffs().lookupOrDefault<bool>("master", true);
46 
47  nbrRegionName_ =
49  ({
50  "nbrRegion",
51  "nbrRegionName"
52  });
53 
54  coeffs().lookup("interpolationMethod") >> interpolationMethod_;
55 }
56 
57 
59 {
60  if (!interpolationPtr_.valid())
61  {
62  Info<< incrIndent;
63 
64  if (master_)
65  {
66  Info<< indent << "- selecting inter region mapping" << endl;
67 
68  if (mesh().name() == nbrMesh().name())
69  {
71  << "Inter-region model selected, but local and "
72  << "neighbour regions are the same: " << nl
73  << " local region: " << mesh().name() << nl
74  << " secondary region: " << nbrMesh().name() << nl
75  << exit(FatalError);
76  }
77 
78  if (mesh().bounds().overlaps(nbrMesh().bounds()))
79  {
80  interpolationPtr_ = cellsToCells::New(interpolationMethod_);
81  interpolationPtr_->update(mesh(), nbrMesh());
82  }
83  else
84  {
86  << "regions " << mesh().name() << " and "
87  << nbrMesh().name() << " do not intersect"
88  << exit(FatalError);
89  }
90  }
91 
92  Info<< decrIndent;
93  }
94 
95  return interpolationPtr_();
96 }
97 
98 
100 {
101  const fvMesh& nbrMesh = mesh().time().lookupObject<fvMesh>(nbrRegionName());
102 
104  nbrMesh.lookupObject<Foam::fvModels>("fvModels");
105 
106  forAll(fvModels, fvModeli)
107  {
108  if (isA<interRegionModel>(fvModels[fvModeli]))
109  {
110  const interRegionModel& model =
111  refCast<const interRegionModel>(fvModels[fvModeli]);
112 
113  if (model.nbrRegionName() == mesh().name())
114  {
115  return model;
116  }
117  }
118  }
119 
121  << "Neighbour model not found in region " << nbrMesh.name() << nl
122  << exit(FatalError);
123  return NullObjectRef<interRegionModel>();
124 }
125 
126 
127 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 
130 (
131  const word& name,
132  const word& modelType,
133  const fvMesh& mesh,
134  const dictionary& dict
135 )
136 :
137  fvModel(name, modelType, mesh, dict),
138  master_(false),
139  nbrRegionName_(word::null),
140  interpolationMethod_(cellsToCellss::matching::typeName),
141  interpolationPtr_()
142 {
143  readCoeffs();
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
148 
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
156 {
157  if (fvModel::read(dict))
158  {
159  readCoeffs();
160  interpolationPtr_.clear();
161  return true;
162  }
163  else
164  {
165  return false;
166  }
167 }
168 
169 
170 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Class to calculate interpolative addressing and weights between the cells of two overlapping meshes.
Definition: cellsToCells.H:56
static autoPtr< cellsToCells > New(const word &cellsToCellsType)
Select from name.
Definition: cellsToCells.C:163
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T, if not found return the given default.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:710
ITstream & lookupBackwardsCompatible(const wordList &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream, trying a list of keywords.
Definition: dictionary.C:721
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:418
const word & name() const
Return reference to name.
Definition: fvMesh.H:432
Finite volume model abstract base class.
Definition: fvModel.H:59
const dictionary & coeffs() const
Return dictionary.
Definition: fvModelI.H:59
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:199
Finite volume models.
Definition: fvModels.H:65
Base class for inter-region exchange.
interRegionModel(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from dictionary.
virtual bool read(const dictionary &dict)
Read dictionary.
const word & nbrRegionName() const
Return const access to the neighbour region name.
const cellsToCells & interpolation() const
Return const access to the interpolation engine.
virtual ~interRegionModel()
Destructor.
const interRegionModel & nbrModel() const
Get the neighbour interRegionModel.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
defineTypeNameAndDebug(bound, 0)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:241
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:234
error FatalError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
static const char nl
Definition: Ostream.H:266
labelList fv(nPoints)
dictionary dict