1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "threeDofMotion.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "motionSolver.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "uniformDimensionedFields.H"
34 #include "tetFemMatrices.H"
35 #include "tetPointFields.H"
36 #include "faceTetPolyPatch.H"
37 #include "fixedValueTetPolyPatchFields.H"
39 #include "incompressible/incompressibleTwoPhaseMixture/twoPhaseMixture.H"
40 #include "incompressible/RAS/RASModel/RASModel.H"
41 #include "incompressible/LES/LESModel/LESModel.H"
44 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
48 defineTypeNameAndDebug(threeDofMotion, 0);
50 addToRunTimeSelectionTable(dynamicFvMesh, threeDofMotion, IOobject);
51 } // End namespace Foam
54 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 Foam::tmp<Foam::volSymmTensorField> Foam::threeDofMotion::devRhoReff() const
58 if (this->foundObject<incompressible::RASModel>("RASProperties"))
60 const incompressible::RASModel& ras =
61 this->lookupObject<incompressible::RASModel>("RASProperties");
65 else if (this->foundObject<incompressible::LESModel>("LESProperties"))
67 const incompressible::LESModel& les =
68 this->lookupObject<incompressible::LESModel>("LESProperties");
72 else if (this->foundObject<twoPhaseMixture>("transportProperties"))
74 const twoPhaseMixture& twoPhaseProperties =
75 this->lookupObject<twoPhaseMixture>("transportProperties");
77 const volVectorField& U = this->lookupObject<volVectorField>("U");
79 return twoPhaseProperties.nu()*dev(twoSymm(fvc::grad(U)));
83 FatalErrorIn("floatingBody::devRhoReff()")
84 << "No valid model for viscous stress calculation."
87 return volSymmTensorField::null();
92 Foam::vector Foam::threeDofMotion::hullForce() const
94 const fvMesh& mesh = *this;
96 const volScalarField& alpha = mesh.lookupObject<volScalarField>("alpha1");
97 const volScalarField& p = mesh.lookupObject<volScalarField>("p");
98 const volVectorField& U = mesh.lookupObject<volVectorField>("U");
100 tmp<volSymmTensorField> tdevRhoReff = devRhoReff();
101 const volSymmTensorField::GeometricBoundaryField& devRhoReffb
102 = tdevRhoReff().boundaryField();
104 // Get index of current patch
105 const label curPatch = hullPatch_.index();
107 vector pressureForce =
110 alpha.boundaryField()[curPatch]*
111 p.boundaryField()[curPatch]*
112 mesh.Sf().boundaryField()[curPatch]
115 vector viscousForce =
118 alpha.boundaryField()[curPatch]*
119 (mesh.Sf().boundaryField()[curPatch] & devRhoReffb[curPatch])
122 vector totalForce = pressureForce + viscousForce;
124 Info<< "Pressure force = " << pressureForce << nl
125 << "Viscous force = " << viscousForce << nl
126 << "Total force = " << totalForce << endl;
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
134 Foam::threeDofMotion::threeDofMotion(const IOobject& io)
149 ).subDict(typeName + "Coeffs")
155 dict_.lookup("name"),
166 dict_.lookup("solver"),
170 epsilon_(readScalar(dict_.lookup("epsilon"))),
171 motionPtr_(motionSolver::New(*this)),
172 hullPatch_(word(dict_.lookup("hullPatchName")), boundaryMesh()),
174 oldForce_(vector::zero)
176 // Check that the hull patch has been found
177 if (!hullPatch_.active())
179 FatalErrorIn("threeDofMotion::threeDofMotion(const IOobject& io)")
180 << "Cannot find hull patch "<< hullPatch_.name() << nl
181 << "Valid patches are: " << boundaryMesh().names()
182 << abort(FatalError);
187 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
189 Foam::threeDofMotion::~threeDofMotion()
193 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
195 bool Foam::threeDofMotion::update()
198 vector curForce = hullForce();
200 const uniformDimensionedVectorField& g =
201 this->lookupObject<uniformDimensionedVectorField>("g");
203 equation_.force().value() = 0.5*(curForce + oldForce_)
204 + equation_.mass().value()*g.value();
206 if (curTimeIndex_ == -1 || curTimeIndex_ < time().timeIndex())
208 Info << "Storing current force as old force" << endl;
209 oldForce_ = curForce;
210 curTimeIndex_ = time().timeIndex();
216 time().value() + time().deltaT().value(),
218 time().deltaT().value()
221 // Set the motion onto the motion patch
222 tetPointVectorField& motionU =
223 const_cast<tetPointVectorField&>
225 this->objectRegistry::lookupObject<tetPointVectorField>("motionU")
228 fixedValueTetPolyPatchVectorField& motionUHullPatch =
229 refCast<fixedValueTetPolyPatchVectorField>
231 motionU.boundaryField()[hullPatch_.index()]
234 Info << "Boundary velocity = " << equation_.U().value() << endl;
236 motionUHullPatch == equation_.U().value();
238 fvMesh::movePoints(motionPtr_->newPoints());
240 // Mesh motion only - return false
245 // ************************************************************************* //