Esempio n. 1
0
    def computeError4level(self, meanApprox4lvl, lastSpace, meanExact = None):
        if meanExact == None:
            solMesh = lastSpace.mesh()
            solFamily = lastSpace.ufl_element().family()
            solDegree = lastSpace.ufl_element().degree()
            refSpace = FunctionSpace(refine(refine(solMesh)), solFamily, solDegree)
            meanExact = self.solveMean(refSpace)

        refSpace = meanExact.function_space()
        error4lvl = list(
                np.sqrt(assemble(
                    (project(meanApprox, refSpace) - interpolate(meanExact, refSpace)) ** 2 * dx
                )) for meanApprox in meanApprox4lvl)

        return error4lvl
Esempio n. 2
0
 def addLevel(self):
     self.optNumSamples4Level.append(0)
     self.y4Level.append([])
     lastSpace = self.space4Level[-1]
     lastMesh = lastSpace.mesh()
     lastFamiliy = lastSpace.ufl_element().family()
     lastDegree = lastSpace.ufl_element().degree()
     if self.adaptiveMesh:
         solution = self.problem.solveMean(lastSpace)
         _, cell_markers = self.problem.estimate(solution)
         self.space4Level.append(FunctionSpace(refine(lastMesh, cell_markers),
             lastFamiliy, lastDegree))
     else:
         self.space4Level.append(FunctionSpace(refine(lastMesh),
             lastFamiliy, lastDegree))
     self.variance4level.append(None)
     self.compCost4lvl.append(0)
Esempio n. 3
0
  def __init__(self, coarse_mesh, nref, p_coarse, p_fine, sym=False):
    """

    :param dolfin.cpp.mesh.Mesh coarse_mesh:
    :param int nref:
    :param int p_coarse:
    :param int p_fine:
    :param bool sym:
    :return:
    """

    print0("Creating approximation spaces")

    self.V_coarse = FunctionSpace(coarse_mesh, "CG", p_coarse)
    self.ndof_coarse = self.V_coarse.dim()

    refined_mesh = coarse_mesh
    for ref in xrange(nref):
      refined_mesh = refine(refined_mesh)   # creates a new Mesh, initial coarse mesh is unchanged

    self.V_fine = FunctionSpace(refined_mesh, "CG", p_fine)
    self.ndof_fine = self.V_fine.dim()

    H = coarse_mesh.hmax()
    h = refined_mesh.hmax()
    self.alpha = log(H)/log(h)
    self.beta = p_fine + 1

    if comm.rank == 0:
      prop = Table("Approximation properties")
      prop.set("ndof", "coarse", self.ndof_coarse)
      prop.set("ndof", "fine", self.ndof_fine)
      prop.set("h", "coarse", H)
      prop.set("h", "fine", h)

      info(prop)

      print "alpha = {}, beta = {}".format(self.alpha, self.beta)

    self.bc_coarse = None

    self.A_fine = PETScMatrix()
    self.B_fine = PETScMatrix()
    self.A_coarse = PETScMatrix()
    self.B_coarse = PETScMatrix()

    self.sym = sym
    self.switch_gep_matrices = False