16#include <Schema_Temps_base.h>
17#include <Probleme_base.h>
18#include <Loi_horaire.h>
32 EChaine x(
dimension==3?
"3 0. 0. 0.":
"2 0. 0.");
34 EChaine v(
dimension==3?
"3 0. 0. 0.":
"2 0. 0.");
36 EChaine r(
dimension==3?
"9 1. 0. 0. 0. 1. 0. 0. 0. 1.":
"4 1. 0. 0. 1.");
38 EChaine drdt(
dimension==3?
"9 0. 0. 0. 0. 0. 0. 0. 0. 0.":
"4 0. 0. 0. 0.");
39 drdt >> derivee_rotation_;
43 param.ajouter(
"position",&position_);
45 param.ajouter(
"vitesse",&vitesse_);
47 param.ajouter(
"rotation",&rotation_);
48 param.ajouter(
"derivee_rotation",&derivee_rotation_);
49 param.ajouter(
"verification_derivee",&verification_derivee_);
50 param.ajouter(
"impr",&impr_);
51 param.lire_avec_accolades_depuis(is);
54 if (position_.valeurs().size_array()!=
dimension)
56 Cerr <<
"The position vector of the schedule law " <<
le_nom() <<
" must have " <<
dimension <<
" components." << finl;
59 if (vitesse_.valeurs().size_array()!=
dimension)
61 Cerr <<
"The velocity vector of the schedule law " <<
le_nom() <<
" must have " <<
dimension <<
" components." << finl;
66 Cerr <<
"The matrix rotation of the schedule law " <<
le_nom() <<
" must be read" << finl;
72 Cerr <<
"The matrix derivee_rotation of the schedule law " <<
le_nom() <<
" must be read" << finl;
79inline void check(
const DoubleTab& mat)
84 Cerr <<
"Problem in Loi_horaire::check" << finl;
85 Cerr <<
"Format of the array of values of Champ_Fonc_t" << finl;
86 Cerr <<
"Contact TRUST support." << finl;
92inline void multiplie(
const DoubleTab& matrice, ArrOfDouble& vecteur)
95 ArrOfDouble x(vecteur);
97 int dimension = vecteur.size_array();
98 for (
int i=0; i<dimension; i++)
99 for (
int j=0; j<dimension; j++)
100 vecteur[i] += matrice(0,i*dimension+j) * x[j];
104inline void inverse(
const DoubleTab& mat, ArrOfDouble& x)
110 const double a=mat(0,0);
111 const double b=mat(0,1);
112 const double c=mat(0,2);
113 const double d=mat(0,3);
117 Cerr <<
"Matrix of order 2 not invertible in Loi_horaire::inverse" << finl;
121 double y0=(d*x[0]-b*x[1])/det;
122 double y1=(-c*x[0]+a*x[1])/det;
126 else if (dimension==3)
128 const double a=mat(0,0);
129 const double b=mat(0,1);
130 const double c=mat(0,2);
131 const double d=mat(0,3);
132 const double e=mat(0,4);
133 const double f=mat(0,5);
134 const double g=mat(0,6);
135 const double h=mat(0,7);
136 const double i=mat(0,8);
138 double det=a*(e*i-f*h)
143 Cerr <<
"Matrix of order 3 not invertible in Loi_horaire::inverse" << finl;
147 double y0=((e*i-f*h)*x[0]
149 +(b*f-c*e)*x[2])/det;
150 double y1=((f*g-d*i)*x[0]
152 +(c*d-a*f)*x[2])/det;
153 double y2=((d*h-e*g)*x[0]
155 +(a*e-b*d)*x[2])/det;
162 Cerr <<
"Case not provided in Loi_horaire::inverse()" << finl;
179 ArrOfDouble xMt(xMt0);
180 position_.me_calculer(t0);
181 xMt -= position_.valeurs();
182 rotation_.me_calculer(t0);
183 inverse(rotation_.valeurs(),xMt);
184 rotation_.me_calculer(t);
185 multiplie(rotation_.valeurs(),xMt);
186 position_.me_calculer(t);
187 xMt += position_.valeurs();
203 ArrOfDouble vMt(xMt);
204 position_.me_calculer(t);
205 vMt -= position_.valeurs();
206 rotation_.me_calculer(t);
207 inverse(rotation_.valeurs(),vMt);
208 derivee_rotation_.me_calculer(t);
209 multiplie(derivee_rotation_.valeurs(),vMt);
210 vitesse_.me_calculer(t);
211 vMt += vitesse_.valeurs();
219void Loi_horaire::verifier_derivee(
const double t)
221 if (verification_derivee_)
224 DoubleVect err_t(position_.valeurs());
225 position_.me_calculer(t+dt);
226 err_t=position_.valeurs();
227 position_.me_calculer(t);
228 err_t-=position_.valeurs();
229 vitesse_.me_calculer(t);
230 err_t.ajoute(-dt, vitesse_.valeurs());
232 ArrOfDouble seuil_t(position_.valeurs());
233 vitesse_.me_calculer(t+dt);
234 seuil_t=vitesse_.valeurs();
235 vitesse_.me_calculer(t);
236 seuil_t-=vitesse_.valeurs();
238 int n=err_t.size_array();
239 for (
int i=0; i<n; i++)
241 double seuil=std::fabs(seuil_t[i]);
242 if (!est_egal(seuil,0) && std::fabs(err_t(i))>seuil)
244 Cerr <<
"At time " << t <<
", inconsistency in the schedule law " <<
le_nom() << finl;
245 Cerr <<
"The expression of the component " << i <<
" of velocity does not appear" << finl;
246 Cerr <<
"to be the time derivative of the position expression." << finl;
247 Cerr <<
"Verify the expressions of this schedule law in your data set." << finl;
248 Cerr <<
"If the expressions are correct after all, add the option 'verification_derivee 0'" << finl;
249 Cerr <<
"in the law to not to make this verification." << finl;
253 DoubleTab err_r(rotation_.valeurs());
254 rotation_.me_calculer(t+dt);
255 err_r=rotation_.valeurs();
256 rotation_.me_calculer(t);
257 err_r-=rotation_.valeurs();
258 derivee_rotation_.me_calculer(t);
259 err_r.ajoute(-dt, derivee_rotation_.valeurs());
261 DoubleTab seuil_r(rotation_.valeurs());
262 derivee_rotation_.me_calculer(t+dt);
263 seuil_r=derivee_rotation_.valeurs();
264 derivee_rotation_.me_calculer(t);
265 seuil_r-=derivee_rotation_.valeurs();
267 int ni=err_r.dimension(0);
268 int nj=err_r.dimension(1);
269 for (
int i=0; i<ni; i++)
270 for (
int j=0; j<nj; j++)
272 double seuil=std::fabs(seuil_r(i,j));
273 if (!est_egal(seuil,0) && std::fabs(err_r(i,j))>seuil)
275 Cerr <<
"At time " << t <<
", inconsistency in the schedule law " <<
le_nom() << finl;
276 Cerr <<
"The expression of the component " << i*ni+j <<
" of derivee_rotation does not appear" << finl;
277 Cerr <<
"to be the time derivative of the rotation expression." << finl;
278 Cerr <<
"Verify the expressions of this schedule law in your data set" << finl;
279 Cerr <<
"or add the option 'verification_derivee 0' in this law." << finl;
292 nom_fichier+=
"_loi_horaire_";
303 fic <<
"# (xG,yG,...):Position du centre de gravite dont le mouvement est defini par la loi horaire " <<
le_nom() << finl;
304 fic <<
"# (moy(xi),moy(yi),...):Position du barycentre des noeuds du maillage de l'interface." << finl;
305 fic <<
"# Les trajectoires de ces 2 points doivent etre proches." << finl;
306 fic <<
"# Pour visualiser dans gnuplot ces trajectoires, faire: " << finl;
309 fic <<
"# set param;splot '" << nom_fichier <<
"' using 2:3:4 with lines,'" << nom_fichier <<
"' using 5:6:7 with points" << finl;
310 fic <<
"# Temps xG(t) yG(t) zG(t) moy(xi) moy(yi) moy(zi)" << finl;
314 fic <<
"# set param;plot '" << nom_fichier <<
"' using 2:3 with lines,'" << nom_fichier <<
"' using 4:5 with points" << finl;
315 fic <<
"# Temps xG(t) yG(t) moy(xi) moy(yi)" << finl;
319 fic.
ouvrir(nom_fichier,ios::app);
322 fic.
setf(ios::scientific);
326 position_.me_calculer(t);
328 fic <<
" " << position_.valeurs()(0,i);
330 fic <<
" " << coord_barycentre[i];
341 for (
int dim=2; dim<=3; dim++)
343 DoubleTab mat(1,dim*dim);
344 for (
int i=0; i<dim; i++)
345 for (
int j=0; j<dim; j++)
346 mat(0,i*dim+j)=(i>j?1+i+j:-2*j);
347 ArrOfDouble vect(dim);
348 for (
int i=0; i<dim; i++)
350 ArrOfDouble tmp(vect);
353 for (
int i=0; i<dim; i++)
354 if (!est_egal(tmp[i],vect[i]))
356 Cerr <<
"Loi_horaire::inverse is not validated for dim=" << dim << finl;
357 Cerr <<
"A=" << mat << finl;
358 Cerr <<
"x=" << tmp << finl;
359 Cerr <<
"Inv(A)Ax=" << vect << finl;
360 Cerr <<
"Contact TRUST support." << finl;
369 for (
int i=1; i<n; i++)
371 double temps=tinit+(tmax-tinit)*(i+1)/n;
373 verifier_derivee(temps);
376 double t=0.5*(tinit+tmax);
386 if (!est_egal(tmp[i],pos[i]))
388 Cerr <<
"Loi_horaire::position is not validated for pos=position(t,t,pos):" << finl;
391 Cerr <<
"Contact TRUST support." << finl;
398 ArrOfDouble vit(
vitesse(t,pos));
399 ArrOfDouble relative_error(vit);
401 relative_error/=(norme_array(tmp)!=0?norme_array(tmp):1);
403 if (!est_egal(relative_error[i],0,0.001))
405 Cerr <<
"Loi_horaire::position is not validated for velocity(t,pos):" << finl;
406 Cerr <<
"t=" << t << finl;
407 Cerr <<
"dt=" << dt << finl;
408 Cerr <<
"vit=" << vit << finl;
409 Cerr <<
"tmp=" << tmp << finl;
410 Cerr <<
"relative_error=" << relative_error << finl;
411 Cerr <<
"Contact TRUST support." << finl;
414 Cerr <<
"Loi_horaire::tester() OK" << finl;
Class defining operators and methods for all reading operation in an input flow (file,...
ArrOfDouble vitesse(const double t, const ArrOfDouble &position_a_t)
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
void imprimer(const Schema_Temps_base &, const ArrOfDouble &)
ArrOfDouble position(const double t, const double t0, const ArrOfDouble &position_a_t0)
class Nom Une chaine de caractere pour nommer les objets de TRUST
classe Objet_U Cette classe est la classe de base des Objets de TRUST
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
static const Nom & nom_du_cas()
Renvoie une reference constante vers le nom du cas.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
bool & reprise_effectuee()
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
int nb_impr() const
Renvoie le nombre d'impressions effectuees.
double temps_courant() const
Renvoie le temps courant.
int precision_impr() const
double temps_max() const
Renvoie une reference sur le temps maximum.
Probleme_base & pb_base()
double temps_init() const
Renvoie le temps initial.
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out)
void precision(int pre) override
void setf(IOS_FORMAT code) override
Classe de base des flux de sortie.
_SIZE_ size_array() const
_SIZE_ dimension(int d) const