Exemplo n.º 1
0
    def testPropagateA(self, mockGetFunctToPropagate,
                       mockPropagateToNextTimeStep):
        #Setup
        functToPropagate = mock.Mock()
        newMgConc, newOConc = self.mgStartConc + 10, self.oStartConc + 12
        mockGetFunctToPropagate.side_effect = lambda *args, **kwargs: functToPropagate
        #		functToPropagate.side_effect = lambda *ags,**kwargs: [newMgConc,newOConc]
        startInpReactants = copy.deepcopy(self.inputReactants)

        mockPropagateToNextTimeStep.side_effect = lambda *args, **kwargs: [
            newMgConc, newOConc
        ]

        expOutReactants = [
            coreHelp.ChemSpeciesStd("Mg", newMgConc),
            coreHelp.ChemSpeciesStd("H", self.hStartConc),
            coreHelp.ChemSpeciesStd("O", newOConc)
        ]

        self.testObjA.propagate(self.inputReactants,
                                self.step,
                                temperature=self.temp,
                                potential=self.potential)

        mockGetFunctToPropagate.assert_called_with(self.inputReactants,
                                                   self.temp, self.potential)
        mockPropagateToNextTimeStep.assert_called_with(
            [self.mgStartConc, self.oStartConc], self.step, functToPropagate)
        self.assertEqual(
            expOutReactants, self.inputReactants
        )  #self.inputReactants SHOULD have been updated with new concs
Exemplo n.º 2
0
    def testUpdateConcsStaysWithinLimits(self):
        self.reactants = [
            coreHelp.ChemSpeciesStd("Mg", 0.15),
            coreHelp.ChemSpeciesStd("O", 0.9)
        ]
        self.concChanges = {"Mg": -0.2, "O": 0.15}

        self.testObjA._updateConcs(self.reactants, self.concChanges)

        expUpdatedVals = [
            coreHelp.ChemSpeciesStd("Mg", 0),
            coreHelp.ChemSpeciesStd("O", 1)
        ]
        self.assertEqual(expUpdatedVals, self.reactants)
Exemplo n.º 3
0
    def createTestObjs(self):
        self.inputReactants = [
            coreHelp.ChemSpeciesStd("Mg", self.mgStartConc),
            coreHelp.ChemSpeciesStd("H", self.hStartConc),
            coreHelp.ChemSpeciesStd("O", self.oStartConc)
        ]
        self.mockRatesDictA = {
            "Mg": 2,
            "H": 3,
            "O": 4
        }  #Return even fixed conc vals; propagator will figure out which need using/discarding
        self.mockRateCalculator = mock.Mock()
        self.mockRateCalculator.getRates.side_effect = lambda *args, **kwargs: self.mockRatesDictA

        self.testObjA = tCode.ConcsPropagatorTemplate(self.mockRateCalculator,
                                                      self.variableConcSpecies)
Exemplo n.º 4
0
    def testGetFunctToPropagate_useNonInitialStartConcs(self):
        """ Check our implementation doesnt rely on the integrator only propagating from starting concentrations. """
        funct = self.testObjA.getFunctToPropagate(self.inputReactants,
                                                  self.temp, self.potential)

        funct(self.step, [self.mgStartConc, self.oStartConc])
        newMgConc, newOConc = self.mgStartConc + 2, self.oStartConc + 2
        actOutVals = funct(self.step, [newMgConc, newOConc])
        expOutVals = [self.mgRate, self.oRate]
        expInputReactants = [
            coreHelp.ChemSpeciesStd("Mg", newMgConc),
            coreHelp.ChemSpeciesStd("H", self.hStartConc),
            coreHelp.ChemSpeciesStd("O", newOConc)
        ]

        self.mockRateCalculator.getRates.assert_called_with(
            expInputReactants, temperature=self.temp, potential=self.potential)
        for exp, act in it.zip_longest(expOutVals, actOutVals):
            self.assertAlmostEqual(exp, act)
Exemplo n.º 5
0
    def createTestObjs(self):
        self.chemA = coreHelp.ChemSpeciesStd(self.nameA, self.concA)
        self.chemB = coreHelp.ChemSpeciesStd(self.nameB, self.concB)
        self.inpReactants = {self.nameA: self.chemA, self.nameB: self.chemB}
        self.reactionA, self.reactionB = mock.Mock(), mock.Mock()

        reactionAReturnVals = {
            self.nameA: self.reactionA_returnA,
            self.nameB: self.reactionA_returnB
        }
        reactionBReturnVals = {
            self.nameA: self.reactionB_returnA,
            self.nameB: self.reactionB_returnB
        }
        self.reactionA.getChangesInReactants.side_effect = lambda *args, **kwargs: reactionAReturnVals
        self.reactionB.getChangesInReactants.side_effect = lambda *args, **kwargs: reactionBReturnVals

        self.testObjA = tCode.RateCalculatorStandard(
            [self.reactionA, self.reactionB])
Exemplo n.º 6
0
    def testMoveForward(self):
        #setup
        def _propagate(inpReactants, *args, **kwargs):
            for reactant in inpReactants:
                if reactant.name == "Mg":
                    reactant.conc -= 10

        self.propagator.propagate.side_effect = lambda inpReactants, *args, **kwargs: _propagate(
            inpReactants, *args, **kwargs)

        #test
        timeStep = 10
        expReactants = [coreHelp.ChemSpeciesStd("Mg", -8)]
        self.testObjA.moveForwardByT(timeStep)

        actReactants = self.testObjA.currentReactants
        self.assertEqual(expReactants, actReactants)
Exemplo n.º 7
0
    def testExpectedUpdateA(self):
        expReactants = [coreHelp.ChemSpeciesStd(self.nameA, 2 + 1 + 3 + 4)]
        self._runTestFunct()

        expRequestedTimeSteps = [1.5, 1.4, 1.0]
        self.assertEqual(
            len(expRequestedTimeSteps),
            len(self.concChangesFinder.getConcChangesForNextTimeStep.
                call_args_list))
        for idx, callArgs in enumerate(
                self.concChangesFinder.getConcChangesForNextTimeStep.
                call_args_list):
            args, kwargs = callArgs
            expTimeStep, actTimeStep = expRequestedTimeSteps[idx], args[1]
            self.assertAlmostEqual(expTimeStep, actTimeStep)

        self.assertEqual(expReactants, self.inpReactants)
Exemplo n.º 8
0
 def testResetFunction(self):
     expReactants = self.startReactants
     self.testObjA.currentReactants = [coreHelp.ChemSpeciesStd("O", 4)]
     self.assertNotEqual(expReactants, self.testObjA.currentReactants)
     self.testObjA.reset()
     self.assertEqual(expReactants, self.testObjA.currentReactants)
Exemplo n.º 9
0
 def createTestObjs(self):
     self.inpReactants = [coreHelp.ChemSpeciesStd(self.nameA, self.concA)]
     self.concChangesFinder = mock.Mock()
     retVals = it.zip_longest(self.stepSizes, self.concChanges)
     self.concChangesFinder.getConcChangesForNextTimeStep.side_effect = retVals
     self.testObjA = tCode.ConcsPropagatorStandard(self.concChangesFinder)
Exemplo n.º 10
0
 def setUp(self):
     self.startReactants = [coreHelp.ChemSpeciesStd("Mg", 2)]
     self.temp = 25
     self.pot = 4
     self.createTestObjs()