Skip to content

Commit

Permalink
Merge pull request #329 from ONSAS/mforets/320
Browse files Browse the repository at this point in the history
Use single field in `FixedDof` boundary condition
  • Loading branch information
mvanzulli authored Jun 18, 2023
2 parents ec9c8d5 + 196f31a commit 233fd8f
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ function linear_cylinder_structure(; ms::Real=0.5)
# -------------------------------
# Boundary conditions
# -------------------------------
# Dirichlet boundary conditions
bc₁ = FixedDof(; components=[1], name=bc₁_label)
bc₂ = FixedDof(; components=[2], name=bc₂_label)
bc₃ = FixedDof(; components=[3], name=bc₃_label)
# Neumann boundary conditions
# Dirichlet boundary conditions
bc₁ = FixedDof(:u, [1], bc₁_label)
bc₂ = FixedDof(:u, [2], bc₂_label)
bc₃ = FixedDof(:u, [3], bc₃_label)
# Neumann boundary conditions
bc₄ = Pressure(; values=pressure, name=bc₄_label)
boundary_conditions = StructuralBoundaryCondition(bc₁, bc₂, bc₃, bc₄)
# Assign boundary conditions to the ones defined in the mesh
Expand Down Expand Up @@ -98,7 +98,7 @@ function point_eval_handler(structure::Structure;
## scalar parameters (dimensions in mm an MPa)
Lₖ = 30.0 # cylinder length in 𝐞ₖ mm
Rₑ = 200.0 # outer radius in mm
Lᵢ = Lⱼ = 2.25Rₑ # hyper rectangle origin in 𝐞ᵢ,𝐞ⱼ and 𝐞ₖ in mm
Lᵢ = Lⱼ = 2.25Rₑ # hyper rectangle origin in 𝐞ᵢ,𝐞ⱼ and 𝐞ₖ in mm
O = (x=-Lᵢ / 2, y=-Lⱼ / 2, z=0.0) # hyper rectangle origin in 𝐞ᵢ,𝐞ⱼ and 𝐞ₖ in mm

# Create an hyper rectangle Lᵢ x Lⱼ x Lₖ
Expand Down
12 changes: 6 additions & 6 deletions benchmark/linear_extension/bench_linear_extension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Linear extension GMSH mesh and `IsotropicLinearElastic` material.
function linear_extension_structure(; ms=0.5)

# x, y and z dimensions of the box in the mesh respectively.
Lᵢ = 2.0 # Dimension in x of the box in m
Lᵢ = 2.0 # Dimension in x of the box in m
Lⱼ = 1.0 # Dimension in y of the box in m
Lₖ = 1.0 # Dimension in z of the box in m

Expand All @@ -25,16 +25,16 @@ function linear_extension_structure(; ms=0.5)
# Material types without assigned elements.
materials = StructuralMaterial(mat)

# Dirichlet boundary conditions
# Dirichlet boundary conditions
bc₁_label = "fixed-ux"
bc₂_label = "fixed-uj"
bc₃_label = "fixed-uk"
bc₄_label = "tension"
bc₁ = FixedDof([:u], [1], bc₁_label)
bc₂ = FixedDof([:u], [2], bc₂_label)
bc₃ = FixedDof([:u], [3], bc₃_label)
bc₁ = FixedDof(:u, [1], bc₁_label)
bc₂ = FixedDof(:u, [2], bc₂_label)
bc₃ = FixedDof(:u, [3], bc₃_label)

# Neumann boundary conditions
# Neumann boundary conditions
bc₄ = GlobalLoad([:u], t -> [p * t, 0, 0], bc₄_label)

boundary_conditions = StructuralBoundaryCondition(bc₁, bc₂, bc₃, bc₄)
Expand Down
14 changes: 7 additions & 7 deletions benchmark/uniaxial_compression/bench_uniaxial_compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function strain_energy_neo(𝔼::AbstractMatrix, K::Real, μ::Real)
J = sqrt(det(ℂ))
# First invariant
I₁ = tr(ℂ)
# Strain energy function
return Ψ = μ / 2 * (I₁ - 2 * log(J)) + K / 2 * (J - 1)^2
# Strain energy function
Ψ = μ / 2 * (I₁ - 2 * log(J)) + K / 2 * (J - 1)^2
end

# Include `create_mesh` function.
Expand Down Expand Up @@ -39,16 +39,16 @@ function uniaxial_compression_structure(; ms=0.5)
# Material types without assigned elements.
materials = StructuralMaterial(neo_hookean_hyper)

# Dirichlet boundary conditions
# Dirichlet boundary conditions
bc₁_label = "fixed-ux"
bc₂_label = "fixed-uj"
bc₃_label = "fixed-uk"
bc₄_label = "tension"
bc₁ = FixedDof([:u], [1], bc₁_label)
bc₂ = FixedDof([:u], [2], bc₂_label)
bc₃ = FixedDof([:u], [3], bc₃_label)
bc₁ = FixedDof(:u, [1], bc₁_label)
bc₂ = FixedDof(:u, [2], bc₂_label)
bc₃ = FixedDof(:u, [3], bc₃_label)

# Neumann boundary conditions
# Neumann boundary conditions
bc₄ = Pressure([:u], t -> p * t, bc₄_label)
bc_labels = [bc₁_label, bc₂_label, bc₃_label, bc₄_label]

Expand Down
8 changes: 4 additions & 4 deletions benchmark/uniaxial_extension/bench_uniaxial_extension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ function uniaxial_extension_structure(; ms=0.5)
# Material types without assigned elements.
materials = StructuralMaterial(svk)

# Dirichlet boundary conditions
# Dirichlet boundary conditions
bc₁_label = "fixed-ux"
bc₂_label = "fixed-uj"
bc₃_label = "fixed-uk"
bc₄_label = "tension"
bc₁ = FixedDof([:u], [1], bc₁_label)
bc₂ = FixedDof([:u], [2], bc₂_label)
bc₃ = FixedDof([:u], [3], bc₃_label)
bc₁ = FixedDof(:u, [1], bc₁_label)
bc₂ = FixedDof(:u, [2], bc₂_label)
bc₃ = FixedDof(:u, [3], bc₃_label)

# Neumann boundary conditions the tension is apliad in the negative direction of the z local axis.
bc₄ = Pressure(; values=t -> -p * t, name=bc₄_label)
Expand Down
2 changes: 1 addition & 1 deletion examples/clamped_truss/clamped_truss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function run_clamped_truss_example()
# Boundary conditions
# -------------------------------
# Fixed dofs
bc₁ = FixedDof(; components=[1], name="fixed_uₓ")
bc₁ = FixedDof(:u, [1], "fixed_uₓ")
# Load
bc₂ = GlobalLoad(; values=t -> [F * t], name="load in j")
# Apply bcs to the nodes
Expand Down
26 changes: 13 additions & 13 deletions examples/cylinder_internal_pressure/cylinder_internal_pressure.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# --------------------------------------------------
# Cylinder submitted to an Internal Pressure Example
# Cylinder submitted to an Internal Pressure Example
#----------------------------------------------------
using LinearAlgebra, Test, Suppressor
using ONSAS
Expand All @@ -17,7 +17,7 @@ function run_cylinder_internal_pressure_example()
E = 210.0 # Young modulus in MPa
ν = 0.3 # Poisson ratio
pressure(t::Real) = p * t
## number of steps
## number of steps
NSTEPS = 9
## tolerances for testing
ATOL = 1e-2 * (Rₑ - Rᵢ)
Expand Down Expand Up @@ -76,11 +76,11 @@ function run_cylinder_internal_pressure_example()
# -------------------------------
# Boundary conditions
# -------------------------------
# Dirichlet boundary conditions
bc₁ = FixedDof(; components=[1], name=bc₁_label)
bc₂ = FixedDof(; components=[2], name=bc₂_label)
bc₃ = FixedDof(; components=[3], name=bc₃_label)
# Neumann boundary conditions
# Dirichlet boundary conditions
bc₁ = FixedDof(:u, [1], bc₁_label)
bc₂ = FixedDof(:u, [2], bc₂_label)
bc₃ = FixedDof(:u, [3], bc₃_label)
# Neumann boundary conditions
bc₄ = Pressure(; values=pressure, name=bc₄_label)
boundary_conditions = StructuralBoundaryCondition(bc₁, bc₂, bc₃, bc₄)
# Assign boundary conditions to the ones defined in the mesh
Expand Down Expand Up @@ -118,9 +118,9 @@ function run_cylinder_internal_pressure_example()
# Numerical solution
# -------------------------------
states_lin_sol = solve!(linear_analysis)
# get time vector or load factors
# get time vector or load factors
λᵥ = load_factors(linear_analysis)
# Get the solution at a random point
# Get the solution at a random point
"Return a rand point in the cylinder (R, θ, L)."
function rand_point_cylinder(Rᵢ::Real=Rᵢ, Rₑ::Real=Rₑ, Lₖ::Real=Lₖ)
[rand() * (Rₑ - Rᵢ) + Rᵢ, rand() * 2 * π, rand() * Lₖ]
Expand All @@ -142,7 +142,7 @@ function run_cylinder_internal_pressure_example()
uᵢ_numeric_p_rand = displacements(states_lin_sol, point_evaluator, 1)
uⱼ_numeric_p_rand = displacements(states_lin_sol, point_evaluator, 2)
uₖ_numeric_p_rand = displacements(states_lin_sol, point_evaluator, 3)
#
#
uᵣ_numeric_p_rand = sqrt.(@. uᵢ_numeric_p_rand^2 + uⱼ_numeric_p_rand^2)
# -------------------------------
# Analytic solution
Expand Down Expand Up @@ -173,7 +173,7 @@ function run_cylinder_internal_pressure_example()
atol::Real=ATOL, atolr=ATOLR,
Rᵢ::Real=Rᵢ, Rₑ::Real=Rₑ, Lₖ::Real=Lₖ)
structure = ONSAS.structure(analysis(sol))
# Generic surface s at z = Lₖ
# Generic surface s at z = Lₖ
rand_R, rand_θ₁, Lₖ = rand_point_cylinder(Rᵢ, Rₑ, Lₖ)
# Set by force Lₖ
rand_θ₂ = rand() * 2 * π
Expand Down Expand Up @@ -250,7 +250,7 @@ function run_cylinder_internal_pressure_example()
@test zero_uⱼ_axis_x_nonlinear
end
#-----------------------------
# Plot & plots
# Plot & plots
#-----------------------------
PLOT_RESULTS && plot_results(λᵥ, nonlinear_analysis, uᵣ_numeric_nᵢ, uᵣ_numeric_nₑ,
uᵣ_analytic_nᵢ, uᵣ_analytic_nₑ)
Expand All @@ -272,7 +272,7 @@ function plot_results(λᵥ, nonlinear_analysis, uᵣ_numeric_nᵢ, uᵣ_numeric
plot!(fig,
vec_p, uᵣ_analytic_nₑ; label="analytic linear uᵣ(Rₑ)",
legend=:topleft, color=:black, lw=2, ls=:solid)
# Plot comparing linear and non linear solutions
# Plot comparing linear and non linear solutions
plot!(fig,
vec_p_non_in, uᵣ_numeric_nonlinear_nᵢ; label="non-linear uᵣ(0, Rᵢ, 0)",
color=:red, lw=2, marker=:circle, markersize=3)
Expand Down
14 changes: 7 additions & 7 deletions examples/linear_extension/linear_extension.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ----------------------------------------------------------------
# ----------------------------------------------------------------
# Uniaxial Extension Example 1 from (Zerpa et. Al., 2019, CMAME).
# ----------------------------------------------------------------
using Test, LinearAlgebra, Suppressor
Expand All @@ -17,7 +17,7 @@ function run_linear_extension_example()
ν = 0.4 # Poisson's ratio
p = 3 # Tension load in Pa
tension(t) = p * t # Tension load function
Lᵢ = 2.0 # Dimension in x of the box in m
Lᵢ = 2.0 # Dimension in x of the box in m
Lⱼ = 1.0 # Dimension in y of the box in m
Lₖ = 1.0 # Dimension in z of the box in m
RTOL = 1e-4 # Relative tolerance for tests
Expand All @@ -34,11 +34,11 @@ function run_linear_extension_example()
# -------------------------------
# Fixed dofs
bc₁_label = "fixed-ux"
bc₁ = FixedDof([:u], [1], bc₁_label)
bc₁ = FixedDof(:u, [1], bc₁_label)
bc₂_label = "fixed-uj"
bc₂ = FixedDof([:u], [2], bc₂_label)
bc₂ = FixedDof(:u, [2], bc₂_label)
bc₃_label = "fixed-uk"
bc₃ = FixedDof([:u], [3], bc₃_label)
bc₃ = FixedDof(:u, [3], bc₃_label)
# Load
bc₄_label = "tension"
bc₄ = GlobalLoad([:u], t -> [tension(t), 0, 0], bc₄_label)
Expand Down Expand Up @@ -172,7 +172,7 @@ function run_linear_extension_example()
σⱼ_analytic_p_rand_e = σ_analytic_p_rand_e[2]
σₖ_analytic_p_rand_e = σ_analytic_p_rand_e[3]
#-----------------------------
# Test boolean for CI
# Test boolean for CI
#-----------------------------
@testset "Linear Extension example" begin
# Displacements
Expand All @@ -186,7 +186,7 @@ function run_linear_extension_example()
@test ϵᵢ_numeric_e_rand ϵᵢ_analytic_p_rand_e rtol = RTOL
@test norm(ϵⱼ_numeric_e_rand) 0 atol = RTOL
@test norm(ϵₖ_numeric_e_rand) 0 atol = RTOL
# Stresses
# Stresses
@test σᵢ_analytic_p_rand_e σᵢ_analytic_p_rand_e rtol = RTOL
@test σⱼ_analytic_p_rand_e σⱼ_analytic_p_rand_e atol = RTOL
@test σₖ_analytic_p_rand_e σₖ_analytic_p_rand_e atol = RTOL
Expand Down
Loading

0 comments on commit 233fd8f

Please sign in to comment.