Skip to content

Commit a32533c

Browse files
committed
Add random mesh distribution
1 parent d35073c commit a32533c

File tree

6 files changed

+55
-7
lines changed

6 files changed

+55
-7
lines changed

examples/Hdiv-mixed/conv_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ declare -A run_flags
4444
declare -A test_flags
4545
test_flags[res_start]=2
4646
test_flags[res_stride]=1
47-
test_flags[res_end]=6
47+
test_flags[res_end]=12
4848

4949
file_name=conv_test_result.csv
5050

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
run,mesh_res,error_u,error_p
2-
0,2,0.99085,0.05737
3-
1,3,0.51742,0.03392
4-
2,4,0.30793,0.02117
5-
3,5,0.20227,0.01422
6-
4,6,0.14246,0.01014
2+
0,2,0.85636,0.09544
3+
1,3,0.43484,0.05265
4+
2,4,0.26359,0.03280
5+
3,5,0.17618,0.02214
6+
4,6,0.12591,0.01588
7+
5,7,0.09423,0.01191
8+
6,8,0.07307,0.00925
9+
7,9,0.05826,0.00738
10+
8,10,0.04750,0.00602
11+
9,11,0.03946,0.00501
12+
10,12,0.03328,0.00422
2.64 KB
Loading

examples/Hdiv-mixed/include/setup-dm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
// Setup DM
1212
// ---------------------------------------------------------------------------
1313
PetscErrorCode CreateDM(MPI_Comm comm, VecType vec_type, DM *dm);
14+
PetscErrorCode PerturbVerticesSmooth(DM dm);
1415

1516
#endif // setupdm_h

examples/Hdiv-mixed/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ int main(int argc, char **argv) {
107107
// ---------------------------------------------------------------------------
108108
DM dm;
109109
PetscCall( CreateDM(comm, vec_type, &dm) );
110+
// TODO: add mesh option
111+
// perturb to have smooth random mesh
112+
PetscCall( PerturbVerticesSmooth(dm) );
110113

111114
// ---------------------------------------------------------------------------
112115
// Setup FE

examples/Hdiv-mixed/src/setup-dm.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../include/setup-dm.h"
2+
#include "petscerror.h"
23

34
// ---------------------------------------------------------------------------
45
// Setup DM
@@ -18,4 +19,41 @@ PetscErrorCode CreateDM(MPI_Comm comm, VecType vec_type, DM *dm) {
1819
PetscCall( DMViewFromOptions(*dm, NULL, "-dm_view") );
1920

2021
PetscFunctionReturn(0);
21-
};
22+
};
23+
24+
PetscErrorCode PerturbVerticesSmooth(DM dm) {
25+
26+
Vec coordinates;
27+
PetscSection coordSection;
28+
PetscScalar *coords;
29+
PetscInt v,vStart,vEnd,offset,dim;
30+
PetscReal x,y,z;
31+
32+
PetscFunctionBeginUser;
33+
34+
PetscCall( DMGetDimension(dm, &dim) );
35+
PetscCall( DMGetCoordinateSection(dm, &coordSection) );
36+
PetscCall( DMGetCoordinatesLocal(dm, &coordinates) );
37+
PetscCall( DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd) );
38+
PetscCall( VecGetArray(coordinates,&coords) );
39+
for(v=vStart; v<vEnd; v++) {
40+
PetscCall( PetscSectionGetOffset(coordSection,v,&offset) );
41+
if(dim==2) {
42+
x = coords[offset]; y = coords[offset+1];
43+
coords[offset] = x + 0.06*PetscSinReal(2.0*PETSC_PI*x)*PetscSinReal(
44+
2.0*PETSC_PI*y);
45+
coords[offset+1] = y - 0.05*PetscSinReal(2.0*PETSC_PI*x)*PetscSinReal(
46+
2.0*PETSC_PI*y);
47+
} else {
48+
x = coords[offset]; y = coords[offset+1]; z = coords[offset+2];
49+
coords[offset] = x + 0.03*PetscSinReal(3*PETSC_PI*x)*PetscCosReal(
50+
3*PETSC_PI*y)*PetscCosReal(3*PETSC_PI*z);
51+
coords[offset+1] = y - 0.04*PetscCosReal(3*PETSC_PI*x)*PetscSinReal(
52+
3*PETSC_PI*y)*PetscCosReal(3*PETSC_PI*z);
53+
coords[offset+2] = z + 0.05*PetscCosReal(3*PETSC_PI*x)*PetscCosReal(
54+
3*PETSC_PI*y)*PetscSinReal(3*PETSC_PI*z);
55+
}
56+
}
57+
PetscCall( VecRestoreArray(coordinates,&coords) );
58+
PetscFunctionReturn(0);
59+
}

0 commit comments

Comments
 (0)