Date: 2021-03-03T22:25:51+00:00

Actual source code: simple.c
petsc-3.14.5 2021-03-03
Report Typos and Errors

      2: #include <petsc/private/vecimpl.h>
      3: #include "../src/vec/vec/utils/tagger/impls/simple.h"

      5: PetscErrorCode VecTaggerDestroy_Simple(VecTagger tagger)
      6: {
      7:   VecTagger_Simple *smpl = (VecTagger_Simple *) tagger->data;

     11:   PetscFree (smpl->box);
     12:   PetscFree (tagger->data);
     13:   return(0);
     14: }

     16: PetscErrorCode VecTaggerSetFromOptions_Simple(PetscOptionItems *PetscOptionsObject,VecTagger tagger)
     17: {
     18:   PetscInt       nvals, bs;
     19:   char           headstring[BUFSIZ];
     20:   char           funcstring[BUFSIZ];
     21:   const char     *name;
     22:   PetscBool      set;
     23:   PetscScalar    *inBoxVals;

     27:   PetscObjectGetType((PetscObject)tagger,&name);
     28:   VecTaggerGetBlockSize(tagger,&bs);
     29:   nvals = 2 * bs;
     30:   PetscMalloc1(nvals,&inBoxVals);
     31:   PetscSNPrintf(headstring,BUFSIZ,"VecTagger %s options",name);
     32:   PetscSNPrintf(funcstring,BUFSIZ,"VecTagger%sSetBox()",name);
     33:   PetscOptionsHead(PetscOptionsObject,headstring);
     34:   PetscOptionsScalarArray("-vec_tagger_box","lower and upper bounds of the box",funcstring,inBoxVals,&nvals,&set);
     35:   PetscOptionsTail();
     36:   if (set) {
     37:     if (nvals != 2 *bs) SETERRQ2(PetscObjectComm((PetscObject)tagger),PETSC_ERR_ARG_INCOMP,"Expect array of %D values for -vec_tagger_box, got %D",2 * bs,nvals);
     38:     VecTaggerSetBox_Simple(tagger,(VecTaggerBox *)inBoxVals);
     39:   }
     40:   PetscFree(inBoxVals);
     41:   return(0);
     42: }

     44: PetscErrorCode VecTaggerSetUp_Simple(VecTagger tagger)
     45: {
     46:   VecTagger_Simple *smpl = (VecTagger_Simple *) tagger->data;

     49:   if (!smpl->box) SETERRQ(PetscObjectComm((PetscObject)tagger),PETSC_ERR_ARG_WRONGSTATE,"Must set a box before calling setup.");
     50:   return(0);
     51: }

     53: PetscErrorCode VecTaggerView_Simple(VecTagger tagger, PetscViewer viewer)
     54: {
     55:   VecTagger_Simple *smpl = (VecTagger_Simple *) tagger->data;
     56:   PetscBool        iascii;
     57:   PetscErrorCode   ierr;

     60:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
     61:   if (iascii) {
     62:     PetscInt bs, i;
     63:     const char *name;

     65:     PetscObjectGetType((PetscObject)tagger,&name);
     66:     VecTaggerGetBlockSize(tagger,&bs);
     67:     PetscViewerASCIIPrintf(viewer," %s box=[",name);
     68:     for (i = 0; i < bs; i++) {
     69:       if (i) {PetscViewerASCIIPrintf(viewer,"; ");}
     70: #if !defined(PETSC_USE_COMPLEX)
     71:       PetscViewerASCIIPrintf(viewer,"%g,%g",(double)smpl->box[i].min,(double)smpl->box[i].max);
     72: #else
     73:       PetscViewerASCIIPrintf(viewer,"%g+%gi,%g+%gi",(double)PetscRealPart(smpl->box[i].min),(double)PetscImaginaryPart(smpl->box[i].min),(double)PetscRealPart(smpl->box[i].max),(double)PetscImaginaryPart(smpl->box[i].max));
     74: #endif
     75:     }
     76:     PetscViewerASCIIPrintf(viewer,"]\n");
     77:   }
     78:   return(0);
     79: }

     81: PetscErrorCode VecTaggerSetBox_Simple(VecTagger tagger,VecTaggerBox *box)
     82: {
     83:   VecTagger_Simple *smpl = (VecTagger_Simple *) tagger->data;

     89:   if (box != smpl->box) {
     90:     PetscInt bs, i;

     92:     VecTaggerGetBlockSize(tagger,&bs);
     93:     PetscFree(smpl->box);
     94:     PetscMalloc1(bs,&(smpl->box));
     95:     for (i = 0; i < bs; i++) smpl->box[i] = box[i];
     96:   }
     97:   return(0);
     98: }

    100: PetscErrorCode VecTaggerGetBox_Simple(VecTagger tagger,const VecTaggerBox **box)
    101: {
    102:   VecTagger_Simple *smpl = (VecTagger_Simple *) tagger->data;

    107:   *box = smpl->box;
    108:   return(0);
    109: }

    111: PetscErrorCode VecTaggerCreate_Simple(VecTagger tagger)
    112: {
    113:   VecTagger_Simple *smpl;
    114:   PetscErrorCode     ierr;

    117:   tagger->ops->destroy          = VecTaggerDestroy_Simple;
    118:   tagger->ops->setfromoptions   = VecTaggerSetFromOptions_Simple;
    119:   tagger->ops->setup            = VecTaggerSetUp_Simple;
    120:   tagger->ops->view             = VecTaggerView_Simple;
    121:   tagger->ops->computeis        = VecTaggerComputeIS_FromBoxes;
    122:   PetscNewLog(tagger,&smpl);
    123:   tagger->data = smpl;
    124:   return(0);
    125: }