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  << "index out of range"
84  << abort(FatalError);
85  }
86 # endif
87 
88  return v_[d];
89 }
90 
91 
92 template<class Form, class Cmpt, int nCmpt>
94 (
95  const direction d
96 )
97 {
98 # ifdef FULLDEBUG
99  if (d >= nCmpt)
100  {
102  << "index out of range"
103  << abort(FatalError);
104  }
105 # endif
106 
107  return v_[d];
108 }
109 
110 
111 template<class Form, class Cmpt, int nCmpt>
113 (
114  Cmpt& c,
115  const direction d
116 ) const
117 {
118 # ifdef FULLDEBUG
119  if (d >= nCmpt)
120  {
122  << "index out of range"
123  << abort(FatalError);
124  }
125 # endif
126 
127  c = v_[d];
128 }
129 
130 
131 template<class Form, class Cmpt, int nCmpt>
133 (
134  const direction d,
135  const Cmpt& c
136 )
137 {
138 # ifdef FULLDEBUG
139  if (d >= nCmpt)
140  {
142  << "index out of range"
143  << abort(FatalError);
144  }
145 # endif
146 
147  v_[d] = c;
148 }
149 
150 
151 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
152 
153 template<class Form, class Cmpt, int nCmpt>
154 inline const Cmpt& VectorSpace<Form, Cmpt, nCmpt>::operator[]
155 (
156  const direction d
157 ) const
158 {
159 # ifdef FULLDEBUG
160  if (d >= nCmpt)
161  {
163  << "index out of range"
164  << abort(FatalError);
165  }
166 # endif
167 
168  return v_[d];
169 }
170 
171 
172 template<class Form, class Cmpt, int nCmpt>
174 (
175  const direction d
176 )
177 {
178 # ifdef FULLDEBUG
179  if (d >= nCmpt)
180  {
182  << "index out of range"
183  << abort(FatalError);
184  }
185 # endif
186 
187  return v_[d];
188 }
189 
190 
191 template<class Form, class Cmpt, int nCmpt>
193 (
195 )
196 {
198 }
199 
200 
201 template<class Form, class Cmpt, int nCmpt>
203 (
205 )
206 {
208 }
209 
210 
211 template<class Form, class Cmpt, int nCmpt>
213 (
215 )
216 {
218 }
219 
220 
221 template<class Form, class Cmpt, int nCmpt>
223 (
224  const scalar s
225 )
226 {
228 }
229 
230 
231 template<class Form, class Cmpt, int nCmpt>
233 (
234  const scalar s
235 )
236 {
238 }
239 
240 
241 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
242 
243 template<class Form, class Cmpt, int nCmpt>
244 inline Cmpt& setComponent
245 (
247  const direction d
248 )
249 {
250  return vs.component(d);
251 }
252 
253 
254 template<class Form, class Cmpt, int nCmpt>
255 inline const Cmpt& component
256 (
258  const direction d
259 )
260 {
261  return vs.component(d);
262 }
263 
264 
265 // Powers of a Form
266 // Equivalent to outer-products between the Form and itself
267 // Form^0 = 1.0
268 template<class Form, class Cmpt, int nCmpt>
269 inline typename powProduct<Form, 0>::type pow
270 (
274 )
275 {
276  return 1.0;
277 }
278 
279 // Form^1 = Form
280 template<class Form, class Cmpt, int nCmpt>
281 inline typename powProduct<Form, 1>::type pow
282 (
286 )
287 {
288  return static_cast<const Form&>(v);
289 }
290 
291 
292 // Form^2 = sqr(Form)
293 template<class Form, class Cmpt, int nCmpt>
294 inline typename powProduct<Form, 2>::type pow
295 (
299 )
300 {
301  return sqr(static_cast<const Form&>(v));
302 }
303 
304 
305 template<class Form, class Cmpt, int nCmpt>
306 inline scalar magSqr
307 (
309 )
310 {
311  scalar ms = magSqr(vs.v_[0]);
313  return ms;
314 }
315 
316 
317 template<class Form, class Cmpt, int nCmpt>
318 inline scalar mag
319 (
321 )
322 {
323  return ::sqrt(magSqr(static_cast<const Form&>(vs)));
324 }
325 
326 
327 template<class Form, class Cmpt, int nCmpt>
328 inline VectorSpace<Form, Cmpt, nCmpt> cmptMultiply
329 (
332 )
333 {
334  Form v;
336  return v;
337 }
338 
339 
340 template<class Form, class Cmpt, int nCmpt>
341 inline VectorSpace<Form, Cmpt, nCmpt> cmptPow
342 (
345 )
346 {
347  Form v;
349  return v;
350 }
351 
352 
353 template<class Form, class Cmpt, int nCmpt>
354 inline VectorSpace<Form, Cmpt, nCmpt> cmptDivide
355 (
358 )
359 {
360  Form v;
362  return v;
363 }
364 
365 
366 template<class Form, class Cmpt, int nCmpt>
367 inline VectorSpace<Form, Cmpt, nCmpt> stabilise
368 (
370  const Cmpt& small
371 )
372 {
373  Form v;
375  return v;
376 }
377 
378 
379 template<class Form, class Cmpt, int nCmpt>
380 inline Cmpt cmptMax
381 (
383 )
384 {
385  Cmpt cMax = vs.v_[0];
387  return cMax;
388 }
389 
390 
391 template<class Form, class Cmpt, int nCmpt>
392 inline Cmpt cmptMin
393 (
395 )
396 {
397  Cmpt cMin = vs.v_[0];
399  return cMin;
400 }
401 
402 
403 template<class Form, class Cmpt, int nCmpt>
404 inline Cmpt cmptSum
405 (
407 )
408 {
409  Cmpt sum = vs.v_[0];
411  return sum;
412 }
413 
414 
415 template<class Form, class Cmpt, int nCmpt>
416 inline Cmpt cmptAv
417 (
419 )
420 {
421  return cmptSum(vs)/nCmpt;
422 }
423 
424 template<class Form, class Cmpt, int nCmpt>
425 inline Cmpt cmptProduct
426 (
428 )
429 {
430  Cmpt product = vs.v_[0];
432  return product;
433 }
434 
435 
436 template<class Form, class Cmpt, int nCmpt>
437 inline Form cmptMag
438 (
440 )
441 {
442  Form v;
444  return v;
445 }
446 
447 
448 template<class Form, class Cmpt, int nCmpt>
449 inline Form max
450 (
453 )
454 {
455  Form v;
457  return v;
458 }
459 
460 
461 template<class Form, class Cmpt, int nCmpt>
462 inline Form min
463 (
466 )
467 {
468  Form v;
470  return v;
471 }
472 
473 
474 template<class Form, class Cmpt, int nCmpt>
475 inline Form minMod
476 (
479 )
480 {
481  Form v;
483  return v;
484 }
485 
486 
487 template<class Type>
488 inline Type dot(const scalar s, const Type& t)
489 {
490  return s * t;
491 }
492 
493 
494 template<class Type>
495 inline Type dot(const Type& t, const scalar s)
496 {
497  return t * s;
498 }
499 
500 
501 template
502 <
503  class Form1, class Cmpt1, int nCmpt1,
504  class Form2, class Cmpt2, int nCmpt2
505 >
507 (
510 )
511 {
512  return static_cast<const Form1&>(t1) & static_cast<const Form2&>(t2);
513 }
514 
515 
516 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
517 
518 template<class Form, class Cmpt, int nCmpt>
519 inline Form operator-
520 (
522 )
523 {
524  Form v;
526  return v;
527 }
528 
529 
530 template<class Form, class Cmpt, int nCmpt>
531 inline Form operator+
532 (
535 )
536 {
537  Form v;
539  return v;
540 }
541 
542 template<class Form, class Cmpt, int nCmpt>
543 inline Form operator-
544 (
547 )
548 {
549  Form v;
551  return v;
552 }
553 
554 
555 template<class Form, class Cmpt, int nCmpt>
556 inline Form operator*
557 (
558  scalar s,
560 )
561 {
562  Form v;
564  return v;
565 }
566 
567 
568 template<class Form, class Cmpt, int nCmpt>
569 inline Form operator*
570 (
572  scalar s
573 )
574 {
575  Form v;
577  return v;
578 }
579 
580 
581 template<class Form, class Cmpt, int nCmpt>
582 inline Form operator/
583 (
585  scalar s
586 )
587 {
588  Form v;
590  return v;
591 }
592 
593 /*
594 template<class Form, class Cmpt, int nCmpt>
595 inline Form operator/
596 (
597  const VectorSpace<Form, Cmpt, nCmpt>& vs1,
598  const VectorSpace<Form, Cmpt, nCmpt>& vs2
599 )
600 {
601  Form v;
602  VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, divideOp<Cmpt>());
603  return v;
604 }
605 
606 
607 template<class Form, class Cmpt, int nCmpt>
608 inline Form operator/
609 (
610  scalar s,
611  const VectorSpace<Form, Cmpt, nCmpt>& vs
612 )
613 {
614  Form v;
615  VectorSpaceOps<nCmpt,0>::opSV(v, s, vs, divideOp2<scalar, Cmpt>());
616  return v;
617 }
618 */
619 
620 
621 template<class Form, class Cmpt, int nCmpt>
622 inline Cmpt operator&&
623 (
626 )
627 {
628  Cmpt ddProd = vs1.v_[0]*vs2.v_[0];
629  for (int i=1; i<nCmpt; ++i)
630  {
631  ddProd += vs1.v_[i]*vs2.v_[i];
632  }
633  return ddProd;
634 }
635 
636 
637 template<class Form, class Cmpt, int nCmpt>
638 inline bool operator==
639 (
642 )
643 {
644  bool eq = true;
645  for (int i=0; i<nCmpt; ++i)
646  {
647  if (!(eq &= (equal(vs1.v_[i], vs2.v_[i])))) break;
648  }
649  return eq;
650 }
651 
652 
653 template<class Form, class Cmpt, int nCmpt>
654 inline bool operator!=
655 (
658 )
659 {
660  return !(vs1 == vs2);
661 }
662 
663 
664 template<class Form, class Cmpt, int nCmpt>
665 inline bool operator>
666 (
669 )
670 {
671  bool gt = true;
672  for (int i=0; i<nCmpt; ++i)
673  {
674  if (!(gt &= vs1.v_[i] > vs2.v_[i])) break;
675  }
676  return gt;
677 }
678 
679 
680 template<class Form, class Cmpt, int nCmpt>
681 inline bool operator<
682 (
685 )
686 {
687  bool lt = true;
688  for (int i=0; i<nCmpt; ++i)
689  {
690  if (!(lt &= vs1.v_[i] < vs2.v_[i])) break;
691  }
692  return lt;
693 }
694 
695 
696 template<class Form, class Cmpt, int nCmpt>
697 inline bool operator>=
698 (
701 )
702 {
703  return !(vs1 < vs2);
704 }
705 
706 
707 template<class Form, class Cmpt, int nCmpt>
708 inline bool operator<=
709 (
712 )
713 {
714  return !(vs1 > vs2);
715 }
716 
717 
718 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
719 
720 } // End namespace Foam
721 
722 // ************************************************************************* //
Foam::maxOp
Definition: ops.H:172
Foam::VectorSpaceOps::opSV
static void opSV(V &vs, const S &s, const V1 &vs1, Op o)
Definition: VectorSpaceOps.H:78
Foam::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:79
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:41
Foam::cmptPow
Scalar cmptPow(const Scalar s1, const Scalar s2)
Definition: Scalar.H:249
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::minusEqOp
Definition: ops.H:72
VectorSpaceOps.H
Foam::minOp
Definition: ops.H:173
Foam::VectorSpace::size
label size() const
Return the number of elements in the VectorSpace = nCmpt.
Definition: VectorSpaceI.H:67
Foam::dot
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:875
Foam::maxEqOp
Definition: ops.H:77
ops.H
Combination-Reduction operation for a parallel run.
Foam::plusOp
Definition: ops.H:164
Foam::minusOp
Definition: ops.H:165
Foam::VectorSpace::component
const Cmpt & component(const direction) const
Foam::VectorSpaceOps::eqOpS
static void eqOpS(V &vs, const S &s, EqOp eo)
Definition: VectorSpaceOps.H:49
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::VectorSpaceOps::eqOp
static void eqOp(V1 &vs1, const V2 &vs2, EqOp eo)
Definition: VectorSpaceOps.H:63
Foam::powProduct::type
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *int(pTraits< arg1 >::rank) >::type type
Definition: products.H:118
Foam::cmptDivideOp
Definition: ops.H:170
Foam::cmptMultiplyOp
Definition: ops.H:168
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:52
Foam::cmptMin
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:269
Foam::cmptMag
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:359
Foam::cmptMax
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:224
Foam::cmptPowOp
Definition: ops.H:169
Foam::minModOp
Definition: ops.H:176
Foam::divideEqOp2
Definition: ops.H:74
Foam::divideOp3
Definition: ops.H:167
Foam::label
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
Foam::multiplyEqOp
Definition: ops.H:73
error.H
Foam::stabilise
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
Definition: DimensionedScalarField.C:40
Foam::VectorSpaceOps::op
static void op(V &vs, const V1 &vs1, const V1 &vs2, Op o)
Definition: VectorSpaceOps.H:85
Foam::minEqOp
Definition: ops.H:78
Foam::VectorSpace::VectorSpace
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:39
Foam::innerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank) - 2 >::type type
Definition: products.H:97
Foam::eqMagOp
Definition: ops.H:75
Foam::plusEqMagSqrOp2
Definition: ops.H:76
Foam::stabiliseOp
Definition: ops.H:171
Foam::VectorSpace::v_
Cmpt v_[nCmpt]
The components of this vector space.
Definition: VectorSpace.H:95
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:73
Foam::cmptProduct
Cmpt cmptProduct(const VectorSpace< Form, Cmpt, nCmpt > &vs)
Definition: VectorSpaceI.H:426
Foam::VectorSpace::replace
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:133
Foam::VectorSpaceOps::opVS
static void opVS(V &vs, const V1 &vs1, const S &s, Op o)
Definition: VectorSpaceOps.H:71
Foam::FatalError
error FatalError
Foam::plusEqOp
Definition: ops.H:71
Foam::eqOp
Definition: ops.H:70
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
s
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))
Foam::VectorSpaceOps::SeqOp
static void SeqOp(S &s, const V &vs, EqOp eo)
Definition: VectorSpaceOps.H:56
Foam::small
const Scalar small
Definition: Scalar.H:319
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::multiplyEqOp2
Definition: ops.H:73
Foam::cmptAv
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:252
Foam::VectorSpace::operator
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, nCmpt > &)
Foam::minMod
Scalar minMod(const Scalar s1, const Scalar s2)
Definition: Scalar.H:167
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::eqMinusOp
Definition: ops.H:84
Foam::equal
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:78
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::cmptSum
Cmpt cmptSum(const VectorSpace< Form, Cmpt, nCmpt > &vs)
Definition: VectorSpaceI.H:405
products.H
Traits classes for inner and outer products of primitives.
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::multiplyOp3
Definition: ops.H:166
Foam::zero
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47