Example #1
0
 def testMinima(self):
     """
     Test the correct computation of all local minima
     for a bistable potential.
     """
     #Predict result
     x0, curv, mask = fixedPoints(
         numpy.array([self.LAMBDA]), kappa1=self.kappa1
         )
     expectedResult = DC.FieldContainer(
         numpy.extract(curv[0]>0,x0[0]),
         unit = self.xField.unit,
         longname = 'position of the local minima of electric potential',
         shortname = 'x_0'
         )
     #Retrieve result from worker
     w = MRA.MRA(None)
     w.paramScale.value = "1.0m"
     result = w.mra(self.V)
     #Testing
     i = numpy.array(range(self.n))
     index = numpy.logical_and(self.u > 0.7, self.u < 0.72)
     index = MRA.findMinima(self.V.data, 5)
     numpy.testing.assert_array_almost_equal(
         result[r'x_{min}'].data, expectedResult.data, 4
         )
Example #2
0
 def testRoots(self):
     """
     Test the correct computation of all local extrema
     for a bistable potential.
     """
     #Prepare dimensions
     self.prepareDimensions()
     lambField = DC.FieldContainer(
         self.lambDim,
         unit='1 V / m**3',
         longname='parameter',
         shortname='\lambda'
         )
     xField = DC.FieldContainer(
         self.xDim[0],
         unit='1 m',
         longname='position',
         shortname='x'
         )
     #Prepare potential
     V = []
     for i in xrange(len(lambField.data)):
         u = xField.data
         V.append(
             -lambField.data[i] / 2 * u ** 2 + u ** 4 / 4 - u * self.kappa1
             )
     self.V = DC.FieldContainer(
         numpy.array(V), unit='1 V', dimensions=[lambField, xField],
         longname = 'electric potential',
         shortname = r'\varphi'
         )
     #Predict result
     x0, curv, mask = fixedPoints(lambField.data, kappa1=self.kappa1)
     x0 = numpy.where(curv > 0, x0, numpy.NaN)
     data = x0[:, ::2]
     dims = [DC.generateIndex(0, 2), lambField]
     expectedResult = DC.FieldContainer(
         data.transpose(),
         unit=xField.unit,
         mask=numpy.isnan(data).transpose(),
         dimensions=dims,
         longname='position of the local extrema of electric potential',
         shortname='x_0'
         )
     #Configure worker
     w = MRA.MRA(None)
     w.paramScale.value = "1.0m"
     #Retrieve result from worker
     result = copy.deepcopy(w.mra(self.V))['x_{min}']
     result.error=None
     self.test(result,expectedResult,1e-2,1e-2)
Example #3
0
 def testMaxima(self):
     """
     Test the correct computation of all local maxima
     for a bistable potential.
     """
     #Predict result
     x0, curv, mask = fixedPoints(
         numpy.array([self.LAMBDA]), kappa1=self.kappa1
         )
     expectedResult = DC.FieldContainer(
         numpy.extract(curv[0] > 0, x0[0]),
         unit = self.xField.unit,
         longname = 'position of the local minima of electric potential',
         shortname = 'x_0')
     #Retrieve result from worker
     w = MRA.MRA(None)
     w.paramScale.value = "1.0m"
     V = copy.deepcopy(self.V)
     V.data*=-1
     result = w.mra(V)
     #Testing
     numpy.testing.assert_array_almost_equal(
         result[r'x_{max}'].data,expectedResult.data, 4
         )