points0MotionSolver.C 6.2 KB
Newer Older
mattijs's avatar
mattijs committed
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2012-2017 OpenFOAM Foundation
9
    Copyright (C) 2015-2019 OpenCFD Ltd.
mattijs's avatar
mattijs committed
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    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.
mattijs's avatar
mattijs committed
18 19 20 21 22 23 24

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
mattijs's avatar
mattijs committed
26 27 28

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

29
#include "points0MotionSolver.H"
mattijs's avatar
mattijs committed
30 31 32 33 34 35
#include "mapPolyMesh.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
36
    defineTypeNameAndDebug(points0MotionSolver, 0);
mattijs's avatar
mattijs committed
37 38 39
}


40
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
41

42
Foam::IOobject Foam::points0MotionSolver::points0IO(const polyMesh& mesh)
43 44
{
    const word instance =
45
        mesh.time().findInstance
46 47 48 49 50 51
        (
            mesh.meshDir(),
            "points0",
            IOobject::READ_IF_PRESENT
        );

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    IOobject io
    (
        "points0",
        instance,
        polyMesh::meshSubDir,
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE,
        false
    );

    // If points0 are located in constant directory, verify their existence
    // or fallback to a copy of the original mesh points
    if
    (
        instance == mesh.time().constant()
     && !io.typeHeaderOk<pointIOField>()
    )
70
    {
71
        io.rename("points");
72 73
    }

74
    return io;
75 76 77
}


mattijs's avatar
mattijs committed
78 79
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

80
Foam::points0MotionSolver::points0MotionSolver
mattijs's avatar
mattijs committed
81 82
(
    const polyMesh& mesh,
83 84
    const IOdictionary& dict,
    const word& type
mattijs's avatar
mattijs committed
85 86
)
:
87
    motionSolver(mesh, dict, type),
88
    zoneMotion(dict, mesh),
89
    points0_(points0IO(mesh))
90
{
91 92 93 94 95 96 97 98 99
    if
    (
        FieldBase::allowConstructFromLargerSize
     && (points0_.size() > mesh.nPoints())
    )
    {
        // Allowed
    }
    else if (points0_.size() != mesh.nPoints())
100
    {
101 102
        FatalErrorInFunction
            << "Number of points in mesh " << mesh.nPoints()
103 104
            << " differs from number of points " << points0_.size()
            << " read from file "
105
            <<  typeFilePath<pointIOField>
106
                (
107 108 109 110
                    IOobject
                    (
                        "points",
                        time().constant(),
111
                        polyMesh::meshSubDir,
112 113 114 115 116 117
                        mesh,
                        IOobject::MUST_READ,
                        IOobject::NO_WRITE,
                        false
                    )
                )
118 119 120
            << exit(FatalError);
    }
}
mattijs's avatar
mattijs committed
121 122


123
Foam::points0MotionSolver::points0MotionSolver
124 125 126 127 128 129 130 131
(
    const polyMesh& mesh,
    const IOdictionary& dict,
    const pointIOField& points0,
    const word& type
)
:
    motionSolver(mesh, dict, type),
132
    zoneMotion(dict, mesh),
133 134 135 136
    points0_(points0)
{
    if (points0_.size() != mesh.nPoints())
    {
137 138
        FatalErrorInFunction
            << "Number of points in mesh " << mesh.nPoints()
139 140 141 142 143 144 145
            << " differs from number of points " << points0_.size()
            << " read from file " << points0.filePath()
            << exit(FatalError);
    }
}


mattijs's avatar
mattijs committed
146 147
// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

148
Foam::points0MotionSolver::~points0MotionSolver()
mattijs's avatar
mattijs committed
149 150 151 152 153
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

154 155
void Foam::points0MotionSolver::movePoints(const pointField&)
{}
156 157


158
void Foam::points0MotionSolver::updateMesh(const mapPolyMesh& mpm)
159
{
160
    // pointMesh already updates pointFields
161 162

    motionSolver::updateMesh(mpm);
mattijs's avatar
mattijs committed
163 164 165 166 167 168 169 170 171 172

    // Map points0_. Bit special since we somehow have to come up with
    // a sensible points0 position for introduced points.
    // Find out scaling between points0 and current points

    // Get the new points either from the map or the mesh
    const pointField& points =
    (
        mpm.hasMotionPoints()
      ? mpm.preMotionPoints()
173
      : mesh().points()
mattijs's avatar
mattijs committed
174 175 176 177
    );

    // Note: boundBox does reduce
    const vector span0 = boundBox(points0_).span();
178
    const vector span = boundBox(points).span();
mattijs's avatar
mattijs committed
179 180 181 182 183

    vector scaleFactors(cmptDivide(span0, span));

    pointField newPoints0(mpm.pointMap().size());

184
    forAll(newPoints0, pointi)
mattijs's avatar
mattijs committed
185
    {
186
        label oldPointi = mpm.pointMap()[pointi];
mattijs's avatar
mattijs committed
187

188
        if (oldPointi >= 0)
mattijs's avatar
mattijs committed
189
        {
190
            label masterPointi = mpm.reversePointMap()[oldPointi];
mattijs's avatar
mattijs committed
191

192
            if (masterPointi == pointi)
mattijs's avatar
mattijs committed
193
            {
194
                newPoints0[pointi] = points0_[oldPointi];
mattijs's avatar
mattijs committed
195 196 197
            }
            else
            {
198
                // New point - assume motion is scaling
199
                newPoints0[pointi] = points0_[oldPointi] + cmptMultiply
mattijs's avatar
mattijs committed
200 201
                (
                    scaleFactors,
202
                    points[pointi] - points[masterPointi]
mattijs's avatar
mattijs committed
203 204 205 206 207
                );
            }
        }
        else
        {
208
            FatalErrorInFunction
209 210
                << "Cannot determine coordinates of introduced vertices."
                << " New vertex " << pointi << " at coordinate "
211
                << points[pointi] << exit(FatalError);
mattijs's avatar
mattijs committed
212 213
        }
    }
214 215 216

    twoDCorrectPoints(newPoints0);

mattijs's avatar
mattijs committed
217
    points0_.transfer(newPoints0);
218 219 220 221 222 223

    // points0 changed - set to write and check-in to database
    points0_.rename("points0");
    points0_.writeOpt() = IOobject::AUTO_WRITE;
    points0_.instance() = time().timeName();
    points0_.checkIn();
mattijs's avatar
mattijs committed
224 225 226 227
}


// ************************************************************************* //