# This python codes reads a file and search for an specified keywords. Based on # the line number of the line containing that keyword, it moves few lines back # ward or forward to seach for another keywords and then prints the entire line # containing that keyword. Get Line Number of certain phrase in file Python -> # Add a counter to the line number ->Move the position of a file pointer by # specified number of line import sys, os import numpy as np #Get input file datFile = 'report.sum' def checkShadow(datFile): #This check is applicable and valid for cases where ENERGY is turned ON line_num = O #Set counter for shadow walls not coupled j = 0 #Number of lines to move forward from line containing identified keyword #Reduce this number to 3 in case only one solid material defined line_jump = 4 #Keywords wallNames = "shadow" #Open input files and store lines as 'LIST' fi = open(datFile, "r") line_list = fi.readlines () fi.close() nLines = len(line_list) - line_jump #Output file to store summary of all shadow walls fo = open("summaryShadow. txt", "w") #Output file to store shadow walls which are not coupled fe = open("sumShadowNotCoupled.txt", "w") with open(datFile) as fi: while line := fi.readline(): line_num = line_num + 1 if (wal11Names in line) and ('wall' not in line): strg = line.rstrip() + " at line -> " + str(line_num) fo.write(strg) #Ensure that line number is always positve if (line_num > line_jump) and (line_num < nLines): lineText = line_list[line_num + line_jump].rstrip() fo.write(lineText) fo.write("\n--------------------------------\n") if ('Coupled' not in lineText ): j = j + 1 fe.write(lineText) fe.write("\n--------------------------\n") errText = "Number of wall zones not coupled: ", str(j) fe.write (errText) fo.close() fe.close() def solidZoneMat(datFile): #This check is applicable and valid for cases where ENERGY is turned ON line_num = 0 #Number of lines to move forward from the line containing identified keyword #Reduce this number to 3 in case only one solid material defined though #one do not need to run this function if there is only one solid material line_jump = 4 #Open input files and store lines as 'LIST' fi = open (datFile, "r") line_list = fi.readlines() fi.close() #Output TXT file to store zone name and material name fo = open("summarySolidZones.txt", "w") with open(datFile) as fi: while line := fi.readline(): if ("Material Name" in line): #Ensure that line number is always positve nextLine = line_list [line_num + 1] if (line_num > line_jump) and "BC Type" not in nextLine: txt = line_list[line_num - line_jump].rstrip() txt = txt + ">>" + line_list[line_num].rstrip() + '\n' fo.write(txt) line_num = line_num + 1 fo.close() def checkAdiabatic(datFile): #This check is applicable and valid for cases where ENERGY is turned ON line_num = 0 #Number of lines to move forward from the line containing identified keyword line_jump = 6 #Open input files and store lines as 'LIST' fi = open(datFile, "r") line_list = fi.readlines () fi.close() #Output file to store summary of all walls with Heat Flux B.C. fo = open("summaryHeatFlux.txt", "w") with open(datFile) as fi: while line := fi.readline(): line_num = line_num + 1 if ("Heat Flux" in line): strg = line.rstrip() #Ensure that line number is always positive if (line_num > line_jump): lineText = line_list[line_num - line_jump].rstrip() txt = lineText + strg fo.write(txt) fo.write("\n--------------------------------\n") fo.close() def checkConvective(datFile): #This check is applicable and valid for cases where ENERGY is turned ON line_num = 0 #Number of lines to move forward from the line containing identified keyword #Change this value to 5 in case only one solid material is defined line_jump = 6 #Open input files and store lines as 'LIST' fi = open(datFile, "r") line_list = fi.readlines () fi.close() #Output file to store summary of all walls with Heat Flux B.C. fo = open("summaryConvectiveBC.txt", "w") with open(datFile) as fi: while line := fi.readline(): line_num = line_num + 1 if ("Convection" in line): strg = line.rstrip() #Ensure that line number is always positive if (line_num > line_jump): lineText = line_list[line_num - line_jump].rstrip() txt = lineText + strg fo.write(txt) fo.write("\n--------------------------------\n") j = j + 1 fo.close() print("Number of wall zones with convective boundary: ", str(j)) def checkTemperature(datFile): #This check is applicable and valid for cases where ENERGY is turned ON line_num = 0 #Number of lines to move forward from the line containing identified keyword #Change this value to 5 in case only one solid material is defined line_jump = 6 #Open input files and store lines as 'LIST' fi = open(datFile, "r") line_list = fi.readlines () fi.close() #Output file to store summary of all walls with Heat Flux B.C. fo = open("summaryFixedTemp.txt", "w") with open(datFile) as fi: while line := fi.readline(): line_num = line_num + 1 if ("Thermal" in line and "Temperature" in line): strg = line.rstrip() #Ensure that line number is always positive if (line_num > line_jump): lineText = line_list[line_num - line_jump].rstrip() txt = lineText + strg fo.write(txt) fo.write("\n--------------------------------\n") j = j + 1 fo.close() print("Number of wall zones with fixed temperature boundary: ", str(j)) checkShadow(datFile) checkTemperature(datFile) checkConvective(datFile) checkAdiabatic(datFile) solidZoneMat(datFile)