# Building a function in which one of its inputs is a variable of type Vh

**URL:** <https://community.freefem.org/t/building-a-function-in-which-one-of-its-inputs-is-a-variable-of-type-vh/1712>\
**Category:** General Discussion\
**Created:** [May 2, 2022, 8:25pm UTC](https://community.freefem.org/t/building-a-function-in-which-one-of-its-inputs-is-a-variable-of-type-vh/1712 "2022-05-02T20:25:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucassfernandez](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lucassfernandez](https://community.freefem.org/u/lucassfernandez)\
**Post date:** [May 2, 2022, 8:25pm UTC](https://community.freefem.org/t/building-a-function-in-which-one-of-its-inputs-is-a-variable-of-type-vh/1712/1 "2022-05-02T20:25:33Z")

</div>

Hi, folks!

Suppose I have:

```auto
int n;
real[int] vi;
mesh Th;
fespace Vh(Th, P1);
Vh u;

```

_I’d like to build a function_ in which one of its inputs is u, i.e., the variable of Vh-type. For example:

```auto
func int myfunction(int n, real[int] &vi, mesh &Th, [???] ){
   return 0;
}

```

The question is: How should I pass u (the Vh-type variable) in [???] ?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [May 3, 2022, 9:19am UTC](https://community.freefem.org/t/building-a-function-in-which-one-of-its-inputs-is-a-variable-of-type-vh/1712/2 "2022-05-03T09:19:51Z")

</div>

The line: `Vh u;` defines a real array called `u[]` that is defined on the fespace `Vh`. Hence, you can pass `u[]` just like any other real array, (e.g. `vi`). Just be sure to include the square brackets so that FreeFEM interprets it as a real array.

---

<div class="post-metadata">

**Author:** ![lucassfernandez](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lucassfernandez](https://community.freefem.org/u/lucassfernandez)\
**Post date:** [May 3, 2022, 12:12pm UTC](https://community.freefem.org/t/building-a-function-in-which-one-of-its-inputs-is-a-variable-of-type-vh/1712/3 "2022-05-03T12:12:52Z")

</div>

Thanks for your reply. However, such a strategy does not work in my code. Could you provide a simple example?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [May 3, 2022, 12:38pm UTC](https://community.freefem.org/t/building-a-function-in-which-one-of-its-inputs-is-a-variable-of-type-vh/1712/4 "2022-05-03T12:38:02Z")

</div>

Define the function like:

```auto
func int myfunction(int n, real[int] &vi, mesh &Th, real[int] &u){
   return 0;
}

```

Then call it like:

```auto
int k = myfunction(n,vi,Th, u[]);

```

---

<div class="post-metadata">

**Author:** ![lucassfernandez](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lucassfernandez](https://community.freefem.org/u/lucassfernandez)\
**Post date:** [May 3, 2022, 1:52pm UTC](https://community.freefem.org/t/building-a-function-in-which-one-of-its-inputs-is-a-variable-of-type-vh/1712/5 "2022-05-03T13:52:45Z")

</div>

**Thank you for your response.** Indeed, this is the solution for the case when `myfunction` is built within the file .edp.
