Skip to content

Commit 47b9f42

Browse files
authored
Merge pull request #14 from MultiSimOLab/latest-gridap
Latest Gridap.jl
2 parents fc191ae + 82cea77 commit 47b9f42

6 files changed

Lines changed: 56 additions & 37 deletions

File tree

src/PhysicalModels/ViscousModels.jl

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function JacobianReturnMapping(γα, Ce, Se, Se_trial, ∂Se∂Ce, F, λα)
157157
∂res1_∂λα = -(1-γα) * Ge
158158
∂res2_∂Ce = Ge
159159
res = [get_array(res1)[:]; res2]
160-
∂res = MMatrix{10,10}(zeros(10, 10))
160+
∂res = MMatrix{10,10}(zeros(10, 10)) # TODO: It'd be nice to use hvcat: ∂res = [∂res1_Ce ∂res1_∂λα; ∂res2_∂Ce 0.0]
161161
∂res[1:9, 1:9] = get_array(∂res1_∂Ce)
162162
∂res[1:9, 10] = get_array(∂res1_∂λα)[:]
163163
∂res[10, 1:9] = (get_array(∂res2_∂Ce)[:])'
@@ -309,10 +309,9 @@ end
309309

310310
function Energy(obj::ViscousIncompressible, Δt::Float64,
311311
Ψe::Function, Se_::Function, ∂Se∂Ce_::Function,
312-
F::TensorValue, Fn::TensorValue, stateVars::VectorValue)
313-
state_vars = get_array(stateVars)
314-
Uvn = TensorValue{3,3}(Tuple(state_vars[1:9])) # TODO: Update tensor slicing until next Gridap version has been released
315-
λαn = state_vars[10]
312+
F::TensorValue, Fn::TensorValue, A::VectorValue)
313+
Uvn = TensorValue{3,3}(A[1:9]...)
314+
λαn = A[10]
316315
#------------------------------------------
317316
# Get kinematics
318317
#------------------------------------------
@@ -343,17 +342,16 @@ end
343342
- `∂Se∂Ce_`: 2nd Piola Derivatives (function of C)
344343
- `F`: Current deformation gradient
345344
- `Fn`: Previous deformation gradient
346-
- `stateVars`: State variables (Uvα and λα)
345+
- `A`: State variables (Uvα and λα)
347346
348347
# Return
349348
- `Pα::Gridap.TensorValues.TensorValue`
350349
"""
351350
function Piola(obj::ViscousIncompressible, Δt::Float64,
352351
Se_::Function, ∂Se∂Ce_::Function,
353-
F::TensorValue, Fn::TensorValue, stateVars::VectorValue)
354-
state_vars = get_array(stateVars)
355-
Uvn = TensorValue{3,3}(Tuple(state_vars[1:9])) # TODO: Update tensor slicing until next Gridap version has been released
356-
λαn = state_vars[10]
352+
F::TensorValue, Fn::TensorValue, A::VectorValue)
353+
Uvn = TensorValue{3,3}(A[1:9]...)
354+
λαn = A[10]
357355
#------------------------------------------
358356
# Get kinematics
359357
#------------------------------------------
@@ -386,17 +384,16 @@ Visco-Elastic model for incompressible case
386384
- `∂Se∂Ce_`: 2nd Piola Derivatives (function of C)
387385
- `∇u_`: Current deformation gradient
388386
- `∇un_`: Previous deformation gradient
389-
- `stateVars`: State variables (Uvα and λα)
387+
- `A`: State variables (Uvα and λα)
390388
391389
# Return
392390
- `Cα::Gridap.TensorValues.TensorValue`
393391
"""
394392
function Tangent(obj::ViscousIncompressible, Δt::Float64,
395393
Se_::Function, ∂Se∂Ce_::Function,
396-
F::TensorValue, Fn::TensorValue, stateVars::VectorValue)
397-
state_vars = get_array(stateVars)
398-
Uvn = TensorValue{3,3}(Tuple(state_vars[1:9])) # TODO: Update tensor slicing until next Gridap version has been released
399-
λαn = state_vars[10]
394+
F::TensorValue, Fn::TensorValue, A::VectorValue)
395+
Uvn = TensorValue{3,3}(A[1:9]...)
396+
λαn = A[10]
400397
#------------------------------------------
401398
# Get kinematics
402399
#------------------------------------------
@@ -432,18 +429,17 @@ end
432429
- `∂Se∂Ce_::Function`: Piola Derivatives (function of C)
433430
- `∇u_::TensorValue`
434431
- `∇un_::TensorValue`
435-
- `stateVars::VectorValue`: State variables (10-component vector gathering Uvα and λα)
432+
- `A::VectorValue`: State variables (10-component vector gathering Uvα and λα)
436433
437434
# Return
438435
- `::bool`: indicates whether the state variables should be updated
439436
- `::VectorValue`: State variables at new time
440437
"""
441438
function ReturnMapping(obj::ViscousIncompressible, Δt::Float64,
442439
Se_::Function, ∂Se∂Ce_::Function,
443-
F::TensorValue, Fn::TensorValue, stateVars::VectorValue)
444-
state_vars = get_array(stateVars)
445-
Uvn = TensorValue{3,3}(Tuple(state_vars[1:9])) # TODO: Update tensor slicing until next Gridap version has been released
446-
λαn = state_vars[10]
440+
F::TensorValue, Fn::TensorValue, A::VectorValue)
441+
Uvn = TensorValue{3,3}(A[1:9]...)
442+
λαn = A[10]
447443
#------------------------------------------
448444
# Get kinematics
449445
#------------------------------------------
@@ -468,10 +464,9 @@ end
468464

469465
function ViscousDissipation(obj::ViscousIncompressible, Δt::Float64,
470466
Se_::Function, ∂Se∂Ce_::Function,
471-
F::TensorValue, Fn::TensorValue, stateVars::VectorValue)
472-
state_vars = get_array(stateVars)
473-
Uvn = TensorValue{3,3}(Tuple(state_vars[1:9])) # TODO: Update tensor slicing until next Gridap version has been released
474-
λαn = state_vars[10]
467+
F::TensorValue, Fn::TensorValue, A::VectorValue)
468+
Uvn = TensorValue{3,3}(A[1:9]...)
469+
λαn = A[10]
475470
#------------------------------------------
476471
# Get kinematics
477472
#------------------------------------------

src/TensorAlgebra/TensorAlgebra.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export Ellipsoid
5353
Compute the square root of a 3x3 matrix by means of eigen decomposition.
5454
"""
5555
function sqrt(A::TensorValue{3})
56-
λ, Q = eigen(get_array(A)) # TODO: the get_array must be removed as long as it is supported after https://github.com/gridap/Gridap.jl/pull/1157
56+
λ, Q = eigen(A)
5757
λ = sqrt.(λ)
5858
TensorValue{3}(λ[1]*Q[1:3]*Q[1:3]' + λ[2]*Q[4:6]*Q[4:6]' + λ[3]*Q[7:9]*Q[7:9]')
5959
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Gridap.TensorValues
2+
using HyperFEM.PhysicalModels
3+
using BenchmarkTools
4+
5+
6+
function benchmark_viscous_model(model)
7+
Ψ, ∂Ψu, ∂Ψuu = model(Δt = 1e-2)
8+
F = TensorValue(1.:9...) * 1e-3 + I3
9+
Fn = TensorValue(1.:9...) * 5e-4 + I3
10+
Uvn = TensorValue(1.,2.,3.,2.,4.,5.,3.,5.,6.) * 2e-4 + I3
11+
J = det(F)
12+
Uvn *= J^(-1/3)
13+
λvn = 1e-3
14+
Avn = VectorValue(Uvn.data..., λvn)
15+
print("Ψ(F, Fn, Avn) |")
16+
@btime $Ψ($F, $Fn, $Avn)
17+
print("∂Ψu(F, Fn, Avn) |")
18+
@btime $∂Ψu($F, $Fn, $Avn)
19+
print("∂Ψuu(F, Fn, Avn) |")
20+
@btime $∂Ψuu($F, $Fn, $Avn)
21+
end
22+
23+
24+
elasto = NeoHookean3D=λ, μ=μ)
25+
visco = ViscousIncompressible(IncompressibleNeoHookean3D=0., μ=μ1), τ1)
26+
visco_elastic = GeneralizedMaxwell(elasto, visco)
27+
benchmark_viscous_model(visco);
28+
benchmark_viscous_model(visco_elastic);

test/TestConstitutiveModels/ViscousModelsTests.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ using HyperFEM.TensorAlgebra
55
using HyperFEM.PhysicalModels
66
using StaticArrays
77
using Test
8-
import Base:
9-
(a::MultiValue, b::MultiValue; kwargs...) = (get_array(a), get_array(b); kwargs...)
108

119

1210
μ = 1.367e4 # Pa

test/TestTensorAlgebra/TensorAlgebra.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ end
4545
# @code_warntype (A ⊗₁₃²⁴ B)
4646
# @code_warntype (D × A)
4747

48-
4948

5049
@testset "cross" begin
5150
A = TensorValue(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) * 1e-3
@@ -60,11 +59,7 @@ end
6059
@test norm(B × C) == 1.104276381618298e-6
6160
@test norm(D × A) == 0.00012378691368638284
6261
@test norm(get_array(A) × get_array(B))== 6.246230863488799e-5
63-
64-
65-
66-
67-
end
62+
end
6863

6964

7065
@testset "inner" begin
@@ -124,3 +119,10 @@ end
124119
@test contraction_IP_PJKL(A,H) == TensorValue(7.0, 10.0, 15.0, 22.0, 23.0, 34.0, 31.0, 46.0, 39.0, 58.0, 47.0, 70.0, 55.0, 82.0, 63.0, 94.0)
125120
@test contraction_IP_JPKL(A,H) == TensorValue(10.0, 14.0, 14.0, 20.0, 26.0, 38.0, 30.0, 44.0, 42.0, 62.0, 46.0, 68.0, 58.0, 86.0, 62.0, 92.0)
126121
end
122+
123+
124+
@testset "sqrt" begin
125+
A = TensorValue(1.:9...)
126+
A = A'*A + I3
127+
@test isapprox(sqrt(A), TensorValue(sqrt(get_array(A))), rtol=1e-14)
128+
end

test/runtests.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ using Gridap.TensorValues
99
using HyperFEM: jacobian, IterativeSolver, solve!
1010
using BenchmarkTools
1111

12-
import Base.isapprox
13-
14-
isapprox(A::MultiValue, B::MultiValue; kwargs...) = isapprox(get_array(A), get_array(B); kwargs...)
15-
1612

1713
@testset "HyperFEMTests" verbose = true begin
1814

0 commit comments

Comments
 (0)