Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linear elasticity example #799

Merged
merged 39 commits into from
Aug 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3666310
start linear elasticity tutorial
kimauth Sep 14, 2023
5c855f1
start linear elasticity tutorial
kimauth Sep 23, 2023
7773404
runnable linear elasticity example
kimauth Sep 27, 2023
8cee8b7
suppress output after code blocks
kimauth Sep 27, 2023
9e148c9
load mesh from assets
kimauth Sep 27, 2023
de13a38
revert unindented changes on heat equation tutorial
kimauth Sep 27, 2023
0244357
an actual introduction for linear elasticity
kimauth Sep 27, 2023
ce6fb00
forgotten semicolon
kimauth Sep 27, 2023
d1a7aad
Update docs/src/literate-tutorials/linear_elasticity.jl
kimauth Sep 28, 2023
82ad164
remove internal force vector computation
kimauth Nov 1, 2023
5bde8aa
suppress gmsh output
kimauth Nov 1, 2023
97e3d6d
add comment on addfaceset
kimauth Nov 2, 2023
ea3cffe
add neumann bc
kimauth Nov 2, 2023
38ca056
changes I don't remember
kimauth Apr 9, 2024
9dfb691
Merge branch 'master' into ka/elasticity_example
KnutAM Aug 4, 2024
e1bde02
Elasticity tutorial update and fixups
KnutAM Aug 4, 2024
3b8c26e
Further improvements, update figure
KnutAM Aug 4, 2024
e56d33d
Fix test on linux
KnutAM Aug 4, 2024
a906ec3
Minor formatting
KnutAM Aug 4, 2024
8b4ffd1
Merge branch 'master' into ka/elasticity_example
KnutAM Aug 4, 2024
c6783e4
Disable test that fails seemingly unrelated
KnutAM Aug 4, 2024
26ceb4a
Fix some traction-related formatting
KnutAM Aug 4, 2024
bc41b54
Apply solution by @termi-official
KnutAM Aug 5, 2024
263ac8d
Merge branch 'master' into ka/elasticity_example
KnutAM Aug 5, 2024
1038b51
Use VTKGridFile
KnutAM Aug 5, 2024
9cd5d64
Merge branch 'master' into ka/elasticity_example
KnutAM Aug 8, 2024
d123875
Hopefully complete example
KnutAM Aug 8, 2024
95517a7
Fix links and test hiding
KnutAM Aug 8, 2024
30fbaf8
Improve figure and fix spelling/grammar/formatting
KnutAM Aug 10, 2024
6dd8418
Merge branch 'master' into ka/elasticity_example
KnutAM Aug 10, 2024
c5820ab
Merge branch 'master' into ka/elasticity_example
KnutAM Aug 10, 2024
6103a81
Apply suggestions from reviews
KnutAM Aug 18, 2024
c8936ae
Download stress results to elasticity tutorial
KnutAM Aug 18, 2024
e9913bd
Supress outputs
KnutAM Aug 18, 2024
fd58706
Remove performance tips completely
KnutAM Aug 19, 2024
dc3067b
Apply suggestions from code review
KnutAM Aug 19, 2024
d223659
Adress review comments
KnutAM Aug 19, 2024
551dca3
4th order tensor to mathsf
KnutAM Aug 19, 2024
f5796ef
Remove unused figure
KnutAM Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
start linear elasticity tutorial
kimauth committed Sep 23, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5c855f11a3a42bd0f7cffb5e0bc07b3a4ce7f9c1
46 changes: 41 additions & 5 deletions docs/src/literate-tutorials/linear_elasticity.jl
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
# \int_{\partial\Omega}
# \boldsymbol{t}^\ast \cdot \delta \boldsymbol{u}
# \, \mathrm{d}A
# +
# \int_\Omega
# \boldsymbol{b} \cdot \delta \boldsymbol{u}
# \, \mathrm{d}V
@@ -50,6 +51,42 @@
# $\mathbb{T}$ are suitable trial and test function sets, respectively.
#-

# First we load Ferrite, and some other packages we need
using Ferrite, FerriteGmsh, SparseArrays
# Like for the Heat Equation example, we will use a unit square - but here we'll load the grid of the Ferrite logo! This is done by `FerriteGmsh` here.
grid = togrid("logo.geo") # TODO: where to store correctly and how to refer to this?
# By default the grid lacks the facesets for the boundaries, so we add them by Ferrite here.
# Note that approximate comparison to 0.0 doesn't work well, so we use a tolerance instead.
addfaceset!(grid, "right", x->x[1] ≈ 1.0)
addfaceset!(grid, "top", x->x[2] ≈ 1.0)
addfaceset!(grid, "left", x->x[1] < 1e-6)
addfaceset!(grid, "bottom", x->x[2] < 1e-6)

# ### Trial and test functions
# We use linear Lagrange functions as test and trial functions. The grid is composed of triangular elements, thus we need the Lagrange functions defined on `RefTriangle`. All currently available interpolations can be found under [`Interpolation`](@ref).
# Since the displacement field $\boldsymbol{u}$ is a vector valued field, we vectorize the interpolation by the spatial dimension `dim`.
dim = 2
order = 1 # linear interpolation
ip = Lagrange{RefTriangle, order}()^dim
qr = QuadratureRule{RefQuadrilateral}(2) # 2 quadrature points per spatial dimension
cellvalues = CellValues(qr, ip)

# ### Degrees of freedom
# For distributing degrees of freedom, we define a `DofHandler`. The `DofHandler` knows that `u` has two degrees of freedom per node because we vectorized the interpolation above.
dh = DofHandler(grid)
add!(dh, :u, ip)
close!(dh);

# ### Boundary conditions
# Now, we add boundary conditions. We simply support the bottom and the left side and prescribe a displacement upwards on the top edge.
# The last argument to `Dirichlet` determines which components of the field should be constrained.
ch = ConstraintHandler(dh)
add!(ch, Dirichlet(:u, getfaceset(grid, "bottom"), (x, t) -> 0.0, 2))
add!(ch, Dirichlet(:u, getfaceset(grid, "left"), (x, t) -> 0.0, 1))
add!(ch, Dirichlet(:u, getfaceset(grid, "top"), (x, t) -> 0.1, 2))
close!(ch)

# ### Element routine
function assemble_cell!(ke, re, cellvalues, cell, material, ue)
fill!(ke, 0.0)
fill!(re, 0.0)
@@ -64,15 +101,14 @@ function assemble_cell!(ke, re, cellvalues, cell, material, ue)

dΩ = getdetJdV(cellvalues, q_point)
for i in 1:n_basefuncs
Nᵢ∇ = shape_gradient(cellvalues, q_point, i)# shape_symmetric_gradient(cellvalues, q_point, i)
re[i] += σ ⊡ Nᵢ∇ * dΩ # add internal force to residual
for j in 1:i # loop only over lower half
∇Nᵢ = shape_gradient(cellvalues, q_point, i)# shape_symmetric_gradient(cellvalues, q_point, i)
re[i] += σ ⊡ ∇Nᵢ * dΩ # add internal force to residual
for j in 1:n_basefuncs
∇ˢʸᵐNⱼ = shape_symmetric_gradient(cellvalues, q_point, j)
ke[i, j] += Nᵢ∇ ⊡ ∂σ∂ε ⊡ ∇ˢʸᵐNⱼ * dΩ
ke[i, j] += ∇Nᵢ ⊡ ∂σ∂ε ⊡ ∇ˢʸᵐNⱼ * dΩ
end
end
end
# symmetrize_lower!(ke) # needed? what does assembly in symmetric global matrix does?
end


43 changes: 43 additions & 0 deletions docs/src/literate-tutorials/logo.geo
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Point (1) = {1.000000000000,1.000000000000,0.000000000000};
Point (2) = {1.000000000000,0.379757979263,-0.000000000000};
Point (3) = {0.801534880751,0.454963545532,-0.000000000000};
Point (4) = {0.656107331955,1.000000000000,-0.000000000000};
Point (5) = {0.600672553037,0.775245709538,-0.000000000000};
Point (6) = {0.000000000000,1.000000000000,0.000000000000};
Point (7) = {0.392825178821,0.672136259831,-0.000000000000};
Point (8) = {1.000000000000,0.000000000000,0.000000000000};
Point (9) = {0.547800422194,-0.000000000000,-0.000000000000};
Point (10) = {0.488710023938,0.224380304618,-0.000000000000};
Point (11) = {0.000000000000,0.000000000000,0.000000000000};
Point (12) = {-0.000000000000,0.324566579562,-0.000000000000};
Point (13) = {0.172066723668,0.367888021869,-0.000000000000};
Line (1) = {2,1};
Line (2) = {1,4};
Line (3) = {2,3};
Line (4) = {3,5};
Line (5) = {5,4};
Line (6) = {4,6};
Line (7) = {7,6};
Line (8) = {5,7};
Line (9) = {8,2};
Line (10) = {9,8};
Line (11) = {9,10};
Line (12) = {10,3};
Line (13) = {12,11};
Line (14) = {11,9};
Line (15) = {12,13};
Line (16) = {13,10};
Line (17) = {6,12};
Line (18) = {7,13};
Line Loop (1) = {-1,3,4,5,-2};
Plane Surface (1) = {1}; Physical Surface (1) = {1};
Line Loop (2) = {7,-6,-5,8};
Plane Surface (2) = {2}; Physical Surface (2) = {2};
Line Loop (3) = {-10,11,12,-3,-9};
Plane Surface (3) = {3}; Physical Surface (3) = {3};
Line Loop (4) = {-11,-14,-13,15,16};
Plane Surface (4) = {4}; Physical Surface (4) = {4};
Line Loop (5) = {-7,18,-15,-17};
Plane Surface (5) = {5}; Physical Surface (5) = {5};
Line Loop (6) = {-16,-18,-8,-4,-12};
Plane Surface (6) = {6}; Physical Surface (6) = {6};