TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Q1NC.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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 <Domaine_Cl_dis_base.h>
17#include <Equation_base.h>
18#include <Champ_Q1NC.h>
19#include <Periodique.h>
20#include <Debog.h>
21
22Implemente_instanciable(Champ_Q1NC,"Champ_Q1NC",Champ_Inc_base);
23
24Sortie& Champ_Q1NC::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
25
27{
28 lire_donnees(s) ;
29 return s ;
30}
31
32// Periodic BC case: ensures that values on facing periodic boundary faces are identical.
33// To do so, the half-sum of the two values is used.
35{
37 int nb_cl = zcl.nb_cond_lim();
38 DoubleTab& ch_tab = valeurs();
39 int nb_compo = nb_comp();
40 int ndeb, nfin, num_face;
41
42 for (int i = 0; i < nb_cl; i++)
43 {
44 const Cond_lim_base& la_cl = zcl.les_conditions_limites(i).valeur();
45 if (sub_type(Periodique, la_cl))
46 {
47 const Periodique& la_cl_perio = ref_cast(Periodique, la_cl);
48 const Front_VF& le_bord = ref_cast(Front_VF, la_cl.frontiere_dis());
49 ndeb = le_bord.num_premiere_face();
50 nfin = ndeb + le_bord.nb_faces();
51 int voisine;
52 double moy;
53
54 for (num_face = ndeb; num_face < nfin; num_face++)
55 {
56 voisine = la_cl_perio.face_associee(num_face - ndeb) + ndeb;
57 for (int comp = 0; comp < nb_compo; comp++)
58 {
59 if (ch_tab(num_face, comp) != ch_tab(voisine, comp))
60 {
61 moy = 0.5 * (ch_tab(num_face, comp) + ch_tab(voisine, comp));
62 ch_tab(num_face, comp) = moy;
63 ch_tab(voisine, comp) = moy;
64 }
65 }
66 }
67 }
68 }
70}
71
73{
74 double vit_norm = 0;
75 for (int ncomp = 0; ncomp < nb_comp(); ncomp++)
76 vit_norm += valeurs()(num_face, ncomp) * domaine_vef().face_normales(num_face, ncomp);
77 return (vit_norm > 0);
78}
79
80DoubleTab& Champ_Q1NC::trace(const Frontiere_dis_base& fr, DoubleTab& x, double tps, int distant) const
81{
82 return Champ_Q1NC_implementation::trace(fr, valeurs(tps), x, distant);
83}
84
85void Champ_Q1NC::cal_rot_ordre1(DoubleTab& vorticite)
86{
87 const int nb_elem = domaine_vef().nb_elem();
88
89 DoubleTab gradient_elem(0, dimension, dimension);
90 // the array is initialized in the gradient() method:
91 domaine_vef().domaine().creer_tableau_elements(gradient_elem, RESIZE_OPTIONS::NOCOPY_NOINIT);
92
93 gradient(gradient_elem);
94 Debog::verifier("apres calcul gradient", gradient_elem);
95 int num_elem;
96
97 switch(dimension)
98 {
99 case 2:
100 {
101 for (num_elem = 0; num_elem < nb_elem; num_elem++)
102 {
103 vorticite(num_elem) = gradient_elem(num_elem, 1, 0) - gradient_elem(num_elem, 0, 1);
104 }
105 }
106 break;
107 case 3:
108 {
109 for (num_elem = 0; num_elem < nb_elem; num_elem++)
110 {
111 vorticite(num_elem, 0) = gradient_elem(num_elem, 2, 1) - gradient_elem(num_elem, 1, 2);
112 vorticite(num_elem, 1) = gradient_elem(num_elem, 0, 2) - gradient_elem(num_elem, 2, 0);
113 vorticite(num_elem, 2) = gradient_elem(num_elem, 1, 0) - gradient_elem(num_elem, 0, 1);
114 }
115 }
116 }
117
118 Debog::verifier("apres calcul vort", vorticite);
119 return;
120}
121
122void Champ_Q1NC::gradient(DoubleTab& gradient_elem)
123{
124 // Compute the velocity gradient for vorticity computation
125 const Domaine_VEF& domaine_VEF = domaine_vef();
126 const DoubleTab& vitesse = equation().inconnue().valeurs();
127
128 const DoubleTab& face_normales = domaine_VEF.face_normales();
129 const int nb_faces = domaine_VEF.nb_faces();
130 const int nb_elem = domaine_VEF.nb_elem();
131 const IntTab& face_voisins = domaine_VEF.face_voisins();
132 int premiere_face_int = domaine_VEF.premiere_face_int();
133 const DoubleVect& volumes = domaine_VEF.volumes();
134
135 assert(gradient_elem.dimension(0) == nb_elem);
136 assert(gradient_elem.dimension(1) == dimension);
137 assert(gradient_elem.dimension(2) == dimension);
138 operator_egal(gradient_elem, 0.); // Espace reel uniquement
139 int icomp, fac, i, elem1, elem2;
140
141 // Loop over faces
142
143 for (fac = 0; fac < premiere_face_int; fac++)
144 {
145 elem1 = face_voisins(fac, 0);
146 for (icomp = 0; icomp < dimension; icomp++)
147 for (i = 0; i < dimension; i++)
148 {
149 gradient_elem(elem1, icomp, i) += face_normales(fac, i) * vitesse(fac, icomp);
150 }
151 }
152 for (; fac < nb_faces; fac++)
153 {
154 elem1 = face_voisins(fac, 0);
155 elem2 = face_voisins(fac, 1);
156 for (icomp = 0; icomp < dimension; icomp++)
157 for (i = 0; i < dimension; i++)
158 {
159 gradient_elem(elem1, icomp, i) += face_normales(fac, i) * vitesse(fac, icomp);
160 if (elem2 < nb_elem)
161 gradient_elem(elem2, icomp, i) -= face_normales(fac, i) * vitesse(fac, icomp);
162 }
163 }
164
165 tab_divide_any_shape(gradient_elem, volumes);
166}
167
169{
170 const MD_Vector& md = domaine_vef().md_vector_faces();
172 return 1;
173}
Class Champ_Inc_base.
virtual void creer_tableau_distribue(const MD_Vector &, RESIZE_OPTIONS=RESIZE_OPTIONS::COPY_INIT)
int lire_donnees(Entree &)
Reads the field values from an input stream.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
DoubleTab & trace(const Frontiere_dis_base &fr, const DoubleTab &y, DoubleTab &x, int distant) const
void cal_rot_ordre1(DoubleTab &)
int compo_normale_sortante(int) const
void gradient(DoubleTab &)
DoubleTab & trace(const Frontiere_dis_base &, DoubleTab &, double, int distant) const override
See Champ_base. Special case (unfortunately) of Champ_P0_VDF:
void verifie_valeurs_cl() override
const Domaine_VEF & domaine_vef() const override
Definition Champ_Q1NC.h:37
int fixer_nb_valeurs_nodales(int n) override
class Cond_lim_base Base class for the hierarchy of classes that represent the different boundary con...
virtual Frontiere_dis_base & frontiere_dis()
Returns the discretized boundary to which the boundary conditions apply.
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
virtual void creer_tableau_elements(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
Creates a parallel array of values at elements.
Definition Domaine.cpp:850
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
int nb_cond_lim() const
Returns the number of boundary conditions.
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
class Domaine_VEF
Definition Domaine_VEF.h:53
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
const MD_Vector & md_vector_faces() const
Definition Domaine_VF.h:158
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
double volumes(int i) const
Definition Domaine_VF.h:113
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
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Champ_Inc_base & inconnue() const =0
virtual Domaine_Cl_dis_base & domaine_Cl_dis()
Returns the discretized boundary condition domain associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
virtual int nb_comp() const
Definition Field_base.h:56
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
class Frontiere_dis_base Class representing a discretized boundary.
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
class Periodique This class represents a periodic boundary condition.
Definition Periodique.h:31
int face_associee(int i) const
Definition Periodique.h:35
Base class for output streams.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")