xolotl/solver/src/monitor/Monitor1D.cpp
/**
 * This is a monitoring method that will save 1D plots of the xenon
 * concentration distribution at the middle of the grid.
 */
This is a monitoring method that will save 1D plots of the xenon
concentration distribution at the middle of the grid.
This is a monitoring method that will save 1D plots of the xenon concentration distribution at the middle of the grid .
PetscErrorCode
monitorScatter1D(TS ts, PetscInt timestep, PetscReal time, Vec solution, void*)
{
	perf::ScopedTimer myTimer(scatterTimer);
	PetscErrorCode ierr;
	double **solutionArray, *gridPointSolution;
	IdType xs, xm, Mx, ys, ym, My, zs, zm, Mz;
	PetscFunctionBeginUser;
	if (timestep % 200 != 0)
		PetscFunctionReturn(0);
	auto xolotlComm = util::getMPIComm();
	int procId;
	MPI_Comm_rank(xolotlComm, &procId);
	DM da;
	ierr = TSGetDM(ts, &da);
	CHKERRQ(ierr);
	ierr = DMDAVecGetArrayDOFRead(da, solution, &solutionArray);
	CHKERRQ(ierr);
	auto& solverHandler = PetscSolver::getSolverHandler();
	solverHandler.getLocalCoordinates(xs, xm, Mx, ys, ym, My, zs, zm, Mz);
	using NetworkType = core::network::NEReactionNetwork;
	using Spec = typename NetworkType::Species;
	using Region = typename NetworkType::Region;
	auto& network = dynamic_cast<NetworkType&>(solverHandler.getNetwork());
	auto networkSize = network.getNumClusters();
	auto ix = Mx / 2;
	if (ix >= xs && ix < xs + xm) {
		auto myPoints =
			std::make_shared<std::vector<viz::dataprovider::DataPoint>>();
		gridPointSolution = solutionArray[ix];
		for (auto i = 0; i < networkSize; i++) {
			auto cluster = network.getCluster(i);
			const Region& clReg = cluster.getRegion();
			for (auto j : makeIntervalRange(clReg[Spec::Xe])) {
				viz::dataprovider::DataPoint aPoint;
				aPoint.value = gridPointSolution[i];
				aPoint.t = time;
				aPoint.x = (double)j;
				myPoints->push_back(aPoint);
			}
		}
		scatterPlot1D->getDataProvider()->setDataPoints(myPoints);
		std::stringstream title;
		title << "Size Distribution";
		scatterPlot1D->getDataProvider()->setDataName(title.str());
		scatterPlot1D->plotLabelProvider->titleLabel = title.str();
		std::stringstream timeLabel;
		timeLabel << "time: " << std::setprecision(4) << time << "s";
		scatterPlot1D->plotLabelProvider->timeLabel = timeLabel.str();
		PetscReal currentTimeStep;
		ierr = TSGetTimeStep(ts, &currentTimeStep);
		CHKERRQ(ierr);
		std::stringstream timeStepLabel;
		timeStepLabel << "dt: " << std::setprecision(4) << currentTimeStep
					  << "s";
		scatterPlot1D->plotLabelProvider->timeStepLabel = timeStepLabel.str();
		std::stringstream fileName;
		fileName << "Scatter_TS" << timestep << ".png";
		scatterPlot1D->write(fileName.str());
	}
	ierr = DMDAVecRestoreArrayDOFRead(da, solution, &solutionArray);
	CHKERRQ(ierr);
	PetscFunctionReturn(0);
}
PetscErrorCode monitorScatter1D ( TS ts , PetscInt timestep , PetscReal time , Vec solution , void * ) { perf :: ScopedTimer myTimer ( scatterTimer ) ; PetscErrorCode ierr ; double * * solutionArray , * gridPointSolution ; IdType xs , xm , Mx , ys , ym , My , zs , zm , Mz ; PetscFunctionBeginUser ; if ( timestep % 200 != 0 ) PetscFunctionReturn ( 0 ) ; auto xolotlComm = util :: getMPIComm ( ) ; int procId ; MPI_Comm_rank ( xolotlComm , & procId ) ; DM da ; ierr = TSGetDM ( ts , & da ) ; CHKERRQ ( ierr ) ; ierr = DMDAVecGetArrayDOFRead ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; auto & solverHandler = PetscSolver :: getSolverHandler ( ) ; solverHandler . getLocalCoordinates ( xs , xm , Mx , ys , ym , My , zs , zm , Mz ) ; using NetworkType = core :: network :: NEReactionNetwork ; using Spec = typename NetworkType :: Species ; using Region = typename NetworkType :: Region ; auto & network = dynamic_cast < NetworkType & > ( solverHandler . getNetwork ( ) ) ; auto networkSize = network . getNumClusters ( ) ; auto ix = Mx / 2 ; if ( ix >= xs && ix < xs + xm ) { auto myPoints = std :: make_shared < std :: vector < viz :: dataprovider :: DataPoint > > ( ) ; gridPointSolution = solutionArray [ ix ] ; for ( auto i = 0 ; i < networkSize ; i ++ ) { auto cluster = network . getCluster ( i ) ; const Region & clReg = cluster . getRegion ( ) ; for ( auto j : makeIntervalRange ( clReg [ Spec :: Xe ] ) ) { viz :: dataprovider :: DataPoint aPoint ; aPoint . value = gridPointSolution [ i ] ; aPoint . t = time ; aPoint . x = ( double ) j ; myPoints -> push_back ( aPoint ) ; } } scatterPlot1D -> getDataProvider ( ) -> setDataPoints ( myPoints ) ; std :: stringstream title ; title << " " ; scatterPlot1D -> getDataProvider ( ) -> setDataName ( title . str ( ) ) ; scatterPlot1D -> plotLabelProvider -> titleLabel = title . str ( ) ; std :: stringstream timeLabel ; timeLabel << " " << std :: setprecision ( 4 ) << time << " " ; scatterPlot1D -> plotLabelProvider -> timeLabel = timeLabel . str ( ) ; PetscReal currentTimeStep ; ierr = TSGetTimeStep ( ts , & currentTimeStep ) ; CHKERRQ ( ierr ) ; std :: stringstream timeStepLabel ; timeStepLabel << " " << std :: setprecision ( 4 ) << currentTimeStep << " " ; scatterPlot1D -> plotLabelProvider -> timeStepLabel = timeStepLabel . str ( ) ; std :: stringstream fileName ; fileName << " " << timestep << " " ; scatterPlot1D -> write ( fileName . str ( ) ) ; } ierr = DMDAVecRestoreArrayDOFRead ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; PetscFunctionReturn ( 0 ) ; }
This is a monitoring method that will save 1D plots of the xenon
 concentration distribution at the middle of the grid.
This is a monitoring method that will save 1D plots of the xenon concentration distribution at the middle of the grid .
// Initial declarations // Don't do anything if it is not on the stride // Gets the process ID (important when it is running in parallel) // Get the da from ts // Get the solutionArray // Get the solver handler and local coordinates // Get the network and its size // Get the index of the middle of the grid // If the middle is on this process // Create a DataPoint vector to store the data to give to the data // provider for the visualization // Get the pointer to the beginning of the solution data for this grid // point // Create a Point with the concentration[i] as the value // and add it to myPoints // Get the data provider and give it the points // Change the title of the plot and the name of the data // Give the time to the label provider // Get the current time step // Give the timestep to the label provider // Render and save in file // Restore the solutionArray