Forward compatibility: flex
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / anisotropicMeshing / coordinateModification / coordinateModifier.C
blobb548e4ed9b7439bc25e9913bfbdc4a801102c281
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.
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
19     for more details.
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"
27 #include "plane.H"
29 namespace Foam
32 void coordinateModifier::checkForValidInverse() const
34     if( modifiers_.size() > 1 )
35     {
36         //- the if the modifiers allow combinations
37         forAll(modifiers_, modI)
38             if( !modifiers_[modI].combiningPossible() )
39             {
40                 FatalErrorIn
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             }
48         //- check if the modifications overlap
49         forAll(modifiers_, modI)
50         {
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;
57             # endif
59             for(label modJ=modI+1;modJ<modifiers_.size();++modJ)
60             {
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;
67                 # endif
69                 for(label i=0;i<bndPlanes.size();i+=2)
70                 {
71                     const plane& pl = bndPlanes[i];
73                     for(label j=0;j<otherBndPlanes.size();j+=2)
74                     {
75                         const plane& opl = otherBndPlanes[j];
77                         const scalar dn = mag(pl.normal() & opl.normal());
78                         if( dn > SMALL )
79                         {
80                             if( dn < (1.0 - SMALL) )
81                             {
82                                 FatalErrorIn
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();
102                                 const scalar t0 =
103                                     (
104                                         otherBndPlanes[j].refPoint() -
105                                         pl.refPoint()
106                                     ) & pl.normal();
108                                 const scalar t1 =
109                                     (
110                                         otherBndPlanes[j+1].refPoint() -
111                                         pl.refPoint()
112                                     ) & pl.normal();
114                                 # ifdef DEBUGCoordinateModifier
115                                 Info << "tMax " << tMax << endl;
116                                 Info << "t0 " << t0 << endl;
117                                 Info << "t1 " << t1 << endl;
118                                 # endif
120                                 //- check if the intervals overlap
121                                 if( (t1 >= 0) && (t0 < tMax) )
122                                 {
123                                     FatalErrorIn
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     }
144 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
146 coordinateModifier::coordinateModifier(const dictionary& geomModDict)
148     modificationDict_(geomModDict),
149     modifiers_(),
150     backwardModifiers_()
152     const wordList modifiers = modificationDict_.toc();
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));
163         backwardModifiers_.set
164         (
165             modI,
166             coordinateModification::New(mName, modDict)
167         );
168     }
170     //- setup backward modification
171     forAll(backwardModifiers_, modI)
172     {
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);
180     }
182     checkForValidInverse();
185 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
187 coordinateModifier::~coordinateModifier()
191 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
193 point coordinateModifier::modifiedPoint(const point& p) const
195     point pNew = p;
197     forAll(modifiers_, modI)
198     {
199         pNew += modifiers_[modI].displacement(p);
200     }
202     return pNew;
205 point coordinateModifier::backwardModifiedPoint(const point& p) const
207     point pNew = p;
209     forAll(backwardModifiers_, modI)
210         pNew += backwardModifiers_[modI].backwardDisplacement(p);
212     return pNew;
215 void coordinateModifier::printObjects() const
217     Info << "Modification objects " << modifiers_ << endl;
219     Info << "Backward modification objects " << backwardModifiers_ << endl;
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 } // End namespace Foam
226 // ************************************************************************* //