dynamicMultiMotionSolverFvMesh.C 5.08 KB
Newer Older
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
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7 8
-------------------------------------------------------------------------------
    Copyright (C) 2016 OpenCFD Ltd.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    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.

    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
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

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

#include "dynamicMultiMotionSolverFvMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
31
#include "bitSet.H"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include "syncTools.H"

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

namespace Foam
{
    defineTypeNameAndDebug(dynamicMultiMotionSolverFvMesh, 0);
    addToRunTimeSelectionTable
    (
        dynamicFvMesh,
        dynamicMultiMotionSolverFvMesh,
        IOobject
    );
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::dynamicMultiMotionSolverFvMesh::dynamicMultiMotionSolverFvMesh
(
    const IOobject& io
)
:
    dynamicFvMesh(io)
{
    IOdictionary dynDict
    (
        IOobject
        (
            "dynamicMeshDict",
            io.time().constant(),
            *this,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE,
            false
        )
    );
    const dictionary& dynamicMeshCoeffs = dynDict.subDict(typeName + "Coeffs");

    zoneIDs_.setSize(dynamicMeshCoeffs.size());
    motionPtr_.setSize(dynamicMeshCoeffs.size());
    pointIDs_.setSize(dynamicMeshCoeffs.size());
74 75 76 77

    label zonei = 0;

    bitSet movePts;
78

79
    for (const entry& dEntry : dynamicMeshCoeffs)
80
    {
81
        if (dEntry.isDict())
82
        {
83
            const dictionary& subDict = dEntry.dict();
84

85
            const word zoneName(subDict.get<word>("cellZone"));
86

87
            zoneIDs_[zonei] = cellZones().findZoneID(zoneName);
88

89
            if (zoneIDs_[zonei] == -1)
90
            {
91 92
                FatalIOErrorInFunction(dynamicMeshCoeffs)
                    << "Cannot find cellZone named " << zoneName
93 94 95 96 97 98 99 100 101
                    << ". Valid zones are " << cellZones().names()
                    << exit(FatalIOError);
            }

            IOobject io(dynDict);
            io.readOpt() = IOobject::NO_READ;

            motionPtr_.set
            (
102
                zonei,
103 104 105 106 107 108 109
                motionSolver::New
                (
                    *this,
                    IOdictionary(io, subDict)
                )
            );

110

111 112
            // Collect points of cell zone.

113 114
            movePts.reset();
            movePts.resize(nPoints());
115

116
            for (const label celli : cellZones()[zoneIDs_[zonei]])
117
            {
118
                for (const label facei : cells()[celli])
119
                {
120
                    movePts.set(faces()[facei]);  // set multiple points
121 122 123
                }
            }

124 125 126 127
            syncTools::syncPointList
            (
                *this, movePts, orEqOp<unsigned int>(), 0u
            );
128

129
            pointIDs_[zonei] = movePts.sortedToc();
130

131
            Info<< "Applying motionSolver " << motionPtr_[zonei].type()
132
                << " to "
133
                << returnReduce(pointIDs_[zonei].size(), sumOp<label>())
134 135
                << " points of cellZone " << zoneName << endl;

136
            ++zonei;
137 138
        }
    }
139 140 141
    zoneIDs_.setSize(zonei);
    motionPtr_.setSize(zonei);
    pointIDs_.setSize(zonei);
142 143 144 145 146 147 148 149 150
}


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

bool Foam::dynamicMultiMotionSolverFvMesh::update()
{
    pointField transformedPts(points());

151
    forAll(motionPtr_, zonei)
152
    {
153
        tmp<pointField> tnewPoints(motionPtr_[zonei].newPoints());
154 155
        const pointField& newPoints = tnewPoints();

156
        for (const label pointi : pointIDs_[zonei])
157
        {
158
            transformedPts[pointi] = newPoints[pointi];
159 160 161 162 163 164 165
        }
    }

    fvMesh::movePoints(transformedPts);

    static bool hasWarned = false;

166 167 168
    volVectorField* Uptr = getObjectPtr<volVectorField>("U");

    if (Uptr)
169
    {
170
        Uptr->correctBoundaryConditions();
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    }
    else if (!hasWarned)
    {
        hasWarned = true;

        WarningInFunction
            << "Did not find volVectorField U."
            << " Not updating U boundary conditions." << endl;
    }

    return true;
}


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