# Find the lagest function value on the boundary

**URL:** https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256
**Category:** General Discussion
**Created:** [May 20, 2024, 7:24pm UTC](https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256 "2024-05-20T19:24:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![wdachub](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/wdachub/32/1589_2.png) [@wdachub](https://community.freefem.org/u/wdachub)
#### Post date: [May 20, 2024, 7:24pm UTC](https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256/1 "2024-05-20T19:24:13Z")

</div>

Hello to all of you FreeFem users,

I want to find the largest value of my PDE solution on the boundary of the domain. I know “u.max” gives the largest value of the u on the mesh, but I don’t know how to modify it to get the largest function value on the boundary of the domain.

Thank you in advance.

---

<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 20, 2024, 10:05pm UTC](https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256/2 "2024-05-20T22:05:53Z")

</div>

Are you looking for something like this?

```auto
mesh Th = square(10,10);
fespace Vh(Th, P2);
Vh u = x*y;
varf onBoundary(u,v) = on(1, 2, 3, 4, u = 1.0);
real[int] onB = onBoundary(0, Vh, tgv = -1);
u[] .*= onB;
cout << u[].max << endl;
plot(u);

```

---

<div class="post-metadata">

### Author: ![emmawilson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/emmawilson/32/2346_2.png) [@emmawilson](https://community.freefem.org/u/emmawilson)
#### Post date: [May 23, 2024, 10:51am UTC](https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256/3 "2024-05-23T10:51:06Z")

</div>

Hello,

To find the largest value of your PDE solution 𝑢u specifically on the boundary of the domain in FreeFem, you can follow these steps:

1. **Identify Boundary Elements** : Use boundary labels to identify the elements that lie on the boundary.
2. **Evaluate Boundary Values** : Extract the values of 𝑢u at these boundary elements.
3. **Find Maximum** : Compute the maximum value among these boundary values.  
Thanks

---

<div class="post-metadata">

### Author: ![wdachub](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/wdachub/32/1589_2.png) [@wdachub](https://community.freefem.org/u/wdachub)
#### Post date: [May 27, 2024, 2:44am UTC](https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256/4 "2024-05-27T02:44:27Z")

</div>

Thanks for your reply! I understand this strategy but I don’t know what is the syntax for them. For example, how to identify the element that lies on the boundary?

---

<div class="post-metadata">

### Author: ![wdachub](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/wdachub/32/1589_2.png) [@wdachub](https://community.freefem.org/u/wdachub)
#### Post date: [May 27, 2024, 2:55am UTC](https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256/5 "2024-05-27T02:55:07Z")

</div>

Thank you, it works. My understanding of this code is that, when envaluates onBoundary(0,vh, tgv=-1), it returns a vector that is zero on the interior point and is 1 for all boundary points. Therefore, u=u.\*onB makes the function value on the interior point to be zero, which stands out from the boundary points. Is that correct understanding? If so I think an addition modification is required if the function value is negative on the boundary. In addition to that, could I ask why tgv is set to be -1 when constructs onB?

---

<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 27, 2024, 11:05am UTC](https://community.freefem.org/t/find-the-lagest-function-value-on-the-boundary/3256/6 "2024-05-27T11:05:12Z")

</div>

Your understanding is correct. No modification is needed if the function value on the boundary is negative. A negative number multiplied by 1 is still negative.

See [here](https://doc.freefem.org/documentation/finite-element.html) for an explanation of `tgv = -1`.
