# Error while simulating electrostatic problem for a multi-dielectric system using Gridap

**URL:** <https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044>\
**Category:** Numerics\
**Tags:** pde, gridap\
**Created:** [June 22, 2024, 11:02am UTC](https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044 "2024-06-22T11:02:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![balaji\_sriram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balaji_sriram/32/208000_2.png) [@balaji\_sriram](https://discourse.julialang.org/u/balaji_sriram)\
**Post date:** [June 22, 2024, 11:02am UTC](https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044/1 "2024-06-22T11:02:34Z")

</div>

I am trying to solve an electrostatic poissons equation with 2 different materials. I am trying to compute the electric potential for a sphere (ϵr= 10) embedded inside a box (ϵr= 1).

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/0/00c63929c9de403fdbb2cd3b8308f33c691baca6.png)

I am getting the below error at the affineFEoperator step:

```julia
julia> op = AffineFEOperator(a,b,U,V)
ERROR: promotion of types VectorValue{3, Float64} and Int64 failed to change any arguments

```

**I am using the below code:**

```julia
using Gridap, GridapGmsh, Gridap.Fields, Gridap.Geometry
const epsr_box = 1.0 ; # Relative electric permittivity for box
const epsr_sphere = 10.0 ; # Relative electric permittivity for sphere

model = GmshDiscreteModel("box_sph.msh"); # geometry contains a sphere domain and a box excluding the sphere i.e.. box-sphere
order = 1;
reffe = ReferenceFE(lagrangian,Float64,order);
V = TestFESpace(model,reffe,dirichlet_tags = ["HVelec", "GNDelec"]);
U = TrialFESpace(V, [2.0, 0.0]); # apply voltage at the two opposite faces of the box

degree = 1;
Ω = Triangulation(model);
dΩ = Measure(Ω,degree);

labels = get_face_labeling(model);
dimension = num_cell_dims(model);
tags = get_face_tag(labels,dimension); # get all the tags in the geometry
const sphere_tag = get_tag_from_name(labels,"sphere"); # get tag of sphere geometry
const box_tag = get_tag_from_name(labels,"box"); # get tag of box geometry

function epsr(tag)
    if tag == box_tag
        return epsr_box
    elseif tag == sphere_tag
        return epsr_sphere
    end
end

a(u,v) = ∫( (∇(v)).(epsr*(∇(u))) )dΩ
f(x)=0.0; # assume laplace equation for now and later to have f as f(x,y,z)
b(v) = ∫(v*f)dΩ ;
op = AffineFEOperator(a,b,U,V)
uh = solve(op)

```

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 22, 2024, 11:53am UTC](https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044/2 "2024-06-22T11:53:22Z")

</div>

Welcome Balaji, Please read [this topic](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) to make it easier to help you. Please edit you post and write your julia code within quoted code.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 22, 2024, 12:51pm UTC](https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044/3 "2024-06-22T12:51:57Z")

</div>

> [@raman\_kumar](#):
>
> Please edit you post and write your julia code within quoted code.

(I edited the post to quote the code.)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 22, 2024, 12:58pm UTC](https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044/4 "2024-06-22T12:58:36Z")

</div>

> [@balaji\_sriram](#):
>
> `a(u,v) = ∫( (∇(v)).(epsr*(∇(u))) )dΩ`

This doesn’t look right. The dot product operator is `⋅` ([unicode dot operator](https://www.compart.com/en/unicode/U+22C5), which can be typed with `\cdot<TAB>` at the `julia>` prompt or in editors with appropriate plugins), not `.` (period). A dot product can also be written `dot(∇(v), epsr*(∇(u)))` without the Unicode operator, but Gridap’s API is pretty Unicode-heavy in general.

See also the [Gridap Poisson tutorial](https://gridap.github.io/Tutorials/dev/pages/t001_poisson/).

Also, I think you need to tell it to pass the tags to `epsr` more explicitly here. See e.g. how the tags are passed in the [Gridap linear elasticity example](https://gridap.github.io/Tutorials/dev/pages/t003_elasticity/#Constitutive-law-1). I think that is the source of your error message — from the way you are using it, Gridap thinks that `epsr` must be a function `epsr(x)` of the position vector `x`, which causes an error because `epsr` expects an integer `tag` argument.

---

<div class="post-metadata">

**Author:** ![balaji\_sriram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balaji_sriram/32/208000_2.png) [@balaji\_sriram](https://discourse.julialang.org/u/balaji_sriram)\
**Post date:** [June 22, 2024, 5:18pm UTC](https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044/5 "2024-06-22T17:18:09Z")

</div>

Thank you very much. I am relatively new to julia programming. I modified the original code using the **dot()** operator instead of “ **.** ” as you suggested .I am writing the modified section of the new code below.

```julia
function epsr(tag)
    if tag == box_tag
        return epsr_box
    elseif tag == sphere_tag
        return epsr_sphere
    end
end
a(u,v) = ∫( dot(∇(v) , (epsr∘(∇(u),tags))) )*dΩ

```

I am getting a different error but at the same step as before:

```julia
julia> op = AffineFEOperator(a,b,U,V)
ERROR: MethodError: no method matching epsr(::VectorValue{3, Float64}, ::Int8)
Closest candidates are:
  epsr(::Any)

```

Also, I went through the documentation on multi-material elasticity modeling: [3 Linear elasticity · Gridap tutorials](https://gridap.github.io/Tutorials/dev/pages/t003_elasticity/#Constitutive-law-1). I am still unclear on the syntax part. because, in the example problem the function **σ\_bimat** has arguments **(ε,tag)** of which **ε** is itself an operator defined by **1/2(∇u+(∇u) ')**. Whereas in my case, the function **epsr** has only **tag** as the argument, so how can I write the weak form.  
I request you to help me with 2 things.

1. The correct modification of the code.
2. Any link or documentation or youtube material that will help me learn the syntax of these operators/functions (as I am a beginner).

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 22, 2024, 5:27pm UTC](https://discourse.julialang.org/t/error-while-simulating-electrostatic-problem-for-a-multi-dielectric-system-using-gridap/116044/6 "2024-06-22T17:27:00Z")

</div>

> [@balaji\_sriram](#):
>
> `MethodError: no method matching epsr(::VectorValue{3, Float64}, ::Int8)`

That’s because your `epsr` function should now take `∇(u)` as the first argument since you are composing it with `(∇(u),tags)`, e.g.

```julia
function epsr(∇u, tag)
    if tag == box_tag
        return epsr_box * ∇u
    elseif tag == sphere_tag
        return epsr_sphere * ∇u
    end
end

```

(similar to the tutorial I linked),
