lyc102 / ifem

iFEM is a MATLAB software package containing robust, efficient, and easy-following codes for the main building blocks of adaptive finite element methods on unstructured simplicial grids in both two and three dimensions.
https://lyc102.github.io/ifem/
GNU General Public License v3.0
185 stars 73 forks source link

`Uniformrefine3` unfavorable behavior after update in `cubemesh` #8

Open scaomath opened 2 years ago

scaomath commented 2 years ago

Problem

In 842ba40a497cc7aeb2d3293f6dd54082818b5cb4 commit, the loop ordering of the cubemesh is changed such that the elem generated by it will have a nice ascending ordering in both rows and columns. For example

[node, elem] = cubemesh([-1,1,-1,1,-1,1],1);

gives

elem =
     1     4     5    14
     1     2     5    14
     1    10    13    14
     1    10    11    14
     1     4    13    14
     1     2    11    14
     2     5     6    15
     2     3     6    15
     2    11    14    15
     2    11    12    15
     2     5    14    15
     2     3    12    15
     4     7     8    17
     4     5     8    17
     4    13    16    17
     4    13    14    17
     4     7    16    17
     4     5    14    17
     5     8     9    18
     5     6     9    18
     5    14    17    18
     5    14    15    18
     5     8    17    18
     5     6    15    18
    10    13    14    23
    10    11    14    23
    10    19    22    23
    10    19    20    23
    10    13    22    23
    10    11    20    23
    11    14    15    24
    11    12    15    24
    11    20    23    24
    11    20    21    24
    11    14    23    24
    11    12    21    24
    13    16    17    26
    13    14    17    26
    13    22    25    26
    13    22    23    26
    13    16    25    26
    13    14    23    26
    14    17    18    27
    14    15    18    27
    14    23    26    27
    14    23    24    27
    14    17    26    27
    14    15    24    27

Visualizing the elements by a six-element group we will have mesh1

However, if we do from cubemesh then uniformrefine3, the ascending ordering is gone.

[node,elem] = cubemesh([-1,1,-1,1,-1,1],2);
[node,elem] = uniformrefine3(node,elem);

gives

elem =
     1    10    11    15
     1     9    11    15
     1    12    14    15
     1    12    13    15
     1    10    14    15
     1     9    13    15
    10     3    19    21
     9     2    16    18
    12     5    24    25
    12     5    23    25
    10     3    20    21
     9     2    17    18
    11    19     4    22
    11    16     4    22
    14    24     7    27
    13    23     6    26
    14    20     7    27
    13    17     6    26
    15    21    22     8
    15    18    22     8
    15    25    27     8
    15    25    26     8
    15    21    27     8
    15    18    26     8
    10    11    15    21
     9    11    15    18
    12    14    15    25
    12    13    15    25
    10    14    15    21
     9    13    15    18
    10    11    19    21
     9    11    16    18
    12    14    24    25
    12    13    23    25
    10    14    20    21
     9    13    17    18
    11    15    21    22
    11    15    18    22
    14    15    25    27
    13    15    25    26
    14    15    21    27
    13    15    18    26
    11    19    21    22
    11    16    18    22
    14    24    25    27
    13    23    25    26
    14    20    21    27
    13    17    18    26

and visualizing the refined elements by 6-element groups yields something like the following: mesh2

Potential solution

scaomath commented 2 years ago

Assigned myself to fix this.