/*@C DMSNESSetJacobianLocal - set a local Jacobian evaluation function Logically Collective Input Arguments: + dm - DM to associate callback with . func - local Jacobian evaluation - ctx - optional context for local Jacobian evaluation Level: beginner .seealso: DMSNESSetJacobian(), DMDASNESSetJacobian(), DMDACreate1d(), DMDACreate2d(), DMDACreate3d() @*/ PetscErrorCode DMSNESSetJacobianLocal(DM dm,PetscErrorCode (*func)(DM,Vec,Mat,Mat,MatStructure*,void*),void *ctx) { PetscErrorCode ierr; DMSNES sdm; DMSNES_Local *dmlocalsnes; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr); ierr = DMLocalSNESGetContext(dm,sdm,&dmlocalsnes);CHKERRQ(ierr); dmlocalsnes->jacobianlocal = func; dmlocalsnes->jacobianlocalctx = ctx; ierr = DMSNESSetJacobian(dm,SNESComputeJacobian_DMLocal,dmlocalsnes);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMSNESSetBoundaryLocal - set a local boundary value function. This function is called with local vector containing the local vector information PLUS ghost point information. It should insert values into the local vector that do not come from the global vector, such as essential boundary condition data. Logically Collective Input Arguments: + dm - DM to associate callback with . func - local boundary value evaluation - ctx - optional context for local boundary value evaluation Level: intermediate .seealso: DMSNESSetFunctionLocal(), DMDASNESSetJacobianLocal() @*/ PetscErrorCode DMSNESSetBoundaryLocal(DM dm,PetscErrorCode (*func)(DM,Vec,void*),void *ctx) { PetscErrorCode ierr; DMSNES sdm; DMSNES_Local *dmlocalsnes; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr); ierr = DMLocalSNESGetContext(dm,sdm,&dmlocalsnes);CHKERRQ(ierr); dmlocalsnes->boundarylocal = func; dmlocalsnes->boundarylocalctx = ctx; PetscFunctionReturn(0); }
/*@C DMDASNESSetObjectiveLocal - set a local residual evaluation function Logically Collective Input Arguments: + dm - DM to associate callback with . func - local objective evaluation - ctx - optional context for local residual evaluation Calling sequence for func: + info - DMDALocalInfo defining the subdomain to evaluate the residual on . x - dimensional pointer to state at which to evaluate residual . ob - eventual objective value - ctx - optional context passed above Level: beginner .seealso: DMSNESSetFunction(), DMDASNESSetJacobian(), DMDACreate1d(), DMDACreate2d(), DMDACreate3d() @*/ PetscErrorCode DMDASNESSetObjectiveLocal(DM dm,DMDASNESObjective func,void *ctx) { PetscErrorCode ierr; DMSNES sdm; DMSNES_DA *dmdasnes; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr); ierr = DMDASNESGetContext(dm,sdm,&dmdasnes);CHKERRQ(ierr); dmdasnes->objectivelocal = func; dmdasnes->objectivelocalctx = ctx; ierr = DMSNESSetObjective(dm,SNESComputeObjective_DMDA,dmdasnes);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMSNESSetFunctionLocal - set a local residual evaluation function. This function is called with local vector containing the local vector information PLUS ghost point information. It should compute a result for all local elements and DMSNES will automatically accumulate the overlapping values. Logically Collective Input Arguments: + dm - DM to associate callback with . func - local residual evaluation - ctx - optional context for local residual evaluation Level: beginner .seealso: DMSNESSetFunction(), DMDASNESSetJacobianLocal(), DMDACreate1d(), DMDACreate2d(), DMDACreate3d() @*/ PetscErrorCode DMSNESSetFunctionLocal(DM dm,PetscErrorCode (*func)(DM,Vec,Vec,void*),void *ctx) { PetscErrorCode ierr; DMSNES sdm; DMSNES_Local *dmlocalsnes; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr); ierr = DMLocalSNESGetContext(dm,sdm,&dmlocalsnes);CHKERRQ(ierr); dmlocalsnes->residuallocal = func; dmlocalsnes->residuallocalctx = ctx; ierr = DMSNESSetFunction(dm,SNESComputeFunction_DMLocal,dmlocalsnes);CHKERRQ(ierr); if (!sdm->ops->computejacobian) { /* Call us for the Jacobian too, can be overridden by the user. */ ierr = DMSNESSetJacobian(dm,SNESComputeJacobian_DMLocal,dmlocalsnes);CHKERRQ(ierr); } PetscFunctionReturn(0); }
/*@C DMDASNESSetPicardLocal - set a local right hand side and matrix evaluation function for Picard iteration Logically Collective Input Arguments: + dm - DM to associate callback with . imode - INSERT_VALUES if local function computes owned part, ADD_VALUES if it contributes to ghosted part . func - local residual evaluation - ctx - optional context for local residual evaluation Calling sequence for func: + info - DMDALocalInfo defining the subdomain to evaluate the residual on . x - dimensional pointer to state at which to evaluate residual . f - dimensional pointer to residual, write the residual here - ctx - optional context passed above Notes: The user must use extern PetscErrorCode SNESPicardComputeFunction(SNES,Vec,Vec,void*); extern PetscErrorCode SNESPicardComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*); ierr = SNESSetFunction(snes,NULL,SNESPicardComputeFunction,&user);CHKERRQ(ierr); in their code before calling this routine. Level: beginner .seealso: DMSNESSetFunction(), DMDASNESSetJacobian(), DMDACreate1d(), DMDACreate2d(), DMDACreate3d() @*/ PetscErrorCode DMDASNESSetPicardLocal(DM dm,InsertMode imode,PetscErrorCode (*func)(DMDALocalInfo*,void*,void*,void*), PetscErrorCode (*jac)(DMDALocalInfo*,void*,Mat,Mat,MatStructure*,void*),void *ctx) { PetscErrorCode ierr; DMSNES sdm; DMSNES_DA *dmdasnes; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = DMGetDMSNESWrite(dm,&sdm);CHKERRQ(ierr); ierr = DMDASNESGetContext(dm,sdm,&dmdasnes);CHKERRQ(ierr); dmdasnes->residuallocalimode = imode; dmdasnes->rhsplocal = func; dmdasnes->jacobianplocal = jac; dmdasnes->picardlocalctx = ctx; ierr = DMSNESSetPicard(dm,SNESComputePicard_DMDA,SNESComputePicardJacobian_DMDA,dmdasnes);CHKERRQ(ierr); PetscFunctionReturn(0); }