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-2021 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 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace fv
34 {
35  defineTypeNameAndDebug(interRegionModel, 0);
36 }
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::fv::interRegionModel::readCoeffs()
43 {
44  master_ = coeffs().lookupOrDefault<bool>("master", true);
45 
46  nbrRegionName_ =
47  coeffs().lookupBackwardsCompatible<word>
48  ({
49  "nbrRegion",
50  "nbrRegionName"
51  });
52 
53  interpolationMethod_ =
55  (
56  coeffs().lookup("interpolationMethod")
57  );
58 }
59 
60 
61 void Foam::fv::interRegionModel::setMapper() const
62 {
63  Info<< incrIndent;
64 
65  if (master_)
66  {
67  Info<< indent << "- selecting inter region mapping" << endl;
68 
69  if (mesh().name() == nbrMesh().name())
70  {
72  << "Inter-region model selected, but local and "
73  << "neighbour regions are the same: " << nl
74  << " local region: " << mesh().name() << nl
75  << " secondary region: " << nbrMesh().name() << nl
76  << exit(FatalError);
77  }
78 
79  if (mesh().bounds().overlaps(nbrMesh().bounds()))
80  {
81  meshInterpPtr_.reset
82  (
83  new meshToMesh
84  (
85  mesh(),
86  nbrMesh(),
87  interpolationMethod_,
88  false // not interpolating patches
89  )
90  );
91  }
92  else
93  {
95  << "regions " << mesh().name() << " and "
96  << nbrMesh().name() << " do not intersect"
97  << exit(FatalError);
98  }
99  }
100 
101  Info<< decrIndent;
102 }
103 
104 
106 {
107  const fvMesh& nbrMesh = mesh().time().lookupObject<fvMesh>(nbrRegionName());
108 
110  nbrMesh.lookupObject<Foam::fvModels>("fvModels");
111 
112  forAll(fvModels, fvModeli)
113  {
114  if (isA<interRegionModel>(fvModels[fvModeli]))
115  {
116  const interRegionModel& model =
117  refCast<const interRegionModel>(fvModels[fvModeli]);
118 
119  if (model.nbrRegionName() == mesh().name())
120  {
121  return model;
122  }
123  }
124  }
125 
127  << "Neighbour model not found in region " << nbrMesh.name() << nl
128  << exit(FatalError);
129  return NullObjectRef<interRegionModel>();
130 }
131 
132 
133 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
134 
136 (
137  const word& name,
138  const word& modelType,
139  const dictionary& dict,
140  const fvMesh& mesh
141 )
142 :
143  fvModel(name, modelType, dict, mesh),
144  master_(false),
145  nbrRegionName_(word::null),
146  interpolationMethod_(meshToMesh::imDirect),
147  meshInterpPtr_()
148 {
149  readCoeffs();
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 {
163  if (fvModel::read(dict))
164  {
165  readCoeffs();
166  setMapper();
167  return true;
168  }
169  else
170  {
171  return false;
172  }
173 }
174 
175 
176 // ************************************************************************* //
const word & nbrRegionName() const
Return const access to the neighbour region name.
defineTypeNameAndDebug(fixedTemperatureConstraint, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:158
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static const NamedEnum< interpolationMethod, 3 > interpolationMethodNames_
Definition: meshToMesh.H:75
Finite volume model abstract base class.
Definition: fvModel.H:55
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Base class for inter-region exchange.
stressControl lookup("compactNormalStress") >> compactNormalStress
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
interRegionModel(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from dictionary.
Finite volume models.
Definition: fvModels.H:60
static const word null
An empty word.
Definition: word.H:77
virtual bool read(const dictionary &dict)
Read dictionary.
static const char nl
Definition: Ostream.H:260
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
const word & name() const
Return reference to name.
Definition: fvMesh.H:253
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
virtual ~interRegionModel()
Destructor.
const interRegionModel & nbrModel() const
Get the neighbour interRegionModel.
Enum read(Istream &) const
Read a word from Istream and return the corresponding.
Definition: NamedEnum.C:61
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Namespace for OpenFOAM.