multiSolidBodyMotionSolver.C 4.79 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-------------------------------------------------------------------------------
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/>.

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

26
#include "multiSolidBodyMotionSolver.H"
27
28
29
30
31
32
33
34
35
36
#include "addToRunTimeSelectionTable.H"
#include "transformField.H"
#include "cellZoneMesh.H"
#include "boolList.H"
#include "syncTools.H"

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

namespace Foam
{
37
    defineTypeNameAndDebug(multiSolidBodyMotionSolver, 0);
38
39
    addToRunTimeSelectionTable
    (
40
41
42
        motionSolver,
        multiSolidBodyMotionSolver,
        dictionary
43
44
45
46
47
48
    );
}


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

49
50
51
52
53
Foam::multiSolidBodyMotionSolver::multiSolidBodyMotionSolver
(
    const polyMesh& mesh,
    const IOdictionary& dict
)
54
:
55
    points0MotionSolver(mesh, dict, typeName)
56
{
57
58
59
60
    zoneIDs_.setSize(coeffDict().size());
    SBMFs_.setSize(coeffDict().size());
    pointIDs_.setSize(coeffDict().size());
    label zonei = 0;
61

62
    forAllConstIter(dictionary, coeffDict(), iter)
63
64
65
    {
        if (iter().isDict())
        {
66
            zoneIDs_[zonei] = mesh.cellZones().findZoneID(iter().keyword());
67

68
            if (zoneIDs_[zonei] == -1)
69
            {
70
                FatalIOErrorInFunction
71
                (
72
                    coeffDict()
73
                )   << "Cannot find cellZone named " << iter().keyword()
74
                    << ". Valid zones are " << mesh.cellZones().names()
75
76
77
78
79
80
81
                    << exit(FatalIOError);
            }

            const dictionary& subDict = iter().dict();

            SBMFs_.set
            (
82
83
                zonei,
                solidBodyMotionFunction::New(subDict, mesh.time())
84
85
86
            );

            // Collect points of cell zone.
87
            const cellZone& cz = mesh.cellZones()[zoneIDs_[zonei]];
88

89
            boolList movePts(mesh.nPoints(), false);
90
91
92

            forAll(cz, i)
            {
93
                label celli = cz[i];
94
                const cell& c = mesh.cells()[celli];
95
96
                forAll(c, j)
                {
97
                    const face& f = mesh.faces()[c[j]];
98
99
                    forAll(f, k)
                    {
100
101
                        label pointi = f[k];
                        movePts[pointi] = true;
102
103
104
105
                    }
                }
            }

106
            syncTools::syncPointList(mesh, movePts, orEqOp<bool>(), false);
107

108
            DynamicList<label> ptIDs(mesh.nPoints());
109
110
111
112
113
114
115
116
            forAll(movePts, i)
            {
                if (movePts[i])
                {
                    ptIDs.append(i);
                }
            }

117
            pointIDs_[zonei].transfer(ptIDs);
118

119
            Info<< "Applying solid body motion " << SBMFs_[zonei].type()
120
121
122
                << " to "
                << returnReduce(pointIDs_[zonei].size(), sumOp<label>())
                << " points of cellZone " << iter().keyword() << endl;
123

124
            zonei++;
125
126
        }
    }
127
128
129
    zoneIDs_.setSize(zonei);
    SBMFs_.setSize(zonei);
    pointIDs_.setSize(zonei);
130
131
132
133
134
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

135
Foam::multiSolidBodyMotionSolver::~multiSolidBodyMotionSolver()
136
137
138
139
140
{}


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

141
Foam::tmp<Foam::pointField> Foam::multiSolidBodyMotionSolver::curPoints() const
142
{
143
    tmp<pointField> ttransformedPts(new pointField(mesh().points()));
144
    pointField& transformedPts = ttransformedPts.ref();
145
146
147
148
149

    forAll(zoneIDs_, i)
    {
        const labelList& zonePoints = pointIDs_[i];

150
151
152
153
154
        UIndirectList<point>(transformedPts, zonePoints) = transformPoints
        (
            SBMFs_[i].transformation(),
            pointField(points0_, zonePoints)
        );
155
156
    }

157
    return ttransformedPts;
158
159
160
161
}


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