gridap / Gridap.jl

Grid-based approximation of partial differential equations in Julia
MIT License
691 stars 97 forks source link

Error message defining a Multifield for displacement vector and stress tensor #923

Open LoveFrootLoops opened 1 year ago

LoveFrootLoops commented 1 year ago

Hi there, I recently came across this package, and I must say it's been great so far. I've been experimenting with it and encountered an error message while defining a multi field using the following code:

using Gridap
# Define domain
domain = (0,1,0,1)
partition = (10, 10)
model = CartesianDiscreteModel(domain,partition)

labels = get_face_labeling(model)
add_tag_from_tags!(labels,"diri_0",[1,3,7])
add_tag_from_tags!(labels,"diri_1",[2,4,8])

degree = 2
Ω = Triangulation(model)
dΩ = Measure(Ω, degree)

# Material constants
const E = 70.0e9
const ν = 0.3
const λ = (E*ν)/((1+ν)*(1-2*ν))
const μ = E/(2*(1+ν))
σmat(ε) = λ*tr(ε)*one(ε) + 2*μ*ε

### Define solution spaces
# Space for displacement u
order = 1
reffeᵤ = ReferenceFE(lagrangian, VectorValue{2,Float64}, order)
Vᵤ = TestFESpace(model, reffeᵤ, conformity=:H1, dirichlet_tags = ["diri_0", "diri_1"])
disp_x = 0.75
g1 = VectorValue(0.0,0.0)
g2 = VectorValue(disp_x, 0.0)
U = TrialFESpace(Vᵤ,[g1,g2])

# Space for stress σ
reffeₛ = ReferenceFE(lagrangian, TensorValues.SymTensorValue{2, Float64, 3}, order)
Vₛ = TestFESpace(model, reffeₛ; conformity=:H1)
Σ = TrialFESpace(Vₛ)

# Multifield Spaces
X = MultiFieldFESpace([Vᵤ, Vₛ])
Y = MultiFieldFESpace([U, Σ])

# Define Objective functions
function res((u, σ), (vᵤ, vₛ))
    ∫(σ - σmat∘ε(u))*dΩ 
end

The error is related to the line "Vₛ = TestFESpace(model, reffeₛ; conformity=:H1)", and I'm receiving the error message: "ERROR: UndefVarError: i not defined".

I would appreciate any insights or assistance to resolve this issue.

ericneiva commented 1 year ago

Hi, @LoveFrootLoops, maybe you can find some assistance in this related discussion https://github.com/gridap/Gridap.jl/issues/908 and the gitter discussion it is referring to https://matrix.to/#/!mSZoaZwNZhWulNruaK:gitter.im/$08HwU3kACfNW6x6Dj6rswjgoOpXfGCJbgmWkzxzrerA?via=gitter.im&via=matrix.org&via=tu-dresden.de

Btw, could you please modify the code such that it can be run as a script? I mean adding using Gridap etc...

LoveFrootLoops commented 1 year ago

Hello @ericneiva,

Thank you for your prompt reply. It appears that the fix is more complicated, requiring some workarounds. I maybe just use VectorValues. But is there an implemented method to transform the symmetric gradient into a vector using Voigt notation?

Alternatively, I could try using TensorValues, but comparing the Tensor with the symmetric gradient i.e. SymTensorValues causes issues with mathematical operations between the two data types. For example, subtracting or adding a symmetric tensor to a normal tensor does not work as expected.

Antoinemarteau commented 1 month ago

Hi @LoveFrootLoops , I'm now working on the (Sym)TensorValue'd FESpaces implementation, do you remember what you meant by "subtracting or adding a symmetric tensor to a normal tensor does not work as expected"? The following works as expected I think:

using Gridap
using Gridap.TensorValues

TensorValue(1.,2,3,4) + SymTensorValue(1.,2,3) # -> TensorValue{2, 2, Float64, 4}(2.0, 4.0, 5.0, 7.0)
TensorValue(1.,2,3,4) - SymTensorValue(1.,2,3) # -> TensorValue{2, 2, Float64, 4}(0.0, 0.0, 1.0, 1.0)