# Refinement meshgrids

**URL:** <https://discourse.julialang.org/t/refinement-meshgrids/129982>\
**Category:** New to Julia\
**Tags:** question, mesh\
**Created:** [June 18, 2025, 5:59am UTC](https://discourse.julialang.org/t/refinement-meshgrids/129982 "2025-06-18T05:59:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cyan](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cyan](https://discourse.julialang.org/u/Cyan)\
**Post date:** [June 18, 2025, 5:59am UTC](https://discourse.julialang.org/t/refinement-meshgrids/129982/1 "2025-06-18T05:59:40Z")

</div>

Hi, all. I am trying to plot the curves of potential `1/r` on mesh grid `xg` and `yg` (`xg` and `yg` are 2d mesh grids, `r = @. sqrt(xg^2 + yg^2)`). I want to solve the curves where the potential equals 1. I want to refine the grids near the curve. Is there any simple way to construct refined meshes?

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [June 19, 2025, 6:25pm UTC](https://discourse.julialang.org/t/refinement-meshgrids/129982/2 "2025-06-19T18:25:07Z")

</div>

Hi,  
I’m not quite sure what you mean by solve for curves, but if you want to construct the level set for value 1, you could just use something like

```julia
using GLMakie

xs = LinRange(-1.5, 1.5, 100) # 100 equidistant points between -1.5 and 1.5 (inclusive)
ys = LinRange(-1.5, 1.5, 100)
f(x, y) = sqrt(x^2 + y^2)

contour(xs, ys, [f(x, y) for x in xs, y in ys], levels=[1])

```

Now if you would want to refine this to get a higher resolution, what does that mean for `xs` and `ys` (or your `xg` and `yg`)? Would you want to obtain something like `xs = ys = LinRange(-1.5, 1.5, 200)`? Do you want to abandon the grid structure in favour of something like a quadtree?

---

<div class="post-metadata">

**Author:** ![Cyan](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cyan](https://discourse.julialang.org/u/Cyan)\
**Post date:** [June 20, 2025, 5:06am UTC](https://discourse.julialang.org/t/refinement-meshgrids/129982/3 "2025-06-20T05:06:04Z")

</div>

it closes, I want to obtain the grid structure like `xsub = ysus = LinRange(-.5, .5, 100)`

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [June 21, 2025, 12:07pm UTC](https://discourse.julialang.org/t/refinement-meshgrids/129982/4 "2025-06-21T12:07:24Z")

</div>

> [@Cyan](#):
>
> it closes

Assuming you’re referring to the Makie window, and you’re running the code as a script, you could use `wait(display(contour(...)))`.

> [@Cyan](#):
>
> I want to obtain the grid structure like `xsub = ysus = LinRange(-.5, .5, 100)`

I’m not sure how exactly you get to `-.5`, but you could use e.g. `new_xs = LinRange(xs[cld(length(xs), 3)], xs[cld(2*length(xs), 3)], length(xs))`.

* * *

In general, if your `xs` is not a `LinRange` you could refine it by interpolating:

```julia
using Interpolations

itp = linear_interpolation(eachindex(xs), xs)

new_xs = itp[begin:0.5:end]  
# 199-element Vector{Float64}
# xs[1] (xs[1] + xs[2])/2 xs[2] ... xs[end]

new_xs2 = itp[LinRange(searchsortedfirst(xs, -0.5), searchsortedlast(xs, 0.5), 100)]
# 100-element Vector{Float64}:
# -0.5 -0.48989898989898983 ... 0.48989898989899006 0.5

```
