TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
IJK_Field_tools.tpp
1/****************************************************************************
2* Copyright (c) 2025, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef IJK_Field_tools_TPP_H
17#define IJK_Field_tools_TPP_H
18
19template<typename _TYPE_, typename _TYPE_ARRAY_>
20double norme_ijk(const IJK_Field_template<_TYPE_, _TYPE_ARRAY_>& residu)
21{
22 const int ni = residu.ni();
23 const int nj = residu.nj();
24 const int nk = residu.nk();
25 double somme = 0.;
26 for (int k = 0; k < nk; k++)
27 {
28 double partial1 = 0.;
29 for (int j = 0; j < nj; j++)
30 {
31 double partial2 = 0.;
32 for (int i = 0; i < ni; i++)
33 {
34 double x = residu(i, j, k);
35 partial2 += x * x;
36 }
37 partial1 += partial2;
38 }
39 somme += partial1;
40 }
41 somme = Process::mp_sum(somme);
42 return sqrt(somme);
43}
44
45template<typename _TYPE_, typename _TYPE_ARRAY_>
47{
48 const int ni = x.ni();
49 const int nj = x.nj();
50 const int nk = x.nk();
51 _TYPE_ somme = 0.;
52 const _TYPE_ARRAY_& xd = x.data();
53 const _TYPE_ARRAY_& yd = y.data();
54 for (int k = 0; k < nk; k++)
55 {
56 for (int j = 0; j < nj; j++)
57 {
58 for (int i = 0; i < ni; i++)
59 {
60 int index = x.linear_index(i,j,k);
61 assert(index == y.linear_index(i,j,k));
62 somme += xd[index] * yd[index];
63 }
64 }
65 }
66 somme = (_TYPE_)Process::mp_sum(somme); //!!!! WARNING: possible conversion to double to float!!!!!!!!
67 return somme;
68}
69
70template<typename _TYPE_, typename _TYPE_ARRAY_>
71double somme_ijk(const IJK_Field_template<_TYPE_, _TYPE_ARRAY_>& residu)
72{
73 const int ni = residu.ni();
74 const int nj = residu.nj();
75 const int nk = residu.nk();
76 double somme = 0.;
77 for (int k = 0; k < nk; k++)
78 {
79 double partial1 = 0.;
80 for (int j = 0; j < nj; j++)
81 {
82 double partial2 = 0.;
83 for (int i = 0; i < ni; i++)
84 {
85 double x = residu(i, j, k);
86 partial2 += x;
87 }
88 partial1 += partial2;
89 }
90 somme += partial1;
91 }
92 somme = Process::mp_sum(somme);
93 return somme;
94}
95
96template<typename _TYPE_, typename _TYPE_ARRAY_>
97_TYPE_ max_ijk(const IJK_Field_template<_TYPE_, _TYPE_ARRAY_>& residu)
98{
99 const int ni = residu.ni();
100 const int nj = residu.nj();
101 const int nk = residu.nk();
102 _TYPE_ res = (_TYPE_)-1.e30;
103 for (int k = 0; k < nk; k++)
104 for (int j = 0; j < nj; j++)
105 for (int i = 0; i < ni; i++)
106 {
107 _TYPE_ x = residu(i,j,k);
108 res = std::max(x,res);
109 }
110 res = (_TYPE_)Process::mp_max(res);
111 return res;
112}
113
114#endif /* IJK_Field_tools_TPP_H */
int linear_index(int i, int j, int k) const
: This class is an IJK_Field_local with parallel informations.
static double mp_max(double)
Definition Process.cpp:376
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146