xolotl/solver/src/monitor/Monitor1D.cpp
/**
 * This is a monitoring method that looks at if there are negative
 * concentrations at each time step.
 */
This is a monitoring method that looks at if there are negative
concentrations at each time step.
This is a monitoring method that looks at if there are negative concentrations at each time step .
PetscErrorCode
checkNegative1D(TS ts, PetscInt timestep, PetscReal time, Vec solution, void*)
{
	perf::ScopedTimer myTimer(checkNegativeTimer);
	PetscErrorCode ierr;
	double **solutionArray, *gridPointSolution;
	IdType xs, xm, Mx, ys, ym, My, zs, zm, Mz;
	PetscFunctionBeginUser;
	DM da;
	ierr = TSGetDM(ts, &da);
	CHKERRQ(ierr);
	ierr = DMDAVecGetArrayDOF(da, solution, &solutionArray);
	CHKERRQ(ierr);
	auto& solverHandler = PetscSolver::getSolverHandler();
	solverHandler.getLocalCoordinates(xs, xm, Mx, ys, ym, My, zs, zm, Mz);
	auto& network = solverHandler.getNetwork();
	const auto nClusters = network.getNumClusters();
	for (auto i = xs; i < xs + xm; i++) {
		gridPointSolution = solutionArray[i]; 
		for (auto l = 0; l < nClusters; l++) {
			if (gridPointSolution[l] < negThreshold1D &&
				gridPointSolution[l] > 0.0) {
				gridPointSolution[l] = negThreshold1D;
			}
			else if (gridPointSolution[l] > -negThreshold1D &&
				gridPointSolution[l] < 0.0) {
				gridPointSolution[l] = -negThreshold1D;
			}
		}
	}
	ierr = DMDAVecRestoreArrayDOF(da, solution, &solutionArray);
	CHKERRQ(ierr);
	PetscFunctionReturn(0);
}
PetscErrorCode checkNegative1D ( TS ts , PetscInt timestep , PetscReal time , Vec solution , void * ) { perf :: ScopedTimer myTimer ( checkNegativeTimer ) ; PetscErrorCode ierr ; double * * solutionArray , * gridPointSolution ; IdType xs , xm , Mx , ys , ym , My , zs , zm , Mz ; PetscFunctionBeginUser ; DM da ; ierr = TSGetDM ( ts , & da ) ; CHKERRQ ( ierr ) ; ierr = DMDAVecGetArrayDOF ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; auto & solverHandler = PetscSolver :: getSolverHandler ( ) ; solverHandler . getLocalCoordinates ( xs , xm , Mx , ys , ym , My , zs , zm , Mz ) ; auto & network = solverHandler . getNetwork ( ) ; const auto nClusters = network . getNumClusters ( ) ; for ( auto i = xs ; i < xs + xm ; i ++ ) { gridPointSolution = solutionArray [ i ] ; for ( auto l = 0 ; l < nClusters ; l ++ ) { if ( gridPointSolution [ l ] < negThreshold1D && gridPointSolution [ l ] > 0.0 ) { gridPointSolution [ l ] = negThreshold1D ; } else if ( gridPointSolution [ l ] > - negThreshold1D && gridPointSolution [ l ] < 0.0 ) { gridPointSolution [ l ] = - negThreshold1D ; } } } ierr = DMDAVecRestoreArrayDOF ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; PetscFunctionReturn ( 0 ) ; }
This is a monitoring method that looks at if there are negative
 concentrations at each time step.
This is a monitoring method that looks at if there are negative concentrations at each time step .
// Initial declaration // Get the da from ts // Get the solutionArray // Get the solver handler and local coordinates // Get the network and dof // Loop on the local grid // Get the pointer to the beginning of the solution data for this grid // point // Loop on the concentrations // Restore the solutionArray