TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_front_calc_interne.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_front_calc_interne.h>
17#include <Interprete.h>
18#include <Equation_base.h>
19#include <Probleme_base.h>
20#include <Domaine.h>
21#include <Domaine_VF.h>
22#ifdef MEDCOUPLING_
23#include <MEDCouplingMemArray.hxx>
24#endif
25
26Implemente_instanciable_sans_constructeur(Champ_front_calc_interne,"Champ_front_calc_interne",Champ_front_calc);
27
28
33
34/*! @brief DOES NOTHING
35 *
36 * @param (Sortie& os) an output stream
37 * @return (Sortie&) the modified output stream
38 */
40{
41 return os;
42}
43
44/*! @brief Read the name of an unknown field from an input stream.
45 *
46 * Then creates the corresponding boundary field that will relate the two
47 * sides of the internal boundary.
48 * Format:
49 * Champ_front_calc_interne pb_name boundary_name field_name
50 *
51 * @param (Entree& is) an input stream
52 * @return (Entree&) the modified input stream
53 */
55{
56#ifndef MEDCOUPLING_
57 Cerr << "Champ_front_calc_interne needs MEDCoupling" << finl;
58#endif
59
61 return is;
62}
63
65{
66#ifdef MEDCOUPLING_
67 using namespace MEDCoupling;
68
70
71 // Get barycenters of the concerned faces:
72 const Front_VF& fvf = ref_cast(Front_VF, front_dis());
73 const Domaine_VF& zvf = ref_cast(Domaine_VF, fvf.domaine_dis());
74 const DoubleTab& xv = zvf.xv();
75 int nbfaces = fvf.nb_faces();
76
77 if (nbfaces % 2)
78 {
79 Cerr << "ERROR : Champ_front_calc_interne::completer() - number of faces of the internal boundary is not even!"<< finl;
81 }
82 face_map_.resize(nbfaces,RESIZE_OPTIONS::NOCOPY_NOINIT);
83
84 if (nbfaces>0)
85 {
86 const int ndim = xv.dimension(1);
87 MCAuto<DataArrayDouble> coo(DataArrayDouble::New());
88 coo->alloc(nbfaces, ndim);
89
90 for (int i = 0; i < nbfaces; i++)
91 {
92 int num_f = fvf.num_face(i);
93
94 for (int d = 0; d < ndim; d++)
95 coo->setIJSilent(i, d, xv(num_f, d));
96 }
97
98 DataArrayIdType *cP, *cIP;
99 coo->findCommonTuples(Objet_U::precision_geom, 0, cP, cIP);
100 int nb_faces_dup = (int)cP->getNumberOfTuples();
101 if (nb_faces_dup == nbfaces)
102 {
103 // Duplicated faces -> singularity at the gap level
104 MCAuto<DataArrayIdType> dsi(cIP->deltaShiftIndex());
105
106 if (!dsi->isUniform(2))
107 {
108 Cerr << "ERROR : Problem on internal boundary. Some face(s) not duplicated." << finl;
109 Process::exit(1);
110 }
111
112 const mcIdType *p(cP->begin());
113 for (int i = 0; i < nbfaces / 2; i++, p += 2)
114 {
115 int pi1 = (int)(*p), pi2 = (int)(*(p+1));
116 face_map_(pi1) = pi2;
117 face_map_(pi2) = pi1;
118 }
119 }
120 else
121 {
122 // Non-zero dimension gap -> we search for the closest
123 // opposite face point
124 const DoubleVect& face_surfaces = zvf.face_surfaces();
125 MCAuto<DataArrayDouble> fnorm(DataArrayDouble::New());
126 fnorm->alloc(nbfaces, 1);
127 fnorm->fillWithZero();
128
129 double* pfnorm = fnorm->getPointer();
130
131 for (int i = 0; i < nbfaces; i++)
132 {
133 int num_f = fvf.num_face(i);
134
135 for (int d = 0; d < ndim; d++)
136 {
137 pfnorm[i]+=zvf.face_normales(num_f,d);
138 coo->setIJSilent(i, d, xv(num_f, d));
139 }
140 pfnorm[i]/=face_surfaces(num_f);
141 }
142
143 double eps = 1e-10;
144
145 MCAuto<DataArrayIdType> Idpos = fnorm->findIdsInRange(1-eps,1+eps);
146 MCAuto<DataArrayIdType> Idneg = fnorm->findIdsInRange(-1-eps,-1+eps);
147
148 mcIdType n1 = Idpos->getNumberOfTuples();
149 mcIdType n2 = Idneg->getNumberOfTuples();
150
151 if ((n1!=n2) || (n1+n2)!=nbfaces)
152 {
153 Cerr << "ERROR : Problem on internal boundary. Cannot associate pairs of faces." << finl;
154 Process::exit(1);
155 }
156 MCAuto<DataArrayDouble> coo_pos = coo->selectByTupleId(*Idpos);
157 MCAuto<DataArrayDouble> coo_neg = coo->selectByTupleId(*Idneg);
158
159 const mcIdType* pIdpos = Idpos->getConstPointer();
160 const mcIdType* pIdneg = Idneg->getConstPointer();
161
162 MCAuto<DataArrayIdType> idx = coo_pos->findClosestTupleId(coo_neg);
163
164 const mcIdType* pidx = idx->getConstPointer();
165
166 for (int i=0; i<nbfaces/2; i++)
167 {
168 int j2 = (int)pIdneg[i];
169 int k = (int)pidx[i];
170 int j1 = (int)pIdpos[k];
171
172 face_map_(j1) = j2;
173 face_map_(j2) = j1;
174 }
175 }
176 cIP->decrRef();
177 cP->decrRef();
178 }
179#endif
180}
181
183{
185 // Swap values (implies a copy)
186 DoubleTab& tab=valeurs_au_temps(temps);
187 assert(tab.nb_dim() == 2 && tab.dimension(1) == 1);
188 DoubleTab tmp(tab);
189 for (int i = 0; i < tab.dimension(0); i++)
190 tab(i,0) = tmp(face_map_(i),0);
191}
virtual void completer()
class Champ_front_calc_interne Derived class of Champ_front_calc representing
void mettre_a_jour(double temps) override
Time update of the field. We simply take the trace of the unknown field at the.
class Champ_front_calc Derived class of Champ_front_var representing
const Frontiere_dis_base & front_dis() const
Returns the discretized boundary corresponding to the domain on which the trace is taken.
void set_distant(int d)
void mettre_a_jour(double temps) override
Time update of the field. We simply take the trace of the unknown field at the.
DoubleTab & valeurs_au_temps(double temps) override
Returns the values at the desired time.
class Domaine_VF
Definition Domaine_VF.h:44
virtual const DoubleVect & face_surfaces() const
Definition Domaine_VF.h:51
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
double xv(int num_face, int k) const
Definition Domaine_VF.h:76
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_face(const int) const
Definition Front_VF.h:68
const Domaine_dis_base & domaine_dis() const
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
static double precision_geom
Definition Objet_U.h:81
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
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133