TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
TRUST_2_CGNS.h
1/****************************************************************************
2* Copyright (c) 2026, 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 TRUST_2_CGNS_included
17#define TRUST_2_CGNS_included
18
19#include <Ecrire_CGNS_helper.h>
20#include <TRUST_Ref.h>
21#include <vector>
22
23#ifdef HAS_CGNS
24
25using CGNS_TYPE = CGNS_ENUMT(ElementType_t);
26using CGNS_LOC = CGNS_ENUMT(GridLocation_t);
27
28#include <Domaine_forward.h>
29class Motcle;
30
31class TRUST_2_CGNS
32{
33public:
34 TRUST_2_CGNS() { }
35 void associer_domaine_TRUST(const Domaine *, const Domaine_dis_base*, const DoubleTab&, const IntTab&, const bool, const std::string& );
36 void associer_connec_pour_dual(const IntTab&, const IntTab&);
37 void fill_coords(std::vector<double>&, std::vector<double>&, std::vector<double>&) const;
38 CGNS_TYPE convert_elem_type(const Motcle&) const;
39 int topo_dim_from_elem(CGNS_TYPE etype, bool is_polyedre) const;
40
41 int nb_procs_writing() const { return nb_procs_writing_; }
42 const bool& all_procs_write() const { return all_procs_write_; }
43 const std::vector<int>& get_proc_non_zero_elem() const { return proc_non_zero_elem_; }
44 const std::vector<int>& get_global_nb_elem() const { return global_nb_elem_; }
45 const std::vector<int>& get_global_nb_som() const { return global_nb_som_; }
46
47 int get_proc_me_local_comm() const { return proc_me_local_comm_; }
48 int get_nb_proc_local_comm() const { return nb_proc_local_comm_; }
49
50 void fill_global_infos();
51 void fill_global_infos_poly(const bool);
52 int compute_shift(const std::vector<int>&) const;
53
54 int get_nb_fs() const { return nb_fs_; }
55 const std::vector<int>& get_global_nb_face_som() const { return global_nb_face_som_; }
56 const std::vector<int>& get_global_nb_face_som_offset() const { return global_nb_face_som_offset_; }
57
58 int get_nb_ef() const { return nb_ef_; }
59 const std::vector<int>& get_global_nb_elem_face() const { return global_nb_elem_face_; }
60 const std::vector<int>& get_global_nb_elem_face_offset() const { return global_nb_elem_face_offset_; }
61
62 int get_nb_es() const { return nb_es_; }
63 const std::vector<int>& get_global_nb_elem_som_offset() const { return global_nb_elem_som_offset_; }
64
65 int get_ne_tot() const { return ne_tot_; }
66 const std::vector<int>& get_global_incr_min_elem() const { return global_incr_min_elem_; }
67 const std::vector<int>& get_global_incr_max_elem() const { return global_incr_max_elem_; }
68
69 int get_ns_tot() const { return ns_tot_; }
70 const std::vector<int>& get_global_incr_min_som() const { return global_incr_min_som_; }
71 const std::vector<int>& get_global_incr_max_som() const { return global_incr_max_som_; }
72
73 int get_nfs_tot() const { return nfs_tot_; }
74 int get_nfs_offset_tot() const { return nfs_offset_tot_; }
75 const std::vector<int>& get_global_incr_min_face_som() const { return global_incr_min_face_som_; }
76 const std::vector<int>& get_global_incr_max_face_som() const { return global_incr_max_face_som_; }
77
78 int get_nef_tot() const { return nef_tot_; }
79 int get_nef_offset_tot() const { return nef_offset_tot_; }
80 const std::vector<int>& get_global_incr_min_elem_face() const { return global_incr_min_elem_face_; }
81 const std::vector<int>& get_global_incr_max_elem_face() const { return global_incr_max_elem_face_; }
82
83 int get_nes_offset_tot() const { return nes_offset_tot_; }
84
85 int convert_connectivity(const CGNS_TYPE, std::vector<cgsize_t>& ) const;
86 int convert_connectivity_ngon(std::vector<cgsize_t>&, std::vector<cgsize_t>&, const bool, int decal = 0);
87 int convert_connectivity_nface(std::vector<cgsize_t>&, std::vector<cgsize_t>&, int decal = 0);
88
89 const std::vector<cgsize_t>& get_local_fs() const { return local_fs_; }
90 const std::vector<cgsize_t>& get_local_fs_offset() const { return local_fs_offset_; }
91
92 const std::vector<cgsize_t>& get_local_ef() const { return local_ef_; }
93 const std::vector<cgsize_t>& get_local_ef_offset() const { return local_ef_offset_; }
94
95 const std::vector<cgsize_t>& get_local_es() const { return local_es_; }
96 const std::vector<cgsize_t>& get_local_es_offset() const { return local_es_offset_; }
97
98 void clear_vectors();
99
100 /* methods statiques utiles */
101 static inline Nom modify_domaine_name_for_link(const Nom&, const std::string&);
102 static inline int get_index_nom_vector(const std::vector<Nom>&, const Nom&);
103 static inline void remove_slash_linkfile(std::string&);
104 static inline void init_has_field_and_loc_iters(const Nom& nom_dom, const std::map<std::string, Nom>& map, bool& has_field, std::string& LOC);
105 static inline void init_glob_base_domain_idx(const std::vector<Nom>& doms_written, const Nom& nom_dom, const bool has_field, const std::string& LOC, int& ind_glob, int& ind_base);
106 static inline int get_base_domain_idx(const std::vector<Nom>& doms_written, const Nom& nom_dom, const bool has_field, const std::string& LOC, const int ind_glob);
107
108 static Motcle modify_field_name_for_post(const Nom&, const Nom&, const std::string&, int&, int&, int&);
109 static std::string modify_domaine_name_for_post(const Nom& );
110 static void map_face_values(const Domaine_VF&, const DoubleTab& , DoubleTrav&);
111
112private:
113 OBS_PTR(Domaine_dis_base) domaine_dis_; ///< Reference to the discretized domain - used for face fields.
114 OBS_PTR(Domaine) dom_trust_;
115 OBS_PTR(DoubleTab) sommets_;
116 OBS_PTR(IntTab) elems_;
117 Nom discr_type_ = "";
118
119 // specifique maillage dual pour faces
120 OBS_PTR(IntTab) fs_dual_, ef_dual_;
121 void get_domaine_dis_vf_if_poly(Domaine_dis_base*& , Domaine_VF*& );
122
123 bool par_in_zone_ = false, all_procs_write_ = true, postraiter_domaine_ = false;
124 int ns_tot_ = -123, ne_tot_ = -123, nb_procs_writing_ = -123;
125 int proc_me_local_comm_ = -123, nb_proc_local_comm_ = -123;
126
127 std::vector<int> global_nb_elem_, global_nb_som_, proc_non_zero_elem_;
128
129 std::vector<int> global_incr_min_elem_, global_incr_max_elem_; // elem
130
131 std::vector<int> global_incr_min_som_, global_incr_max_som_; //som
132
133 // pour polyedre
134 int nb_fs_ = -123, nb_ef_ = -123, nb_es_ = -123, nfs_tot_ = -123, nef_tot_ = -123, nfs_offset_tot_ = -123, nef_offset_tot_ = -123, nes_offset_tot_ = -123;
135
136 std::vector<int> global_nb_face_som_, global_nb_elem_face_, global_nb_face_som_offset_, global_nb_elem_face_offset_, global_nb_elem_som_offset_;
137
138 std::vector<int> global_incr_min_face_som_, global_incr_max_face_som_; // pour NGON_n - face_som
139
140 std::vector<int> global_incr_min_elem_face_, global_incr_max_elem_face_; // pour NFACE_n - elem_face
141
142 std::vector<cgsize_t> local_fs_, local_fs_offset_, local_ef_, local_ef_offset_, local_es_, local_es_offset_;
143};
144
145inline Nom TRUST_2_CGNS::modify_domaine_name_for_link(const Nom& nom_dom, const std::string& LOC)
146{
147 if (LOC != "FACES")
148 {
149 Nom nom_dom_mod = nom_dom;
150 nom_dom_mod.prefix(LOC.c_str());
151 nom_dom_mod.prefix("_");
152 return nom_dom_mod;
153 }
154 else
155 return nom_dom;
156}
157
158inline int TRUST_2_CGNS::get_index_nom_vector(const std::vector<Nom>& vect, const Nom& nom)
159{
160 int ind = -1;
161 auto it = find(vect.begin(), vect.end(), nom);
162
163 if (it != vect.end()) // element found
164 ind = static_cast<int>(it - vect.begin()); // XXX sinon utilse std::distance ...
165
166 return ind;
167}
168
169inline void TRUST_2_CGNS::remove_slash_linkfile(std::string& linkfile)
170{
171 const auto found = linkfile.find_last_of("/");
172 if (found != std::string::npos)
173 linkfile.erase(0, found + 1);
174}
175
176inline void TRUST_2_CGNS::init_has_field_and_loc_iters(const Nom& nom_dom, const std::map<std::string, Nom>& map, bool& has_field, std::string& LOC)
177{
178 if (nom_dom.finit_par("_ELEM"))
179 has_field = true, LOC = "ELEM";
180 else if (nom_dom.finit_par("_SOM"))
181 has_field = true, LOC = "SOM";
182 else if (nom_dom.finit_par("_FACES"))
183 has_field = true, LOC = "FACES";
184
185 // XXX just to be sure that there is no issues of use; ie domaine dom_ELEM in jdd lol
186 if (has_field)
187 {
188 if (!map.count(LOC))
189 has_field = false, LOC = "rien";
190 else
191 {
192 const Nom& nom_dom_fld = map.at(LOC);
193 if (nom_dom_fld != nom_dom)
194 has_field = false, LOC = "rien";
195 }
196 }
197}
198
199inline void TRUST_2_CGNS::init_glob_base_domain_idx(const std::vector<Nom>& doms_written, const Nom& nom_dom, const bool has_field, const std::string& LOC, int& ind_glob, int& ind_base)
200{
201 ind_glob = TRUST_2_CGNS::get_index_nom_vector(doms_written, nom_dom); // Glob means can be with fields ..
202 assert(ind_glob > -1);
203 ind_base = ind_glob;
204 if (has_field && LOC != "FACES")
205 {
206 const Nom nom_dom_mod = modify_domaine_name_for_link(nom_dom, LOC);
207 ind_base = TRUST_2_CGNS::get_index_nom_vector(doms_written, nom_dom_mod); // index to base dom written by write domaine !
208 }
209 assert(ind_base > -1);
210}
211
212inline int TRUST_2_CGNS::get_base_domain_idx(const std::vector<Nom>& doms_written, const Nom& nom_dom, const bool has_field, const std::string& LOC, const int ind_glob)
213{
214 int ind_base = ind_glob;
215 if (has_field && LOC != "FACES")
216 {
217 const Nom nom_dom_mod = modify_domaine_name_for_link(nom_dom, LOC);
218 ind_base = TRUST_2_CGNS::get_index_nom_vector(doms_written, nom_dom_mod); // index to base dom written by write domaine !
219 }
220 assert(ind_base > -1);
221 return ind_base;
222}
223
224#endif /* HAS_CGNS */
225
226#endif /* TRUST_2_CGNS_included */
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
virtual int finit_par(const char *const n) const
Definition Nom.cpp:324
Nom & prefix(const char *const)
Definition Nom.cpp:329