def test1dsplineeval_singlepoint(self):
     out = eval.evalMultivarSpline(self.spline, (240, ))
     self.assertEqual(1, out.size, 'Output has too many values')
     mlout = self.mlout[
         0]  # pick out just the upper left corner of the output
     self.assertTrue(np.allclose(out, mlout, rtol=0, atol=1e-11),
                     'output not within absolute tolerances')
     self.assertTrue(np.allclose(out, mlout, rtol=1e-12, atol=0),
                     'output not within relative tolerances')
 def test2dsplineeval_singlepoint(self):
     out = eval.evalMultivarSpline(self.spline, (0.1, 250))
     self.assertEqual(1, out.size, 'Output has too many values')
     mlout = self.mlout[0][0]
     if not (np.allclose(out, mlout, rtol=0,
                         atol=1e-10)  # check both abs and rel differences
             and np.allclose(out, mlout, rtol=1e-10, atol=0)):
         absDiffs = np.absolute(out - mlout)
         relDiffs = absDiffs / np.absolute(mlout)
         self.fail('Output has absolute differences as large as ' + str(np.max(absDiffs)) + \
                   ' and relative differences as large as ' + str(np.max(relDiffs)) + '.\n')
 def test2dsplineeval(self):
     x = np.empty(2, np.object)
     x[0] = np.logspace(-1, 3.7, 50)
     x[1] = np.linspace(250, 800, 20)
     out = eval.evalMultivarSpline(self.spline, x)
     self.assertEqual(out.shape, self.mlout.shape, 'shapes not equal')
     if not (np.allclose(out, self.mlout, rtol=0,
                         atol=1e-10)  # check both abs and rel differences
             and np.allclose(out, self.mlout, rtol=1e-10, atol=0)):
         absDiffs = np.absolute(out - self.mlout)
         relDiffs = absDiffs / np.absolute(self.mlout)
         self.fail('Output has absolute differences as large as ' + str(np.max(absDiffs)) + \
                   ' and relative differences as large as ' + str(np.max(relDiffs)) + '.\n')
 def test1dsplineeval_grid(self):
     x = np.empty(
         1, np.object
     )  # sadly, must do this so numpy won't nest or unnest against your will
     x[0] = np.arange(240, 501, 20)  # in Matlab, a = 240:20:500;
     out = eval.evalMultivarSpline(self.spline, x)
     self.assertEqual(out.shape, self.mlout.shape, 'shapes not equal')
     if not (np.allclose(out, self.mlout, rtol=0,
                         atol=1e-10)  # check both abs and rel differences
             and np.allclose(out, self.mlout, rtol=1e-10, atol=0)):
         absDiffs = np.absolute(out - self.mlout)
         relDiffs = absDiffs / np.absolute(self.mlout)
         self.fail('Output has absolute differences as large as ' + str(np.max(absDiffs)) + \
                   ' and relative differences as large as ' + str(np.max(relDiffs)) + '.\n')
Ejemplo n.º 5
0
 def test3dsplineeval(self):
     x = np.empty(3, np.object)
     x[0] = np.arange(.1, 8001, 10)
     x[1] = np.arange(239, 502, 5)
     x[2] = np.arange(0, 8.1, .5)
     out = eval.evalMultivarSpline(self.spline, x)
     self.assertEqual(out.shape, self.mlout.shape, 'shapes not equal')
     # unfortunately, the three rounds of estimations that go on with a 3d spline result in more error
     if not (np.allclose(out, self.mlout, rtol=0,
                         atol=2e-9)  # check both abs and rel differences
             and np.allclose(out, self.mlout, rtol=1e-10, atol=0)):
         absDiffs = np.absolute(out - self.mlout)
         relDiffs = absDiffs / np.absolute(self.mlout)
         self.fail('Output has absolute differences as large as ' +
                   str(np.max(absDiffs)) +
                   ' and relative differences as large as ' +
                   str(np.max(relDiffs)) + '.\n')
Ejemplo n.º 6
0
 def test3dsplineeval_singlepoint_arrofarr(self):
     x = np.empty(3, np.object)
     for i in np.arange(0, 3):
         x[i] = np.empty((1, ), float)
     x[0][0] = 0.1
     x[1][0] = 244
     x[2][0] = 1
     out = eval.evalMultivarSpline(self.spline, x)
     self.assertEqual(1, out.size, 'Output has too many values')
     mlout = self.mlout[0][1][2]
     if not (np.allclose(out, mlout, rtol=0,
                         atol=2e-9)  # check both abs and rel differences
             and np.allclose(out, mlout, rtol=1e-10, atol=0)):
         absDiffs = np.absolute(out - mlout)
         relDiffs = absDiffs / np.absolute(mlout)
         self.fail('Output has absolute differences as large as ' +
                   str(np.max(absDiffs)) +
                   ' and relative differences as large as ' +
                   str(np.max(relDiffs)) + '.\n')
Ejemplo n.º 7
0
def getDerivatives(gibbsSp, PTM, dimCt, tdvSpec, verbose=False):
    """

    :param gibbsSp:     The Gibbs energy spline
    :param PTM:         The pressure, temperature[, molality] points at which the spine should be evaluated
    :param dimCt:       2 if a PT spline, 3 if a PTM spline
    :param tdvSpec:     The expanded TDVSpec describing the thermodynamic variables to be calculated
    :param verbose:     True to output timings
    :return:            Gibbs energy derivatives necessary to calculate the tdvs listed in the tdvSpec
    """
    GibbsDerivs = _createGibbsDerivativesClass(tdvSpec)
    out = GibbsDerivs()
    reqderivs = {d for t in tdvSpec for d in t.reqDerivs}   # get set of derivative names that are needed
    getDerivSpec = lambda dn: next(d for d in statevars.derivatives if d.name == dn)
    for rd in reqderivs:
        derivDirective = _buildDerivDirective(getDerivSpec(rd), dimCt)
        start = time()
        setattr(out, rd, evalMultivarSpline(gibbsSp, PTM, derivDirective))
        end = time()
        if verbose: _printTiming('deriv '+rd, start, end)
    return out