xolotl/solver/src/monitor/Monitor2D.cpp
/**
 * This is a monitoring method that will save 2D plots of the concentration of
 * a specific cluster at each grid point.
 */
This is a monitoring method that will save 2D plots of the concentration of
a specific cluster at each grid point.
This is a monitoring method that will save 2D plots of the concentration of a specific cluster at each grid point .
PetscErrorCode
monitorSurface2D(TS ts, PetscInt timestep, PetscReal time, Vec solution, void*)
{
	PetscErrorCode ierr;
	const double ***solutionArray, *gridPointSolution;
	IdType xs, xm, Mx, ys, ym, My, zs, zm, Mz;
	double x = 0.0, y = 0.0;
	PetscFunctionBeginUser;
	if (timestep % 10 != 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);
	CHKERRQ(ierr);
	auto& solverHandler = PetscSolver::getSolverHandler();
	solverHandler.getLocalCoordinates(xs, xm, Mx, ys, ym, My, zs, zm, Mz);
	auto grid = solverHandler.getXGrid();
	double hy = solverHandler.getStepSizeY();
	IdType iCluster = 0;
	auto myPoints =
		std::make_shared<std::vector<viz::dataprovider::DataPoint>>();
	viz::dataprovider::DataPoint thePoint;
	for (auto j = 0; j < My; j++) {
		for (auto i = 0; i < Mx; i++) {
			if (i >= xs && i < xs + xm && j >= ys && j < ys + ym) {
				gridPointSolution = solutionArray[j][i];
				x = (grid[i] + grid[i + 1]) / 2.0 - grid[1];
				y = (double)j * hy;
				if (procId == 0) {
					thePoint.value = gridPointSolution[iCluster];
					thePoint.t = time;
					thePoint.x = x;
					thePoint.y = y;
					myPoints->push_back(thePoint);
				}
				else {
					MPI_Send(&x, 1, MPI_DOUBLE, 0, 10, xolotlComm);
					MPI_Send(&y, 1, MPI_DOUBLE, 0, 11, xolotlComm);
					MPI_Send(&gridPointSolution[iCluster], 1, MPI_DOUBLE, 0, 12,
						xolotlComm);
				}
			}
			else if (procId == 0) {
				MPI_Recv(&x, 1, MPI_DOUBLE, MPI_ANY_SOURCE, 10, xolotlComm,
					MPI_STATUS_IGNORE);
				MPI_Recv(&y, 1, MPI_DOUBLE, MPI_ANY_SOURCE, 11, xolotlComm,
					MPI_STATUS_IGNORE);
				double conc = 0.0;
				MPI_Recv(&conc, 1, MPI_DOUBLE, MPI_ANY_SOURCE, 12, xolotlComm,
					MPI_STATUS_IGNORE);
				thePoint.value = conc;
				thePoint.t = time;
				thePoint.x = x;
				thePoint.y = y;
				myPoints->push_back(thePoint);
			}
			MPI_Barrier(xolotlComm);
		}
	}
	if (procId == 0) {
		surfacePlot2D->getDataProvider()->setDataPoints(myPoints);
		std::stringstream title;
		title << "First Cluster";
		surfacePlot2D->getDataProvider()->setDataName(title.str());
		title << " concentration";
		surfacePlot2D->plotLabelProvider->titleLabel = title.str();
		std::stringstream timeLabel;
		timeLabel << "time: " << std::setprecision(4) << time << "s";
		surfacePlot2D->plotLabelProvider->timeLabel = timeLabel.str();
		PetscReal currentTimeStep;
		ierr = TSGetTimeStep(ts, &currentTimeStep);
		CHKERRQ(ierr);
		std::stringstream timeStepLabel;
		timeStepLabel << "dt: " << std::setprecision(4) << currentTimeStep
					  << "s";
		surfacePlot2D->plotLabelProvider->timeStepLabel = timeStepLabel.str();
		std::stringstream fileName;
		fileName << "surface_TS" << timestep << ".png";
		surfacePlot2D->write(fileName.str());
	}
	ierr = DMDAVecRestoreArrayDOFRead(da, solution, &solutionArray);
	CHKERRQ(ierr);
	PetscFunctionReturn(0);
}
PetscErrorCode monitorSurface2D ( TS ts , PetscInt timestep , PetscReal time , Vec solution , void * ) { PetscErrorCode ierr ; const double * * * solutionArray , * gridPointSolution ; IdType xs , xm , Mx , ys , ym , My , zs , zm , Mz ; double x = 0.0 , y = 0.0 ; PetscFunctionBeginUser ; if ( timestep % 10 != 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 ) ; CHKERRQ ( ierr ) ; auto & solverHandler = PetscSolver :: getSolverHandler ( ) ; solverHandler . getLocalCoordinates ( xs , xm , Mx , ys , ym , My , zs , zm , Mz ) ; auto grid = solverHandler . getXGrid ( ) ; double hy = solverHandler . getStepSizeY ( ) ; IdType iCluster = 0 ; auto myPoints = std :: make_shared < std :: vector < viz :: dataprovider :: DataPoint > > ( ) ; viz :: dataprovider :: DataPoint thePoint ; for ( auto j = 0 ; j < My ; j ++ ) { for ( auto i = 0 ; i < Mx ; i ++ ) { if ( i >= xs && i < xs + xm && j >= ys && j < ys + ym ) { gridPointSolution = solutionArray [ j ] [ i ] ; x = ( grid [ i ] + grid [ i + 1 ] ) / 2.0 - grid [ 1 ] ; y = ( double ) j * hy ; if ( procId == 0 ) { thePoint . value = gridPointSolution [ iCluster ] ; thePoint . t = time ; thePoint . x = x ; thePoint . y = y ; myPoints -> push_back ( thePoint ) ; } else { MPI_Send ( & x , 1 , MPI_DOUBLE , 0 , 10 , xolotlComm ) ; MPI_Send ( & y , 1 , MPI_DOUBLE , 0 , 11 , xolotlComm ) ; MPI_Send ( & gridPointSolution [ iCluster ] , 1 , MPI_DOUBLE , 0 , 12 , xolotlComm ) ; } } else if ( procId == 0 ) { MPI_Recv ( & x , 1 , MPI_DOUBLE , MPI_ANY_SOURCE , 10 , xolotlComm , MPI_STATUS_IGNORE ) ; MPI_Recv ( & y , 1 , MPI_DOUBLE , MPI_ANY_SOURCE , 11 , xolotlComm , MPI_STATUS_IGNORE ) ; double conc = 0.0 ; MPI_Recv ( & conc , 1 , MPI_DOUBLE , MPI_ANY_SOURCE , 12 , xolotlComm , MPI_STATUS_IGNORE ) ; thePoint . value = conc ; thePoint . t = time ; thePoint . x = x ; thePoint . y = y ; myPoints -> push_back ( thePoint ) ; } MPI_Barrier ( xolotlComm ) ; } } if ( procId == 0 ) { surfacePlot2D -> getDataProvider ( ) -> setDataPoints ( myPoints ) ; std :: stringstream title ; title << " " ; surfacePlot2D -> getDataProvider ( ) -> setDataName ( title . str ( ) ) ; title << " " ; surfacePlot2D -> plotLabelProvider -> titleLabel = title . str ( ) ; std :: stringstream timeLabel ; timeLabel << " " << std :: setprecision ( 4 ) << time << " " ; surfacePlot2D -> plotLabelProvider -> timeLabel = timeLabel . str ( ) ; PetscReal currentTimeStep ; ierr = TSGetTimeStep ( ts , & currentTimeStep ) ; CHKERRQ ( ierr ) ; std :: stringstream timeStepLabel ; timeStepLabel << " " << std :: setprecision ( 4 ) << currentTimeStep << " " ; surfacePlot2D -> plotLabelProvider -> timeStepLabel = timeStepLabel . str ( ) ; std :: stringstream fileName ; fileName << " " << timestep << " " ; surfacePlot2D -> write ( fileName . str ( ) ) ; } ierr = DMDAVecRestoreArrayDOFRead ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; PetscFunctionReturn ( 0 ) ; }
This is a monitoring method that will save 2D plots of the concentration of
 a specific cluster at each grid point.
This is a monitoring method that will save 2D plots of the concentration of a specific cluster at each grid point .
// Initial declarations // Don't do anything if it is not on the stride // Gets the process ID // Get the da from ts // Get the solutionArray // Get the solver handler and local coordinates // Get the physical grid in the x direction // Setup step size variables // Choice of the cluster to be plotted // Create a DataPoint vector to store the data to give to the data provider // for the visualization // Create a point here so that it is not created and deleted in the loop // Loop on the full grid // If it is the locally owned part of the grid // Get the pointer to the beginning of the solution data for // this grid point // Compute x and y // If it is procId 0 just store the value in the myPoints vector // Modify the Point with the gridPointSolution[iCluster] as // the value and add it to myPoints // Else, the values must be sent to procId 0 // Send the value of the local position to the master // process // Send the value of the local position to the master // process // Send the value of the concentration to the master process // Else if it is NOT the locally owned part of the grid but still // procId == 0, it should receive the values for the point and add // them to myPoint // Get the position // and the concentration // Modify the Point with the received values and add it to // myPoints // Wait for everybody at each grid point // Plot everything from procId == 0 // Get the data provider and give it the points // Change the title of the plot and the name of the data // TODO: get the name or comp of the cluster // 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