Open Balaje opened 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
Also generating the random perturbation was hard since rand()
keeps generating a different output each time and messes up the output.
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.
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.
@santiagobadia @ericneiva @oriolcg
map
option to perturb the original mesh. Example meshes here in Fig 6.1.FEFunction
struct using the nodal values in the previous step.FEFunction
.