TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Don_lu.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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 <LecFicDiffuse.h>
17#include <Champ_Don_lu.h>
18
19Implemente_instanciable(Champ_Don_lu,"Champ_Don_lu",TRUSTChamp_Don_generique<Champ_Don_Type::LU>);
20// XD champ_don_lu champ_don_base champ_don_lu NO_BRACE Field to read a data field (values located at the center of the
21// XD_CONT cells) in a file.
22// XD attr dom ref_domaine dom REQ Name of the domain.
23// XD attr nb_comp entier nb_comp REQ Number of field components.
24// XD attr file chaine file REQ Name of the file. NL2 This file has the following format: NL2 nb_val_lues -> Number of
25// XD_CONT values readen in th file NL2 Xi Yi Zi -> Coordinates readen in the file NL2 Ui Vi Wi -> Value of the field
26
27
29
31{
32 int dim;
33 //Motcle motlu;
34 Nom nom;
35 is >> nom;
36
37 Domaine& domaine = interprete_get_domaine(nom);
38 int nb_elems = domaine.nb_elem();
39 dim = lire_dimension(is, que_suis_je());
40
41 dimensionner(nb_elems, dim);
42 domaine.creer_tableau_elements(valeurs());
43
44 is >> nom;
45 LecFicDiffuse fic(nom);
46 Cerr << "Open and read the file : " << nom << finl;
47
48 int nb_val_lues = 0;
49 Nom chaine;
50 fic >> chaine;
51 int star_ccm = 0;
52 // Est ce un fichier .csv de STAR-CCM avec en tete: "champ1 unite" "champ2 unite" .... "X" "Y" "Z"
53 if (chaine.debute_par("\""))
54 {
55 star_ccm=1;
56 Cerr << "STAR-CCM csv file detected..." << finl;
57 Cerr << "Find component 1 of the field: " << chaine << finl;
58 for (int i=0; i<dim; i++)
59 {
60 fic >> chaine; // Unite du champ
61 fic >> chaine;
62 if (i<dim-1) Cerr << "Find component " << i+2 << " of the field: " << chaine << finl;
63 }
64 if (chaine!="\"X\"")
65 {
66 Cerr << "Error in the file. There must be one field with " << dim << " components." << finl;
68 }
69 fic >> chaine; // "Y"
70 fic >> chaine; // "Z"
71 // Determination du nombre de lignes du fichier STAR-CCM
72 LecFicDiffuse tmp(nom);
73 while (!tmp.eof())
74 {
75 nb_val_lues++;
76 tmp >> chaine;
77 }
78 nb_val_lues-=(dim*2+dimension+1);
79 nb_val_lues/=(dim+dimension);
80 }
81 else
82 {
83 // Sinon nombre de lignes a lire
84 nb_val_lues=atoi(chaine);
85 Cerr << "The format of this file containing values of a field should be:" << finl;
86 Cerr << "N" << finl;
87 int nb_lines=4;
88 for (int line=1; line<=nb_lines; line++)
89 {
90 if (line==nb_lines-1) Cerr << "..." << finl;
91 else
92 {
93 Nom l;
94 if (line==nb_lines) l="N";
95 else l=(Nom)line;
96
97 Cerr << "x["<<l<<"] y["<<l<<"] ";
98 if (dimension==3) Cerr << "z["<<l<<"] ";
99 for (int k=0; k<dim; k++)
100 Cerr << "value["<<l<<","<<k<<"] ";
101 Cerr << finl;
102 }
103 }
104 }
105 Cerr << finl << "Read number of values (N)=" << nb_val_lues << finl;
106 // Lecture des valeurs dans le fichier fic
107 DoubleTab& mes_val = valeurs();
108 IntTab compteur(nb_elems);
109 compteur = 0;
110 DoubleVect point(dimension);
111 DoubleVect val_lu(dim);
112 int elem2;
113 double x,y,z=0;
114 int pourcent=0,tmp;
115 for (int i=0; i<nb_val_lues; i++)
116 {
117 tmp=(i+1)*10/nb_val_lues;
118 if (tmp>pourcent)
119 {
120 pourcent=tmp;
121 Cerr<<"\rProcess "<<Process::me()<<" has read "<<pourcent*10<<"% of values"<<flush;
122 }
123
124 // Lecture des coordonnees du centre de l'element et des valeurs du champs
125 if (star_ccm)
126 {
127 for (int k=0; k<dim; k++) fic >> val_lu[k];
128 for (int k=0; k<dimension; k++) fic >> point[k];
129 }
130 else
131 {
132 for (int k=0; k<dimension; k++) fic >> point[k];
133 for (int k=0; k<dim; k++) fic >> val_lu[k];
134 }
135 x=point[0];
136 y=point[1];
137 if (Objet_U::dimension==3) z=point[2];
138
139 // Recherche de l'element
140 elem2=domaine.chercher_elements(x,y,z);
141 if ((elem2!=-1) && (elem2<nb_elems))
142 {
143 for (int k=0; k<dim; k++) mes_val(elem2,k) = val_lu[k];
144 compteur[elem2] += 1;
145 }
146 }
147 Cerr << finl;
148 // Verification que tous les elements ont ete trouves
149 for (int num_elem=0; num_elem<nb_elems; num_elem++)
150 if (compteur[num_elem] == 0)
151 {
152 Cerr << "Error when using Champ_Don_lu keyword:" << finl;
153 Cerr << "There is no value found for the cell number " << num_elem << finl;
154 Cerr << "Check your mesh and/or the file " << nom << finl;
156 }
157
158 mes_val.echange_espace_virtuel();
159
160 return is;
161}
void dimensionner(int, int)
Fixe le nombre de composantes et le nombre de valeurs nodales.
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
: class Champ_Don_lu Cette classe represente un champ de donnees que l'on lit dans un fichier avec le...
int lire_dimension(Entree &, const Nom &)
Verification de la dimension du champ Renvoie la dimension du champ.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual int debute_par(const char *const n) const
Definition Nom.cpp:319
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
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
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
Sortie & printOn(Sortie &os) const override
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")