TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Op_VDF_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 <Matrice_Morse.h>
17#include <Equation_base.h>
18#include <Matrix_tools.h>
19#include <Op_VDF_Elem.h>
20#include <Domaine_Cl_VDF.h>
21#include <Array_tools.h>
22#include <Periodique.h>
23#include <Matrix_tools.h>
24#include <Domaine_VDF.h>
25
26void Op_VDF_Elem::dimensionner(const Domaine_VDF& le_dom, const Domaine_Cl_VDF& le_dom_cl, Matrice_Morse& la_matrice, const bool multi_scalar_diff) const
27{
28 if (multi_scalar_diff)
29 dimensionner_multiscalar(le_dom, le_dom_cl, la_matrice, multi_scalar_diff);
30 else
31 dimensionner_old(le_dom, le_dom_cl, la_matrice);
32}
33
34void Op_VDF_Elem::dimensionner_old(const Domaine_VDF& le_dom, const Domaine_Cl_VDF& le_dom_cl, Matrice_Morse& la_matrice) const
35{
36 // Sizing of the matrix that will receive the coefficients from convection and diffusion for element unknowns.
37 // This matrix has a Morse matrix structure.
38 // We start by computing the sizes of arrays tab1 and tab2.
39
40 const IntTab& face_voisins = le_dom.face_voisins();
41 const Conds_lim& les_cl = le_dom_cl.les_conditions_limites();
42 const DoubleTab& champ_inconnue = le_dom_cl.equation().inconnue().valeurs();
43 const int n1 = le_dom.domaine().nb_elem_tot(), nb_comp = champ_inconnue.line_size();
44
45 la_matrice.dimensionner(n1*nb_comp, n1*nb_comp, 0);
46
47 auto& tab1 = la_matrice.get_set_tab1();
48 auto& tab2 = la_matrice.get_set_tab2();
49 auto& coeff = la_matrice.get_set_coeff();
50
51 const int ndeb = le_dom.premiere_face_int(), nfin = le_dom.nb_faces();
52 coeff = 0;
53
54 IntVect rang_voisin(n1*nb_comp);
55 rang_voisin = 1;
56
57 for (int num_face = ndeb; num_face < nfin; num_face++)
58 {
59 const int elem1 = face_voisins(num_face,0), elem2 = face_voisins(num_face,1);
60 (rang_voisin(elem2))++;
61 (rang_voisin(elem1))++;
62 }
63
64 // Taking into account periodic boundary conditions
65 for (const auto& itr : les_cl)
66 {
67 const Cond_lim& la_cl = itr;
68 if (sub_type(Periodique,la_cl.valeur()))
69 {
70 const Periodique& la_cl_perio = ref_cast(Periodique,la_cl.valeur());
71 const Front_VF& la_front_dis = ref_cast(Front_VF,la_cl->frontiere_dis());
72 const int numdeb = la_front_dis.num_premiere_face(), nfaces = la_front_dis.nb_faces();
73 int ind_face_global;
74 IntVect fait(nfaces);
75 fait = 0;
76 for (int face = 0; face < nfaces; face++)
77 {
78 if (fait[face] == 0)
79 {
80 fait[face] = 1;
81 fait[la_cl_perio.face_associee(face)] = 1;
82 ind_face_global = face+numdeb;
83
84 const int elem1 = face_voisins(ind_face_global,0), elem2 = face_voisins(ind_face_global,1);
85
86 (rang_voisin(elem2))++;
87 (rang_voisin(elem1))++;
88 }
89 }
90 }
91 }
92
93 // iterate over elements to size tab1 and tab2
94 tab1(0) = 1;
95 for(int i = 0; i < n1; i++)
96 for (int k = 0; k < nb_comp; k++) tab1(i*nb_comp+1+k) = rang_voisin(i) + tab1(i*nb_comp+k);
97
98 la_matrice.dimensionner(n1*nb_comp,tab1(n1*nb_comp)-1);
99
100 for (int i = 0; i < n1*nb_comp; i++)
101 {
102 tab2[tab1[i]-1] = i+1;
103 rang_voisin[i] = (int)tab1[i];
104 }
105
106 // process internal faces for neighbors
107 for (int num_face = ndeb; num_face < nfin; num_face++)
108 {
109 const int elem1 = face_voisins(num_face,0), elem2 = face_voisins(num_face,1);
110 for (int k = 0; k < nb_comp; k++)
111 {
112 tab2[rang_voisin[elem2*nb_comp+k]] = elem1*nb_comp+1+k;
113 rang_voisin[elem2*nb_comp+k]++;
114
115 tab2[rang_voisin[elem1*nb_comp+k]] = elem2*nb_comp+1+k;
116 rang_voisin[elem1*nb_comp+k]++;
117 }
118 }
119
120 // handle the periodicity condition
121 for (int i=0; i<les_cl.size(); i++)
122 {
123 const Cond_lim& la_cl = les_cl[i];
124 if (sub_type(Periodique,la_cl.valeur()) )
125 {
126 const Periodique& la_cl_perio = ref_cast(Periodique,la_cl.valeur());
127 const Front_VF& la_front_dis = ref_cast(Front_VF,la_cl->frontiere_dis());
128 const int numdeb = la_front_dis.num_premiere_face(), nfaces = la_front_dis.nb_faces();
129 IntVect fait(nfaces);
130 fait = 0;
131 for (int ind_face_local = 0; ind_face_local < nfaces; ind_face_local++)
132 {
133 if (fait[ind_face_local] == 0)
134 {
135 const int num_face = numdeb + ind_face_local;
136 fait[ind_face_local] = 1;
137 fait[la_cl_perio.face_associee(ind_face_local)] = 1;
138
139 const int elem1 = face_voisins(num_face,0), elem2 = face_voisins(num_face,1);
140
141 for (int k = 0; k < nb_comp; k++)
142 {
143 tab2[rang_voisin[elem2*nb_comp+k]] = elem1*nb_comp+1+k;
144 rang_voisin[elem2*nb_comp+k]++;
145
146 tab2[rang_voisin[elem1*nb_comp+k]] = elem2*nb_comp+1+k;
147 rang_voisin[elem1*nb_comp+k]++;
148 }
149 }
150 }
151 }
152 }
153}
154
155void Op_VDF_Elem::dimensionner_multiscalar(const Domaine_VDF& le_dom, const Domaine_Cl_VDF& le_dom_cl, Matrice_Morse& la_matrice, const bool multi_scalar_diff) const
156{
157 const DoubleTab& inco = le_dom_cl.equation().inconnue().valeurs();
158 const int ne = le_dom.nb_elem_tot(), M = inco.line_size();
159 const IntTab& f_e = le_dom.face_voisins(), &e_f = le_dom.elem_faces();
160
161 Stencil sten(0, 2);
162
163 for (int e = 0; e < ne; e++) // Loop over elements
164 for (int i = 0, f, n; i < e_f.dimension(1); i++) // Loop over faces of each element
165 if ((f = e_f(e, i)) >= 0)
166 for (int j = 0; j < 2; j++) // Each side of the hexahedral element?
167 if ((n = f_e(f, j)) >= 0)
168 for (int k = 0; k < M; k++)
169 for (int m = (multi_scalar_diff ? 0 : k); m < (multi_scalar_diff ? M : k + 1); m++) // Each component
170 sten.append_line(M * e + k, M * n + m);
171
172 tableau_trier_retirer_doublons(sten);
173 Matrix_tools::allocate_morse_matrix(inco.size_totale(), inco.size_totale(), sten, la_matrice);
174}
175
176void Op_VDF_Elem:: modifier_pour_Cl(const Domaine_VDF& , const Domaine_Cl_VDF& , Matrice_Morse& , DoubleTab& ) const { /* Do nothing */ }
DoubleTab & valeurs() override
Returns the array of field values at the current time.
class Conds_lim This class represents a vector of boundary conditions.
Definition Conds_lim.h:32
int_t nb_elem_tot() const
Definition Domaine.h:132
class Domaine_Cl_VDF
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
class Domaine_VDF
Definition Domaine_VDF.h:61
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
int elem_faces(int i, int j) const
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
int premiere_face_int() const
A face is internal if and only if it separates two elements.
Definition Domaine_VF.h:463
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in direction i.
Definition Domaine_VF.h:418
int nb_elem_tot() const
const Domaine & domaine() const
virtual const Champ_Inc_base & inconnue() const =0
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
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
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
void modifier_pour_Cl(const Domaine_VDF &, const Domaine_Cl_VDF &, Matrice_Morse &, DoubleTab &) const
void dimensionner(const Domaine_VDF &, const Domaine_Cl_VDF &, Matrice_Morse &, const bool) const
int face_associee(int i) const
Definition Periodique.h:35
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67