coordinateModifier.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "coordinateModifier.H"
27 #include "plane.H"
28 
29 namespace Foam
30 {
31 
33 {
34  if( modifiers_.size() > 1 )
35  {
36  //- the if the modifiers allow combinations
37  forAll(modifiers_, modI)
38  if( !modifiers_[modI].combiningPossible() )
39  {
41  (
42  "void coordinateModifier::checkForValidInverse() const"
43  ) << modifiers_[modI].name() << " cannot be combined with"
44  << " other anisotropic sources. The operation"
45  << " cannot be reverted!" << exit(FatalError);
46  }
47 
48  //- check if the modifications overlap
49  forAll(modifiers_, modI)
50  {
51  PtrList<plane> bndPlanes;
52  modifiers_[modI].boundingPlanes(bndPlanes);
53 
54  # ifdef DEBUGCoordinateModifier
55  Info << "Checking planes for object " << modifiers_[modI].name()
56  << " which are " << bndPlanes << endl;
57  # endif
58 
59  for(label modJ=modI+1;modJ<modifiers_.size();++modJ)
60  {
61  PtrList<plane> otherBndPlanes;
62  modifiers_[modJ].boundingPlanes(otherBndPlanes);
63 
64  # ifdef DEBUGCoordinateModifier
65  Info << "Bnd planes planes for " << modifiers_[modJ].name()
66  << " are " << otherBndPlanes << endl;
67  # endif
68 
69  for(label i=0;i<bndPlanes.size();i+=2)
70  {
71  const plane& pl = bndPlanes[i];
72 
73  for(label j=0;j<otherBndPlanes.size();j+=2)
74  {
75  const plane& opl = otherBndPlanes[j];
76 
77  const scalar dn = mag(pl.normal() & opl.normal());
78  if( dn > SMALL )
79  {
80  if( dn < (1.0 - SMALL) )
81  {
83  (
84  "void coordinateModifier::"
85  "checkForValidInverse() const"
86  ) << "Bounding planes of the objects "
87  << modifiers_[modI].name()
88  << " and " << modifiers_[modJ].name()
89  << " are not parallel. This combination of"
90  << " modifications cannot be reverted!"
91  << exit(FatalError);
92  }
93  else
94  {
95  //- check if the scaling regions overlap
96  const scalar tMax =
97  (
98  bndPlanes[i+1].refPoint() -
99  pl.refPoint()
100  ) & pl.normal();
101 
102  const scalar t0 =
103  (
104  otherBndPlanes[j].refPoint() -
105  pl.refPoint()
106  ) & pl.normal();
107 
108  const scalar t1 =
109  (
110  otherBndPlanes[j+1].refPoint() -
111  pl.refPoint()
112  ) & pl.normal();
113 
114  # ifdef DEBUGCoordinateModifier
115  Info << "tMax " << tMax << endl;
116  Info << "t0 " << t0 << endl;
117  Info << "t1 " << t1 << endl;
118  # endif
119 
120  //- check if the intervals overlap
121  if( (t1 >= 0) && (t0 < tMax) )
122  {
124  (
125  "void coordinateModifier::"
126  "checkForValidInverse() const"
127  ) << "Scaling regions of objects "
128  << modifiers_[modI].name()
129  << " and " << modifiers_[modJ].name()
130  << " are overlapping each other."
131  << " This combination of"
132  << " modifications cannot be reverted!"
133  << exit(FatalError);
134  }
135  }
136  }
137  }
138  }
139  }
140  }
141  }
142 }
143 
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
145 
147 :
148  modificationDict_(geomModDict),
149  modifiers_(),
150  backwardModifiers_()
151 {
152  const wordList modifiers = modificationDict_.toc();
153 
154  //- setup modification
155  modifiers_.setSize(modifiers.size());
156  backwardModifiers_.setSize(modifiers.size());
157  forAll(modifiers, modI)
158  {
159  const word& mName = modifiers[modI];
160  const dictionary& modDict = modificationDict_.subDict(mName);
161  modifiers_.set(modI, coordinateModification::New(mName, modDict));
162 
164  (
165  modI,
166  coordinateModification::New(mName, modDict)
167  );
168  }
169 
170  //- setup backward modification
172  {
173  vector disp(vector::zero);
174  const point pOrigin = backwardModifiers_[modI].origin();
175 
176  forAll(modifiers_, i)
177  disp += modifiers_[i].displacement(pOrigin);
178 
179  backwardModifiers_[modI].translateAndModifyObject(disp);
180  }
181 
183 }
184 
185 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
186 
188 {}
189 
190 
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 
194 {
195  point pNew = p;
196 
197  forAll(modifiers_, modI)
198  {
199  pNew += modifiers_[modI].displacement(p);
200  }
201 
202  return pNew;
203 }
204 
206 {
207  point pNew = p;
208 
210  pNew += backwardModifiers_[modI].backwardDisplacement(p);
211 
212  return pNew;
213 }
214 
216 {
217  Info << "Modification objects " << modifiers_ << endl;
218 
219  Info << "Backward modification objects " << backwardModifiers_ << endl;
220 }
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 } // End namespace Foam
225 
226 // ************************************************************************* //
Foam::plane::normal
const vector & normal() const
Return plane normal.
Definition: plane.C:248
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::coordinateModifier::modifiedPoint
point modifiedPoint(const point &) const
calculate the modified coordinate of the point
Definition: coordinateModifier.C:193
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::coordinateModification::New
static autoPtr< coordinateModification > New(const word &name, const dictionary &dict)
Select constructed from dictionary.
Definition: newCoordinateModification.C:38
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::coordinateModifier::modifiers_
coordinateModificationList modifiers_
list of coordinate modification objects
Definition: coordinateModifier.H:62
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Foam::PtrList::set
bool set(const label) const
Is element set.
Foam::label
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
Foam::coordinateModifier::coordinateModifier
coordinateModifier(const dictionary &)
Construct from dictionary.
Definition: coordinateModifier.C:146
plane.H
Foam::Info
messageStream Info
coordinateModifier.H
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::coordinateModifier::backwardModifiers_
coordinateModificationList backwardModifiers_
list of backward coordinate modifiers
Definition: coordinateModifier.H:65
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::coordinateModifier::modificationDict_
const dictionary & modificationDict_
Reference to dictionary.
Definition: coordinateModifier.H:59
Foam::coordinateModifier::checkForValidInverse
void checkForValidInverse() const
check if the comibination of modifiers has a valid inverse
Definition: coordinateModifier.C:32
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::plane::refPoint
const point & refPoint() const
Return or return plane base point.
Definition: plane.C:255
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::PtrList::setSize
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:142
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::coordinateModifier::backwardModifiedPoint
point backwardModifiedPoint(const point &) const
calculate the displacement vector for the backward modification
Definition: coordinateModifier.C:205
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::coordinateModifier::printObjects
void printObjects() const
Print modification objects.
Definition: coordinateModifier.C:215
Foam::coordinateModifier::~coordinateModifier
~coordinateModifier()
Definition: coordinateModifier.C:187