VectorSpaceI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "error.H"
27 #include "products.H"
28 #include "VectorSpaceOps.H"
29 #include "ops.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
38 template<class Form, class Cmpt, int nCmpt>
40 {}
41 
42 
43 template<class Form, class Cmpt, int nCmpt>
45 (
47 )
48 {
50 }
51 
52 
53 template<class Form, class Cmpt, int nCmpt>
54 template<class Form2, class Cmpt2>
56 (
58 )
59 {
61 }
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
66 template<class Form, class Cmpt, int nCmpt>
68 {
69  return nCmpt;
70 }
71 
72 
73 template<class Form, class Cmpt, int nCmpt>
75 (
76  const direction d
77 ) const
78 {
79 # ifdef FULLDEBUG
80  if (d >= nCmpt)
81  {
83  (
84  "VectorSpace<Form, Cmpt, nCmpt>::component(direction) const"
85  ) << "index out of range"
86  << abort(FatalError);
87  }
88 # endif
89 
90  return v_[d];
91 }
92 
93 
94 template<class Form, class Cmpt, int nCmpt>
96 (
97  const direction d
98 )
99 {
100 # ifdef FULLDEBUG
101  if (d >= nCmpt)
102  {
103  FatalErrorIn("VectorSpace<Form, Cmpt, nCmpt>::component(direction)")
104  << "index out of range"
105  << abort(FatalError);
106  }
107 # endif
108 
109  return v_[d];
110 }
111 
112 
113 template<class Form, class Cmpt, int nCmpt>
115 (
116  Cmpt& c,
117  const direction d
118 ) const
119 {
120 # ifdef FULLDEBUG
121  if (d >= nCmpt)
122  {
124  (
125  "VectorSpace<Form, Cmpt, nCmpt>::component(Cmpt&, direction) const"
126  ) << "index out of range"
127  << abort(FatalError);
128  }
129 # endif
130 
131  c = v_[d];
132 }
133 
134 
135 template<class Form, class Cmpt, int nCmpt>
137 (
138  const direction d,
139  const Cmpt& c
140 )
141 {
142 # ifdef FULLDEBUG
143  if (d >= nCmpt)
144  {
146  (
147  "VectorSpace<Form, Cmpt, nCmpt>::"
148  "replace(direction, const Cmpt&) const"
149  ) << "index out of range"
150  << abort(FatalError);
151  }
152 # endif
153 
154  v_[d] = c;
155 }
156 
157 
158 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
159 
160 template<class Form, class Cmpt, int nCmpt>
161 inline const Cmpt& VectorSpace<Form, Cmpt, nCmpt>::operator[]
162 (
163  const direction d
164 ) const
165 {
166 # ifdef FULLDEBUG
167  if (d >= nCmpt)
168  {
170  (
171  "VectorSpace<Form, Cmpt, nCmpt>::operator[](direction d) const"
172  ) << "index out of range"
173  << abort(FatalError);
174  }
175 # endif
176 
177  return v_[d];
178 }
179 
180 
181 template<class Form, class Cmpt, int nCmpt>
182 inline Cmpt& VectorSpace<Form, Cmpt, nCmpt>::operator[]
183 (
184  const direction d
185 )
186 {
187 # ifdef FULLDEBUG
188  if (d >= nCmpt)
189  {
190  FatalErrorIn("VectorSpace<Form, Cmpt, nCmpt>::operator[](direction d)")
191  << "index out of range"
192  << abort(FatalError);
193  }
194 # endif
195 
196  return v_[d];
197 }
198 
199 
200 template<class Form, class Cmpt, int nCmpt>
201 inline void VectorSpace<Form, Cmpt, nCmpt>::operator=
202 (
204 )
205 {
207 }
208 
209 
210 template<class Form, class Cmpt, int nCmpt>
211 inline void VectorSpace<Form, Cmpt, nCmpt>::operator+=
212 (
214 )
215 {
217 }
218 
219 
220 template<class Form, class Cmpt, int nCmpt>
221 inline void VectorSpace<Form, Cmpt, nCmpt>::operator-=
222 (
224 )
225 {
227 }
228 
229 
230 template<class Form, class Cmpt, int nCmpt>
231 inline void VectorSpace<Form, Cmpt, nCmpt>::operator*=
232 (
233  const scalar s
234 )
235 {
237 }
238 
239 
240 template<class Form, class Cmpt, int nCmpt>
241 inline void VectorSpace<Form, Cmpt, nCmpt>::operator/=
242 (
243  const scalar s
244 )
245 {
247 }
248 
249 
250 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
251 
252 template<class Form, class Cmpt, int nCmpt>
253 inline Cmpt& setComponent
254 (
256  const direction d
257 )
258 {
259  return vs.component(d);
260 }
261 
262 
263 template<class Form, class Cmpt, int nCmpt>
264 inline const Cmpt& component
265 (
267  const direction d
268 )
269 {
270  return vs.component(d);
271 }
272 
273 
274 // Powers of a Form
275 // Equivalent to outer-products between the Form and itself
276 // Form^0 = 1.0
277 template<class Form, class Cmpt, int nCmpt>
278 inline typename powProduct<Form, 0>::type pow
279 (
283 )
284 {
285  return 1.0;
286 }
287 
288 // Form^1 = Form
289 template<class Form, class Cmpt, int nCmpt>
290 inline typename powProduct<Form, 1>::type pow
291 (
295 )
296 {
297  return static_cast<const Form&>(v);
298 }
299 
300 
301 // Form^2 = sqr(Form)
302 template<class Form, class Cmpt, int nCmpt>
303 inline typename powProduct<Form, 2>::type pow
304 (
308 )
309 {
310  return sqr(static_cast<const Form&>(v));
311 }
312 
313 
314 template<class Form, class Cmpt, int nCmpt>
315 inline scalar magSqr
316 (
318 )
319 {
320  scalar ms = magSqr(vs.v_[0]);
322  return ms;
323 }
324 
325 
326 template<class Form, class Cmpt, int nCmpt>
327 inline scalar mag
328 (
330 )
331 {
332  return ::sqrt(magSqr(static_cast<const Form&>(vs)));
333 }
334 
335 
336 template<class Form, class Cmpt, int nCmpt>
338 (
341 )
342 {
343  Form v;
345  return v;
346 }
347 
348 
349 template<class Form, class Cmpt, int nCmpt>
351 (
354 )
355 {
356  Form v;
358  return v;
359 }
360 
361 
362 template<class Form, class Cmpt, int nCmpt>
364 (
367 )
368 {
369  Form v;
371  return v;
372 }
373 
374 
375 template<class Form, class Cmpt, int nCmpt>
377 (
379  const Cmpt& small
380 )
381 {
382  Form v;
384  return v;
385 }
386 
387 
388 template<class Form, class Cmpt, int nCmpt>
389 inline Cmpt cmptMax
390 (
392 )
393 {
394  Cmpt cMax = vs.v_[0];
396  return cMax;
397 }
398 
399 
400 template<class Form, class Cmpt, int nCmpt>
401 inline Cmpt cmptMin
402 (
404 )
405 {
406  Cmpt cMin = vs.v_[0];
408  return cMin;
409 }
410 
411 
412 template<class Form, class Cmpt, int nCmpt>
413 inline Cmpt cmptSum
414 (
416 )
417 {
418  Cmpt sum = vs.v_[0];
420  return sum;
421 }
422 
423 
424 template<class Form, class Cmpt, int nCmpt>
425 inline Cmpt cmptAv
426 (
428 )
429 {
430  return cmptSum(vs)/nCmpt;
431 }
432 
433 template<class Form, class Cmpt, int nCmpt>
434 inline Cmpt cmptProduct
435 (
437 )
438 {
439  Cmpt product = vs.v_[0];
441  return product;
442 }
443 
444 
445 template<class Form, class Cmpt, int nCmpt>
446 inline Form cmptMag
447 (
449 )
450 {
451  Form v;
453  return v;
454 }
455 
456 
457 template<class Form, class Cmpt, int nCmpt>
458 inline Form max
459 (
462 )
463 {
464  Form v;
466  return v;
467 }
468 
469 
470 template<class Form, class Cmpt, int nCmpt>
471 inline Form min
472 (
475 )
476 {
477  Form v;
479  return v;
480 }
481 
482 
483 template<class Form, class Cmpt, int nCmpt>
484 inline Form minMod
485 (
488 )
489 {
490  Form v;
492  return v;
493 }
494 
495 
496 template<class Type>
497 inline Type dot(const scalar s, const Type& t)
498 {
499  return s * t;
500 }
501 
502 
503 template<class Type>
504 inline Type dot(const Type& t, const scalar s)
505 {
506  return t * s;
507 }
508 
509 
510 template
511 <
512  class Form1, class Cmpt1, int nCmpt1,
513  class Form2, class Cmpt2, int nCmpt2
514 >
516 (
519 )
520 {
521  return static_cast<const Form1&>(t1) & static_cast<const Form2&>(t2);
522 }
523 
524 
525 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
526 
527 template<class Form, class Cmpt, int nCmpt>
528 inline Form operator-
529 (
531 )
532 {
533  Form v;
535  return v;
536 }
537 
538 
539 template<class Form, class Cmpt, int nCmpt>
540 inline Form operator+
541 (
544 )
545 {
546  Form v;
548  return v;
549 }
550 
551 template<class Form, class Cmpt, int nCmpt>
552 inline Form operator-
553 (
556 )
557 {
558  Form v;
560  return v;
561 }
562 
563 
564 template<class Form, class Cmpt, int nCmpt>
565 inline Form operator*
566 (
567  scalar s,
569 )
570 {
571  Form v;
573  return v;
574 }
575 
576 
577 template<class Form, class Cmpt, int nCmpt>
578 inline Form operator*
579 (
581  scalar s
582 )
583 {
584  Form v;
586  return v;
587 }
588 
589 
590 template<class Form, class Cmpt, int nCmpt>
591 inline Form operator/
592 (
594  scalar s
595 )
596 {
597  Form v;
599  return v;
600 }
601 
602 /*
603 template<class Form, class Cmpt, int nCmpt>
604 inline Form operator/
605 (
606  const VectorSpace<Form, Cmpt, nCmpt>& vs1,
607  const VectorSpace<Form, Cmpt, nCmpt>& vs2
608 )
609 {
610  Form v;
611  VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, divideOp<Cmpt>());
612  return v;
613 }
614 
615 
616 template<class Form, class Cmpt, int nCmpt>
617 inline Form operator/
618 (
619  scalar s,
620  const VectorSpace<Form, Cmpt, nCmpt>& vs
621 )
622 {
623  Form v;
624  VectorSpaceOps<nCmpt,0>::opSV(v, s, vs, divideOp2<scalar, Cmpt>());
625  return v;
626 }
627 */
628 
629 
630 template<class Form, class Cmpt, int nCmpt>
631 inline Cmpt operator&&
632 (
635 )
636 {
637  Cmpt ddProd = vs1.v_[0]*vs2.v_[0];
638  for (int i=1; i<nCmpt; ++i)
639  {
640  ddProd += vs1.v_[i]*vs2.v_[i];
641  }
642  return ddProd;
643 }
644 
645 
646 template<class Form, class Cmpt, int nCmpt>
647 inline bool operator==
648 (
651 )
652 {
653  bool eq = true;
654  for (int i=0; i<nCmpt; ++i)
655  {
656  if (!(eq &= (equal(vs1.v_[i], vs2.v_[i])))) break;
657  }
658  return eq;
659 }
660 
661 
662 template<class Form, class Cmpt, int nCmpt>
663 inline bool operator!=
664 (
667 )
668 {
669  return !(vs1 == vs2);
670 }
671 
672 
673 template<class Form, class Cmpt, int nCmpt>
674 inline bool operator>
675 (
678 )
679 {
680  bool gt = true;
681  for (int i=0; i<nCmpt; ++i)
682  {
683  if (!(gt &= vs1.v_[i] > vs2.v_[i])) break;
684  }
685  return gt;
686 }
687 
688 
689 template<class Form, class Cmpt, int nCmpt>
690 inline bool operator<
691 (
694 )
695 {
696  bool lt = true;
697  for (int i=0; i<nCmpt; ++i)
698  {
699  if (!(lt &= vs1.v_[i] < vs2.v_[i])) break;
700  }
701  return lt;
702 }
703 
704 
705 template<class Form, class Cmpt, int nCmpt>
706 inline bool operator>=
707 (
710 )
711 {
712  return !(vs1 < vs2);
713 }
714 
715 
716 template<class Form, class Cmpt, int nCmpt>
717 inline bool operator<=
718 (
721 )
722 {
723  return !(vs1 > vs2);
724 }
725 
726 
727 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
728 
729 } // End namespace Foam
730 
731 // ************************************************************************* //
dimensionedScalar sqrt(const dimensionedScalar &ds)
label size() const
Return the number of elements in the VectorSpace = nCmpt.
Definition: VectorSpaceI.H:67
static void opVS(V &vs, const V1 &vs1, const S &s, Op o)
unsigned char direction
Definition: direction.H:43
Scalar cmptPow(const Scalar s1, const Scalar s2)
Definition: Scalar.H:246
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject( name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE ))
dimensioned< scalar > mag(const dimensioned< Type > &)
Scalar minMod(const Scalar s1, const Scalar s2)
Definition: Scalar.H:164
static void eqOpS(V &vs, const S &s, EqOp eo)
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:75
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Definition: ops.H:70
label & setComponent(label &l, const direction)
Definition: label.H:79
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank)-2 >::type type
Definition: products.H:97
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
static void op(V &vs, const V1 &vs1, const V1 &vs2, Op o)
Namespace for OpenFOAM.
Traits classes for inner and outer products of primitives.
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Cmpt v_[nCmpt]
The components of this vector space.
Definition: VectorSpace.H:95
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:39
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:137
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static void opSV(V &vs, const S &s, const V1 &vs1, Op o)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
Cmpt cmptSum(const VectorSpace< Form, Cmpt, nCmpt > &vs)
Definition: VectorSpaceI.H:414
Traits class for primitives.
Definition: pTraits.H:50
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
error FatalError
Cmpt cmptProduct(const VectorSpace< Form, Cmpt, nCmpt > &vs)
Definition: VectorSpaceI.H:435
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
Templated vector space.
Definition: VectorSpace.H:52
static void eqOp(V1 &vs1, const V2 &vs2, EqOp eo)
const dimensionedScalar c
Speed of light in a vacuum.
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Combination-Reduction operation for a parallel run.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
static void SeqOp(S &s, const V &vs, EqOp eo)
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *int(pTraits< arg1 >::rank) >::type type
Definition: products.H:118