Discussion:
User subroutine in C++
D'Arconte, Rich
2004-03-24 16:09:06 UTC
Permalink
Will ABAQUS run with a user subroutine written in C++ rather than FORTRAN?
If so, are there any special requirements for linking or for passing data
back to ABAQUS, etc.? I have not found anything in the manuals covering
this issue. Thanks in advance.

0000
Rich D'Arconte
Assistant Principal Engineer
Aerojet
703-754-5083 (voice mail)
703-754-5638 (fax)
0000

DISCLAIMER: This email message and any attachments are for the sole use of
the intended recipient and may contain proprietary and/or confidential
information which may be privileged or otherwise protected from disclosure.
Any unauthorized review, use, disclosure or distribution is prohibited. If
you are not the intended recipient, please destroy the original message and
any copies of the message as well as any attachments to the original
message.



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/PMYolB/TM
---------------------------------------------------------------------~->
fernandocachonerin
2004-03-25 09:16:03 UTC
Permalink
Hi,
Post by D'Arconte, Rich
Will ABAQUS run with a user subroutine written in C++ rather than
FORTRAN? If so, are there any special requirements for linking or
for passing data back to ABAQUS, etc.? I have not found anything
in the manuals covering this issue.
Well the manuals say you can write your subroutine in any programming
language. BUT you need a fortran compiler (in addition to the compiler
for the language you are using) AND the knowledge to call your code
from fortran (that is, you must use a fortran subroutine as a wrapper
for your code).

The symbol export convention is compiler-specific. However, you can
find help on calling C/C++ code from fortran in the manual page of
your compiler. I know this help exists for Compaq Visual Fortran and
for the intel compiler suite. In general, unix platforms also have man
pages for this, or at least a couple of pointers in the compiler
documentation.

Also, bear in mind that fortran orders matrices column-wise, while
C/C++ ordering is row-wise. Oh, and all data are passed by reference
in fortran...

Hope this helps,

Fernando



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/PMYolB/TM
---------------------------------------------------------------------~->
fernandocachonerin
2004-03-25 10:24:18 UTC
Permalink
Post by D'Arconte, Rich
Will ABAQUS run with a user subroutine written in C++ rather than
FORTRAN? If so, are there any special requirements for linking or
for passing data back to ABAQUS, etc.? I have not found anything
in the manuals covering this issue.
Digging around a little bit more, there is an answer in the AOSS
(ABAQUS Online Support System) that responds this question in detail.
It is answer #737: "Is it possible to write user subroutines for
ABAQUS/Standard in C++?". There you will find detailed information on
how to do this including sample C++ subroutine (VISCO), inputdecks and
instruction on how to run the code on different platforms. The answer
is meant for 'Customer w/o Support' that means that every ABAQUS
customer (commercial, non-commercial, academic) can access it,
provided you have an account. If you don't have an account, yet, you
should sign in (it's for free).


Regards,

Fernando
barryodonnell2003
2004-03-25 07:11:02 UTC
Permalink
Attached is previous abaqus response to this query:


Question
Is it possible to write user subroutines for ABAQUS/Standard in C++?


Answer
(The following applies to versions 6.3-1 and higher.)

It is possible to write user subroutines for ABAQUS/Standard in C++,
but it is generally recommended that user subroutines be written in
Fortran. The interface for each of the user subroutines in
ABAQUS/Standard is in Fortran, and the use of another programming
language adds an additional layer of complexity to the programming
task.

The procedure for calling a C++ function from a Fortran application
is machine dependent, and requires an expert knowledge of compilers
and operating system conventions. Among the items that must be
understood are:


Mapping external C++ names to external Fortran names
Mapping C++ data types to Fortran data types
Conventions for inter-language procedure calls
In the example outlined below, a simple user subroutine in C++ will
be used in an ABAQUS/Standard analysis. To avoid platform
dependencies, certain macros in the C++ subroutine have been defined.
A function to transfer character arrays between Fortran and C++ has
also been defined. Please note that this approach is not supported-
ABAQUS, Inc will not provide technical support for this approach and
associated bugs, if any, will not necessarily be fixed.

To illustrate this procedure we provide a variation of the analysis
in Section 2.2.7 of the Version 6.3 ABAQUS Verification
Manual, "Transient internal pressure loading of a viscoelastic
cylinder." The files visco_dload.inp, viscocylinder.for and visco.C
are attached to this answer and available for download.

To run the analysis with the C++ subroutine, complete the following
steps:

Obtain the C++ compile command used by ABAQUS. On the command line
type:

abaqus info=env > env.txt

In the file env.txt look for the string 'compile_cpp'. Some examples
of the output on different platforms include:

Windows

compile_cpp='cl /c /nologo /W0 /MD /TP /DNDEBUG
/DWIN32 /DTP_IP /D_CONSOLE /DNTI /DFLT_LIC /DOL_DOC /D__LIB__ /DHKS_NT

/DFAR= /D_WINDOWS /O1 /I%I'
IBM AIX

compile_cpp='xlC -c -qsrcmsg -q64 -qarch=pwr3 -qtune=pwr3 -DRS6000 -
DCPLUS_IMPLEMENTED -D_LARGE_FILES -D_LARGE_FILES_API -DHAS_INT64 -
DBIT64 -DMULTI_THREADING_ENABLED -DTHREADED_SOLVER -DIBM -
DSPIN_YIELD -O3 -qstrict'
SGI

compile_cpp='CC -mips4 -64 -avoid_gp_overflow -c -DORIGIN2000 -
DSGI8000 -DSGI -DBIT64 -DFOR_TRAIL -DCPLUS_IMPLEMENTED -DNATIVE64 -
TARG:processor=r10000 -O3 -TENV:X=0 -I%I'
HP

compile_cpp='aCC +DA2.0W +DS2.0a -c -DHP -DHP11 -DFOR_TRAIL -
DCPLUS_IMPLEMENTED -DSWAPPED -ext -DBIT64 +O2 +Olibcalls -I%I'
Compaq

compile_cpp='cxx -c -std arm +inst_none -nopt -
distinguish_nested_enums -nodemangle -assume noaligned_objects -DDEC -
DHKS_DEC -DFOR_TRAIL -DDEC_ALPHA -DHKS_OPEN_GL -DCPLUS_IMPLEMENTED -
D_OSF_SOURCE -I/usr/include/X11R6 -I/opt/graphics/OpenGL/include -
DTYPENAME= -D_POSIX_SOURCE -D_XOPEN_SOURCE -DSPECIALIZE -I%I'
Compile the C++ user subroutine with the command found in Step 1.


Run the analysis with the C++ object file.

Windows

abaqus -j visco_dload -user visco.obj
UNIX

abaqus -j visco_dload -user visco.o
On certain UNIX platforms you will need to specify the correct flag
to link in the C++ libraries. First, obtain the applicable link
command used by ABAQUS by typing:


abaqus info=env | grep link_sl
Modify the commands as follows, with the new flag shown in red:

IBM AIX

link_sl='xlf_r -q64 -bM:SRE -bE:export.def -bnolibpath -bnoentry -o %
U %F %A %B -lxlsmp -lxlf -lxlf90 -lm -lC'
Compaq

link_sl='cxx -shared -Wl,-error_unresolved -Wl,-soname,%U -o %U %F -
Wl,-input,%E %A %B -lUfor -lfor -lm -lc'
The modification must be made to the link_sl command shown in your
environment file.


For additional information see:


'User Subroutines,' Section 24.1.1 of the Version 6.3 ABAQUS/Standard
User's Manual
Post by D'Arconte, Rich
Will ABAQUS run with a user subroutine written in C++ rather than FORTRAN?
If so, are there any special requirements for linking or for
passing data
Post by D'Arconte, Rich
back to ABAQUS, etc.? I have not found anything in the manuals covering
this issue. Thanks in advance.
0000
Rich D'Arconte
Assistant Principal Engineer
Aerojet
703-754-5083 (voice mail)
703-754-5638 (fax)
0000
DISCLAIMER: This email message and any attachments are for the sole use of
the intended recipient and may contain proprietary and/or
confidential
Post by D'Arconte, Rich
information which may be privileged or otherwise protected from disclosure.
Any unauthorized review, use, disclosure or distribution is
prohibited. If
Post by D'Arconte, Rich
you are not the intended recipient, please destroy the original message and
any copies of the message as well as any attachments to the original
message.
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/PMYolB/TM
---------------------------------------------------------------------~->
Jose Felix Rodriguez
2004-03-25 14:48:32 UTC
Permalink
Dear Rich,

You can use C subroutines in abaqus, but you have to create
a library with your C subroutines to link with the Abaqus subroutines.
The following steps I am about to describe, have been tested in Abaqus 6.4.1
under linux, even though some commands might change slightly under other
platforms, the procedure is exactly the same. First some things
to point out about Fortran and C:

i) In Fortran, all arguments are passed by reference, so your C
subroutine should received pointers to the variables.
ii) two dimensional arrays in fortran are passed by columns and not
by files as in C.

Now, let's go to the details:

1) Your C subroutine must be declare as follows in order to allow
the fortran calling

extern "C" myfunction_ (int *A, double *B)

NOTE: Please, do not forget the "_" otherwise you will be in troubles,
and name the routine in lowercase.

2) To call this function from fortran

CALL MYFUNCTION (A,B)

where A and B have been declared as:
integer A
real*8 B

3) To create the library, you follow two steps, first compile your subroutine,
then create the library. To compile the subroutine, go to your abaqus_v6.env
and copy the lines regarding the C compilation instructions. For linux they
are:

icpc -c -Kpic -DHKS_LINUX -DLINUX -DFOR_TRAIL \
-DHAS_BOOL -DEMULATE_EXCEPTIONS=0 -DASSERT_ENABLED \
-D_BSD_TYPES -D_BSD_SOURCE -D_GNU_SOURCE -D_POSIX_SOURCE \
-D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE \
-DHAVE_OPENGL -DHKS_OPEN_GL \
-DGL_GLEXT_PROTOTYPES -DTYPENAME= \
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \
-w -fpic -include iosfwd -O0 -I%I <myprogram>.c

The last term corresponds to your C program. Once you get the .o, create
a library as

ar rv -o libuser.a *.o
ranlib libsuer.a

I have named the library as libuser.a, you can use any other name, but make
sure it starts with "lib".

4) Now you have the library created. The last step is to modify your
abaqus_v6.env to
provide the required instructions to link this library. For linux it looks like

link_sl = ("ifc -Kpic -xK -axW -i_dynamic -export-dynamic -shared %E " +
"-Xlinker -soname %U -o %U %F %A %B -Wl,-Bdynamic " +
"-lintrins -limf -lF90 -lIEPCF90 -lPEPCF90 -lPOSF90 -lCEPCF90 " +
"-L/path/to/your/directory -luser"

link_exe = ("icpc -i_dynamic -Kpic -xK -axW -Xlinker -noinhibit-exec " +
"-o %J %F %M %L %B %O -lintrins -limf" +
"-lF90 -lIEPCF90 -lPEPCF90 -lPOSF90 -lCEPCF90 -fpic" +
"-L/path/to/your/directory -luser"

The last line in the link_sl and link_exe tells the compiler to look for
libraries in your local directory and to link the library libuser.a (note that
lib has been substituted by l)

5) Execute abaqus as: abaqus job=myjob user=myuser

myuser.f contains your user subroutines which make a call to the C subroutine.

I hope this helps. I think I have not forgotten any thing, if so, please
let me know

Take care and good luck

jose


José F. Rodríguez
Investigador Ramón y Cajal
Area de Mecánica de Medios Continuos y Teoría de Estructuras
Departamento de Ingeniería Mecánica
Centro Politécnico Superior. Universidad de Zaragoza
C/ María de Luna 3, Ed. Agustín de Betancourt
50018 Zaragoza
Tel: 976.761000 ext.5230 / Fax: 976.762578
e-mail: ***@unizar.es

Loading...