Common point puzzle

B

Bil Kleb

Warning: the following really needs a sketch.

I have a series of three (x,y) grids with values, z,
at each point. Each successive grid is twice as fine
as the previous, i.e., dx1 = 2 * dx2 = 4 * dx3.

For a series of three nested grids, I'd like to compute
(z2-z1)/(z3-z2) at each of the points shared between all
three grids, i.e., at all the points of the coarsest grid.

The catch? The (x,y) points are not ordered in the same
fashion for each grid. In other words, I need find the
(x,y) coordinate shared by all three for each point in
the coarsest grid.

Now, I can do this with a bunch of conditional checks,
but I thought it might be possible to use Ruby's set
functions or Array intersection in some elegant way to
create some sort of a mask that I could overlay the medium
and fine grids with to find the coincident points.

Thanks for reading this far,
 
M

M. Edward (Ed) Borasky

Bil said:
Warning: the following really needs a sketch.

I have a series of three (x,y) grids with values, z,
at each point. Each successive grid is twice as fine
as the previous, i.e., dx1 = 2 * dx2 = 4 * dx3.

For a series of three nested grids, I'd like to compute
(z2-z1)/(z3-z2) at each of the points shared between all
three grids, i.e., at all the points of the coarsest grid.

The catch? The (x,y) points are not ordered in the same
fashion for each grid. In other words, I need find the
(x,y) coordinate shared by all three for each point in
the coarsest grid.

Now, I can do this with a bunch of conditional checks,
but I thought it might be possible to use Ruby's set
functions or Array intersection in some elegant way to
create some sort of a mask that I could overlay the medium
and fine grids with to find the coincident points.

Thanks for reading this far,
Are these grids large enough that brute force in-core solutions are
ruled out? :)
 
B

Bil Kleb

M. Edward (Ed) Borasky said:
Are these grids large enough that brute force in-core solutions are
ruled out? :)

Unfortunately, I don't understand the question.

Regards,
 
W

William James

Bil said:
Warning: the following really needs a sketch.

I have a series of three (x,y) grids with values, z,
at each point. Each successive grid is twice as fine
as the previous, i.e., dx1 = 2 * dx2 = 4 * dx3.

For a series of three nested grids, I'd like to compute
(z2-z1)/(z3-z2) at each of the points shared between all
three grids, i.e., at all the points of the coarsest grid.

The catch? The (x,y) points are not ordered in the same
fashion for each grid. In other words, I need find the
(x,y) coordinate shared by all three for each point in
the coarsest grid.

Now, I can do this with a bunch of conditional checks,
but I thought it might be possible to use Ruby's set
functions or Array intersection in some elegant way to
create some sort of a mask that I could overlay the medium
and fine grids with to find the coincident points.

Thanks for reading this far,

What is the layout of the array? Something like this?

[ [x1,y1,z1], [x2,y2,z2] ... ]
 
D

Devin Mullins

Bil said:
Unfortunately, I don't understand the question.
The naive implementation is n^2 (with n being the number of gridpoints),
and simply iterates over the coarsest grid, each time finding the
matching points in the two others. That code's destined not to look to
ugly (possibly helped with clever application of #zip or sth? dunno),
but if you have stricter speed requirements...

(Not the OP.. just taking a crack at a translation.)

Devin
 
B

Bil Kleb

William said:
What is the layout of the array? Something like this?

[ [x1,y1,z1], [x2,y2,z2] ... ]

No, not currently, but it could be made to look that way
with some zip action.

Currently, each grid is in a separate hash that contains
variable_name => [ array of values ]

Regards,
 
B

Bil Kleb

Devin said:
The naive implementation is n^2 (with n being the number of gridpoints),
and simply iterates over the coarsest grid, each time finding the
matching points in the two others.

That's going to be my route unless someone comes up
with a nifty array intersection sort of solution.

Speed is not a requirement, yet.

Thanks,
 
F

F. Senault

Le 21 décembre à 13:21, Bil Kleb a écrit :
William said:
What is the layout of the array? Something like this?

[ [x1,y1,z1], [x2,y2,z2] ... ]

No, not currently, but it could be made to look that way
with some zip action.

Currently, each grid is in a separate hash that contains
variable_name => [ array of values ]

Couldn't you make three hashes with the structure h["#{x}x#{y}"] = z ?

After that, you get the keys of the coarse grid and fetch the datapoints
of the others directly.

If you format the x and y in the hash key, you can even order them içf
needed...

Fred
 
W

William James

F. Senault said:
Le 21 décembre à 13:21, Bil Kleb a écrit :
William said:
What is the layout of the array? Something like this?

[ [x1,y1,z1], [x2,y2,z2] ... ]

No, not currently, but it could be made to look that way
with some zip action.

Currently, each grid is in a separate hash that contains
variable_name => [ array of values ]

Couldn't you make three hashes with the structure h["#{x}x#{y}"] = z ?

After that, you get the keys of the coarse grid and fetch the datapoints
of the others directly.

If you format the x and y in the hash key, you can even order them içf
needed...

I think you'd only need to make the hashes for the medium and for the
fine grid. Then you'd iterate through the points in the course grid,
checking to see if each point is in both of the hashes.

And the keys to the hashes could be arrays:
h[ [x,y] ] = z
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,221
Messages
2,571,133
Members
47,747
Latest member
swapote

Latest Threads

Top