コード例 #1
0
 def test_replaceNaNTagged(self):
     dom=self.domain
     sigma = es.Scalar(0,es.FunctionOnBoundary(dom))
     dat=(sigma*0)/0
     sigma.setTaggedValue(1 , es.Lsup(dat))
     sigma.replaceNaN(10)
     self.assertEqual(es.Lsup(sigma), 10)
     sigma = es.Scalar(0,es.FunctionOnBoundary(dom))
     sigma.promote()
     dat=(sigma*0)/0
     sigma.setTaggedValue(1 , es.Lsup(dat))
     sigma.replaceNaN(3+4j)
     self.assertEqual(es.Lsup(sigma), 5)
コード例 #2
0
 def getBoundaryDataPointIDsAndRefIDs(self):
     """
   get a dictionary contains data point IDs and reference IDs on BoundaryOnFunction
   numbering order of reference IDs and interface elements need to be consistent
   """
     # get "FunctionOnBoundary" FunctionSpace
     bfs = escript.FunctionOnBoundary(self.getDomain())
     # convert discrete reference IDs to continous numbers
     num = bfs.getX().getNumberOfDataPoints()
     FEDEBoundMap = {}
     n = 0
     for i in xrange(num):
         refID = bfs.getReferenceIDFromDataPointNo(i)
         if n != refID: newID = 2 * (refID - 1)
         else: newID = 2 * (refID - 1) + 1
         # save DataPoint IDs in keys and converted newIDs in values
         n = refID
         FEDEBoundMap[i] = newID
     return FEDEBoundMap
コード例 #3
0
    def __init__(self,
                 domain,
                 omega,
                 w,
                 data,
                 F,
                 coordinates=None,
                 fixAtBottom=False,
                 tol=1e-10,
                 saveMemory=True,
                 scaleF=True):
        """
        initializes a new forward model with acoustic wave form inversion.

        :param domain: domain of the model
        :type domain: `Domain`
        :param w: weighting factors
        :type w: ``Scalar``
        :param data: real and imaginary part of data
        :type data: ``escript.Data`` of shape (2,)
        :param F: real and imaginary part of source given at Dirac points,
                  on surface or at volume.
        :type F: ``escript.Data`` of shape (2,)
        :param coordinates: defines coordinate system to be used (not supported yet)
        :type coordinates: `ReferenceSystem` or `SpatialCoordinateTransformation`
        :param tol: tolerance of underlying PDE
        :type tol: positive ``float``
        :param saveMemory: if true stiffness matrix is deleted after solution
                           of PDE to minimize memory requests. This will
                           require more compute time as the matrix needs to be
                           reallocated.
        :type saveMemory: ``bool``
        :param scaleF: if true source F is scaled to minimize defect.
        :type scaleF: ``bool``
        :param fixAtBottom: if true pressure is fixed to zero at the bottom of
                            the domain
        :type fixAtBottom: ``bool``
        """
        super(AcousticWaveForm, self).__init__()
        self.__trafo = edc.makeTransformation(domain, coordinates)
        if not self.getCoordinateTransformation().isCartesian():
            raise ValueError(
                "Non-Cartesian Coordinates are not supported yet.")
        if not isinstance(data, escript.Data):
            raise ValueError("data must be an escript.Data object.")
        if not data.getFunctionSpace() == escript.FunctionOnBoundary(domain):
            raise ValueError("data must be defined on boundary")
        if not data.getShape() == (2, ):
            raise ValueError(
                "data must have shape (2,) (real and imaginary part).")
        if w is None:
            w = 1.
        if not isinstance(w, escript.Data):
            w = escript.Data(w, escript.FunctionOnBoundary(domain))
        else:
            if not w.getFunctionSpace() == escript.FunctionOnBoundary(domain):
                raise ValueError("Weights must be defined on boundary.")
            if not w.getShape() == ():
                raise ValueError("Weights must be scalar.")

        self.__domain = domain
        self.__omega = omega
        self.__weight = w
        self.__data = data
        self.scaleF = scaleF
        if scaleF:
            A = escript.integrate(self.__weight *
                                  escript.length(self.__data)**2)
            if A > 0:
                self.__data *= 1. / escript.sqrt(A)

        self.__BX = escript.boundingBox(domain)
        self.edge_lengths = np.asarray(escript.boundingBoxEdgeLengths(domain))

        if not isinstance(F, escript.Data):
            F = escript.interpolate(F, escript.DiracDeltaFunctions(domain))
        if not F.getShape() == (2, ):
            raise ValueError(
                "Source must have shape (2,) (real and imaginary part).")

        self.__F = escript.Data()
        self.__f = escript.Data()
        self.__f_dirac = escript.Data()

        if F.getFunctionSpace() == escript.DiracDeltaFunctions(domain):
            self.__f_dirac = F
        elif F.getFunctionSpace() == escript.FunctionOnBoundary(domain):
            self.__f = F
        else:
            self.__F = F
        self.__tol = tol
        self.__fixAtBottom = fixAtBottom
        self.__pde = None
        if not saveMemory:
            self.__pde = self.setUpPDE()