1
+ # -*- coding: utf-8 -*-
1
2
# ---
2
3
# jupyter:
3
4
# jupytext:
84
85
import matplotlib .pyplot as plt
85
86
import numpy as np
86
87
from mpltools import annotation # for slope markers
87
- from solvers import LinearProblem
88
+ from solvers import SNESProblem
88
89
from utilities import find_cell_by_point
89
90
90
91
import basix
@@ -655,7 +656,26 @@ def F_ext(v):
655
656
# applied to other plasticity models.
656
657
657
658
# %%
658
- external_operator_problem = LinearProblem (J_replaced , - F_replaced , Du , bcs = bcs )
659
+ petsc_options = {
660
+ "snes_type" : "vinewtonrsls" ,
661
+ "ksp_type" : "preonly" ,
662
+ "pc_type" : "lu" ,
663
+ "pc_factor_mat_solver_type" : "mumps" ,
664
+ "snes_atol" : 1.0e-11 ,
665
+ "snes_rtol" : 1.0e-11 ,
666
+ "snes_max_it" : 50 ,
667
+ "snes_monitor" : "" ,
668
+ # "snes_monitor_cancel": "",
669
+ }
670
+
671
+ def constitutive_update ():
672
+ evaluated_operands = evaluate_operands (F_external_operators )
673
+ ((_ , sigma_new ),) = evaluate_external_operators (J_external_operators , evaluated_operands )
674
+ # Direct access to the external operator values
675
+ sigma .ref_coefficient .x .array [:] = sigma_new
676
+
677
+ external_operator_problem = SNESProblem (Du , F_replaced , J_replaced , bcs = bcs , petsc_options = petsc_options , system_update = constitutive_update )
678
+
659
679
660
680
# %%
661
681
x_point = np .array ([[0 , H , 0 ]])
@@ -665,56 +685,33 @@ def F_ext(v):
665
685
# parameters of the manual Newton method
666
686
max_iterations , relative_tolerance = 200 , 1e-8
667
687
668
- load_steps_1 = np .linspace (2 , 21 , 40 )
669
- load_steps_2 = np .linspace (21 , 22.75 , 20 )[1 :]
670
- load_steps = np .concatenate ([load_steps_1 , load_steps_2 ])
688
+ # load_steps_1 = np.linspace(2, 21, 40)
689
+ # load_steps_2 = np.linspace(21, 22.75, 20)[1:]
690
+ # load_steps = np.concatenate([load_steps_1, load_steps_2])
691
+ # load_steps = np.concatenate([np.linspace(1.1, 22.3, 100)[:-1]])
692
+ load_steps = np .concatenate ([np .linspace (1.2 , 22.3 , 150 )[:- 1 ]])
671
693
num_increments = len (load_steps )
672
694
results = np .zeros ((num_increments + 1 , 2 ))
673
695
674
696
# %% tags=["scroll-output"]
675
-
676
697
for i , load in enumerate (load_steps ):
677
698
q .value = load * np .array ([0 , - gamma ])
678
- external_operator_problem .assemble_vector ()
679
699
680
- residual_0 = external_operator_problem .b .norm ()
681
- residual = residual_0
682
- Du .x .array [:] = 0
700
+ # Du.x.array[:] = 0
683
701
684
702
if MPI .COMM_WORLD .rank == 0 :
685
- print (f"Load increment #{ i } , load: { load } , initial residual: { residual_0 } " )
686
-
687
- for iteration in range (0 , max_iterations ):
688
- if residual / residual_0 < relative_tolerance :
689
- break
690
-
691
- if MPI .COMM_WORLD .rank == 0 :
692
- print (f"\t Outer Newton iteration #{ iteration } " )
693
- external_operator_problem .assemble_matrix ()
694
- external_operator_problem .solve (du )
695
-
696
- Du .x .petsc_vec .axpy (1.0 , du .x .petsc_vec )
697
- Du .x .scatter_forward ()
698
-
699
- evaluated_operands = evaluate_operands (F_external_operators )
700
- ((_ , sigma_new ),) = evaluate_external_operators (J_external_operators , evaluated_operands )
701
- # Direct access to the external operator values
702
- sigma .ref_coefficient .x .array [:] = sigma_new
703
-
704
- external_operator_problem .assemble_vector ()
705
- residual = external_operator_problem .b .norm ()
706
-
707
- if MPI .COMM_WORLD .rank == 0 :
708
- print (f"\t Residual: { residual } \n " )
703
+ print (f"Load increment #{ i } , load: { load } " )
709
704
705
+ external_operator_problem .solve ()
706
+
710
707
u .x .petsc_vec .axpy (1.0 , Du .x .petsc_vec )
711
708
u .x .scatter_forward ()
712
709
713
710
sigma_n .x .array [:] = sigma .ref_coefficient .x .array
714
711
715
712
if len (points_on_process ) > 0 :
716
713
results [i + 1 , :] = (- u .eval (points_on_process , cells )[0 ], load )
717
-
714
+
718
715
print (f"Slope stability factor: { - q .value [- 1 ] * H / c } " )
719
716
720
717
# %% [markdown]
0 commit comments