jfriedlein / usrmat_LS-Dyna_Fortran

Basics to implement user-defined materials (usrmat, umat) in LS-Dyna with Fortran
52 stars 28 forks source link

Compiling error due to preprocessor definition on Linux #5

Closed Wabbaaa closed 3 years ago

Wabbaaa commented 3 years ago

Hello @jfriedlein ,

Thanks a lot for the repository, I am trying to make LS-Dyna work with an user-defined material without knowing much about fortran and programming in general, and this is helping me a lot!

I am trying to run your first example on Linux and I think there is an issue with the first two lines:

#define NOR4
#include 'ttb/ttb_library.F'

The object files I've downloaded contain all the files with extension ".f", not ".F", so the file to modify is named "dyn21umats.f". When I use "make" to compile, I get the following errors:

dyn21umats.f(2): warning #5117: Bad # preprocessor line
#define NOR4
-^
dyn21umats.f(3): warning #5117: Bad # preprocessor line
#include 'ttb/ttb_library.F'
-^
dyn21umats.f(302): error #6353: A RETURN statement is invalid in the main program.
      return
------^
compilation aborted for dyn21umats.f (code 1)
make: *** [dyn21umats.o] Error 1

First thing I've tried is to change the extension to "dyn21umats.F". I've only changed the name of this file, not the others, is it correct?

I've also changed the makefile; the only thing I've changed is the extension of that single file from:

dyn21umats.o: dyn21umats.f nhisparm.inc userinterface.o
    $(FC) -c $(FF) -I. dyn21umats.f

to:

dyn21umats.o: dyn21umats.F nhisparm.inc userinterface.o
    $(FC) -c $(FF) -I. dyn21umats.F

But when I try to compile I get the following errors:

dyn21umats.F(1): error #5149: Illegal character in statement label field  [▒]
c Compiler flags and include for the tensor toolbox
^
dyn21umats.F(1): error #5149: Illegal character in statement label field  [▒]
c Compiler flags and include for the tensor toolbox
-^
dyn21umats.F(1): error #5149: Illegal character in statement label field  [▒]
c Compiler flags and include for the tensor toolbox
--^
dyn21umats.F(1): error #5149: Illegal character in statement label field  [c]
c Compiler flags and include for the tensor toolbox
---^
dyn21umats.F(1): error #5118: First statement in file must not be continued
c Compiler flags and include for the tensor toolbox
-----^
dyn21umats.F(1): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: => = . [ % ( :
c Compiler flags and include for the tensor toolbox
------------------------------------------------------^
./ttb/ttb_library.F(2): error #6218: This statement is positioned incorrectly and/or has syntax errors.
       module Tensor
-------^
./ttb/libtools.f(1): error #8095: The name of the internal procedure conflicts with a procedure name in the MODULE PROCEDURE statement.   [FACT_I]
       function fact_i(n)
----------------^
./ttb/libadd.f(1): error #8095: The name of the internal procedure conflicts with a procedure name in the MODULE PROCEDURE statement.   [ADD_11]
       function add_11(T1, T2)
----------------^
./ttb/libadd.f(11): error #8095: The name of the internal procedure conflicts with a procedure name in the MODULE PROCEDURE statement.   [ADD_22]
       function add_22(T1, T2)
----------------^
./ttb/libadd.f(21): error #8095: The name of the internal procedure conflicts with a procedure name in the MODULE PROCEDURE statement.   [ADD_2S2S]
       function add_2s2s(T1, T2)
----------------^
./ttb/libadd.f(31): error #8095: The name of the internal procedure conflicts with a procedure name in the MODULE PROCEDURE statement.   [ADD_22S]
       function add_22s(T1, T2)
----------------^
./ttb/libadd.f(42): error #8095: The name of the internal procedure conflicts with a procedure name in the MODULE PROCEDURE statement.   [ADD_2S2]
       function add_2s2(T1, T2)

Can you help me?

Thanks in advance.

jfriedlein commented 3 years ago

Hi @Wabbaaa,

Thank you a lot! You're welcome.

In case, the problem is related to the toolbox, I would refer you to Andreas @adtzlr (https://github.com/adtzlr/ttb), he is the pro on this. I just initiated the extension to LS-Dyna (https://github.com/adtzlr/ttb/issues/10), which introduced the "#define NOR4" line. Nevertheless, I'll try to help you, also because meanwhile Andreas has other priorities.

Okay, enough background information. In the LS-Dyna object version that I downloaded all Fortran extensions are already ".F", besides the "dynrfn_user.f". Maybe that is something Linux and Fortran compiler related, which Fortran compiler do you use by the way? I guess, you successfully checked steps 1-8 in "Test setup and compiler", so we know that the compiler and the object version are fine.

My best guess right now is that your compiler cannot handle compiler flags. I'm not into that at all, so I would propose the following bold workaround: When you check the previous ttb version you notice that we did not have this preprocessor flag, also used 'include ...' instead of '#include ...' and lower case file extensions. The problem with this version was that the R4 function variants were not accepted by my compiler together with LS-Dyna. So, the workaround would be similar to mine back then by simply removing all the R4 variants manually, see https://github.com/adtzlr/ttb/issues/10, if you then get the same error "Ambiguous generic interface": Just be aware that there have been some minor updates of the toolbox since the previous version (see the open and closed issues here https://github.com/adtzlr/ttb/issues). From https://github.com/adtzlr/ttb/issues/10: "By simply deleting all the module procedure *r4 in ttb_library.f all errors disappear and we can use the toolbox (of course without the r4 variants). Is this because this fortran version cannot yet distinguish between data type-"templated" functions?"

Hopefully that already helps you, in case it does not, we just continue the troubleshooting. It would at least rule out a few things.

Best regards, Johannes

Wabbaaa commented 3 years ago

Hi @jfriedlein,

Thanks a lot for your detailed reply, it's really appreciated.

The Fortran version I use is Intel Fortran 16.0.8. I don't know why, I've reinstalled and setup everything from scratch and now it seems to work fine. I don't know what to say, I remember following the same steps from your guide.

I'll try to follow your suggestions in case I incur in the same issue again, many thanks!

Kind regards, Raffaele

jfriedlein commented 3 years ago

Hi Raffaele @Wabbaaa,

A pleasure. Good to hear that you solved the problem. It's also interesting to see that LS-Dyna compiles with Fortran 16. Typically the object versions are very picky with regard to the environment and compiler, but maybe that occurs mainly under Windows and concerning the older releases, I don't know.

Best regards, Johannes