test/io/HDF5UtilsTester.cpp
/**
 * Method checking the writing and reading of the surface position specifically
 * in the case of a 3D grid.
 */
Method checking the writing and reading of the surface position specifically
in the case of a 3D grid.
Method checking the writing and reading of the surface position specifically in the case of a 3D grid .
BOOST_AUTO_TEST_CASE(checkSurface3D)
{
	const std::string testFileName = "test_surface3D.h5";
	{
		BOOST_TEST_MESSAGE("Creating 3D 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::Surface3DType iSurface = {
		{2, 4, 1, 0, 5}, {2, 3, 2, 0, 5}, {6, 1, 2, 3, 2}};
	XFile::TimestepGroup::Data3DType nInter = {{0.0, 0.0, 0.0, 0.0, 0.0},
		{2.0, 3.0, 2.0, 0.0, 0.5}, {0.0, 0.0, 0.0, 0.0, 0.0}};
	XFile::TimestepGroup::Data3DType previousIFlux = {{0.0, 0.0, 0.0, 0.0, 0.0},
		{-2.0, 3.0, 2.0, 0.0, -0.5}, {0.0, 0.0, 0.0, 0.0, 0.0}};
	{
		BOOST_TEST_MESSAGE("Adding 3D 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->writeSurface3D(iSurface, nInter, previousIFlux);
	}
	{
		BOOST_TEST_MESSAGE("Opening 3D 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->readSurface3D();
		for (int i = 0; i < surfacePos.size(); i++) {
			for (int j = 0; j < surfacePos[0].size(); j++) {
				BOOST_REQUIRE_EQUAL(surfacePos[i][j], iSurface[i][j]);
			}
		}
		auto nInterstitial = tsGroup->readData3D("nInterstitial");
		for (int i = 0; i < nInterstitial.size(); i++) {
			for (int j = 0; j < nInterstitial[0].size(); j++) {
				BOOST_REQUIRE_CLOSE(nInterstitial[i][j], nInter[i][j], 0.0001);
			}
		}
		auto previousIFlux = tsGroup->readData3D("previousFluxI");
		for (int i = 0; i < previousIFlux.size(); i++) {
			for (int j = 0; j < previousIFlux[0].size(); j++) {
				BOOST_REQUIRE_CLOSE(
					previousIFlux[i][j], previousIFlux[i][j], 0.0001);
			}
		}
	}
}
BOOST_AUTO_TEST_CASE ( checkSurface3D ) { 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 :: Surface3DType iSurface = { { 2 , 4 , 1 , 0 , 5 } , { 2 , 3 , 2 , 0 , 5 } , { 6 , 1 , 2 , 3 , 2 } } ; XFile :: TimestepGroup :: Data3DType nInter = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } , { 2.0 , 3.0 , 2.0 , 0.0 , 0.5 } , { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } } ; XFile :: TimestepGroup :: Data3DType previousIFlux = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } , { -2.0 , 3.0 , 2.0 , 0.0 , -0.5 } , { 0.0 , 0.0 , 0.0 , 0.0 , 0.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 -> writeSurface3D ( 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 -> readSurface3D ( ) ; for ( int i = 0 ; i < surfacePos . size ( ) ; i ++ ) { for ( int j = 0 ; j < surfacePos [ 0 ] . size ( ) ; j ++ ) { BOOST_REQUIRE_EQUAL ( surfacePos [ i ] [ j ] , iSurface [ i ] [ j ] ) ; } } auto nInterstitial = tsGroup -> readData3D ( " " ) ; for ( int i = 0 ; i < nInterstitial . size ( ) ; i ++ ) { for ( int j = 0 ; j < nInterstitial [ 0 ] . size ( ) ; j ++ ) { BOOST_REQUIRE_CLOSE ( nInterstitial [ i ] [ j ] , nInter [ i ] [ j ] , 0.0001 ) ; } } auto previousIFlux = tsGroup -> readData3D ( " " ) ; for ( int i = 0 ; i < previousIFlux . size ( ) ; i ++ ) { for ( int j = 0 ; j < previousIFlux [ 0 ] . size ( ) ; j ++ ) { BOOST_REQUIRE_CLOSE ( previousIFlux [ i ] [ j ] , previousIFlux [ i ] [ j ] , 0.0001 ) ; } } } }
Method checking the writing and reading of the surface position specifically
 in the case of a 3D grid.
Method checking the writing and reading of the surface position specifically in the case of a 3D grid .
// Create test 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 // Set the 3D surface information. // Open test file to add timestep group with 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 // Check contents of file we wrote. // Access the last written timestep group. // Read the surface position // Check all the values // Check all the values // Check all the values