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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2019-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "error.H"
30#include "products.H"
31#include "VectorSpaceOps.H"
32#include "ops.H"
33#include <type_traits>
34
35// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36
37template<class Form, class Cmpt, Foam::direction Ncmpts>
39{
41}
42
43
44template<class Form, class Cmpt, Foam::direction Ncmpts>
46(
48)
49{
51}
52
53
54template<class Form, class Cmpt, Foam::direction Ncmpts>
55template<class Form2, class Cmpt2>
57(
59)
60{
62}
63
64
65template<class Form, class Cmpt, Foam::direction Ncmpts>
66template<class SubVector, Foam::direction BStart>
69(
70 const vsType& vs
71)
72:
73 vs_(vs)
74{
75 static_assert
76 (
78 "Requested block size > VectorSpace size"
79 );
80}
81
82
83// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84
85template<class Form, class Cmpt, Foam::direction Ncmpts>
87(
88 const direction d
89) const
90{
91 #ifdef FULLDEBUG
92 if (d >= Ncmpts)
93 {
95 << "index out of range"
96 << abort(FatalError);
97 }
98 #endif
99
100 return v_[d];
101}
102
103
104template<class Form, class Cmpt, Foam::direction Ncmpts>
106(
107 const direction d
108)
109{
110 #ifdef FULLDEBUG
111 if (d >= Ncmpts)
112 {
114 << "index out of range"
115 << abort(FatalError);
116 }
117 #endif
118
119 return v_[d];
120}
121
122
123template<class Form, class Cmpt, Foam::direction Ncmpts>
125(
126 Cmpt& c,
127 const direction d
128) const
129{
130 #ifdef FULLDEBUG
131 if (d >= Ncmpts)
132 {
134 << "index out of range"
135 << abort(FatalError);
136 }
137 #endif
138
139 c = v_[d];
141
142
143template<class Form, class Cmpt, Foam::direction Ncmpts>
145(
146 const direction d,
147 const Cmpt& c
148)
149{
150 #ifdef FULLDEBUG
151 if (d >= Ncmpts)
152 {
154 << "index out of range"
155 << abort(FatalError);
156 }
157 #endif
158
159 v_[d] = c;
161
162
163template<class Form, class Cmpt, Foam::direction Ncmpts>
165{
166 Form v;
168 return v;
169}
170
171
172template<class Form, class Cmpt, Foam::direction Ncmpts>
173template<class SubVector, Foam::direction BStart>
175 ConstBlock<SubVector, BStart>
177{
178 return *this;
179}
180
182// * * * * * * * * * * * * * * * * Iterator * * * * * * * * * * * * * * * * //
183
184template<class Form, class Cmpt, Foam::direction Ncmpts>
186{
187 return v_;
189
190
191template<class Form, class Cmpt, Foam::direction Ncmpts>
193{
194 return v_;
195}
196
197
198template<class Form, class Cmpt, Foam::direction Ncmpts>
200{
201 return v_;
204
205template<class Form, class Cmpt, Foam::direction Ncmpts>
208 return (v_ + Ncmpts);
212template<class Form, class Cmpt, Foam::direction Ncmpts>
214const noexcept
215{
216 return v_;
217}
218
219
220template<class Form, class Cmpt, Foam::direction Ncmpts>
222const noexcept
223{
224 return (v_ + Ncmpts);
225}
227
228template<class Form, class Cmpt, Foam::direction Ncmpts>
230const noexcept
231{
232 return v_;
233}
234
236template<class Form, class Cmpt, Foam::direction Ncmpts>
239{
240 return (v_ + Ncmpts);
242
243
244// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
245
246template<class Form, class Cmpt, Foam::direction Ncmpts>
248(
249 const direction d
250) const
251{
252 #ifdef FULLDEBUG
253 if (d >= Ncmpts)
254 {
256 << "index out of range"
257 << abort(FatalError);
258 }
259 #endif
260
261 return v_[d];
262}
263
264
265template<class Form, class Cmpt, Foam::direction Ncmpts>
267(
268 const direction d
269)
270{
271 #ifdef FULLDEBUG
272 if (d >= Ncmpts)
273 {
275 << "index out of range"
276 << abort(FatalError);
277 }
278 #endif
279
280 return v_[d];
281}
282
283
284template<class Form, class Cmpt, Foam::direction Ncmpts>
285template<class SubVector, Foam::direction BStart>
286inline const Cmpt&
289(
290 const direction d
291) const
292{
293 #ifdef FULLDEBUG
294 if (d >= Ncmpts)
295 {
297 << "index out of range"
298 << abort(FatalError);
299 }
300 #endif
301
302 return vs_[BStart + d];
303}
304
305
306template<class Form, class Cmpt, Foam::direction Ncmpts>
307template<class SubVector, Foam::direction BStart>
308inline const Cmpt&
311(
312 const direction i,
313 const direction j
314) const
315{
316 #ifdef FULLDEBUG
317 if (i >= Ncmpts)
318 {
320 << "index " << i << " out of range"
321 << abort(FatalError);
322 }
323
324 if (j)
325 {
327 << "index " << j << " != 0"
328 << abort(FatalError);
329 }
330 #endif
331
332 return vs_[BStart + i];
333}
334
335
336template<class Form, class Cmpt, Foam::direction Ncmpts>
338(
340)
341{
343}
344
345
346template<class Form, class Cmpt, Foam::direction Ncmpts>
348(
350)
351{
353}
354
355
356template<class Form, class Cmpt, Foam::direction Ncmpts>
358(
360)
361{
363}
364
365
366template<class Form, class Cmpt, Foam::direction Ncmpts>
368{
370}
371
372
373template<class Form, class Cmpt, Foam::direction Ncmpts>
375(
376 const scalar s
377)
378{
380}
381
382
383template<class Form, class Cmpt, Foam::direction Ncmpts>
385(
386 const scalar s
387)
388{
390}
391
392
393// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394
395namespace Foam
396{
397
398// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
399
400template<class Form, class Cmpt, direction Ncmpts>
401inline Cmpt& setComponent
402(
404 const direction d
405)
406{
407 return vs.component(d);
408}
409
410
411template<class Form, class Cmpt, direction Ncmpts>
412inline const Cmpt& component
413(
415 const direction d
416)
417{
418 return vs.component(d);
419}
420
421
422// Powers of a Form
423// Equivalent to outer-products between the Form and itself
424// Form^0 = 1.0
425template<class Form, class Cmpt, direction Ncmpts>
427(
430 = pTraits<typename powProduct<Form, 0>::type>::zero
431)
432{
433 return 1.0;
434}
435
436
437// Form^1 = Form
438template<class Form, class Cmpt, direction Ncmpts>
440(
443 = pTraits<typename powProduct<Form, 1>::type>::zero
444)
445{
446 return static_cast<const Form&>(v);
447}
448
449
450// Form^2 = sqr(Form)
451template<class Form, class Cmpt, direction Ncmpts>
453(
456 = pTraits<typename powProduct<Form, 2>::type>::zero
457)
458{
459 return sqr(static_cast<const Form&>(v));
460}
461
462
463template<class Form, class Cmpt, direction Ncmpts>
464inline scalar magSqr
465(
467)
468{
469 scalar ms = magSqr(vs.v_[0]);
471 return ms;
472}
473
474
475template<class Form, class Cmpt, direction Ncmpts>
476inline scalar mag
477(
479)
480{
481 return ::sqrt(magSqr(static_cast<const Form&>(vs)));
482}
483
484
485//- Return the vector type normalised by its magnitude
486// For small magnitudes (less than ROOTVSMALL) return zero.
487template<class Form, class Cmpt, direction Ncmpts>
489(
491)
492{
493 const scalar s(mag(vs));
494 return s < ROOTVSMALL ? Zero : vs/s;
495}
496
497
498template<class Form, class Cmpt, direction Ncmpts>
500(
503)
504{
505 Form v;
507 return v;
508}
509
510
511template<class Form, class Cmpt, direction Ncmpts>
513(
516)
517{
518 Form v;
520 return v;
521}
522
523
524template<class Form, class Cmpt, direction Ncmpts>
526(
529)
530{
531 Form v;
533 return v;
534}
535
536
537template<class Form, class Cmpt, direction Ncmpts>
539(
541 const Cmpt& small
542)
543{
544 Form v;
546 return v;
547}
548
549
550template<class Form, class Cmpt, direction Ncmpts>
551inline Cmpt cmptMax
552(
554)
555{
556 Cmpt cMax = vs.v_[0];
558 return cMax;
559}
560
561
562template<class Form, class Cmpt, direction Ncmpts>
563inline Cmpt cmptMin
564(
566)
567{
568 Cmpt cMin = vs.v_[0];
570 return cMin;
571}
572
573
574template<class Form, class Cmpt, direction Ncmpts>
575inline Cmpt cmptSum
576(
578)
579{
580 Cmpt sum = vs.v_[0];
582 return sum;
583}
584
585
586template<class Form, class Cmpt, direction Ncmpts>
587inline Cmpt cmptAv
588(
590)
591{
592 return cmptSum(vs)/Ncmpts;
593}
594
595
596template<class Form, class Cmpt, direction Ncmpts>
597inline Cmpt cmptProduct
598(
600)
601{
602 Cmpt product = vs.v_[0];
604 return product;
605}
606
607
608template<class Form, class Cmpt, direction Ncmpts>
609inline Form cmptSqr
610(
612)
613{
614 Form v;
616 return v;
617}
618
619
620template<class Form, class Cmpt, direction Ncmpts>
621inline Form cmptMag
622(
624)
625{
626 Form v;
628 return v;
629}
630
631
632template<class Form, class Cmpt, direction Ncmpts>
633inline Form cmptMagSqr
634(
636)
637{
638 Form v;
640 return v;
641}
642
643
644template<class Form, class Cmpt, direction Ncmpts>
645inline Form max
646(
649)
650{
651 Form v;
653 return v;
654}
655
656
657template<class Form, class Cmpt, direction Ncmpts>
658inline Form min
659(
662)
663{
664 Form v;
666 return v;
667}
668
669
670template<class Form, class Cmpt, direction Ncmpts>
671inline Form minMod
672(
675)
676{
677 Form v;
679 return v;
680}
681
682
683template<class Type>
684inline Type dot(const scalar s, const Type& t)
685{
686 return s * t;
687}
688
689
690template<class Type>
691inline Type dot(const Type& t, const scalar s)
692{
693 return t * s;
694}
695
696
697template
698<
699 class Form1, class Cmpt1, direction Ncmpts1,
700 class Form2, class Cmpt2, direction Ncmpts2
701>
703(
706)
707{
708 return static_cast<const Form1&>(t1) & static_cast<const Form2&>(t2);
709}
710
711
712// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
713
714template<class Form, class Cmpt, direction Ncmpts>
715inline Form operator-
716(
718)
719{
720 Form v;
722 return v;
723}
724
725
726template<class Form, class Cmpt, direction Ncmpts>
727inline Form operator+
728(
731)
732{
733 Form v;
735 return v;
736}
737
738template<class Form, class Cmpt, direction Ncmpts>
739inline Form operator-
740(
743)
744{
745 Form v;
747 return v;
748}
749
750
751template<class Form, class Cmpt, direction Ncmpts>
752inline Form operator*
753(
754 scalar s,
756)
757{
758 Form v;
760 return v;
761}
762
763
764template<class Form, class Cmpt, direction Ncmpts>
765inline Form operator*
766(
768 scalar s
769)
770{
771 Form v;
773 return v;
774}
775
776
777template<class Form, class Cmpt, direction Ncmpts>
778inline Form operator/
779(
781 scalar s
782)
783{
784 Form v;
786 return v;
787}
788
789/*
790template<class Form, class Cmpt, direction Ncmpts>
791inline Form operator/
792(
793 const VectorSpace<Form, Cmpt, Ncmpts>& vs1,
794 const VectorSpace<Form, Cmpt, Ncmpts>& vs2
795)
796{
797 Form v;
798 VectorSpaceOps<Ncmpts,0>::op(v, vs1, vs2, divideOp<Cmpt>());
799 return v;
800}
801
802
803template<class Form, class Cmpt, direction Ncmpts>
804inline Form operator/
805(
806 scalar s,
807 const VectorSpace<Form, Cmpt, Ncmpts>& vs
808)
809{
810 Form v;
811 VectorSpaceOps<Ncmpts,0>::opSV(v, s, vs, divideOp2<scalar, Cmpt>());
812 return v;
813}
814*/
815
816
817template<class Form, class Cmpt, direction Ncmpts>
818inline Cmpt operator&&
819(
822)
823{
824 Cmpt ddProd = vs1.v_[0]*vs2.v_[0];
825 for (direction i=1; i<Ncmpts; ++i)
826 {
827 ddProd += vs1.v_[i]*vs2.v_[i];
828 }
829 return ddProd;
830}
831
832
833template<class Form, class Cmpt, direction Ncmpts>
834inline bool operator==
835(
838)
839{
840 for (direction i=0; i<Ncmpts; ++i)
841 {
842 if (!equal(vs1.v_[i], vs2.v_[i])) return false;
843 }
844 return true;
845}
846
847
848template<class Form, class Cmpt, direction Ncmpts>
849inline bool operator!=
850(
853)
854{
855 return !(vs1 == vs2);
856}
857
858
859template<class Form, class Cmpt, direction Ncmpts>
860inline bool operator>
861(
864)
865{
866 for (direction i=0; i<Ncmpts; ++i)
867 {
868 if (!(vs1.v_[i] > vs2.v_[i])) return false;
869 }
870 return true;
871}
872
873
874template<class Form, class Cmpt, direction Ncmpts>
875inline bool operator<
876(
879)
880{
881 for (direction i=0; i<Ncmpts; ++i)
882 {
883 if (!(vs1.v_[i] < vs2.v_[i])) return false;
884 }
885 return true;
886}
887
888
889template<class Form, class Cmpt, direction Ncmpts>
890inline bool operator>=
891(
894)
895{
896 return !(vs1 < vs2);
897}
898
899
900template<class Form, class Cmpt, direction Ncmpts>
901inline bool operator<=
902(
905)
906{
907 return !(vs1 > vs2);
908}
909
910
911// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
912
913} // End namespace Foam
914
915// ************************************************************************* //
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:134
Templated vector space.
Definition: VectorSpace.H:79
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:87
Cmpt * data() noexcept
Return pointer to the first data element.
Definition: VectorSpaceI.H:185
void operator=(const VectorSpace< Form, Cmpt, Ncmpts > &)
Definition: VectorSpaceI.H:338
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:145
const ConstBlock< SubVector, BStart > block() const
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101
const Cmpt * cdata() const noexcept
Return const pointer to the first data element.
Definition: VectorSpaceI.H:192
iterator end() noexcept
Return an iterator to end of VectorSpace.
Definition: VectorSpaceI.H:206
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:83
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
const_iterator cend() const noexcept
Return const_iterator to end of VectorSpace.
Definition: VectorSpaceI.H:221
VectorSpace()=default
Default construct.
iterator begin() noexcept
Return an iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:199
const_iterator cbegin() const noexcept
Return const_iterator to begin of VectorSpace.
Definition: VectorSpaceI.H:213
Particle-size distribution model wherein random samples are drawn from the doubly-truncated uniform p...
Definition: uniform.H:164
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
type
Volume classification types.
Definition: volumeType.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensionedSymmTensor sqr(const dimensionedVector &dv)
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
Definition: quaternionI.H:680
Scalar minMod(const Scalar s1, const Scalar s2)
Definition: Scalar.H:303
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Scalar cmptPow(const Scalar s1, const Scalar s2)
Definition: Scalar.H:369
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components)
Definition: label.H:123
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Scalar cmptSqr(const Scalar s)
Definition: Scalar.H:399
Cmpt cmptProduct(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:598
Cmpt cmptSum(const SphericalTensor< Cmpt > &st)
Return the sum of components of a SphericalTensor.
void cmptMagSqr(Field< Type > &res, const UList< 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)
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
uint8_t direction
Definition: direction.H:56
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensionedScalar stabilise(const dimensionedScalar &x, const dimensionedScalar &y)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
const direction noexcept
Definition: Scalar.H:223
error FatalError
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh > > cmptAv(const DimensionedField< Type, GeoMesh > &df)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Various functors for unary and binary operations. Can be used for parallel combine-reduce operations ...
Traits classes for inner and outer products of primitives.
General looping form. Executing at index <I> with termination at <N>
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 op(V &vs, const V1 &vs1, const V1 &vs2, Op o)
Definition: ops.H:71