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/error.H>
00027 #include "products.H"
00028 #include "VectorSpaceM.H"
00029 #include <OpenFOAM/ops.H>
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036
00037
00038 template<class Form, class Cmpt, int nCmpt>
00039 inline VectorSpace<Form, Cmpt, nCmpt>::VectorSpace()
00040 {}
00041
00042
00043 template<class Form, class Cmpt, int nCmpt>
00044 inline VectorSpace<Form, Cmpt, nCmpt>::VectorSpace
00045 (
00046 const VectorSpace<Form, Cmpt, nCmpt>& vs
00047 )
00048 {
00049 VectorSpaceOps<nCmpt,0>::eqOp(*this, vs, eqOp<Cmpt>());
00050 }
00051
00052
00053
00054
00055 template<class Form, class Cmpt, int nCmpt>
00056 inline label VectorSpace<Form, Cmpt, nCmpt>::size() const
00057 {
00058 return nCmpt;
00059 }
00060
00061
00062 template<class Form, class Cmpt, int nCmpt>
00063 inline const Cmpt& VectorSpace<Form, Cmpt, nCmpt>::component
00064 (
00065 const direction d
00066 ) const
00067 {
00068 # ifdef FULLDEBUG
00069 if (d >= nCmpt)
00070 {
00071 FatalErrorIn
00072 (
00073 "VectorSpace<Form, Cmpt, nCmpt>::component(direction) const"
00074 ) << "index out of range"
00075 << abort(FatalError);
00076 }
00077 # endif
00078
00079 return v_[d];
00080 }
00081
00082
00083 template<class Form, class Cmpt, int nCmpt>
00084 inline Cmpt& VectorSpace<Form, Cmpt, nCmpt>::component
00085 (
00086 const direction d
00087 )
00088 {
00089 # ifdef FULLDEBUG
00090 if (d >= nCmpt)
00091 {
00092 FatalErrorIn("VectorSpace<Form, Cmpt, nCmpt>::component(direction)")
00093 << "index out of range"
00094 << abort(FatalError);
00095 }
00096 # endif
00097
00098 return v_[d];
00099 }
00100
00101
00102 template<class Form, class Cmpt, int nCmpt>
00103 inline void VectorSpace<Form, Cmpt, nCmpt>::component
00104 (
00105 Cmpt& c,
00106 const direction d
00107 ) const
00108 {
00109 # ifdef FULLDEBUG
00110 if (d >= nCmpt)
00111 {
00112 FatalErrorIn
00113 (
00114 "VectorSpace<Form, Cmpt, nCmpt>::component(Cmpt&, direction) const"
00115 ) << "index out of range"
00116 << abort(FatalError);
00117 }
00118 # endif
00119
00120 c = v_[d];
00121 }
00122
00123
00124 template<class Form, class Cmpt, int nCmpt>
00125 inline void VectorSpace<Form, Cmpt, nCmpt>::replace
00126 (
00127 const direction d,
00128 const Cmpt& c
00129 )
00130 {
00131 # ifdef FULLDEBUG
00132 if (d >= nCmpt)
00133 {
00134 FatalErrorIn
00135 (
00136 "VectorSpace<Form, Cmpt, nCmpt>::"
00137 "replace(direction, const Cmpt&) const"
00138 ) << "index out of range"
00139 << abort(FatalError);
00140 }
00141 # endif
00142
00143 v_[d] = c;
00144 }
00145
00146
00147
00148
00149 template<class Form, class Cmpt, int nCmpt>
00150 inline const Cmpt& VectorSpace<Form, Cmpt, nCmpt>::operator[]
00151 (
00152 const direction d
00153 ) const
00154 {
00155 # ifdef FULLDEBUG
00156 if (d >= nCmpt)
00157 {
00158 FatalErrorIn
00159 (
00160 "VectorSpace<Form, Cmpt, nCmpt>::operator[](direction d) const"
00161 ) << "index out of range"
00162 << abort(FatalError);
00163 }
00164 # endif
00165
00166 return v_[d];
00167 }
00168
00169
00170 template<class Form, class Cmpt, int nCmpt>
00171 inline Cmpt& VectorSpace<Form, Cmpt, nCmpt>::operator[]
00172 (
00173 const direction d
00174 )
00175 {
00176 # ifdef FULLDEBUG
00177 if (d >= nCmpt)
00178 {
00179 FatalErrorIn("VectorSpace<Form, Cmpt, nCmpt>::operator[](direction d)")
00180 << "index out of range"
00181 << abort(FatalError);
00182 }
00183 # endif
00184
00185 return v_[d];
00186 }
00187
00188
00189 template<class Form, class Cmpt, int nCmpt>
00190 inline void VectorSpace<Form, Cmpt, nCmpt>::operator=
00191 (
00192 const VectorSpace<Form, Cmpt, nCmpt>& vs
00193 )
00194 {
00195 VectorSpaceOps<nCmpt,0>::eqOp(*this, vs, eqOp<Cmpt>());
00196 }
00197
00198
00199 template<class Form, class Cmpt, int nCmpt>
00200 inline void VectorSpace<Form, Cmpt, nCmpt>::operator+=
00201 (
00202 const VectorSpace<Form, Cmpt, nCmpt>& vs
00203 )
00204 {
00205 VectorSpaceOps<nCmpt,0>::eqOp(*this, vs, plusEqOp<Cmpt>());
00206 }
00207
00208
00209 template<class Form, class Cmpt, int nCmpt>
00210 inline void VectorSpace<Form, Cmpt, nCmpt>::operator-=
00211 (
00212 const VectorSpace<Form, Cmpt, nCmpt>& vs
00213 )
00214 {
00215 VectorSpaceOps<nCmpt,0>::eqOp(*this, vs, minusEqOp<Cmpt>());
00216 }
00217
00218
00219 template<class Form, class Cmpt, int nCmpt>
00220 inline void VectorSpace<Form, Cmpt, nCmpt>::operator*=
00221 (
00222 const scalar s
00223 )
00224 {
00225 VectorSpaceOps<nCmpt,0>::eqOpS(*this, s, multiplyEqOp2<Cmpt, scalar>());
00226 }
00227
00228
00229 template<class Form, class Cmpt, int nCmpt>
00230 inline void VectorSpace<Form, Cmpt, nCmpt>::operator/=
00231 (
00232 const scalar s
00233 )
00234 {
00235 VectorSpaceOps<nCmpt,0>::eqOpS(*this, s, divideEqOp2<Cmpt, scalar>());
00236 }
00237
00238
00239
00240
00241 template<class Form, class Cmpt, int nCmpt>
00242 inline Cmpt& setComponent
00243 (
00244 VectorSpace<Form, Cmpt, nCmpt>& vs,
00245 const direction d
00246 )
00247 {
00248 return vs.component(d);
00249 }
00250
00251
00252 template<class Form, class Cmpt, int nCmpt>
00253 inline const Cmpt& component
00254 (
00255 const VectorSpace<Form, Cmpt, nCmpt>& vs,
00256 const direction d
00257 )
00258 {
00259 return vs.component(d);
00260 }
00261
00262
00263
00264
00265
00266 template<class Form, class Cmpt, int nCmpt>
00267 inline typename powProduct<Form, 0>::type pow
00268 (
00269 const VectorSpace<Form, Cmpt, nCmpt>&,
00270 typename powProduct<Form, 0>::type
00271 = pTraits<typename powProduct<Form, 0>::type>::zero
00272 )
00273 {
00274 return 1.0;
00275 }
00276
00277
00278 template<class Form, class Cmpt, int nCmpt>
00279 inline typename powProduct<Form, 1>::type pow
00280 (
00281 const VectorSpace<Form, Cmpt, nCmpt>& v,
00282 typename powProduct<Form, 1>::type
00283 = pTraits<typename powProduct<Form, 1>::type>::zero
00284 )
00285 {
00286 return static_cast<const Form&>(v);
00287 }
00288
00289
00290
00291 template<class Form, class Cmpt, int nCmpt>
00292 inline typename powProduct<Form, 2>::type pow
00293 (
00294 const VectorSpace<Form, Cmpt, nCmpt>& v,
00295 typename powProduct<Form, 2>::type
00296 = pTraits<typename powProduct<Form, 2>::type>::zero
00297 )
00298 {
00299 return sqr(static_cast<const Form&>(v));
00300 }
00301
00302
00303 template<class Form, class Cmpt, int nCmpt>
00304 inline scalar magSqr
00305 (
00306 const VectorSpace<Form, Cmpt, nCmpt>& vs
00307 )
00308 {
00309 scalar ms = magSqr(vs.v_[0]);
00310 VectorSpaceOps<nCmpt,1>::SeqOp(ms, vs, plusEqMagSqrOp2<scalar, Cmpt>());
00311 return ms;
00312 }
00313
00314
00315 template<class Form, class Cmpt, int nCmpt>
00316 inline scalar mag
00317 (
00318 const VectorSpace<Form, Cmpt, nCmpt>& vs
00319 )
00320 {
00321 return ::sqrt(magSqr(static_cast<const Form&>(vs)));
00322 }
00323
00324
00325 template<class Form, class Cmpt, int nCmpt>
00326 inline VectorSpace<Form, Cmpt, nCmpt> cmptMultiply
00327 (
00328 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00329 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00330 )
00331 {
00332 Form v;
00333 VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, cmptMultiplyOp<Cmpt>());
00334 return v;
00335 }
00336
00337
00338 template<class Form, class Cmpt, int nCmpt>
00339 inline VectorSpace<Form, Cmpt, nCmpt> cmptDivide
00340 (
00341 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00342 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00343 )
00344 {
00345 Form v;
00346 VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, cmptDivideOp<Cmpt>());
00347 return v;
00348 }
00349
00350
00351 template<class Form, class Cmpt, int nCmpt>
00352 inline VectorSpace<Form, Cmpt, nCmpt> stabilise
00353 (
00354 const VectorSpace<Form, Cmpt, nCmpt>& vs,
00355 const Cmpt& small
00356 )
00357 {
00358 Form v;
00359 VectorSpaceOps<nCmpt,0>::opVS(v, vs, small, stabiliseOp<Cmpt>());
00360 return v;
00361 }
00362
00363
00364 template<class Form, class Cmpt, int nCmpt>
00365 inline Cmpt cmptMax
00366 (
00367 const VectorSpace<Form, Cmpt, nCmpt>& vs
00368 )
00369 {
00370 Cmpt cMax = vs.v_[0];
00371 VectorSpaceOps<nCmpt,1>::SeqOp(cMax, vs, maxEqOp<Cmpt>());
00372 return cMax;
00373 }
00374
00375
00376 template<class Form, class Cmpt, int nCmpt>
00377 inline Cmpt cmptMin
00378 (
00379 const VectorSpace<Form, Cmpt, nCmpt>& vs
00380 )
00381 {
00382 Cmpt cMin = vs.v_[0];
00383 VectorSpaceOps<nCmpt,1>::SeqOp(cMin, vs, minEqOp<Cmpt>());
00384 return cMin;
00385 }
00386
00387
00388 template<class Form, class Cmpt, int nCmpt>
00389 inline Cmpt cmptSum
00390 (
00391 const VectorSpace<Form, Cmpt, nCmpt>& vs
00392 )
00393 {
00394 Cmpt sum = vs.v_[0];
00395 VectorSpaceOps<nCmpt,1>::SeqOp(sum, vs, plusEqOp<Cmpt>());
00396 return sum;
00397 }
00398
00399
00400 template<class Form, class Cmpt, int nCmpt>
00401 inline Cmpt cmptAv
00402 (
00403 const VectorSpace<Form, Cmpt, nCmpt>& vs
00404 )
00405 {
00406 return cmptSum(vs)/nCmpt;
00407 }
00408
00409
00410 template<class Form, class Cmpt, int nCmpt>
00411 inline Form cmptMag
00412 (
00413 const VectorSpace<Form, Cmpt, nCmpt>& vs
00414 )
00415 {
00416 Form v;
00417 VectorSpaceOps<nCmpt,0>::eqOp(v, vs, eqMagOp<Cmpt>());
00418 return v;
00419 }
00420
00421
00422 template<class Form, class Cmpt, int nCmpt>
00423 inline Form max
00424 (
00425 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00426 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00427 )
00428 {
00429 Form v;
00430 VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, maxOp<Cmpt>());
00431 return v;
00432 }
00433
00434
00435 template<class Form, class Cmpt, int nCmpt>
00436 inline Form min
00437 (
00438 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00439 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00440 )
00441 {
00442 Form v;
00443 VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, minOp<Cmpt>());
00444 return v;
00445 }
00446
00447
00448 template<class Form, class Cmpt, int nCmpt>
00449 inline Form minMod
00450 (
00451 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00452 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00453 )
00454 {
00455 Form v;
00456 VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, minModOp<Cmpt>());
00457 return v;
00458 }
00459
00460
00461 template<class Type>
00462 inline Type dot(const scalar s, const Type& t)
00463 {
00464 return s * t;
00465 }
00466
00467
00468 template<class Type>
00469 inline Type dot(const Type& t, const scalar s)
00470 {
00471 return t * s;
00472 }
00473
00474
00475 template
00476 <
00477 class Form1, class Cmpt1, int nCmpt1,
00478 class Form2, class Cmpt2, int nCmpt2
00479 >
00480 inline typename innerProduct<Form1, Form2>::type dot
00481 (
00482 const VectorSpace<Form1, Cmpt1, nCmpt1>& t1,
00483 const VectorSpace<Form2, Cmpt2, nCmpt2>& t2
00484 )
00485 {
00486 return static_cast<const Form1&>(t1) & static_cast<const Form2&>(t2);
00487 }
00488
00489
00490
00491
00492 template<class Form, class Cmpt, int nCmpt>
00493 inline Form operator-
00494 (
00495 const VectorSpace<Form, Cmpt, nCmpt>& vs
00496 )
00497 {
00498 Form v;
00499 VectorSpaceOps<nCmpt,0>::eqOp(v, vs, eqMinusOp<Cmpt>());
00500 return v;
00501 }
00502
00503
00504 template<class Form, class Cmpt, int nCmpt>
00505 inline Form operator+
00506 (
00507 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00508 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00509 )
00510 {
00511 Form v;
00512 VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, plusOp<Cmpt>());
00513 return v;
00514 }
00515
00516 template<class Form, class Cmpt, int nCmpt>
00517 inline Form operator-
00518 (
00519 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00520 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00521 )
00522 {
00523 Form v;
00524 VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, minusOp<Cmpt>());
00525 return v;
00526 }
00527
00528
00529 template<class Form, class Cmpt, int nCmpt>
00530 inline Form operator*
00531 (
00532 scalar s,
00533 const VectorSpace<Form, Cmpt, nCmpt>& vs
00534 )
00535 {
00536 Form v;
00537 VectorSpaceOps<nCmpt,0>::opSV(v, s, vs, multiplyOp3<Cmpt, scalar, Cmpt>());
00538 return v;
00539 }
00540
00541
00542 template<class Form, class Cmpt, int nCmpt>
00543 inline Form operator*
00544 (
00545 const VectorSpace<Form, Cmpt, nCmpt>& vs,
00546 scalar s
00547 )
00548 {
00549 Form v;
00550 VectorSpaceOps<nCmpt,0>::opVS(v, vs, s, multiplyOp3<Cmpt, Cmpt, scalar>());
00551 return v;
00552 }
00553
00554
00555 template<class Form, class Cmpt, int nCmpt>
00556 inline Form operator/
00557 (
00558 const VectorSpace<Form, Cmpt, nCmpt>& vs,
00559 scalar s
00560 )
00561 {
00562 Form v;
00563 VectorSpaceOps<nCmpt,0>::opVS(v, vs, s, divideOp3<Cmpt, Cmpt, scalar>());
00564 return v;
00565 }
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 template<class Form, class Cmpt, int nCmpt>
00596 inline Cmpt operator&&
00597 (
00598 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00599 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00600 )
00601 {
00602 Cmpt ddProd = vs1.v_[0]*vs2.v_[0];
00603 for (int i=1; i<nCmpt; ++i)
00604 {
00605 ddProd += vs1.v_[i]*vs2.v_[i];
00606 }
00607 return ddProd;
00608 }
00609
00610
00611 template<class Form, class Cmpt, int nCmpt>
00612 inline bool operator==
00613 (
00614 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00615 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00616 )
00617 {
00618 bool eq = true;
00619 for (int i=0; i<nCmpt; ++i)
00620 {
00621 if (!(eq &= (equal(vs1.v_[i], vs2.v_[i])))) break;
00622 }
00623 return eq;
00624 }
00625
00626
00627 template<class Form, class Cmpt, int nCmpt>
00628 inline bool operator!=
00629 (
00630 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00631 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00632 )
00633 {
00634 return !(vs1 == vs2);
00635 }
00636
00637
00638 template<class Form, class Cmpt, int nCmpt>
00639 inline bool operator>
00640 (
00641 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00642 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00643 )
00644 {
00645 bool gt = true;
00646 for (int i=0; i<nCmpt; ++i)
00647 {
00648 if (!(gt &= vs1.v_[i] > vs2.v_[i])) break;
00649 }
00650 return gt;
00651 }
00652
00653
00654 template<class Form, class Cmpt, int nCmpt>
00655 inline bool operator<
00656 (
00657 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00658 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00659 )
00660 {
00661 bool lt = true;
00662 for (int i=0; i<nCmpt; ++i)
00663 {
00664 if (!(lt &= vs1.v_[i] < vs2.v_[i])) break;
00665 }
00666 return lt;
00667 }
00668
00669
00670 template<class Form, class Cmpt, int nCmpt>
00671 inline bool operator>=
00672 (
00673 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00674 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00675 )
00676 {
00677 return !(vs1 < vs2);
00678 }
00679
00680
00681 template<class Form, class Cmpt, int nCmpt>
00682 inline bool operator<=
00683 (
00684 const VectorSpace<Form, Cmpt, nCmpt>& vs1,
00685 const VectorSpace<Form, Cmpt, nCmpt>& vs2
00686 )
00687 {
00688 return !(vs1 > vs2);
00689 }
00690
00691
00692
00693
00694 }
00695
00696