def compute_diagnostics(self):
    diagnostic_field_count = libspud.option_count("/system/diagnostic_fields/diagnostic")
    if(diagnostic_field_count == 0):
       return
       
    LOG.info("Computing diagnostic fields...")
    d = Diagnostics(self.mesh)
    for i in range(0, diagnostic_field_count):
       name = libspud.get_option("/system/diagnostic_fields/diagnostic[%d]/name" % i)
       try:
          if(name == "grid_reynolds_number"):
             viscosity = Function(self.W.sub(1)).interpolate(Expression(libspud.get_option("/system/equations/momentum_equation/stress_term/scalar_field::Viscosity/value/constant")))
             field = d.grid_reynolds_number(self.u, viscosity)
          elif(name == "courant_number"):
             field = d.courant_number(self.u, self.options["dt"])
          else:
             raise ValueError("Unknown diagnostic field: %s" % name)
       except ValueError as e:
          LOG.exception(name)
          sys.exit()
          
       LOG.info("Diagnostic results for: %s" % name)
       LOG.info("Maximum value: %f" % max(field.vector()))
       LOG.info("Maximum value: %f" % min(field.vector()))
       
    return
    def compute_diagnostics(self):
        diagnostic_field_count = libspud.option_count(
            "/system/diagnostic_fields/diagnostic")
        if (diagnostic_field_count == 0):
            return

        LOG.info("Computing diagnostic fields...")
        d = Diagnostics(self.mesh)
        for i in range(0, diagnostic_field_count):
            name = libspud.get_option(
                "/system/diagnostic_fields/diagnostic[%d]/name" % i)
            try:
                if (name == "grid_reynolds_number"):
                    viscosity = Function(self.W.sub(1)).interpolate(
                        Expression(
                            libspud.get_option(
                                "/system/equations/momentum_equation/stress_term/scalar_field::Viscosity/value/constant"
                            )))
                    field = d.grid_reynolds_number(self.u, viscosity)
                elif (name == "courant_number"):
                    field = d.courant_number(self.u, self.options["dt"])
                else:
                    raise ValueError("Unknown diagnostic field: %s" % name)
            except ValueError as e:
                LOG.exception(name)
                sys.exit()

            LOG.info("Diagnostic results for: %s" % name)
            LOG.info("Maximum value: %f" % max(field.vector()))
            LOG.info("Maximum value: %f" % min(field.vector()))

        return
Esempio n. 3
0
def diagnostics_courant_number():
    from firedrake_fluids.diagnostics import Diagnostics

    mesh = UnitSquareMesh(10, 10)
    fs = FunctionSpace(mesh, "CG", 1)
    vfs = VectorFunctionSpace(mesh, "CG", 1)
    velocity = Function(vfs).interpolate(Expression(("x[0]", "x[1]")))
    dt = 0.5

    diagnostics = Diagnostics(mesh)

    courant_number = diagnostics.courant_number(velocity, dt)
    courant_number_exact = Function(fs).interpolate(
        Expression("sqrt(pow(x[0], 2) + pow(x[1], 2))*0.5/0.1414213562"))
    norm = sqrt(
        assemble(
            dot(courant_number - courant_number_exact,
                courant_number - courant_number_exact) * dx))
    return norm