Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FORTRAN check particle distance to centre of an object.

Status
Not open for further replies.

Kututo

Technical User
May 29, 2014
3
GB
Hi,

I am quite new to FORTRAN and am currently making programs to gain an understanding of it. I am using FORTRAN 90 and Microsoft Visual Studio.

I have made a program in FORTRAN 90, this spawns particles in which then land on a plane. What I would like to do is to check to see if any of the particles are within any cylinders in a line. If they are then I would like to keep them, if not then I would like them to be deleted.

I have thought about how this could be achieved. I have the centre points of the cylinder and the radius (ie. xyz for centre of the top and xyz for centre of the bottom, and a radius value). I thought that the centre of the particle with the radius could be compared with each co-ordinate of the centre point through the cylinder, and then to see if it is within the radius of that point, thus within the cylinder.

Please could you point me in the direction of a tutorial which teaches how to code this, or give me some guidance of how I can achieve this?

Thank you for your time, I really appreciate it.
 
Sorry to post on the thread I made before other people have posted. I have worked out mostly what I need to do.

I have 3 co-ordinates for the top and base of the cylinder, such that the base is 1.00, 1.00, 1.00 and the top is 1.00, 3.00, 1.00, with a radius of 1.00

The generated particles have a co-ordinate for the centre as well as a radius value.

For the Y co-ordinate (yP(i)) it would be:
IF (yP(i) > 1.00 .and. yP(i) < 3.00) THEN
!Test the x and z values (with radius?) to work out if they are in a cylinder
IF ((xP(i)+r(i))) THEN
ELSE DELETE Particle (if not within the x or z range)
ElSE DELETE Particle (If not within the y range)

I have also come into a problem that if it is within a 1.00 radius of the x, then it is fine, and the same for z. But if taken in conjunction they will form a square and be wrongly accepted. What could I do to overcome this? Would an IF ((xP(i)+r(i))) AND IF ((zP(i)+r(i))) THEN (keep particle) work?

If anyone has a more elegant way to write this please let me know, or a better way rather than the convoluted route I am taking.

Many thanks.
 
Apologies again, I have found a solution to this that might be viable.

(xP(i) and zP(i) are the particle co-ordinates)
IF ((((xP(i)-cylinder_x)**2)+((zP(i)-cylinder_z)**2)) < (cylinder_radius**2)) THEN

Could I improve this further?

Also, this is going to sound like a really silly question. I have the statements to define if a particle is in the cylinder, how would I code to store the particle co-ordinates within the cylinder, and delete the particle if it is outside?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top