Is it possible to access the python console from the non gui version of flac

Hi,

I use the non-gui version of flac3d with the executable fla3d_console on a linux server that does not have a gui interface.
I wanted to know if there was a way to access the python console in this version of FLAC3D. I went through the documentation but I couldn’t find anything.

Right now my option is to write the python code in a file and execute with program call “myscript.py” but it is a little impractical.

Thanks in advance!

You can issue python commands in the flac3d command line by starting the line with “python …”, so e.g. python import numpy.

1 Like

Where is the resource of this command? I cannot find this command in manual.

Hi,

I never could found the command in the documentation, this is why I asked this question in the first place.

I can explain you how it works:

  • type python and then any one line valid python command that would work in a python REPL/shell will work. my understanding is that flac passes the python command to the active python instance. This has a few implications:

    • You can construct consistent scripts by chaining one liners as long as they are a single line command each prefaced by the python command. For example here a a valid script:
      • [A = 1]
      • python import itasca as it
      • python a= 1
      • python a += it.fish.get(“A”)
      • python print(f"sum is equal to: {a}"
    • Conversely, this is not a valid python script because you are not using one liners:
      • python for i in range(0, 1):
      • python print(i)
    • The solution is to wrap the loop into a function define in a python file that is then either loaded with the import function or a program call command.
    • for the persistence of the global python state it follows the rules of python in which python is unaffected by the model new, restore unlike fish variables, but is also not saved ( Python Scripting — Itasca Software 9.6 documentation )
  • There are a few annoying limitations:

    • “;” cannot be used anywhere, even inside a string as it is understood by FLAC as the comment separator → everything after the semi-column is a comment.
    • because it understand python as single lines you cannot construct multiple lines indented to make you python more readable.
    • It can be tricky to save python objects/class if the object contains constructions that are not the base ones or numpy ones. A workaround is to use setstate() and getstate() function to serialize the class as a dict and deserialize it back into a class.