1

I am interested in rewriting an old Fortran code to Python. The code was for solving any general field variable, call it F (velocity, temperature, pressure, etc). But to solve each variable we have to define EQUIVALENCE of that variable to F.

For example, something like this:

EQUIVALENCE (F(1,1,1),TP(1,1)),(FOLD(1,1,1),TPOLD(1,1))

Is there a Python version of the above concept?

francescalus
  • 30,576
  • 16
  • 61
  • 96
Bharath Ram
  • 190
  • 1
  • 12

1 Answers1

1

To my knowledge, there is no way to manipulate the memory usage in python. You can perhaps simply use a list.

F=[]

and

FOLD=[]

When you do

F=FOLD 

F and FOLD will point to the same data. I would suggest to use numpy and scipy to create solvers and use python concepts to make it efficient instead of trying to mimic fortran concepts. Especially very old ones.

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
Michael
  • 104
  • 4
  • (I don't understand the Python concept mentioned here, but a quick comment:) The Fortran `equivalence` statement of the question doesn't necessarily make `F` and `TP` "point" to the same data. Instead it makes (part of) `T` and (part of) `TP` point to the same thing. That is, the two arrays may be of different lengths and it'll be only the _overlap_ that share memory. Does this Python construct of the answer have the same effect? – francescalus Nov 27 '19 at 10:08
  • No it doesn't it moves the pointer (so to speak) from one list to the other. – Michael Nov 27 '19 at 10:09
  • @Michael, I won't be equating `F` and `FOLD`. Instead, I have to equate `F` to `T` and `FOLD` to `TOLD`. `F`and `FOLD` has been defined as 3-dimensional arrays. Since there'd be so many variables (velocity, temperature, pressure etc), it's difficult to solve each of them SEPARATELY and hence he has used the idea of `EQUIVALENCE` to solve for each variable as `F(:,:,1) = T`, `F(:,:,2) = v`, `F(:,:,3) = p` etc... – Bharath Ram Nov 28 '19 at 06:00
  • I think I have to do something similar to above but not exactly based on `EQUIVALENCE`. Maybe something like `F(:,:,1) = T`, `F(:,:,2) = v`, `F(:,:,3) = p`. And then solve for them all in a loop with loop index as 3rd dimension of the array `F`. Can someone tell me if the above approach would be fine or would there be a better way to do this? – Bharath Ram Nov 28 '19 at 06:05