00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "displacementComponentLaplacianFvMotionSolver.H"
00028 #include "motionDiffusivity.H"
00029 #include "fvmLaplacian.H"
00030 #include "addToRunTimeSelectionTable.H"
00031 #include "mapPolyMesh.H"
00032 #include "volPointInterpolation.H"
00033
00034
00035
00036 namespace Foam
00037 {
00038 defineTypeNameAndDebug(displacementComponentLaplacianFvMotionSolver, 0);
00039
00040 addToRunTimeSelectionTable
00041 (
00042 fvMotionSolver,
00043 displacementComponentLaplacianFvMotionSolver,
00044 dictionary
00045 );
00046 }
00047
00048
00049
00050
00051 Foam::direction Foam::displacementComponentLaplacianFvMotionSolver::cmpt
00052 (
00053 const word& cmptName
00054 ) const
00055 {
00056 if (cmptName == "x")
00057 {
00058 return vector::X;
00059 }
00060 else if (cmptName == "y")
00061 {
00062 return vector::Y;
00063 }
00064 else if (cmptName == "z")
00065 {
00066 return vector::Z;
00067 }
00068 else
00069 {
00070 FatalErrorIn
00071 (
00072 "displacementComponentLaplacianFvMotionSolver::"
00073 "displacementComponentLaplacianFvMotionSolver"
00074 "(const polyMesh& mesh, Istream& msData)"
00075 ) << "Given component name " << cmptName << " should be x, y or z"
00076 << exit(FatalError);
00077
00078 return 0;
00079 }
00080 }
00081
00082
00083
00084
00085 Foam::displacementComponentLaplacianFvMotionSolver::
00086 displacementComponentLaplacianFvMotionSolver
00087 (
00088 const polyMesh& mesh,
00089 Istream& msData
00090 )
00091 :
00092 fvMotionSolver(mesh),
00093 cmptName_(msData),
00094 cmpt_(cmpt(cmptName_)),
00095 points0_
00096 (
00097 pointIOField
00098 (
00099 IOobject
00100 (
00101 "points",
00102 time().constant(),
00103 polyMesh::meshSubDir,
00104 mesh,
00105 IOobject::MUST_READ,
00106 IOobject::NO_WRITE,
00107 false
00108 )
00109 ).component(cmpt_)
00110 ),
00111 pointDisplacement_
00112 (
00113 IOobject
00114 (
00115 "pointDisplacement" + cmptName_,
00116 fvMesh_.time().timeName(),
00117 fvMesh_,
00118 IOobject::MUST_READ,
00119 IOobject::AUTO_WRITE
00120 ),
00121 pointMesh::New(fvMesh_)
00122 ),
00123 cellDisplacement_
00124 (
00125 IOobject
00126 (
00127 "cellDisplacement" + cmptName_,
00128 mesh.time().timeName(),
00129 mesh,
00130 IOobject::READ_IF_PRESENT,
00131 IOobject::AUTO_WRITE
00132 ),
00133 fvMesh_,
00134 dimensionedScalar
00135 (
00136 "cellDisplacement",
00137 pointDisplacement_.dimensions(),
00138 0
00139 ),
00140 cellMotionBoundaryTypes<scalar>(pointDisplacement_.boundaryField())
00141 ),
00142 pointLocation_(NULL),
00143 diffusivityPtr_
00144 (
00145 motionDiffusivity::New(*this, lookup("diffusivity"))
00146 ),
00147 frozenPointsZone_
00148 (
00149 found("frozenPointsZone")
00150 ? fvMesh_.pointZones().findZoneID(lookup("frozenPointsZone"))
00151 : -1
00152 )
00153 {
00154 IOobject io
00155 (
00156 "pointLocation",
00157 fvMesh_.time().timeName(),
00158 fvMesh_,
00159 IOobject::MUST_READ,
00160 IOobject::AUTO_WRITE
00161 );
00162
00163 if (debug)
00164 {
00165 Info<< "displacementComponentLaplacianFvMotionSolver:" << nl
00166 << " diffusivity : " << diffusivityPtr_().type() << nl
00167 << " frozenPoints zone : " << frozenPointsZone_ << endl;
00168 }
00169
00170 if (io.headerOk())
00171 {
00172 pointLocation_.reset
00173 (
00174 new pointVectorField
00175 (
00176 io,
00177 pointMesh::New(fvMesh_)
00178 )
00179 );
00180
00181 if (debug)
00182 {
00183 Info<< "displacementComponentLaplacianFvMotionSolver :"
00184 << " Read pointVectorField "
00185 << io.name() << " to be used for boundary conditions on points."
00186 << nl
00187 << "Boundary conditions:"
00188 << pointLocation_().boundaryField().types() << endl;
00189 }
00190 }
00191 }
00192
00193
00194
00195
00196 Foam::displacementComponentLaplacianFvMotionSolver::
00197 ~displacementComponentLaplacianFvMotionSolver()
00198 {}
00199
00200
00201
00202
00203 Foam::tmp<Foam::pointField>
00204 Foam::displacementComponentLaplacianFvMotionSolver::curPoints() const
00205 {
00206 volPointInterpolation::New(fvMesh_).interpolate
00207 (
00208 cellDisplacement_,
00209 pointDisplacement_
00210 );
00211
00212 if (pointLocation_.valid())
00213 {
00214 if (debug)
00215 {
00216 Info<< "displacementComponentLaplacianFvMotionSolver : applying "
00217 << " boundary conditions on " << pointLocation_().name()
00218 << " to new point location."
00219 << endl;
00220 }
00221
00222
00223
00224 pointLocation_().internalField() = fvMesh_.points();
00225
00226 pointLocation_().internalField().replace
00227 (
00228 cmpt_,
00229 points0_ + pointDisplacement_.internalField()
00230 );
00231
00232 pointLocation_().correctBoundaryConditions();
00233
00234
00235 if (frozenPointsZone_ != -1)
00236 {
00237 const pointZone& pz = fvMesh_.pointZones()[frozenPointsZone_];
00238
00239 forAll(pz, i)
00240 {
00241 label pointI = pz[i];
00242
00243 pointLocation_()[pointI][cmpt_] = points0_[pointI];
00244 }
00245 }
00246
00247 twoDCorrectPoints(pointLocation_().internalField());
00248
00249 return tmp<pointField>(pointLocation_().internalField());
00250 }
00251 else
00252 {
00253 tmp<pointField> tcurPoints(new pointField(fvMesh_.points()));
00254
00255 tcurPoints().replace
00256 (
00257 cmpt_,
00258 points0_ + pointDisplacement_.internalField()
00259 );
00260
00261
00262 if (frozenPointsZone_ != -1)
00263 {
00264 const pointZone& pz = fvMesh_.pointZones()[frozenPointsZone_];
00265
00266 forAll(pz, i)
00267 {
00268 label pointI = pz[i];
00269
00270 tcurPoints()[pointI][cmpt_] = points0_[pointI];
00271 }
00272 }
00273
00274 twoDCorrectPoints(tcurPoints());
00275
00276 return tcurPoints;
00277 }
00278 }
00279
00280
00281 void Foam::displacementComponentLaplacianFvMotionSolver::solve()
00282 {
00283
00284
00285 movePoints(fvMesh_.points());
00286
00287 diffusivityPtr_->correct();
00288 pointDisplacement_.boundaryField().updateCoeffs();
00289
00290 Foam::solve
00291 (
00292 fvm::laplacian
00293 (
00294 diffusivityPtr_->operator()(),
00295 cellDisplacement_,
00296 "laplacian(diffusivity,cellDisplacement)"
00297 )
00298 );
00299 }
00300
00301
00302 void Foam::displacementComponentLaplacianFvMotionSolver::updateMesh
00303 (
00304 const mapPolyMesh& mpm
00305 )
00306 {
00307 fvMotionSolver::updateMesh(mpm);
00308
00309
00310
00311
00312
00313
00314 const scalarField points
00315 (
00316 mpm.hasMotionPoints()
00317 ? mpm.preMotionPoints().component(cmpt_)
00318 : fvMesh_.points().component(cmpt_)
00319 );
00320
00321
00322 const scalar scale =
00323 (gMax(points0_)-gMin(points0_))
00324 /(gMax(points)-gMin(points));
00325
00326 scalarField newPoints0(mpm.pointMap().size());
00327
00328 forAll(newPoints0, pointI)
00329 {
00330 label oldPointI = mpm.pointMap()[pointI];
00331
00332 if (oldPointI >= 0)
00333 {
00334 label masterPointI = mpm.reversePointMap()[oldPointI];
00335
00336 if (masterPointI == pointI)
00337 {
00338 newPoints0[pointI] = points0_[oldPointI];
00339 }
00340 else
00341 {
00342
00343 newPoints0[pointI] =
00344 points0_[oldPointI]
00345 + scale*(points[pointI]-points[masterPointI]);
00346 }
00347 }
00348 else
00349 {
00350 FatalErrorIn
00351 (
00352 "displacementLaplacianFvMotionSolver::updateMesh"
00353 "(const mapPolyMesh& mpm)"
00354 ) << "Cannot work out coordinates of introduced vertices."
00355 << " New vertex " << pointI << " at coordinate "
00356 << points[pointI] << exit(FatalError);
00357 }
00358 }
00359 points0_.transfer(newPoints0);
00360
00361
00362
00363 diffusivityPtr_.reset(NULL);
00364 diffusivityPtr_ = motionDiffusivity::New(*this, lookup("diffusivity"));
00365 }
00366
00367
00368