TrioCFD 1.9.9_beta
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}
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
void remplir_vit_som_bord_ALE(double temps) override
DoubleTab vit_som_bord_ALE
virtual DoubleTab & valeurs() override
Returns the array of field values.
DoubleTab_t & les_sommets()
Definition Domaine.h:113
int_t nb_som() const
Returns the number of vertices of the domain.
Definition Domaine.h:121
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this 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
Returns the array of vertices of all faces.
Definition Faces.h:74
virtual void fixer_nb_comp(int i)
Sets the number of components of the field.
virtual int nb_comp() const
Definition Field_base.h:56
const Domaine_t & domaine() const
Returns the domain associated with the boundary (const version).
const Faces_t & faces() const
Definition Frontiere.h:54
const Nom & le_nom() const override
Returns *this.
Definition Nom.cpp:555
const Interprete & interprete() const
Definition Objet_U.cpp:211
static int dimension
Definition Objet_U.h:94
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
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Probleme_U.h:109
class Probleme_base It is a Probleme_U that is not a coupling.
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
const Domaine & domaine() const
Returns the domain associated with the problem.
const Champ_base & get_champ(const Motcle &nom) const override
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
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133