TrioCFD 1.9.9_beta
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 // Is this a STAR-CCM .csv file with header: "field1 unit" "field2 unit" .... "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; // Field unit
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 // Determine the number of lines in the STAR-CCM file
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 // Otherwise number of lines to read
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 // Read the values from file 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 // Read the element center coordinates and field values
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 // Find the 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 // Check that all elements have been found
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)
Sets the number of components and the number of nodal values.
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
: class Champ_Don_lu This class represents a data field read from a file with the following conventio...
int lire_dimension(Entree &, const Nom &)
Verification of the field dimension Returns the dimension of the field.
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:314
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
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52
Sortie & printOn(Sortie &os) const override
Writes the object to an output stream. Virtual method to override.
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")