test/io/HDF5UtilsTester.cpp
BOOST_AUTO_TEST_CASE(checkSurface2D)
{
	// Create the test HDF5 file.
	// Done in its own scope so that it closes when the
	// object goes out of scope.
	const std::string testFileName = "test_surface2D.h5";
	{
		BOOST_TEST_MESSAGE("Creating 2D test file");

		// Set the number of grid points and step size
		int nGrid = 5;
		double stepSize = 0.5;
		std::vector<double> grid;
		for (int i = 0; i < nGrid + 2; i++)
			grid.push_back((double)i * stepSize);

		XFile testFile(testFileName, grid, MPI_COMM_WORLD);
	}

	// Set the time information
	double currentTime = 0.0001;
	double previousTime = 0.00001;
	double currentTimeStep = 0.000001;

	// Define the 2D surface information.
	XFile::TimestepGroup::Surface2DType iSurface = {2, 3, 2, 0, 5};
	XFile::TimestepGroup::Data2DType nInter = {0.0, 0.0, 0.5, 0.6, 0.5};
	XFile::TimestepGroup::Data2DType previousIFlux = {0.0, 0.1, 3.0, -1.0, 5.0};

	// Open the file to add concentrations.
	// Done in its own scope so that it closes when the
	// object goes out of scope.
	{
		BOOST_TEST_MESSAGE("Adding 2D timestep group");

		XFile testFile(
			testFileName, MPI_COMM_WORLD, XFile::AccessMode::OpenReadWrite);

		// Set the time step number
		int timeStep = 0;

		// Add the concentration sub group
		auto concGroup = testFile.getGroup<XFile::ConcentrationGroup>();
		BOOST_REQUIRE(concGroup);
		auto tsGroup = concGroup->addTimestepGroup(
			timeStep, currentTime, previousTime, currentTimeStep);
		BOOST_REQUIRE(tsGroup);

		// Write the surface position
		tsGroup->writeSurface2D(iSurface, nInter, previousIFlux);
	}

	// Read the file to check the values we wrote.
	{
		BOOST_TEST_MESSAGE("Opening 2D file to check its contents.");

		XFile testFile(
			testFileName, MPI_COMM_WORLD, XFile::AccessMode::OpenReadOnly);

		// Access the last written timestep group.
		auto concGroup = testFile.getGroup<XFile::ConcentrationGroup>();
		BOOST_REQUIRE(concGroup);
		auto tsGroup = concGroup->getLastTimestepGroup();
		BOOST_REQUIRE(tsGroup);

		// Read the surface position
		auto surfacePos = tsGroup->readSurface2D();
		// Check all the values
		for (int i = 0; i < surfacePos.size(); i++) {
			BOOST_REQUIRE_EQUAL(surfacePos[i], iSurface[i]);
		}

		// Read the interstitial quantity
		auto nInterstitial = tsGroup->readData2D("nInterstitial");
		// Check all the values
		for (int i = 0; i < nInterstitial.size(); i++) {
			BOOST_REQUIRE_CLOSE(nInterstitial[i], nInter[i], 0.0001);
		}

		// Read the interstitial flux
		auto previousIFlux = tsGroup->readData2D("previousFluxI");
		// Check all the values
		for (int i = 0; i < previousIFlux.size(); i++) {
			BOOST_REQUIRE_CLOSE(previousIFlux[i], previousIFlux[i], 0.0001);
		}
	}
}
/**
 * Method checking the writing and reading of the surface position specifically
 * in the case of a 2D grid.
 */
Method checking the writing and reading of the surface position specifically
in the case of a 2D grid.
Method checking the writing and reading of the surface position specifically in the case of a 2D grid .
BOOST_AUTO_TEST_CASE(checkSurface2D)
{
	const std::string testFileName = "test_surface2D.h5";
	{
		BOOST_TEST_MESSAGE("Creating 2D test file");
		int nGrid = 5;
		double stepSize = 0.5;
		std::vector<double> grid;
		for (int i = 0; i < nGrid + 2; i++)
			grid.push_back((double)i * stepSize);
		XFile testFile(testFileName, grid, MPI_COMM_WORLD);
	}
	double currentTime = 0.0001;
	double previousTime = 0.00001;
	double currentTimeStep = 0.000001;
	XFile::TimestepGroup::Surface2DType iSurface = {2, 3, 2, 0, 5};
	XFile::TimestepGroup::Data2DType nInter = {0.0, 0.0, 0.5, 0.6, 0.5};
	XFile::TimestepGroup::Data2DType previousIFlux = {0.0, 0.1, 3.0, -1.0, 5.0};
	{
		BOOST_TEST_MESSAGE("Adding 2D timestep group");
		XFile testFile(
			testFileName, MPI_COMM_WORLD, XFile::AccessMode::OpenReadWrite);
		int timeStep = 0;
		auto concGroup = testFile.getGroup<XFile::ConcentrationGroup>();
		BOOST_REQUIRE(concGroup);
		auto tsGroup = concGroup->addTimestepGroup(
			timeStep, currentTime, previousTime, currentTimeStep);
		BOOST_REQUIRE(tsGroup);
		tsGroup->writeSurface2D(iSurface, nInter, previousIFlux);
	}
	{
		BOOST_TEST_MESSAGE("Opening 2D file to check its contents.");
		XFile testFile(
			testFileName, MPI_COMM_WORLD, XFile::AccessMode::OpenReadOnly);
		auto concGroup = testFile.getGroup<XFile::ConcentrationGroup>();
		BOOST_REQUIRE(concGroup);
		auto tsGroup = concGroup->getLastTimestepGroup();
		BOOST_REQUIRE(tsGroup);
		auto surfacePos = tsGroup->readSurface2D();
		for (int i = 0; i < surfacePos.size(); i++) {
			BOOST_REQUIRE_EQUAL(surfacePos[i], iSurface[i]);
		}
		auto nInterstitial = tsGroup->readData2D("nInterstitial");
		for (int i = 0; i < nInterstitial.size(); i++) {
			BOOST_REQUIRE_CLOSE(nInterstitial[i], nInter[i], 0.0001);
		}
		auto previousIFlux = tsGroup->readData2D("previousFluxI");
		for (int i = 0; i < previousIFlux.size(); i++) {
			BOOST_REQUIRE_CLOSE(previousIFlux[i], previousIFlux[i], 0.0001);
		}
	}
}
BOOST_AUTO_TEST_CASE ( checkSurface2D ) { const std :: string testFileName = " " ; { BOOST_TEST_MESSAGE ( " " ) ; int nGrid = 5 ; double stepSize = 0.5 ; std :: vector < double > grid ; for ( int i = 0 ; i < nGrid + 2 ; i ++ ) grid . push_back ( ( double ) i * stepSize ) ; XFile testFile ( testFileName , grid , MPI_COMM_WORLD ) ; } double currentTime = 0.0001 ; double previousTime = 0.00001 ; double currentTimeStep = 0.000001 ; XFile :: TimestepGroup :: Surface2DType iSurface = { 2 , 3 , 2 , 0 , 5 } ; XFile :: TimestepGroup :: Data2DType nInter = { 0.0 , 0.0 , 0.5 , 0.6 , 0.5 } ; XFile :: TimestepGroup :: Data2DType previousIFlux = { 0.0 , 0.1 , 3.0 , -1.0 , 5.0 } ; { BOOST_TEST_MESSAGE ( " " ) ; XFile testFile ( testFileName , MPI_COMM_WORLD , XFile :: AccessMode :: OpenReadWrite ) ; int timeStep = 0 ; auto concGroup = testFile . getGroup < XFile :: ConcentrationGroup > ( ) ; BOOST_REQUIRE ( concGroup ) ; auto tsGroup = concGroup -> addTimestepGroup ( timeStep , currentTime , previousTime , currentTimeStep ) ; BOOST_REQUIRE ( tsGroup ) ; tsGroup -> writeSurface2D ( iSurface , nInter , previousIFlux ) ; } { BOOST_TEST_MESSAGE ( " " ) ; XFile testFile ( testFileName , MPI_COMM_WORLD , XFile :: AccessMode :: OpenReadOnly ) ; auto concGroup = testFile . getGroup < XFile :: ConcentrationGroup > ( ) ; BOOST_REQUIRE ( concGroup ) ; auto tsGroup = concGroup -> getLastTimestepGroup ( ) ; BOOST_REQUIRE ( tsGroup ) ; auto surfacePos = tsGroup -> readSurface2D ( ) ; for ( int i = 0 ; i < surfacePos . size ( ) ; i ++ ) { BOOST_REQUIRE_EQUAL ( surfacePos [ i ] , iSurface [ i ] ) ; } auto nInterstitial = tsGroup -> readData2D ( " " ) ; for ( int i = 0 ; i < nInterstitial . size ( ) ; i ++ ) { BOOST_REQUIRE_CLOSE ( nInterstitial [ i ] , nInter [ i ] , 0.0001 ) ; } auto previousIFlux = tsGroup -> readData2D ( " " ) ; for ( int i = 0 ; i < previousIFlux . size ( ) ; i ++ ) { BOOST_REQUIRE_CLOSE ( previousIFlux [ i ] , previousIFlux [ i ] , 0.0001 ) ; } } }
Method checking the writing and reading of the surface position specifically
 in the case of a 2D grid.
Method checking the writing and reading of the surface position specifically in the case of a 2D grid .
// Create the test HDF5 file. // Done in its own scope so that it closes when the // object goes out of scope. // Set the number of grid points and step size // Set the time information // Define the 2D surface information. // Open the file to add concentrations. // Done in its own scope so that it closes when the // object goes out of scope. // Set the time step number // Add the concentration sub group // Write the surface position // Read the file to check the values we wrote. // Access the last written timestep group. // Read the surface position // Check all the values // Read the interstitial quantity // Check all the values // Read the interstitial flux // Check all the values