Balaje / Gridap.jl

Grid-based approximation of partial differential equations in Julia
MIT License
0 stars 0 forks source link

GSoC Interpolator - Task list #2 #1

Open Balaje opened 3 years ago

Balaje commented 3 years ago

@santiagobadia @ericneiva @oriolcg

Balaje commented 3 years ago

Hi @ericneiva @santiagobadia @oriolcg,

I have a solution for the above task list, but I am not sure if this is the most optimal way. The code is here:

https://gist.github.com/Balaje/a487594a59bf2ccd609d851ce4882c27

interp1

Also generating the random perturbation was hard since rand() keeps generating a different output each time and messes up the output.

interp2

I built a dictionary using the point and a random permutation of 1:num_coords(model) to map the points to a random integer. I then used

Random.seed!(get(D,p,1234))

to seed the random number generator using the Dictionary. Here p is the point and D is the dictionary.

This is the code block

pt_to_ind = randperm(num_nodes(model))
# Build a dictionary with random indices for points
pt_to_rand = Dict(zip(get_node_coordinates(model),pt_to_ind))
function rndm(p::Point, D=pt_to_rand)
    r, s = p
    Random.seed!(get(D,p,1234))
    x = (r ≈ 1.0 || r ≈ 0.0) ? r : r + 0.012*rand()
    y = (s ≈ 1.0 || s ≈ 0.0) ? s : s + 0.012*rand()
    Point(x,y)
end

This generates the same random number (corresponding to the node coordinate) each time map=rndm is called in CartesianDiscreteModel. There should be a direct way to do this :thinking:..?

Aside from this, the main procedure to interpolate is the same.

https://gist.github.com/Balaje/a487594a59bf2ccd609d851ce4882c27#file-interpolate_random-jl-L49 https://gist.github.com/Balaje/a487594a59bf2ccd609d851ce4882c27#file-interpolate_sinusoidal-jl-L40

There may be a more general way to do this interpolation though.

oriolcg commented 3 years ago

Great job @Balaje! I have just some minor comments:

1) You define reffe twice, but you could just re-use the same. 2) Instead of creating the cache and then call evaluate!, you can just call the evaluate function.