contactAngleForce.C 5.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011-2011 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
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 "contactAngleForce.H"
#include "addToRunTimeSelectionTable.H"
#include "fvcGrad.H"
#include "unitConversion.H"
andy's avatar
andy committed
30
#include "fvPatchField.H"
31
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

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

namespace Foam
{
namespace regionModels
{
namespace surfaceFilmModels
{

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

defineTypeNameAndDebug(contactAngleForce, 0);
addToRunTimeSelectionTable(force, contactAngleForce, dictionary);

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

contactAngleForce::contactAngleForce
(
    const surfaceFilmModel& owner,
    const dictionary& dict
)
:
    force(typeName, owner, dict),
    deltaWet_(readScalar(coeffs_.lookup("deltaWet"))),
    Ccf_(readScalar(coeffs_.lookup("Ccf"))),
    rndGen_(label(0), -1),
    distribution_
    (
        distributionModels::distributionModel::New
        (
            coeffs_.subDict("contactAngleDistribution"),
            rndGen_
        )
    )
{}


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

contactAngleForce::~contactAngleForce()
{}


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

tmp<fvVectorMatrix> contactAngleForce::correct(volVectorField& U)
{
    tmp<volVectorField> tForce
    (
        new volVectorField
        (
            IOobject
            (
                "contactForce",
                owner_.time().timeName(),
                owner_.regionMesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            owner_.regionMesh(),
            dimensionedVector("zero", dimForce/dimArea, vector::zero)
        )
    );

    vectorField& force = tForce().internalField();

    const labelUList& own = owner_.regionMesh().owner();
    const labelUList& nbr = owner_.regionMesh().neighbour();

    const scalarField& magSf = owner_.magSf();

    const volScalarField& delta = owner_.delta();
    const volScalarField& sigma = owner_.sigma();

    volScalarField alpha
    (
        "alpha",
        pos(delta - dimensionedScalar("deltaWet", dimLength, deltaWet_))
    );
    volVectorField gradAlpha(fvc::grad(alpha));

andy's avatar
andy committed
113
114

    scalarField nHits(owner_.regionMesh().nCells(), 0.0);
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

    forAll(nbr, faceI)
    {
        const label cellO = own[faceI];
        const label cellN = nbr[faceI];

        label cellI = -1;
        if ((delta[cellO] > deltaWet_) && (delta[cellN] < deltaWet_))
        {
            cellI = cellO;
        }
        else if ((delta[cellO] < deltaWet_) && (delta[cellN] > deltaWet_))
        {
            cellI = cellN;
        }

        if (cellI != -1)
        {
//            const scalar dx = Foam::sqrt(magSf[cellI]);
andy's avatar
andy committed
134
            // bit of a cheat, but ok for regular meshes
135
136
137
138
139
140
141
142
143
            const scalar dx = owner_.regionMesh().deltaCoeffs()[faceI];
            const vector n =
                gradAlpha[cellI]/(mag(gradAlpha[cellI]) + ROOTVSMALL);
            scalar theta = cos(degToRad(distribution_->sample()));
            force[cellI] += Ccf_*n*sigma[cellI]*(1.0 - theta)/dx;
            nHits[cellI]++;
        }
    }

andy's avatar
andy committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    forAll(delta.boundaryField(), patchI)
    {
        const fvPatchField<scalar>& df = delta.boundaryField()[patchI];
        const scalarField& dx = df.patch().deltaCoeffs();
        const labelUList& faceCells = df.patch().faceCells();

        forAll(df, faceI)
        {
            label cellO = faceCells[faceI];

            if ((delta[cellO] > deltaWet_) && (df[faceI] < deltaWet_))
            {
                const vector n =
                    gradAlpha[cellO]/(mag(gradAlpha[cellO]) + ROOTVSMALL);
                scalar theta = cos(degToRad(distribution_->sample()));
                force[cellO] += Ccf_*n*sigma[cellO]*(1.0 - theta)/dx[faceI];
                nHits[cellO]++;
            }
        }
    }

    force /= (max(nHits, 1.0)*magSf);
    tForce().correctBoundaryConditions();
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

    if (owner_.regionMesh().time().outputTime())
    {
        tForce().write();
    }

    tmp<fvVectorMatrix>
        tfvm(new fvVectorMatrix(U, dimForce/dimArea*dimVolume));

    tfvm() += tForce;

    return tfvm;
}


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

} // End namespace surfaceFilmModels
} // End namespace regionModels
} // End namespace Foam

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