All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorSpaceI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 #include <type_traits>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
39 template<class Form, class Cmpt, direction Ncmpts>
41 {}
42 
43 
44 template<class Form, class Cmpt, direction Ncmpts>
46 {
48 }
49 
50 
51 template<class Form, class Cmpt, direction Ncmpts>
52 template<class Form2, class Cmpt2>
54 (
56 )
57 {
59 }
60 
61 
62 template<class Form, class Cmpt, direction Ncmpts>
63 template<class SubVector, direction BStart>
64 inline
66 (
67  const vsType& vs
68 )
69 :
70  vs_(vs)
71 {
72  static_assert
73  (
74  vsType::nComponents >= BStart + nComponents,
75  "Requested block size > VectorSpace size"
76  );
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
82 template<class Form, class Cmpt, direction Ncmpts>
84 {
85  return Ncmpts;
86 }
87 
88 
89 template<class Form, class Cmpt, direction Ncmpts>
91 (
92  const direction d
93 ) const
94 {
95  #ifdef FULLDEBUG
96  if (d >= Ncmpts)
97  {
99  << "index out of range"
100  << abort(FatalError);
101  }
102  #endif
103 
104  return v_[d];
105 }
106 
107 
108 template<class Form, class Cmpt, direction Ncmpts>
110 (
111  const direction d
112 )
113 {
114  #ifdef FULLDEBUG
115  if (d >= Ncmpts)
116  {
118  << "index out of range"
119  << abort(FatalError);
120  }
121  #endif
122 
123  return v_[d];
124 }
125 
126 
127 template<class Form, class Cmpt, direction Ncmpts>
129 (
130  Cmpt& c,
131  const direction d
132 ) const
133 {
134  #ifdef FULLDEBUG
135  if (d >= Ncmpts)
136  {
138  << "index out of range"
140  }
141  #endif
142 
143  c = v_[d];
144 }
145 
146 
147 template<class Form, class Cmpt, direction Ncmpts>
149 (
150  const direction d,
151  const Cmpt& c
152 )
153 {
154  #ifdef FULLDEBUG
155  if (d >= Ncmpts)
156  {
158  << "index out of range"
160  }
161  #endif
162 
163  v_[d] = c;
164 }
165 
166 
167 template<class Form, class Cmpt, direction Ncmpts>
169 {
170  Form v;
172  return v;
173 }
174 
175 
176 template<class Form, class Cmpt, direction Ncmpts>
177 template<class SubVector, direction BStart>
179  ConstBlock<SubVector, BStart>
181 {
182  return *this;
183 }
184 
185 
186 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
187 
188 template<class Form, class Cmpt, direction Ncmpts>
190 (
191  const direction d
192 ) const
193 {
194  #ifdef FULLDEBUG
195  if (d >= Ncmpts)
196  {
198  << "index out of range"
199  << abort(FatalError);
200  }
201  #endif
202 
203  return v_[d];
204 }
205 
206 
207 template<class Form, class Cmpt, direction Ncmpts>
209 (
210  const direction d
211 )
212 {
213  #ifdef FULLDEBUG
214  if (d >= Ncmpts)
215  {
217  << "index out of range"
218  << abort(FatalError);
219  }
220  #endif
221 
222  return v_[d];
223 }
224 
225 
226 template<class Form, class Cmpt, direction Ncmpts>
227 template<class SubVector, direction BStart>
228 inline const Cmpt&
230 ConstBlock<SubVector, BStart>::operator[]
231 (
232  const direction i
233 ) const
234 {
235  #ifdef FULLDEBUG
236  if (i >= Ncmpts)
237  {
239  << "index out of range"
240  << abort(FatalError);
241  }
242  #endif
243 
244  return vs_[BStart + i];
245 }
246 
247 
248 template<class Form, class Cmpt, direction Ncmpts>
249 template<class SubVector, direction BStart>
250 inline const Cmpt&
253 (
254  const direction i,
255  const direction j
256 ) const
257 {
258  #ifdef FULLDEBUG
259  if (i >= Ncmpts)
260  {
262  << "index out of range"
263  << abort(FatalError);
264  }
265 
266  if (j != 0)
267  {
269  << "j != 0"
270  << abort(FatalError);
271  }
272  #endif
273 
274  return vs_[BStart + i];
275 }
276 
277 
278 template<class Form, class Cmpt, direction Ncmpts>
280 (
282 )
283 {
285 }
286 
287 
288 template<class Form, class Cmpt, direction Ncmpts>
290 (
292 )
293 {
295 }
296 
297 
298 template<class Form, class Cmpt, direction Ncmpts>
300 {
302 }
303 
304 
305 template<class Form, class Cmpt, direction Ncmpts>
307 (
308  const scalar s
309 )
310 {
312 }
313 
314 
315 template<class Form, class Cmpt, direction Ncmpts>
317 (
318  const scalar s
319 )
320 {
322 }
323 
324 
325 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
326 
327 template<class Form, class Cmpt, direction Ncmpts>
328 inline Cmpt& setComponent
329 (
331  const direction d
332 )
333 {
334  return vs.component(d);
335 }
336 
337 
338 template<class Form, class Cmpt, direction Ncmpts>
339 inline const Cmpt& component
340 (
342  const direction d
343 )
344 {
345  return vs.component(d);
346 }
347 
348 
349 // Powers of a Form
350 // Equivalent to outer-products between the Form and itself
351 // Form^0 = 1.0
352 template<class Form, class Cmpt, direction Ncmpts>
354 (
358 )
359 {
360  return 1.0;
361 }
362 
363 // Form^1 = Form
364 template<class Form, class Cmpt, direction Ncmpts>
366 (
370 )
371 {
372  return static_cast<const Form&>(v);
373 }
374 
375 
376 // Form^2 = sqr(Form)
377 template<class Form, class Cmpt, direction Ncmpts>
379 (
383 )
384 {
385  return sqr(static_cast<const Form&>(v));
386 }
387 
388 
389 template<class Form, class Cmpt, direction Ncmpts>
390 inline scalar magSqr
391 (
393 )
394 {
395  scalar ms = magSqr(vs.v_[0]);
397  return ms;
398 }
399 
400 
401 template<class Form, class Cmpt, direction Ncmpts>
402 inline scalar mag
403 (
405 )
406 {
407  return ::sqrt(magSqr(static_cast<const Form&>(vs)));
408 }
409 
410 
411 template<class Form, class Cmpt, direction Ncmpts>
412 inline Form normalised
413 (
415 )
416 {
417  const scalar magVs = mag(vs);
418  return magVs > 0 ? vs/magVs : Zero;
419 }
420 
421 
422 template<class Form, class Cmpt, direction Ncmpts>
424 (
427 )
428 {
429  Form v;
431  return v;
432 }
433 
434 
435 template<class Form, class Cmpt, direction Ncmpts>
437 (
440 )
441 {
442  Form v;
444  return v;
445 }
446 
447 
448 template<class Form, class Cmpt, direction Ncmpts>
450 (
453 )
454 {
455  Form v;
457  return v;
458 }
459 
460 
461 template<class Form, class Cmpt, direction Ncmpts>
463 (
465  const Cmpt& small
466 )
467 {
468  Form v;
470  return v;
471 }
472 
473 
474 template<class Form, class Cmpt, direction Ncmpts>
475 inline Cmpt cmptMax
476 (
478 )
479 {
480  Cmpt cMax = vs.v_[0];
482  return cMax;
483 }
484 
485 
486 template<class Form, class Cmpt, direction Ncmpts>
487 inline Cmpt cmptMin
488 (
490 )
491 {
492  Cmpt cMin = vs.v_[0];
494  return cMin;
495 }
496 
497 
498 template<class Form, class Cmpt, direction Ncmpts>
499 inline Cmpt cmptSum
500 (
502 )
503 {
504  Cmpt sum = vs.v_[0];
506  return sum;
507 }
508 
509 
510 template<class Form, class Cmpt, direction Ncmpts>
511 inline Cmpt cmptAv
512 (
514 )
515 {
516  return cmptSum(vs)/Ncmpts;
517 }
518 
519 template<class Form, class Cmpt, direction Ncmpts>
520 inline Cmpt cmptProduct
521 (
523 )
524 {
525  Cmpt product = vs.v_[0];
527  return product;
528 }
529 
530 
531 template<class Form, class Cmpt, direction Ncmpts>
532 inline Form cmptSqr
533 (
535 )
536 {
537  Form v;
539  return v;
540 }
541 
542 
543 template<class Form, class Cmpt, direction Ncmpts>
544 inline Form cmptMag
545 (
547 )
548 {
549  Form v;
551  return v;
552 }
553 
554 
555 template<class Form, class Cmpt, direction Ncmpts>
556 inline Form max
557 (
560 )
561 {
562  Form v;
564  return v;
565 }
566 
567 
568 template<class Form, class Cmpt, direction Ncmpts>
569 inline Form min
570 (
573 )
574 {
575  Form v;
577  return v;
578 }
579 
580 
581 template<class Form, class Cmpt, direction Ncmpts>
582 inline Form minMod
583 (
586 )
587 {
588  Form v;
590  return v;
591 }
592 
593 
594 template<class Type>
595 inline Type dot(const scalar s, const Type& t)
596 {
597  return s * t;
598 }
599 
600 
601 template<class Type>
602 inline Type dot(const Type& t, const scalar s)
603 {
604  return t * s;
605 }
606 
607 
608 template
609 <
610  class Form1, class Cmpt1, direction Ncmpts1,
611  class Form2, class Cmpt2, direction Ncmpts2
612 >
614 (
617 )
618 {
619  return static_cast<const Form1&>(t1) & static_cast<const Form2&>(t2);
620 }
621 
622 
623 template<class Form, class Cmpt, direction Ncmpts>
625 {
626  direction index = 0;
627  for (direction i=1; i<Ncmpts; ++i)
628  {
629  index = vs[index] > vs[i] ? index : i;
630  }
631  return index;
632 }
633 
634 
635 template<class Form, class Cmpt, direction Ncmpts>
637 {
638  direction index = 0;
639  for (direction i=1; i<Ncmpts; ++i)
640  {
641  index = vs[index] < vs[i] ? index : i;
642  }
643  return index;
644 }
645 
646 
647 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
648 
649 template<class Form, class Cmpt, direction Ncmpts>
650 inline Form operator-
651 (
653 )
654 {
655  Form v;
657  return v;
658 }
659 
660 
661 template<class Form, class Cmpt, direction Ncmpts>
662 inline Form operator+
663 (
666 )
667 {
668  Form v;
670  return v;
671 }
672 
673 template<class Form, class Cmpt, direction Ncmpts>
674 inline Form operator-
675 (
678 )
679 {
680  Form v;
682  return v;
683 }
684 
685 
686 template<class Form, class Cmpt, direction Ncmpts>
687 inline Form operator*
688 (
689  scalar s,
691 )
692 {
693  Form v;
695  return v;
696 }
697 
698 
699 template<class Form, class Cmpt, direction Ncmpts>
700 inline Form operator*
701 (
703  scalar s
704 )
705 {
706  Form v;
708  return v;
709 }
710 
711 
712 template<class Form, class Cmpt, direction Ncmpts>
713 inline Form operator/
714 (
716  scalar s
717 )
718 {
719  Form v;
721  return v;
722 }
723 
724 /*
725 template<class Form, class Cmpt, direction Ncmpts>
726 inline Form operator/
727 (
728  const VectorSpace<Form, Cmpt, Ncmpts>& vs1,
729  const VectorSpace<Form, Cmpt, Ncmpts>& vs2
730 )
731 {
732  Form v;
733  VectorSpaceOps<Ncmpts,0>::op(v, vs1, vs2, divideOp<Cmpt>());
734  return v;
735 }
736 
737 
738 template<class Form, class Cmpt, direction Ncmpts>
739 inline Form operator/
740 (
741  scalar s,
742  const VectorSpace<Form, Cmpt, Ncmpts>& vs
743 )
744 {
745  Form v;
746  VectorSpaceOps<Ncmpts,0>::opSV(v, s, vs, divideOp2<scalar, Cmpt>());
747  return v;
748 }
749 */
750 
751 
752 template<class Form, class Cmpt, direction Ncmpts>
753 inline Cmpt operator&&
754 (
757 )
758 {
759  Cmpt ddProd = vs1.v_[0]*vs2.v_[0];
760  for (direction i=1; i<Ncmpts; ++i)
761  {
762  ddProd += vs1.v_[i]*vs2.v_[i];
763  }
764  return ddProd;
765 }
766 
767 
768 template<class Form, class Cmpt, direction Ncmpts>
769 inline bool operator==
770 (
773 )
774 {
775  bool eq = true;
776  for (direction i=0; i<Ncmpts; ++i)
777  {
778  if (!(eq &= (equal(vs1.v_[i], vs2.v_[i])))) break;
779  }
780  return eq;
781 }
782 
783 
784 template<class Form, class Cmpt, direction Ncmpts>
785 inline bool operator!=
786 (
789 )
790 {
791  return !(vs1 == vs2);
792 }
793 
794 
795 template<class Form, class Cmpt, direction Ncmpts>
796 inline bool operator>
797 (
800 )
801 {
802  bool gt = true;
803  for (direction i=0; i<Ncmpts; ++i)
804  {
805  if (!(gt &= vs1.v_[i] > vs2.v_[i])) break;
806  }
807  return gt;
808 }
809 
810 
811 template<class Form, class Cmpt, direction Ncmpts>
812 inline bool operator<
813 (
816 )
817 {
818  bool lt = true;
819  for (direction i=0; i<Ncmpts; ++i)
820  {
821  if (!(lt &= vs1.v_[i] < vs2.v_[i])) break;
822  }
823  return lt;
824 }
825 
826 
827 template<class Form, class Cmpt, direction Ncmpts>
828 inline bool operator>=
829 (
832 )
833 {
834  return !(vs1 < vs2);
835 }
836 
837 
838 template<class Form, class Cmpt, direction Ncmpts>
839 inline bool operator<=
840 (
843 )
844 {
845  return !(vs1 > vs2);
846 }
847 
848 
849 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
850 
851 } // End namespace Foam
852 
853 // ************************************************************************* //
static void opVS(V &vs, const V1 &vs1, const S &s, Op o)
static void opSV(V &vs, const S &s, const V1 &vs1, Op o)
static void SeqOp(S &s, const V &vs, EqOp eo)
static void eqOpS(V &vs, const S &s, EqOp eo)
static void eqOp(V1 &vs1, const V2 &vs2, EqOp eo)
static void op(V &vs, const V1 &vs1, const V1 &vs2, Op o)
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:136
Templated vector space.
Definition: VectorSpace.H:79
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:91
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:99
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:149
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:40
static const Form max
Definition: VectorSpace.H:115
const ConstBlock< SubVector, BStart > block() const
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:84
static Form uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
Definition: VectorSpaceI.H:168
static const Form min
Definition: VectorSpace.H:116
static direction size()
Return the number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpaceI.H:83
void operator=(const Foam::zero)
Definition: VectorSpaceI.H:299
Definition: ops.H:70
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) - 2 >::type type
Definition: products.H:115
Traits class for primitives.
Definition: pTraits.H:53
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:136
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
label findMax(const ListType &, const label start=0)
Find index of max element (and larger than given element).
Cmpt cmptProduct(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:521
label & setComponent(label &l, const direction)
Definition: label.H:86
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Scalar minMod(const Scalar s1, const Scalar s2)
Definition: Scalar.H:227
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
Form normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:413
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionSet cmptMag(const dimensionSet &)
Definition: dimensionSet.C:275
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
label findMin(const ListType &, const label start=0)
Find index of min element (and less than given element).
Scalar cmptPow(const Scalar s1, const Scalar s2)
Definition: Scalar.H:293
error FatalError
Cmpt cmptSum(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:500
dimensioned< scalar > magSqr(const dimensioned< Type > &)
uint8_t direction
Definition: direction.H:45
Scalar cmptSqr(const Scalar s)
Definition: Scalar.H:323
Combination-Reduction operation for a parallel run.
Traits classes for inner and outer products of primitives.