xolotl/solver/src/PetscSolver.cpp
/*
 Compute the Jacobian entries based on IFunction() and insert them into the
 matrix
 */
Compute the Jacobian entries based on IFunction() and insert them into the
matrix
Compute the Jacobian entries based on IFunction () and insert them into the matrix
PetscErrorCode
RHSJacobian(TS ts, PetscReal ftime, Vec C, Mat A, Mat J, void*)
{
	RHSJacobianTimer->start();
	PetscErrorCode ierr;
	PetscFunctionBeginUser;
	ierr = MatZeroEntries(J);
	CHKERRQ(ierr);
	DM da;
	ierr = TSGetDM(ts, &da);
	CHKERRQ(ierr);
	Vec localC;
	ierr = DMGetLocalVector(da, &localC);
	CHKERRQ(ierr);
	ierr = DMGlobalToLocalBegin(da, C, INSERT_VALUES, localC);
	CHKERRQ(ierr);
	ierr = DMGlobalToLocalEnd(da, C, INSERT_VALUES, localC);
	CHKERRQ(ierr);
	auto& solverHandler = Solver::getSolverHandler();
	solverHandler.computeJacobian(ts, localC, J, ftime);
	ierr = DMRestoreLocalVector(da, &localC);
	CHKERRQ(ierr);
	ierr = MatAssemblyBegin(J, MAT_FINAL_ASSEMBLY);
	CHKERRQ(ierr);
	ierr = MatAssemblyEnd(J, MAT_FINAL_ASSEMBLY);
	CHKERRQ(ierr);
	if (A != J) {
		ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
		CHKERRQ(ierr);
		ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
		CHKERRQ(ierr);
	}
	RHSJacobianTimer->stop();
	PetscFunctionReturn(0);
}
PetscErrorCode RHSJacobian ( TS ts , PetscReal ftime , Vec C , Mat A , Mat J , void * ) { RHSJacobianTimer -> start ( ) ; PetscErrorCode ierr ; PetscFunctionBeginUser ; ierr = MatZeroEntries ( J ) ; CHKERRQ ( ierr ) ; DM da ; ierr = TSGetDM ( ts , & da ) ; CHKERRQ ( ierr ) ; Vec localC ; ierr = DMGetLocalVector ( da , & localC ) ; CHKERRQ ( ierr ) ; ierr = DMGlobalToLocalBegin ( da , C , INSERT_VALUES , localC ) ; CHKERRQ ( ierr ) ; ierr = DMGlobalToLocalEnd ( da , C , INSERT_VALUES , localC ) ; CHKERRQ ( ierr ) ; auto & solverHandler = Solver :: getSolverHandler ( ) ; solverHandler . computeJacobian ( ts , localC , J , ftime ) ; ierr = DMRestoreLocalVector ( da , & localC ) ; CHKERRQ ( ierr ) ; ierr = MatAssemblyBegin ( J , MAT_FINAL_ASSEMBLY ) ; CHKERRQ ( ierr ) ; ierr = MatAssemblyEnd ( J , MAT_FINAL_ASSEMBLY ) ; CHKERRQ ( ierr ) ; if ( A != J ) { ierr = MatAssemblyBegin ( A , MAT_FINAL_ASSEMBLY ) ; CHKERRQ ( ierr ) ; ierr = MatAssemblyEnd ( A , MAT_FINAL_ASSEMBLY ) ; CHKERRQ ( ierr ) ; } RHSJacobianTimer -> stop ( ) ; PetscFunctionReturn ( 0 ) ; }
Compute the Jacobian entries based on IFunction() and insert them into the
matrix
Compute the Jacobian entries based on IFunction () and insert them into the matrix
// Start the RHSJacobian timer // Get the matrix from PETSc // Get the complete data array // Get the solver handler // Return the local vector //	ierr = MatView(J, PETSC_VIEWER_STDOUT_WORLD); // Stop the RHSJacobian timer