- #1
member 428835
Hi PF!
I'm trying to edit two lines from files in different directories, U and controlDict. I want to change the lines with numbers from two other .dat files, VEL.dat (vector of numbers) and VEL_t.dat (single scalar number). Below is my attempt, but I know at least two things that are wrong.
1) in line 28, I use length(VEL) to signify the length of the row number from the VEL.dat file. This is incorrect, but I can't figure out how to do it.
2) the RHS of line 34 should paste "endTime NUMBER" where "NUMBER" is a real number. Example: if VEL_t is a .dat file with lone entry 12 and j = 2, then line 26 in the controlDict file should be replaced with "endTime 24".
Really appreciate any help you have to offer. I've googled as much as I can to get this far (and with the help of some members here too!).
I'm trying to edit two lines from files in different directories, U and controlDict. I want to change the lines with numbers from two other .dat files, VEL.dat (vector of numbers) and VEL_t.dat (single scalar number). Below is my attempt, but I know at least two things that are wrong.
Python:
# LOAD FILES TO WORK WITH
filenameVEL = "/home/josh/Documents/NASA/PSI_DATA/Double_Drain/ICF1-9/VEL.dat"
filenameVEL_t = "/home/josh/Documents/NASA/PSI_DATA/Double_Drain/ICF1-9/VEL_t.dat"
filenameU = "./0/U"
filenameCD = "./system/controlDict"
# Read filenameVEL
fileVEL = open(filenameVEL,'r')
linesVEL = fileVEL.readlines()
fileVEL.close
# Read filenameVEL_t
fileVEL_t = open(filenameVEL_t,'r')
linesVEL_t = fileVEL_t.readlines()
fileVEL_t.close
# Read filenameU
fileU = open(filenameU,'r')
linesU = fileU.readlines()
fileU.close
# Read filenameCD
fileCD = open(filenameCD,'r')
linesCD = fileCD.readlines()
fileCD.close
# CHANGE LINES OF BOTH FILES
for j in range(0,length(VEL):
# Replace line 33 in U with RHS of equation below
linesU[33] = sample line here linesVEL[j]
# Replace line 26 in controlDict with RHS of equation below
linesCD[26] = endTime j*linesVEL_t[1]
os.system("mpirun -np 16 interFoam -parallel") # RUN interFoam IN PARALLEL
1) in line 28, I use length(VEL) to signify the length of the row number from the VEL.dat file. This is incorrect, but I can't figure out how to do it.
2) the RHS of line 34 should paste "endTime NUMBER" where "NUMBER" is a real number. Example: if VEL_t is a .dat file with lone entry 12 and j = 2, then line 26 in the controlDict file should be replaced with "endTime 24".
Really appreciate any help you have to offer. I've googled as much as I can to get this far (and with the help of some members here too!).