114 if (
l_ ==
"unset string")
117 if(
f_ !=
"unset string")
122 path = std::string(getenv(
"TrioCFD_project_directory")) +
"/share/Mfront_material_libraries/" +
f_+
"/src/libBehaviour.so";
127 Cerr <<
"MFront model name is undefined (keyword: Mfront_model_name)." << finl;
128 Cerr <<
"Cannot set the default MFront library path: "
129 <<
"$project_directory/share/MFront_material_libraries/<Mfront_library_keyword>/src/libBehaviour.so" << finl;
130 Cerr <<
"Please define either the MFront library path (keyword: Mfront_library) "
131 <<
"or the MFront model name (keyword: Mfront_model_name)." << finl;
136 if (
f_ ==
"unset string")
138 Cerr <<
"Error: Mfront model name undefined (Mfront_model_name keyword)" << finl ;
142 if (
h_ ==
"unset string")
147 Cerr <<
"Use default Mfront hypothesis for 2D (PlaneStrain)" << finl ;
151 Cerr <<
"Use default Mfront hypothesis for 3D (Tridimensional)" << finl ;
152 h_ =
"Tridimensional" ;
157 hypothesis_= mgis::behaviour::fromString(
h_) ;
163 load_behaviour_(StressMeasureKind::cauchy, TangentOperatorKind::none) ;
166 Cerr <<
"Mfront behaviour: internal state variables:" << finl ;
169 size_t vOffset = mgis::behaviour::getVariableOffset(
mgisBehaviour_.isvs, isvs.name, hypothesis_);
170 size_t vSize = mgis::behaviour::getVariableSize(isvs, hypothesis_);
171 Cerr <<
" - " << isvs.name <<
": " << vOffset <<
" -> " << vOffset + vSize << finl ;
174 Cerr <<
"Wrong Mfront behaviour for structural dynamic mesh motion" << finl ;
175 Cerr <<
"Only pure elastic materials are allowed" << finl ;
180 Cerr <<
"Mfront behaviour: external state variables:" << finl ;
184 size_t vOffset = mgis::behaviour::getVariableOffset(
mgisBehaviour_.esvs, esvs.name, hypothesis_);
185 size_t vSize = mgis::behaviour::getVariableSize(esvs, hypothesis_);
186 Cerr <<
" - " << esvs.name <<
": " << vOffset <<
" -> " << vOffset + vSize << finl ;
187 sizeEvars_ +=
static_cast<int> (vSize) ;
190 Cerr <<
"Warning: external variables ignored for mesh motion" << finl ;
194 matpSize_ =
static_cast<int> (mgis::behaviour::getArraySize(
mgisBehaviour_.mps, hypothesis_));
201 size_t vOffset = mgis::behaviour::getVariableOffset(
mgisBehaviour_.mps, mps.name, hypothesis_);
202 size_t vSize = mgis::behaviour::getVariableSize(mps, hypothesis_);
203 auto it =
matp_.find(mps.name);
204 if (it !=
matp_.end())
206 if (vSize != (it->second).size())
208 Cerr <<
"Error with input for Mfront behaviour " <<
f_ << finl ;
209 Cerr <<
"The number of scalar values must be " << vSize <<
" for property " << mps.name << finl ;
212 for (
size_t i = 0; i < vSize; ++i)
220 Cerr <<
"Warning with input for Mfront behaviour " <<
f_ << finl ;
221 Cerr <<
"Missing data for for property " << mps.name <<
", default value(s) set to zero" << finl ;
222 for (
size_t i = 0; i < vSize; ++i)
407 for (
int k=0; k <
nbn_; k++)
413 Jac(j,i) +=
Eta_(j,k) *
xl_(k,i) ;
424 Det = Jac(0,0) * Jac(1,1) - Jac(0,1) * Jac(1,0) ;
426 InvJac(0,0) = Jac(1,1) * aux ;
427 InvJac(0,1) = -Jac(0,1) * aux ;
428 InvJac(1,0) = -Jac(1,0) * aux ;
429 InvJac(1,1) = Jac(0,0) * aux ;
435 Det= Jac(0,0) * (Jac(1,1) * Jac(2,2) - Jac(1,2) * Jac(2,1))
436 - Jac(0,1) * (Jac(1,0) * Jac(2,2) - Jac(1,2) * Jac(2,0))
437 + Jac(0,2) * (Jac(1,0) * Jac(2,1) - Jac(1,1) * Jac(2,0)) ;
439 InvJac(0,0) = (Jac(1,1) * Jac(2,2) - Jac(2,1) * Jac(1,2)) * aux ;
440 InvJac(0,1) = -(Jac(0,1) * Jac(2,2) - Jac(2,1) * Jac(0,2)) * aux ;
441 InvJac(0,2) = (Jac(0,1) * Jac(1,2) - Jac(1,1) * Jac(0,2)) * aux ;
442 InvJac(1,0) = -(Jac(1,0) * Jac(2,2) - Jac(2,0) * Jac(1,2)) * aux ;
443 InvJac(1,1) = (Jac(0,0) * Jac(2,2) - Jac(2,0) * Jac(0,2)) * aux ;
444 InvJac(1,2) = -(Jac(0,0) * Jac(1,2) - Jac(1,0) * Jac(0,2)) * aux ;
445 InvJac(2,0) = (Jac(1,0) * Jac(2,1) - Jac(2,0) * Jac(1,1)) * aux ;
446 InvJac(2,1) = -(Jac(0,0) * Jac(2,1) - Jac(2,0) * Jac(0,1)) * aux ;
447 InvJac(2,2) = (Jac(0,0) * Jac(1,1) - Jac(1,0) * Jac(0,1)) * aux ;
460 for (
int i=0; i <
nbn_ ; i++)
462 B(j,i) += InvJac(j,k) *
Eta_(k,i) ;
508#define _xikbjk(i,j) xl_(k,i)*B0l_(j,k)
509 std::vector <double> stress(
symSize_) ;
517 for (
int i=0; i<
nSymSize_; i++) ftpdt[i] = 0 ;
519 for (
int k=0; k<
nbn_; k++)
521 ftpdt[0] += _xikbjk(0,0);
522 ftpdt[1] += _xikbjk(1,1);
523 ftpdt[3] += _xikbjk(0,1);
524 ftpdt[4] += _xikbjk(1,0);
531 ftpdt[2] += _xikbjk(2,2);
532 ftpdt[5] += _xikbjk(0,2);
533 ftpdt[6] += _xikbjk(2,0);
534 ftpdt[7] += _xikbjk(1,2);
535 ftpdt[8] += _xikbjk(2,1);
546 std::vector <double> evars(sizeEvars_) ;
547 for (
int i=0; i<sizeEvars_; i++) evars[i] = mfrontEvars_(
iel_,i) ;
549 double voidInternalVars[1] ;
554 double speedOfSound[1] ;
556 integrate_behaviour_(&stress[0], voidInternalVars, &evars[0], &K[0], &ft[0], &ftpdt[0], speedOfSound) ;
558 if (speedOfSound[0] <= 0.)
560 Cerr <<
"Error (mesh motion): speed of sound not computed in provided Mfront behaviour" << finl ;
565 cSound = speedOfSound[0];
583 std::vector <double> cauchy(
symSize_) ;
588 cauchy[0] = stress[0] ;
589 cauchy[1] = stress[1] ;
590 cauchy[2] = stress[3] * aux ;
591 cauchy[3] = stress[2] ;
593 for (
int k=0; k<
nbn_; k++)
595 fl_(k,0) += Vol * (B(0,k) * cauchy[0] + B(1,k) * cauchy[2]) ;
596 fl_(k,1) += Vol * (B(0,k) * cauchy[2] + B(1,k) * cauchy[1]) ;
599 Pressure = (cauchy[0] + cauchy[1] + cauchy[3]) / 3. ;
601 VonMises = sqrt(abs(cauchy[0] * (cauchy[0] - cauchy[1]) + cauchy[1] * (cauchy[1] - cauchy[3])
602 + cauchy[3] * (cauchy[3] - cauchy[0]) + 3. * cauchy[2] * cauchy[2])) ;
607 cauchy[0] = stress[0] ;
608 cauchy[1] = stress[1] ;
609 cauchy[2] = stress[2] ;
610 cauchy[3] = stress[3] * aux ;
611 cauchy[4] = stress[5] * aux ;
612 cauchy[5] = stress[4] * aux ;
614 for (
int k=0; k<
nbn_; k++)
616 fl_(k,0) += Vol * (B(0,k) * cauchy[0] + B(1,k) * cauchy[3] + B(2,k) * cauchy[5]) ;
617 fl_(k,1) += Vol * (B(0,k) * cauchy[3] + B(1,k) * cauchy[1] + B(2,k) * cauchy[4]) ;
618 fl_(k,2) += Vol * (B(0,k) * cauchy[5] + B(1,k) * cauchy[4] + B(2,k) * cauchy[2]) ;
621 Pressure = (cauchy[0] + cauchy[1] + cauchy[2]) / 3. ;
623 VonMises = sqrt(abs(cauchy[0] * (cauchy[0] - cauchy[1]) + cauchy[1] * (cauchy[1] - cauchy[2]) + cauchy[2] * (cauchy[2] - cauchy[0])
624 + 3. * (cauchy[3] * cauchy[3] + cauchy[4] * cauchy[4] + cauchy[5] * cauchy[5]))) ;
671 v21[i] =
xl_(0,i) -
xl_(1,i) ;
672 v31[i] =
xl_(0,i) -
xl_(2,i) ;
673 v41[i] =
xl_(0,i) -
xl_(3,i) ;
674 v32[i] =
xl_(1,i) -
xl_(2,i) ;
675 v42[i] =
xl_(1,i) -
xl_(3,i) ;
682 w[0] = v21[1]*v31[2] - v21[2]*v31[1] ;
683 w[1] = v21[2]*v31[0] - v21[0]*v31[2] ;
684 w[2] = v21[0]*v31[1] - v21[1]*v31[0] ;
685 s[0] = w[0]*w[0] + w[1]*w[1] + w[2]*w[2] ;
687 w[0] = v21[1]*v41[2] - v21[2]*v41[1] ;
688 w[1] = v21[2]*v41[0] - v21[0]*v41[2] ;
689 w[2] = v21[0]*v41[1] - v21[1]*v41[0] ;
690 s[1] = w[0]*w[0] + w[1]*w[1] + w[2]*w[2] ;
692 w[0] = v31[1]*v41[2] - v31[2]*v41[1] ;
693 w[1] = v31[2]*v41[0] - v31[0]*v41[2] ;
694 w[2] = v31[0]*v41[1] - v31[1]*v41[0] ;
695 s[2] = w[0]*w[0] + w[1]*w[1] + w[2]*w[2] ;
697 w[0] = v32[1]*v42[2] - v32[2]*v42[1] ;
698 w[1] = v32[2]*v42[0] - v32[0]*v42[2] ;
699 w[2] = v32[0]*v42[1] - v32[1]*v42[0] ;
700 s[3] = w[0]*w[0] + w[1]*w[1] + w[2]*w[2] ;
702 double max_value = std::max({s[0], s[1], s[2], s[3]}) ;
703 xlong = Det / sqrt(max_value) ;
732 auto getMgisStressMeasureKind = [](StressMeasureKind k)
736 case StressMeasureKind::cauchy:
737 return mgis::behaviour::FiniteStrainBehaviourOptions::CAUCHY;
738 case StressMeasureKind::pk1:
739 return mgis::behaviour::FiniteStrainBehaviourOptions::PK1;
740 case StressMeasureKind::pk2:
741 return mgis::behaviour::FiniteStrainBehaviourOptions::PK2;
742 case StressMeasureKind::conjugate:
743 return mgis::behaviour::FiniteStrainBehaviourOptions::CAUCHY;
745 return mgis::behaviour::FiniteStrainBehaviourOptions::CAUCHY;
748 auto getMgisTangentOperatorKind = [](TangentOperatorKind k)
752 case TangentOperatorKind::none:
753 return mgis::behaviour::FiniteStrainBehaviourOptions::DSIG_DF;
754 case TangentOperatorKind::dCauchydF:
755 return mgis::behaviour::FiniteStrainBehaviourOptions::DSIG_DF;
756 case TangentOperatorKind::dPk2dE:
757 return mgis::behaviour::FiniteStrainBehaviourOptions::DS_DEGL;
758 case TangentOperatorKind::dPk1dF:
759 return mgis::behaviour::FiniteStrainBehaviourOptions::DPK1_DF;
761 return mgis::behaviour::FiniteStrainBehaviourOptions::DSIG_DF;
765 {getMgisStressMeasureKind(smk), getMgisTangentOperatorKind(tok)},
l_,
f_, mgis::behaviour::fromString(
h_));
768 this->nbIvars_ =
static_cast<int> (mgis::behaviour::getArraySize(
mgisBehaviour_.isvs, hypothesis_));
771 this->nbEvars_ =
static_cast<int> (mgis::behaviour::getArraySize(
mgisBehaviour_.esvs, hypothesis_));
774 this->KSize_ =
static_cast<int> (mgis::behaviour::getArraySize(
mgisBehaviour_.gradients, hypothesis_) *
775 mgis::behaviour::getArraySize(
mgisBehaviour_.thermodynamic_forces, hypothesis_));
1021 DoubleTab& outputMeshVelocity,
const int nbSom,
const int nbElem,
const int nbSomElem,
1022 const IntTab& sommets,
const int nbFace,
const int nbSomFace,
const IntTab& face_sommets,
const Domaine_ALE& dom)
1028 bool loopOnGridProblem = true ;
1049 while (loopOnGridProblem)
1052 if (
gridDt >= temps - tt)
1055 loopOnGridProblem = false ;
1057 else if (
gridDt >= 0.5 * (temps - tt))
1059 gridDt = 0.5 * (temps - tt) ;
1070 for (
int i=0; i<nbSom; i++)
1075 vp(i,j) =
v(i,j) + 0.5 * Dt *
a(i,j) ;
1076 if (imposedVelocityTag[i] == 1)
vp(i,j) = imposedVelocity(ii,j) ;
1078 double du = Dt *
vp(i,j) ;
1089 loopOnGridProblem = false ;
1095 for (
int i=0; i<nbSom; i++)
1100 if (imposedVelocityTag[i] == 1)
1102 vp(i,j) = imposedVelocity(ii,j) ;
1103 double du = Dt *
vp(i,j) ;
1105 x(i,j) = x0(i,j) + du ;
1130 double totalScaleMass = 0 ;
1141 for (
int elem=0; elem<nbElem; elem++)
1143 for (
int i=0; i< nbn; i++) elnodes[i] = sommets(elem,i) ;
1149 for (
int i=0; i< nbn; i++)
1168 for (
int i=0; i< nbn; i++)
1170 int ii = elnodes[i] ;
1171 mass[ii] += volume * density / nbn ;
1177 dtmin = std::min(dtmin, dts) ;
1181 totalScaleMass += scaleMass ;
1182 for (
int i=0; i< nbn; i++)
1184 int ii = elnodes[i] ;
1204 totalScaleMass =
mp_sum(totalScaleMass) ;
1205 if (totalScaleMass > 0.)
1221 double dtUpdate=Dt ;
1224 for (
int i=0; i<nbSom; i++)
1230 rhs = -
ff(i,j) - d * mm *
vp(i,j) ;
1231 den = mm * (1. + 0.5 * d * dtUpdate) ;
1232 a(i,j) = rhs / den ;
1233 v(i,j) =
vp(i,j) + 0.5 * dtUpdate *
a(i,j) ;
1243 if (
acceleratedSolution == 0) Cerr <<
"Grid dynamic problem, internal step: "<< nstepCurr <<
", dt= " << Dt <<
", dt_stab= " <<
gridDt <<
", [mass scaling] added_mass_ratio= "<< totalScaleMass /
totalMass <<
", time= " << tt <<
", target fluid time= " << temps << finl ;
1244 else Cerr <<
"Grid dynamic problem, accelerated internal step: "<< nstepCurr <<
", dt= " << Dt <<
", [mass scaling] added_mass_ratio= "<< totalScaleMass /
totalMass <<
", time= " << tt <<
", target fluid time= " << temps << finl ;
1248 if (
acceleratedSolution == 0) Cerr <<
"Grid dynamic problem, internal step: "<< nstepCurr <<
", dt= " << Dt <<
", dt_stab= " <<
gridDt <<
", time= " << tt <<
", target fluid time= " << temps << finl ;
1249 else Cerr <<
"Grid dynamic problem, accelerated internal step: "<< nstepCurr <<
", dt= " << Dt <<
", time= " << tt <<
", target fluid time= " << temps << finl ;
1256 for (
int i=0; i<nbSom; i++)
1260 outputMeshVelocity(i,j) = (
x(i,j) - x0(i,j)) / (tt - t0) ;
1267 outputMeshVelocity = 0. ;