Commits

Debojyoti Ghosh committed 432e1e3

Bugfix in IJacobians of Hull problem c1 and c2 in TS ex31.c

Comments (0)

Files changed (1)

src/ts/examples/tutorials/ex31.c

   PetscInt  i;
   PetscInt  col[2];
   PetscReal value[2];
+  i = 0;
+  value[0] = a+1; col[0] = 0;
+  value[1] =  0;  col[1] = 1;
+  ierr = MatSetValues(*A,1,&i,2,col,value,INSERT_VALUES);CHKERRQ(ierr);
   for (i = 0; i < N; i++) {
-    if (i == 0) {
-      value[0] = a-1; col[0] = i;
-      value[1] =  0;  col[1] = i+1;
-    } else if (i == N-1) {
-      value[0] = -1;  col[0] = i-1;
-      value[1] =  a;  col[1] = i;
-    } else { 
-      value[0] =  -1; col[0] = i-1;
-      value[1] = a+1; col[1] = i;
-    }
+    value[0] =  -1; col[0] = i-1;
+    value[1] = a+1; col[1] = i;
     ierr = MatSetValues(*A,1,&i,2,col,value,INSERT_VALUES);CHKERRQ(ierr);
   }
+  i = N-1;
+  value[0] = -1;  col[0] = N-2;
+  value[1] = a;   col[1] = N-1;
+  ierr = MatSetValues(*A,1,&i,2,col,value,INSERT_VALUES);CHKERRQ(ierr);
   ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
   ierr = MatAssemblyEnd  (*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
   ierr = VecRestoreArray(Y,&y);CHKERRQ(ierr);
   PetscInt  i;
   PetscInt  col[2];
   PetscReal value[2];
+  i = 0;
+  value[0] = a+1;                 col[0] = 0;
+  value[1] = 0;                   col[1] = 1;
+  ierr = MatSetValues(*A,1,&i,2,col,value,INSERT_VALUES);CHKERRQ(ierr);
   for (i = 0; i < N; i++) {
-    if (i == 0) {
-      value[0] = a-(PetscReal)(-i-1); col[0] = i;
-      value[1] = 0;                   col[1] = i+1;
-    } else if (i == N-1) {
-      value[0] = -(PetscReal) i;      col[0] = i-1;
-      value[1] = a;                   col[1] = i;
-    } else { 
-      value[0] = -(PetscReal) i;      col[0] = i-1;
-      value[1] = a-(PetscReal)(-1-1); col[1] = i;
-    }
+    value[0] = -(PetscReal) i;      col[0] = i-1;
+    value[1] = a+(PetscReal)(i+1);  col[1] = i;
     ierr = MatSetValues(*A,1,&i,2,col,value,INSERT_VALUES);CHKERRQ(ierr);
   }
+  i = N-1;
+  value[0] = -(PetscReal) (N-1);  col[0] = N-2;
+  value[1] = a;                   col[1] = N-1;
+  ierr = MatSetValues(*A,1,&i,2,col,value,INSERT_VALUES);CHKERRQ(ierr);
   ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
   ierr = MatAssemblyEnd  (*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
   ierr = VecRestoreArray(Y,&y);CHKERRQ(ierr);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.