Giter VIP home page Giter VIP logo

Comments (5)

mikaem avatar mikaem commented on August 22, 2024

Interesting. A few things go wrong here and I don't think these things are very well documented.

  1. P0 uses boundary conditions (-1, 1), but the function you are trying to approximate pr has boundary conditions (-sin(y), sin(y)). This can be easily fixed using
import sympy as sp
x, y = sp.symbols('x,y', real=True)
P0   = Basis(N[0], family='C', domain=(-L[0]/2,L[0]/2), bc=(a*sp.sin(y), b*sp.sin(y)), scaled=True)
  1. The gradient grad(pk) has homogeneous boundary conditions for it's first item and inhomogeneous (a*sp.cos(y), b*sp.cos(y)) for its second item. I would suggest projecting the gradient to the regular Chebyshev or Legendre space that has no boundary conditions. Much more convenient:-)
P1   = Basis(N[0], family='C', domain=(-L[0]/2,L[0]/2))
TF1  = TensorProductSpace(comm, (P1, F1), axes=(0, 1))
TV1  = VectorTensorProductSpace(TF1) 
ur = project(grad(pk), TV1).backward()

The reason your code fails is, like you suggest, that one cannot project to a Dirichlet space with inhomogeneous boundary conditions. I think I could make that work quite easily, but I guess it has not come up until now because it has always been a better idea to project to the regular, non-restricted, spaces, since boundary conditions are not required for a projection.

from shenfun.

francispoulin avatar francispoulin commented on August 22, 2024

Ah, that makes so much sense. I am sorry for not figuring this out myself but what you say is very clear.

I don't think there is anything for you to change, it's more like the user, me, needing to be clearer as to what I want to do.

The P0 space is for my streamfunction and I was foolishly using this to build my space for the velocity, but even though the streamfunction has fixed Dirichlet boundary conditions, the velocity does not have the same. They do inherhet no-normal flow but that will come automatically from the streamfunction.

Also, thanks for pointing out how to impose boundary conditions more generally, that will come in handy.

I am happy to say that following your help, I do get that part of it running. Now to get this working with the time stepping.

Cheers!

from shenfun.

francispoulin avatar francispoulin commented on August 22, 2024

I am having an odd problem and not sure what to make of it. Below is a samle code that produces the error, albeit in a round about way.

The essence of it is that if I define qk as before to be the div and gradient, then afterwards I cannot compute qk to be the forward transform of qk. I realize this might be a bit odd but I wonder what's going on here? If I redefine qk then it seems to work but this seems less than idea and wonder what I am not understanding here.

`# sample code

a =  1.
P0   = Basis(N[0], family=family, domain=(-L[0]/2,L[0]/2), bc=(-a, a), scaled=True)
P1   = Basis(N[0], family=family, domain=(-L[0]/2,L[0]/2))
F0   = Basis(N[1], family='F', dtype='d', domain=(0., L[1]))
TF0  = TensorProductSpace(comm, (P0, F0), axes=(0, 1))
TF1  = TensorProductSpace(comm, (P1, F0), axes=(0, 1))
TV1  = VectorTensorProductSpace(TF1)

X    = TF0.local_mesh(True)

pr,  pk  = Array(TF0), Function(TF0)                          # Streamfunction
qr,  qk  = Array(TF1), Function(TF1)                          # Potential Vorticity

qr[:] = -2.*np.tanh(X[0])/pow(np.cosh(X[0]),2)        
qk    = TF1.forward(qr, qk)

pr[:] = np.tanh(X[0]) 
pk    = TF0.forward(pr, pk)
qk    = div(grad(pk))                                     # this seems to change qk
qr   = project(qk,TF1).backward(qr)
qk = TF1.forward(qr, qk)

`

from shenfun.

mikaem avatar mikaem commented on August 22, 2024

qk is no longer a Function and cannot be used in the last forward call. qk is now an Expr instance. That's just the way regular Python assignments work.

from shenfun.

francispoulin avatar francispoulin commented on August 22, 2024

Thanks. I didn't realize that div(grad) was an expression and not a function. Now I know, and hopefully I won't forget anytime soon.

from shenfun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.