2

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:

  1. Do a Modal analysis in Abaqus;
  2. GUI plugin get the above results from modalResult.odb and transfer them into a custom computing module which is written in Fortran;
  3. GUI plugin transfer the computed results into another Abaqus odb;

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:

  1. 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.
  2. 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
hwzhou
  • 31
  • 4
  • Welcome, be sure to take the [tour]. Unfortunately the main question is very broad. I suggest to make a specific question about your current approach, but for that you need to tell us what is wrong with it. Any errors? Which ones? Wrong results? Which ones? Why are they wrong? – Vladimir F Героям слава May 07 '18 at 15:14
  • is `c_int` a 64 bit integer? If not, then there is a discrepancy between the fortran and python functions. – ptb May 07 '18 at 17:54
  • @VladimirF, Thanks . I check it again today, sorry for cellphone pothograph cause I cannot acess Intenet at my office. _t3.py_ and the _interface_ in _test.dll_ is just the same as above.I'm confuse that goes well in `abaqus python`, but when I run it in `abaqus cae` the error I mentioned before occurs, whenas callback the _runtime in dll_ , as [Error in Abaqus](http://i38.photobucket.com/albums/e138/hwzhou/1_zpsst1xzbr2.jpg). – hwzhou May 08 '18 at 01:34
  • @ptb, Thanks. I've realize this problem. If `int64` used in `python` the discrepancy does exist. But in this situation, only wrong results would be got, not the `access violation` error as I mentioned before. – hwzhou May 08 '18 at 01:39
  • @VladimirF, I found that there are so many ads on the website where I shared my picture, so that I reupload it to _Flickr_, please check it as [AbaqusError](https://flic.kr/p/25QK4nL). – hwzhou May 08 '18 at 01:57
  • Do NOT use pictures. Copy the **TEXT** here. If you don't know how to copy text from Windows terminal, just search on the internet for something like https://stackoverflow.com/questions/11543578/copy-text-from-a-windows-cmd-window-to-clipboard Put the error into the question using an [edit]. – Vladimir F Героям слава May 08 '18 at 09:07
  • 1
    Have you tested this independently of abaqus? That would help isolate the problem – ptb May 08 '18 at 15:32

1 Answers1

0

By update Abaqus from 6.13 to 6.14, the codes works!

hwzhou
  • 31
  • 4