Skip to content

Commit

Permalink
Implemented Contours ADT Module in GlassBR as per issue #134
Browse files Browse the repository at this point in the history
  • Loading branch information
elwazana committed Jul 27, 2018
1 parent ca4f3d7 commit f42a19e
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions CaseStudies/glass/src/Python/NewImplementation/ContoursADT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## @file ContoursADT.py
# @brief Implements an ADT for a contour
# @date 07/26/2018

from Exceptions import *
from FunctADT import FuncT

class ContoursT :

# exported constants
MAX_ORDER = 2

def __init__ ( self, i ):

if (not(i in list(range(1, self.MAX_ORDER + 1)))):
raise InvalidInterpOrder("Invalid interpretation error!")

# state variables
self.S = []
self.Z = []
self.o = i

## @brief Appends elements to state variable sequences
def add( self, s, z):
if ((len(self.Z)) > 0) and (z <= self.Z[len(self.Z) - 1]):
raise IndepVarNotAscending("Independent variables not in ascending order!")
self.S = self.S.append(s)
self.Z = self.Z.append(z)

## @brief Gets the ith element from the sequence S
# @return the ith element from S
def getC( self, i):
if (not(0 <= i <= len(self.S))):
raise InvalidIndex("Index out of range")
return self.S[i]

## @brief Evaluates the FuncT class with respect to input z
# @return the calculated FuncT class based on z
def eval( self, x, z):
return (self.slice(x,False).eval(z))

## @brief Evaluates the FuncT class with respect to input y
# @return the calculated FuncT class based on y
def evaly( self, x, y):
return (self.slice(x,True).eval(y))

## @brief Generates a FuncT class using the state variable sequences
# @return the generated FuncT class
def slice( self, c, flip):
Zdef = []
F = []
for i in range(0,(len(self.S)) - 1):
try:
y = self.S[i].eval(x)
Zdef.append(self.Z[i])
F.append(y)
except OutOfDomain:
pass
if (len(Zdef)) > 0:
if flip:
return FuncT(F, Zdef, o)
else:
return FuncT(Zdef, F, o)
else:
raise OutOfDomain("Out of domain!")

0 comments on commit f42a19e

Please sign in to comment.