dynamicMotionSolverListFvMesh.C 4.33 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
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2016 OpenFOAM Foundation
9
    Copyright (C) 2019-2021 OpenCFD Ltd.
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.
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/>.
26
27
28

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

29
30
31
#include "dynamicMotionSolverListFvMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "motionSolver.H"
32
#include "pointMesh.H"
33
#include "volFields.H"
34
35
36
37
38

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

namespace Foam
{
39
40
41
42
43
44
45
    defineTypeNameAndDebug(dynamicMotionSolverListFvMesh, 0);
    addToRunTimeSelectionTable
    (
        dynamicFvMesh,
        dynamicMotionSolverListFvMesh,
        IOobject
    );
46
47
48
49
50
51
    addToRunTimeSelectionTable
    (
        dynamicFvMesh,
        dynamicMotionSolverListFvMesh,
        doInit
    );
52
53
54
55
56
}


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

57
Foam::dynamicMotionSolverListFvMesh::dynamicMotionSolverListFvMesh
58
(
59
60
    const IOobject& io,
    const bool doInit
61
)
62
:
63
    dynamicFvMesh(io, doInit),
64
65
    motionSolvers_()
{
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    if (doInit)
    {
        init(false);    // do not initialise lower levels
    }
}


bool Foam::dynamicMotionSolverListFvMesh::init(const bool doInit)
{
    if (doInit)
    {
        dynamicFvMesh::init(doInit);
    }

80
    IOobject ioDict
81
    (
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
        "dynamicMeshDict",
        time().constant(),
        *this,
        IOobject::MUST_READ,
        IOobject::NO_WRITE,
        false
    );

    IOdictionary dict(ioDict);

    label i = 0;
    if (dict.found("solvers"))
    {
        const dictionary& solvertDict = dict.subDict("solvers");

        motionSolvers_.setSize(solvertDict.size());

        for (const entry& dEntry : solvertDict)
        {
            if (dEntry.isDict())
            {
                IOobject io(ioDict);
104
105
                io.readOpt(IOobject::NO_READ);
                io.writeOpt(IOobject::AUTO_WRITE);
106
107
108
109
110
111
112
113
114
115
116
                io.rename(dEntry.dict().dictName());

                IOdictionary IOsolverDict
                (
                    io,
                    dEntry.dict()
                );

                motionSolvers_.set
                (
                    i++,
117
                    motionSolver::New(*this, IOsolverDict)
118
119
120
121
122
123
124
125
126
127
                );
            }
        }
        motionSolvers_.setSize(i);
    }
    else
    {
        motionSolvers_.setSize(1);
        motionSolvers_.set(i++, motionSolver::New(*this));
    }
128
129
130

    // Assume something changed
    return true;
131
}
132
133
134
135


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

136
Foam::dynamicMotionSolverListFvMesh::~dynamicMotionSolverListFvMesh()
137
138
139
140
141
{}


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

142
bool Foam::dynamicMotionSolverListFvMesh::update()
143
{
144
    if (motionSolvers_.size())
145
    {
146
147
        // Accumulated displacement
        pointField disp(motionSolvers_[0].newPoints() - fvMesh::points());
148

149
150
151
152
153
154
155
        for (label i = 1; i < motionSolvers_.size(); i++)
        {
            disp += motionSolvers_[i].newPoints() - fvMesh::points();
        }

        fvMesh::movePoints(points() + disp);

156
157
158
        volVectorField* Uptr = getObjectPtr<volVectorField>("U");

        if (Uptr)
159
        {
160
            Uptr->correctBoundaryConditions();
161
        }
162
163
164
    }

    return true;
165
166
167
168
}


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