# Path: dolfin_navier_scipy/residual_checks.py
# def get_steady_state_res(V=None, outflowds=None, gradvsymmtrc=True, nu=None):
# 
#     def steady_state_res(vel, pres, phi=None):
#         if phi is None:
#             phi = dolfin.TestFunction(V)
# 
#         cnvfrm = inner(dolfin.dot(vel, nabla_grad(vel)), phi)*dx
#         diffrm = nu*inner(grad(vel)+grad(vel).T, grad(phi))*dx
#         if gradvsymmtrc:
#             nvec = dolfin.FacetNormal(V.mesh())
#             diffrm = diffrm - (nu*inner(grad(vel).T*nvec, phi))*outflowds
# 
#         pfrm = inner(pres, div(phi))*dx
#         res = dolfin.assemble(diffrm+cnvfrm-pfrm)
#         return res
# 
#     return steady_state_res


import numpy as np
import dolfin
import dolfin_navier_scipy.stokes_navier_utils as snu
import dolfin_navier_scipy.dolfin_to_sparrays as dts
import dolfin_navier_scipy.problem_setups as dnsps
from dolfin_navier_scipy.residual_checks import get_steady_state_res




geodata = 'mesh/karman2D-rotcyl-bm_geo_cntrlbc.json'
proutdir = 'results/'


def testit(problem=None, nu=None, charvel=None, Re=None,
           meshlvl=1, gradvsymmtrc=True,
           rho=1.,
           ParaviewOutput=False, scheme='TH'):


# Path: dolfin_navier_scipy/residual_checks.py
# def get_steady_state_res(V=None, outflowds=None, gradvsymmtrc=True, nu=None):
# 
#     def steady_state_res(vel, pres, phi=None):
#         if phi is None:
#             phi = dolfin.TestFunction(V)
# 
#         cnvfrm = inner(dolfin.dot(vel, nabla_grad(vel)), phi)*dx
#         diffrm = nu*inner(grad(vel)+grad(vel).T, grad(phi))*dx
#         if gradvsymmtrc:
#             nvec = dolfin.FacetNormal(V.mesh())
#             diffrm = diffrm - (nu*inner(grad(vel).T*nvec, phi))*outflowds
# 
#         pfrm = inner(pres, div(phi))*dx
#         res = dolfin.assemble(diffrm+cnvfrm-pfrm)
#         return res
# 
#     return steady_state_res


# Path: tests/steadystate_schaefer-turek_2D-1.py
import numpy as np
import dolfin
import dolfin_navier_scipy.stokes_navier_utils as snu
import dolfin_navier_scipy.dolfin_to_sparrays as dts
import dolfin_navier_scipy.problem_setups as dnsps
from dolfin_navier_scipy.residual_checks import get_steady_state_res





geodata = 'mesh/karman2D-rotcyl-bm_geo_cntrlbc.json'
proutdir = 'results/'


def testit(problem=None, nu=None, charvel=None, Re=None,
           meshlvl=1, gradvsymmtrc=True,
           rho=1.,
           ParaviewOutput=False, scheme='TH'):


    meshfile = 'mesh/karman2D-rotcyl_lvl{0}.xml.gz'.format(meshlvl)