Periodic boundary conditions cant be applied because assembly changes sparsity pattern? #1167
-
|
What I want to achieve is a transient simulation on a 1D grid with periodicity in the left/right boundaries (what comes out on the right goes in on the left and vice versa). So I assemble two matrices, ch = ConstraintHandler(dh)
mapping = collect_periodic_facets(grid, "left", "right", (x) -> x - Ferrite.Vec{2}((2.0, 0.0)))
pdbc = PeriodicDirichlet(:c, mapping, [1,])
add!(ch, pdbc)
close!(ch)This so I initially suspected I was creating my constraint handler wrong? Ferrite finally errors out when I try to apply this constraint handler to my matrix: rhs_data = get_rhs_data(ch, A)
apply!(A, ch)But if I run B = allocate_matrix(dh)
_ = get_rhs_data(ch, B)
apply!(B, ch)What am I doing wrong? Any help is much appreciated, so I've a made a small non-working example 😄 for your reference. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
The PeriodicDirichlet object is not stored in the ConstrainHandler, but constraint are still added. I dont think anyone has tried combining PBC with RHSData, so I am not sure if it works. But try Fredriks solution and let us know if that solves your problem. |
Beta Was this translation helpful? Give feedback.

You need to pass the constraint handler to
allocate_matrixbecuase the constraints changes the sparsity pattern in the case of periodic constraints, e.g.The operation
A = M .+ (Δt .* K)results inAhaving different sparsity pattern because some values inMandKare zero, and these indices are not preserved in broadcasting... I don't know what that best way to fix this is, but perhaps buildAlike this instead (which works since we knowMandKhave identical patterns):