Python Forum
Help with a CFD script development
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a CFD script development
#1
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
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)
#and this is the executable
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020