Giter Club home page Giter Club logo

Comments (4)

mikaem avatar mikaem commented on June 14, 2024

Hi Thilo

Thanks a lot for reporting. This is a bug. The form represents a scalar and it should not go into this if test. I know this used to work, so this only goes to show that we need better tests! I'll look into it right away.

from shenfun.

mikaem avatar mikaem commented on June 14, 2024

If you want to fix this locally, then the following added just above mentioned line should do:

if test.expr_rank() == 0:
    recursive = False

from shenfun.

sebglane avatar sebglane commented on June 14, 2024

Hi Mikael,

Thilo and I realized that you added the lines above in commit 955a326. The code which is shown above is working properly now. Thank you for fixing this.

However, we think that there is deeper a problem somewhere. If we modify the boundary conditions in our example from homogeneous Dirichlet bcs to inhomogeneous ones, an error occurs if the linear is solved. We hope that example below show the problem. We are not sure if we should close this issue and open a new one because the problem does not seem to be related to the div-div-term. The problem also occurs if only the grad-grad is considered.

Best wishes,
Sebastian and Thilo

from sympy import symbols, cos, sin
from mpi4py import MPI
from shenfun import inner, grad, div, TestFunction, TrialFunction, Array,\
    Basis, TensorProductSpace, VectorTensorProductSpace, BlockMatrix
from mpi4py_fft.pencil import Subcomm

comm = MPI.COMM_WORLD

family = 'legendre'

# Size of discretization
n = 40
N = [n, n+1]

# Bases and spaces
BX_hom = Basis(N[0], family=family, bc=(0, 0))
BX_inhom = Basis(N[0], family=family, bc=(0, 0.1))
BY_hom = Basis(N[1], family=family, bc=(0, 0))

# Function spaces
subcomms = Subcomm(MPI.COMM_WORLD, [0, 1])
T_hom = TensorProductSpace(subcomms, (BX_hom, BY_hom))
T_inhom = TensorProductSpace(subcomms, (BX_inhom, BY_hom))

V_hom = VectorTensorProductSpace([T_hom, T_hom])
V_inhom = VectorTensorProductSpace([T_inhom, T_inhom])
V_mixed = VectorTensorProductSpace([T_hom, T_inhom])

# Choose the BCs you want
# working
V = V_hom

# not working
# V = V_inhom
# V = V_mixed

# Functions
u = TrialFunction(V)
v = TestFunction(V)

# Compute matrices
# Assemble standard term
A = inner(grad(u), grad(v))

# Assemble (div(u), div(v))-term
# non-working
B = inner(div(u), div(v)) # raises an error

# Compute BlockMatrix
M = BlockMatrix(A + B)

# Compute right hand side
# Use sympy to compute a rhs
x, y = symbols("x,y")
fe = (sin(x**2)*(1-y)*(1+y), y**2*(cos(x-y**2)))
fj = Array(V, buffer=fe)

b = inner(v, fj)

# Compute solution
u_hat = M.solve(b) # This line fails because inconsistent shapes
u_sol = u_hat.backward()

from shenfun.

mikaem avatar mikaem commented on June 14, 2024

Hi

Non-homogeneous bcs are tricky. Please have a close look at, e.g., the driven cavity demo. There are matrices in A and B that should go on the right hand side. Please also look at the Rayleigh Bénard demo.
Best of luck😀
Mikael

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.