thelfer / MFrontGenericInterfaceSupport

This project aims at providing support for MFront generic behaviours. This project can be embedded in open-source and propriary sofware
35 stars 34 forks source link

Get stress results from MFront #72

Closed CUMTBer01 closed 2 years ago

CUMTBer01 commented 2 years ago

I am a beginner for MFront and FEniCS. Recently I ran into a problem about the Drucker-Prager model coupling FEniCS with Mfront. When I tend to check the stress-strain curves, I found the stress results is not consistent with MTest results. When the material yields, the stress should remain unchanged. The code for get stress results in FEniCS is "sig = problem.get_flux("Stress", project_on=("DG", 0))".Maybe the the code is wrong ,so I hope the related researchers can give me some suggestion to solve this problem. The MFront, MTest and FEniCS files about DruckerPrager model have been attached. Thank you very much!

https://github.com/CUMTBer01/DruckerPrager.git

thelfer commented 2 years ago

Hi @CUMTBer01,

Thanks for your interest for MFront and mgis.fenics.

I think that you somehow messed up your boundary conditions:

With the same boundary conditions, both computations seems to agree quite well, fortunately !

comparison

See the attached files for details.

Best,

Thomas

tests.zip

CUMTBer01 commented 2 years ago

Hi, Helfer Thank you for helping to solve my problem. I have check the codes you attached. With the same modelling hypothesis(Tridimensional and Plane_Strain) and boundary conditions, the results will be consistent between FEniCS and MTest.

thelfer commented 2 years ago

Great ! Do not hesitate to open another issue if you need further help.

CUMTBer01 commented 2 years ago

Hi, Helfer Recently, I want to get the convergence history, that is the global and local Newton iteration numbers and tolerance value (or the norm of the global and local residual vector) in every time step based on FEniCS and MFront. I don't how to program the code for this purpose in FEniCS. I hope you can give some suggestion.
https://github.com/CUMTBer01/DruckerPrager.git

thelfer commented 2 years ago

Hi @CUMTBer01

Let's start with the local quantities (number of iterations+local residual).

Please find attached the a version of your behaviour with two additional auxiliary state variables. Those are updated after the convergence of the local Newton method.

DruckerPrager.zip

thelfer commented 2 years ago

For the global quantities, you may want to have a look at the output of the solve method which is a pair of number of Newton iterations, and whether iteration converged (int, bool). For the value of the residual, you may want to get the solver data member of the MFrontNonlinearProblem class and call the residual method.

CUMTBer01 commented 2 years ago

Hi, Helfer Thank you reply about my problem. I try to calculate the DP model with FEniCS and MFront(you send me the DruckerPrager.mfront), and I can get the number of iterations and local residual in FEniCS. All FEniCS , MFront files and local results have been attached. Such as the code" error = problem.get_state_variable("LocalResidual", project_on=("CG", 1)) iteration_number = problem.get_state_variable("LocalIterationNumber", project_on=("CG", 1)) results[i+1, 0] = error(x1/2, y1/2, z1/2) results[i+1, 1] = iteration_number(x1/2, y1/2, z1/2) np.savetxt('Error', results[:,0]) np.savetxt('Iteration_Number', results[:,1])". Q1:The FEniCS code includes 1000 time steps, so we can see 1000 lines results of the local iteration number and residual in Error.txt and Iteration_Number.txt. But the local iteration number in each time step is more than one, so the I am confused the local residual in each time step. Maybe the local residual should be more than one in every time step. Q2:I copy the convergence history in Terminal window after the FEniCS calculation. I don't understand what is meaning for these codes. " DruckerPrager::integrate() : beginning of resolution(Is it local convergence history?) DruckerPrager::integrate() : iteration 0 : 0 DruckerPrager::integrate() : convergence after 0 iterations

DruckerPrager::integrate() : beginning of resolution DruckerPrager::integrate() : iteration 0 : 1.23693e-20 DruckerPrager::integrate() : convergence after 0 iterations

DruckerPrager::integrate() : beginning of resolution DruckerPrager::integrate() : iteration 0 : 0 DruckerPrager::integrate() : convergence after 0 iterations

Newton iteration 0: r (abs) = 2.713e-09 (tol = 1.000e-06) r (rel) = 1.000e+00 (tol = 1.000e-06)(Is it gloabal convergence history?) Newton solver finished in 0 iterations and 0 linear solver @@@@iterations." Q3: How to get in the global iteration numbers and residual in every iteration in FEniCS(except check the terminal window)?

Iteration_information.zip

@bleyerj

thelfer commented 2 years ago

Q1:The FEniCS code includes 1000 time steps, so we can see 1000 lines results of the local iteration number and residual in Error.txt and Iteration_Number.txt. But the local iteration number in each time step is more than one, so the I am confused the local residual in each time step. Maybe the local residual should be more than one in every time step.

Sorry I am not sure to understand this sentence.

You get the number of iterations for the last call to the behaviour integration for the given time step. If 0, it usually means that the solution at the beginning of the time step is a valid solution for the end of the time step (no increment of the state variables).

Q2:I copy the convergence history in Terminal window after the FEniCS calculation. I don't understand what is meaning for these codes.

Those lines are printed by MFront in debug mode and shows the evolution of the residual of the local Newton:

DruckerPrager::integrate() : beginning of resolution(Is it local convergence history?)
DruckerPrager::integrate() : iteration 0 : 0
DruckerPrager::integrate() : convergence after 0 iterations

Those lines are printed by the Newton solver of FEniCS:

Newton iteration 0: r (abs) = 2.713e-09 (tol = 1.000e-06) r (rel) = 1.000e+00 (tol = 1.000e-06)
Newton solver finished in 0 iterations and 0 linear solver @@@@Iterations."

Q3: How to get in the global iteration numbers and residual in every iteration in FEniCS

You probably need to override the Newton solver. @bleyerj Any idea ?

tengfeideng commented 2 years ago

Hi, Dr.Helfer, Your explanation is useful for Q1. The iteration number and tolerance of the last integration could be obtained. I got it.

And for Q2, I also have a confusion. Why include so many Local Newton iteration printed by Mfront between two Global Newton iteration? Does it depend on the number of integration points or some parameters in MFront file? Or maybe in debug mode, as a default setting, local Newton iteration must be repeated a specific number.

Regards

CUMTBer01 commented 2 years ago

Hi, Helfer I am very sorry for not explaining my question clearly, but your answer to Q1 made me understand that the output result is only the iteration result of the last step of the local iteration at each time step. About Q3,If I load mfront by the code "mfront --obuild --interface=generic DruckerPrager.mfront" and don't include "--debug", and I can get and output the global iteration information in FEniCS by Terminal window.

thelfer commented 2 years ago

And for Q2, I also have a confusion. Why include so many Local Newton iteration printed by Mfront between two Global Newton iteration? Does it depend on the number of integration points or some parameters in MFront file? Or maybe in debug mode, as a default setting, local Newton iteration must be repeated a specific number.

The behaviour integration is indeed called at each integration point for each global iteration.