# 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 scipy.optimize as sco
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
import dolfin_navier_scipy.data_output_utils as dou
from dolfin_navier_scipy.residual_checks import get_steady_state_res
                          meshparams=meshparams)
    soldict = {}
    soldict.update(stokesmatsc)  # containing A, J, JT
    soldict.update(femp)  # adding V, Q, invinds, diribcs

    ddir = 'data/'
    data_prfx = problem + '{2}_mesh{0}_Re{1}'.\
        format(meshlvl, femp['Re'], scheme)
    soldict.update(fv=rhsd['fv'], fp=rhsd['fp'],
                   N=meshlvl, nu=nu,
                   verbose=True,
                   vel_pcrd_stps=0,
                   vel_nwtn_tol=1e-10,
                   vel_nwtn_stps=10,
                   return_vp=True,
                   get_datastring=None,
                   dbcinds=femp['dbcinds'], dbcvals=femp['dbcvals'],
                   data_prfx=ddir+data_prfx,
                   paraviewoutput=ParaviewOutput,
                   vfileprfx=proutdir+'vel_',
                   pfileprfx=proutdir+'p_')
    L = femp['charlen']  # characteristic length

    phionevec = np.zeros((femp['V'].dim(), 1))
    phionevec[femp['mvwbcinds'], :] = 1.
    phione = dolfin.Function(femp['V'])
    phione.vector().set_local(phionevec)
    pickx = dolfin.as_matrix([[1., 0.], [0., 0.]])
    picky = dolfin.as_matrix([[0., 0.], [0., 1.]])
    pox = pickx*phione

# 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_rotcyl.py
import numpy as np
import scipy.optimize as sco
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
import dolfin_navier_scipy.data_output_utils as dou
from dolfin_navier_scipy.residual_checks import get_steady_state_res

                          meshparams=meshparams)
    soldict = {}
    soldict.update(stokesmatsc)  # containing A, J, JT
    soldict.update(femp)  # adding V, Q, invinds, diribcs

    ddir = 'data/'
    data_prfx = problem + '{2}_mesh{0}_Re{1}'.\
        format(meshlvl, femp['Re'], scheme)
    soldict.update(fv=rhsd['fv'], fp=rhsd['fp'],
                   N=meshlvl, nu=nu,
                   verbose=True,
                   vel_pcrd_stps=0,
                   vel_nwtn_tol=1e-10,
                   vel_nwtn_stps=10,
                   return_vp=True,
                   get_datastring=None,
                   dbcinds=femp['dbcinds'], dbcvals=femp['dbcvals'],
                   data_prfx=ddir+data_prfx,
                   paraviewoutput=ParaviewOutput,
                   vfileprfx=proutdir+'vel_',
                   pfileprfx=proutdir+'p_')
    L = femp['charlen']  # characteristic length

    phionevec = np.zeros((femp['V'].dim(), 1))
    phionevec[femp['mvwbcinds'], :] = 1.
    phione = dolfin.Function(femp['V'])
    phione.vector().set_local(phionevec)
    pickx = dolfin.as_matrix([[1., 0.], [0., 0.]])
    picky = dolfin.as_matrix([[0., 0.], [0., 1.]])
    pox = pickx*phione

    poy = picky*phione