xolotl/solver/src/monitor/Monitor1D.cpp
/**
 * This is a monitoring method that update an hdf5 file every given time.
 */
This is a monitoring method that update an hdf5 file every given time.
This is a monitoring method that update an hdf5 file every given time .
PetscErrorCode
startStop1D(TS ts, PetscInt timestep, PetscReal time, Vec solution, void*)
{
	perf::ScopedTimer myTimer(startStopTimer);
	PetscErrorCode ierr;
	const double **solutionArray, *gridPointSolution;
	IdType xs, xm, Mx, ys, ym, My, zs, zm, Mz;
	PetscFunctionBeginUser;
	auto& solverHandler = PetscSolver::getSolverHandler();
	solverHandler.getLocalCoordinates(xs, xm, Mx, ys, ym, My, zs, zm, Mz);
	double previousTime = solverHandler.getPreviousTime();
	double dt = time - previousTime;
	if (((PetscInt)((time + dt / 10.0) / hdf5Stride1D) <= hdf5Previous1D) &&
		timestep > 0) {
		PetscFunctionReturn(0);
	}
	if ((PetscInt)((time + dt / 10.0) / hdf5Stride1D) > hdf5Previous1D)
		hdf5Previous1D++;
	auto xolotlComm = util::getMPIComm();
	DM da;
	ierr = TSGetDM(ts, &da);
	CHKERRQ(ierr);
	ierr = DMDAVecGetArrayDOFRead(da, solution, &solutionArray);
	CHKERRQ(ierr);
	auto& network = solverHandler.getNetwork();
	const auto dof = network.getDOF();
	double concArray[dof + 1][2];
	auto surfacePos = solverHandler.getSurfacePosition();
	io::XFile checkpointFile(
		hdf5OutputName1D, xolotlComm, io::XFile::AccessMode::OpenReadWrite);
	double currentTimeStep;
	ierr = TSGetTimeStep(ts, &currentTimeStep);
	CHKERRQ(ierr);
	auto concGroup = checkpointFile.getGroup<io::XFile::ConcentrationGroup>();
	assert(concGroup);
	auto tsGroup = concGroup->addTimestepGroup(
		timestep, time, previousTime, currentTimeStep);
	auto numSpecies = network.getSpeciesListSize();
	std::vector<std::string> names;
	for (auto id = core::network::SpeciesId(numSpecies); id; ++id) {
		names.push_back(network.getSpeciesName(id));
	}
	if (solverHandler.moveSurface() || solverHandler.getLeftOffset() == 1) {
		tsGroup->writeSurface1D(surfacePos, nInterEvent1D, previousIEventFlux1D,
			nSurf1D, previousSurfFlux1D, names);
	}
	if (solverHandler.getRightOffset() == 1)
		tsGroup->writeBottom1D(nBulk1D, previousBulkFlux1D, names);
	if (solverHandler.burstBubbles())
		tsGroup->writeBursting1D(
			nHeliumBurst1D, nDeuteriumBurst1D, nTritiumBurst1D);
	io::XFile::TimestepGroup::Concs1DType concs(xm);
	for (auto i = 0; i < xm; ++i) {
		auto gridPointSolution = solutionArray[xs + i];
		for (auto l = 0; l < dof + 1; ++l) {
			if (std::fabs(gridPointSolution[l]) > 1.0e-16) {
				concs[i].emplace_back(l, gridPointSolution[l]);
			}
		}
	}
	tsGroup->writeConcentrations(checkpointFile, xs, concs);
	ierr = DMDAVecRestoreArrayDOFRead(da, solution, &solutionArray);
	CHKERRQ(ierr);
	ierr = computeTRIDYN1D(ts, timestep, time, solution, NULL);
	CHKERRQ(ierr);
	PetscFunctionReturn(0);
}
PetscErrorCode startStop1D ( TS ts , PetscInt timestep , PetscReal time , Vec solution , void * ) { perf :: ScopedTimer myTimer ( startStopTimer ) ; PetscErrorCode ierr ; const double * * solutionArray , * gridPointSolution ; IdType xs , xm , Mx , ys , ym , My , zs , zm , Mz ; PetscFunctionBeginUser ; auto & solverHandler = PetscSolver :: getSolverHandler ( ) ; solverHandler . getLocalCoordinates ( xs , xm , Mx , ys , ym , My , zs , zm , Mz ) ; double previousTime = solverHandler . getPreviousTime ( ) ; double dt = time - previousTime ; if ( ( ( PetscInt ) ( ( time + dt / 10.0 ) / hdf5Stride1D ) <= hdf5Previous1D ) && timestep > 0 ) { PetscFunctionReturn ( 0 ) ; } if ( ( PetscInt ) ( ( time + dt / 10.0 ) / hdf5Stride1D ) > hdf5Previous1D ) hdf5Previous1D ++ ; auto xolotlComm = util :: getMPIComm ( ) ; DM da ; ierr = TSGetDM ( ts , & da ) ; CHKERRQ ( ierr ) ; ierr = DMDAVecGetArrayDOFRead ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; auto & network = solverHandler . getNetwork ( ) ; const auto dof = network . getDOF ( ) ; double concArray [ dof + 1 ] [ 2 ] ; auto surfacePos = solverHandler . getSurfacePosition ( ) ; io :: XFile checkpointFile ( hdf5OutputName1D , xolotlComm , io :: XFile :: AccessMode :: OpenReadWrite ) ; double currentTimeStep ; ierr = TSGetTimeStep ( ts , & currentTimeStep ) ; CHKERRQ ( ierr ) ; auto concGroup = checkpointFile . getGroup < io :: XFile :: ConcentrationGroup > ( ) ; assert ( concGroup ) ; auto tsGroup = concGroup -> addTimestepGroup ( timestep , time , previousTime , currentTimeStep ) ; auto numSpecies = network . getSpeciesListSize ( ) ; std :: vector < std :: string > names ; for ( auto id = core :: network :: SpeciesId ( numSpecies ) ; id ; ++ id ) { names . push_back ( network . getSpeciesName ( id ) ) ; } if ( solverHandler . moveSurface ( ) || solverHandler . getLeftOffset ( ) == 1 ) { tsGroup -> writeSurface1D ( surfacePos , nInterEvent1D , previousIEventFlux1D , nSurf1D , previousSurfFlux1D , names ) ; } if ( solverHandler . getRightOffset ( ) == 1 ) tsGroup -> writeBottom1D ( nBulk1D , previousBulkFlux1D , names ) ; if ( solverHandler . burstBubbles ( ) ) tsGroup -> writeBursting1D ( nHeliumBurst1D , nDeuteriumBurst1D , nTritiumBurst1D ) ; io :: XFile :: TimestepGroup :: Concs1DType concs ( xm ) ; for ( auto i = 0 ; i < xm ; ++ i ) { auto gridPointSolution = solutionArray [ xs + i ] ; for ( auto l = 0 ; l < dof + 1 ; ++ l ) { if ( std :: fabs ( gridPointSolution [ l ] ) > 1.0e-16 ) { concs [ i ] . emplace_back ( l , gridPointSolution [ l ] ) ; } } } tsGroup -> writeConcentrations ( checkpointFile , xs , concs ) ; ierr = DMDAVecRestoreArrayDOFRead ( da , solution , & solutionArray ) ; CHKERRQ ( ierr ) ; ierr = computeTRIDYN1D ( ts , timestep , time , solution , NULL ) ; CHKERRQ ( ierr ) ; PetscFunctionReturn ( 0 ) ; }
This is a monitoring method that update an hdf5 file every given time.
This is a monitoring method that update an hdf5 file every given time .
// Initial declaration // Get the solver handler and local coordinates // Compute the dt // Don't do anything if it is not on the stride // Update the previous time // Gets MPI comm // Get the da from ts // Get the solutionArray // Get the network and dof // Create an array for the concentration // Get the position of the surface // Open the existing HDF5 file // Get the current time step // Add a concentration time step group for the current time step. // Get the names of the species in the network // Write the surface positions and the associated interstitial // quantities in the concentration sub group // Write the bottom impurity information if the bottom is a free surface // Write the bursting information if the bubble bursting is used // Determine the concentration values we will write. // We only examine and collect the grid points we own. // TODO measure impact of us building the flattened representation // rather than a ragged 2D representation. // Access the solution data for the current grid point. // Write our concentration data to the current timestep group // in the HDF5 file. // We only write the data for the grid points we own. // Restore the solutionArray