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 #include "directMethod.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace fv
35 {
36  defineTypeNameAndDebug(interRegionModel, 0);
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_ =
48  coeffs().lookupBackwardsCompatible<word>
49  ({
50  "nbrRegion",
51  "nbrRegionName"
52  });
53 
54  coeffs().lookup("interpolationMethod") >> interpolationMethod_;
55 }
56 
57 
58 void Foam::fv::interRegionModel::setMapper() const
59 {
60  Info<< incrIndent;
61 
62  if (master_)
63  {
64  Info<< indent << "- selecting inter region mapping" << endl;
65 
66  if (mesh().name() == nbrMesh().name())
67  {
69  << "Inter-region model selected, but local and "
70  << "neighbour regions are the same: " << nl
71  << " local region: " << mesh().name() << nl
72  << " secondary region: " << nbrMesh().name() << nl
73  << exit(FatalError);
74  }
75 
76  if (mesh().bounds().overlaps(nbrMesh().bounds()))
77  {
78  meshInterpPtr_.reset
79  (
80  new meshToMesh
81  (
82  mesh(),
83  nbrMesh(),
84  interpolationMethod_,
85  false // not interpolating patches
86  )
87  );
88  }
89  else
90  {
92  << "regions " << mesh().name() << " and "
93  << nbrMesh().name() << " do not intersect"
94  << exit(FatalError);
95  }
96  }
97 
98  Info<< decrIndent;
99 }
100 
101 
103 {
104  const fvMesh& nbrMesh = mesh().time().lookupObject<fvMesh>(nbrRegionName());
105 
107  nbrMesh.lookupObject<Foam::fvModels>("fvModels");
108 
109  forAll(fvModels, fvModeli)
110  {
111  if (isA<interRegionModel>(fvModels[fvModeli]))
112  {
113  const interRegionModel& model =
114  refCast<const interRegionModel>(fvModels[fvModeli]);
115 
116  if (model.nbrRegionName() == mesh().name())
117  {
118  return model;
119  }
120  }
121  }
122 
124  << "Neighbour model not found in region " << nbrMesh.name() << nl
125  << exit(FatalError);
126  return NullObjectRef<interRegionModel>();
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
131 
133 (
134  const word& name,
135  const word& modelType,
136  const dictionary& dict,
137  const fvMesh& mesh
138 )
139 :
140  fvModel(name, modelType, dict, mesh),
141  master_(false),
142  nbrRegionName_(word::null),
143  interpolationMethod_(directMethod::typeName),
144  meshInterpPtr_()
145 {
146  readCoeffs();
147 }
148 
149 
150 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
151 
153 {}
154 
155 
156 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
157 
159 {
160  if (fvModel::read(dict))
161  {
162  readCoeffs();
163  setMapper();
164  return true;
165  }
166  else
167  {
168  return false;
169  }
170 }
171 
172 
173 // ************************************************************************* //
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:306
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Finite volume model abstract base class.
Definition: fvModel.H:57
fvMesh & mesh
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Base class for inter-region exchange.
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:386
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
messageStream Info
virtual ~interRegionModel()
Destructor.
const interRegionModel & nbrModel() const
Get the neighbour interRegionModel.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Namespace for OpenFOAM.