16#include <Beam_model.h>
17#include <Domaine_ALE.h>
18#include <TRUSTVects.h>
20#include <Probleme_base.h>
21#include <Domaine_VEF.h>
22#include <Domaine_Cl_VEF.h>
24#include <MD_Vector_tools.h>
25#include <MD_Vector_std.h>
38Implemente_instanciable_sans_constructeur_ni_destructeur(
Beam_model,
"Beam_model", Interprete_geometrique_base ) ;
186 Cerr <<
"Reading beam model coefficients from file: " << masse_and_stiffness_file_name << finl;
191 Cerr <<
"ERROR: invalid configuration. The number of modes (" <<
nbModes_
192 <<
") must be divisible by the number of planes (" <<
nb_planes_ <<
")." << finl;
193 Cerr <<
"Each plane must have the same number of modes." << finl;
203 const std::string filename(masse_and_stiffness_file_name);
204 std::ifstream monFlux(filename.c_str());
208 Cerr <<
"ERROR: Unable to open file '" << filename <<
"'." << finl;
216 while (std::getline(monFlux, line))
224 if (!std::isspace(
static_cast<unsigned char>(c))) { empty =
false;
break; }
229 std::istringstream issCheck(line);
231 if (!(issCheck >> dummy))
continue;
235 Cerr <<
"ERROR: File '" << filename <<
"' contains more data lines than nb_modes = "
236 <<
nbModes_ <<
" (at line " << lineNumber <<
")." << finl;
241 std::istringstream iss(line);
242 double mass, stiffness, damping;
244 if (!(iss >> mass >> stiffness >> damping))
246 Cerr <<
"ERROR: In file '" << filename <<
"', line " << lineNumber
247 <<
" does not contain exactly three numerical values." << finl;
248 Cerr <<
"Line content: [" << line <<
"]" << finl;
256 Cerr <<
"ERROR: In file '" << filename <<
"', line " << lineNumber
257 <<
" contains more than three values." << finl;
258 Cerr <<
"Line content: [" << line <<
"]" << finl;
262 if (std::abs(mass) <= 1.e-16 || std::abs(stiffness) <= 1.e-16)
264 Cerr <<
"ERROR: Invalid mass or stiffness in file '" << filename
265 <<
"' at line " << lineNumber <<
"." << finl;
266 Cerr <<
"mass = " << mass <<
", stiffness = " << stiffness
267 <<
", damping = " << damping << finl;
271 int p = index / modes_per_plane;
272 int m = index % modes_per_plane;
281 Cerr <<
"ERROR: File '" << filename <<
"' contains too few data lines. "
282 <<
"Expected nb_modes = " <<
nbModes_ <<
", but only " << index <<
" valid lines were read." << finl;
286 Cerr <<
"Beam coefficients successfully read from '" << filename
287 <<
"' (" << index <<
" modes)." << finl;
292 Cerr <<
"Reading initial beam conditions from file: " << CI_file_name << finl;
296 Cerr <<
"ERROR: invalid configuration. nb_modes (" <<
nbModes_
297 <<
") must be divisible by nb_planes (" <<
nb_planes_ <<
")." << finl;
313 const std::string filename(CI_file_name);
314 std::ifstream monFlux(filename.c_str());
318 Cerr <<
"ERROR: Unable to open file '" << filename <<
"'." << finl;
326 while (std::getline(monFlux, line))
333 if (!std::isspace(
static_cast<unsigned char>(c))) { empty =
false;
break; }
337 if (line[0] ==
'#')
continue;
340 std::istringstream issCheck(line);
342 if (!(issCheck >> dummy))
continue;
346 Cerr <<
"ERROR: File '" << filename
347 <<
"' contains more data than expected (nb_modes = " <<
nbModes_
348 <<
"), at line " << lineNumber <<
"." << finl;
352 std::istringstream iss(line);
355 if (!(iss >> displacement))
357 Cerr <<
"ERROR: Invalid displacement value at line "
358 << lineNumber <<
" in file '" << filename <<
"'." << finl;
359 Cerr <<
"Line content: [" << line <<
"]" << finl;
367 Cerr <<
"ERROR: Too many values at line " << lineNumber
368 <<
" in file '" << filename <<
"'." << finl;
369 Cerr <<
"Line content: [" << line <<
"]" << finl;
373 int p = index / modes_per_plane;
374 int m = index % modes_per_plane;
388 Cerr <<
"ERROR: File '" << filename <<
"' contains too few data lines. "
389 <<
"Expected " <<
nbModes_ <<
", but found " << index <<
"." << finl;
393 Cerr <<
"Initial beam conditions successfully read from '" << filename
394 <<
"' (" << index <<
" values)." << finl;
400 Cerr <<
"Reading restart file: " << Restart_file_name << finl;
409 const std::string filename(Restart_file_name);
410 std::ifstream monFlux(filename.c_str());
414 Cerr <<
"ERROR: Unable to open restart file '" << filename <<
"'." << finl;
422 while (std::getline(monFlux, line))
428 std::istringstream iss(line);
429 double temps, displacement, speed, acceleration;
431 if (!(iss >> temps >> displacement >> speed >> acceleration))
433 Cerr <<
"ERROR: Line " << lineNumber <<
" in file '" << filename
434 <<
"' does not contain exactly 4 numerical values." << finl;
435 Cerr <<
"Line content: [" << line <<
"]" << finl;
443 Cerr <<
"ERROR: Line " << lineNumber <<
" in file '" << filename
444 <<
"' contains more than 4 values." << finl;
445 Cerr <<
"Line content: [" << line <<
"]" << finl;
449 int plane = index / modes_per_plane;
450 int mode = index % modes_per_plane;
463 Cerr <<
"ERROR: File '" << filename <<
"' contains too few valid data lines. "
464 <<
"Expected nb_modes = " <<
nbModes_ <<
", but only " << index <<
" were read." << finl;
469 Cerr <<
"Restart file successfully read from '" << filename
470 <<
"' (" << index <<
" modes, " <<
nb_planes_ <<
" planes)." << finl;
475 Cerr <<
"Reading beam coordinates from file: " << absc_file_name << finl;
477 const std::string filename(absc_file_name);
478 std::ifstream monFlux(filename.c_str());
481 Cerr <<
"ERROR: Unable to open file '" << filename <<
"'." << finl;
490 while (std::getline(monFlux, line))
495 if (line.find_first_not_of(
" \t\n\r") == std::string::npos)
continue;
498 if (line[0] ==
'#')
continue;
501 std::istringstream iss(line);
503 if (!(iss >> absc))
continue;
509 Cerr <<
"ERROR: In file '" << filename <<
"', line " << lineNumber
510 <<
" contains more than one value." << finl;
511 Cerr <<
"Line content: [" << line <<
"]" << finl;
520 Cerr <<
"ERROR: No valid numeric values found in file '" << filename <<
"'." << finl;
533 while (std::getline(monFlux, line))
538 if (line.find_first_not_of(
" \t\n\r") == std::string::npos)
continue;
541 if (line[0] ==
'#')
continue;
544 std::istringstream issCheck(line);
546 if (!(issCheck >> absc))
continue;
549 std::istringstream iss(line);
552 Cerr <<
"ERROR: Unable to read numeric value in file '" << filename
553 <<
"' at line " << lineNumber <<
"." << finl;
554 Cerr <<
"Line content: [" << line <<
"]" << finl;
562 Cerr <<
"Beam coordinates successfully read from '" << filename
563 <<
"' (" <<
abscissa_.size() <<
" points)." << finl;
570 Cerr <<
"Error: no deformation modes defined. Use 'nb_modes'.\n";
574 if (
nbModes_ != modal_deformation_file_name.size())
576 Cerr <<
"Error: mismatch: nbModes = " <<
nbModes_
577 <<
" but " << modal_deformation_file_name.size()
578 <<
" files provided.\n";
582 Cerr <<
"Reading beam modal deformation from: "
583 << modal_deformation_file_name << finl;
588 std::vector<DoubleVect> tmp_u(
nbModes_);
589 std::vector<DoubleVect> tmp_R(
nbModes_);
592 for (
int global_mode = 0; global_mode <
nbModes_; ++global_mode)
594 const std::string filename(modal_deformation_file_name[global_mode]);
595 std::ifstream monFlux(filename.c_str());
598 Cerr <<
"ERROR: Cannot open '" << filename <<
"'" << finl;
602 DoubleVect u_vec(nPoints);
603 DoubleVect R_vec(nPoints);
605 std::string lineContent;
609 while (std::getline(monFlux, lineContent))
613 if (lineContent.find_first_not_of(
" \t\r\n") == std::string::npos)
continue;
614 if (lineContent[0] ==
'#')
continue;
616 std::istringstream issCheck(lineContent);
618 if (!(issCheck >> dummy))
continue;
620 std::istringstream iss(lineContent);
622 if (!(iss >> disp >> rot))
624 Cerr <<
"ERROR: '" << filename <<
"', line "
625 << lineNumber <<
" : could not read two numeric values.\n";
633 Cerr <<
"ERROR: '" << filename <<
"', line "
634 << lineNumber <<
" : line contains more than two values.\n";
635 Cerr <<
"Line: [" << lineContent <<
"]\n";
641 Cerr <<
"ERROR: file '" << filename
642 <<
"' has too many data lines (expected " << nPoints <<
").\n";
653 Cerr <<
"ERROR: file '" << filename
654 <<
"' contains " << k <<
" valid data rows, expected "
659 tmp_u[global_mode] = u_vec;
660 tmp_R[global_mode] = R_vec;
669 for (
int mode = 0; mode < modes_per_plane; ++mode)
674 for (
int plane = 0; plane <
nb_planes_; ++plane)
676 int global = plane * modes_per_plane + mode;
677 for (
int p = 0; p < nPoints; ++p)
679 Ut(p, plane) = tmp_u[global](p);
680 Rt(p, plane) = tmp_R[global](p);
687 Cerr <<
"Modal deformation successfully loaded for "
743 j = (i + 1 < abscissa_size) ? i + 1 : i;
782 double alpha=0.0, betha=0.0 ;
785 double phi=alpha*u(i, comp) + betha*u(j, comp);
793 double alpha=0.0, betha=0.0 ;
798 for (
int plane = 0; plane <
nb_planes_; ++plane)
800 u_interp[plane]=alpha*u(i, plane) + betha*u(j, plane);
801 R_interp[plane]=alpha*R(i, plane) + betha*R(j, plane);
812 for (
int plane = 0; plane <
nb_planes_; ++plane)
817 double W = u_interp[plane];
818 double Rot = R_interp[plane];
821 int idx1 = (e_long + 1) % 3;
822 int idx2 = (e_long + 2) % 3;
826 phi(e_long, plane) = Rot * pos(idx2);
827 phi(idx2, plane) = 0.0;
828 phi(idx1, plane) = W;
830 else if (e_trans == idx2)
832 phi(e_long, plane) = -Rot * pos(idx1);
833 phi(idx1, plane) = 0.0;
834 phi(idx2, plane) = W;
839 phi(e_long, plane) = 0.0;
840 phi(idx1, plane) = 0.0;
841 phi(idx2, plane) = 0.0;
852 const Nom filename =
beamName_ +
"SaveBeamForRestart.txt";
853 std::ofstream ofs_sauve(filename, std::ofstream::out | std::ofstream::trunc);
854 ofs_sauve.precision(32);
858 Cerr <<
"ERROR: Unable to open file '" << filename <<
"' for writing restart data." << finl;
864 for (
int plane = 0; plane <
nb_planes_; ++plane)
866 for (
int mode = 0; mode < modes_per_plane; ++mode)
868 ofs_sauve <<
temps_ <<
" "
876 Cerr <<
"Beam state saved for restart in '" << filename <<
"' ("
888 for (
int plane = 0; plane <
nb_planes_; ++plane)
891 DoubleVect displacement(nb_output_points);
892 DoubleVect velocity(nb_output_points);
893 DoubleVect acceleration(nb_output_points);
899 for (
int mode = 0; mode < modes_per_plane; ++mode)
901 const DoubleTab& u = u_(mode);
903 for (
int k = 0; k < nb_output_points; ++k)
907 velocity[k] +=
qSpeed_(mode, plane) * u(idx, plane);
916 filename +=
"_Displacement1D_plane_";
917 filename +=
Nom(plane);
921 out.
ouvrir(filename, first_writing ? ios::out : ios::app);
922 out.
setf(ios::scientific);
926 out <<
"# Plane " << plane
927 <<
" Beam 1D displacement: time x y z at points ";
928 for (
int k = 0; k < nb_output_points; ++k)
934 for (
int k = 0; k < nb_output_points; ++k)
935 out << displacement[k] <<
" ";
942 filename +=
"_Velocity1D_plane_";
943 filename +=
Nom(plane);
947 out.
ouvrir(filename, first_writing ? ios::out : ios::app);
948 out.
setf(ios::scientific);
952 out <<
"# Plane " << plane
953 <<
" Beam 1D velocity: time x y z at points ";
954 for (
int k = 0; k < nb_output_points; ++k)
960 for (
int k = 0; k < nb_output_points; ++k)
961 out << velocity[k] <<
" ";
968 filename +=
"_Acceleration1D_plane_";
969 filename +=
Nom(plane);
973 out.
ouvrir(filename, first_writing ? ios::out : ios::app);
974 out.
setf(ios::scientific);
978 out <<
"# Plane " << plane
979 <<
" Beam 1D acceleration: time x y z at points ";
980 for (
int k = 0; k < nb_output_points; ++k)
986 for (
int k = 0; k < nb_output_points; ++k)
987 out << acceleration[k] <<
" ";
999 DoubleTab displacement(nb_output_points, 3);
1000 DoubleTab velocity(nb_output_points, 3);
1001 DoubleTab acceleration(nb_output_points, 3);
1010 DoubleTab phi3D(3, nb_planes);
1012 for (
int p = 0; p < nb_planes; p++)
1014 for (
int m = 0; m < modes_per_plane; m++)
1016 const DoubleTab& u = u_(m);
1017 const DoubleTab& R = R_(m);
1019 for (
int k = 0; k < nb_output_points; k++)
1027 for (
int i = 0; i < 3; i++)
1030 velocity(k,i) +=
qSpeed_(m,p) * phi3D(i,p);
1050 speed_out_3d_.ouvrir(filename_speed, (first_writing ? ios::out : ios::app));
1063 speed_out_3d_ <<
"# 3D beam velocity: time, (x,y,z) at each output point ";
1066 for (
int k = 0; k < nb_output_points; k++)
1071 for (
int k = 0; k < nb_output_points; k++)
1076 for (
int k = 0; k < nb_output_points; k++)
1087 for (
int k = 0; k < nb_output_points; k++)
1089 for (
int i = 0; i < 3; i++)
1110 for (
int plane = 0; plane <
nb_planes_; ++plane)
1114 filename +=
"_ModalForceFluide1D_plane_";
1115 filename +=
Nom(plane);
1120 out.
ouvrir(filename, (first_writing ? ios::out : ios::app));
1121 out.
setf(ios::scientific);
1126 out <<
"# Modal fluid force for plane " << plane <<
": time ";
1127 for (
int m = 0; m < modes_per_plane; ++m)
1128 out <<
"(mode " << m + 1 <<
") ";
1135 for (
int m = 0; m < modes_per_plane; ++m)
1171 double squareDt = dt * dt;
1175 for (
int plane = 0; plane <
nb_planes_; ++plane)
1177 for (
int mode = 0; mode < modes_per_plane; ++mode)
1185 double coeff1 =
mass_(mode, plane)
1188 double coeff2 = (1. +
alpha_) *
damping_(mode, plane) * qSpeed_pred;
1215 Nom masse_and_stiffness_file_name;
1218 Nom CI_file_name=
"none";
1219 Nom Restart_file_name=
"none";
1222 int nb_output_points_1D=0;
1223 DoubleVect output_position_1D(nb_output_points_1D);
1224 int nb_output_points_3D=0;
1225 DoubleTab output_position_3D(nb_output_points_3D,0);
1228 if (motlu != open_brace)
1230 Cerr <<
"Error while reading Beam\n";
1231 Cerr <<
"Expected a { but found: "<< motlu;
1239 if(motlu==
"nb_modes")
1243 Cerr <<
"Number of modes : " <<
nbModes_ << finl;
1245 if(motlu==
"nb_planes")
1250 if (var_int != 1 && var_int != 2)
1252 Cerr <<
"ERROR: invalid number of beam planes: " << var_int << finl;
1253 Cerr <<
"Valid values are: 1 or 2." << finl;
1257 Cerr <<
"Number of planes : " <<
nb_planes_ << finl;
1259 if(motlu==
"longitudinal_axis")
1262 if (nomlu ==
"x" || nomlu ==
"X")
1264 else if (nomlu ==
"y" || nomlu ==
"Y")
1266 else if (nomlu ==
"z" || nomlu ==
"Z")
1270 Cerr <<
"ERROR: invalid main axis: " << nomlu
1271 <<
"'. Valid options are: x, y, or z." << finl;
1277 if(motlu==
"bendingDirection")
1280 if (nomlu ==
"x" || nomlu ==
"X")
1282 else if (nomlu ==
"y" || nomlu ==
"Y")
1284 else if (nomlu ==
"z" || nomlu ==
"Z")
1288 Cerr <<
"ERROR: invalid direction of bending: '" << nomlu
1289 <<
"'. Valid options are: x, y, or z." << finl;
1293 Cerr <<
"Bending direction : " <<
bending_dir_ << finl;
1295 if(motlu==
"BaseCenterCoordinates")
1298 double x=var_double;
1300 double y=var_double;
1302 double z=var_double;
1306 if(motlu==
"Young_Module")
1310 Cerr <<
"Young module : " <<
young_ << finl;
1312 if(motlu==
"Rho_beam")
1316 Cerr <<
"Rho beam : " <<
rho_ << finl;
1318 if(motlu==
"Mass_and_stiffness_file_name")
1321 masse_and_stiffness_file_name=nomlu;
1324 if(motlu==
"Absc_file_name")
1327 absc_file_name=nomlu;
1330 if(motlu==
"CI_file_name")
1337 if(motlu==
"Modal_deformation_file_name")
1340 for (
int i=0; i< var_int; i ++)
1343 phi_file_name.add(nomlu);
1346 if(motlu==
"NewmarkTimeScheme")
1357 if(motlu==
"Output_position_1D")
1359 Cerr <<
"Beam Output_position_1D "<< finl;
1360 is>>nb_output_points_1D;
1361 output_position_1D.
resize(nb_output_points_1D);
1363 for (
int i=0; i< nb_output_points_1D; i ++)
1366 output_position_1D[i]=poz;
1371 if(motlu==
"Output_position_3D")
1373 Cerr <<
"Beam Output_position_3D "<< finl;
1374 is>>nb_output_points_3D;
1375 output_position_3D.
resize(nb_output_points_3D, 3);
1377 for (
int i=0; i< nb_output_points_3D; i ++)
1379 for (
int j=0; j< 3; j ++)
1382 output_position_3D(i,j)=poz;
1387 if (motlu==
"Restart_file_name")
1390 Restart_file_name=nomlu;
1392 if (motlu==
"direction")
1394 Cerr <<
"Error: Syntax changed in v1.9.7. You should now replace:" << finl;
1395 Cerr <<
" 'direction N'" << finl;
1396 Cerr <<
" by something like:" << finl;
1397 Cerr <<
" 'longitudinal_axis X'" << finl;
1398 Cerr <<
" 'bendingDirection Y'" << finl;
1402 if (motlu == close_brace)
1409 Cerr <<
"ERROR: you must specify the axis along the length of the beam."<<finl;
1414 Cerr <<
"ERROR: you must specify the bending direction."<<finl;
1421 Cerr <<
"ERROR: invalid bendingDirection: it must be different from the longitudinal_axis."<<finl;
1431 for (
int axis = 0; axis < 3; ++axis)
1445 if(CI_file_name!=
"none")
1453 if(Restart_file_name!=
"none")
1461 bool first_writing=
true;
1463 if (nb_output_points_1D>0)
1465 if (nb_output_points_3D>0)
void setTimeScheme(const Nom &, double &)
double tempsComputeForceOnBeam_
void readInputAbscFiles(Nom &absc_file_name)
DoubleTab & getVelocity(const double &tps, const double &dt)
void saveBeamForRestart() const
void printOutputFluidForceOnBeam(bool first_writing=false) const
DoubleTab fluidForceOnBeam_
void printOutputBeam1D(bool first_writing=false) const
Entree & interpreter_(Entree &) override
DoubleTab interpolationOnThe3DSurface(const double &x, const double &y, const double &z, const DoubleTab &u, const DoubleTab &R) const
void readInputCIFile(Nom &CI_file_name)
void interpolationWeights(const double &, const double &, const double &, int &, int &, double &, double &) const
void setCenterCoordinates(const double &, const double &, const double &)
void setOutputPosition3D(const DoubleTab &)
void printOutputBeam3D(bool first_writing=false) const
DoubleVect output_position_1D_
double interpolationPhiOnThe3DSurface(const double &x, const double &y, const double &z, const int &comp, const DoubleTab &u) const
SFichier displacement_out_3d_
DoubleTab output_position_3D_
void readRestartFile(Nom &Restart_file_name)
SFichier acceleration_out_3d_
DoubleTab & NewmarkScheme(const double &dt)
void read_beam(Entree &is)
void readInputMassStiffnessFiles(Nom &masse_and_stiffness_file_name)
void setOutputPosition1D(const DoubleVect &)
void readInputModalDeformation(Noms &modal_deformation_file_name)
void reading_beam_model(Entree &is)
Class defining operators and methods for all reading operation in an input flow (file,...
void associer_domaine(Nom &nom_dom)
Domaine_t & domaine(int i=0)
Une chaine de caractere (Nom) en majuscules.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Un tableau de chaine de caracteres (VECT(Nom)).
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
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...
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out)
void setf(IOS_FORMAT code) override
Classe de base des flux de sortie.
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)