TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Fonc_P0_VDF.cpp
1/****************************************************************************
2* Copyright (c) 2022, 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_Fonc_P0_VDF.h>
17#include <LecFicDiffuse.h>
18#include <Domaine_VF.h>
19
20Implemente_instanciable(Champ_Fonc_P0_VDF, "Champ_Fonc_P0_VDF", Champ_Fonc_P0_base);
21
22Sortie& Champ_Fonc_P0_VDF::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
23
25
26/*! @brief Writes the field in IJK format.
27 *
28 * @param os Output stream.
29 * @param ncomp Component index to print.
30 * @return 1 on success.
31 */
32int Champ_Fonc_P0_VDF::imprime(Sortie& os, int ncomp) const
33{
34 // valeur_au_ijk(xi,yj,zk,valeurs,ncomp);
35 // principle: create a point array depending on whether the field is element-based or face-based
36 // with a grid built from xi,yj,zk read from a file
37 // sub_type(Champ_P0, *this): grid built from (xi+xi+1)/2, etc...
38 // Otherwise: grid built from xi, xi+1, etc...
39 // Loop over ni,nj,nk
40 // K=
41 // I=1 I=2 I=3 I=4
42 // J=10 Vij
43 // J=9
44 // ...
45 int ni, nj, nk = -1;
46 int ii, jj, k;
47 int np, elem;
48 int cmax = 7;
49 DoubleVect xi, yj, zk;
50 DoubleTab Grille;
51 //Reading xi,yj,zk from a .xiyjzk file
52 Nom nomfic(nom_du_cas());
53 nomfic += ".xiyjzk";
54 LecFicDiffuse ficijk(nomfic);
55 ficijk >> xi;
56 ni = xi.size();
57 ficijk >> yj;
58 nj = yj.size();
59 if (dimension == 3)
60 {
61 ficijk >> zk;
62 nk = zk.size();
63 }
64 if (ncomp == 1)
65 {
66 if (dimension == 3)
67 {
68 // Grid ordered at element centers
69 np = (ni - 1) * (nj - 1) * (nk - 1);
70 Grille.resize(np, dimension);
71 for (k = 0; k < nk - 1; k++)
72 for (ii = 0; ii < ni - 1; ii++)
73 for (jj = 0; jj < nj - 1; jj++)
74 {
75 elem = jj + (nj - 1) * (ii + k * (ni - 1));
76 Grille(elem, 0) = 0.5 * (xi(ii) + xi(ii + 1));
77 Grille(elem, 1) = 0.5 * (yj(jj) + yj(jj + 1));
78 Grille(elem, 2) = 0.5 * (zk(k) + zk(k + 1));
79 }
80 DoubleTab tab_valeurs(np, nb_compo_);
81 valeur_aux(Grille, tab_valeurs);
82 for (k = 0; k < nk - 1; k++)
83 {
84 os << finl;
85 os << "Coupe a K= " << k << finl;
86 int n1 = 0, n2 = 0;
87 while (n2 < ni - 1)
88 {
89 n1 = n2;
90 n2 = std::min(ni - 1, n2 + cmax);
91 os << finl;
92 os << "I= ";
93 for (int i = n1; i < n2; i++)
94 os << i << " ";
95 os << finl;
96 for (int j = nj - 2; j > -1; j--)
97 {
98 os << "J= " << j << " ";
99 for (int i = n1; i < n2; i++)
100 {
101 elem = j + (nj - 1) * (i + k * (ni - 1));
102 os << tab_valeurs(elem, 0) << " ";
103 }
104 os << finl;
105 }
106 }
107 }
108 }
109 else if (dimension == 2)
110 {
111 np = (ni - 1) * (nj - 1);
112 Grille.resize(np, dimension);
113 for (ii = 0; ii < ni - 1; ii++)
114 for (jj = 0; jj < nj - 1; jj++)
115 {
116 elem = jj + (nj - 1) * ii;
117 Grille(elem, 0) = 0.5 * (xi(ii) + xi(ii + 1));
118 Grille(elem, 1) = 0.5 * (yj(jj) + yj(jj + 1));
119 }
120 DoubleTab tab_valeurs(np, nb_compo_);
121 valeur_aux(Grille, tab_valeurs);
122 int n1 = 0, n2 = 0;
123 while (n2 < ni - 1)
124 {
125 n1 = n2;
126 n2 = std::min(ni - 1, n2 + cmax);
127 os << finl;
128 os << "I= ";
129 for (int i = n1; i < n2; i++)
130 os << i << " ";
131 os << finl;
132 for (int j = nj - 2; j > -1; j--)
133 {
134 os << "J= " << j << " ";
135 for (int i = n1; i < n2; i++)
136 {
137 elem = j + (nj - 1) * i;
138 os << tab_valeurs(elem, 0) << " ";
139 }
140 os << finl;
141 }
142 }
143 }
144 }
145 else
146 {
147 Cerr << "Champ_P0_implementation::imprime_P0_VDF with nb_compo_>1 not implemented." << finl;
148 exit();
149 }
150 return 1;
151}
class Champ_Fonc_P0_VDF
int imprime(Sortie &, int) const override
Writes the field in IJK format.
DoubleTab & valeur_aux(const DoubleTab &, DoubleTab &) const override
Causes an error! Must be overridden by derived classes.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const Nom & le_nom() const override
Returns the name of the field.
int nb_compo_
Definition Field_base.h:95
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
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
static const Nom & nom_du_cas()
Returns a constant reference to the case name. This method is static.
Definition Objet_U.cpp:145
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
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
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ size() const
Definition TRUSTVect.tpp:45