In the previous post arrays were created in Python and passed to a Fortran dll as ctype pointers. The data written to these arrays in the Fortran routines was then converted back to Python arrays with statements such as: nodedisp = npc.as_array(nodedisp). In fact this conversion is not necessary. The data passed to the Fortran code is a pointer to the location of the arrays created in Python. The Fortran results are therefore written to these arrays, which may be read directly from Python using the original array names. More importantly, I found the results of using the npc.as_array() method to be inconsistent; sometimes returning the expected results, but sometimes empty or corrupted arrays. Reading the results of the Fortran code using the original Python arrays is therefore both simpler and more reliable.
I have updated the previous post to reflect the revised process, and also updated the download file with the revised code. The new file, including full open-source code, may be downloaded from:
It is even easier to call Fortran from C. I can’t wait until you figure out the FP data type. Just hand a pointer to a double to the Fortran routine and there is no copying of data. It just runs 10x faster.
Like my grandpappy always told me, cut out the middleman.
LikeLike
Good to see you are still visiting 🙂
There’s only a few milliseconds to be saved in data transfer time. 99.9% of the computation is in the Fortran, which takes a few seconds to a few minutes (or much longer for more complicated analyses which I’ll be looking at later).
The only area with real scope for time saving is in the solution of the systems of linear equations, which is done with fairly simplistic algorithms in the code from the book. This is the main reason for introducing Python, which has some much better compiled routines for solving spares matrices.
LikeLike
Pingback: Plane Strain FEA – Non linear staged analysis | Newton Excel Bach, not (just) an Excel Blog