1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 "skewCorrectionVectors.H"
28 #include "surfaceFields.H"
29 #include "volFields.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(skewCorrectionVectors, 0);
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 Foam::skewCorrectionVectors::skewCorrectionVectors(const fvMesh& mesh)
43 MeshObject<fvMesh, skewCorrectionVectors>(mesh),
45 skewCorrectionVectors_(NULL)
49 Foam::skewCorrectionVectors::~skewCorrectionVectors()
51 deleteDemandDrivenData(skewCorrectionVectors_);
55 void Foam::skewCorrectionVectors::makeSkewCorrectionVectors() const
59 Info<< "surfaceInterpolation::makeSkewCorrectionVectors() : "
60 << "Constructing skew correction vectors"
64 skewCorrectionVectors_ = new surfaceVectorField
68 "skewCorrectionVectors",
69 mesh_.pointsInstance(),
78 surfaceVectorField& SkewCorrVecs = *skewCorrectionVectors_;
80 // Set local references to mesh data
81 const volVectorField& C = mesh_.C();
82 const surfaceVectorField& Cf = mesh_.Cf();
83 const surfaceVectorField& Sf = mesh_.Sf();
85 const unallocLabelList& owner = mesh_.owner();
87 // Build the d-vectors
88 surfaceVectorField d = Sf/(mesh_.magSf()*mesh_.deltaCoeffs());
90 if (!mesh_.orthogonal())
92 d -= mesh_.correctionVectors()/mesh_.deltaCoeffs();
97 vector Cpf = Cf[faceI] - C[owner[faceI]];
100 Cpf - ((Sf[faceI] & Cpf)/(Sf[faceI] & d[faceI]))*d[faceI];
104 forAll(SkewCorrVecs.boundaryField(), patchI)
106 fvsPatchVectorField& patchSkewCorrVecs =
107 SkewCorrVecs.boundaryField()[patchI];
109 if (!patchSkewCorrVecs.coupled())
111 patchSkewCorrVecs = vector::zero;
115 const fvPatch& p = patchSkewCorrVecs.patch();
116 const unallocLabelList& faceCells = p.faceCells();
117 const vectorField& patchFaceCentres = Cf.boundaryField()[patchI];
118 const vectorField& patchSf = Sf.boundaryField()[patchI];
119 const vectorField& patchD = d.boundaryField()[patchI];
121 forAll(p, patchFaceI)
124 patchFaceCentres[patchFaceI] - C[faceCells[patchFaceI]];
126 patchSkewCorrVecs[patchFaceI] =
129 (patchSf[patchFaceI] & Cpf)/
130 (patchSf[patchFaceI] & patchD[patchFaceI])
131 )*patchD[patchFaceI];
136 scalar skewCoeff = 0.0;
138 if (Sf.internalField().size())
140 skewCoeff = max(mag(SkewCorrVecs)/mag(d)).value();
145 Info<< "surfaceInterpolation::makeSkewCorrectionVectors() : "
146 << "skew coefficient = " << skewCoeff << endl;
151 if (skewCoeff < 1e-5)
154 deleteDemandDrivenData(skewCorrectionVectors_);
163 Info<< "surfaceInterpolation::makeSkewCorrectionVectors() : "
164 << "Finished constructing skew correction vectors"
170 bool Foam::skewCorrectionVectors::skew() const
172 if (skew_ == true && !skewCorrectionVectors_)
174 makeSkewCorrectionVectors();
181 const Foam::surfaceVectorField& Foam::skewCorrectionVectors::operator()() const
185 FatalErrorIn("skewCorrectionVectors::operator()()")
186 << "Cannot return correctionVectors; mesh is not skewed"
187 << abort(FatalError);
190 return *skewCorrectionVectors_;
194 // Do what is neccessary if the mesh has moved
195 bool Foam::skewCorrectionVectors::movePoints()
198 deleteDemandDrivenData(skewCorrectionVectors_);
204 // ************************************************************************* //