PetscErrorCode Parameter_settings(AppCtx *user) { PetscErrorCode ierr; PetscBool flg; PetscFunctionBeginUser; /* Set default parameters */ user->ws = 1.0; user->H = 5.0; user->Pmax = 2.1; user->PM_min = 1.0; user->lambda = 0.1; user->q = 1.0; user->mux = asin(user->PM_min/user->Pmax); user->sigmax = 0.1; user->sigmay = 0.1; user->rho = 0.0; user->xmin = -PETSC_PI; user->xmax = PETSC_PI; user->bx = DMDA_BOUNDARY_PERIODIC; user->by = DMDA_BOUNDARY_MIRROR; user->nonoiseinitial = PETSC_FALSE; /* ymin of -3 seems to let the unstable solution move up and leave a zero in its wake with an ymin of -1 the wake is never exactly zero */ user->ymin = -3.0; user->ymax = 10.0; user->st_width = 1; ierr = PetscOptionsGetScalar(NULL,"-ws",&user->ws,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-Inertia",&user->H,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-Pmax",&user->Pmax,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-PM_min",&user->PM_min,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-lambda",&user->lambda,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-q",&user->q,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-mux",&user->mux,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-sigmax",&user->sigmax,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-muy",&user->muy,&flg);CHKERRQ(ierr); if (flg == 0) { user->muy = user->ws; } ierr = PetscOptionsGetScalar(NULL,"-sigmay",&user->sigmay,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-rho",&user->rho,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-xmin",&user->xmin,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-xmax",&user->xmax,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-ymin",&user->ymin,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-ymax",&user->ymax,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,"-stencil_width",&user->st_width,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetEnum(NULL,"-bx",DMDABoundaryTypes,(PetscEnum*)&user->bx,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetEnum(NULL,"-by",DMDABoundaryTypes,(PetscEnum*)&user->by,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetBool(NULL,"-nonoiseinitial",&user->nonoiseinitial,&flg);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode Parameter_settings(AppCtx *user) { PetscErrorCode ierr; PetscBool flg; PetscFunctionBeginUser; /* Set default parameters */ user->ws = 1.0; user->H = 5.0; user->D = 0.0; user->Pmax = user->Pmax_s = 2.1; user->PM_min = 1.0; user->lambda = 0.1; user->q = 1.0; user->mux = PetscAsinScalar(user->PM_min/user->Pmax); user->sigmax = 0.1; user->sigmay = 0.1; user->rho = 0.0; user->xmin = -PETSC_PI; user->xmax = PETSC_PI; user->bx = DM_BOUNDARY_PERIODIC; user->by = DM_BOUNDARY_GHOSTED; user->tf = user->tcl = -1; user->ymin = -2.0; user->ymax = 2.0; user->st_width = 1; ierr = PetscOptionsGetScalar(NULL,"-ws",&user->ws,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-Inertia",&user->H,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-D",&user->D,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-Pmax",&user->Pmax,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-PM_min",&user->PM_min,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-lambda",&user->lambda,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-q",&user->q,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-mux",&user->mux,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-muy",&user->muy,&flg);CHKERRQ(ierr); if (flg == 0) { user->muy = user->ws; } ierr = PetscOptionsGetScalar(NULL,"-xmin",&user->xmin,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-xmax",&user->xmax,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-ymin",&user->ymin,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,"-ymax",&user->ymax,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,"-stencil_width",&user->st_width,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetEnum("","-bx",BoundaryTypes,(PetscEnum*)&user->bx,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetEnum("","-by",BoundaryTypes,(PetscEnum*)&user->by,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetReal(NULL,"-tf",&user->tf,&flg);CHKERRQ(ierr); ierr = PetscOptionsGetReal(NULL,"-tcl",&user->tcl,&flg);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode PetscP4estInitialize(void) { PetscBool psc_catch_signals = PETSC_FALSE; PetscBool psc_print_backtrace = PETSC_TRUE; int psc_log_threshold = SC_LP_DEFAULT; int pp4est_log_threshold = SC_LP_DEFAULT; char logList[256], *className; PetscBool opt; PetscErrorCode ierr; PetscFunctionBegin; if (PetscP4estInitialized) PetscFunctionReturn(0); PetscP4estInitialized = PETSC_TRUE; ierr = PetscClassIdRegister("p4est logging",&P4ESTLOGGING_CLASSID);CHKERRQ(ierr); ierr = PetscOptionsGetString(NULL,NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); if (opt) { ierr = PetscStrstr(logList, "p4est", &className);CHKERRQ(ierr); if (className) { ierr = PetscInfoDeactivateClass(P4ESTLOGGING_CLASSID);CHKERRQ(ierr); } } ierr = PetscHeaderCreate(P4estLoggingObject,P4ESTLOGGING_CLASSID,"p4est","p4est logging","DM",PETSC_COMM_WORLD,NULL,PetscObjectView);CHKERRQ(ierr); if (sc_package_id == -1) { int log_threshold_shifted = psc_log_threshold + 1; PetscBool set; PetscBeganSc = PETSC_TRUE; ierr = PetscOptionsGetBool(NULL,NULL,"-petsc_sc_catch_signals",&psc_catch_signals,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetBool(NULL,NULL,"-petsc_sc_print_backtrace",&psc_print_backtrace,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetEnum(NULL,NULL,"-petsc_sc_log_threshold",SCLogTypes,(PetscEnum*)&log_threshold_shifted,&set);CHKERRQ(ierr); if (set) psc_log_threshold = log_threshold_shifted - 1; sc_init(PETSC_COMM_WORLD,(int)psc_catch_signals,(int)psc_print_backtrace,PetscScLogHandler,psc_log_threshold); if (sc_package_id == -1) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_LIB,"Could not initialize libsc package used by p4est"); sc_set_abort_handler(PetscScAbort); } if (p4est_package_id == -1) { int log_threshold_shifted = pp4est_log_threshold + 1; PetscBool set; ierr = PetscOptionsGetEnum(NULL,NULL,"-petsc_p4est_log_threshold",SCLogTypes,(PetscEnum*)&log_threshold_shifted,&set);CHKERRQ(ierr); if (set) pp4est_log_threshold = log_threshold_shifted - 1; PetscStackCallP4est(p4est_init,(PetscScLogHandler,pp4est_log_threshold)); if (p4est_package_id == -1) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_LIB,"Could not initialize p4est"); } ierr = DMForestRegisterType(DMP4EST);CHKERRQ(ierr); ierr = DMForestRegisterType(DMP8EST);CHKERRQ(ierr); ierr = PetscRegisterFinalize(PetscP4estFinalize);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscBagRegisterEnum - add an enum value to the bag Logically Collective on PetscBag Input Parameter: + bag - the bag of values . addr - location of enum in struct . mdefault - the initial value . list - array of strings containing names of enum values followed by enum name followed by enum prefix - help - longer string with more information about the value Level: beginner .seealso: PetscBag, PetscBagSetName(), PetscBagView(), PetscBagLoad(), PetscBagGetData() PetscBagRegisterInt(), PetscBagRegisterBool(), PetscBagRegisterScalar() PetscBagSetFromOptions(), PetscBagCreate(), PetscBagGetName() @*/ PetscErrorCode PetscBagRegisterEnum(PetscBag bag,void *addr,const char *const *list,PetscEnum mdefault, const char *name, const char *help) { PetscErrorCode ierr; PetscBagItem item; char nname[PETSC_BAG_NAME_LENGTH+1]; PetscBool printhelp; PetscInt i = 0; PetscFunctionBegin; nname[0] = '-'; nname[1] = 0; ierr = PetscStrncat(nname,name,PETSC_BAG_NAME_LENGTH-1);CHKERRQ(ierr); ierr = PetscOptionsHasName(NULL,"-help",&printhelp);CHKERRQ(ierr); if (printhelp) { while (list[i++]) ; ierr = (*PetscHelpPrintf)(bag->bagcomm," -%s%s <%s>: (%s) %s (choose one of) ",bag->bagprefix ? bag->bagprefix : "",name,list[mdefault],list[i-3],help);CHKERRQ(ierr); for (i=0; list[i+2]; i++) { ierr = (*PetscHelpPrintf)(bag->bagcomm," %s",list[i]);CHKERRQ(ierr); } ierr = (*PetscHelpPrintf)(bag->bagcomm,"\n");CHKERRQ(ierr); } ierr = PetscOptionsGetEnum(bag->bagprefix,nname,list,&mdefault,NULL);CHKERRQ(ierr); ierr = PetscNew(&item);CHKERRQ(ierr); item->dtype = PETSC_ENUM; item->offset = ((char*)addr) - ((char*)bag); if (item->offset > bag->bagsize) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Registered item %s %s is not in bag memory space",name,help); item->next = 0; item->msize = 1; ierr = PetscStrArrayallocpy(list,(char***)&item->list);CHKERRQ(ierr); *(PetscEnum*)addr = mdefault; ierr = PetscBagRegister_Private(bag,item,name,help);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ PetscDrawLGSetFromOptions - Sets options related to the PetscDrawLG Collective on PetscDrawLG Options Database: Level: intermediate Concepts: line graph^creating .seealso: PetscDrawLGDestroy(), PetscDrawLGCreate() @*/ PetscErrorCode PetscDrawLGSetFromOptions(PetscDrawLG lg) { PetscErrorCode ierr; PetscBool usemarkers,set; PetscDrawMarkerType markertype; PetscFunctionBegin; PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1); ierr = PetscDrawGetMarkerType(lg->win,&markertype);CHKERRQ(ierr); ierr = PetscOptionsGetEnum(((PetscObject)lg)->options,((PetscObject)lg)->prefix,"-lg_marker_type",PetscDrawMarkerTypes,(PetscEnum*)&markertype,&set);CHKERRQ(ierr); if (set) { ierr = PetscDrawLGSetUseMarkers(lg,PETSC_TRUE);CHKERRQ(ierr); ierr = PetscDrawSetMarkerType(lg->win,markertype);CHKERRQ(ierr); } usemarkers = lg->use_markers; ierr = PetscOptionsGetBool(((PetscObject)lg)->options,((PetscObject)lg)->prefix,"-lg_use_markers",&usemarkers,&set);CHKERRQ(ierr); if (set) {ierr = PetscDrawLGSetUseMarkers(lg,usemarkers);CHKERRQ(ierr);} PetscFunctionReturn(0); }
/*@ PetscCommBuildTwoSidedGetType - set algorithm to use when building two-sided communication Logically Collective Output Arguments: + comm - communicator on which to query algorithm - twosided - algorithm to use for PetscCommBuildTwoSided() Level: developer .seealso: PetscCommBuildTwoSided(), PetscCommBuildTwoSidedSetType() @*/ PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm comm,PetscBuildTwoSidedType *twosided) { PetscErrorCode ierr; PetscFunctionBegin; *twosided = PETSC_BUILDTWOSIDED_NOTSET; if (_twosided_type == PETSC_BUILDTWOSIDED_NOTSET) { #if defined(PETSC_HAVE_MPI_IBARRIER) # if defined(PETSC_HAVE_MPICH_CH3_SOCK) && !defined(PETSC_HAVE_MPICH_CH3_SOCK_FIXED_NBC_PROGRESS) /* Deadlock in Ibarrier: http://trac.mpich.org/projects/mpich/ticket/1785 */ _twosided_type = PETSC_BUILDTWOSIDED_ALLREDUCE; # else _twosided_type = PETSC_BUILDTWOSIDED_IBARRIER; # endif #else _twosided_type = PETSC_BUILDTWOSIDED_ALLREDUCE; #endif ierr = PetscOptionsGetEnum(NULL,"-build_twosided",PetscBuildTwoSidedTypes,(PetscEnum*)&_twosided_type,NULL);CHKERRQ(ierr); } *twosided = _twosided_type; PetscFunctionReturn(0); }
int main(int argc,char **argv) { PetscMPIInt rank; PetscInt M = 13,s=1,dof=1; DMDABoundaryType bx = DMDA_BOUNDARY_PERIODIC; PetscErrorCode ierr; DM da; PetscViewer viewer; Vec local,global; PetscScalar value; PetscDraw draw; PetscBool flg = PETSC_FALSE; ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); /* Create viewers */ ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",280,480,600,200,&viewer);CHKERRQ(ierr); ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr); ierr = PetscDrawSetDoubleBuffer(draw);CHKERRQ(ierr); /* Readoptions */ ierr = PetscOptionsGetInt(NULL,"-M",&M,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetEnum(NULL,"-wrap",DMDABoundaryTypes,(PetscEnum*)&bx,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,"-dof",&dof,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,"-s",&s,NULL);CHKERRQ(ierr); /* Create distributed array and get vectors */ ierr = DMDACreate1d(PETSC_COMM_WORLD,bx,M,dof,s,NULL,&da);CHKERRQ(ierr); ierr = DMView(da,viewer);CHKERRQ(ierr); ierr = DMCreateGlobalVector(da,&global);CHKERRQ(ierr); ierr = DMCreateLocalVector(da,&local);CHKERRQ(ierr); /* Set global vector; send ghost points to local vectors */ value = 1; ierr = VecSet(global,value);CHKERRQ(ierr); ierr = DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);CHKERRQ(ierr); ierr = DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);CHKERRQ(ierr); /* Scale local vectors according to processor rank; pass to global vector */ ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); value = rank+1; ierr = VecScale(local,value);CHKERRQ(ierr); ierr = DMLocalToGlobalBegin(da,local,INSERT_VALUES,global);CHKERRQ(ierr); ierr = DMLocalToGlobalEnd(da,local,INSERT_VALUES,global);CHKERRQ(ierr); ierr = VecView(global,viewer);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nGlobal Vector:\n");CHKERRQ(ierr); ierr = VecView(global,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\n");CHKERRQ(ierr); /* Send ghost points to local vectors */ ierr = DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);CHKERRQ(ierr); ierr = DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);CHKERRQ(ierr); ierr = PetscOptionsGetBool(NULL,"-local_print",&flg,NULL);CHKERRQ(ierr); if (flg) { PetscViewer sviewer; ISLocalToGlobalMapping is; ierr = PetscViewerASCIISynchronizedAllow(PETSC_VIEWER_STDOUT_WORLD,PETSC_TRUE);CHKERRQ(ierr); ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,"\nLocal Vector: processor %d\n",rank);CHKERRQ(ierr); ierr = PetscViewerGetSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);CHKERRQ(ierr); ierr = VecView(local,sviewer);CHKERRQ(ierr); ierr = PetscViewerRestoreSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);CHKERRQ(ierr); ierr = PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);CHKERRQ(ierr); ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,"\nLocal to global mapping: processor %d\n",rank);CHKERRQ(ierr); ierr = PetscViewerGetSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);CHKERRQ(ierr); ierr = DMGetLocalToGlobalMapping(da,&is);CHKERRQ(ierr); ierr = ISLocalToGlobalMappingView(is,sviewer);CHKERRQ(ierr); ierr = PetscViewerRestoreSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);CHKERRQ(ierr); ierr = PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);CHKERRQ(ierr); } /* Free memory */ ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); ierr = VecDestroy(&global);CHKERRQ(ierr); ierr = VecDestroy(&local);CHKERRQ(ierr); ierr = DMDestroy(&da);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }