1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "coordinateModifier.H"
32 void coordinateModifier::checkForValidInverse() const
34 if( modifiers_.size() > 1 )
36 //- the if the modifiers allow combinations
37 forAll(modifiers_, modI)
38 if( !modifiers_[modI].combiningPossible() )
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);
48 //- check if the modifications overlap
49 forAll(modifiers_, modI)
51 PtrList<plane> bndPlanes;
52 modifiers_[modI].boundingPlanes(bndPlanes);
54 # ifdef DEBUGCoordinateModifier
55 Info << "Checking planes for object " << modifiers_[modI].name()
56 << " which are " << bndPlanes << endl;
59 for(label modJ=modI+1;modJ<modifiers_.size();++modJ)
61 PtrList<plane> otherBndPlanes;
62 modifiers_[modJ].boundingPlanes(otherBndPlanes);
64 # ifdef DEBUGCoordinateModifier
65 Info << "Bnd planes planes for " << modifiers_[modJ].name()
66 << " are " << otherBndPlanes << endl;
69 for(label i=0;i<bndPlanes.size();i+=2)
71 const plane& pl = bndPlanes[i];
73 for(label j=0;j<otherBndPlanes.size();j+=2)
75 const plane& opl = otherBndPlanes[j];
77 const scalar dn = mag(pl.normal() & opl.normal());
80 if( dn < (1.0 - SMALL) )
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!"
95 //- check if the scaling regions overlap
98 bndPlanes[i+1].refPoint() -
104 otherBndPlanes[j].refPoint() -
110 otherBndPlanes[j+1].refPoint() -
114 # ifdef DEBUGCoordinateModifier
115 Info << "tMax " << tMax << endl;
116 Info << "t0 " << t0 << endl;
117 Info << "t1 " << t1 << endl;
120 //- check if the intervals overlap
121 if( (t1 >= 0) && (t0 < tMax) )
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!"
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
146 coordinateModifier::coordinateModifier(const dictionary& geomModDict)
148 modificationDict_(geomModDict),
152 const wordList modifiers = modificationDict_.toc();
154 //- setup modification
155 modifiers_.setSize(modifiers.size());
156 backwardModifiers_.setSize(modifiers.size());
157 forAll(modifiers, modI)
159 const word& mName = modifiers[modI];
160 const dictionary& modDict = modificationDict_.subDict(mName);
161 modifiers_.set(modI, coordinateModification::New(mName, modDict));
163 backwardModifiers_.set
166 coordinateModification::New(mName, modDict)
170 //- setup backward modification
171 forAll(backwardModifiers_, modI)
173 vector disp(vector::zero);
174 const point pOrigin = backwardModifiers_[modI].origin();
176 forAll(modifiers_, i)
177 disp += modifiers_[i].displacement(pOrigin);
179 backwardModifiers_[modI].translateAndModifyObject(disp);
182 checkForValidInverse();
185 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
187 coordinateModifier::~coordinateModifier()
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
193 point coordinateModifier::modifiedPoint(const point& p) const
197 forAll(modifiers_, modI)
199 pNew += modifiers_[modI].displacement(p);
205 point coordinateModifier::backwardModifiedPoint(const point& p) const
209 forAll(backwardModifiers_, modI)
210 pNew += backwardModifiers_[modI].backwardDisplacement(p);
215 void coordinateModifier::printObjects() const
217 Info << "Modification objects " << modifiers_ << endl;
219 Info << "Backward modification objects " << backwardModifiers_ << endl;
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 } // End namespace Foam
226 // ************************************************************************* //