def _getSolution(self, system): """returns exact solution""" dim = self.domain.getDim() x = Solution(self.domain).getX() if system: u_ex = Vector(0., Solution(self.domain)) if dim == 2: u_ex[0] = 1. + 2. * x[0] + 3. * x[1] + 4. * x[0]**2 + 5. * x[ 1] * x[0] + 6. * x[1]**2 u_ex[1] = -1. + 4. * x[0] + 2. * x[1] + 1. * x[0]**2 + 6. * x[ 1] * x[0] + 4. * x[1]**2 else: u_ex[0] = 1.+2.*x[0]+3.*x[1]+4.*x[2]+\ 6.*x[0]*x[1]+7.*x[1]*x[2]+8.*x[2]*x[0]+\ 9.*x[0]**2+10.*x[1]**2+11.*x[2]**2 u_ex[1] = 2.+4.*x[0]+1.*x[1]-6.*x[2]+\ 3.*x[0]*x[1]+2.*x[1]*x[2]-8.*x[2]*x[0]-\ 2.*x[0]**2+7.*x[1]**2+5.*x[2]**2 u_ex[2] = -2.+7.*x[0]+9.*x[1]+2*x[2]-\ 6.*x[0]*x[1]+8.*x[1]*x[2]+2.*x[2]*x[0]+\ 2.*x[0]**2+8.*x[1]**2+1.*x[2]**2 else: if dim == 2: u_ex = 1. + 2. * x[0] + 3. * x[1] + 4. * x[0]**2 + 5. * x[ 1] * x[0] + 6. * x[1]**2 else: u_ex = 1.+2.*x[0]+3.*x[1]+4.*x[2]+\ 6.*x[0]*x[1]+7.*x[1]*x[2]+8.*x[2]*x[0]+\ 9.*x[0]**2+10.*x[1]**2+11.*x[2]**2 return u_ex
def _getGrad(self, system): """returns exact gradient""" dim = self.domain.getDim() x = Solution(self.domain).getX() if system: g_ex = Data(0., (dim, dim), Solution(self.domain)) if dim == 2: g_ex[0, 0] = 2. + 8. * x[0] + 5. * x[1] g_ex[0, 1] = 3. + 5. * x[0] + 12. * x[1] g_ex[1, 0] = 4. + 2. * x[0] + 6. * x[1] g_ex[1, 1] = 2. + 6. * x[0] + 8. * x[1] else: g_ex[0, 0] = 2. + 6. * x[1] + 8. * x[2] + 18. * x[0] g_ex[0, 1] = 3. + 6. * x[0] + 7. * x[2] + 20. * x[1] g_ex[0, 2] = 4. + 7. * x[1] + 8. * x[0] + 22. * x[2] g_ex[1, 0] = 4. + 3. * x[1] - 8. * x[2] - 4. * x[0] g_ex[1, 1] = 1. + 3. * x[0] + 2. * x[2] + 14. * x[1] g_ex[1, 2] = -6. + 2. * x[1] - 8. * x[0] + 10. * x[2] g_ex[2, 0] = 7. - 6. * x[1] + 2. * x[2] + 4. * x[0] g_ex[2, 1] = 9. - 6. * x[0] + 8. * x[2] + 16. * x[1] g_ex[2, 2] = 2. + 8. * x[1] + 2. * x[0] + 2. * x[2] else: g_ex = Data(0., (dim, ), Solution(self.domain)) if dim == 2: g_ex[0] = 2. + 8. * x[0] + 5. * x[1] g_ex[1] = 3. + 5. * x[0] + 12. * x[1] else: g_ex[0] = 2. + 6. * x[1] + 8. * x[2] + 18. * x[0] g_ex[1] = 3. + 6. * x[0] + 7. * x[2] + 20. * x[1] g_ex[2] = 4. + 7. * x[1] + 8. * x[0] + 22. * x[2] return g_ex
def getGrad(self, system): """returns exact gradient""" dim = self.domain.getDim() if system: g_ex = Data(0., (dim,dim), Solution(self.domain)) if dim == 2: g_ex[0,0] = 2. g_ex[0,1] = 3. g_ex[1,0] = 3. g_ex[1,1] = 2. else: g_ex[0,0] = 2. g_ex[0,1] = 3. g_ex[0,2] = 4. g_ex[1,0] = 4. g_ex[1,1] = 1. g_ex[1,2] = -2. g_ex[2,0] = 8. g_ex[2,1] = 4. g_ex[2,2] = 5. else: g_ex = Data(0., (dim,), Solution(self.domain)) if dim == 2: g_ex[0] = 2. g_ex[1] = 3. else: g_ex[0] = 2. g_ex[1] = 3. g_ex[2] = 4. return g_ex
def interpolateEscriptData(domain, data): """ esys.weipa does not support the function spaces Solution and ReducedSolution. This function interpolates Data defined on those function spaces to compatible alternatives. """ from esys.escript import Solution, ReducedSolution from esys.escript import ContinuousFunction, ReducedContinuousFunction from esys.escript.util import interpolate new_data={} for n,d in sorted(list(data.items()), key=lambda x: x[0]): if not d.isEmpty(): fs=d.getFunctionSpace() if domain is None: domain=fs.getDomain() elif domain != fs.getDomain(): raise ValueError("weipa: All Data must be on the same domain!") new_data[n]=d try: if fs == Solution(domain): new_data[n]=interpolate(d, ContinuousFunction(domain)) elif domain.getDescription().startswith("speckley"): new_data[n]=interpolate(d, ContinuousFunction(domain)) elif fs == ReducedSolution(domain): new_data[n]=interpolate(d, ReducedContinuousFunction(domain)) except RuntimeError as e: if str(e).startswith("FunctionSpaceException"): pass else: raise e return domain,new_data
def setCoefficients(self, pde, system): """sets PDE coefficients""" FAC_DIAG = self.FAC_DIAG FAC_OFFDIAG =self.FAC_OFFDIAG x = Solution(self.domain).getX() mask = whereZero(x[0]) dim = self.domain.getDim() u_ex = self.getSolution(system) g_ex = self.getGrad(system) if system: A = Tensor4(0., Function(self.domain)) for i in range(dim): A[i,:,i,:] = kronecker(dim) Y = Vector(0., Function(self.domain)) if dim == 2: Y[0] = u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG-20 Y[1] = u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG-10 else: Y[0] = u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG-60 Y[1] = u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG-20 Y[2] = u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG-22 pde.setValue(r=u_ex, q=mask*numpy.ones(dim,), A=A, D=kronecker(dim)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((dim,dim))*FAC_OFFDIAG, Y=Y, y=matrixmult(g_ex,self.domain.getNormal())) else: pde.setValue(r=u_ex, q=mask, A=kronecker(dim), y=inner(g_ex, self.domain.getNormal())) if dim == 2: pde.setValue(Y=-20.) else: pde.setValue(Y=-60.)
def getSolution(self, system): """returns exact solution""" dim = self.domain.getDim() x = Solution(self.domain).getX() if system: u_ex = Vector(0., Solution(self.domain)) if dim == 2: u_ex[0] = 1.+2.*x[0]+3.*x[1] u_ex[1] = -1.+3.*x[0]+2.*x[1] else: u_ex[0] = 1.+2.*x[0]+3.*x[1]+4.*x[2] u_ex[1] = -1.+4.*x[0]+1.*x[1]-2.*x[2] u_ex[2] = 5.+8.*x[0]+4.*x[1]+5.*x[2] else: if dim == 2: u_ex = 1.+2.*x[0]+3.*x[1] else: u_ex = 1.+2.*x[0]+3.*x[1]+4.*x[2] return u_ex