coordinateModifier.C 7.65 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | cfMesh: A library for mesh generation
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5 6
    \\  /    A nd           | www.cfmesh.com
     \\/     M anipulation  |
7
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8 9 10 11 12
    Copyright (C) 2014-2017 Creative Fields, Ltd.
-------------------------------------------------------------------------------
Author
     Franjo Juretic (franjo.juretic@c-fields.com)

13
License
Andrew Heather's avatar
Andrew Heather committed
14
    This file is part of OpenFOAM.
15

Andrew Heather's avatar
Andrew Heather committed
16 17 18 19
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
20

Andrew Heather's avatar
Andrew Heather committed
21
    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
22 23 24 25 26
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
Andrew Heather's avatar
Andrew Heather committed
27
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
28 29 30 31

\*---------------------------------------------------------------------------*/

#include "coordinateModifier.H"
32
#include "plane.H"
33

34
void Foam::Module::coordinateModifier::checkForValidInverse() const
35
{
Andrew Heather's avatar
Andrew Heather committed
36
    if (modifiers_.size() > 1)
37
    {
Andrew Heather's avatar
Andrew Heather committed
38
        // the if the modifiers allow combinations
39
        forAll(modifiers_, modI)
Andrew Heather's avatar
Andrew Heather committed
40
            if (!modifiers_[modI].combiningPossible())
41
            {
Andrew Heather's avatar
Andrew Heather committed
42 43 44 45
                FatalErrorInFunction
                    << modifiers_[modI].name() << " cannot be combined with"
                    << " other anisotropic sources. The operation"
                    << " cannot be reverted!" << exit(FatalError);
46 47
            }

Andrew Heather's avatar
Andrew Heather committed
48
        // check if the modifications overlap
49 50 51 52 53 54
        forAll(modifiers_, modI)
        {
            PtrList<plane> bndPlanes;
            modifiers_[modI].boundingPlanes(bndPlanes);

            # ifdef DEBUGCoordinateModifier
Andrew Heather's avatar
Andrew Heather committed
55 56
            Info<< "Checking planes for object " << modifiers_[modI].name()
                << " which are " << bndPlanes << endl;
57 58
            # endif

Andrew Heather's avatar
Andrew Heather committed
59
            for (label modJ = modI + 1; modJ < modifiers_.size(); ++modJ)
60 61 62 63 64
            {
                PtrList<plane> otherBndPlanes;
                modifiers_[modJ].boundingPlanes(otherBndPlanes);

                # ifdef DEBUGCoordinateModifier
Andrew Heather's avatar
Andrew Heather committed
65 66
                Info<< "Bnd planes planes for " << modifiers_[modJ].name()
                    << " are " << otherBndPlanes << endl;
67 68
                # endif

Andrew Heather's avatar
Andrew Heather committed
69
                for (label i = 0; i < bndPlanes.size(); i += 2)
70 71 72
                {
                    const plane& pl = bndPlanes[i];

Andrew Heather's avatar
Andrew Heather committed
73
                    for (label j = 0; j < otherBndPlanes.size(); j += 2)
74 75 76 77
                    {
                        const plane& opl = otherBndPlanes[j];

                        const scalar dn = mag(pl.normal() & opl.normal());
Andrew Heather's avatar
Andrew Heather committed
78
                        if (dn > SMALL)
79
                        {
Andrew Heather's avatar
Andrew Heather committed
80
                            if (dn <(1.0 - SMALL))
81
                            {
Andrew Heather's avatar
Andrew Heather committed
82 83 84 85 86 87 88
                                FatalErrorInFunction
                                    << "Bounding planes of the objects "
                                    << modifiers_[modI].name()
                                    << " and " << modifiers_[modJ].name()
                                    << " are not parallel. This combination of"
                                    << " modifications cannot be reverted!"
                                    << exit(FatalError);
89 90 91
                            }
                            else
                            {
Andrew Heather's avatar
Andrew Heather committed
92
                                // check if the scaling regions overlap
93 94
                                const scalar tMax =
                                    (
Andrew Heather's avatar
Andrew Heather committed
95
                                        bndPlanes[i + 1].refPoint() -
96 97 98 99 100 101 102 103 104 105 106
                                        pl.refPoint()
                                    ) & pl.normal();

                                const scalar t0 =
                                    (
                                        otherBndPlanes[j].refPoint() -
                                        pl.refPoint()
                                    ) & pl.normal();

                                const scalar t1 =
                                    (
Andrew Heather's avatar
Andrew Heather committed
107
                                        otherBndPlanes[j + 1].refPoint() -
108 109 110 111
                                        pl.refPoint()
                                    ) & pl.normal();

                                # ifdef DEBUGCoordinateModifier
Andrew Heather's avatar
Andrew Heather committed
112 113 114
                                Info<< "tMax " << tMax << endl;
                                Info<< "t0 " << t0 << endl;
                                Info<< "t1 " << t1 << endl;
115 116
                                # endif

Andrew Heather's avatar
Andrew Heather committed
117 118
                                // check if the intervals overlap
                                if ((t1 >= 0) && (t0 < tMax))
119
                                {
Andrew Heather's avatar
Andrew Heather committed
120 121 122 123 124 125 126 127
                                    FatalErrorInFunction
                                        << "Scaling regions of objects "
                                        << modifiers_[modI].name()
                                        << " and " << modifiers_[modJ].name()
                                        << " are overlapping each other."
                                        << " This combination of"
                                        << " modifications cannot be reverted!"
                                        << exit(FatalError);
128 129 130 131 132 133 134 135 136 137
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Andrew Heather's avatar
Andrew Heather committed
138

139 140
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

141 142 143 144
Foam::Module::coordinateModifier::coordinateModifier
(
    const dictionary& geomModDict
)
145 146 147 148 149 150 151
:
    modificationDict_(geomModDict),
    modifiers_(),
    backwardModifiers_()
{
    const wordList modifiers = modificationDict_.toc();

Andrew Heather's avatar
Andrew Heather committed
152
    // setup modification
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    modifiers_.setSize(modifiers.size());
    backwardModifiers_.setSize(modifiers.size());
    forAll(modifiers, modI)
    {
        const word& mName = modifiers[modI];
        const dictionary& modDict = modificationDict_.subDict(mName);
        modifiers_.set(modI, coordinateModification::New(mName, modDict));

        backwardModifiers_.set
        (
            modI,
            coordinateModification::New(mName, modDict)
        );
    }

Andrew Heather's avatar
Andrew Heather committed
168
    // setup backward modification
169 170 171 172 173 174
    forAll(backwardModifiers_, modI)
    {
        vector disp(vector::zero);
        const point pOrigin = backwardModifiers_[modI].origin();

        forAll(modifiers_, i)
Andrew Heather's avatar
Andrew Heather committed
175
        {
176
            disp += modifiers_[i].displacement(pOrigin);
Andrew Heather's avatar
Andrew Heather committed
177
        }
178 179 180

        backwardModifiers_[modI].translateAndModifyObject(disp);
    }
181 182

    checkForValidInverse();
183 184
}

Andrew Heather's avatar
Andrew Heather committed
185

186 187
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

188 189 190 191
Foam::point Foam::Module::coordinateModifier::modifiedPoint
(
    const point& p
) const
192 193 194 195
{
    point pNew = p;

    forAll(modifiers_, modI)
196
    {
197
        pNew += modifiers_[modI].displacement(p);
198
    }
199 200 201 202

    return pNew;
}

Andrew Heather's avatar
Andrew Heather committed
203

204 205 206 207
Foam::point Foam::Module::coordinateModifier::backwardModifiedPoint
(
    const point& p
) const
208 209 210 211
{
    point pNew = p;

    forAll(backwardModifiers_, modI)
Andrew Heather's avatar
Andrew Heather committed
212
    {
213
        pNew += backwardModifiers_[modI].backwardDisplacement(p);
Andrew Heather's avatar
Andrew Heather committed
214
    }
215 216 217 218

    return pNew;
}

Andrew Heather's avatar
Andrew Heather committed
219

220
void Foam::Module::coordinateModifier::printObjects() const
221
{
Andrew Heather's avatar
Andrew Heather committed
222
    Info<< "Modification objects " << modifiers_ << endl;
223

Andrew Heather's avatar
Andrew Heather committed
224
    Info<< "Backward modification objects " << backwardModifiers_ << endl;
225 226
}

Andrew Heather's avatar
Andrew Heather committed
227

228
// ************************************************************************* //