FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

displacementFvMotionSolver.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "displacementFvMotionSolver.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <OpenFOAM/mapPolyMesh.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(displacementFvMotionSolver, 0);
00035 }
00036 
00037 
00038 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00039 
00040 Foam::displacementFvMotionSolver::displacementFvMotionSolver
00041 (
00042     const polyMesh& mesh,
00043     Istream&
00044 )
00045 :
00046     fvMotionSolver(mesh),
00047     points0_
00048     (
00049         pointIOField
00050         (
00051             IOobject
00052             (
00053                 "points",
00054                 mesh.time().constant(),
00055                 polyMesh::meshSubDir,
00056                 mesh,
00057                 IOobject::MUST_READ,
00058                 IOobject::NO_WRITE,
00059                 false
00060             )
00061         )
00062     )
00063 {
00064     if (points0_.size() != mesh.nPoints())
00065     {
00066         FatalErrorIn
00067         (
00068             "displacementFvMotionSolver::displacementFvMotionSolver\n"
00069             "(\n"
00070             "    const polyMesh&,\n"
00071             "    Istream&\n"
00072             ")"
00073         )   << "Number of points in mesh " << mesh.nPoints()
00074             << " differs from number of points " << points0_.size()
00075             << " read from file "
00076             <<
00077                 IOobject
00078                 (
00079                     "points",
00080                     mesh.time().constant(),
00081                     polyMesh::meshSubDir,
00082                     mesh,
00083                     IOobject::MUST_READ,
00084                     IOobject::NO_WRITE,
00085                     false
00086                 ).filePath()
00087             << exit(FatalError);
00088     }
00089 }
00090 
00091 
00092 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00093 
00094 Foam::displacementFvMotionSolver::~displacementFvMotionSolver()
00095 {}
00096 
00097 
00098 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00099 
00100 void Foam::displacementFvMotionSolver::updateMesh(const mapPolyMesh& mpm)
00101 {
00102     fvMotionSolver::updateMesh(mpm);
00103 
00104     // Map points0_. Bit special since we somehow have to come up with
00105     // a sensible points0 position for introduced points.
00106     // Find out scaling between points0 and current points
00107 
00108     // Get the new points either from the map or the mesh
00109     const pointField& points =
00110     (
00111         mpm.hasMotionPoints()
00112       ? mpm.preMotionPoints()
00113       : fvMesh_.points()
00114     );
00115 
00116     // Note: boundBox does reduce
00117     const vector span0 = boundBox(points0_).span();
00118     const vector span  = boundBox(points).span();
00119 
00120     vector scaleFactors(cmptDivide(span0, span));
00121 
00122     pointField newPoints0(mpm.pointMap().size());
00123 
00124     forAll(newPoints0, pointI)
00125     {
00126         label oldPointI = mpm.pointMap()[pointI];
00127 
00128         if (oldPointI >= 0)
00129         {
00130             label masterPointI = mpm.reversePointMap()[oldPointI];
00131 
00132             if (masterPointI == pointI)
00133             {
00134                 newPoints0[pointI] = points0_[oldPointI];
00135             }
00136             else
00137             {
00138                 // New point. Assume motion is scaling.
00139                 newPoints0[pointI] = points0_[oldPointI] + cmptMultiply
00140                 (
00141                     scaleFactors,
00142                     points[pointI]-points[masterPointI]
00143                 );
00144             }
00145         }
00146         else
00147         {
00148             FatalErrorIn
00149             (
00150                 "displacementLaplacianFvMotionSolver::updateMesh"
00151                 "(const mapPolyMesh& mpm)"
00152             )   << "Cannot work out coordinates of introduced vertices."
00153                 << " New vertex " << pointI << " at coordinate "
00154                 << points[pointI] << exit(FatalError);
00155         }
00156     }
00157     points0_.transfer(newPoints0);
00158 }
00159 
00160 
00161 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines