Skip to content
Snippets Groups Projects
Commit 143117c1 authored by Theodore Efremov's avatar Theodore Efremov :hibiscus:
Browse files

[Exogam] Added sanity check for failed NR convergence and fixed returned var in this case

parent 2556a9d5
No related branches found
No related tags found
No related merge requests found
......@@ -186,6 +186,7 @@ Vector3D TExogamGeo::newton_raphson(double initial_guess,
Vector3D& TargetPos, double tolerance = 1e-6, int max_iterations = 100) {
double alpha = initial_guess;
Vector3D unit(0.,1.,0.);
Vector3D fail ;
setclover(&unit);
// std::cout << "new NewtonRaphson" << std::endl;
for (int i = 0; i < max_iterations; ++i) {
......@@ -204,15 +205,19 @@ Vector3D TExogamGeo::newton_raphson(double initial_guess,
// Si la différence est inférieure à la tolérance, on considère la solution trouvée
if (std::fabs(alpha_new - alpha) < tolerance) {
return SegmentPos - TargetPos;
}
// std::cout << alpha << " " << alpha_new << std::endl;
alpha = alpha_new;
fail = SegmentPos-TargetPos ;
}
std::cerr << "Newton-Raphson n'a pas convergé après " << max_iterations << " itérations.\n";
Vector3D fail;
// If failed convergence is wrong by more than 100% of initial guess just return initial guess
if ((std::fabs(alpha - initial_guess) > (initial_guess *2)) ){
Vector3D outerpos = getouterpos(initial_guess,InteractionDepth);
Vector3D SegmentPos(outerpos.X(), getdistance() + std::cos(initial_guess) * InteractionDepth, outerpos.Z());
fail = SegmentPos - TargetPos;
}
return fail; // Retourne la dernière valeur trouvée si la convergence n'est pas atteinte
}
......
......@@ -212,4 +212,4 @@ class TExogamCartesian: public TExogamGeo{
double getdistance() override;
double tolerance = 1; // tolerance is in mm
};
#endif
\ No newline at end of file
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment