.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/PhaseField/LShape.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_PhaseField_LShape.py: LShape ====== Damage simulation for a L-part. .. GENERATED FROM PYTHON SOURCE LINES 12-248 .. image-sg:: /examples/PhaseField/images/sphx_glr_LShape_001.gif :alt: LShape :srcset: /examples/PhaseField/images/sphx_glr_LShape_001.gif :class: sphx-glr-single-img .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/PhaseField/images/sphx_glr_LShape_002.png :alt: $\phi$ :srcset: /examples/PhaseField/images/sphx_glr_LShape_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/PhaseField/images/sphx_glr_LShape_003.png :alt: TRI3: Ne = 4234, Nn = 2178 :srcset: /examples/PhaseField/images/sphx_glr_LShape_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/PhaseField/images/sphx_glr_LShape_004.png :alt: Boundary conditions :srcset: /examples/PhaseField/images/sphx_glr_LShape_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/PhaseField/images/sphx_glr_LShape_005.png :alt: LShape :srcset: /examples/PhaseField/images/sphx_glr_LShape_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/PhaseField/images/sphx_glr_LShape_006.png :alt: LShape :srcset: /examples/PhaseField/images/sphx_glr_LShape_006.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.8.3/examples/PhaseField/results/LShape2D/Test/Miehe_AT1_optimMesh nL=50 1 : 0.000 mm, [0.00e+00; 0.00e+00], 1:0.085s, tol=0.00e+00 2 : 0.040 mm, [0.00e+00; 0.00e+00], 1:0.074s, tol=1.00e+00 4.00% -> 1.78s 3 : 0.080 mm, [0.00e+00; 0.00e+00], 1:0.074s, tol=7.50e-01 8.00% -> 1.71s 4 : 0.120 mm, [0.00e+00; 0.00e+00], 1:0.074s, tol=5.56e-01 12.00% -> 1.64s 5 : 0.160 mm, [0.00e+00; 0.00e+00], 1:0.074s, tol=4.37e-01 16.00% -> 1.56s 6 : 0.200 mm, [0.00e+00; 0.00e+00], 1:0.074s, tol=3.60e-01 20.00% -> 1.49s 7 : 0.240 mm, [0.00e+00; 0.00e+00], 1:0.074s, tol=3.06e-01 24.00% -> 1.41s 8 : 0.280 mm, [0.00e+00; 8.98e-03], 1:0.074s, tol=2.65e-01 28.00% -> 1.34s 9 : 0.320 mm, [0.00e+00; 4.57e-02], 1:0.075s, tol=2.32e-01 32.00% -> 1.27s 10 : 0.360 mm, [0.00e+00; 1.10e-01], 1:0.075s, tol=2.07e-01 36.00% -> 1.20s 11 : 0.400 mm, [0.00e+00; 2.07e-01], 1:0.075s, tol=1.86e-01 40.00% -> 1.12s 12 : 0.440 mm, [0.00e+00; 3.48e-01], 1:0.075s, tol=1.69e-01 44.00% -> 1.05s 13 : 0.480 mm, [0.00e+00; 5.46e-01], 1:0.075s, tol=1.55e-01 48.00% -> 970.18ms 14 : 0.520 mm, [0.00e+00; 7.78e-01], 1:0.075s, tol=1.62e-01 52.00% -> 894.00ms 15 : 0.540 mm, [0.00e+00; 9.48e-01], 1:0.075s, tol=2.22e-01 54.00% -> 894.39ms 16 : 0.560 mm, [0.00e+00; 9.93e-01], 1:0.075s, tol=3.80e-01 56.00% -> 884.86ms 17 : 0.580 mm, [0.00e+00; 1.00e+00], 1:0.075s, tol=4.44e-01 58.00% -> 870.87ms 18 : 0.600 mm, [0.00e+00; 1.00e+00], 1:0.075s, tol=3.82e-01 60.00% -> 852.05ms 19 : 0.620 mm, [0.00e+00; 1.00e+00], 1:0.075s, tol=3.28e-01 62.00% -> 828.04ms 20 : 0.640 mm, [0.00e+00; 1.00e+00], 1:0.075s, tol=2.91e-01 64.00% -> 802.20ms 21 : 0.660 mm, [0.00e+00; 1.00e+00], 1:0.075s, tol=2.78e-01 66.00% -> 776.15ms 22 : 0.680 mm, [0.00e+00; 1.00e+00], 1:0.078s, tol=2.54e-01 68.00% -> 773.82ms 23 : 0.700 mm, [0.00e+00; 1.00e+00], 1:0.076s, tol=2.53e-01 70.00% -> 718.73ms 24 : 0.720 mm, [0.00e+00; 1.00e+00], 1:0.078s, tol=2.03e-01 72.00% -> 701.51ms 25 : 0.740 mm, [0.00e+00; 1.00e+00], 1:0.079s, tol=1.76e-01 74.00% -> 664.54ms 26 : 0.760 mm, [0.00e+00; 1.00e+00], 1:0.078s, tol=1.87e-01 76.00% -> 619.13ms 27 : 0.780 mm, [0.00e+00; 1.00e+00], 1:0.085s, tol=1.72e-01 78.00% -> 620.79ms 28 : 0.800 mm, [0.00e+00; 1.00e+00], 1:0.080s, tol=1.65e-01 80.00% -> 537.75ms 29 : 0.820 mm, [0.00e+00; 1.00e+00], 1:0.081s, tol=1.90e-01 82.00% -> 495.70ms 30 : 0.840 mm, [0.00e+00; 1.00e+00], 1:0.080s, tol=1.64e-01 84.00% -> 440.74ms 31 : 0.860 mm, [0.00e+00; 1.00e+00], 1:0.087s, tol=1.51e-01 86.00% -> 422.45ms 32 : 0.880 mm, [0.00e+00; 1.00e+00], 1:0.083s, tol=1.15e-01 88.00% -> 352.12ms 33 : 0.900 mm, [0.00e+00; 1.00e+00], 1:0.079s, tol=1.10e-01 90.00% -> 280.99ms 34 : 0.920 mm, [0.00e+00; 1.00e+00], 1:0.085s, tol=9.94e-02 92.00% -> 243.84ms 35 : 0.940 mm, [0.00e+00; 1.00e+00], 1:0.084s, tol=9.95e-02 94.00% -> 182.70ms 36 : 0.960 mm, [0.00e+00; 1.00e+00], 1:0.084s, tol=9.12e-02 96.00% -> 122.98ms 37 : 0.980 mm, [0.00e+00; 1.00e+00], 1:0.086s, tol=1.02e-01 98.00% -> 63.55ms 38 : 1.000 mm, [0.00e+00; 1.00e+00], 1:0.088s, tol=9.35e-02 100.00% -> -0.00µs Saved simulation and summary in: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.8.3/examples/PhaseField/results/LShape2D/Test/Miehe_AT1_optimMesh nL=50 Generate movie 01/38 (2.63 %) 3.85 s Generate movie 02/38 (5.26 %) 3.14 s Generate movie 03/38 (7.89 %) 3.02 s Generate movie 04/38 (10.53 %) 3.00 s Generate movie 05/38 (13.16 %) 2.84 s Generate movie 06/38 (15.79 %) 2.87 s Generate movie 07/38 (18.42 %) 2.74 s Generate movie 08/38 (21.05 %) 2.77 s Generate movie 09/38 (23.68 %) 2.59 s Generate movie 10/38 (26.32 %) 2.45 s Generate movie 11/38 (28.95 %) 2.40 s Generate movie 12/38 (31.58 %) 2.33 s Generate movie 13/38 (34.21 %) 2.21 s Generate movie 14/38 (36.84 %) 2.06 s Generate movie 15/38 (39.47 %) 1.99 s Generate movie 16/38 (42.11 %) 1.97 s Generate movie 17/38 (44.74 %) 1.82 s Generate movie 18/38 (47.37 %) 1.77 s Generate movie 19/38 (50.00 %) 1.70 s Generate movie 20/38 (52.63 %) 1.59 s Generate movie 21/38 (55.26 %) 1.47 s Generate movie 22/38 (57.89 %) 1.38 s Generate movie 23/38 (60.53 %) 1.30 s Generate movie 24/38 (63.16 %) 1.24 s Generate movie 25/38 (65.79 %) 1.15 s Generate movie 26/38 (68.42 %) 1.04 s Generate movie 27/38 (71.05 %) 967.98 ms Generate movie 28/38 (73.68 %) 898.00 ms Generate movie 29/38 (76.32 %) 817.09 ms Generate movie 30/38 (78.95 %) 719.89 ms Generate movie 31/38 (81.58 %) 613.63 ms Generate movie 32/38 (84.21 %) 527.17 ms Generate movie 33/38 (86.84 %) 450.84 ms Generate movie 34/38 (89.47 %) 360.68 ms Generate movie 35/38 (92.11 %) 258.58 ms Generate movie 36/38 (94.74 %) 181.23 ms Generate movie 37/38 (97.37 %) 86.50 ms Generate movie 38/38 (100.00 %) 0.00 µs | .. code-block:: Python :lineno-start: 13 import matplotlib.pyplot as plt import numpy as np from EasyFEA import Display, Folder, Models, ElemType, Simulations, Paraview, PyVista from EasyFEA.Geoms import Point, Points, Domain, Circle if __name__ == "__main__": Display.Clear() # ---------------------------------------------- # Configuration # ---------------------------------------------- # simu options doSimu = True meshTest = True optimMesh = True # outputs folder = Folder.Results_Dir() pltIter = False pltLoad = False makeMovie = True makeParaview = False # geom dim = 2 L = 250 # mm nL = 50 ep = 100 # model E = 2e4 # MPa v = 0.18 split = Models.PhaseField.SplitType.Miehe regu = Models.PhaseField.ReguType.AT1 Gc = 130 # J/m2 Gc *= 1000 / 1e6 # mJ/mm2 # convergence tolConv = 1e-0 convOption = 2 # load uMax = 1 # mm inc0 = uMax / 25 inc1 = inc0 / 2 config = f""" uMax = {uMax} inc0 = {inc0} inc1 = {inc1} while ud <= uMax: ud += inc0 if simu.damage.max() < 0.6 else inc1 simu.add_dirichlet(nodes_circle, [0], ['d'], "damage") simu.add_dirichlet(nodes_y0, [0]*dim, simu.Get_dofs()) simu.add_dirichlet(nodes_load, [ud], ['y']) """ # ---------------------------------------------- # Mesh # ---------------------------------------------- l0 = L / nL if meshTest: hC = l0 else: hC = 0.5 # hC = 0.25 p1 = Point() p2 = Point(L, 0) p3 = Point(L, L) p4 = Point(2 * L - 30, L) p5 = Point(2 * L, L) p6 = Point(2 * L, 2 * L) p7 = Point(0, 2 * L) if optimMesh: h = 100 refineDomain = Domain(Point(0, L - h / 3), Point(L + h / 3, L + h), hC) hD = hC * 5 else: refineDomain = None hD = hC contour = Points([p1, p2, p3, p4, p5, p6, p7], hD) circle = Circle(p5, 100) if dim == 2: mesh = contour.Mesh_2D([], ElemType.TRI3, refineGeoms=[refineDomain]) else: mesh = contour.Mesh_Extrude( [], [0, 0, -ep], [3], ElemType.HEXA8, refineGeoms=[refineDomain] ) # Display.Plot_Mesh(mesh) # Display.Plot_Tags(mesh) # from EasyFEA import PyVista # PyVista.Plot_Mesh(mesh).show() nodes_y0 = mesh.Nodes_Conditions(lambda x, y, z: y == 0) nodes_load = mesh.Nodes_Conditions(lambda x, y, z: (y == L) & (x >= 2 * L - 30)) node3 = mesh.Nodes_Point(p3) node4 = mesh.Nodes_Point(p4) nodes_circle = mesh.Nodes_Cylinder(circle, direction=[0, 0, ep]) nodes_edges = mesh.Nodes_Conditions(lambda x, y, z: (x == 0) | (y == 0)) # ---------------------------------------------- # Simulation # ---------------------------------------------- material = Models.Elastic.Isotropic(dim, E, v, True, ep) pfm = Models.PhaseField(material, split, regu, Gc, l0) folder_save = Simulations.PhaseField.Folder( f"{folder}{dim}D", "", pfm.split, pfm.regularization, "", tolConv, "", meshTest, optimMesh, nL=nL, ) Display.MyPrint(folder_save, "green", end="\n") if doSimu: simu = Simulations.PhaseField(mesh, pfm) simu.Results_Set_Bc_Summary(config) dofsY_load = simu.Bc_dofs_nodes(nodes_load, ["y"]) if pltIter: axIter = Display.Plot_Result(simu, "damage") axLoad = Display.Init_Axes() axLoad.set_xlabel("displacement [mm]") axLoad.set_ylabel("load [kN]") list_ud = [] list_f = [] ud = -inc0 iter = -1 while ud <= uMax: # update displacement iter += 1 ud += inc0 if simu.damage.max() < 0.6 else inc1 # update boundary conditions simu.Bc_Init() simu.add_dirichlet(nodes_circle, [0], ["d"], "damage") simu.add_dirichlet(nodes_y0, [0] * dim, simu.Get_unknowns()) simu.add_dirichlet(nodes_load, [ud], ["y"]) # solve u, d, convergence = simu.Solve(tolConv, 500, convOption) # calc load f = np.sum(simu.Calc_Reaction(dofsY_load, "elastic")) # saves load and displacement list_ud.append(ud) list_f.append(f) # print iter simu.Results_Set_Iteration_Summary(iter, ud, "mm", ud / uMax, True) # saves iteration simu.Save_Iter() if pltIter: plt.figure(axIter.figure) Display.Plot_Result(simu, "damage", ax=axIter) plt.pause(1e-12) plt.figure(axLoad.figure) axLoad.scatter(ud, f / 1000, c="black") plt.pause(1e-12) if not convergence or simu.Detect_Damage(nodes_edges): # stops simulation if damage occurs on edges or convergence has not been reached break # saves load and displacement Simulations.Save_pickle((list_f, list_ud), folder_save, "force-displacement") # saves the simulation simu.Save(folder_save) else: simu = Simulations.Load_Simu(folder_save) mesh = simu.mesh list_f, list_ud = Simulations.Load_pickle(folder_save, "force-displacement") # ---------------------------------------------- # Results # ---------------------------------------------- Display.Plot_Result(simu, "damage", folder=folder_save) Display.Plot_Mesh(simu) Display.Plot_BoundaryConditions(simu) axLoad = Display.Init_Axes() axLoad.set_xlabel("displacement [mm]") axLoad.set_ylabel("load [kN]") axLoad.plot(list_ud, np.abs(list_f) / 1000, c="blue") Display.Save_fig(folder_save, "forcedep") Display.Plot_Iter_Summary(simu, folder_save) if makeMovie: simu.Set_Iter(-1) deformFactor = L * 0.05 / simu.Result("displacement_norm").max() iterations = np.arange(0, simu.Niter, simu.Niter // 20) def Func(plotter, iter): simu.Set_Iter(iterations[iter]) thresh = PyVista._pvMesh(simu, "damage", deformFactor).threshold((0, 0.8)) PyVista.Plot(thresh, "damage", plotMesh=True, plotter=plotter, clim=(0, 1)) PyVista.Movie_func(Func, iterations.size, folder_save, "damage.gif") if makeParaview: Paraview.Save_simu(simu, folder_save) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 9.995 seconds) .. _sphx_glr_download_examples_PhaseField_LShape.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: LShape.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: LShape.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: LShape.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_