1 static char help[] = "Tests 1D Gauss-Lobatto-Legendre discretization on [-1, 1].\n\n"; 2 3 #include <petscdt.h> 4 #include <petscviewer.h> 5 6 int main(int argc,char **argv) 7 { 8 9 PetscInt n = 3,i; 10 PetscReal *la_nodes,*la_weights,*n_nodes,*n_weights; 11 12 PetscFunctionBeginUser; 13 PetscCall(PetscInitialize(&argc,&argv,(char*)0,help)); 14 PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL)); 15 16 PetscCall(PetscMalloc1(n,&la_nodes)); 17 PetscCall(PetscMalloc1(n,&la_weights)); 18 PetscCall(PetscMalloc1(n,&n_nodes)); 19 PetscCall(PetscMalloc1(n,&n_weights)); 20 PetscCall(PetscDTGaussLobattoLegendreQuadrature(n,PETSCGAUSSLOBATTOLEGENDRE_VIA_LINEAR_ALGEBRA,la_nodes,la_weights)); 21 22 PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_SELF,"Gauss-Lobatto-Legendre nodes and weights computed via linear algebra: \n")); 23 PetscCall(PetscRealView(n,la_nodes,PETSC_VIEWER_STDOUT_SELF)); 24 PetscCall(PetscRealView(n,la_weights,PETSC_VIEWER_STDOUT_SELF)); 25 PetscCall(PetscDTGaussLobattoLegendreQuadrature(n,PETSCGAUSSLOBATTOLEGENDRE_VIA_NEWTON,n_nodes,n_weights)); 26 PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_SELF,"Gauss-Lobatto-Legendre nodes and weights computed via Newton: \n")); 27 PetscCall(PetscRealView(n,n_nodes,PETSC_VIEWER_STDOUT_SELF)); 28 PetscCall(PetscRealView(n,n_weights,PETSC_VIEWER_STDOUT_SELF)); 29 30 for (i=0; i<n; i++) { 31 la_nodes[i] -= n_nodes[i]; 32 la_weights[i] -= n_weights[i]; 33 } 34 PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_SELF,"Difference: \n")); 35 PetscCall(PetscRealView(n,la_nodes,PETSC_VIEWER_STDOUT_SELF)); 36 PetscCall(PetscRealView(n,la_weights,PETSC_VIEWER_STDOUT_SELF)); 37 38 PetscCall(PetscFree(la_nodes)); 39 PetscCall(PetscFree(la_weights)); 40 PetscCall(PetscFree(n_nodes)); 41 PetscCall(PetscFree(n_weights)); 42 43 PetscCall(PetscFinalize()); 44 return 0; 45 } 46 47 /*TEST 48 49 test: 50 51 TEST*/ 52