Skip to content
Snippets Groups Projects
Commit bca919f4 authored by Yonghui56's avatar Yonghui56 Committed by Dmitri Naumov
Browse files

Move local NewtonRaphson from the Material\Solid to NumLib (#1611)

The local NewtonRaphson is moved from MaterialLib/SolidModels to NumLib in order for further reusing.
This class provides a basic NewtonRaphson routine to handle the nonlinear constitutive relationships existing in the local problem. After being moved to NumLib , it can be reused by other processes, e.g the two-phase multicomponent process which I am working on now.
(p.s. Some of the changes are caused by running clang-format)
parent 0d5713e0
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include <boost/math/special_functions/pow.hpp> #include <boost/math/special_functions/pow.hpp>
#include <logog/include/logog.hpp> #include <logog/include/logog.hpp>
#include "MaterialLib/SolidModels/KelvinVector.h" #include "MaterialLib/SolidModels/KelvinVector.h"
#include "NewtonRaphson.h" #include "NumLib/NewtonRaphson.h"
namespace MaterialLib namespace MaterialLib
{ {
...@@ -82,7 +82,7 @@ struct OnePlusGamma_pTheta final ...@@ -82,7 +82,7 @@ struct OnePlusGamma_pTheta final
double const m_p) double const m_p)
: value{1 + gamma_p * theta}, : value{1 + gamma_p * theta},
pow_m_p{std::pow(value, m_p)}, pow_m_p{std::pow(value, m_p)},
pow_m_p1{pow_m_p/value} pow_m_p1{pow_m_p / value}
{ {
} }
...@@ -104,16 +104,14 @@ double plasticFlowVolumetricPart( ...@@ -104,16 +104,14 @@ double plasticFlowVolumetricPart(
} }
template <int DisplacementDim> template <int DisplacementDim>
typename SolidEhlers<DisplacementDim>::KelvinVector typename SolidEhlers<DisplacementDim>::KelvinVector plasticFlowDeviatoricPart(
plasticFlowDeviatoricPart(
PhysicalStressWithInvariants<DisplacementDim> const& s, PhysicalStressWithInvariants<DisplacementDim> const& s,
OnePlusGamma_pTheta const& one_gt, double const sqrtPhi, OnePlusGamma_pTheta const& one_gt, double const sqrtPhi,
typename SolidEhlers<DisplacementDim>::KelvinVector const& typename SolidEhlers<DisplacementDim>::KelvinVector const& dtheta_dsigma,
dtheta_dsigma,
double const gamma_p, double const m_p) double const gamma_p, double const m_p)
{ {
return (one_gt.pow_m_p * (s.D + return (one_gt.pow_m_p *
s.J_2 * m_p * gamma_p * dtheta_dsigma / one_gt.value)) / (s.D + s.J_2 * m_p * gamma_p * dtheta_dsigma / one_gt.value)) /
(2 * sqrtPhi); (2 * sqrtPhi);
} }
template <int DisplacementDim> template <int DisplacementDim>
...@@ -194,8 +192,8 @@ void calculatePlasticResidual( ...@@ -194,8 +192,8 @@ void calculatePlasticResidual(
s, one_gt, sqrtPhi, dtheta_dsigma, gamma_p, m_p); s, one_gt, sqrtPhi, dtheta_dsigma, gamma_p, m_p);
KelvinVector const lambda_flow_D = lambda * flow_D; KelvinVector const lambda_flow_D = lambda * flow_D;
residual.template segment<KelvinVectorSize>(KelvinVectorSize) residual.template segment<KelvinVectorSize>(KelvinVectorSize).noalias() =
.noalias() = eps_p_D_dot - lambda_flow_D; eps_p_D_dot - lambda_flow_D;
// plastic volume strain // plastic volume strain
{ {
...@@ -494,8 +492,7 @@ void SolidEhlers<DisplacementDim>::MaterialProperties:: ...@@ -494,8 +492,7 @@ void SolidEhlers<DisplacementDim>::MaterialProperties::
template <int DisplacementDim> template <int DisplacementDim>
typename SolidEhlers<DisplacementDim>::KelvinVector predict_sigma( typename SolidEhlers<DisplacementDim>::KelvinVector predict_sigma(
double const G, double const K, double const G, double const K,
typename SolidEhlers<DisplacementDim>::KelvinVector const& typename SolidEhlers<DisplacementDim>::KelvinVector const& sigma_prev,
sigma_prev,
typename SolidEhlers<DisplacementDim>::KelvinVector const& eps, typename SolidEhlers<DisplacementDim>::KelvinVector const& eps,
typename SolidEhlers<DisplacementDim>::KelvinVector const& eps_prev, typename SolidEhlers<DisplacementDim>::KelvinVector const& eps_prev,
double const eps_V) double const eps_V)
...@@ -512,8 +509,8 @@ typename SolidEhlers<DisplacementDim>::KelvinVector predict_sigma( ...@@ -512,8 +509,8 @@ typename SolidEhlers<DisplacementDim>::KelvinVector predict_sigma(
// dimensioness hydrostatic stress increment // dimensioness hydrostatic stress increment
double const pressure = pressure_prev - K / G * (eps_V - e_prev); double const pressure = pressure_prev - K / G * (eps_V - e_prev);
// dimensionless deviatoric initial stress // dimensionless deviatoric initial stress
typename SolidEhlers<DisplacementDim>::KelvinVector const typename SolidEhlers<DisplacementDim>::KelvinVector const sigma_D_prev =
sigma_D_prev = P_dev * sigma_prev / G; P_dev * sigma_prev / G;
// dimensionless deviatoric stress // dimensionless deviatoric stress
typename SolidEhlers<DisplacementDim>::KelvinVector const sigma_D = typename SolidEhlers<DisplacementDim>::KelvinVector const sigma_D =
sigma_D_prev + 2 * P_dev * (eps - eps_prev); sigma_D_prev + 2 * P_dev * (eps - eps_prev);
...@@ -599,9 +596,8 @@ bool SolidEhlers<DisplacementDim>::computeConstitutiveRelation( ...@@ -599,9 +596,8 @@ bool SolidEhlers<DisplacementDim>::computeConstitutiveRelation(
auto const update_solution = [&]( auto const update_solution = [&](
ResidualVectorType const& increment) { ResidualVectorType const& increment) {
sigma.noalias() += sigma.noalias() += increment.template segment<KelvinVectorSize>(
increment.template segment<KelvinVectorSize>( KelvinVectorSize * 0);
KelvinVectorSize * 0);
s = PhysicalStressWithInvariants<DisplacementDim>{G * sigma}; s = PhysicalStressWithInvariants<DisplacementDim>{G * sigma};
_state.eps_p_D.noalias() += _state.eps_p_D.noalias() +=
increment.template segment<KelvinVectorSize>( increment.template segment<KelvinVectorSize>(
...@@ -618,13 +614,12 @@ bool SolidEhlers<DisplacementDim>::computeConstitutiveRelation( ...@@ -618,13 +614,12 @@ bool SolidEhlers<DisplacementDim>::computeConstitutiveRelation(
int const maximum_iterations(100); int const maximum_iterations(100);
double const tolerance(1e-14); double const tolerance(1e-14);
auto newton_solver = auto newton_solver = NumLib::NewtonRaphson<
NewtonRaphson<decltype(linear_solver), JacobianMatrix, decltype(linear_solver), JacobianMatrix,
decltype(update_jacobian), ResidualVectorType, decltype(update_jacobian), ResidualVectorType,
decltype(update_residual), decltype(update_residual), decltype(update_solution)>(
decltype(update_solution)>( linear_solver, update_jacobian, update_residual,
linear_solver, update_jacobian, update_residual, update_solution, maximum_iterations, tolerance);
update_solution, maximum_iterations, tolerance);
auto const success_iterations = newton_solver.solve(jacobian); auto const success_iterations = newton_solver.solve(jacobian);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#ifndef MATERIALLIB_SOLIDMODELS_LUBBY2_IMPL_H_ #ifndef MATERIALLIB_SOLIDMODELS_LUBBY2_IMPL_H_
#define MATERIALLIB_SOLIDMODELS_LUBBY2_IMPL_H_ #define MATERIALLIB_SOLIDMODELS_LUBBY2_IMPL_H_
#include "NewtonRaphson.h" #include "NumLib/NewtonRaphson.h"
namespace MaterialLib namespace MaterialLib
{ {
...@@ -105,12 +105,12 @@ bool Lubby2<DisplacementDim>::computeConstitutiveRelation( ...@@ -105,12 +105,12 @@ bool Lubby2<DisplacementDim>::computeConstitutiveRelation(
const int maximum_iterations(20); const int maximum_iterations(20);
const double tolerance(1.e-10); const double tolerance(1.e-10);
auto newton_solver = auto newton_solver = NumLib::NewtonRaphson<
NewtonRaphson<decltype(linear_solver), LocalJacobianMatrix, decltype(linear_solver), LocalJacobianMatrix,
decltype(update_jacobian), LocalResidualVector, decltype(update_jacobian), LocalResidualVector,
decltype(update_residual), decltype(update_solution)>( decltype(update_residual), decltype(update_solution)>(
linear_solver, update_jacobian, update_residual, linear_solver, update_jacobian, update_residual, update_solution,
update_solution, maximum_iterations, tolerance); maximum_iterations, tolerance);
auto const success_iterations = newton_solver.solve(K_loc); auto const success_iterations = newton_solver.solve(K_loc);
......
...@@ -7,17 +7,15 @@ ...@@ -7,17 +7,15 @@
* *
*/ */
#ifndef MATERIALLIB_SOLIDMODELS_NEWTONRAPHSON_H_ #ifndef NUMLIB_NEWTONRAPHSON_H_
#define MATERIALLIB_SOLIDMODELS_NEWTONRAPHSON_H_ #define NUMLIB_NEWTONRAPHSON_H_
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <logog/include/logog.hpp> #include <logog/include/logog.hpp>
#include <Eigen/Dense> #include <Eigen/Dense>
namespace MaterialLib namespace NumLib
{
namespace Solids
{ {
/// Newton-Raphson solver for system of equations using an Eigen linear solvers /// Newton-Raphson solver for system of equations using an Eigen linear solvers
/// library. /// library.
...@@ -92,8 +90,6 @@ private: ...@@ -92,8 +90,6 @@ private:
const int _maximum_iterations; const int _maximum_iterations;
const double _tolerance_squared; const double _tolerance_squared;
}; };
} // namespace NumLib
} // namespace Solids #endif // NUMLIB_NEWTONRAPHSON_H_
} // namespace MaterialLib
#endif // MATERIALLIB_SOLIDMODELS_NEWTONRAPHSON_H_
...@@ -9,9 +9,8 @@ ...@@ -9,9 +9,8 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <limits> #include <limits>
#include "MaterialLib/SolidModels/NewtonRaphson.h" #include "NumLib/NewtonRaphson.h"
TEST(NumLibNewtonRaphson, Sqrt3)
TEST(MaterialLibNewtonRaphson, Sqrt3)
{ {
static const int N = 1; // Problem's size. static const int N = 1; // Problem's size.
...@@ -40,7 +39,7 @@ TEST(MaterialLibNewtonRaphson, Sqrt3) ...@@ -40,7 +39,7 @@ TEST(MaterialLibNewtonRaphson, Sqrt3)
auto const update_solution = [&state]( auto const update_solution = [&state](
LocalResidualVector const& increment) { state += increment[0]; }; LocalResidualVector const& increment) { state += increment[0]; };
auto const newton_solver = MaterialLib::Solids::NewtonRaphson< auto const newton_solver = NumLib::NewtonRaphson<
decltype(linear_solver), LocalJacobianMatrix, decltype(update_jacobian), decltype(linear_solver), LocalJacobianMatrix, decltype(update_jacobian),
LocalResidualVector, decltype(update_residual), LocalResidualVector, decltype(update_residual),
decltype(update_solution)>(linear_solver, update_jacobian, decltype(update_solution)>(linear_solver, update_jacobian,
......
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