Calling a function

I am trying to call a function. I have installed the package JuAFEM. The function file is already there.

My code

using JuAFEM

generate_grid(Quadrilateral, (4,5), [0.0,0.0], [1.0,0.0], [1.0,1.0], [0.0,1.0])

But it shows

MethodError: no method matching generate_grid(::Type{Cell{2,4,4}}, ::Tuple{Int64,Int64}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1})

Can somebody help?

Looks like you’re passing in the type name Quadrilateral and you need to be passing in an instance of that type.

I am new to programmning . Could you please explain?

# this is the name of the struct (the definition of the type)
julia> struct MyType 
         a 
       end

# This is the generation of an instance of that type
julia> x = MyType(1)
MyType(1)

# This is a function that expects an instance of that type
julia> f( x :: MyType ) = x.a
f (generic function with 2 methods)

# Here I call the function with x, which is an instance of that type
julia> f(x)
1

# Here I call it with the name
julia> f(MyType)
ERROR: MethodError: no method matching f(::Type{MyType})
Closest candidates are:
  f(::Any, ::Any) at REPL[3]:1
  f(::MyType) at REPL[44]:1
Stacktrace:
 [1] top-level scope at REPL[46]:1


I have not installed that package you are using, but the error is something like that. You need to generate a Quadrilateral instance of some sort, and you are passing the name.

3 Likes

The generate_grid function in 2D takes the lower left and the upper right corner as arguments. It also wants these as Tensor. So you would need to write

generate_grid(Quadrilateral, (4,5), Vec(0.0,0.0), Vec(1.0,1.0))

where Vec(0.0, 0.0) creates a 1D Tensor. E.g. in the von Mises plasticity example the grid is generated like this.

1 Like