def testBuildConstantFunction2(self): f = Function.ConstantFunction(-2) self.assertAlmostEqual(f(-1, -1), -2, 9) self.assertAlmostEqual(f(0, 0), -2, 9) self.assertAlmostEqual(f(1, 2), -2, 9) self.assertEqual(str(f), "-2.0")
def testBuildConstantFunction1(self): f = Function.ConstantFunction(1) self.assertAlmostEqual(f(-1, -1), 1, 9) self.assertAlmostEqual(f(0, 0), 1, 9) self.assertAlmostEqual(f(1, 2), 1, 9) self.assertEqual(str(f), "1.0")
def computeProductionVector(z, slopeFunctions, parameters): #Return value P = scipy.sparse.lil_matrix((parameters.n, 1)) #Functions beta = Function.FunctionWrapper(parameters.productionEffciency, "B") rho = Function.ConstantFunction(parameters.productionThreshold) #For each element for element in parameters.omegaThree: #Build a sum of non-zero functions on this element sum = Function.ConstantFunction(0) for i in range(0, 3): #Get the point xi = element.points[i] #The coefficient zl = z[xi.index, 0] #The shape function slopeL = slopeFunctions[element.index][i] zFunction = Function.ConstantFunction(zl) slopeLWrapper = Function.FunctionWrapper(slopeL.evaluate, str(slopeL)) sumElement = zFunction * slopeLWrapper sum = sum + sumElement #Build a 'B(x)(rho - sum)+' term g = beta * Function.PositivePartFunction(rho - sum) #Integrate for i in range(0, 3): xi = element.points[i] slopeK = slopeFunctions[element.index][i] slopeKWrapper = Function.FunctionWrapper(slopeK.evaluate, str(slopeK)) h = g * slopeKWrapper I = Integrator.integrate2D(h, element) P[xi.index, 0] += I return P.tocsc()