8 Replies - 4813 Views - Last Post: 19 February 2008 - 06:33 AM Rate Topic: -----

#1 Tim_A  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-February 08

Fortran: gradient of 3D array

Post icon  Posted 11 February 2008 - 06:35 AM

Hi everyone.

I'm a physics student, of course from time to time I have to do some programming, I just haven't cracked it yet, doesn't really come naturally to me.

Anyway, I'm writing a program modelling specific magnetic fields, and I have a 3D scalar field named flux(i,j,k).

My task now is to take the gradient of this array to convert each point to the magnetic field. I can picture quite easily how I would do this in a 1-dimensional case, just sum a number of points and divide by the distance between the end points. I can't quite seem to translate this to 3D in my mind, though.

Any hints or suggestions or pseudocode would be really helpful.

Many thanks,
Tim.

Is This A Good Question/Topic? 0
  • +

Replies To: Fortran: gradient of 3D array

#2 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Fortran: gradient of 3D array

Posted 15 February 2008 - 06:51 PM

Two questions:
1. Are you working with the Cartesian (or rectangular) coordinates or some other one?
2. Are you saying that you have data i.e. the values of flux at various points and not the expression (i.e. function) for calculating flux and therefore (atleast for 1D) you are approximating the derivative at each point?
Was This Post Helpful? 0
  • +
  • -

#3 Tim_A  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-February 08

Re: Fortran: gradient of 3D array

Posted 18 February 2008 - 04:12 PM

View PostLouisda16th, on 15 Feb, 2008 - 06:51 PM, said:

1. Are you working with the Cartesian (or rectangular) coordinates or some other one?
2. Are you saying that you have data i.e. the values of flux at various points and not the expression (i.e. function) for calculating flux and therefore (atleast for 1D) you are approximating the derivative at each point?



1. Cartesian coordinates.

2. Yes, I have the data for the values, not the function, so the gradient will be an approximation.
Was This Post Helpful? 0
  • +
  • -

#4 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Fortran: gradient of 3D array

Posted 18 February 2008 - 04:26 PM

Sorry I forgot to ask earlier. What procedure do you use in the 1D case? Do you divide the difference in flux values by difference in position?
Was This Post Helpful? 0
  • +
  • -

#5 Tim_A  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-February 08

Re: Fortran: gradient of 3D array

Posted 18 February 2008 - 05:06 PM

yes, that's right isn't it?

is it just a case of doing pythagoras? if so, i'm gonna feel rather stupid, but at least it's nice and simple :)
Was This Post Helpful? 0
  • +
  • -

#6 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Fortran: gradient of 3D array

Posted 18 February 2008 - 05:28 PM

Well in that case why can't you implement the procedure for the 3D case? After all,
gradV = dV/dx i + dV/dy j + dV/dz k

Store V, x, y and z in separate arrays in the same order. Use a loop to access the current and next elements and then calculate each derivative. If you want the gradient at a particular point, find twp points which lie equidistant with respect to the point you are concerned with. Remember this procedure will give you the derivative of the point in the middle of the two points you are using.
Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#7 Tim_A  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-February 08

Re: Fortran: gradient of 3D array

Posted 18 February 2008 - 05:31 PM

I'm with you. That does help, thanks a lot.

It really is pretty obvious and simple, I just needed a kick-start I guess, I should be ok with it now.
Was This Post Helpful? 0
  • +
  • -

#8 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Fortran: gradient of 3D array

Posted 18 February 2008 - 05:33 PM

I want to try this in the general curvilinear coordinate system sometime. Now that would be a challenge :D.
Field theory can be a big pain sometimes :P.
Was This Post Helpful? 0
  • +
  • -

#9 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: Fortran: gradient of 3D array

Posted 19 February 2008 - 06:33 AM

So could you write the code? If yes it would be nice if you could post it here. People would benefit by knowing how you solved your problem.
Thanks :).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1