JordiManyer / upa

FEM library for Plasma Physics and Confinement Fusion.
1 stars 0 forks source link

1D Laplace FEM not working for some problem sizes #8

Open JordiManyer opened 3 years ago

JordiManyer commented 3 years ago

In the implementation of 1D Laplace, in file src/Tests/v0_Laplace1D, there is an allocation error in the mesh when the number of elements per side in an even number.

Lines 18 to 21 of the file are as follows:

    int dim = 1;
    ElemType type = ElemType::Line;

    auto* mesh = new StructuredMesh();
    mesh->produceCartesian(dim,11,type);

In the last line, if 11 is the number of elements per side the created cartesian mesh will have (the mesh is the line [0,1], divided into as many elements as the number states. If 11 is changed to any other odd number (13, 19, 21, ....) the code will run as intended. However, if the number of elements is changed to an even number (10, 12, 8, ...) the code will give a malloc error when allocating the arrays in the mesh.

For 12, the output is as follows

Selected rows: 
0 1 1 1 1 1 1 1 1 1 1 1 0 
Complete matrix: 
    24    -12    0    0    0    0    0    0    0    0    0
    -12    24    -12    0    0    0    0    0    0    0    0
    0    -12    24    -12    0    0    0    0    0    0    0
    0    0    -12    24    -12    0    0    0    0    0    0
    0    0    0    -12    24    -12    0    0    0    0    0
    0    0    0    0    -12    24    -12    0    0    0    0
    0    0    0    0    0    -12    24    -12    0    0    0
    0    0    0    0    0    0    -12    24    -12    0    0
    0    0    0    0    0    0    0    -12    24    -12    0
    0    0    0    0    0    0    0    0    -12    24    -12
    0    0    0    0    0    0    0    0    0    -12    24

Complete Vector: 
    0.0833333    0.0833333    0.0833333    0.0833333    0.0833333    0.0833333    0.0833333    0.0833333    0.0833333    0.0833333    0.0833333
malloc(): corrupted top size

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

I do not know why this happens. Why is it doing this?