def getPotentialNumeric(self):
        """
        Returns 3 list each made up of a number of list containing primary, secondary and total
        potentials diferences. Each of the lists contain a list for each value of n.
        """
        primCon=self.primaryConductivity
        coords=self.domain.getX()
        tol=1e-8
        pde=LinearPDE(self.domain, numEquations=1)
        pde.getSolverOptions().setTolerance(tol)
        pde.setSymmetryOn()
        primaryPde=LinearPDE(self.domain, numEquations=1)
        primaryPde.getSolverOptions().setTolerance(tol)
        primaryPde.setSymmetryOn()
        DIM=self.domain.getDim()
        x=self.domain.getX()
        q=whereZero(x[DIM-1]-inf(x[DIM-1]))
        for i in xrange(DIM-1):
            xi=x[i]
            q+=whereZero(xi-inf(xi))+whereZero(xi-sup(xi))
        A = self.secondaryConductivity * kronecker(self.domain)
        APrimary = self.primaryConductivity * kronecker(self.domain)
        pde.setValue(A=A,q=q)
        primaryPde.setValue(A=APrimary,q=q)

        delPhiSecondaryList = []
        delPhiPrimaryList = []
        delPhiTotalList = []
        for i in range(1,self.n+1): # 1 to n
            maxR = self.numElectrodes - 1 - (2*i) #max amount of readings that will fit in the survey
            delPhiSecondary = []
            delPhiPrimary = []
            delPhiTotal = []
            for j in range(maxR):
                y_dirac=Scalar(0,DiracDeltaFunctions(self.domain))
                y_dirac.setTaggedValue(self.electrodeTags[j],self.current)
                y_dirac.setTaggedValue(self.electrodeTags[j + ((2*i) + 1)],-self.current)
                self.sources.append([self.electrodeTags[j], self.electrodeTags[j + ((2*i) + 1)]])
                primaryPde.setValue(y_dirac=y_dirac)
                numericPrimaryPot = primaryPde.getSolution()
                X=(primCon-self.secondaryConductivity) * grad(numericPrimaryPot)
                pde.setValue(X=X)
                u=pde.getSolution()
                loc=Locator(self.domain,[self.electrodes[j+i],self.electrodes[j+i+1]])
                self.samples.append([self.electrodeTags[j+i],self.electrodeTags[j+i+1]])
                valPrimary=loc.getValue(numericPrimaryPot)
                valSecondary=loc.getValue(u)
                delPhiPrimary.append(valPrimary[1]-valPrimary[0])
                delPhiSecondary.append(valSecondary[1]-valSecondary[0])
                delPhiTotal.append(delPhiPrimary[j]+delPhiSecondary[j])
            delPhiPrimaryList.append(delPhiPrimary)
            delPhiSecondaryList.append(delPhiSecondary)
            delPhiTotalList.append(delPhiTotal)

        self.delPhiPrimaryList=delPhiPrimaryList
        self.delPhiSecondaryList=delPhiSecondaryList
        self.delPhiTotalList = delPhiTotalList
        return [delPhiPrimaryList, delPhiSecondaryList, delPhiTotalList]
    def getGradient(self, sigma, phi, loc_phi):
        """
        Returns the gradient of the defect with respect to density.

        :param sigma: a suggestison for conductivity
        :type sigma: ``Data`` of shape (1,)
        :param phi: potential field
        :type phi: ``Data`` of shape (1,)
        """
        val = loc_phi
        if not isinstance(val, list):
            tmp = val
            val = [tmp]
        sampleTags = self.__sampleTags

        jointSamples = {}
        for i in range(0, 2 * len(sampleTags),
                       2):  #2*len because sample tags is a list of tuples
            half = i // 2
            if sampleTags[half][1] != "-":
                tmp = (val[i + 1] - val[i] - self.delphiIn[half]) * self.__w[i]
            else:
                tmp = (val[i] - self.delphiIn[i // 2]) * self.__w[i]
            sample = sampleTags[half]
            if sample[1] != "-":
                if sample[0] in jointSamples.keys():
                    jointSamples[sample[0]].append((sample[1], -tmp))
                else:
                    jointSamples[sampleTags[half][0]] = [(sample[1], -tmp)]
                if sample[1] in jointSamples.keys():
                    jointSamples[sample[1]].append((sample[0], tmp))
                else:
                    jointSamples[sample[1]] = [(sample[0], tmp)]
            else:
                if sample[0] in jointSamples.keys():
                    jointSamples[sample[0]].append((sample[1], tmp))
                else:
                    jointSamples[sampleTags[half][0]] = [(sample[1], tmp)]

        pde = self.setUpPDE()
        dom = self.__domain
        # conPrimary=self.__sigmaPrimary
        # APrimary = conPrimary * kronecker(dom)

        y_dirac = Scalar(0, DiracDeltaFunctions(dom))
        for i in jointSamples:
            total = 0
            for j in jointSamples[i]:
                total += j[1]
            y_dirac.setTaggedValue(i, total)

        pde.setValue(A=sigma * kronecker(dom), y_dirac=y_dirac)
        u = pde.getSolution()
        retVal = -inner(grad(u), grad(phi + self.__phiPrimary))
        return retVal
Exemple #3
0
    def getGradient(self, sigma, phi, loc_phi):
        """
        Returns the gradient of the defect with respect to density.

        :param sigma: a suggestison for conductivity
        :type sigma: ``Data`` of shape (1,)
        :param phi: potential field
        :type phi: ``Data`` of shape (1,)
        """
        val=loc_phi
        if not isinstance(val,list):
            tmp=val
            val=[tmp]
        sampleTags=self.__sampleTags

        jointSamples={}
        for i in range(0,2*len(sampleTags),2): #2*len because sample tags is a list of tuples
            half = i//2
            if sampleTags[half][1]!="-":
                tmp=(val[i+1]-val[i]-self.delphiIn[half])*self.__w[i]
            else:
                tmp=(val[i]-self.delphiIn[i//2]) *self.__w[i]
            sample = sampleTags[half]
            if sample[1]!="-":
                if sample[0] in jointSamples.keys():
                    jointSamples[sample[0]].append((sample[1], -tmp))
                else:
                    jointSamples[sampleTags[half][0]]=[(sample[1],-tmp)]
                if sample[1] in jointSamples.keys():
                    jointSamples[sample[1]].append((sample[0], tmp))
                else:
                    jointSamples[sample[1]]=[(sample[0], tmp)]
            else:
                if sample[0] in jointSamples.keys():
                    jointSamples[sample[0]].append((sample[1], tmp))
                else:
                    jointSamples[sampleTags[half][0]]=[(sample[1],tmp)]

        pde =self.setUpPDE()
        dom=self.__domain
        # conPrimary=self.__sigmaPrimary
        # APrimary = conPrimary * kronecker(dom)

        y_dirac = Scalar(0,DiracDeltaFunctions(dom))
        for i in jointSamples:
            total=0
            for j in jointSamples[i]:
                total+=j[1]
            y_dirac.setTaggedValue(i,total)

        pde.setValue(A=sigma*kronecker(dom), y_dirac=y_dirac)
        u=pde.getSolution()
        retVal=-inner(grad(u),grad(phi+self.__phiPrimary))
        return retVal
Exemple #4
0
def makeTagField(functionspace):
    """
    this creates a data object making the tagged regions with the corresponding tag id 
    
    :param functionspace: function space to create tags for
    :type functionspace: `esys.escript.FunctionSpace` 
    :return: `esys.escript.Scalar` with tags 
    """
    out = Scalar(-1, functionspace)
    for t in functionspace.getListOfTags():
        out.setTaggedValue(t, t)
    out.expand()
    return out
Exemple #5
0
def true_properties(domain):
    from esys.escript import Scalar, Function
    sigma_true = Scalar(sigma_background, Function(domain))
    sigma_true.setTaggedValue("InnerBox", sigma_background)
    sigma_true.setTaggedValue("Anomaly1", sigma_background * 10)
    sigma_true.setTaggedValue("Anomaly2", sigma_background * 10)
    sigma_true.setTaggedValue("Anomaly3", sigma_background)

    gamma_background = eta_background / (1 - eta_background)
    gamma_true = Scalar(gamma_background, Function(domain))
    gamma_true.setTaggedValue("InnerBox", gamma_background)
    gamma_true.setTaggedValue("Anomaly1", gamma_background)
    gamma_true.setTaggedValue("Anomaly2", gamma_background * 20)
    gamma_true.setTaggedValue("Anomaly3", gamma_background * 20)

    return sigma_true, gamma_true
Exemple #6
0
def true_properties(domain):
    from esys.escript import Scalar, Function
    sigma_true = Scalar(sigma_background, Function(domain))
    sigma_true.setTaggedValue("R1", 0.01)
    sigma_true.setTaggedValue("R2", 0.1)

    gamma_background = eta_background / (1 - eta_background)
    gamma_true = Scalar(gamma_background, Function(domain))
    gamma_true.setTaggedValue("R1", 0.02)
    gamma_true.setTaggedValue("R2", 0.2)

    return sigma_true, gamma_true