TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Fonc_MED.h
1/****************************************************************************
2* Copyright (c) 2026, 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#ifndef Champ_Fonc_MED_included
17#define Champ_Fonc_MED_included
18
19#include <Domaine_VF_inst.h>
20#include <TRUSTArray.h>
21
22#include <Param.h>
23#include <med++.h>
24#include <medcoupling++.h>
25#ifdef MEDCOUPLING_
26#include <MEDCouplingFieldDouble.hxx>
27using MEDCoupling::MEDCouplingField;
28#endif
29
30
31/*! @brief class Champ_Fonc_MED Load a field from a MED file for a given time.
32 *
33 * @sa Champ_Fonc_P0
34 */
36{
37 Declare_instanciable(Champ_Fonc_MED);
38public :
39 inline void associer_domaine_dis_base(const Domaine_dis_base&) override;
40 const Domaine_dis_base& domaine_dis_base() const override { return domainebidon_inst; }
41 const Domaine_VF& domaine_vf() const override { throw; }
42
43 void mettre_a_jour(double ) override;
44 int creer(const Nom&,const Domaine& dom,const Motcle& localisation,ArrOfDouble& temps_sauv);
45
46 const Domaine& domaine() const override { return mon_dom; }
47 virtual void lire(double tps,int given_iteration=-1);
48 int nb_pas_temps() { return nb_dt; }
50 inline DoubleTab& valeurs() override;
51 inline const DoubleTab& valeurs() const override;
52
53 inline DoubleTab& valeur_aux_elems(const DoubleTab& positions, const IntVect& les_polys, DoubleTab& valeurs) const override;
54 inline DoubleVect& valeur_aux_elems_compo(const DoubleTab& positions, const IntVect& les_polys, DoubleVect& valeurs, int ncomp) const override;
55 inline DoubleTab& valeur_aux_sommets(const Domaine&, DoubleTab&) const override;
56 inline DoubleVect& valeur_aux_sommets_compo(const Domaine&, DoubleVect&, int) const override;
57 inline DoubleVect& valeur_a(const DoubleVect& position, DoubleVect& valeurs) const override;
58
59 inline DoubleVect& valeur_a_elem(const DoubleVect& position, DoubleVect& valeurs, int le_poly) const override ;
60 inline DoubleTab& remplir_coord_noeuds(DoubleTab& ) const override;
61 inline int remplir_coord_noeuds_et_polys(DoubleTab&, IntVect&) const override;
62 inline virtual const Champ_Fonc_base& le_champ() const;
63 inline virtual Champ_Fonc_base& le_champ();
64 const ArrOfDouble& get_saved_times() const { return temps_sauv_; }
65private:
66#ifdef MEDCOUPLING_
67 ArrOfDouble lire_temps_champ(const std::string& fileName, const std::string& fieldName);
68 virtual void lire_donnees_champ(const std::string& fileName, const std::string& meshName, const std::string& fieldName,
69 ArrOfDouble& temps_sauv, int& size, int& nbcomp, Nom& type_champ);
70 MCAuto<MEDCoupling::MEDCouplingField> lire_champ(const std::string& fileName, const std::string& meshName, const std::string& fieldName, const int iteration, const int order);
71#endif
72
73protected:
74 // Parameters read in the dataset:
79 double temps_=0.0;
80 bool last_time_only_ = false;
81
82 // Other:
83 OBS_PTR(Domaine) mon_dom;
84 Domaine dom_med_;
86 int numero_ch = -10;
87 int nb_dt = -10;
88#ifdef MED_
89 med_entity_type type_ent;
90 med_geometry_type type_geo;
91#ifdef MEDCOUPLING_
92 INTERP_KERNEL::NormalizedCellType cell_type;
93 MEDCoupling::TypeOfField field_type = MEDCoupling::ON_CELLS;
94 std::vector< std::pair<int,int> > time_steps_;
95#endif
96#endif
99 std::vector<trustIdType> filter;
100 ArrOfDouble temps_sauv_;
101
102 virtual void set_param(Param& param) const override;
103 void readOn_old_syntax(Entree& is, Nom& chaine_lue, bool& nom_decoup_lu);
104 MCAuto<MEDCouplingField> ffield_ = nullptr;
105};
106
108{
109 Cerr<<"Champ_Fonc_MED::associer_domaine_dis_base does nothing"<<finl;
110}
112{
113 return vrai_champ_.valeur();
114}
115
117{
118 return vrai_champ_.valeur();
119}
120inline DoubleTab& Champ_Fonc_MED::valeurs()
121{
122 return le_champ().valeurs();
123}
124inline const DoubleTab& Champ_Fonc_MED::valeurs() const
125{
126 return le_champ().valeurs();
127}
128
129inline DoubleTab& Champ_Fonc_MED::valeur_aux_elems(const DoubleTab& positions, const IntVect& les_polys, DoubleTab& tab_valeurs) const
130{
131 return le_champ().valeur_aux_elems(positions, les_polys, tab_valeurs);
132}
133inline DoubleVect& Champ_Fonc_MED::valeur_a(const DoubleVect& position, DoubleVect& tab_valeurs) const
134{
135 const Domaine& domaine=domainebidon_inst.domaine();
136 IntVect le_poly(1);
137 domaine.chercher_elements(position, le_poly);
138 return le_champ().valeur_a_elem(position,tab_valeurs,le_poly(0));
139}
140
141inline DoubleVect& Champ_Fonc_MED::valeur_a_elem(const DoubleVect& position, DoubleVect& tab_valeurs, int le_poly) const
142{
143 // This method is implemented via valeur_a() and ignores the integer le_poly,
144 // because using le_champ().valeur_a_elem(position, tab_valeurs, le_poly) causes
145 // sequential-parallel discrepancies for P0 fields (and probably for other fields too).
146 // The reason is that in parallel, le_poly refers to an element index within the partition
147 // associated with a processor, while the field pointed to by vrai_champ_
148 // is defined over the entire domain.
149 // For this reason, valeur_a() is used, which locates the position within the entire domain
150 // and returns the value of vrai_champ_ in that element.
151 return le_champ().valeur_a(position,tab_valeurs);
152}
153
154inline DoubleVect& Champ_Fonc_MED::valeur_aux_elems_compo(const DoubleTab& positions, const IntVect& les_polys, DoubleVect& tab_valeurs, int ncomp) const
155{
156 return le_champ().valeur_aux_elems_compo(positions, les_polys, tab_valeurs, ncomp);
157}
158
159inline DoubleTab& Champ_Fonc_MED::valeur_aux_sommets(const Domaine& un_dom, DoubleTab& sommets) const
160{
161 return le_champ().valeur_aux_sommets(un_dom, sommets);
162}
163
164inline DoubleVect& Champ_Fonc_MED::valeur_aux_sommets_compo(const Domaine& un_dom, DoubleVect& sommets, int compo) const
165{
166 return le_champ().valeur_aux_sommets_compo(un_dom, sommets, compo);
167}
168
169inline DoubleTab& Champ_Fonc_MED::remplir_coord_noeuds(DoubleTab& coord) const
170{
171 return le_champ().remplir_coord_noeuds(coord);
172}
173
174inline int Champ_Fonc_MED::remplir_coord_noeuds_et_polys(DoubleTab& coord, IntVect& elems) const
175{
176 return le_champ().remplir_coord_noeuds_et_polys(coord, elems);
177}
178
179
180#endif
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
class Champ_Fonc_MED Load a field from a MED file for a given time.
const Domaine & domaine() const override
const ArrOfDouble & get_saved_times() const
OBS_PTR(Domaine) mon_dom
std::vector< trustIdType > filter
const Domaine_VF & domaine_vf() const override
virtual void lire(double tps, int given_iteration=-1)
DoubleTab & valeur_aux_sommets(const Domaine &, DoubleTab &) const override
Returns the values at the vertices of the Domain dom.
MCAuto< MEDCouplingField > ffield_
void associer_domaine_dis_base(const Domaine_dis_base &) override
void readOn_old_syntax(Entree &is, Nom &chaine_lue, bool &nom_decoup_lu)
ArrOfDouble temps_sauv_
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
int creer(const Nom &, const Domaine &dom, const Motcle &localisation, ArrOfDouble &temps_sauv)
void mettre_a_jour(double) override
Time update of the field.
DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &les_polys, DoubleTab &valeurs) const override
Causes an error! Must be overridden by derived classes.
DoubleVect & valeur_aux_sommets_compo(const Domaine &, DoubleVect &, int) const override
Returns the compo-th value at the vertices of dom.
Domaine_VF_inst domainebidon_inst
const Domaine_dis_base & domaine_dis_base() const override
OWN_PTR(Champ_Fonc_base) vrai_champ_
DoubleVect & valeur_a_elem(const DoubleVect &position, DoubleVect &valeurs, int le_poly) const override
Causes an error! Must be overridden by derived classes.
virtual const Champ_Fonc_base & le_champ() const
DoubleVect & valeur_a(const DoubleVect &position, DoubleVect &valeurs) const override
Computes the "values" of the field at the point with coordinates "pos".
virtual void set_param(Param &param) const override
Nom nom_champ_dans_fichier_med_
int remplir_coord_noeuds_et_polys(DoubleTab &, IntVect &) const override
DOES NOTHING TO override in derived classes.
DoubleTab & remplir_coord_noeuds(DoubleTab &) const override
DOES NOTHING TO override in derived classes.
DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &les_polys, DoubleVect &valeurs, int ncomp) const override
Causes an error! Must be overridden by derived classes.
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
virtual int remplir_coord_noeuds_et_polys(DoubleTab &, IntVect &) const
DOES NOTHING TO override in derived classes.
virtual DoubleTab & remplir_coord_noeuds(DoubleTab &) const
DOES NOTHING TO override in derived classes.
virtual DoubleVect & valeur_a(const DoubleVect &position, DoubleVect &valeurs) const
Computes the "values" of the field at the point with coordinates "pos".
virtual DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &les_polys, DoubleVect &valeurs, int ncomp) const
Causes an error! Must be overridden by derived classes.
virtual DoubleVect & valeur_aux_sommets_compo(const Domaine &, DoubleVect &, int) const
Returns the compo-th value at the vertices of dom.
virtual DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &les_polys, DoubleTab &valeurs) const
Causes an error! Must be overridden by derived classes.
virtual DoubleVect & valeur_a_elem(const DoubleVect &position, DoubleVect &valeurs, int le_poly) const
Causes an error! Must be overridden by derived classes.
virtual DoubleTab & valeur_aux_sommets(const Domaine &, DoubleTab &) const
Returns the values at the vertices of the Domain dom.
class Domaine_VF_inst
class Domaine_VF
Definition Domaine_VF.h:44
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112