TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Fonc_MED_Table_Temps.cpp
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#include <Champ_Fonc_MED_Table_Temps.h>
17#include <Lecture_Table.h>
18#include <EChaine.h>
19#include <Param.h>
20#ifdef MEDCOUPLING_
21#include <MEDLoader.hxx>
22#include <MEDCouplingFieldDouble.hxx>
23#pragma GCC diagnostic ignored "-Wreorder"
24#include <MEDFileField.hxx>
25#include <MEDCouplingField.hxx>
26using MEDCoupling::MEDCouplingField;
27using MEDCoupling::MEDCouplingFieldDouble;
28using MEDCoupling::MCAuto;
29using MEDCoupling::MEDFileFieldMultiTS;
30using MEDCoupling::MEDFileField1TS;
31#endif
32
33Implemente_instanciable( Champ_Fonc_MED_Table_Temps, "Champ_Fonc_MED_Table_Temps", Champ_Fonc_MED );
34// XD Champ_Fonc_MED_Table_Temps champ_fonc_med Champ_Fonc_MED_Table_Temps INHERITS_BRACE Field defined as a fixed
35// XD_CONT spatial shape scaled by a temporal coefficient
36// XD attr table_temps bloc_lecture table_temps OPT Table containing the temporal coefficient used to scale the field
37// XD attr table_temps_lue chaine table_temps_lue OPT Name of the file containing the values of the temporal coefficient
38// XD_CONT used to scale the field
39
41
43{
45 param.ajouter_non_std("table_temps",(this));
46 param.ajouter_non_std("table_temps_lue",(this));
47}
48
50{
52 if (!table_lue_)
53 {
54 Cerr << "A table must be read using table_temps or table_temps_lue !" << finl;
56 }
57 return is;
58}
59
61{
62 if (mot == "table_temps")
63 {
64 if (table_lue_) Process::exit("Champ_Fonc_MED_Table_Temps : table already read!");
65 Lecture_Table lec_table;
66 lec_table.lire_table(is, la_table);
67 table_lue_ = true;
68 }
69 else if (mot == "table_temps_lue")
70 {
71 if (table_lue_) Process::exit("Champ_Fonc_MED_Table_Temps : table already read!");
72 Nom ch;
73 is >> ch;
74 ch = put_file_into_nom(1, ch);
75 EChaine chaine(ch);
76 Lecture_Table lec_table;
77 lec_table.lire_table(chaine, la_table);
78 table_lue_ = true;
79 }
80 else
82 return 1;
83}
84
85void Champ_Fonc_MED_Table_Temps::lire_donnees_champ(const std::string& fileName, const std::string& meshName, const std::string& fieldName, ArrOfDouble& temps_sauv, int& size, int& nbcomp,
86 Nom& type_champ)
87{
88#ifdef MEDCOUPLING_
89 MCAuto<MEDFileFieldMultiTS> ft1(MEDFileFieldMultiTS::New(fileName,fieldName));
90 std::vector<double> tps;
91 std::vector< std::pair<int,int> > tst = ft1->getTimeSteps(tps);
92
93 temps_sauv.resize_array(1);
94
95 int first_iter = tst[0].first;
96 int first_order = tst[0].second;
97 temps_sauv[0] = tps[0];
99 {
100 Cerr << "last_time not possible. Champ_Fonc_MED_Table_Temps can be used only with the first time " << tps[0] << " in the file." << finl;
102 }
103 if (meshName == domaine().le_nom()) domaine().build_mc_mesh();
104 bool fast = domaine().is_mc_mesh_ready();
105 MCAuto<MEDCouplingField> ffield;
106 if (fast)
107 {
108 MCAuto<MEDFileField1TS> file = MEDFileField1TS::New(fileName, fieldName, first_iter, first_order);
109 ffield = file->getFieldOnMeshAtLevel(field_type, domaine().get_mc_mesh(), 0);
110 }
111 else
112 {
113 // Only one MCAuto below to avoid double deletion:
114 ffield = ReadField(field_type, fileName, meshName, 0, fieldName,
115 first_iter, first_order);
116 }
117 MEDCouplingFieldDouble * field = dynamic_cast<MEDCouplingFieldDouble *>((MEDCouplingField *)ffield);
118 if (field == 0)
119 {
120 Cerr << "ERROR reading MED field! Not a MEDCouplingFieldDouble!!" << finl;
121 Process::exit(-1);
122 }
123 size = (int)field->getNumberOfTuplesExpected();
124 nbcomp = (int) field->getNumberOfComponents();
125
126 if (field_type == MEDCoupling::ON_NODES)
127 {
128 if ((cell_type == INTERP_KERNEL::NORM_QUAD4) || (cell_type == INTERP_KERNEL::NORM_HEXA8))
129 type_champ = "Champ_Fonc_Q1_MED";
130 else
131 type_champ = "Champ_Fonc_P1_MED";
132 }
133 else if (field_type == MEDCoupling::ON_CELLS)
134 type_champ = "Champ_Fonc_P0_MED";
135
136 vrai_champ0_.typer(type_champ);
137 fixer_nb_comp(nbcomp);
138 le_champ0().fixer_nb_comp(nbcomp);
139 domainebidon_inst.associer_domaine(mon_dom.valeur());
141 if (domainebidon_inst.nb_elem()==0) size = 0;
143 if (size != le_champ0().valeurs().dimension(0))
144 {
145 Cerr << "Error in " << que_suis_je() << " : nb_ddl incorrect" << finl;
147 }
148 const double *field_values = field->getArray()->begin();
149 assert(field->getNumberOfTuplesExpected() == le_champ0().valeurs().dimension(0));
150 assert((int) field->getNumberOfComponents() ==
151 (le_champ0().valeurs().nb_dim() == 1 ? 1 : le_champ0().valeurs().dimension(1)));
152 memcpy(le_champ0().valeurs().addr(), field_values,
153 le_champ0().valeurs().size_array() * sizeof(double));
154#endif
155}
156
157void Champ_Fonc_MED_Table_Temps::lire(double t, int given_it)
158{
159#ifdef MED_
160#ifndef MEDCOUPLING_
161 Cerr << "Error while reading " << que_suis_je() << ". MEDCoupling library is mandatory." << finl;
163#endif
164#endif
165
166 if (domainebidon_inst.nb_elem() > 0)
167 {
168 double frac = la_table.val(t);
169 const DoubleTab& vals0 = le_champ0().valeurs();
170 DoubleTab& vals = le_champ().valeurs();
171
172 vals = vals0;
173 vals *= frac;
174 }
176 le_champ().Champ_Fonc_base::mettre_a_jour(t);
177}
178
180{
181 return la_table.instationnaire();
182}
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
: class Champ_Fonc_MED_Table_Temps
void lire_donnees_champ(const std::string &fileName, const std::string &meshName, const std::string &fieldName, ArrOfDouble &temps_sauv, int &size, int &nbcomp, Nom &type_champ) override
void set_param(Param &param) const override
void lire(double tps, int given_iteration=-1) override
virtual const Champ_Fonc_base & le_champ0() const
int lire_motcle_non_standard(const Motcle &, Entree &) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
classe Champ_Fonc_MED Load a field from a MED file for a given time.
const Domaine & domaine() const override
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
Domaine_VF_inst domainebidon_inst
virtual const Champ_Fonc_base & le_champ() const
virtual void set_param(Param &param) const override
void associer_domaine_dis_base(const Domaine_dis_base &) override
void mettre_a_jour(double temps) override
Mise a jour en temps du champ.
int fixer_nb_valeurs_nodales(int nb_noeuds) override
Fixe le nombre de degres de liberte par composante.
Nom put_file_into_nom(int n, const Nom &col_file) const
void build_mc_mesh(bool virt=false) const
Build the MEDCoupling mesh corresponding to the TRUST mesh.
Definition Domaine.cpp:1327
bool is_mc_mesh_ready() const
Definition Domaine.h:355
Une entree dont la source est une chaine de caracteres.
Definition EChaine.h:31
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Fixe le nombre de composantes du champ.
const Nom & le_nom() const override
Renvoie le nom du champ.
: class Lecture_Table
Entree & lire_table(Entree &is, Table &la_table)
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
virtual int lire_motcle_non_standard(const Motcle &motlu, Entree &is)
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
Definition Objet_U.cpp:115
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
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
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_non_std(const char *keyword, const Objet_U *value, Param::Nature nat=Param::OPTIONAL)
Register a keyword handled by Objet_U::lire_motcle_non_standard.
Definition Param.cpp:489
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
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)