static char help[] = "Solves DAE with integrator only on non-algebraic terms \n"; #include /* \dot{U} = f(U,V) F(U,V) = 0 Same as ex6.c except the user provided functions take input values as a single vector instead of two vectors */ /* f(U,V) = U + V */ PetscErrorCode f(PetscReal t,Vec UV,Vec F) { const PetscScalar *u,*v; PetscScalar *f; PetscInt n,i; PetscFunctionBeginUser; PetscCall(VecGetLocalSize(UV,&n)); n = n/2; PetscCall(VecGetArrayRead(UV,&u)); v = u + n; PetscCall(VecGetArrayWrite(F,&f)); for (i=0; it = t; PetscCall(VecScatterBegin(ctx->scatterU,U,ctx->UV,INSERT_VALUES,SCATTER_FORWARD)); PetscCall(VecScatterEnd(ctx->scatterU,U,ctx->UV,INSERT_VALUES,SCATTER_FORWARD)); PetscCall(SNESSolve(ctx->snes,NULL,ctx->V)); PetscCall(VecScatterBegin(ctx->scatterV,ctx->V,ctx->UV,INSERT_VALUES,SCATTER_FORWARD)); PetscCall(VecScatterEnd(ctx->scatterV,ctx->V,ctx->UV,INSERT_VALUES,SCATTER_FORWARD)); PetscCall((*ctx->f)(t,ctx->UV,F)); PetscFunctionReturn(0); } /* Defines the nonlinear function that is passed to the nonlinear solver */ PetscErrorCode SNESFunction(SNES snes,Vec V,Vec F,void *actx) { AppCtx *ctx = (AppCtx*)actx; PetscFunctionBeginUser; PetscCall(VecScatterBegin(ctx->scatterV,V,ctx->UV,INSERT_VALUES,SCATTER_FORWARD)); PetscCall(VecScatterEnd(ctx->scatterV,V,ctx->UV,INSERT_VALUES,SCATTER_FORWARD)); PetscCall((*ctx->F)(ctx->t,ctx->UV,F)); PetscFunctionReturn(0); } /*TEST test: args: -ts_monitor -ts_view TEST*/