Hello, I am new to programming and especially new to python. I have been self-learning and I managed to write a script for a CFD code and it works fine. I later wanted to include an area for the pipe and have the inlet area different than the outlet area. I included logic in my main script that if there is an area for a port(inlet) it will be true and the same goes for the outlet.
I later use an executable script to call the main program and add the values of the area in the executable.
here is part of my script where the error and the area is included
#this is the main program
#and this is the executable
I later use an executable script to call the main program and add the values of the area in the executable.
here is part of my script where the error and the area is included
#this is the main program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import numpy as np import sys uCounter = 0 class Pipe( object ): global uCounter def __init__( self , nPorts, volume): self .volume = volume self .rhoj = D( 1 ) self .Pj = D( 1 ) self .nPorts = nPorts self .freePorts = [] self .portSetm = [] self .portSetP = [] self .portSetValue = [] self .portSetAreas = [] self .portSetAreasValue = [] for i in range (nPorts): self .freePorts.append(i) self .portSetm.append( False ) self .portSetP.append( False ) self .portSetValue.append( 0.0 ) self .portSetAreas.append( False ) self .portSetAreasValue.append( 0.0 ) self .m = D( self .nPorts) self .P = D( self .nPorts) self .Areas = D( self .nPorts) self .pd = np.zeros(( self .nPorts)) self .dt = 0.0 def logics( self , freePorts): for port in range ( self .nPorts): if self .portSetAreas[ self .freePorts[port]] ! = 0 : self .Areas[port] = self .portSetAreasValue[ self .freePorts[port]] def Values1( self ): equation = Equation( 1 , uCounter) for p in range ( self .nPorts): equation.A[ 0 , self .m.gid[p]] = self .Areas[p] equation.c[ 0 ] = 0.0 return (equation) |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import math import numpy as np import sys import scipy.io import mainproject Pipe1.portSetAreas[ 0 ] = True Pipe1.portSetAreasValue[ 0 ] = 0.1 Pipe1.portSetAreas[ 1 ] = True Pipe1.portSetAreasValue[ 1 ] = 0.1 #0 refers to the inlet of the pipe #1 refers to the outlet of the pipe |