Lisandro Dalcin avatar Lisandro Dalcin committed 7b14e15

Fix IGAAxisSetKnots() to require the array of knots

Comments (0)

Files changed (4)

 PETSC_EXTERN PetscErrorCode IGAAxisGetPeriodic(IGAAxis axis,PetscBool *periodic);
 PETSC_EXTERN PetscErrorCode IGAAxisSetDegree(IGAAxis axis,PetscInt p);
 PETSC_EXTERN PetscErrorCode IGAAxisGetDegree(IGAAxis axis,PetscInt *p);
-PETSC_EXTERN PetscErrorCode IGAAxisSetKnots(IGAAxis axis,PetscInt m,PetscReal U[]);
+PETSC_EXTERN PetscErrorCode IGAAxisSetKnots(IGAAxis axis,PetscInt m,const PetscReal U[]);
 PETSC_EXTERN PetscErrorCode IGAAxisGetKnots(IGAAxis axis,PetscInt *m,PetscReal *U[]);
 PETSC_EXTERN PetscErrorCode IGAAxisGetLimits(IGAAxis axis,PetscReal *Ui,PetscReal *Uf);
 PETSC_EXTERN PetscErrorCode IGAAxisGetSizes(IGAAxis axis,PetscInt *nel,PetscInt *nnp);
 
 #undef  __FUNCT__
 #define __FUNCT__ "IGAAxisSetKnots"
-PetscErrorCode IGAAxisSetKnots(IGAAxis axis,PetscInt m,PetscReal U[])
+PetscErrorCode IGAAxisSetKnots(IGAAxis axis,PetscInt m,const PetscReal U[])
 {
   PetscInt       k;
-  PetscReal      *V = 0;
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidPointer(axis,1);
-  if (U) PetscValidPointer(U,3);
+  PetscValidPointer(U,3);
 
   if (axis->p < 1)
     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,
             "Must call IGAAxisSetDegree() first");
   if (m < 2*axis->p+1)
     SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,
-             "Number of knots must be at least %D, got %D",2*(axis->p+1),m+1);
-  if (U) for (k=1; k<=m; k++)
-           if (U[k-1] > U[k])
-             SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,
-                      "Knot sequence must be increasing, "
-                      "got U[%D]=%G > U[%D]=%G",
-                      k-1,U[k-1],k,U[k]);
+             "Number of knots must be at least %D, got %D",
+             2*(axis->p+1),m+1);
+  for (k=1; k<=m; k++)
+    if (U[k-1] > U[k])
+      SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,
+               "Knot sequence must be increasing, got U[%D]=%G > U[%D]=%G",
+               k-1,U[k-1],k,U[k]);
 
-  if (m != axis->m || !axis->U) {
+  if (m != axis->m) {
+    PetscReal *V;
     ierr = PetscMalloc((m+1)*sizeof(PetscReal),&V);CHKERRQ(ierr);
-    ierr = PetscMemzero(V,(m+1)*sizeof(PetscReal));CHKERRQ(ierr);
     ierr = PetscFree(axis->U);CHKERRQ(ierr);
     axis->m = m;
     axis->U = V;
   }
-  if (U) { ierr = PetscMemcpy(axis->U,U,(m+1)*sizeof(PetscReal));CHKERRQ(ierr); }
+  ierr = PetscMemcpy(axis->U,U,(m+1)*sizeof(PetscReal));CHKERRQ(ierr);
 
   axis->nel = axis->nnp = 0;
   ierr = PetscFree(axis->span);CHKERRQ(ierr);
   { /* */
     PetscInt info = 0;
     ierr = PetscViewerBinaryRead(viewer,&info,1,PETSC_INT);CHKERRQ(ierr);
-    geometry = (info & 0x1) ? PETSC_TRUE : PETSC_FALSE; 
+    geometry = (info & 0x1) ? PETSC_TRUE : PETSC_FALSE;
     property = (info & 0x2) ? PETSC_TRUE : PETSC_FALSE;
   }
   ierr = IGAReset(iga);CHKERRQ(ierr);
       PetscReal *U;
       ierr = PetscViewerBinaryRead(viewer,&p,1,PETSC_INT);CHKERRQ(ierr);
       ierr = PetscViewerBinaryRead(viewer,&m,1,PETSC_INT);CHKERRQ(ierr);
+      ierr = PetscMalloc1(m,PetscReal,&U);CHKERRQ(ierr);
+      ierr = PetscViewerBinaryRead(viewer,U,m,PETSC_REAL);CHKERRQ(ierr);
       ierr = IGAGetAxis(iga,i,&axis);CHKERRQ(ierr);
       ierr = IGAAxisSetDegree(axis,p);CHKERRQ(ierr);CHKERRQ(ierr);
-      ierr = IGAAxisSetKnots(axis,m-1,PETSC_NULL);CHKERRQ(ierr);CHKERRQ(ierr);
-      ierr = IGAAxisGetKnots(axis,PETSC_NULL,&U);CHKERRQ(ierr);CHKERRQ(ierr);
-      ierr = PetscViewerBinaryRead(viewer,U,m,PETSC_REAL);CHKERRQ(ierr);
+      ierr = IGAAxisSetKnots(axis,m-1,U);CHKERRQ(ierr);CHKERRQ(ierr);
+      ierr = PetscFree(U);CHKERRQ(ierr);
     }
   }
   ierr = IGASetUp_Basic(iga);CHKERRQ(ierr);
 CFLAGS          = #-g3 -Wall -Wextra -Wno-unused-parameter #-Wconversion
 FFLAGS          = #-g3 -Wall -Wextra -fcheck=all
 CPPFLAGS        =
-FPPFLAGS        = 
+FPPFLAGS        =
 LOCDIR          = test/
 EXAMPLESC       = Test_SNES_2D.c
-EXAMPLESF       = 
+EXAMPLESF       =
 MANSEC          = IGA
 
 topdir := $(shell cd .. && pwd)
 	-@${MPIEXEC} -n 8 ./IGACreate ${OPTS} -iga_dim 3 -iga_dof 2
 runex1b_seq:
 	-@${MPIEXEC} -n 1 ./IGACreate ${OPTS} -iga_dim 2 -iga_dof 3 -iga_periodic 0,1 -iga_degree 2,3
-	-@${MPIEXEC} -n 1 ./IGACreate ${OPTS} -iga_dim 2 -iga_dof 3 -iga_periodic 1,0 -iga_degree 2,3 
+	-@${MPIEXEC} -n 1 ./IGACreate ${OPTS} -iga_dim 2 -iga_dof 3 -iga_periodic 1,0 -iga_degree 2,3
 	-@${MPIEXEC} -n 1 ./IGACreate ${OPTS} -iga_dim 2 -iga_dof 3 -iga_periodic 1,1 -iga_degree 2,3
 runex1b_mpi:
 	-@${MPIEXEC} -n 4 ./IGACreate ${OPTS} -iga_dim 2 -iga_dof 5 -iga_periodic 0,0,1 -iga_degree 4,3
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.