simulkade / JFVM.jl

A simple finite volume tool for Julia
Other
43 stars 13 forks source link

"solvePDE" function broken #9

Open SA8416 opened 2 years ago

SA8416 commented 2 years ago

It seems the "solvePDE" set of functions cause my terminal to crash when attempting to solve a PDE. The error I receive is:

The terminal process "D:\Programs\Julia-1.8.0\bin\julia.exe '--color=yes', '--startup-file=no', '--history-file=no', '--project=d:\Github\CRUD.jl', 'c:\Users\sa8416.vscode\extensions\julialang.language-julia-1.7.6\scripts\debugger\run_debugger.jl', '\.\pipe\vsc-jl-dbg-9aa81c39-1399-435d-9fb6-f07804f28e12', '\.\pipe\vsc-jl-cr-e272cddf-e589-4ef3-9716-a35a7693db3e'" terminated with exit code: 1.

Edit: It seems the issue lies in the matrix of coefficients 'M' being a sparse matrix, temporary fix is to convert it to a dense matrix:

x=(collect(M))\RHS

simulkade commented 2 years ago

Hi @SA8416 , let me investigate it and come back to you. Converting M to a dense matrix is not a memory-efficient fix. I will come back with a better solution.

simulkade commented 2 years ago

I cannot reproduce this error with the master branch of JFVM and julia 1.8

using JFVM #, JFVMvis
function diff()
    Nx = 10
    Lx = 1.0
    m = createMesh1D(Nx, Lx)
    BC = createBC(m)
    BC.left.a[:].=BC.right.a[:].=0.0
    BC.left.b[:].=BC.right.b[:].=1.0
    BC.left.c[:].=1.0
    BC.right.c[:].=0.0
    c_init = 0.0 # initial value of the variable
    c_old = createCellVariable(m, 0.0, BC)
    D_val = 1.0 # value of the diffusion coefficient
    D_cell = createCellVariable(m, D_val) # assigned to cells
    # Harmonic average
    D_face = harmonicMean(D_cell)
    N_steps = 20 # number of time steps
    dt= sqrt(Lx^2/D_val)/N_steps # time step
    M_diff = diffusionTerm(D_face) # matrix of coefficient for diffusion term
    (M_bc, RHS_bc)=boundaryConditionTerm(BC) # matrix of coefficient and RHS for the BC
    for i =1:5
        (M_t, RHS_t)=transientTerm(c_old, dt, 1.0)
        M=M_t-M_diff+M_bc # add all the [sparse] matrices of coefficient
        RHS=RHS_bc+RHS_t # add all the RHS's together
        c_old = solveLinearPDE(m, M, RHS) # solve the PDE
    end
    return c_old
    #visualizeCells(c_old)
end

diff()
SA8416 commented 2 years ago

Strange, even after re-installing julia the error seems to persist- I have found a more memory-efficient workaround by using the LinearSolve.jl package instead of the julia "\" solver.

simulkade commented 2 years ago

a more memory-efficient workaround by using the LinearSolve.jl package

Very good idea. Let me know if it is faster too. I saw a talk about this package and it is nice to use it instead of the default Julia backslash solver.