Hi
I have received a large .txt file containing imposed displacements for nodes. The .txt file is formed as a matrix.
I would like to import each single row of this .txt file and run a load case inside a loop with the given displacements, but as far as I know, this is not possible in SoFiSTiK?
Instead I’m trying to use the Python API in order to get the same effect. But I’m not quite sure how to implement the python file into SoFiSTiK as it seems to require a separate process which prevents using it inside a loop as loops can’t run across several processes.
I have made a small sample file to show my idea:
SoFiSTiK file:
+PROG template
head Create initial data file
<TEXT,FILE=Initial_Matrix.txt>
35,64,85,48
12,53,84,1
10,55,99,2
</TEXT>
END
+PROG template
head Create looping integer to run through matrix in Python
loop#i 3
<TEXT,FILE=loop.txt>
#i
</TEXT>
$ PYTHON FILE SHOULD GO HERE
$+sys python Python_File.py
$#INCLUDE Python_output.dat
$prt#list
endloop
END
Python file:
import csv
# Open File containing loop integer
f = open("loop.txt", 'r')
nums = f.readlines()
nums = int(nums[0])
# Open file containing imposed displacements
with open('Initial_Matrix.txt') as csv_file:
reader = csv.reader(csv_file, delimiter=',')
rows = list(reader)
data = rows[nums]
# Write file with SoFiSTiK syntax
with open('Python_Output.dat', mode='w') as f:
print('let#List ',",".join(data), file=f, sep='')
The general idea is that SoFiSTiK creates a text file containing a looping integer which is imported into Python which then extract the given row from Initial_Matrix.txt based on that integer and spits out a new text file with proper SoFiSTiK syntax which is the #INCLUDE back into SoFiSTiK.
This way I can apply the imposed displacement inside a loop and don’t have to store a separate variable for each matrix row and in turn manually apply a said variable for several load cases.
Is this the way to go, or is there a simpler method?