TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
VDF_to_IJK.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#ifndef VDF_to_IJK_H_TPP
16#define VDF_to_IJK_H_TPP
17
18#include <VDF_to_IJK.h>
19#include <Schema_Comm_Vecteurs.h>
20#include <Schema_Comm.h>
21#include <communications.h>
22//#include <Domaine_VF.h>
23#include <IJK_Field.h>
24#include <TRUSTTabs.h>
25#include <Array_tools.h>
26#include <Domaine.h>
27
28template <typename _TYPE_, typename _TYPE_ARRAY_>
30{
32 int i;
33 sch.begin_init();
34
35 const int nsend = pe_send_.size_array();
36 for (i = 0; i < nsend; i++)
37 sch.add_send_area_template<double>(pe_send_[i], pe_send_data_.get_list_size(i));
38
39 const int nrecv = pe_recv_.size_array();
40 for (i = 0; i < nrecv; i++)
41 sch.add_recv_area_template<double>(pe_recv_[i], pe_recv_data_.get_list_size(i));
42
43 sch.end_init();
44
45 sch.begin_comm();
46 for (i = 0; i < nsend; i++)
47 {
48 const int ndata = pe_send_data_.get_list_size(i);
49 ArrOfDouble& buf = sch.get_next_area_template<double>(pe_send_[i], ndata);
50 for (int j = 0; j < ndata; j++)
51 {
52 const int index = pe_send_data_(i, j);
53 buf[j] = x[index];
54 }
55 }
56 sch.exchange();
57 for (i = 0; i < nrecv; i++)
58 {
59 const int ndata = pe_recv_data_.get_list_size(i);
60 const ArrOfDouble& buf = sch.get_next_area_template<double>(pe_recv_[i], ndata);
61 for (int j = 0; j < ndata; j++)
62 {
63 const int index = pe_recv_data_(i, j);
64 const int ii = index % ijk_ni_;
65 const int jj = (index / ijk_ni_) % ijk_nj_;
66 const int kk = (index / ijk_ni_) / ijk_nj_;
67 ijk_x(ii,jj,kk) = (_TYPE_)buf[j];
68 }
69 }
70 sch.end_comm();
71}
72
73template <typename _TYPE_, typename _TYPE_ARRAY_>
74void VDF_to_IJK::convert_from_ijk(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& ijk_x, DoubleVect& x, bool add) const
75{
77 sch.begin_init();
78 int i;
79 const int nsend = pe_send_.size_array();
80 for (i = 0; i < nsend; i++)
81 sch.add_recv_area_template<double>(pe_send_[i], pe_send_data_.get_list_size(i));
82
83 const int nrecv = pe_recv_.size_array();
84 for (i = 0; i < nrecv; i++)
85 sch.add_send_area_template<double>(pe_recv_[i], pe_recv_data_.get_list_size(i));
86
87 sch.end_init();
88
89 sch.begin_comm();
90 for (i = 0; i < nrecv; i++)
91 {
92 const int ndata = pe_recv_data_.get_list_size(i);
93 ArrOfDouble& buf = sch.get_next_area_template<double>(pe_recv_[i], ndata);
94 for (int j = 0; j < ndata; j++)
95 {
96 const int index = pe_recv_data_(i, j);
97 const int ii = index % ijk_ni_;
98 const int jj = (index / ijk_ni_) % ijk_nj_;
99 const int kk = (index / ijk_ni_) / ijk_nj_;
100 buf[j] = ijk_x(ii, jj, kk);
101 }
102 }
103 sch.exchange();
104 for (i = 0; i < nsend; i++)
105 {
106 const int ndata = pe_send_data_.get_list_size(i);
107 const ArrOfDouble& buf = sch.get_next_area_template<double>(pe_send_[i], ndata);
108 if (add)
109 {
110 for (int j = 0; j < ndata; j++)
111 {
112 const int index = pe_send_data_(i, j);
113 x[index] += buf[j];
114 }
115 }
116 else
117 {
118 for (int j = 0; j < ndata; j++)
119 {
120 const int index = pe_send_data_(i, j);
121 x[index] = buf[j];
122 }
123 }
124
125 }
126 sch.end_comm();
127}
128
129
130
131#endif
132
: This class is an IJK_Field_local with parallel informations.
void add_send_area_template(int pe, int size)
TRUSTArray< _TYPE_ > & get_next_area_template(int pe, int array_size)
void add_recv_area_template(int pe, int size)
void end_init()
Une fois les donnees a echanger declarees avec add_send/recv_area_.
void begin_init()
Reinitialise les tailles de buffers.
void exchange(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
void begin_comm(bool bufferOnDevice=false)
Commence un nouvel echange de donnees (les tailles de buffers doivent avoir ete initialisees avec beg...
ArrOfInt pe_send_
Definition VDF_to_IJK.h:43
void convert_from_ijk(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &ijk_x, DoubleVect &x, bool add=false) const
ArrOfInt pe_recv_
Definition VDF_to_IJK.h:45
Static_Int_Lists pe_recv_data_
Definition VDF_to_IJK.h:52
Static_Int_Lists pe_send_data_
Definition VDF_to_IJK.h:51
void convert_to_ijk(const DoubleVect &x, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &ijk_x) const