Python Forum
variable call back into an array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable call back into an array
#1
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
Error:
equation.A[0,self.m.gid[p]] = self.Areas TypeError: float() argument must be a string or a number
Reply
#2
You should debug your code.
Then you will see that the argument
is neither a string nor a number.
Probably it will be "None".
Reply
#3
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.
Reply
#4
Sorry, I can not help, your code is too complex.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling for the past hour to define function and call it back godlyredwall 2 2,157 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  Simple automated SoapAPI Call with single variable replacement from csv asaxty 1 2,056 Jun-30-2020, 06:38 PM
Last Post: asaxty
  np array tolist and back anthares 2 1,944 Jun-13-2020, 06:58 AM
Last Post: anthares
  Call a variable jmf08 16 5,768 Jan-18-2019, 05:50 AM
Last Post: jmf08
  call a variable from one function to another ... evilcode1 4 3,955 Sep-16-2018, 10:50 AM
Last Post: gruntfutuk
  Spyder hides middle array values in variable explorer window davidqvist 0 2,366 Aug-03-2018, 11:04 AM
Last Post: davidqvist
  How to call a variable declared in a function in another python script lravikumarvsp 2 2,891 Jun-04-2018, 08:45 AM
Last Post: Larz60+
  2D Array/List OR using variables in other variable names? IAMK 4 3,796 Apr-16-2018, 09:09 PM
Last Post: IAMK

Forum Jump:

User Panel Messages

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