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 <OpenFOAM/IOstream.H>
00027 #include "coordinateSystem.H"
00028 #include "coordinateSystems.H"
00029 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00030
00031
00032
00033 namespace Foam
00034 {
00035 defineTypeNameAndDebug(coordinateSystem, 0);
00036 defineRunTimeSelectionTable(coordinateSystem, dictionary);
00037 defineRunTimeSelectionTable(coordinateSystem, origRotation);
00038 }
00039
00040
00041
00042 Foam::coordinateSystem::coordinateSystem()
00043 :
00044 name_(type()),
00045 note_(),
00046 origin_(point::zero),
00047 R_(),
00048 Rtr_(sphericalTensor::I)
00049 {}
00050
00051
00052 Foam::coordinateSystem::coordinateSystem
00053 (
00054 const word& name,
00055 const coordinateSystem& cs
00056 )
00057 :
00058 name_(name),
00059 note_(),
00060 origin_(cs.origin_),
00061 R_(cs.R_),
00062 Rtr_(cs.Rtr_)
00063 {}
00064
00065
00066 Foam::coordinateSystem::coordinateSystem
00067 (
00068 const word& name,
00069 const point& origin,
00070 const coordinateRotation& cr
00071 )
00072 :
00073 name_(name),
00074 note_(),
00075 origin_(origin),
00076 R_(cr),
00077 Rtr_(R_.T())
00078 {}
00079
00080
00081 Foam::coordinateSystem::coordinateSystem
00082 (
00083 const word& name,
00084 const point& origin,
00085 const vector& axis,
00086 const vector& dirn
00087 )
00088 :
00089 name_(name),
00090 note_(),
00091 origin_(origin),
00092 R_(axis, dirn),
00093 Rtr_(R_.T())
00094 {}
00095
00096
00097 Foam::coordinateSystem::coordinateSystem
00098 (
00099 const word& name,
00100 const dictionary& dict
00101 )
00102 :
00103 name_(name),
00104 note_(),
00105 origin_(point::zero),
00106 R_(),
00107 Rtr_(sphericalTensor::I)
00108 {
00109 operator=(dict);
00110 }
00111
00112
00113 Foam::coordinateSystem::coordinateSystem
00114 (
00115 const dictionary& dict
00116 )
00117 :
00118 name_(type()),
00119 note_(),
00120 origin_(point::zero),
00121 R_(),
00122 Rtr_(sphericalTensor::I)
00123 {
00124 operator=(dict);
00125 }
00126
00127
00128 Foam::coordinateSystem::coordinateSystem
00129 (
00130 const dictionary& dict,
00131 const objectRegistry& obr
00132 )
00133 :
00134 name_(type()),
00135 note_(),
00136 origin_(point::zero),
00137 R_(),
00138 Rtr_(sphericalTensor::I)
00139 {
00140 const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);
00141
00142
00143 if (entryPtr && !entryPtr->isDict())
00144 {
00145 word csName;
00146 entryPtr->stream() >> csName;
00147
00148 const coordinateSystems& csLst = coordinateSystems::New(obr);
00149
00150 label csId = csLst.find(csName);
00151 if (debug)
00152 {
00153 Info<< "coordinateSystem::coordinateSystem"
00154 "(const dictionary&, const objectRegistry&):"
00155 << nl << "using global coordinate system: "
00156 << csName << "=" << csId << endl;
00157 }
00158
00159 if (csId < 0)
00160 {
00161 FatalErrorIn
00162 (
00163 "coordinateSystem::coordinateSystem"
00164 "(const dictionary&, const objectRegistry&)"
00165 ) << "could not find coordinate system: " << csName << nl
00166 << "available coordinate systems: " << csLst.toc() << nl << nl
00167 << exit(FatalError);
00168 }
00169
00170
00171
00172 operator=(csLst[csId]);
00173 name_ = typeName_();
00174 }
00175 else
00176 {
00177 operator=(dict);
00178 }
00179 }
00180
00181
00182 Foam::coordinateSystem::coordinateSystem(Istream& is)
00183 :
00184 name_(is),
00185 note_(),
00186 origin_(point::zero),
00187 R_(),
00188 Rtr_(sphericalTensor::I)
00189 {
00190 dictionary dict(is);
00191 operator=(dict);
00192 }
00193
00194
00195
00196
00197 Foam::coordinateSystem::~coordinateSystem()
00198 {}
00199
00200
00201
00202
00203 Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
00204 {
00205 dictionary dict;
00206
00207 dict.add("name", name_);
00208
00209
00210 if (!ignoreType && type() != typeName_())
00211 {
00212 dict.add("type", type());
00213 }
00214
00215
00216 if (note_.size())
00217 {
00218 dict.add("note", note_);
00219 }
00220
00221 dict.add("origin", origin_);
00222 dict.add("e1", e1());
00223 dict.add("e3", e3());
00224
00225 return dict;
00226 }
00227
00228
00229 Foam::vector Foam::coordinateSystem::localToGlobal
00230 (
00231 const vector& local,
00232 bool translate
00233 ) const
00234 {
00235 if (translate)
00236 {
00237 return (R_ & local) + origin_;
00238 }
00239 else
00240 {
00241 return (R_ & local);
00242 }
00243 }
00244
00245
00246 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
00247 (
00248 const vectorField& local,
00249 bool translate
00250 ) const
00251 {
00252 if (translate)
00253 {
00254 return (R_ & local) + origin_;
00255 }
00256 else
00257 {
00258 return (R_ & local);
00259 }
00260 }
00261
00262
00263 Foam::vector Foam::coordinateSystem::globalToLocal
00264 (
00265 const vector& global,
00266 bool translate
00267 ) const
00268 {
00269 if (translate)
00270 {
00271 return (Rtr_ & (global - origin_));
00272 }
00273 else
00274 {
00275 return (Rtr_ & global);
00276 }
00277 }
00278
00279
00280 Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
00281 (
00282 const vectorField& global,
00283 bool translate
00284 ) const
00285 {
00286 if (translate)
00287 {
00288 return (Rtr_ & (global - origin_));
00289 }
00290 else
00291 {
00292 return (Rtr_ & global);
00293 }
00294 }
00295
00296
00297 void Foam::coordinateSystem::write(Ostream& os) const
00298 {
00299 os << type()
00300 << " origin: " << origin() << " e1: " << e1() << " e3: " << e3();
00301 }
00302
00303
00304 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
00305 {
00306 if (subDict)
00307 {
00308 os << indent << name_ << nl
00309 << indent << token::BEGIN_BLOCK << incrIndent << nl;
00310 }
00311
00312
00313 if (type() != typeName_())
00314 {
00315 os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
00316 }
00317
00318
00319 if (note_.size())
00320 {
00321 os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
00322 }
00323
00324 os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
00325 os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
00326 os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
00327
00328 if (subDict)
00329 {
00330 os << decrIndent << indent << token::END_BLOCK << endl;
00331 }
00332 }
00333
00334
00335
00336 void Foam::coordinateSystem::operator=(const dictionary& rhs)
00337 {
00338 if (debug)
00339 {
00340 Pout<< "coordinateSystem::operator=(const dictionary&) : "
00341 << "assign from " << rhs << endl;
00342 }
00343
00344
00345 const dictionary& dict =
00346 (
00347 rhs.found(typeName_())
00348 ? rhs.subDict(typeName_())
00349 : rhs
00350 );
00351
00352
00353 origin_ = point::zero;
00354 dict.readIfPresent("origin", origin_);
00355
00356
00357 note_.clear();
00358 rhs.readIfPresent("note", note_);
00359
00360
00361 if (dict.found("coordinateRotation"))
00362 {
00363 R_ = coordinateRotation::New(dict.subDict("coordinateRotation"))();
00364 }
00365 else
00366 {
00367
00368 R_ = coordinateRotation(dict);
00369 }
00370
00371 Rtr_ = R_.T();
00372 }
00373
00374
00375
00376
00377 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
00378 {
00379 return (a.origin() != b.origin() || a.R() != b.R() || a.type() != b.type());
00380 }
00381
00382
00383
00384
00385 Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& cs)
00386 {
00387 cs.write(os);
00388 os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
00389 return os;
00390 }
00391
00392
00393