![]() |
variable call back into an array - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: variable call back into an array (/thread-18924.html) |
variable call back into an array - yamifm0f - Jun-06-2019 Hello I would like to get the value of each port area in a pipe in one array. I have developed an array class called Equation where equation.A is an array and equation.c is a vector I want to assign the value for each area in a different script and then add it to the main program in the array. so far I have no luck in getting this to work. any help or advice will be appreciated. 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.nPorts = nPorts self.freePorts = [] #The ports of the pipe that are not in use self.portSetAreas = [] self.portSetAreasValue = [] for i in range(nPorts): self.freePorts.append(i) self.portSetAreas.append(False) self.portSetAreasValue.append(0.0) self.Areas = D(self.nPorts) # where D refers to the domain and how many ports it contain self.pd = np.zeros((self.nPorts)) self.dt = 0.0 def logics(self): nFree = len(self.freePorts) for port in range(nFree): if self.portSetAreas[self.freePorts[port]]: self.Areas = self.portSetAreasValue[self.freePorts[port]] def Values1(self): equation = Equation(1, uCounter) #where Equation is an array class for p in range(self.nPorts): #nPorts is the number of ports with an area equation.A[0, self.m.gid[p]] = self.Areas[p] #the multible values of the Area will be put into an array equation.A equation.c[0] = 0.0 #This is a vector return(equation) #the problem is with self.Areas[p] this multible values will be called form anoth script "test1"This is the test1 script 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 refer to the inlet of the pipe #1 refer to the outlet of the pipe
RE: variable call back into an array - heiner55 - Jun-07-2019 You should debug your code. Then you will see that the argument is neither a string nor a number. Probably it will be "None". RE: variable call back into an array - yamifm0f - Jun-07-2019 What I need is to know how to put a condition for the value of Areas so if there is an Area at port 0 the value will be 0.1 if there is an Area at port 1 the value will be 0.2 I need this to be here def Values1(self): equation = Equation(1, uCounter) #where Equation is an array class for p in range(self.nPorts): #nPorts is the number of ports with an area equation.A[0, self.m.gid[p]] = self.Areas[p] #the multible values of the Area will be put into an array equation.A equation.c[0] = 0.0 #This is a vector return(equation)in the self.Areas[p] if I can do this my problem will be resolved. RE: variable call back into an array - heiner55 - Jun-07-2019 Sorry, I can not help, your code is too complex. |