TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_som_lu.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 <Champ_implementation_P1.h>
17#include <LecFicDiffuse.h>
18#include <Champ_som_lu.h>
19
20Implemente_instanciable(Champ_som_lu,"Champ_som_lu",TRUSTChamp_Don_generique<Champ_Don_Type::LU>);
21
22Sortie& Champ_som_lu::printOn(Sortie& os) const { return not_implemented_champ_<Sortie&>(__func__); }
23
25{
26 int nbcomp;
27 double tolerance;
28 Nom nom;
29 is >> nom;
30 mon_domaine = ref_cast(Domaine, Interprete::objet(nom));
31 is >> nbcomp; // nombre de composantes du champ
32 is >> tolerance; // tolerance en metres pour la recherche des coordonnees
33 is >> nom; // nom du fichier a lire
34 LecFicDiffuse file(nom);
35 fixer_nb_comp(nbcomp);
36 Champ_implementation_P1::init_from_file(valeurs_, mon_domaine.valeur(), nbcomp, tolerance, file);
37 return is;
38}
39
40DoubleTab& Champ_som_lu::valeur_aux_elems(const DoubleTab& positions, const IntVect& les_polys, DoubleTab& val) const
41{
42 if (val.nb_dim() == 2)
43 {
44 assert(val.dimension(0) == les_polys.size_array());
45 assert(val.line_size() == nb_compo_);
46 }
47 else erreur_champ_(__func__);
48
49 const DoubleTab& coord = mon_domaine->coord_sommets();
50 const DoubleTab& ch = valeurs();
51 int le_poly;
52
53 for (int rang_poly = 0; rang_poly < les_polys.size_array(); rang_poly++)
54 {
55 le_poly = les_polys(rang_poly);
56 if (le_poly == -1)
57 for (int ncomp = 0; ncomp < nb_compo_; ncomp++) val(rang_poly, ncomp) = 0;
58 else
59 for (int ncomp = 0; ncomp < nb_compo_; ncomp++)
60 {
61 int som1 = mon_domaine->sommet_elem(le_poly, 0);
62 int som2 = mon_domaine->sommet_elem(le_poly, 1);
63 int som3 = mon_domaine->sommet_elem(le_poly, 2);
64 int som4 = mon_domaine->sommet_elem(le_poly, 3);
65 int som5 = mon_domaine->sommet_elem(le_poly, 4);
66 int som6 = mon_domaine->sommet_elem(le_poly, 5);
67 int som7 = mon_domaine->sommet_elem(le_poly, 6);
68 int som8 = mon_domaine->sommet_elem(le_poly, 7);
69
70 double xmin = coord(som1, 0);
71 double xmax = coord(som2, 0);
72 double ymin = coord(som1, 1);
73 double ymax = coord(som3, 1);
74 double zmin = coord(som1, 2);
75 double zmax = coord(som5, 2);
76
77 double hx = xmax - xmin;
78 double hy = ymax - ymin;
79 double hh = zmax - zmin;
80
81 val(rang_poly, ncomp) = ch(som1, ncomp) * (xmax - positions(rang_poly, 0)) * (ymax - positions(rang_poly, 1)) * (zmax - positions(rang_poly, 2));
82 val(rang_poly, ncomp) += ch(som2, ncomp) * (positions(rang_poly, 0) - xmin) * (ymax - positions(rang_poly, 1)) * (zmax - positions(rang_poly, 2));
83 val(rang_poly, ncomp) += ch(som3, ncomp) * (xmax - positions(rang_poly, 0)) * (positions(rang_poly, 1) - ymin) * (zmax - positions(rang_poly, 2));
84 val(rang_poly, ncomp) += ch(som4, ncomp) * (positions(rang_poly, 0) - xmin) * (positions(rang_poly, 1) - ymin) * (zmax - positions(rang_poly, 2));
85 val(rang_poly, ncomp) += ch(som5, ncomp) * (xmax - positions(rang_poly, 0)) * (ymax - positions(rang_poly, 1)) * (positions(rang_poly, 2) - zmin);
86 val(rang_poly, ncomp) += ch(som6, ncomp) * (positions(rang_poly, 0) - xmin) * (ymax - positions(rang_poly, 1)) * (positions(rang_poly, 2) - zmin);
87 val(rang_poly, ncomp) += ch(som7, ncomp) * (xmax - positions(rang_poly, 0)) * (positions(rang_poly, 1) - ymin) * (positions(rang_poly, 2) - zmin);
88 val(rang_poly, ncomp) += ch(som8, ncomp) * (positions(rang_poly, 0) - xmin) * (positions(rang_poly, 1) - ymin) * (positions(rang_poly, 2) - zmin);
89
90 val(rang_poly, ncomp) /= (hx * hy * hh);
91 }
92 }
93 return val;
94}
95
96DoubleVect& Champ_som_lu::valeur_aux_elems_compo(const DoubleTab& positions, const IntVect& les_polys, DoubleVect& val, int ncomp) const
97{
98 assert(val.size_totale() >= les_polys.size_array());
99 const DoubleTab& coord = mon_domaine->coord_sommets();
100 const DoubleTab& ch = valeurs();
101 int le_poly;
102
103 for (int rang_poly = 0; rang_poly < les_polys.size_array(); rang_poly++)
104 {
105 le_poly = les_polys(rang_poly);
106 if (le_poly == -1) val(rang_poly) = 0;
107 else
108 {
109 int som1 = mon_domaine->sommet_elem(le_poly, 0);
110 int som2 = mon_domaine->sommet_elem(le_poly, 1);
111 int som3 = mon_domaine->sommet_elem(le_poly, 2);
112 int som4 = mon_domaine->sommet_elem(le_poly, 3);
113 int som5 = mon_domaine->sommet_elem(le_poly, 4);
114 int som6 = mon_domaine->sommet_elem(le_poly, 5);
115 int som7 = mon_domaine->sommet_elem(le_poly, 6);
116 int som8 = mon_domaine->sommet_elem(le_poly, 7);
117
118 double xmin = coord(som1, 0);
119 double xmax = coord(som2, 0);
120 double ymin = coord(som1, 1);
121 double ymax = coord(som3, 1);
122 double zmin = coord(som1, 2);
123 double zmax = coord(som5, 2);
124
125 double hx = xmax - xmin;
126 double hy = ymax - ymin;
127 double hh = zmax - zmin;
128
129 val(rang_poly) = ch(som1, ncomp) * (xmax - positions(rang_poly, 0)) * (ymax - positions(rang_poly, 1)) * (zmax - positions(rang_poly, 2));
130 val(rang_poly) += ch(som2, ncomp) * (positions(rang_poly, 0) - xmin) * (ymax - positions(rang_poly, 1)) * (zmax - positions(rang_poly, 2));
131 val(rang_poly) += ch(som3, ncomp) * (xmax - positions(rang_poly, 0)) * (positions(rang_poly, 1) - ymin) * (zmax - positions(rang_poly, 2));
132 val(rang_poly) += ch(som4, ncomp) * (positions(rang_poly, 0) - xmin) * (positions(rang_poly, 1) - ymin) * (zmax - positions(rang_poly, 2));
133 val(rang_poly) += ch(som5, ncomp) * (xmax - positions(rang_poly, 0)) * (ymax - positions(rang_poly, 1)) * (positions(rang_poly, 2) - zmin);
134 val(rang_poly) += ch(som6, ncomp) * (positions(rang_poly, 0) - xmin) * (ymax - positions(rang_poly, 1)) * (positions(rang_poly, 2) - zmin);
135 val(rang_poly) += ch(som7, ncomp) * (xmax - positions(rang_poly, 0)) * (positions(rang_poly, 1) - ymin) * (positions(rang_poly, 2) - zmin);
136 val(rang_poly) += ch(som8, ncomp) * (positions(rang_poly, 0) - xmin) * (positions(rang_poly, 1) - ymin) * (positions(rang_poly, 2) - zmin);
137
138 val(rang_poly) /= (hx * hy * hh);
139 }
140 }
141 return val;
142}
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
DoubleTab valeurs_
static void init_from_file(DoubleTab &val, const Domaine &dom, int nb_comp, double tolerance, Entree &input)
Initialise le tableau de valeurs aux sommets du domaine dom a partir de valeurs lues dans "input".
DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &les_polys, DoubleTab &valeurs) const override
provoque une erreur ! doit etre surchargee par les classes derivees
DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &les_polys, DoubleVect &valeurs, int ncomp) const override
provoque une erreur ! doit etre surchargee par les classes derivees
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Fixe le nombre de composantes du champ.
int nb_compo_
Definition Field_base.h:95
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ size_array() const
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67