TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_front_ALE_lag.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_ALE_lag.h>
17#include <Champ_base.h>
18#include <Frontiere_dis_base.h>
19#include <Interprete.h>
20#include <Probleme_base.h>
21
22#ifdef MEDCOUPLING_
23#include <medcoupling++.h>
24#include <MEDCouplingMemArray.hxx>
25using namespace MEDCoupling;
26#endif
27
28Implemente_instanciable(Champ_front_ALE_lag, "Champ_front_ALE_lag", Champ_front_ALE);
29// XD Champ_front_ALE_lag front_field_base Champ_front_ALE_lag NO_BRACE Boundary field that fetches ALE nodal velocities
30// XD_CONT from an external Lagrangian velocity field. NL2 Example: Champ_front_ALE_lag pb_vitesse champ_vitesse
31
33{
34 is >> external_pb_name_ >> external_field_name_;
36 return is;
37}
38
40{
41 os << external_pb_name_ << " " << external_field_name_;
42 return os;
43}
44
45const Probleme_base& Champ_front_ALE_lag::external_problem() const
46{
47 if (external_pb_name_ == "??")
48 {
49 Cerr << "Champ_front_ALE_lag : aucun probleme externe n'a ete specifie." << finl;
51 }
52 return ref_cast(Probleme_base, interprete().objet(external_pb_name_));
53}
54
55const Champ_base& Champ_front_ALE_lag::external_field(const Probleme_base& pb) const
56{
57 if (external_field_name_ == "??")
58 {
59 Cerr << "Champ_front_ALE_lag : aucun champ externe n'a ete specifie." << finl;
61 }
62 if (!pb.has_champ(external_field_name_))
63 {
64 Cerr << "Champ_front_ALE_lag : le probleme " << pb.le_nom()
65 << " ne contient pas de champ " << external_field_name_ << finl;
67 }
68 return pb.get_champ(external_field_name_);
69}
70
71void Champ_front_ALE_lag::check_external_field(const Champ_base& champ) const
72{
73 const DoubleTab& valeurs = champ.valeurs();
74 if (valeurs.line_size() != nb_comp())
75 {
76 Cerr << "Champ_front_ALE_lag : le champ externe " << champ.le_nom()
77 << " doit avoir " << nb_comp() << " composantes par sommet (line_size="
78 << valeurs.line_size() << ")." << finl;
80 }
81}
82
83void Champ_front_ALE_lag::build_vertex_mapping(const Domaine& ale_dom, const Domaine& ext_dom)
84{
85#ifndef MEDCOUPLING_
86 Cerr << "Champ_front_ALE_lag : MEDCoupling est requis pour utiliser un champ lagrangien externe." << finl;
88#else
89 const DoubleTab& ext_coords = ext_dom.les_sommets();
90 const DoubleTab& ale_coords = ale_dom.les_sommets();
91
92 const int dim = dimension;
93 const int nb_ext = ext_coords.dimension(0);
94 const int nb_ale = ale_coords.dimension(0);
95
96 MCAuto<DataArrayDouble> ext_pts(DataArrayDouble::New());
97 MCAuto<DataArrayDouble> ale_pts(DataArrayDouble::New());
98 ext_pts->alloc(nb_ext, dim);
99 ale_pts->alloc(nb_ale, dim);
100
101 double * ext_ptr = ext_pts->getPointer();
102 for (int i = 0; i < nb_ext; i++)
103 for (int d = 0; d < dim; d++)
104 ext_ptr[i * dim + d] = ext_coords(i, d);
105
106 double * ale_ptr = ale_pts->getPointer();
107 for (int i = 0; i < nb_ale; i++)
108 for (int d = 0; d < dim; d++)
109 ale_ptr[i * dim + d] = ale_coords(i, d);
110
111 MCAuto<DataArrayIdType> closest(ext_pts->findClosestTupleId(ale_pts));
112 external_vertex_id_for_ale_vertex_.resize(nb_ale);
113 external_vertex_id_for_ale_vertex_ = -1;
114 for (int i = 0; i < nb_ale; i++)
115 external_vertex_id_for_ale_vertex_[i] = static_cast<int>(closest->getIJ(i, 0));
116 mapping_initialized_ = true;
117 mapping_size_ = nb_ale;
118#endif
119}
120
122{
123#ifndef MEDCOUPLING_
124 Cerr << "Champ_front_ALE_lag::remplir_vit_som_bord_ALE : MEDCoupling est requis pour utiliser un champ lagrangien externe." << finl;
126#else
127 (void)tps;
128 const Probleme_base& pb = external_problem();
129 const Champ_base& champ = external_field(pb);
130 check_external_field(champ);
131
132 const Frontiere& front = la_frontiere_dis->frontiere();
133 const Domaine& domaine = front.domaine();
134 const Domaine& external_dom = pb.domaine();
135 const DoubleTab& valeurs = champ.valeurs();
136
137 if (valeurs.dimension(0) != external_dom.nb_som())
138 {
139 Cerr << "Champ_front_ALE_lag : le champ " << champ.le_nom()
140 << " contient " << valeurs.dimension(0) << " sommets alors que le domaine "
141 << external_dom.le_nom() << " en possede " << external_dom.nb_som() << "." << finl;
143 }
144
145 if (!mapping_initialized_ || mapping_size_ != domaine.nb_som())
146 build_vertex_mapping(domaine, external_dom);
147
148 const int nb_som_tot = domaine.nb_som_tot();
149 vit_som_bord_ALE.resize(nb_som_tot, nb_comp());
150 vit_som_bord_ALE = 0.;
151
152 const IntTab& faces_som = front.faces().les_sommets();
153 const int nb_faces = faces_som.dimension(0);
154 const int nb_som_face = faces_som.dimension(1);
155 for (int f = 0; f < nb_faces; f++)
156 for (int k = 0; k < nb_som_face; k++)
157 {
158 const int som = faces_som(f, k);
159 if (som < 0) continue;
160 const int ext = external_vertex_id_for_ale_vertex_[som];
161 if (ext < 0) continue;
162 for (int comp = 0; comp < nb_comp(); comp++)
163 vit_som_bord_ALE(som, comp) = valeurs(ext, comp);
164 }
165#endif
166}
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
void remplir_vit_som_bord_ALE(double temps) override
DoubleTab vit_som_bord_ALE
virtual DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ.
DoubleTab_t & les_sommets()
Definition Domaine.h:113
int_t nb_som() const
Renvoie le nombre de sommets du domaine.
Definition Domaine.h:121
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const IntTab_t & les_sommets() const
Renvoie le tableau des sommets de toutes les faces.
Definition Faces.h:74
virtual void fixer_nb_comp(int i)
Fixe le nombre de composantes du champ.
virtual int nb_comp() const
Definition Field_base.h:56
const Domaine_t & domaine() const
Renvoie le domaine associe a la frontiere.
const Faces_t & faces() const
Definition Frontiere.h:54
const Nom & le_nom() const override
Renvoie *this;.
Definition Nom.cpp:563
const Interprete & interprete() const
Definition Objet_U.cpp:212
static int dimension
Definition Objet_U.h:99
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
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Probleme_U.h:109
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
const Domaine & domaine() const
Renvoie le domaine associe au probleme.
const Champ_base & get_champ(const Motcle &nom) const override
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
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133