/*@ TSAdaptCreate - create an adaptive controller context for time stepping Collective on MPI_Comm Input Parameter: . comm - The communicator Output Parameter: . adapt - new TSAdapt object Level: developer Notes: TSAdapt creation is handled by TS, so users should not need to call this function. .keywords: TSAdapt, create .seealso: TSGetAdapt(), TSAdaptSetType(), TSAdaptDestroy() @*/ PetscErrorCode TSAdaptCreate(MPI_Comm comm,TSAdapt *inadapt) { PetscErrorCode ierr; TSAdapt adapt; PetscFunctionBegin; PetscValidPointer(inadapt,1); *inadapt = NULL; ierr = TSAdaptInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(adapt,TSADAPT_CLASSID,"TSAdapt","Time stepping adaptivity","TS",comm,TSAdaptDestroy,TSAdaptView);CHKERRQ(ierr); adapt->always_accept = PETSC_FALSE; adapt->safety = 0.9; adapt->reject_safety = 0.5; adapt->clip[0] = 0.1; adapt->clip[1] = 10.; adapt->dt_min = 1e-20; adapt->dt_max = 1e+20; adapt->ignore_max = -1.0; adapt->glee_use_local = PETSC_TRUE; adapt->scale_solve_failed = 0.25; /* these two safety factors are not public, and they are used only in the TS_EXACTFINALTIME_MATCHSTEP case to prevent from situations were unreasonably small time steps are taken in order to match the final time */ adapt->matchstepfac[0] = 0.01; /* allow 1% step size increase in the last step */ adapt->matchstepfac[1] = 2.0; /* halve last step if it is greater than what remains divided this factor */ adapt->wnormtype = NORM_2; adapt->timestepjustdecreased_delay = 0; *inadapt = adapt; PetscFunctionReturn(0); }
PetscErrorCode PetscRandomCreate(MPI_Comm comm,PetscRandom *r) { PetscRandom rr; PetscErrorCode ierr; PetscMPIInt rank; PetscFunctionBegin; PetscValidPointer(r,3); *r = NULL; ierr = PetscRandomInitializePackage(); CHKERRQ(ierr); ierr = PetscHeaderCreate(rr,PETSC_RANDOM_CLASSID,"PetscRandom","Random number generator","Sys",comm,PetscRandomDestroy,NULL); CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank); CHKERRQ(ierr); rr->data = NULL; rr->low = 0.0; rr->width = 1.0; rr->iset = PETSC_FALSE; rr->seed = 0x12345678 + 76543*rank; ierr = PetscRandomSetType(rr,PETSCRANDER48); CHKERRQ(ierr); *r = rr; PetscFunctionReturn(0); }
/*@C PetscDrawBarCreate - Creates a bar graph data structure. Collective over PetscDraw Input Parameters: . draw - The window where the graph will be made Output Parameters: . bar - The bar graph context Notes: Call PetscDrawBarSetData() to provide the bins to be plotted and then PetscDrawBarDraw() to display the new plot The difference between a bar chart, PetscDrawBar, and a histogram, PetscDrawHG, is explained here http://stattrek.com/statistics/charts/histogram.aspx?Tutorial=AP The MPI communicator that owns the PetscDraw owns this PetscDrawBar, but the calls to set options and add data are ignored on all processes except the zeroth MPI process in the communicator. All MPI processes in the communicator must call PetscDrawBarDraw() to display the updated graph. Level: intermediate Concepts: bar graph^creating .seealso: PetscDrawLGCreate(), PetscDrawLG, PetscDrawSPCreate(), PetscDrawSP, PetscDrawHGCreate(), PetscDrawHG, PetscDrawBarDestroy(), PetscDrawBarSetData(), PetscDrawBar, PetscDrawBarDraw(), PetscDrawBarSave(), PetscDrawBarSetColor(), PetscDrawBarSort(), PetscDrawBarSetLimits(), PetscDrawBarGetAxis(), PetscDrawAxis, PetscDrawBarGetDraw(), PetscDrawBarSetFromOptions() @*/ PetscErrorCode PetscDrawBarCreate(PetscDraw draw,PetscDrawBar *bar) { PetscDrawBar h; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidPointer(bar,2); ierr = PetscHeaderCreate(h,PETSC_DRAWBAR_CLASSID,"DrawBar","Bar Graph","Draw",PetscObjectComm((PetscObject)draw),PetscDrawBarDestroy,NULL);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)draw,(PetscObject)h);CHKERRQ(ierr); ierr = PetscObjectReference((PetscObject)draw);CHKERRQ(ierr); h->win = draw; h->view = NULL; h->destroy = NULL; h->color = PETSC_DRAW_GREEN; h->ymin = 0.; /* if user has not set these then they are determined from the data */ h->ymax = 0.; h->numBins = 0; ierr = PetscDrawAxisCreate(draw,&h->axis);CHKERRQ(ierr); h->axis->xticks = NULL; *bar = h; PetscFunctionReturn(0); }
static PetscErrorCode DMTSCreate(MPI_Comm comm,DMTS *kdm) { PetscErrorCode ierr; PetscFunctionBegin; ierr = TSInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(*kdm, DMTS_CLASSID, "DMTS", "DMTS", "DMTS", comm, DMTSDestroy, DMTSView);CHKERRQ(ierr); PetscFunctionReturn(0); }
static PetscErrorCode DMKSPCreate(MPI_Comm comm,DMKSP *kdm) { PetscErrorCode ierr; PetscFunctionBegin; ierr = KSPInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(*kdm, DMKSP_CLASSID, "DMKSP", "DMKSP", "DMKSP", comm, DMKSPDestroy, NULL);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ KSPCreate - Creates the default KSP context. Collective on MPI_Comm Input Parameter: . comm - MPI communicator Output Parameter: . ksp - location to put the KSP context Notes: The default KSP type is GMRES with a restart of 30, using modified Gram-Schmidt orthogonalization. Level: beginner .keywords: KSP, create, context .seealso: KSPSetUp(), KSPSolve(), KSPDestroy(), KSP @*/ PetscErrorCode KSPCreate(MPI_Comm comm,KSP *inksp) { KSP ksp; PetscErrorCode ierr; void *ctx; PetscFunctionBegin; PetscValidPointer(inksp,2); *inksp = 0; ierr = KSPInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(ksp,KSP_CLASSID,"KSP","Krylov Method","KSP",comm,KSPDestroy,KSPView);CHKERRQ(ierr); ksp->max_it = 10000; ksp->pc_side = ksp->pc_side_set = PC_SIDE_DEFAULT; ksp->rtol = 1.e-5; #if defined(PETSC_USE_REAL_SINGLE) ksp->abstol = 1.e-25; #else ksp->abstol = 1.e-50; #endif ksp->divtol = 1.e4; ksp->chknorm = -1; ksp->normtype = ksp->normtype_set = KSP_NORM_DEFAULT; ksp->rnorm = 0.0; ksp->its = 0; ksp->guess_zero = PETSC_TRUE; ksp->calc_sings = PETSC_FALSE; ksp->res_hist = NULL; ksp->res_hist_alloc = NULL; ksp->res_hist_len = 0; ksp->res_hist_max = 0; ksp->res_hist_reset = PETSC_TRUE; ksp->numbermonitors = 0; ierr = KSPConvergedDefaultCreate(&ctx);CHKERRQ(ierr); ierr = KSPSetConvergenceTest(ksp,KSPConvergedDefault,ctx,KSPConvergedDefaultDestroy);CHKERRQ(ierr); ksp->ops->buildsolution = KSPBuildSolutionDefault; ksp->ops->buildresidual = KSPBuildResidualDefault; ksp->vec_sol = 0; ksp->vec_rhs = 0; ksp->pc = 0; ksp->data = 0; ksp->nwork = 0; ksp->work = 0; ksp->reason = KSP_CONVERGED_ITERATING; ksp->setupstage = KSP_SETUP_NEW; ierr = KSPNormSupportTableReset_Private(ksp);CHKERRQ(ierr); *inksp = ksp; PetscFunctionReturn(0); }
/*@C PetscContainerCreate - Creates a PETSc object that has room to hold a single pointer. This allows one to attach any type of data (accessible through a pointer) with the PetscObjectCompose() function to a PetscObject. The data item itself is attached by a call to PetscContainerSetPointer. Collective on MPI_Comm Input Parameters: . comm - MPI communicator that shares the object Output Parameters: . container - the container created Level: advanced .seealso: PetscContainerDestroy(), PetscContainerSetPointer(), PetscContainerGetPointer() @*/ PetscErrorCode PETSC_DLLEXPORT PetscContainerCreate(MPI_Comm comm,PetscContainer *container) { PetscErrorCode ierr; PetscContainer contain; PetscFunctionBegin; PetscValidPointer(container,2); ierr = PetscHeaderCreate(contain,_p_PetscContainer,PetscInt,PETSC_CONTAINER_COOKIE,0,"PetscContainer",comm,PetscContainerDestroy,0);CHKERRQ(ierr); *container = contain; PetscFunctionReturn(0); }
PetscErrorCode TSGLLEAdaptCreate(MPI_Comm comm,TSGLLEAdapt *inadapt) { PetscErrorCode ierr; TSGLLEAdapt adapt; PetscFunctionBegin; *inadapt = NULL; ierr = PetscHeaderCreate(adapt,TSGLLEADAPT_CLASSID,"TSGLLEAdapt","General Linear adaptivity","TS",comm,TSGLLEAdaptDestroy,TSGLLEAdaptView);CHKERRQ(ierr); *inadapt = adapt; PetscFunctionReturn(0); }
/*@C PetscContainerCreate - Creates a PETSc object that has room to hold a single pointer. This allows one to attach any type of data (accessible through a pointer) with the PetscObjectCompose() function to a PetscObject. The data item itself is attached by a call to PetscContainerSetPointer(). Collective on MPI_Comm Input Parameters: . comm - MPI communicator that shares the object Output Parameters: . container - the container created Level: advanced .seealso: PetscContainerDestroy(), PetscContainerSetPointer(), PetscContainerGetPointer() @*/ PetscErrorCode PetscContainerCreate(MPI_Comm comm,PetscContainer *container) { PetscErrorCode ierr; PetscContainer contain; PetscFunctionBegin; PetscValidPointer(container,2); ierr = PetscSysInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(contain,PETSC_CONTAINER_CLASSID,"PetscContainer","Container","Sys",comm,PetscContainerDestroy,NULL);CHKERRQ(ierr); *container = contain; PetscFunctionReturn(0); }
/*@ PetscConvEstCreate - Create a PetscConvEst object Collective on MPI_Comm Input Parameter: . comm - The communicator for the PetscConvEst object Output Parameter: . ce - The PetscConvEst object Level: beginner .keywords: PetscConvEst, convergence, create .seealso: PetscConvEstDestroy(), PetscConvEstGetConvRate() @*/ PetscErrorCode PetscConvEstCreate(MPI_Comm comm, PetscConvEst *ce) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(ce, 2); ierr = PetscSysInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(*ce, PETSC_OBJECT_CLASSID, "PetscConvEst", "ConvergenceEstimator", "SNES", comm, PetscConvEstDestroy, PetscConvEstView);CHKERRQ(ierr); (*ce)->monitor = PETSC_FALSE; (*ce)->Nr = 4; PetscFunctionReturn(0); }
/*@ PetscViewerCreate - Creates a viewing context Collective on MPI_Comm Input Parameter: . comm - MPI communicator Output Parameter: . inviewer - location to put the PetscViewer context Level: advanced Concepts: graphics^creating PetscViewer Concepts: file input/output^creating PetscViewer Concepts: sockets^creating PetscViewer .seealso: PetscViewerDestroy(), PetscViewerSetType(), PetscViewerType @*/ PetscErrorCode PetscViewerCreate(MPI_Comm comm,PetscViewer *inviewer) { PetscViewer viewer; PetscErrorCode ierr; PetscFunctionBegin; *inviewer = 0; ierr = PetscViewerInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(viewer,PETSC_VIEWER_CLASSID,"PetscViewer","PetscViewer","Viewer",comm,PetscViewerDestroy,NULL);CHKERRQ(ierr); *inviewer = viewer; viewer->data = 0; 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 TSTrajectoryCreate - This function creates an empty trajectory object used to store the time dependent solution of an ODE/DAE Collective on MPI_Comm Input Parameter: . comm - the communicator Output Parameter: . tj - the trajectory object Level: advanced Notes: Usually one does not call this routine, it is called automatically when one calls TSSetSaveTrajectory(). .keywords: TS, trajectory, create .seealso: TSTrajectorySetUp(), TSTrajectoryDestroy(), TSTrajectorySetType() @*/ PetscErrorCode TSTrajectoryCreate(MPI_Comm comm,TSTrajectory *tj) { TSTrajectory t; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(tj,2); *tj = NULL; ierr = TSInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(t,TSTRAJECTORY_CLASSID,"TSTrajectory","Time stepping","TS",comm,TSTrajectoryDestroy,TSTrajectoryView);CHKERRQ(ierr); t->setupcalled = PETSC_FALSE; *tj = t; PetscFunctionReturn(0); }
/*@C PetscDrawHGCreate - Creates a histogram data structure. Collective over PetscDraw Input Parameters: + draw - The window where the graph will be made - bins - The number of bins to use Output Parameters: . hist - The histogram context Level: intermediate Concepts: histogram^creating .seealso: PetscDrawHGDestroy() @*/ PetscErrorCode PetscDrawHGCreate(PetscDraw draw, int bins, PetscDrawHG *hist) { PetscBool isnull; PetscDrawHG h; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID,1); PetscValidLogicalCollectiveInt(draw,bins,2); PetscValidPointer(hist,3); ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr); if (isnull) {*hist = NULL; PetscFunctionReturn(0);} ierr = PetscHeaderCreate(h, PETSC_DRAWHG_CLASSID, "PetscDrawHG", "Histogram", "Draw", PetscObjectComm((PetscObject)draw), PetscDrawHGDestroy, NULL);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)draw,(PetscObject)h);CHKERRQ(ierr); ierr = PetscObjectReference((PetscObject)draw);CHKERRQ(ierr); h->win = draw; h->view = NULL; h->destroy = NULL; h->color = PETSC_DRAW_GREEN; h->xmin = PETSC_MAX_REAL; h->xmax = PETSC_MIN_REAL; h->ymin = 0.; h->ymax = 1.; h->numBins = bins; h->maxBins = bins; ierr = PetscMalloc1(h->maxBins,&h->bins);CHKERRQ(ierr); h->numValues = 0; h->maxValues = CHUNKSIZE; h->calcStats = PETSC_FALSE; h->integerBins = PETSC_FALSE; ierr = PetscMalloc1(h->maxValues,&h->values);CHKERRQ(ierr); ierr = PetscLogObjectMemory((PetscObject)h,(h->maxBins + h->maxValues)*sizeof(PetscReal));CHKERRQ(ierr); ierr = PetscDrawAxisCreate(draw,&h->axis);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)h,(PetscObject)h->axis);CHKERRQ(ierr); *hist = h; PetscFunctionReturn(0); }
PetscErrorCode TaoLineSearchCreate(MPI_Comm comm, TaoLineSearch *newls) { PetscErrorCode ierr; TaoLineSearch ls; PetscFunctionBegin; PetscValidPointer(newls,2); *newls = NULL; #ifndef PETSC_USE_DYNAMIC_LIBRARIES ierr = TaoLineSearchInitializePackage();CHKERRQ(ierr); #endif ierr = PetscHeaderCreate(ls,TAOLINESEARCH_CLASSID,"TaoLineSearch","Linesearch","Tao",comm,TaoLineSearchDestroy,TaoLineSearchView);CHKERRQ(ierr); ls->bounded = 0; ls->max_funcs=30; ls->ftol = 0.0001; ls->gtol = 0.9; #if defined(PETSC_USE_REAL_SINGLE) ls->rtol = 1.0e-5; #else ls->rtol = 1.0e-10; #endif ls->stepmin=1.0e-20; ls->stepmax=1.0e+20; ls->step=1.0; ls->nfeval=0; ls->ngeval=0; ls->nfgeval=0; ls->ops->computeobjective=0; ls->ops->computegradient=0; ls->ops->computeobjectiveandgradient=0; ls->ops->computeobjectiveandgts=0; ls->ops->setup=0; ls->ops->apply=0; ls->ops->view=0; ls->ops->setfromoptions=0; ls->ops->reset=0; ls->ops->destroy=0; ls->setupcalled=PETSC_FALSE; ls->usetaoroutines=PETSC_FALSE; *newls = ls; PetscFunctionReturn(0); }
/*@ MatCreate - Creates a matrix where the type is determined from either a call to MatSetType() or from the options database with a call to MatSetFromOptions(). The default matrix type is AIJ, using the routines MatCreateSeqAIJ() or MatCreateAIJ() if you do not set a type in the options database. If you never call MatSetType() or MatSetFromOptions() it will generate an error when you try to use the matrix. Collective on MPI_Comm Input Parameter: . comm - MPI communicator Output Parameter: . A - the matrix Options Database Keys: + -mat_type seqaij - AIJ type, uses MatCreateSeqAIJ() . -mat_type mpiaij - AIJ type, uses MatCreateAIJ() . -mat_type seqdense - dense type, uses MatCreateSeqDense() . -mat_type mpidense - dense type, uses MatCreateDense() . -mat_type seqbaij - block AIJ type, uses MatCreateSeqBAIJ() - -mat_type mpibaij - block AIJ type, uses MatCreateBAIJ() Even More Options Database Keys: See the manpages for particular formats (e.g., MatCreateSeqAIJ()) for additional format-specific options. Notes: Level: beginner User manual sections: + sec_matcreate - chapter_matrices .keywords: matrix, create .seealso: MatCreateSeqAIJ(), MatCreateAIJ(), MatCreateSeqDense(), MatCreateDense(), MatCreateSeqBAIJ(), MatCreateBAIJ(), MatCreateSeqSBAIJ(), MatCreateSBAIJ(), MatConvert() @*/ PetscErrorCode MatCreate(MPI_Comm comm,Mat *A) { Mat B; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(A,2); *A = NULL; ierr = MatInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(B,MAT_CLASSID,"Mat","Matrix","Mat",comm,MatDestroy,MatView);CHKERRQ(ierr); ierr = PetscLayoutCreate(comm,&B->rmap);CHKERRQ(ierr); ierr = PetscLayoutCreate(comm,&B->cmap);CHKERRQ(ierr); B->preallocated = PETSC_FALSE; *A = B; PetscFunctionReturn(0); }
/*@ VecCreate - Creates an empty vector object. The type can then be set with VecSetType(), or VecSetFromOptions(). If you never call VecSetType() or VecSetFromOptions() it will generate an error when you try to use the vector. Collective on MPI_Comm Input Parameter: . comm - The communicator for the vector object Output Parameter: . vec - The vector object Level: beginner .keywords: vector, create .seealso: VecSetType(), VecSetSizes(), VecCreateMPIWithArray(), VecCreateMPI(), VecDuplicate(), VecDuplicateVecs(), VecCreateGhost(), VecCreateSeq(), VecPlaceArray() @*/ PetscErrorCode VecCreate(MPI_Comm comm, Vec *vec) { Vec v; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(vec,2); *vec = NULL; ierr = VecInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(v, VEC_CLASSID, "Vec", "Vector", "Vec", comm, VecDestroy, VecView);CHKERRQ(ierr); ierr = PetscLayoutCreate(comm,&v->map);CHKERRQ(ierr); v->array_gotten = PETSC_FALSE; v->petscnative = PETSC_FALSE; *vec = v; PetscFunctionReturn(0); }
/*@ TSAdaptCreate - create an adaptive controller context for time stepping Collective on MPI_Comm Input Parameter: . comm - The communicator Output Parameter: . adapt - new TSAdapt object Level: developer Notes: TSAdapt creation is handled by TS, so users should not need to call this function. .keywords: TSAdapt, create .seealso: TSGetAdapt(), TSAdaptSetType(), TSAdaptDestroy() @*/ PetscErrorCode TSAdaptCreate(MPI_Comm comm,TSAdapt *inadapt) { PetscErrorCode ierr; TSAdapt adapt; PetscFunctionBegin; PetscValidPointer(inadapt,1); *inadapt = NULL; ierr = TSAdaptInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(adapt,TSADAPT_CLASSID,"TSAdapt","Time stepping adaptivity","TS",comm,TSAdaptDestroy,TSAdaptView);CHKERRQ(ierr); adapt->dt_min = 1e-20; adapt->dt_max = 1e50; adapt->scale_solve_failed = 0.25; adapt->wnormtype = NORM_2; ierr = TSAdaptSetType(adapt,TSADAPTBASIC);CHKERRQ(ierr); *inadapt = adapt; PetscFunctionReturn(0); }
/*@ MatFDColoringCreate - Creates a matrix coloring context for finite difference computation of Jacobians. Collective on Mat Input Parameters: + mat - the matrix containing the nonzero structure of the Jacobian - iscoloring - the coloring of the matrix; usually obtained with MatColoringCreate() or DMCreateColoring() Output Parameter: . color - the new coloring context Level: intermediate .seealso: MatFDColoringDestroy(),SNESComputeJacobianDefaultColor(), ISColoringCreate(), MatFDColoringSetFunction(), MatFDColoringSetFromOptions(), MatFDColoringApply(), MatFDColoringView(), MatFDColoringSetParameters(), MatColoringCreate(), DMCreateColoring() @*/ PetscErrorCode MatFDColoringCreate(Mat mat,ISColoring iscoloring,MatFDColoring *color) { MatFDColoring c; MPI_Comm comm; PetscErrorCode ierr; PetscInt M,N; PetscFunctionBegin; PetscValidHeaderSpecific(mat,MAT_CLASSID,1); if (!mat->assembled) SETERRQ(PetscObjectComm((PetscObject)mat),PETSC_ERR_ARG_WRONGSTATE,"Matrix must be assembled by calls to MatAssemblyBegin/End();"); ierr = PetscLogEventBegin(MAT_FDColoringCreate,mat,0,0,0);CHKERRQ(ierr); ierr = MatGetSize(mat,&M,&N);CHKERRQ(ierr); if (M != N) SETERRQ(PetscObjectComm((PetscObject)mat),PETSC_ERR_SUP,"Only for square matrices"); ierr = PetscObjectGetComm((PetscObject)mat,&comm);CHKERRQ(ierr); ierr = PetscHeaderCreate(c,MAT_FDCOLORING_CLASSID,"MatFDColoring","Jacobian computation via finite differences with coloring","Mat",comm,MatFDColoringDestroy,MatFDColoringView);CHKERRQ(ierr); c->ctype = iscoloring->ctype; if (mat->ops->fdcoloringcreate) { ierr = (*mat->ops->fdcoloringcreate)(mat,iscoloring,c);CHKERRQ(ierr); } else SETERRQ1(PetscObjectComm((PetscObject)mat),PETSC_ERR_SUP,"Code not yet written for matrix type %s",((PetscObject)mat)->type_name); ierr = MatCreateVecs(mat,NULL,&c->w1);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)c,(PetscObject)c->w1);CHKERRQ(ierr); ierr = VecDuplicate(c->w1,&c->w2);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)c,(PetscObject)c->w2);CHKERRQ(ierr); c->error_rel = PETSC_SQRT_MACHINE_EPSILON; c->umin = 100.0*PETSC_SQRT_MACHINE_EPSILON; c->currentcolor = -1; c->htype = "wp"; c->fset = PETSC_FALSE; c->setupcalled = PETSC_FALSE; *color = c; ierr = PetscObjectCompose((PetscObject)mat,"SNESMatFDColoring",(PetscObject)c);CHKERRQ(ierr); ierr = PetscLogEventEnd(MAT_FDColoringCreate,mat,0,0,0);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ PetscDrawLGCreate - Creates a line graph data structure. Collective on PetscDraw Input Parameters: + draw - the window where the graph will be made. - dim - the number of curves which will be drawn Output Parameters: . outlg - the line graph context Level: intermediate Notes: The MPI communicator that owns the PetscDraw owns this PetscDrawLG, but the calls to set options and add points are ignored on all processes except the zeroth MPI process in the communicator. All MPI processes in the communicator must call PetscDrawLGDraw() to display the updated graph. Concepts: line graph^creating .seealso: PetscDrawLGDestroy(), PetscDrawLGAddPoint(), PetscDrawLGAddCommonPoint(), PetscDrawLGAddPoints(), PetscDrawLGDraw(), PetscDrawLGSave(), PetscDrawLGView(), PetscDrawLGReset(), PetscDrawLGSetDimension(), PetscDrawLGGetDimension(), PetscDrawLGSetLegend(), PetscDrawLGGetAxis(), PetscDrawLGGetDraw(), PetscDrawLGSetUseMarkers(), PetscDrawLGSetLimits(), PetscDrawLGSetColors(), PetscDrawLGSetOptionsPrefix(), PetscDrawLGSetFromOptions() @*/ PetscErrorCode PetscDrawLGCreate(PetscDraw draw,PetscInt dim,PetscDrawLG *outlg) { PetscDrawLG lg; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidLogicalCollectiveInt(draw,dim,2); PetscValidPointer(outlg,3); ierr = PetscHeaderCreate(lg,PETSC_DRAWLG_CLASSID,"DrawLG","Line Graph","Draw",PetscObjectComm((PetscObject)draw),PetscDrawLGDestroy,NULL);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)draw,(PetscObject)lg);CHKERRQ(ierr); ierr = PetscDrawLGSetOptionsPrefix(lg,((PetscObject)draw)->prefix);CHKERRQ(ierr); ierr = PetscObjectReference((PetscObject)draw);CHKERRQ(ierr); lg->win = draw; lg->view = NULL; lg->destroy = NULL; lg->nopts = 0; lg->dim = dim; lg->xmin = 1.e20; lg->ymin = 1.e20; lg->xmax = -1.e20; lg->ymax = -1.e20; ierr = PetscMalloc2(dim*CHUNCKSIZE,&lg->x,dim*CHUNCKSIZE,&lg->y);CHKERRQ(ierr); ierr = PetscLogObjectMemory((PetscObject)lg,2*dim*CHUNCKSIZE*sizeof(PetscReal));CHKERRQ(ierr); lg->len = dim*CHUNCKSIZE; lg->loc = 0; lg->use_markers = PETSC_FALSE; ierr = PetscDrawAxisCreate(draw,&lg->axis);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)lg,(PetscObject)lg->axis);CHKERRQ(ierr); *outlg = lg; PetscFunctionReturn(0); }
/*@C PetscSFCreate - create a star forest communication context Not Collective Input Arguments: . comm - communicator on which the star forest will operate Output Arguments: . sf - new star forest context Level: intermediate .seealso: PetscSFSetGraph(), PetscSFDestroy() @*/ PetscErrorCode PetscSFCreate(MPI_Comm comm,PetscSF *sf) { PetscErrorCode ierr; PetscSF b; PetscFunctionBegin; PetscValidPointer(sf,2); ierr = PetscSFInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(b,PETSCSF_CLASSID,"PetscSF","Star Forest","PetscSF",comm,PetscSFDestroy,PetscSFView);CHKERRQ(ierr); b->nroots = -1; b->nleaves = -1; b->nranks = -1; b->rankorder = PETSC_TRUE; b->ingroup = MPI_GROUP_NULL; b->outgroup = MPI_GROUP_NULL; b->graphset = PETSC_FALSE; *sf = b; PetscFunctionReturn(0); }
/*@C PFCreate - Creates a mathematical function context. Collective on MPI_Comm Input Parameter: + comm - MPI communicator . dimin - dimension of the space you are mapping from - dimout - dimension of the space you are mapping to Output Parameter: . pf - the function context Level: developer .keywords: PF, create, context .seealso: PFSet(), PFApply(), PFDestroy(), PFApplyVec() @*/ PetscErrorCode PFCreate(MPI_Comm comm,PetscInt dimin,PetscInt dimout,PF *pf) { PF newpf; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(pf,1); *pf = NULL; ierr = PFInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(newpf,PF_CLASSID,"PF","Mathematical functions","Vec",comm,PFDestroy,PFView);CHKERRQ(ierr); newpf->data = 0; newpf->ops->destroy = 0; newpf->ops->apply = 0; newpf->ops->applyvec = 0; newpf->ops->view = 0; newpf->dimin = dimin; newpf->dimout = dimout; *pf = newpf; PetscFunctionReturn(0); }
/*@ MatNullSpaceCreate - Creates a data structure used to project vectors out of null spaces. Collective on MPI_Comm Input Parameters: + comm - the MPI communicator associated with the object . has_cnst - PETSC_TRUE if the null space contains the constant vector; otherwise PETSC_FALSE . n - number of vectors (excluding constant vector) in null space - vecs - the vectors that span the null space (excluding the constant vector); these vectors must be orthonormal. These vectors are NOT copied, so do not change them after this call. You should free the array that you pass in and destroy the vectors (this will reduce the reference count for them by one). Output Parameter: . SP - the null space context Level: advanced Notes: See MatNullSpaceSetFunction() as an alternative way of providing the null space information instead of setting vecs. If has_cnst is PETSC_TRUE you do not need to pass a constant vector in as a fourth argument to this routine, nor do you need to pass in a function that eliminates the constant function into MatNullSpaceSetFunction(). Users manual sections: . sec_singular .keywords: PC, null space, create .seealso: MatNullSpaceDestroy(), MatNullSpaceRemove(), MatSetNullSpace(), MatNullSpace, MatNullSpaceSetFunction() @*/ PetscErrorCode MatNullSpaceCreate(MPI_Comm comm,PetscBool has_cnst,PetscInt n,const Vec vecs[],MatNullSpace *SP) { MatNullSpace sp; PetscErrorCode ierr; PetscInt i; PetscFunctionBegin; if (n < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Number of vectors (given %D) cannot be negative",n); if (n) PetscValidPointer(vecs,4); for (i=0; i<n; i++) PetscValidHeaderSpecific(vecs[i],VEC_CLASSID,4); PetscValidPointer(SP,5); *SP = NULL; ierr = MatInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(sp,MAT_NULLSPACE_CLASSID,"MatNullSpace","Null space","Mat",comm,MatNullSpaceDestroy,MatNullSpaceView);CHKERRQ(ierr); sp->has_cnst = has_cnst; sp->n = n; sp->vecs = 0; sp->alpha = 0; sp->remove = 0; sp->rmctx = 0; if (n) { ierr = PetscMalloc1(n,&sp->vecs);CHKERRQ(ierr); ierr = PetscMalloc1(n,&sp->alpha);CHKERRQ(ierr); ierr = PetscLogObjectMemory((PetscObject)sp,n*(sizeof(Vec)+sizeof(PetscScalar)));CHKERRQ(ierr); for (i=0; i<n; i++) { ierr = PetscObjectReference((PetscObject)vecs[i]);CHKERRQ(ierr); sp->vecs[i] = vecs[i]; } } *SP = sp; PetscFunctionReturn(0); }
/*@C PetscMatlabEngineCreate - Creates a MATLAB engine object Not Collective Input Parameters: + comm - a separate MATLAB engine is started for each process in the communicator - machine - name of machine where MATLAB engine is to be run (usually NULL) Output Parameter: . mengine - the resulting object Options Database: . -matlab_engine_graphics - allow the MATLAB engine to display graphics Level: advanced .seealso: PetscMatlabEngineDestroy(), PetscMatlabEnginePut(), PetscMatlabEngineGet(), PetscMatlabEngineEvaluate(), PetscMatlabEngineGetOutput(), PetscMatlabEnginePrintOutput(), PETSC_MATLAB_ENGINE_(), PetscMatlabEnginePutArray(), PetscMatlabEngineGetArray(), PetscMatlabEngine @*/ PetscErrorCode PetscMatlabEngineCreate(MPI_Comm comm,const char machine[],PetscMatlabEngine *mengine) { PetscErrorCode ierr; PetscMPIInt rank,size; char buffer[256]; PetscMatlabEngine e; PetscBool flg = PETSC_FALSE; PetscFunctionBegin; if (MATLABENGINE_CLASSID == -1) { ierr = PetscClassIdRegister("MATLAB Engine",&MATLABENGINE_CLASSID);CHKERRQ(ierr); } ierr = PetscOptionsGetBool(NULL,NULL,"-matlab_engine_graphics",&flg,NULL);CHKERRQ(ierr); ierr = PetscHeaderCreate(e,MATLABENGINE_CLASSID,"MatlabEngine","MATLAB Engine","Sys",comm,PetscMatlabEngineDestroy,NULL);CHKERRQ(ierr); if (!machine) machine = "\0"; ierr = PetscStrcpy(buffer,PETSC_MATLAB_COMMAND);CHKERRQ(ierr); if (!flg) { ierr = PetscStrcat(buffer," -nodisplay ");CHKERRQ(ierr); } ierr = PetscStrcat(buffer," -nojvm ");CHKERRQ(ierr); ierr = PetscInfo2(0,"Starting MATLAB engine on %s with command %s\n",machine,buffer);CHKERRQ(ierr); e->ep = engOpen(buffer); if (!e->ep) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unable to start MATLAB engine on %s",machine); engOutputBuffer(e->ep,e->buffer,1024); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); sprintf(buffer,"MPI_Comm_rank = %d; MPI_Comm_size = %d;\n",rank,size); engEvalString(e->ep, buffer); ierr = PetscInfo1(0,"Started MATLAB engine on %s\n",machine);CHKERRQ(ierr); *mengine = e; PetscFunctionReturn(0); }
/*@C AOCreateMapping - Creates a basic application mapping using two integer arrays. Input Parameters: + comm - MPI communicator that is to share AO . napp - size of integer arrays . myapp - integer array that defines an ordering - mypetsc - integer array that defines another ordering (may be NULL to indicate the identity ordering) Output Parameter: . aoout - the new application mapping Options Database Key: . -ao_view : call AOView() at the conclusion of AOCreateMapping() Level: beginner Notes: the arrays myapp and mypetsc need NOT contain the all the integers 0 to napp-1, that is there CAN be "holes" in the indices. Use AOCreateBasic() or AOCreateBasicIS() if they do not have holes for better performance. .keywords: AO, create .seealso: AOCreateBasic(), AOCreateBasic(), AOCreateMappingIS(), AODestroy() @*/ PetscErrorCode AOCreateMapping(MPI_Comm comm,PetscInt napp,const PetscInt myapp[],const PetscInt mypetsc[],AO *aoout) { AO ao; AO_Mapping *aomap; PetscInt *allpetsc, *allapp; PetscInt *petscPerm, *appPerm; PetscInt *petsc; PetscMPIInt size, rank,*lens, *disp,nnapp; PetscInt N, start; PetscInt i; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(aoout,5); *aoout = 0; ierr = AOInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(ao, AO_CLASSID, "AO", "Application Ordering", "AO", comm, AODestroy, AOView);CHKERRQ(ierr); ierr = PetscNewLog(ao,&aomap);CHKERRQ(ierr); ierr = PetscMemcpy(ao->ops, &AOps, sizeof(AOps));CHKERRQ(ierr); ao->data = (void*) aomap; /* transmit all lengths to all processors */ ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); ierr = PetscMalloc2(size, &lens,size,&disp);CHKERRQ(ierr); nnapp = napp; ierr = MPI_Allgather(&nnapp, 1, MPI_INT, lens, 1, MPI_INT, comm);CHKERRQ(ierr); N = 0; for (i = 0; i < size; i++) { disp[i] = N; N += lens[i]; } aomap->N = N; ao->N = N; ao->n = N; /* If mypetsc is 0 then use "natural" numbering */ if (!mypetsc) { start = disp[rank]; ierr = PetscMalloc1(napp+1, &petsc);CHKERRQ(ierr); for (i = 0; i < napp; i++) petsc[i] = start + i; } else { petsc = (PetscInt*)mypetsc; } /* get all indices on all processors */ ierr = PetscMalloc4(N, &allapp,N,&appPerm,N,&allpetsc,N,&petscPerm);CHKERRQ(ierr); ierr = MPI_Allgatherv((void*)myapp, napp, MPIU_INT, allapp, lens, disp, MPIU_INT, comm);CHKERRQ(ierr); ierr = MPI_Allgatherv((void*)petsc, napp, MPIU_INT, allpetsc, lens, disp, MPIU_INT, comm);CHKERRQ(ierr); ierr = PetscFree2(lens,disp);CHKERRQ(ierr); /* generate a list of application and PETSc node numbers */ ierr = PetscMalloc4(N, &aomap->app,N,&aomap->appPerm,N,&aomap->petsc,N,&aomap->petscPerm);CHKERRQ(ierr); ierr = PetscLogObjectMemory((PetscObject)ao, 4*N * sizeof(PetscInt));CHKERRQ(ierr); for (i = 0; i < N; i++) { appPerm[i] = i; petscPerm[i] = i; } ierr = PetscSortIntWithPermutation(N, allpetsc, petscPerm);CHKERRQ(ierr); ierr = PetscSortIntWithPermutation(N, allapp, appPerm);CHKERRQ(ierr); /* Form sorted arrays of indices */ for (i = 0; i < N; i++) { aomap->app[i] = allapp[appPerm[i]]; aomap->petsc[i] = allpetsc[petscPerm[i]]; } /* Invert petscPerm[] into aomap->petscPerm[] */ for (i = 0; i < N; i++) aomap->petscPerm[petscPerm[i]] = i; /* Form map between aomap->app[] and aomap->petsc[] */ for (i = 0; i < N; i++) aomap->appPerm[i] = aomap->petscPerm[appPerm[i]]; /* Invert appPerm[] into allapp[] */ for (i = 0; i < N; i++) allapp[appPerm[i]] = i; /* Form map between aomap->petsc[] and aomap->app[] */ for (i = 0; i < N; i++) aomap->petscPerm[i] = allapp[petscPerm[i]]; #if defined(PETSC_USE_DEBUG) /* Check that the permutations are complementary */ for (i = 0; i < N; i++) { if (i != aomap->appPerm[aomap->petscPerm[i]]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB, "Invalid ordering"); } #endif /* Cleanup */ if (!mypetsc) { ierr = PetscFree(petsc);CHKERRQ(ierr); } ierr = PetscFree4(allapp,appPerm,allpetsc,petscPerm);CHKERRQ(ierr); ierr = AOViewFromOptions(ao,NULL,"-ao_view");CHKERRQ(ierr); *aoout = ao; PetscFunctionReturn(0); }
/*MC MATMFFD - MATMFFD = "mffd" - A matrix free matrix type. Level: advanced .seealso: MatCreateMFFD(), MatCreateSNESMF(), MatMFFDSetFunction(), MatMFFDSetType(), MatMFFDSetFunctionError(), MatMFFDDSSetUmin(), MatMFFDSetFunction() MatMFFDSetHHistory(), MatMFFDResetHHistory(), MatCreateSNESMF(), MatMFFDGetH(), M*/ PETSC_EXTERN PetscErrorCode MatCreate_MFFD(Mat A) { MatMFFD mfctx; PetscErrorCode ierr; PetscFunctionBegin; ierr = MatMFFDInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(mfctx,MATMFFD_CLASSID,"MatMFFD","Matrix-free Finite Differencing","Mat",PetscObjectComm((PetscObject)A),MatDestroy_MFFD,MatView_MFFD);CHKERRQ(ierr); mfctx->error_rel = PETSC_SQRT_MACHINE_EPSILON; mfctx->recomputeperiod = 1; mfctx->count = 0; mfctx->currenth = 0.0; mfctx->historyh = NULL; mfctx->ncurrenth = 0; mfctx->maxcurrenth = 0; ((PetscObject)mfctx)->type_name = 0; mfctx->vshift = 0.0; mfctx->vscale = 1.0; /* Create the empty data structure to contain compute-h routines. These will be filled in below from the command line options or a later call with MatMFFDSetType() or if that is not called then it will default in the first use of MatMult_MFFD() */ mfctx->ops->compute = 0; mfctx->ops->destroy = 0; mfctx->ops->view = 0; mfctx->ops->setfromoptions = 0; mfctx->hctx = 0; mfctx->func = 0; mfctx->funcctx = 0; mfctx->w = NULL; A->data = mfctx; A->ops->mult = MatMult_MFFD; A->ops->destroy = MatDestroy_MFFD; A->ops->view = MatView_MFFD; A->ops->assemblyend = MatAssemblyEnd_MFFD; A->ops->scale = MatScale_MFFD; A->ops->shift = MatShift_MFFD; A->ops->diagonalscale = MatDiagonalScale_MFFD; A->ops->diagonalset = MatDiagonalSet_MFFD; A->ops->setfromoptions = MatSetFromOptions_MFFD; A->ops->missingdiagonal = MatMissingDiagonal_MFFD; A->assembled = PETSC_TRUE; ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetBase_C",MatMFFDSetBase_MFFD);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunctioniBase_C",MatMFFDSetFunctioniBase_MFFD);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunctioni_C",MatMFFDSetFunctioni_MFFD);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunction_C",MatMFFDSetFunction_MFFD);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetCheckh_C",MatMFFDSetCheckh_MFFD);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetPeriod_C",MatMFFDSetPeriod_MFFD);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDSetFunctionError_C",MatMFFDSetFunctionError_MFFD);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)A,"MatMFFDResetHHistory_C",MatMFFDResetHHistory_MFFD);CHKERRQ(ierr); mfctx->mat = A; ierr = PetscObjectChangeTypeName((PetscObject)A,MATMFFD);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C MatNullSpaceCreate - Creates a data structure used to project vectors out of null spaces. Collective on MPI_Comm Input Parameters: + comm - the MPI communicator associated with the object . has_cnst - PETSC_TRUE if the null space contains the constant vector; otherwise PETSC_FALSE . n - number of vectors (excluding constant vector) in null space - vecs - the vectors that span the null space (excluding the constant vector); these vectors must be orthonormal. These vectors are NOT copied, so do not change them after this call. You should free the array that you pass in and destroy the vectors (this will reduce the reference count for them by one). Output Parameter: . SP - the null space context Level: advanced Notes: See MatNullSpaceSetFunction() as an alternative way of providing the null space information instead of setting vecs. If has_cnst is PETSC_TRUE you do not need to pass a constant vector in as a fourth argument to this routine, nor do you need to pass in a function that eliminates the constant function into MatNullSpaceSetFunction(). Users manual sections: . sec_singular .keywords: PC, null space, create .seealso: MatNullSpaceDestroy(), MatNullSpaceRemove(), MatSetNullSpace(), MatNullSpace, MatNullSpaceSetFunction() @*/ PetscErrorCode MatNullSpaceCreate(MPI_Comm comm,PetscBool has_cnst,PetscInt n,const Vec vecs[],MatNullSpace *SP) { MatNullSpace sp; PetscErrorCode ierr; PetscInt i; PetscFunctionBegin; if (n < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Number of vectors (given %D) cannot be negative",n); if (n) PetscValidPointer(vecs,4); for (i=0; i<n; i++) PetscValidHeaderSpecific(vecs[i],VEC_CLASSID,4); PetscValidPointer(SP,5); if (n) { for (i=0; i<n; i++) { /* prevent the user from changes values in the vector */ ierr = VecLockPush(vecs[i]);CHKERRQ(ierr); } } #if defined(PETSC_USE_DEBUG) if (n) { PetscScalar *dots; for (i=0; i<n; i++) { PetscReal norm; ierr = VecNorm(vecs[i],NORM_2,&norm);CHKERRQ(ierr); if (PetscAbsReal(norm - 1) > PETSC_SQRT_MACHINE_EPSILON) SETERRQ2(PetscObjectComm((PetscObject)vecs[i]),PETSC_ERR_ARG_WRONG,"Vector %D must have 2-norm of 1.0, it is %g",i,(double)norm); } if (has_cnst) { for (i=0; i<n; i++) { PetscScalar sum; ierr = VecSum(vecs[i],&sum);CHKERRQ(ierr); if (PetscAbsScalar(sum) > PETSC_SQRT_MACHINE_EPSILON) SETERRQ2(PetscObjectComm((PetscObject)vecs[i]),PETSC_ERR_ARG_WRONG,"Vector %D must be orthogonal to constant vector, inner product is %g",i,(double)PetscAbsScalar(sum)); } } ierr = PetscMalloc1(n-1,&dots);CHKERRQ(ierr); for (i=0; i<n-1; i++) { PetscInt j; ierr = VecMDot(vecs[i],n-i-1,vecs+i+1,dots);CHKERRQ(ierr); for (j=0;j<n-i-1;j++) { if (PetscAbsScalar(dots[j]) > PETSC_SQRT_MACHINE_EPSILON) SETERRQ3(PetscObjectComm((PetscObject)vecs[i]),PETSC_ERR_ARG_WRONG,"Vector %D must be orthogonal to vector %D, inner product is %g",i,i+j+1,(double)PetscAbsScalar(dots[j])); } } PetscFree(dots);CHKERRQ(ierr); } #endif *SP = NULL; ierr = MatInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(sp,MAT_NULLSPACE_CLASSID,"MatNullSpace","Null space","Mat",comm,MatNullSpaceDestroy,MatNullSpaceView);CHKERRQ(ierr); sp->has_cnst = has_cnst; sp->n = n; sp->vecs = 0; sp->alpha = 0; sp->remove = 0; sp->rmctx = 0; if (n) { ierr = PetscMalloc1(n,&sp->vecs);CHKERRQ(ierr); ierr = PetscMalloc1(n,&sp->alpha);CHKERRQ(ierr); ierr = PetscLogObjectMemory((PetscObject)sp,n*(sizeof(Vec)+sizeof(PetscScalar)));CHKERRQ(ierr); for (i=0; i<n; i++) { ierr = PetscObjectReference((PetscObject)vecs[i]);CHKERRQ(ierr); sp->vecs[i] = vecs[i]; } } *SP = sp; PetscFunctionReturn(0); }