Esempio n. 1
0
        def check_history(result, expected, field, tol, abs_err_tol=1.0):
            t1, p1 = result.getFieldHistoryAtCell(field, 4)
            t2, p2 = expected.getFieldHistoryAtCell(field, 4)
            tc = HistoryWithinTolTC(fieldsToTest=[field],
                                    defFieldTol=tol,
                                    fieldTols=None,
                                    expected=expected,
                                    absoluteErrorTol=abs_err_tol,
                                    testCellIndex=4,
                                    times=None)
            status = tc.check(result)

            if (not status) and SHOW_PLOT:
                from matplotlib import pyplot as plt
                plt.semilogx(t1,
                             p1,
                             '-r+',
                             label=('result (%s)' % result.modelName))
                plt.semilogx(t2,
                             p2,
                             '--b*',
                             label=('expected (%s)' % expected.modelName))
                plt.title('PASS = %s; %s; tol=%f' % (str(status), field, tol))
                plt.legend()
                plt.gca().relim()
                for i, (t, e) in enumerate(zip(tc.times,
                                               tc.fieldErrors[field])):
                    if e > tol:
                        plt.plot(t, p2[i], ' go', alpha=0.5, markersize=10)
                plt.show()

            return status
Esempio n. 2
0
    def test_times_mechanism(self):
        # not specifying times should force interpolation onto expected times
        tc = HistoryWithinTolTC(fieldsToTest=["Temperature"],
                                defFieldTol=10.0,
                                fieldTols=None,
                                expected=self.mres3,
                                testCellIndex=4,
                                times=None)
        status = tc.check(self.mres4)
        self.assertEqual(len(tc.times), len(self.mres3.getTimes()))

        # not specifying times should force interpolation onto expected times
        tc = HistoryWithinTolTC(fieldsToTest=["Temperature"],
                                defFieldTol=10.0,
                                fieldTols=None,
                                expected=self.mres4,
                                testCellIndex=4,
                                times=None)
        status = tc.check(self.mres3)
        self.assertEqual(len(tc.times), len(self.mres4.getTimes()))

        # specifying times should force interpolation to suppliedtimes
        tc = HistoryWithinTolTC(fieldsToTest=["Temperature"],
                                defFieldTol=10.0,
                                fieldTols=None,
                                expected=self.mres4,
                                testCellIndex=4,
                                times=[0.0, 1.0, 2.0],
                                enforceLogic=False)
        status = tc.check(self.mres3)
        self.assertEqual(len(tc.times), 3)

        # if compare to analtic solution, times will be set to result's
        def solution_fn(pos, t):
            """ dummy """
            return 100.0

        tc = HistoryWithinTolTC(fieldsToTest=["Temperature"],
                                defFieldTol=10.0,
                                fieldTols=None,
                                expected=solution_fn,
                                testCellIndex=4,
                                times=None)
        status = tc.check(self.mres3)
        self.assertEqual(len(tc.times), len(self.mres3.getTimes()))