mappedPatchBaseBaseTemplates.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-2024 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 "mappedPatchBaseBase.H"
27 #include "stringOps.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class PatchFieldType, class FieldType>
33 (
34  const PatchFieldType& field,
35  const FieldType& iF,
36  const dictionary& context,
37  const label froms
38 )
39 {
40  const polyPatch& pp = field.patch().patch();
41 
42  if (!isA<mappedPatchBaseBase>(pp))
43  {
44  OStringStream str;
45  str << "Field " << iF.name() << " of type "
46  << field.type() << " cannot apply to patch " << pp.name()
47  << " of type " << pp.type()
48  << ", which should be a " << typeName << " type";
49  FatalIOErrorInFunction(context)
50  << stringOps::breakIntoIndentedLines(str.str()).c_str()
51  << exit(FatalIOError);
52  }
53 
54  refCast<const mappedPatchBaseBase>(pp).validateForField
55  (
56  field,
57  iF,
58  context,
59  froms
60  );
61 }
62 
63 
64 template<class PatchFieldType, class FieldType>
66 (
67  const PatchFieldType& field,
68  const FieldType& iF,
69  const dictionary& context,
70  const label froms
71 ) const
72 {
73  const bool isNotRegion = !sameRegion() && (froms & from::sameRegion);
74  const bool isRegion = sameRegion() && (froms & from::differentRegion);
75  const bool isPatch = samePatch() && (froms & from::differentPatch);
76 
77  OStringStream str;
78 
79  if (isNotRegion || isRegion || isPatch)
80  {
81  str << "Field " << iF.name() << " of type "
82  << field.type() << " cannot apply to patch " << patch_.name()
83  << " because values are mapped from ";
84  }
85 
86  if (isNotRegion)
87  {
88  str << "a different region";
89  }
90  else if (isRegion)
91  {
92  str << "within the same region";
93  }
94  else if (isPatch)
95  {
96  str << "the same patch";
97  }
98 
99  if (isNotRegion || isRegion || isPatch)
100  {
101  FatalIOErrorInFunction(context)
102  << stringOps::breakIntoIndentedLines(str.str()).c_str()
103  << exit(FatalIOError);
104  }
105 }
106 
107 
108 // ************************************************************************* //
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:85
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
fileType type(const bool checkVariants=true, const bool followLink=true) const
Return the file type: file, directory, undefined or.
Definition: fileName.C:52
void validateForField(const PatchField &field, const FieldType &iF, const dictionary &context, const label froms=from::any) const
Validate that the map is appropriate for the given.
static void validateMapForField(const PatchField &field, const FieldType &iF, const dictionary &context, const label froms=from::any)
Validate that the map exists and is appropriate for the given.
const word & name() const
Return name.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
string breakIntoIndentedLines(const string &str, const string::size_type nLength=80, const string::size_type nIndent=0)
Break a string up into indented lines.
Definition: stringOps.C:963
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
IOerror FatalIOError