xolotl/solver/src/monitor/Monitor1D.cpp
/**
 * This is a monitoring method that will store the temperature profile
 */
This is a monitoring method that will store the temperature profile
This is a monitoring method that will store the temperature profile
PetscErrorCode
profileTemperature1D(
	TS ts, PetscInt timestep, PetscReal time, Vec solution, void* ictx)
{
	PetscErrorCode ierr;
	IdType xs, xm, Mx, ys, ym, My, zs, zm, Mz;
	PetscFunctionBeginUser;
	auto xolotlComm = util::getMPIComm();
	int procId;
	MPI_Comm_rank(xolotlComm, &procId);
	auto& solverHandler = PetscSolver::getSolverHandler();
	solverHandler.getLocalCoordinates(xs, xm, Mx, ys, ym, My, zs, zm, Mz);
	auto& network = solverHandler.getNetwork();
	const auto dof = network.getDOF();
	auto surfacePos = solverHandler.getSurfacePosition();
	DM da;
	ierr = TSGetDM(ts, &da);
	CHKERRQ(ierr);
	auto grid = solverHandler.getXGrid();
	PetscReal** solutionArray;
	ierr = DMDAVecGetArrayDOFRead(da, solution, &solutionArray);
	CHKERRQ(ierr);
	PetscReal* gridPointSolution;
	std::ofstream outputFile;
	if (procId == 0) {
		outputFile.open("tempProf.txt", std::ios::app);
		outputFile << time;
	}
	for (auto xi = surfacePos + solverHandler.getLeftOffset();
		 xi < Mx - solverHandler.getRightOffset(); xi++) {
		double x = (grid[xi] + grid[xi + 1]) / 2.0 - grid[1];
		double localTemp = 0.0;
		if (xi >= xs && xi < xs + xm) {
			gridPointSolution = solutionArray[xi];
			localTemp = gridPointSolution[dof];
		}
		double temperature = 0.0;
		MPI_Reduce(
			&localTemp, &temperature, 1, MPI_DOUBLE, MPI_SUM, 0, xolotlComm);
		if (procId == 0) {
			outputFile << " " << temperature;
		}
	}
	if (procId == 0) {
		outputFile << std::endl;
		outputFile.close();
	}
	ierr = DMDAVecRestoreArrayDOFRead(da, solution, &solutionArray);
	CHKERRQ(ierr);
	PetscFunctionReturn(0);
}
PetscErrorCode profileTemperature1D ( TS ts , PetscInt timestep , PetscReal time , Vec solution , void * ictx ) { PetscErrorCode ierr ; IdType xs , xm , Mx , ys , ym , My , zs , zm , Mz ; PetscFunctionBeginUser ; auto xolotlComm = util :: getMPIComm ( ) ; int procId ; MPI_Comm_rank ( xolotlComm , & procId ) ; auto & solverHandler = PetscSolver :: getSolverHandler ( ) ; solverHandler . getLocalCoordinates ( xs , xm , Mx , ys , ym , My , zs , zm , Mz ) ; auto & network = solverHandler . getNetwork ( ) ; const auto dof = network . getDOF ( ) ; auto surfacePos = solverHandler . getSurfacePosition ( ) ; DM da ; ierr = TSGetDM ( ts , & da ) ; CHKERRQ ( ierr ) ; auto grid = solverHandler . getXGrid ( ) ; PetscReal * * solutionArray ; ierr = DMDAVecGetArrayDOFRead ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; PetscReal * gridPointSolution ; std :: ofstream outputFile ; if ( procId == 0 ) { outputFile . open ( " " , std :: ios :: app ) ; outputFile << time ; } for ( auto xi = surfacePos + solverHandler . getLeftOffset ( ) ; xi < Mx - solverHandler . getRightOffset ( ) ; xi ++ ) { double x = ( grid [ xi ] + grid [ xi + 1 ] ) / 2.0 - grid [ 1 ] ; double localTemp = 0.0 ; if ( xi >= xs && xi < xs + xm ) { gridPointSolution = solutionArray [ xi ] ; localTemp = gridPointSolution [ dof ] ; } double temperature = 0.0 ; MPI_Reduce ( & localTemp , & temperature , 1 , MPI_DOUBLE , MPI_SUM , 0 , xolotlComm ) ; if ( procId == 0 ) { outputFile << " " << temperature ; } } if ( procId == 0 ) { outputFile << std :: endl ; outputFile . close ( ) ; } ierr = DMDAVecRestoreArrayDOFRead ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; PetscFunctionReturn ( 0 ) ; }
This is a monitoring method that will store the temperature profile
This is a monitoring method that will store the temperature profile
// Initial declarations // Gets the process ID (important when it is running in parallel) // Get the solver handler and local coordinates // Get the network and dof // Get the position of the surface // Get the da from ts // Get the physical grid // Get the array of concentration // Declare the pointer for the concentrations at a specific grid point // Create the output file // Loop on the entire grid // Set x // Check if this process is in charge of xi // Get the pointer to the beginning of the solution data for this // grid point // Get the local temperature // Get the value on procId = 0 // The master process writes in the file // Close the file // Restore the solutionArray