Dear all, i've solved Navier-stokes stationary problem in 2D. I would like to obtain velocity field components, e.g. ux and uy. How can i do it ?
You can simply form the dot-product with a unit vector.
n = Expression(('0.0','1.0')) uy = dot(field,n)
I did not find a direct way to do it.
Thank you very much !!!! Could I ask you how to evaluate the vorticity values on different points of domain (2D square cavity) ?
Best reguards Francesco
Just use
x = np.array([0.0,0.0]) print test_field(x)
this will also split it up in x and y direction
Last question ( i hope ) I found the solution of stationary Navier-Stokes (for square cavity) , I would estimate the vorticity in the different points but I always find some errors: u #velocity field w = curl (u) # vorticity field np.array center = ([0.5,0.5]) print w (center) # -> error #
Best reguards
Could be anything, could you please post the error meassage?
sure,
Traceback (most recent call last): File "nspf.py", line 202, in print vor(center) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/site-packages/ufl/exproperators.py", line 285, in _call return _eval(self, arg, mapping, component) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/site-packages/ufl/exproperators.py", line 277, in _eval return f.evaluate(coord, mapping, component, index_values) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/site-packages/ufl/algebra.py", line 101, in evaluate return sum(o.evaluate(x, mapping, component, index_values) for o in self.ufl_operands) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/site-packages/ufl/algebra.py", line 101, in return sum(o.evaluate(x, mapping, component, index_values) for o in self.ufl_operands) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/site-packages/ufl/indexed.py", line 90, in evaluate return A.evaluate(x, mapping, component, index_values) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/site-packages/ufl/differentiation.py", line 154, in evaluate derivatives=derivatives) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/site-packages/ufl/core/terminal.py", line 67, in evaluate return self.ufl_evaluate(x, component, derivatives) File "/home/rbnics/install/fenics/2016-03-09-93f759d/petsc-3.6.3/trilinos-/lib/python2.7/dist-packages/dolfin/functions/function.py", line 463, in ufl_evaluate
assert derivatives == () # TODO: Handle derivatives AssertionError
Thank you !!!
I can confirm this behaviour...
Code:
UV.vector()[:] = ev_r # ev_r is a result from SLEPc xx = np.array([1., 2.]) # point within the 2d domain print UV(xx) # Works fine H_phi = grad_rz(UV)/(mu02.np.pi*f) print H_phi(xx) # crashes (see below)
Funny enough, I can plot H_phi (using plot(H_phi))
Traceback (most recent call last): File "test18.py", line 159, in print H_phi(xx) File "/usr/lib/python2.7/dist-packages/ufl/exproperators.py", line 269, in _call return _eval(self, arg, mapping, component) File "/usr/lib/python2.7/dist-packages/ufl/exproperators.py", line 261, in _eval return f.evaluate(coord, mapping, component, index_values) File "/usr/lib/python2.7/dist-packages/ufl/algebra.py", line 259, in evaluate a = a.evaluate(x, mapping, component, index_values) File "/usr/lib/python2.7/dist-packages/ufl/algebra.py", line 101, in evaluate return sum(o.evaluate(x, mapping, component, index_values) for o in self.ufl_operands) File "/usr/lib/python2.7/dist-packages/ufl/algebra.py", line 101, in return sum(o.evaluate(x, mapping, component, index_values) for o in self.ufl_operands) File "/usr/lib/python2.7/dist-packages/ufl/indexed.py", line 93, in evaluate return A.evaluate(x, mapping, component, index_values) File "/usr/lib/python2.7/dist-packages/ufl/differentiation.py", line 150, in evaluate derivatives=derivatives) File "/usr/lib/python2.7/dist-packages/ufl/core/terminal.py", line 80, in evaluate return self.ufl_evaluate(x, component, derivatives) File "/usr/lib/python2.7/dist-packages/dolfin/functions/function.py", line 465, in ufl_evaluate assert derivatives == () # TODO: Handle derivatives AssertionError
Seems like I found the problem: The result remains an ufl algebra object until it is evaluated. That's probably why it works with plot. Projecting it seems to help:
H_phi = dolfin.project(grad_rz(UV)/(mu0*2.*np.pi*f)) print H_phi(xx)
Works...