Two inclusions mechanical analysis
Here we present a study case of a thick plate with 2 inclusions. One softer and the other stiffer than the base material. Then we compute the energy deformation on one inclusion.
Fig. 1 Example of mechanical simulation and post processing
1
2from Muscat.FE.UnstructuredFeaSym import UnstructuredFeaSym
3
4#Main class to
5problem = UnstructuredFeaSym()
6
7# the mecanical problem
8from Muscat.FE.SymPhysics import MecaPhysics
9mecaPhysics = MecaPhysics()
10
11# Definition of the degree of the spaces [1 or 2]
12mecaPhysics.SetSpaceToLagrange(P=1)
13
14# add weak form terms to the tanget matrix
15mecaPhysics.AddBFormulation( "Bulk",mecaPhysics.GetBulkFormulation(1.0,0.3) )
16mecaPhysics.AddBFormulation( "Inclusion1",mecaPhysics.GetBulkFormulation(5.0,0.3) )
17youngModulusInclusionII = 0.5
18mecaPhysics.AddBFormulation( "Inclusion2",mecaPhysics.GetBulkFormulation(0.5,0.3) )
19
20# add weak form term to the rhs
21mecaPhysics.AddLFormulation( "Right", mecaPhysics.GetForceFormulation([1,0,0],1) )
22
23problem.physics.append(mecaPhysics)
24
25# the boundary conditions
26from Muscat.FE.KR.KRBlock import KRBlockVector
27dirichlet = KRBlockVector()
28dirichlet.AddArg("u").On('Left').Fix0().Fix1().Fix2().To()
29
30problem.solver.constraints.AddConstraint(dirichlet)
31
32# Read The mesh
33from Muscat.IO.GmshReader import ReadGmsh
34import pathlib
35
36mesh = ReadGmsh(pathlib.Path(__file__).parent.resolve() / pathlib.Path("TwoInclusions.msh"))
37
38print(mesh)
39
40problem.SetMesh(mesh)
41
42# we compute the numbering (maping from the mesh to the linear system)
43problem.ComputeDofNumbering()
44
45from Muscat.Helpers.Timer import Timer
46with Timer("Assembly "):
47 k,f = problem.GetLinearProblem()
48
49#compute the constraints to add to the system
50problem.ComputeConstraintsEquations()
51
52
53with Timer("Solve"):
54 problem.Solve(k,f)
55
56problem.PushSolutionVectorToUnknownFields()
57
58from Muscat.FE.Fields.FieldTools import GetPointRepresentation
59# Recover a point representation of the displacement
60problem.mesh.nodeFields["sol"] = GetPointRepresentation(problem.unknownFields)
61
62from Muscat.FE.Fields.FEField import FEField
63#Creation of a fake fields to export the rhs member
64rhsFields = [ FEField(mesh=mesh,space=None,numbering=problem.numberings[i]) for i in range(3) ]
65from Muscat.FE.Fields.FieldTools import VectorToFEFieldsData
66VectorToFEFieldsData(f,rhsFields)
67problem.mesh.nodeFields["RHS"] = GetPointRepresentation(rhsFields)
68
69print("Done solve")
70print("Compute of the strain energy only on the second inclusion (integral in each element) ")
71
72import Muscat.FE.SymWeakForm as SWF
73from Muscat.FE.MaterialHelp import HookeIso
74from Muscat.Containers.Filters.FilterObjects import ElementFilter
75
76symdep = SWF.GetField("u",3)
77K = HookeIso(youngModulusInclusionII,0.3,dim=3)
78symCellData = SWF.GetField("cellData",1)
79symCellDataT = SWF.GetTestField("cellData",1)
80
81print("Post process")
82
83EnerForm = SWF.ToVoigtEpsilon(SWF.Strain(symdep)).T*K*SWF.ToVoigtEpsilon(SWF.Strain(symdep))*symCellDataT
84
85print("Post process Eval")
86ff = ElementFilter(eTag="Inclusion2")
87from Muscat.FE.DofNumbering import ComputeDofNumbering
88from Muscat.FE.Spaces.FESpaces import LagrangeSpaceP0
89from Muscat.FE.Integration import IntegrateGeneral
90p0Numbering = ComputeDofNumbering(mesh,LagrangeSpaceP0)
91
92energyDensityField = FEField(name="cellData",mesh=problem.mesh,numbering=p0Numbering,space=LagrangeSpaceP0)
93
94m,energyDensity = IntegrateGeneral(mesh=problem.mesh, wform=EnerForm, constants={},
95 fields=problem.unknownFields, unknownFields = [ energyDensityField ], elementFilter=ff)
96print("energyDensity",energyDensity)
97energyDensityField.data = energyDensity
98
99problem.mesh.elemFields["Energy"] = energyDensity
100
101import numpy as np
102print("Strain energy on the second inclusion:", np.sum(energyDensity) )
103# To visualize this xdmf file you can use ParaView (downloadable from https://www.paraview.org/)
104from Muscat.IO import XdmfWriter as XW
105writer = XW.XdmfWriter('TwoInclusions_Output.xdmf')
106writer.SetHdf5(False)
107writer.Open()
108writer.Write(mesh,PointFields=list(mesh.nodeFields.values()), PointFieldsNames=list(mesh.nodeFields.keys()),
109 CellFields=list(mesh.elemFields.values()), CellFieldsNames=list(mesh.elemFields.keys()))
110writer.Close()
111
112print("Done")
113