Thanks in advance!
I'm a green hand in python and mix-language programing.
My develop environment is Abaqus6.13(with python 2.6.2)
+MSVS2012
+inter Fortran 2013SP1
(I want to use IMSL
), on Windows 7
. And my final purpose is developing an GUI plugin in Abaqus
which can be run only depends on a new installed Abaqus
.
What I want to do is as sorted following:
Abaqus
;Fortran
;Above all, I want to use python
as a glue for Abaqus
and Fortran
, and I don't know how to transfer the variables (perhaps they are only numbers in int or float and one/two dimension arrays ).
So, how can I fix the problem? or is anyone has similar experience to give me some suggestions? Thanks a lot.
My experiences of failures:
f2py
: Because I work on Win7
, and I found that if I choose f2py
, files within the python distribution of Abaqus must be modified, which goes against the purpose for working on a new installed Abaqus
. ctypes
+Dynamic linking library
: I check the following codes using Fortran
generate test.dll and call it from python
, and they runs well in python3.6
, but when I check the using Abaqus(python2.6)
, it goes wrong with error of OSError: exception: access violation reading 0xxxxxx
.Fortran
code for test.dll generation:
module F90Module
use,intrinsic::iso_c_binding
implicit none
contains
subroutine fun_in_fortran(arr,nucle_num,n1,n2)
!dec$ attributes dllexport,decorate,alias:"fun_in_fortran" :: fun_in_python
integer(kind=c_int),intent(in),value::n1,n2,nucle_num
integer(kind=c_int),intent(out),dimension(n1,n2)::arr
xxxxxxxxxxxxxx
end subroutine fun_in_fortran
end module F90Module
Callback in Python
(saved as t.py):
#! /usr/bin/env python
#coding=utf-8
import numpy as np
from numpy.ctypeslib import load_library,ndpointer
from ctypes import *
# shape of 2d array
n1,n2 = 10,10
n3=3
# create an empty 2d array
data = np.zeros(shape=(n1,n2),dtype='int64',order='f')
flib = load_library("test.dll","./")
flib.argtypes = [ndpointer(dtype='int64',ndim=2),c_int,c_int,c_int]
flib.fun_in_python(data.ctypes.data,n3,n1,n2)
print "*"*80
print data
PS: I checked the problem again and I got confused.. It seems like that the matter is on the runtime of Abaqus CAE
. However I really have no idea about how to fix it.
In window terminal, when I use abaqus python t.py
, it went well. But I want to do this computing procedure in Abaqus CAE
, so I tested the command abaqus cae noGui=t.py
, and the error occurs, as follows:
Abaqus License Manager checked out the following license(s):
"cae" release 6.13 from zhouhongwei
<1023 out of 1024 licenses remain available>.
WindowsError: exception: access violation reading 0X000007FF080BA0A0
File "t.py" ,line 13, in <module>
flib.rand_nucle<data.ctypes.data,n3,nl,n2>
Abaqus Error: cae exited with an error
By update Abaqus from 6.13 to 6.14, the codes works!