FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/error.H>
27 #include "products.H"
28 #include "VectorSpaceM.H"
29 #include <OpenFOAM/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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 template<class Form, class Cmpt, int nCmpt>
57 {
58  return nCmpt;
59 }
60 
61 
62 template<class Form, class Cmpt, int nCmpt>
64 (
65  const direction d
66 ) const
67 {
68 # ifdef FULLDEBUG
69  if (d >= nCmpt)
70  {
72  (
73  "VectorSpace<Form, Cmpt, nCmpt>::component(direction) const"
74  ) << "index out of range"
75  << abort(FatalError);
76  }
77 # endif
78 
79  return v_[d];
80 }
81 
82 
83 template<class Form, class Cmpt, int nCmpt>
85 (
86  const direction d
87 )
88 {
89 # ifdef FULLDEBUG
90  if (d >= nCmpt)
91  {
92  FatalErrorIn("VectorSpace<Form, Cmpt, nCmpt>::component(direction)")
93  << "index out of range"
94  << abort(FatalError);
95  }
96 # endif
97 
98  return v_[d];
99 }
100 
101 
102 template<class Form, class Cmpt, int nCmpt>
104 (
105  Cmpt& c,
106  const direction d
107 ) const
108 {
109 # ifdef FULLDEBUG
110  if (d >= nCmpt)
111  {
113  (
114  "VectorSpace<Form, Cmpt, nCmpt>::component(Cmpt&, direction) const"
115  ) << "index out of range"
116  << abort(FatalError);
117  }
118 # endif
119 
120  c = v_[d];
121 }
122 
123 
124 template<class Form, class Cmpt, int nCmpt>
126 (
127  const direction d,
128  const Cmpt& c
129 )
130 {
131 # ifdef FULLDEBUG
132  if (d >= nCmpt)
133  {
135  (
136  "VectorSpace<Form, Cmpt, nCmpt>::"
137  "replace(direction, const Cmpt&) const"
138  ) << "index out of range"
139  << abort(FatalError);
140  }
141 # endif
142 
143  v_[d] = c;
144 }
145 
146 
147 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
148 
149 template<class Form, class Cmpt, int nCmpt>
150 inline const Cmpt& VectorSpace<Form, Cmpt, nCmpt>::operator[]
151 (
152  const direction d
153 ) const
154 {
155 # ifdef FULLDEBUG
156  if (d >= nCmpt)
157  {
159  (
160  "VectorSpace<Form, Cmpt, nCmpt>::operator[](direction d) const"
161  ) << "index out of range"
162  << abort(FatalError);
163  }
164 # endif
165 
166  return v_[d];
167 }
168 
169 
170 template<class Form, class Cmpt, int nCmpt>
172 (
173  const direction d
174 )
175 {
176 # ifdef FULLDEBUG
177  if (d >= nCmpt)
178  {
179  FatalErrorIn("VectorSpace<Form, Cmpt, nCmpt>::operator[](direction d)")
180  << "index out of range"
181  << abort(FatalError);
182  }
183 # endif
184 
185  return v_[d];
186 }
187 
188 
189 template<class Form, class Cmpt, int nCmpt>
191 (
193 )
194 {
196 }
197 
198 
199 template<class Form, class Cmpt, int nCmpt>
201 (
203 )
204 {
206 }
207 
208 
209 template<class Form, class Cmpt, int nCmpt>
211 (
213 )
214 {
216 }
217 
218 
219 template<class Form, class Cmpt, int nCmpt>
221 (
222  const scalar s
223 )
224 {
226 }
227 
228 
229 template<class Form, class Cmpt, int nCmpt>
231 (
232  const scalar s
233 )
234 {
236 }
237 
238 
239 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
240 
241 template<class Form, class Cmpt, int nCmpt>
242 inline Cmpt& setComponent
243 (
245  const direction d
246 )
247 {
248  return vs.component(d);
249 }
250 
251 
252 template<class Form, class Cmpt, int nCmpt>
253 inline const Cmpt& component
254 (
256  const direction d
257 )
258 {
259  return vs.component(d);
260 }
261 
262 
263 // Powers of a Form
264 // Equivalent to outer-products between the Form and itself
265 // Form^0 = 1.0
266 template<class Form, class Cmpt, int nCmpt>
267 inline typename powProduct<Form, 0>::type pow
268 (
272 )
273 {
274  return 1.0;
275 }
276 
277 // Form^1 = Form
278 template<class Form, class Cmpt, int nCmpt>
279 inline typename powProduct<Form, 1>::type pow
280 (
284 )
285 {
286  return static_cast<const Form&>(v);
287 }
288 
289 
290 // Form^2 = sqr(Form)
291 template<class Form, class Cmpt, int nCmpt>
292 inline typename powProduct<Form, 2>::type pow
293 (
297 )
298 {
299  return sqr(static_cast<const Form&>(v));
300 }
301 
302 
303 template<class Form, class Cmpt, int nCmpt>
304 inline scalar magSqr
305 (
307 )
308 {
309  scalar ms = magSqr(vs.v_[0]);
311  return ms;
312 }
313 
314 
315 template<class Form, class Cmpt, int nCmpt>
316 inline scalar mag
317 (
319 )
320 {
321  return ::sqrt(magSqr(static_cast<const Form&>(vs)));
322 }
323 
324 
325 template<class Form, class Cmpt, int nCmpt>
326 inline VectorSpace<Form, Cmpt, nCmpt> cmptMultiply
327 (
330 )
331 {
332  Form v;
334  return v;
335 }
336 
337 
338 template<class Form, class Cmpt, int nCmpt>
339 inline VectorSpace<Form, Cmpt, nCmpt> cmptDivide
340 (
343 )
344 {
345  Form v;
347  return v;
348 }
349 
350 
351 template<class Form, class Cmpt, int nCmpt>
352 inline VectorSpace<Form, Cmpt, nCmpt> stabilise
353 (
355  const Cmpt& small
356 )
357 {
358  Form v;
360  return v;
361 }
362 
363 
364 template<class Form, class Cmpt, int nCmpt>
365 inline Cmpt cmptMax
366 (
368 )
369 {
370  Cmpt cMax = vs.v_[0];
372  return cMax;
373 }
374 
375 
376 template<class Form, class Cmpt, int nCmpt>
377 inline Cmpt cmptMin
378 (
380 )
381 {
382  Cmpt cMin = vs.v_[0];
384  return cMin;
385 }
386 
387 
388 template<class Form, class Cmpt, int nCmpt>
389 inline Cmpt cmptSum
390 (
392 )
393 {
394  Cmpt sum = vs.v_[0];
396  return sum;
397 }
398 
399 
400 template<class Form, class Cmpt, int nCmpt>
401 inline Cmpt cmptAv
402 (
404 )
405 {
406  return cmptSum(vs)/nCmpt;
407 }
408 
409 
410 template<class Form, class Cmpt, int nCmpt>
411 inline Form cmptMag
412 (
414 )
415 {
416  Form v;
418  return v;
419 }
420 
421 
422 template<class Form, class Cmpt, int nCmpt>
423 inline Form max
424 (
427 )
428 {
429  Form v;
431  return v;
432 }
433 
434 
435 template<class Form, class Cmpt, int nCmpt>
436 inline Form min
437 (
440 )
441 {
442  Form v;
444  return v;
445 }
446 
447 
448 template<class Form, class Cmpt, int nCmpt>
449 inline Form minMod
450 (
453 )
454 {
455  Form v;
457  return v;
458 }
459 
460 
461 template<class Type>
462 inline Type dot(const scalar s, const Type& t)
463 {
464  return s * t;
465 }
466 
467 
468 template<class Type>
469 inline Type dot(const Type& t, const scalar s)
470 {
471  return t * s;
472 }
473 
474 
475 template
476 <
477  class Form1, class Cmpt1, int nCmpt1,
478  class Form2, class Cmpt2, int nCmpt2
479 >
481 (
484 )
485 {
486  return static_cast<const Form1&>(t1) & static_cast<const Form2&>(t2);
487 }
488 
489 
490 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
491 
492 template<class Form, class Cmpt, int nCmpt>
493 inline Form operator-
494 (
496 )
497 {
498  Form v;
500  return v;
501 }
502 
503 
504 template<class Form, class Cmpt, int nCmpt>
505 inline Form operator+
506 (
509 )
510 {
511  Form v;
513  return v;
514 }
515 
516 template<class Form, class Cmpt, int nCmpt>
517 inline Form operator-
518 (
521 )
522 {
523  Form v;
525  return v;
526 }
527 
528 
529 template<class Form, class Cmpt, int nCmpt>
530 inline Form operator*
531 (
532  scalar s,
534 )
535 {
536  Form v;
538  return v;
539 }
540 
541 
542 template<class Form, class Cmpt, int nCmpt>
543 inline Form operator*
544 (
546  scalar s
547 )
548 {
549  Form v;
551  return v;
552 }
553 
554 
555 template<class Form, class Cmpt, int nCmpt>
556 inline Form operator/
557 (
559  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 (
571  const VectorSpace<Form, Cmpt, nCmpt>& vs1,
572  const VectorSpace<Form, Cmpt, nCmpt>& vs2
573 )
574 {
575  Form v;
576  VectorSpaceOps<nCmpt,0>::op(v, vs1, vs2, divideOp<Cmpt>());
577  return v;
578 }
579 
580 
581 template<class Form, class Cmpt, int nCmpt>
582 inline Form operator/
583 (
584  scalar s,
585  const VectorSpace<Form, Cmpt, nCmpt>& vs
586 )
587 {
588  Form v;
589  VectorSpaceOps<nCmpt,0>::opSV(v, s, vs, divideOp2<scalar, Cmpt>());
590  return v;
591 }
592 */
593 
594 
595 template<class Form, class Cmpt, int nCmpt>
596 inline Cmpt operator&&
597 (
600 )
601 {
602  Cmpt ddProd = vs1.v_[0]*vs2.v_[0];
603  for (int i=1; i<nCmpt; ++i)
604  {
605  ddProd += vs1.v_[i]*vs2.v_[i];
606  }
607  return ddProd;
608 }
609 
610 
611 template<class Form, class Cmpt, int nCmpt>
612 inline bool operator==
613 (
616 )
617 {
618  bool eq = true;
619  for (int i=0; i<nCmpt; ++i)
620  {
621  if (!(eq &= (equal(vs1.v_[i], vs2.v_[i])))) break;
622  }
623  return eq;
624 }
625 
626 
627 template<class Form, class Cmpt, int nCmpt>
628 inline bool operator!=
629 (
632 )
633 {
634  return !(vs1 == vs2);
635 }
636 
637 
638 template<class Form, class Cmpt, int nCmpt>
639 inline bool operator>
640 (
643 )
644 {
645  bool gt = true;
646  for (int i=0; i<nCmpt; ++i)
647  {
648  if (!(gt &= vs1.v_[i] > vs2.v_[i])) break;
649  }
650  return gt;
651 }
652 
653 
654 template<class Form, class Cmpt, int nCmpt>
655 inline bool operator<
656 (
659 )
660 {
661  bool lt = true;
662  for (int i=0; i<nCmpt; ++i)
663  {
664  if (!(lt &= vs1.v_[i] < vs2.v_[i])) break;
665  }
666  return lt;
667 }
668 
669 
670 template<class Form, class Cmpt, int nCmpt>
671 inline bool operator>=
672 (
675 )
676 {
677  return !(vs1 < vs2);
678 }
679 
680 
681 template<class Form, class Cmpt, int nCmpt>
682 inline bool operator<=
683 (
686 )
687 {
688  return !(vs1 > vs2);
689 }
690 
691 
692 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
693 
694 } // End namespace Foam
695 
696 // ************************ vim: set sw=4 sts=4 et: ************************ //