16#include <Integrer_champ_med.h>
18#include <Champ_Fonc_MED.h>
49void calcul_normal_norme(
const ArrOfDouble& org,
const ArrOfDouble& point1,
const ArrOfDouble& point2,ArrOfDouble& normal);
50double calcul_surface_triangle(
const ArrOfDouble& origine,
const ArrOfDouble& point1,
const ArrOfDouble& point2)
52 double normal0=(point1[1]-origine[1])*(point2[2]-origine[2])-((point2[1]-origine[1])*(point1[2]-origine[2]));
54 double normal1=(point1[2]-origine[2])*(point2[0]-origine[0])-((point2[2]-origine[2])*(point1[0]-origine[0]));
55 double normal2=(point1[0]-origine[0])*(point2[1]-origine[1])-((point2[0]-origine[0])*(point1[1]-origine[1]));
56 double res=normal0*normal0+ normal1*normal1 + normal2*normal2 ;
61double portion_surface_elem(
const ArrOfDouble& pointA,
const ArrOfDouble& pointB,
const ArrOfDouble& pointC,
const double z)
63 if (z<=pointA[2])
return 0;
64 if (z>pointC[2])
return calcul_surface_triangle(pointA,pointB,pointC);
65 ArrOfDouble pointD(3);
68 double lambda=(pointB[2]-pointA[2])/(pointC[2]-pointA[2]);
69 for (
int i=0; i<2; i++)
70 pointD[i]=pointA[i]+lambda*(pointC[i]-pointA[i]);
75 double surf_inf=calcul_surface_triangle(pointA,pointB,pointD);
77 if (pointB[2]!=pointA[2])
78 rap=(z-pointA[2])/(pointB[2]-pointA[2]);
79 return surf_inf*rap*rap;
86 double surf_sup=calcul_surface_triangle(pointB,pointD,pointC);
87 double rap=(z-pointC[2])/(pointB[2]-pointC[2]);
88 double surf_tot=calcul_surface_triangle(pointA,pointB,pointC);
89 return surf_tot-surf_sup*rap*rap;
94double portion_surface(
const ArrOfDouble& point0,
const ArrOfDouble& point1,
const ArrOfDouble& point2,
const double zmin,
const double zmax)
96 return portion_surface_elem(point0,point1,point2,zmax)- portion_surface_elem(point0,point1,point2,zmin);
107 Nom nom_fichier(
"integrale");
108 Nom nom_champ_fonc_med;
110 double zmin=0,zmax=0;
118 param.
ajouter(
"nb_tranche",&nb_tranche);
119 param.
ajouter(
"fichier_sortie",&nom_fichier);
122 if ((nom_methode!=
"integrale_en_z")&&(nom_methode!=
"debit_total"))
124 Cerr<<
"method "<<nom_methode <<
" not coded yet "<<finl;
129 Cerr << nom_champ_fonc_med <<
" type is " <<
objet(nom_champ_fonc_med).
que_suis_je() << finl;
130 Cerr <<
"only the objects of type Champ_Fonc_MED can be meshed" << finl;
134 const Domaine& domaine=champ.domaine_dis_base().domaine();
135 const DoubleTab& coord=domaine.les_sommets();
137 IntTab les_elems_mod=domaine.les_elems();
138 const IntTab& les_elems=domaine.les_elems();
140 ArrOfDouble normal(3);
143 const DoubleTab& valeurs= champ.valeurs();
144 assert(valeurs.
dimension(0)==domaine.nb_elem());
146 double dz=(zmax-zmin)/nb_tranche;
147 ArrOfDouble res(nb_tranche),pos(nb_tranche),surface(nb_tranche);
149 Cerr<<
" Field integration using the method "<<nom_methode<<
" on the domain "<<domaine.
le_nom() <<finl;
150 if (nom_methode==
"debit_total")
163 for (
int elem=0; elem<nb_elem; elem++)
166 for (
int i=0; i<3; i++)
167 zz[i] = les_elems(elem,i);
168 std::sort(zz.
begin(), zz.
end(), [&](
int a,
int b)
170 return (coord(a,2)<coord(b,2));
172 for (
int i=0; i<3; i++)
175 les_elems_mod(elem,i)=ss;
179 ArrOfDouble point0(3),point1(3),point2(3);
180 for (
int elem=0; elem<nb_elem; elem++)
183 for (
int i=0; i<3; i++)
185 point0[i]=coord(les_elems(elem,0),i);
186 point1[i]=coord(les_elems(elem,1),i);
187 point2[i]=coord(les_elems(elem,2),i);
189 calcul_normal_norme(point0,point1, point2, normal);
190 for (
int i=0; i<3; i++)
192 point0[i]=coord(les_elems_mod(elem,0),i);
193 point1[i]=coord(les_elems_mod(elem,1),i);
194 point2[i]=coord(les_elems_mod(elem,2),i);
196 for (
int tranche=0; tranche<nb_tranche; tranche++)
199 double zminl=(zmin)+(zmax-zmin)/nb_tranche*tranche;
200 double zmaxl=zminl+dz;
201 pos[tranche]=(zminl+zmaxl)/2.;
202 double z0=coord(les_elems_mod(elem,0),2);
206 double z2=coord(les_elems_mod(elem,2),2);
211 double portion=portion_surface(point0,point1,point2,zminl,zmaxl);
214 for (
int i=0; i<3; i++)
215 prod_scal+=valeurs(elem,i)*normal[i];
216 res[tranche]+=portion*prod_scal;
217 surface[tranche]+=portion;
227 for (
int nb=0; nb<nb_tranche; nb++)
231 res[nb]/=surface[nb];
232 else assert(res[nb]==0);
234 Cout<<
"# overall balance "<<trace<<finl;
235 so<<
"# bilan global "<<trace<<finl;
236 so<<
"# position, valeur moyenne, surface, flux"<<finl;
237 for (
int nb=0; nb<nb_tranche; nb++)
238 so << pos[nb]<<
" "<<res[nb]<<
" "<<surface[nb]<<
" "<<res[nb]*surface[nb]<<finl;
classe Champ_Fonc_MED Load a field from a MED file for a given time.
Class defining operators and methods for all reading operation in an input flow (file,...
Classe Integrer_champ_med Lecture d'un fichier.
Entree & interpreter(Entree &) override
Fonction principale de l'interprete.
Classe de base des objets "interprete".
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
Une chaine de caractere (Nom) en majuscules.
class Nom Une chaine de caractere pour nommer les objets de TRUST
const Nom & le_nom() const override
Renvoie *this;.
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Helper class to factorize the readOn method of Objet_U classes.
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
int lire_avec_accolades_depuis(Entree &is)
Parse the parameter block { ... } from is.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
Classe de base des flux de sortie.
_SIZE_ dimension(int d) const