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