OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

sampledSurface.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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "sampledSurface.H"
00028 #include "polyMesh.H"
00029 #include "demandDrivenData.H"
00030 
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036     defineTypeNameAndDebug(sampledSurface, 0);
00037     defineRunTimeSelectionTable(sampledSurface, word);
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 void Foam::sampledSurface::clearGeom() const
00044 {
00045     deleteDemandDrivenData(SfPtr_);
00046     deleteDemandDrivenData(magSfPtr_);
00047     deleteDemandDrivenData(CfPtr_);
00048     area_ = -1;
00049 }
00050 
00051 
00052 void Foam::sampledSurface::makeSf() const
00053 {
00054     // It is an error to recalculate if the pointer is already set
00055     if (SfPtr_)
00056     {
00057         FatalErrorIn("Foam::sampledSurface::makeSf()")
00058             << "face area vectors already exist"
00059             << abort(FatalError);
00060     }
00061 
00062     const faceList& theFaces = faces();
00063     SfPtr_ = new vectorField(theFaces.size());
00064 
00065     vectorField& values = *SfPtr_;
00066     forAll(theFaces, faceI)
00067     {
00068         values[faceI] = theFaces[faceI].normal(points());
00069     }
00070 }
00071 
00072 
00073 void Foam::sampledSurface::makeMagSf() const
00074 {
00075     // It is an error to recalculate if the pointer is already set
00076     if (magSfPtr_)
00077     {
00078         FatalErrorIn("Foam::sampledSurface::makeMagSf()")
00079             << "mag face areas already exist"
00080             << abort(FatalError);
00081     }
00082 
00083     const faceList& theFaces = faces();
00084     magSfPtr_ = new scalarField(theFaces.size());
00085 
00086     scalarField& values = *magSfPtr_;
00087     forAll(theFaces, faceI)
00088     {
00089         values[faceI] = theFaces[faceI].mag(points());
00090     }
00091 }
00092 
00093 
00094 void Foam::sampledSurface::makeCf() const
00095 {
00096     // It is an error to recalculate if the pointer is already set
00097     if (CfPtr_)
00098     {
00099         FatalErrorIn("Foam::sampledSurface::makeCf()")
00100             << "face centres already exist"
00101             << abort(FatalError);
00102     }
00103 
00104     const faceList& theFaces = faces();
00105     CfPtr_ = new vectorField(theFaces.size());
00106 
00107     vectorField& values = *CfPtr_;
00108     forAll(theFaces, faceI)
00109     {
00110         values[faceI] = theFaces[faceI].centre(points());
00111     }
00112 }
00113 
00114 
00115 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
00116 
00117 
00118 Foam::autoPtr<Foam::sampledSurface>
00119 Foam::sampledSurface::New
00120 (
00121     const word& name,
00122     const polyMesh& mesh,
00123     const dictionary& dict
00124 )
00125 {
00126     word sampleType(dict.lookup("type"));
00127     if (debug)
00128     {
00129         Info<< "Selecting sampledType " << sampleType << endl;
00130     }
00131 
00132     wordConstructorTable::iterator cstrIter =
00133         wordConstructorTablePtr_->find(sampleType);
00134 
00135     if (cstrIter == wordConstructorTablePtr_->end())
00136     {
00137         FatalErrorIn
00138         (
00139             "sampledSurface::New"
00140             "(const word&, const polyMesh&, const dictionary&)"
00141         )   << "Unknown sample type " << sampleType
00142             << endl << endl
00143             << "Valid sample types : " << endl
00144             << wordConstructorTablePtr_->toc()
00145             << exit(FatalError);
00146     }
00147 
00148     return autoPtr<sampledSurface>(cstrIter()(name, mesh, dict));
00149 }
00150 
00151 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00152 
00153 Foam::sampledSurface::sampledSurface
00154 (
00155     const word& name,
00156     const polyMesh& mesh
00157 )
00158 :
00159     name_(name),
00160     mesh_(mesh),
00161     interpolate_(false),
00162     SfPtr_(NULL),
00163     magSfPtr_(NULL),
00164     CfPtr_(NULL),
00165     area_(-1)
00166 {}
00167 
00168 
00169 // Construct from dictionary
00170 Foam::sampledSurface::sampledSurface
00171 (
00172     const word& name,
00173     const polyMesh& mesh,
00174     const dictionary& dict
00175 )
00176 :
00177     name_(name),
00178     mesh_(mesh),
00179     interpolate_(dict.lookupOrDefault("interpolate", false)),
00180     SfPtr_(NULL),
00181     magSfPtr_(NULL),
00182     CfPtr_(NULL),
00183     area_(-1)
00184 {
00185     dict.readIfPresent("name", name_);
00186 }
00187 
00188 
00189 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00190 
00191 Foam::sampledSurface::~sampledSurface()
00192 {
00193     clearGeom();
00194 }
00195 
00196 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00197 
00198 const Foam::vectorField& Foam::sampledSurface::Sf() const
00199 {
00200     if (!SfPtr_)
00201     {
00202         makeSf();
00203     }
00204 
00205     return *SfPtr_;
00206 }
00207 
00208 
00209 const Foam::scalarField& Foam::sampledSurface::magSf() const
00210 {
00211     if (!magSfPtr_)
00212     {
00213         makeMagSf();
00214     }
00215 
00216     return *magSfPtr_;
00217 }
00218 
00219 
00220 const Foam::vectorField& Foam::sampledSurface::Cf() const
00221 {
00222     if (!CfPtr_)
00223     {
00224         makeCf();
00225     }
00226 
00227     return *CfPtr_;
00228 }
00229 
00230 
00231 Foam::scalar Foam::sampledSurface::area() const
00232 {
00233     if (area_ < 0)
00234     {
00235         area_ = sum(magSf());
00236         reduce(area_, sumOp<scalar>());
00237     }
00238 
00239     return area_;
00240 }
00241 
00242 
00243 // do not project scalar - just copy values
00244 Foam::tmp<Foam::Field<Foam::scalar> >
00245 Foam::sampledSurface::project(const Field<scalar>& field) const
00246 {
00247     tmp<Field<scalar> > tRes(new Field<scalar>(faces().size()));
00248     Field<scalar>& res = tRes();
00249 
00250     forAll(faces(), faceI)
00251     {
00252         res[faceI] = field[faceI];
00253     }
00254 
00255     return tRes;
00256 }
00257 
00258 
00259 Foam::tmp<Foam::Field<Foam::scalar> >
00260 Foam::sampledSurface::project(const Field<vector>& field) const
00261 {
00262     tmp<Field<scalar> > tRes(new Field<scalar>(faces().size()));
00263     project(tRes(), field);
00264     return tRes;
00265 }
00266 
00267 
00268 Foam::tmp<Foam::Field<Foam::vector> >
00269 Foam::sampledSurface::project(const Field<sphericalTensor>& field) const
00270 {
00271     tmp<Field<vector> > tRes(new Field<vector>(faces().size()));
00272     project(tRes(), field);
00273     return tRes;
00274 }
00275 
00276 
00277 Foam::tmp<Foam::Field<Foam::vector> >
00278 Foam::sampledSurface::project(const Field<symmTensor>& field) const
00279 {
00280     tmp<Field<vector> > tRes(new Field<vector>(faces().size()));
00281     project(tRes(), field);
00282     return tRes;
00283 }
00284 
00285 
00286 Foam::tmp<Foam::Field<Foam::vector> >
00287 Foam::sampledSurface::project(const Field<tensor>& field) const
00288 {
00289     tmp<Field<vector> > tRes(new Field<vector>(faces().size()));
00290     project(tRes(), field);
00291     return tRes;
00292 }
00293 
00294 
00295 void Foam::sampledSurface::print(Ostream& os) const
00296 {
00297     os << type();
00298 }
00299 
00300 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00301 
00302 Foam::Ostream& Foam::operator<<(Ostream &os, const sampledSurface& s)
00303 {
00304     s.print(os);
00305     os.check("Ostream& operator<<(Ostream&, const sampledSurface&");
00306     return os;
00307 }
00308 
00309 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd