TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Op_PolyMAC_CDO_Elem.cpp
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#include <Op_PolyMAC_CDO_Elem.h>
17#include <Domaine_PolyMAC_CDO.h>
18#include <Domaine_Cl_PolyMAC_family.h>
19#include <Periodique.h>
20#include <Matrice_Morse.h>
21#include <Equation_base.h>
22#include <Matrix_tools.h>
23#include <Array_tools.h>
24
25void Op_PolyMAC_CDO_Elem::dimensionner(const Domaine_PolyMAC_CDO& le_domaine, const Domaine_Cl_PolyMAC_family& le_domaine_cl, Matrice_Morse& la_matrice) const
26{
27 // Dimensionnement de la matrice qui devra recevoir les coefficients provenant de
28 // la convection, de la diffusion pour le cas des elements.
29 // Cette matrice a une structure de matrice morse.
30 // Nous commencons par calculer les tailles des tableaux tab1 et tab2.
31
32 int num_face, face, k;
33 int n1 = le_domaine.domaine().nb_elem_tot(), n2 = le_domaine.nb_faces_tot();
34 int elem1, elem2, i;
35 const IntTab& face_voisins = le_domaine.face_voisins();
36 // const DoubleVect& face_surfaces = le_domaine.face_surfaces();
37 // const DoubleVect& volumes_entrelaces = le_domaine.volumes_entrelaces();
38 // const DoubleVect& porosite_face = le_domaine.porosite_face();
39 const Conds_lim& les_cl = le_domaine_cl.les_conditions_limites();
40 int nb_comp = 1;
41
42 const DoubleTab& champ_inconnue = le_domaine_cl.equation().inconnue().valeurs();
43 if (champ_inconnue.nb_dim() == 2)
44 nb_comp = champ_inconnue.dimension(1);
45 //Cerr << "nb_compo de Op_PolyMAC_CDO_Elem::dimensionner" << nb_comp << finl;
46 //Cerr << " nombre d'elements de Op_PolyMAC_CDO_Elem::dimensionner" << n1 << finl;
47
48 la_matrice.dimensionner((n1 + n2) * nb_comp, (n1 + n2) * nb_comp, 0);
49
50 auto& tab1 = la_matrice.get_set_tab1();
51 auto& tab2 = la_matrice.get_set_tab2();
52
53 int ndeb = le_domaine.premiere_face_int();
54 int nfin = le_domaine.nb_faces();
55 auto& coeff = la_matrice.get_set_coeff();
56 coeff = 0;
57
58 IntVect rang_voisin(n1 * nb_comp);
59 rang_voisin = 1;
60
61 for (num_face = ndeb; num_face < nfin; num_face++)
62 {
63 elem1 = face_voisins(num_face, 0);
64 elem2 = face_voisins(num_face, 1);
65 (rang_voisin(elem2))++;
66 (rang_voisin(elem1))++;
67 }
68
69 // Prise en compte des conditions de type periodicite
70
71 for (i = 0; i < les_cl.size(); i++)
72 {
73 const Cond_lim& la_cl = les_cl[i];
74
75 if (sub_type(Periodique, la_cl.valeur()))
76 {
77 const Periodique& la_cl_perio = ref_cast(Periodique, la_cl.valeur());
78 const Front_VF& la_front_dis = ref_cast(Front_VF, la_cl->frontiere_dis());
79 int numdeb = la_front_dis.num_premiere_face();
80 int nfaces = la_front_dis.nb_faces();
81 int ind_face_global;
82 IntVect fait(nfaces);
83 fait = 0;
84 for (face = 0; face < nfaces; face++)
85 {
86 if (fait[face] == 0)
87 {
88 fait[face] = 1;
89 fait[la_cl_perio.face_associee(face)] = 1;
90 ind_face_global = face + numdeb;
91
92 elem1 = face_voisins(ind_face_global, 0);
93 elem2 = face_voisins(ind_face_global, 1);
94
95 (rang_voisin(elem2))++;
96 (rang_voisin(elem1))++;
97 }
98 }
99 }
100 }
101
102 // on balaye les elements pour dimensionner tab1 et tab2
103
104 tab1(0) = 1;
105 for (i = 0; i < n1; i++)
106 for (k = 0; k < nb_comp; k++)
107 tab1(i * nb_comp + 1 + k) = rang_voisin(i) + tab1(i * nb_comp + k);
108 for (i = n1; i < n1 + n2; i++)
109 for (k = 0; k < nb_comp; k++)
110 tab1(i * nb_comp + 1 + k) = tab1(i * nb_comp + k);
111
112 // Cerr << " dimension de la matrice " << n1*nb_comp
113 // << " " << tab1(n1*nb_comp)-1 <<finl;
114 la_matrice.dimensionner((n1 + n2) * nb_comp, tab1(n1 * nb_comp) - 1);
115
116 for (i = 0; i < n1 * nb_comp; i++)
117 {
118 tab2[tab1[i] - 1] = i + 1;
119 rang_voisin[i] = (int)tab1[i];
120 }
121
122 // on traite les faces internes pour les voisins
123
124 for (num_face = ndeb; num_face < nfin; num_face++)
125 {
126 elem1 = face_voisins(num_face, 0);
127 elem2 = face_voisins(num_face, 1);
128
129 for (k = 0; k < nb_comp; k++)
130 {
131 tab2[rang_voisin[elem2 * nb_comp + k]] = elem1 * nb_comp + 1 + k;
132 rang_voisin[elem2 * nb_comp + k]++;
133
134 tab2[rang_voisin[elem1 * nb_comp + k]] = elem2 * nb_comp + 1 + k;
135 rang_voisin[elem1 * nb_comp + k]++;
136 }
137 }
138 // Cerr << "tab2 = " << tab2 << finl;
139 // on traite la condition de periodicite
140 for (i = 0; i < les_cl.size(); i++)
141 {
142 const Cond_lim& la_cl = les_cl[i];
143 if (sub_type(Periodique, la_cl.valeur()))
144 {
145 const Periodique& la_cl_perio = ref_cast(Periodique, la_cl.valeur());
146 const Front_VF& la_front_dis = ref_cast(Front_VF, la_cl->frontiere_dis());
147 int numdeb = la_front_dis.num_premiere_face();
148 int nfaces = la_front_dis.nb_faces();
149 int ind_face_local;
150 IntVect fait(nfaces);
151 fait = 0;
152 for (ind_face_local = 0; ind_face_local < nfaces; ind_face_local++)
153 {
154 // ind_face_local = num_face - ndeb;
155 if (fait[ind_face_local] == 0)
156 {
157 num_face = numdeb + ind_face_local;
158 fait[ind_face_local] = 1;
159 fait[la_cl_perio.face_associee(ind_face_local)] = 1;
160
161 elem1 = face_voisins(num_face, 0);
162 elem2 = face_voisins(num_face, 1);
163
164 for (k = 0; k < nb_comp; k++)
165 {
166 tab2[rang_voisin[elem2 * nb_comp + k]] = elem1 * nb_comp + 1 + k;
167 rang_voisin[elem2 * nb_comp + k]++;
168
169 tab2[rang_voisin[elem1 * nb_comp + k]] = elem2 * nb_comp + 1 + k;
170 rang_voisin[elem1 * nb_comp + k]++;
171 }
172 }
173 }
174 }
175 }
176 // Cerr << "tab2 = " << tab2 << finl;
177}
178
180{
181
182 int nb_faces = le_domaine.nb_faces();
183 int nb_faces_tot = le_domaine.nb_faces_tot();
184 int nb_elem_tot = le_domaine.nb_elem_tot();
185 Stencil stencyl(0, 2);
186
187 const IntTab& face_voisins = le_domaine.face_voisins();
188
189 int nb_coef = 0;
190 for (int face = 0; face < nb_faces; face++)
191 {
192 for (int dir = 0; dir < 2; dir++)
193 {
194 int elem = face_voisins(face, dir);
195 if (elem != -1)
196 {
197 stencyl.resize(nb_coef + 1, 2);
198 stencyl(nb_coef, 0) = elem;
199 stencyl(nb_coef, 1) = face;
200 nb_coef++;
201 }
202 }
203 }
204 tableau_trier_retirer_doublons(stencyl);
205 Matrix_tools::allocate_morse_matrix(nb_elem_tot, nb_faces_tot, stencyl, matrice);
206
207}
208
209void Op_PolyMAC_CDO_Elem::modifier_pour_Cl(const Domaine_PolyMAC_CDO& le_domaine, const Domaine_Cl_PolyMAC_family& le_domaine_cl, Matrice_Morse& la_matrice, DoubleTab& secmem) const
210{
211 // Dimensionnement de la matrice qui devra recevoir les coefficients provenant de
212 // la convection, de la diffusion pour le cas des faces.
213 // Cette matrice a une structure de matrice morse.
214 // Nous commencons par calculer les tailles des tableaux tab1 et tab2.
215
216 // int nfin = le_domaine.nb_faces();
217 // const Conds_lim& les_cl = le_domaine_cl.les_conditions_limites();
218 // const IntVect& orientation=le_domaine.orientation();
219
220 // Prise en compte des conditions de type periodicite
221 //Cerr << "dans Op_PolyMAC_CDO_Elem:: modifier_pour_Cl" << finl;
222
223}
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
classe Cond_lim Classe generique servant a representer n'importe quelle classe
Definition Cond_lim.h:31
classe Conds_lim Cette classe represente un vecteur de conditions aux limites.
Definition Conds_lim.h:32
int_t nb_elem_tot() const
Definition Domaine.h:132
const Cond_lim & les_conditions_limites(int) const
Renvoie la i-ieme condition aux limites.
int nb_faces() const
renvoie le nombre global de faces.
Definition Domaine_VF.h:471
int nb_faces_tot() const
renvoie le nombre total de faces.
Definition Domaine_VF.h:481
int premiere_face_int() const
une face est interne ssi elle separe deux elements.
Definition Domaine_VF.h:463
int face_voisins(int num_face, int i) const
renvoie l'element voisin de numface dans la direction i.
Definition Domaine_VF.h:418
int nb_elem_tot() const
const Domaine & domaine() const
virtual const Champ_Inc_base & inconnue() const =0
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
auto & get_set_tab2()
void dimensionner(int n, _SIZE_ nnz)
Size the matrix with n lines and n columns and nnz zero-values coefficients.
auto & get_set_coeff()
auto & get_set_tab1()
static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice_Morse &matrix, const bool &attach_stencil_to_matrix=false)
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
void dimensionner(const Domaine_PolyMAC_CDO &, const Domaine_Cl_PolyMAC_family &, Matrice_Morse &) const
void dimensionner_bloc_vitesse(const Domaine_PolyMAC_CDO &, const Domaine_Cl_PolyMAC_family &, Matrice_Morse &) const
void modifier_pour_Cl(const Domaine_PolyMAC_CDO &, const Domaine_Cl_PolyMAC_family &, Matrice_Morse &, DoubleTab &) const
classe Periodique Cette classe represente une condition aux limites periodique.
Definition Periodique.h:31
int face_associee(int i) const
Definition Periodique.h:35
int nb_dim() const
Definition TRUSTTab.h:199
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133