Actual source code: cmesh.c

  1: #define PETSCVEC_DLL

 3:  #include petscvec.h


  8: /*@
  9:     VecContourScale - Prepares a vector of values to be plotted using 
 10:     the PetscDrawTriangle() contour plotter.

 12:     Collective on Vec

 14:     Input Parameters:
 15: +   v - the vector of values
 16: .   vmin - minimum value (for lowest color)
 17: -   vmax - maximum value (for highest color)

 19:    Level: intermediate

 21: .seealso: PetscDrawTensorContour(),PetscDrawTensorContourPatch()

 23: @*/
 24: PetscErrorCode PETSCVEC_DLLEXPORT VecContourScale(Vec v,PetscReal vmin,PetscReal vmax)
 25: {
 26:   PetscScalar    *values;
 28:   PetscInt       n,i;
 29:   PetscReal      scale;


 34:   if (PetscAbsReal(vmax - vmin) < 1.e-50) {
 35:      scale = 1.0;
 36:   } else {
 37:     scale = (245.0 - PETSC_DRAW_BASIC_COLORS)/(vmax - vmin);
 38:   }

 40:   VecGetLocalSize(v,&n);
 41:   VecGetArray(v,&values);
 42:   for (i=0; i<n; i++) {
 43:     values[i] = (PetscReal)PETSC_DRAW_BASIC_COLORS + scale*(values[i] - vmin);
 44:   }
 45:   VecRestoreArray(v,&values);

 47:   return(0);
 48: }