LORENE
tensor_calculus_ext.C
1/*
2 * Function external to class Tensor for tensor calculus
3 *
4 *
5 */
6
7/*
8 * Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak
9 *
10 * Copyright (c) 1999-2001 Philippe Grandclement (for preceding class Tenseur)
11 *
12 * This file is part of LORENE.
13 *
14 * LORENE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * LORENE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with LORENE; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30
31
32
33/*
34 * $Id: tensor_calculus_ext.C,v 1.15 2016/12/05 16:18:17 j_novak Exp $
35 * $Log: tensor_calculus_ext.C,v $
36 * Revision 1.15 2016/12/05 16:18:17 j_novak
37 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
38 *
39 * Revision 1.14 2014/10/13 08:53:44 j_novak
40 * Lorene classes and functions now belong to the namespace Lorene.
41 *
42 * Revision 1.13 2014/10/06 15:13:20 j_novak
43 * Modified #include directives to use c++ syntax.
44 *
45 * Revision 1.12 2008/12/05 08:44:02 j_novak
46 * New flag to control the "verbosity" of maxabs.
47 *
48 * Revision 1.11 2004/05/13 21:32:29 e_gourgoulhon
49 * Added functions central_value, max_all_domains,
50 * min_all_domains and maxabs_all_domains.
51 *
52 * Revision 1.10 2004/02/27 21:15:34 e_gourgoulhon
53 * Suppressed function contract_desal (since function contract has now
54 * the boolean argument "desaliasing").
55 *
56 * Revision 1.9 2004/02/19 22:11:00 e_gourgoulhon
57 * Added argument "comment" in functions max, min, etc...
58 *
59 * Revision 1.8 2004/02/18 18:51:04 e_gourgoulhon
60 * Tensorial product moved from file tensor_calculus.C, since
61 * it is not a method of class Tensor.
62 *
63 * Revision 1.7 2004/02/18 15:56:23 e_gourgoulhon
64 * -- Added function contract for double contraction.
65 * -- Efficiency improved in functions contract: better handling of variable
66 * "work"(work is now a reference on the relevant component of the result).
67 *
68 * Revision 1.6 2004/01/23 08:00:16 e_gourgoulhon
69 * Minor modifs. in output of methods min, max, maxabs, diffrel to
70 * better handle the display in the scalar case.
71 *
72 * Revision 1.5 2004/01/15 10:59:53 f_limousin
73 * Added method contract_desal for the contraction of two tensors with desaliasing
74 *
75 * Revision 1.4 2004/01/14 11:38:32 f_limousin
76 * Added method contract for one tensor
77 *
78 * Revision 1.3 2003/11/05 15:29:36 e_gourgoulhon
79 * Added declaration of externa functions max, min, maxabs,
80 * diffrel and diffrelmax.
81 *
82 * Revision 1.2 2003/10/11 16:47:10 e_gourgoulhon
83 * Suppressed the call to Ibtl::set_etat_qcq() after the construction
84 * of the Itbl's, thanks to the new property of the Itbl class.
85 *
86 * Revision 1.1 2003/10/06 15:13:38 e_gourgoulhon
87 * Tensor contraction.
88 *
89 *
90 * $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_calculus_ext.C,v 1.15 2016/12/05 16:18:17 j_novak Exp $
91 *
92 */
93
94// Headers C
95#include <cstdlib>
96#include <cassert>
97#include <cmath>
98
99// Headers Lorene
100#include "tensor.h"
101
102
103
104 //-----------------------//
105 // Tensorial product //
106 //-----------------------//
107
108
109namespace Lorene {
110Tensor operator*(const Tensor& t1, const Tensor& t2) {
111
112 assert (t1.mp == t2.mp) ;
113
114 int val_res = t1.valence + t2.valence ;
115
116 Itbl tipe (val_res) ;
117
118 for (int i=0 ; i<t1.valence ; i++)
119 tipe.set(i) = t1.type_indice(i) ;
120 for (int i=0 ; i<t2.valence ; i++)
121 tipe.set(i+t1.valence) = t2.type_indice(i) ;
122
123
124 if ( (t1.valence != 0) && (t2.valence != 0) ) {
125 assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
126 }
127
128 const Base_vect* triad_res ;
129 if (t1.valence != 0) {
130 triad_res = t1.get_triad() ;
131 }
132 else{
133 triad_res = t2.get_triad() ;
134 }
135
136 Tensor res(*t1.mp, val_res, tipe, triad_res) ;
137
138 Itbl jeux_indice_t1 (t1.valence) ;
139 Itbl jeux_indice_t2 (t2.valence) ;
140
141 for (int i=0 ; i<res.n_comp ; i++) {
142 Itbl jeux_indice_res(res.indices(i)) ;
143 for (int j=0 ; j<t1.valence ; j++)
144 jeux_indice_t1.set(j) = jeux_indice_res(j) ;
145 for (int j=0 ; j<t2.valence ; j++)
146 jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
147
148 res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
149 }
150
151 return res ;
152}
153
154
155
156
157 //------------------//
158 // Contraction //
159 //------------------//
160
161// Contraction on one index
162// ------------------------
163Tensor contract(const Tensor& t1, int ind1, const Tensor& t2, int ind2,
164 bool desaliasing) {
165
166 int val1 = t1.get_valence() ;
167 int val2 = t2.get_valence() ;
168
169 // Verifs :
170 assert((ind1>=0) && (ind1<val1)) ;
171 assert((ind2>=0) && (ind2<val2)) ;
172 assert(t1.get_mp() == t2.get_mp()) ;
173
174 // Contraction possible ?
175 if ( (val1 != 0) && (val2 != 0) ) {
176 assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
177 }
178 assert (t1.get_index_type(ind1) != t2.get_index_type(ind2)) ;
179
180 int val_res = val1 + val2 - 2;
181
182 Itbl tipe(val_res) ;
183
184 for (int i=0 ; i<ind1 ; i++)
185 tipe.set(i) = t1.get_index_type(i) ;
186 for (int i=ind1 ; i<val1-1 ; i++)
187 tipe.set(i) = t1.get_index_type(i+1) ;
188 for (int i=val1-1 ; i<val1+ind2-1 ; i++)
189 tipe.set(i) = t2.get_index_type(i-val1+1) ;
190 for (int i = val1+ind2-1 ; i<val_res ; i++)
191 tipe.set(i) = t2.get_index_type(i-val1+2) ;
192
193 const Base_vect* triad_res = (val_res == 0) ? 0x0 : t1.get_triad() ;
194
195 Tensor res(t1.get_mp(), val_res, tipe, triad_res) ;
196
197 // Boucle sur les composantes de res :
198
199 Itbl jeux_indice_t1(val1) ;
200 Itbl jeux_indice_t2(val2) ;
201
202 for (int i=0 ; i<res.get_n_comp() ; i++) {
203
204 Itbl jeux_indice_res(res.indices(i)) ;
205
206 for (int j=0 ; j<ind1 ; j++)
207 jeux_indice_t1.set(j) = jeux_indice_res(j) ;
208
209 for (int j=ind1+1 ; j<val1 ; j++)
210 jeux_indice_t1.set(j) = jeux_indice_res(j-1) ;
211
212 for (int j=0 ; j<ind2 ; j++)
213 jeux_indice_t2.set(j) = jeux_indice_res(val1+j-1) ;
214
215 for (int j=ind2+1 ; j<val2 ; j++)
216 jeux_indice_t2.set(j) = jeux_indice_res(val1+j-2) ;
217
218 Scalar& work = res.set(jeux_indice_res) ;
219 work.set_etat_zero() ;
220
221 for (int j=1 ; j<=3 ; j++) {
222 jeux_indice_t1.set(ind1) = j ;
223 jeux_indice_t2.set(ind2) = j ;
224 if (desaliasing) {
225 work += t1(jeux_indice_t1) % t2(jeux_indice_t2) ;
226 }
227 else {
228 work += t1(jeux_indice_t1) * t2(jeux_indice_t2) ;
229 }
230 }
231
232 }
233
234 return res ;
235}
236
237
238
239// Contraction on two indices
240// --------------------------
241Tensor contract(const Tensor& t1, int i1, int j1,
242 const Tensor& t2, int i2, int j2,
243 bool desaliasing) {
244
245 int val1 = t1.get_valence() ;
246 int val2 = t2.get_valence() ;
247
248 // Verifs :
249 assert( val1 >= 2 ) ;
250 assert( val2 >= 2 ) ;
251 assert( (0<=i1) && (i1<j1) && (j1<val1) ) ;
252 assert( (0<=i2) && (i2<j2) && (j2<val2) ) ;
253 assert( t1.get_mp() == t2.get_mp() ) ;
254
255 // Contraction possible ?
256 assert( *(t1.get_triad()) == *(t2.get_triad()) ) ;
257 assert( t1.get_index_type(i1) != t2.get_index_type(i2) ) ;
258 assert( t1.get_index_type(j1) != t2.get_index_type(j2) ) ;
259
260 int val_res = val1 + val2 - 4 ;
261
262 Itbl tipe(val_res) ;
263
264 for (int i=0 ; i<i1 ; i++)
265 tipe.set(i) = t1.get_index_type(i) ;
266
267 for (int i=i1 ; i<j1-1 ; i++)
268 tipe.set(i) = t1.get_index_type(i+1) ;
269
270 for (int i=j1-1 ; i<val1-2 ; i++)
271 tipe.set(i) = t1.get_index_type(i+2) ;
272
273 for (int i=val1-2 ; i<val1-2+i2 ; i++)
274 tipe.set(i) = t2.get_index_type(i-val1+2) ;
275
276 for (int i=val1-2+i2 ; i<val1+j2-3 ; i++)
277 tipe.set(i) = t2.get_index_type(i-val1+3) ;
278
279 for (int i=val1+j2-3 ; i<val_res ; i++)
280 tipe.set(i) = t2.get_index_type(i-val1+4) ;
281
282 const Base_vect* triad_res = (val_res == 0) ? 0x0 : t1.get_triad() ;
283
284 Tensor res(t1.get_mp(), val_res, tipe, triad_res) ;
285
286 // Boucle sur les composantes de res :
287
288 Itbl jeux_indice_t1(val1) ;
289 Itbl jeux_indice_t2(val2) ;
290
291 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
292
293 Itbl jeux_indice_res(res.indices(ic)) ;
294
295 for (int k=0 ; k<i1 ; k++)
296 jeux_indice_t1.set(k) = jeux_indice_res(k) ;
297
298 for (int k=i1+1 ; k<j1 ; k++)
299 jeux_indice_t1.set(k) = jeux_indice_res(k-1) ;
300
301 for (int k=j1+1 ; k<val1 ; k++)
302 jeux_indice_t1.set(k) = jeux_indice_res(k-2) ;
303
304 for (int k=0 ; k<i2 ; k++)
305 jeux_indice_t2.set(k) = jeux_indice_res(val1+k-2) ;
306
307 for (int k=i2+1 ; k<j2 ; k++)
308 jeux_indice_t2.set(k) = jeux_indice_res(val1+k-3) ;
309
310 for (int k=j2+1 ; k<val2 ; k++)
311 jeux_indice_t2.set(k) = jeux_indice_res(val1+k-4) ;
312
313 Scalar& work = res.set(jeux_indice_res) ;
314 work.set_etat_zero() ;
315
316 for (int i=1 ; i<=3 ; i++) {
317
318 jeux_indice_t1.set(i1) = i ;
319 jeux_indice_t2.set(i2) = i ;
320
321 for (int j=1 ; j<=3 ; j++) {
322
323 jeux_indice_t1.set(j1) = j ;
324 jeux_indice_t2.set(j2) = j ;
325
326 if (desaliasing) {
327 work += t1(jeux_indice_t1) % t2(jeux_indice_t2) ;
328 }
329 else {
330 work += t1(jeux_indice_t1) * t2(jeux_indice_t2) ;
331 }
332 }
333 }
334
335 }
336
337 return res ;
338}
339
340
341
342
343Tensor contract(const Tensor& source, int ind_1, int ind_2) {
344
345 int val = source.get_valence() ;
346
347 // Les verifications :
348 assert ((ind_1 >= 0) && (ind_1 < val)) ;
349 assert ((ind_2 >= 0) && (ind_2 < val)) ;
350 assert (ind_1 != ind_2) ;
351 assert (source.get_index_type(ind_1) != source.get_index_type(ind_2)) ;
352
353 // On veut ind_1 < ind_2 :
354 if (ind_1 > ind_2) {
355 int auxi = ind_2 ;
356 ind_2 = ind_1 ;
357 ind_1 = auxi ;
358 }
359
360 // On construit le resultat :
361 int val_res = val - 2 ;
362
363 Itbl tipe(val_res) ;
364
365 for (int i=0 ; i<ind_1 ; i++)
366 tipe.set(i) = source.get_index_type(i) ;
367 for (int i=ind_1 ; i<ind_2-1 ; i++)
368 tipe.set(i) = source.get_index_type(i+1) ;
369 for (int i = ind_2-1 ; i<val_res ; i++)
370 tipe.set(i) = source.get_index_type(i+2) ;
371
372 Tensor res(source.get_mp(), val_res, tipe, source.get_triad()) ;
373
374 // Boucle sur les composantes de res :
375
376 Itbl jeux_indice_source(val) ;
377
378 for (int i=0 ; i<res.get_n_comp() ; i++) {
379
380 Itbl jeux_indice_res(res.indices(i)) ;
381
382 for (int j=0 ; j<ind_1 ; j++)
383 jeux_indice_source.set(j) = jeux_indice_res(j) ;
384 for (int j=ind_1+1 ; j<ind_2 ; j++)
385 jeux_indice_source.set(j) = jeux_indice_res(j-1) ;
386 for (int j=ind_2+1 ; j<val ; j++)
387 jeux_indice_source.set(j) = jeux_indice_res(j-2) ;
388
389 Scalar& work = res.set(jeux_indice_res) ;
390 work.set_etat_zero() ;
391
392 for (int j=1 ; j<=3 ; j++) {
393 jeux_indice_source.set(ind_1) = j ;
394 jeux_indice_source.set(ind_2) = j ;
395 work += source(jeux_indice_source) ;
396 }
397
398 }
399
400 return res ;
401}
402
403
404
405
406 //------------------//
407 // diffrel //
408 //------------------//
409
410
411Tbl diffrel(const Tensor& aa, const Tensor& bb, const char* comment,
412 ostream& ost) {
413
414 if (comment != 0x0) ost << comment << " : " << endl ;
415
416 int val = aa.get_valence() ;
417
418 assert(bb.get_valence() == val) ;
419
420 int n_comp_a = aa.get_n_comp() ;
421 int n_comp_b = bb.get_n_comp() ;
422
423 const Tensor* tmax ;
424 int n_comp_max ;
425 if (n_comp_a >= n_comp_b) {
426 n_comp_max = n_comp_a ;
427 tmax = &aa ;
428 }
429 else {
430 n_comp_max = n_comp_b ;
431 tmax = &bb ;
432 }
433
434 int nz = aa.get_mp().get_mg()->get_nzone() ;
435 Tbl resu(n_comp_max, nz) ;
436 resu.set_etat_qcq() ;
437
438 Itbl idx(val) ;
439
440 for (int ic=0; ic<n_comp_max; ic++) {
441 idx = tmax->indices(ic) ;
442 Tbl diff = diffrel( aa(idx), bb(idx) ) ;
443
444 if (n_comp_max > 1) ost << " Comp." ;
445 for (int j=0 ; j<val ; j++) {
446 ost << " " << idx(j) ;
447 }
448 if (n_comp_max > 1) ost << " : " ;
449 else ost << " " ;
450 for (int l=0; l<nz; l++) {
451 ost << " " << diff(l) ;
452 resu.set(ic, l) = diff(l) ;
453 }
454 ost << "\n" ;
455
456 }
457
458 return resu ;
459}
460
461
462 //--------------------//
463 // diffrelmax //
464 //--------------------//
465
466
467Tbl diffrelmax(const Tensor& aa, const Tensor& bb, const char* comment,
468 ostream& ost) {
469
470 if (comment != 0x0) ost << comment << " : " << endl ;
471
472 int val = aa.get_valence() ;
473
474 assert(bb.get_valence() == val) ;
475
476 int n_comp_a = aa.get_n_comp() ;
477 int n_comp_b = bb.get_n_comp() ;
478
479 const Tensor* tmax ;
480 int n_comp_max ;
481 if (n_comp_a >= n_comp_b) {
482 n_comp_max = n_comp_a ;
483 tmax = &aa ;
484 }
485 else {
486 n_comp_max = n_comp_b ;
487 tmax = &bb ;
488 }
489
490 int nz = aa.get_mp().get_mg()->get_nzone() ;
491 Tbl resu(n_comp_max, nz) ;
492 resu.set_etat_qcq() ;
493
494 Itbl idx(val) ;
495
496 for (int ic=0; ic<n_comp_max; ic++) {
497 idx = tmax->indices(ic) ;
498 Tbl diff = diffrelmax( aa(idx), bb(idx) ) ;
499
500 if (n_comp_max > 1) ost << " Comp." ;
501 for (int j=0 ; j<val ; j++) {
502 ost << " " << idx(j) ;
503 }
504 if (n_comp_max > 1) ost << " : " ;
505 else ost << " " ;
506 for (int l=0; l<nz; l++) {
507 ost << " " << diff(l) ;
508 resu.set(ic, l) = diff(l) ;
509 }
510 ost << "\n" ;
511
512 }
513
514 return resu ;
515}
516
517
518
519 //----------------//
520 // max //
521 //----------------//
522
523
524Tbl max(const Tensor& aa, const char* comment, ostream& ost) {
525
526 if (comment != 0x0) ost << comment << " : " << endl ;
527
528 int val = aa.get_valence() ;
529
530 int n_comp = aa.get_n_comp() ;
531
532 int nz = aa.get_mp().get_mg()->get_nzone() ;
533 Tbl resu(n_comp, nz) ;
534 resu.set_etat_qcq() ;
535
536 Itbl idx(val) ;
537
538 for (int ic=0; ic<n_comp; ic++) {
539
540 idx = aa.indices(ic) ;
541 Tbl diff = max( aa(idx) ) ;
542
543 if (val > 0) ost << " Comp." ;
544 for (int j=0 ; j<val ; j++) {
545 ost << " " << idx(j) ;
546 }
547 if (val > 0) ost << " : " ;
548 else ost << " " ;
549 for (int l=0; l<nz; l++) {
550 ost << " " << diff(l) ;
551 resu.set(ic, l) = diff(l) ;
552 }
553 ost << "\n" ;
554
555 }
556
557 return resu ;
558}
559
560
561
562 //----------------//
563 // min //
564 //----------------//
565
566
567Tbl min(const Tensor& aa, const char* comment, ostream& ost) {
568
569 if (comment != 0x0) ost << comment << " : " << endl ;
570
571 int val = aa.get_valence() ;
572
573 int n_comp = aa.get_n_comp() ;
574
575 int nz = aa.get_mp().get_mg()->get_nzone() ;
576 Tbl resu(n_comp, nz) ;
577 resu.set_etat_qcq() ;
578
579 Itbl idx(val) ;
580
581 for (int ic=0; ic<n_comp; ic++) {
582
583 idx = aa.indices(ic) ;
584 Tbl diff = min( aa(idx) ) ;
585
586 if (val > 0) ost << " Comp." ;
587 for (int j=0 ; j<val ; j++) {
588 ost << " " << idx(j) ;
589 }
590 if (val > 0) ost << " : " ;
591 else ost << " " ;
592 for (int l=0; l<nz; l++) {
593 ost << " " << diff(l) ;
594 resu.set(ic, l) = diff(l) ;
595 }
596 ost << "\n" ;
597
598 }
599
600 return resu ;
601}
602
603
604 //--------------------//
605 // maxabs //
606 //--------------------//
607
608
609Tbl maxabs(const Tensor& aa, const char* comment, ostream& ost, bool verb) {
610
611 if (comment != 0x0) ost << comment << " : " << endl ;
612
613 int val = aa.get_valence() ;
614
615 int n_comp = aa.get_n_comp() ;
616
617 int nz = aa.get_mp().get_mg()->get_nzone() ;
618 Tbl resu(n_comp, nz) ;
619 resu.set_etat_qcq() ;
620
621 Itbl idx(val) ;
622
623 for (int ic=0; ic<n_comp; ic++) {
624
625 idx = aa.indices(ic) ;
626 Tbl diff = max( abs( aa(idx) ) ) ;
627
628 if (verb) {
629 if (val > 0) ost << " Comp." ;
630 for (int j=0 ; j<val ; j++) {
631 ost << " " << idx(j) ;
632 }
633 if (val > 0 ) ost << " : " ;
634 else ost << " " ;
635 }
636 for (int l=0; l<nz; l++) {
637 if (verb) ost << " " << diff(l) ;
638 resu.set(ic, l) = diff(l) ;
639 }
640 if (verb) ost << "\n" ;
641
642 }
643
644 return resu ;
645}
646
647
648 //-------------------//
649 // Central value //
650 //-------------------//
651
652Tbl central_value(const Tensor& aa, const char* comment, ostream& ost) {
653
654 if (comment != 0x0) ost << comment << " : " << endl ;
655
656 int val = aa.get_valence() ;
657 int n_comp = aa.get_n_comp() ;
658
659 Tbl resu(n_comp) ;
660 resu.set_etat_qcq() ;
661
662 Itbl idx(val) ;
663
664 for (int ic=0; ic<n_comp; ic++) {
665
666 idx = aa.indices(ic) ;
667 double aa_c = aa(idx).val_grid_point(0,0,0,0) ;
668 resu.set(ic) = aa_c ;
669
670 if ( comment != 0x0 ) {
671 if ( val > 0 ) ost << " Comp." ;
672 for (int j=0 ; j<val ; j++) {
673 ost << " " << idx(j) ;
674 }
675 if (val > 0 ) ost << " : " ;
676 else ost << " " ;
677 ost << aa_c << endl ;
678 }
679
680 }
681
682 return resu ;
683}
684
685
686 //-------------------//
687 // max_all_domains //
688 //-------------------//
689
690Tbl max_all_domains(const Tensor& aa, int l_excluded, const char* comment,
691 ostream& ost) {
692
693 if (comment != 0x0) ost << comment << " : " << endl ;
694
695 Tbl max_dom = max(aa) ;
696
697 int val = aa.get_valence() ;
698 int n_comp = aa.get_n_comp() ;
699 int nz = aa.get_mp().get_mg()->get_nzone() ;
700
701 Tbl resu(n_comp) ;
702 resu.set_etat_qcq() ;
703
704 Itbl idx(val) ;
705
706 for (int ic=0; ic<n_comp; ic++) {
707
708 double x0 ;
709 if (l_excluded != 0) x0 = max_dom(ic, 0) ;
710 else x0 = max_dom(ic, 1) ;
711 for (int l=0; l<nz; l++) {
712 if (l == l_excluded) continue ;
713 double x = max_dom(ic,l) ;
714 if (x > x0) x0 = x ;
715 }
716
717 resu.set(ic) = x0 ;
718
719 if ( comment != 0x0 ) {
720 if ( val > 0 ) ost << " Comp." ;
721 idx = aa.indices(ic) ;
722 for (int j=0 ; j<val ; j++) {
723 ost << " " << idx(j) ;
724 }
725 if (val > 0 ) ost << " : " ;
726 else ost << " " ;
727 ost << x0 << endl ;
728 }
729
730 }
731
732 return resu ;
733
734}
735
736 //-------------------//
737 // min_all_domains //
738 //-------------------//
739
740Tbl min_all_domains(const Tensor& aa, int l_excluded, const char* comment,
741 ostream& ost) {
742
743 if (comment != 0x0) ost << comment << " : " << endl ;
744
745 Tbl min_dom = min(aa) ;
746
747 int val = aa.get_valence() ;
748 int n_comp = aa.get_n_comp() ;
749 int nz = aa.get_mp().get_mg()->get_nzone() ;
750
751 Tbl resu(n_comp) ;
752 resu.set_etat_qcq() ;
753
754 Itbl idx(val) ;
755
756 for (int ic=0; ic<n_comp; ic++) {
757
758 double x0 ;
759 if (l_excluded != 0) x0 = min_dom(ic, 0) ;
760 else x0 = min_dom(ic, 1) ;
761 for (int l=0; l<nz; l++) {
762 if (l == l_excluded) continue ;
763 double x = min_dom(ic,l) ;
764 if (x < x0) x0 = x ;
765 }
766
767 resu.set(ic) = x0 ;
768
769 if ( comment != 0x0 ) {
770 if ( val > 0 ) ost << " Comp." ;
771 idx = aa.indices(ic) ;
772 for (int j=0 ; j<val ; j++) {
773 ost << " " << idx(j) ;
774 }
775 if (val > 0 ) ost << " : " ;
776 else ost << " " ;
777 ost << x0 << endl ;
778 }
779
780 }
781
782 return resu ;
783
784}
785
786
787 //----------------------//
788 // maxabs_all_domains //
789 //----------------------//
790
791Tbl maxabs_all_domains(const Tensor& aa, int l_excluded, const char* comment,
792 ostream& ost, bool verb) {
793
794 if (comment != 0x0) ost << comment << " : " << endl ;
795
796 Tbl maxabs_dom = maxabs(aa, 0x0, ost, verb) ;
797
798 int val = aa.get_valence() ;
799 int n_comp = aa.get_n_comp() ;
800 int nz = aa.get_mp().get_mg()->get_nzone() ;
801
802 Tbl resu(n_comp) ;
803 resu.set_etat_qcq() ;
804
805 Itbl idx(val) ;
806
807 for (int ic=0; ic<n_comp; ic++) {
808
809 double x0 ;
810 if (l_excluded != 0) x0 = maxabs_dom(ic, 0) ;
811 else x0 = maxabs_dom(ic, 1) ;
812 for (int l=0; l<nz; l++) {
813 if (l == l_excluded) continue ;
814 double x = maxabs_dom(ic,l) ;
815 if (x > x0) x0 = x ;
816 }
817
818 resu.set(ic) = x0 ;
819
820 if ( comment != 0x0 ) {
821 if ( val > 0 ) ost << " Comp." ;
822 idx = aa.indices(ic) ;
823 for (int j=0 ; j<val ; j++) {
824 ost << " " << idx(j) ;
825 }
826 if (val > 0 ) ost << " : " ;
827 else ost << " " ;
828 ost << x0 << endl ;
829 }
830
831 }
832
833 return resu ;
834
835}
836
837
838
839}
Vectorial bases (triads) with respect to which the tensorial components are defined.
Definition base_vect.h:105
Basic integer array class.
Definition itbl.h:122
int & set(int i)
Read/write of a particular element (index i ) (1D case).
Definition itbl.h:247
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:393
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition scalar.C:330
Basic array class.
Definition tbl.h:161
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition tbl.C:364
double & set(int i)
Read/write of a particular element (index i) (1D case).
Definition tbl.h:281
Tensor handling.
Definition tensor.h:294
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition cmp_math.C:507
Tbl min(const Cmp &)
Minimum values of a Cmp in each domain.
Definition cmp_math.C:461
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition cmp_math.C:438
Cmp abs(const Cmp &)
Absolute value.
Definition cmp_math.C:413
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition cmp_math.C:542
const Map & get_mp() const
Returns the mapping.
Definition tensor.h:874
int get_index_type(int i) const
Gives the type (covariant or contravariant) of the index number i .
Definition tensor.h:899
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition tensor.h:301
int get_valence() const
Returns the valence.
Definition tensor.h:882
virtual Itbl indices(int pos) const
Returns the indices of a component given by its position in the array cmp .
Definition tensor.C:548
Tensor(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i)
Standard constructor.
Definition tensor.C:211
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...).
Definition tensor.h:304
int get_n_comp() const
Returns the number of stored components.
Definition tensor.h:885
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition tensor.h:879
int n_comp
Number of stored components, depending on the symmetry.
Definition tensor.h:318
Itbl type_indice
1D array of integers (class Itbl ) of size valence containing the type of each index: COV for a cov...
Definition tensor.h:316
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:663
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
Tbl maxabs_all_domains(const Tensor &aa, int l_excluded=-1, const char *comment=0x0, ostream &ost=cout, bool verb=true)
Maximum of the absolute value of each component of a tensor over all the domains.
Tbl maxabs(const Tensor &aa, const char *comment=0x0, ostream &ost=cout, bool verb=true)
Maxima in each domain of the absolute values of the tensor components.
Tbl max_all_domains(const Tensor &aa, int l_excluded=-1, const char *comment=0x0, ostream &ost=cout)
Maximum value of each component of a tensor over all the domains.
Tbl central_value(const Tensor &aa, const char *comment=0x0, ostream &ost=cout)
Central value of each component of a tensor.
Tbl min_all_domains(const Tensor &aa, int l_excluded=-1, const char *comment=0x0, ostream &ost=cout)
Minimum value of each component of a tensor over all the domains.
Lorene prototypes.
Definition app_hor.h:67
Coord x
x coordinate centered on the grid
Definition map.h:738