From c55f013cb05de1fb796eeb957ae00cdab282da18 Mon Sep 17 00:00:00 2001 From: wuwenbin2006 Date: Tue, 21 Aug 2018 12:01:38 -0400 Subject: [PATCH 1/7] Cancel memory release of materials in the destructor function of Geometry class In the destructor function of Geometry class, materials should not be released in case they will be needed somewhere else. The materials could be freed explicitly by dict.clear() in python and delete in cpp. --- src/Geometry.cpp | 15 ++++----------- src/TraverseSegments.cpp | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Geometry.cpp b/src/Geometry.cpp index 437431ed9..1dab4c994 100644 --- a/src/Geometry.cpp +++ b/src/Geometry.cpp @@ -42,13 +42,6 @@ Geometry::Geometry() { * @brief Destructor clears FSR to Cells and Materials maps. */ Geometry::~Geometry() { - - /* Free all materials */ - std::map materials = _root_universe->getAllMaterials(); - std::map::iterator iter; - for (iter = materials.begin(); iter != materials.end(); ++iter) - delete iter->second; - /* Free all surfaces */ if (_loaded_from_file) { std::map surfaces = getAllSurfaces(); @@ -422,8 +415,8 @@ std::map Geometry::getAllSurfaces() { surfs = cell->getSurfaces(); for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = (*s_iter).second->_surface; - all_surfs[surf->getId()] = surf; + surf = (*s_iter).second->_surface; + all_surfs[surf->getId()] = surf; } } } @@ -2625,11 +2618,11 @@ void Geometry::computeFissionability(Universe* univ) { Material* material; std::map materials; - std::map::iterator mat_iter; + std::map::iterator mat_iter; Universe* universe; std::map universes; - std::map::iterator univ_iter; + std::map::iterator univ_iter; /* If no Universe was passed in as an argument, then this is the first * recursive call from a user via Python, so get the base Universe */ diff --git a/src/TraverseSegments.cpp b/src/TraverseSegments.cpp index f1fc1a7d7..adee8b835 100644 --- a/src/TraverseSegments.cpp +++ b/src/TraverseSegments.cpp @@ -572,7 +572,7 @@ void TraverseSegments::traceStackOTF(Track* flattened_track, int polar_index, /* Set the current x and y coordinates */ double x_curr = x_start_2D; - double y_curr = flattened_track->getStart()->getY(); + double y_curr = y_start_2D; /* Loop over 2D segments */ double first_start_z = start_z; From 68dd53a6b91ebee8bc3d860e41a6676c5c36f9be Mon Sep 17 00:00:00 2001 From: wuwenbin2006 Date: Mon, 27 Aug 2018 11:37:55 -0400 Subject: [PATCH 2/7] Cell::toString output halfspace indicator, and some tiny corrections --- src/Cell.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Cell.cpp b/src/Cell.cpp index 9ef8ca348..ef579533f 100644 --- a/src/Cell.cpp +++ b/src/Cell.cpp @@ -299,7 +299,7 @@ double* Cell::getRotationMatrix() { * @param units the angular units in "radians" or "degrees" (default) */ void Cell::retrieveRotation(double* rotations, int num_axes, - std::string units) { + std::string units) { if (num_axes != 3) log_printf(ERROR, "Unable to get rotation with %d axes for Cell %d. " "The rotation array should be length 3.", num_axes, _id); @@ -1003,7 +1003,7 @@ void Cell::setNumRings(int num_rings) { log_printf(ERROR, "Unable to give %d rings to Cell %d since this is " "a negative number", num_rings, _id); - _num_rings = num_rings; + _num_rings = num_rings;//seems no need if equals 1 } @@ -1367,7 +1367,7 @@ void Cell::ringify(std::vector& subcells, double max_radius) { increment = fabs(radius1 - radius2) / _num_rings; /* Heuristic to improve area-balancing for low number of rings */ - if (halfspace1 == 0 && radius1 == max_radius && _num_rings < 3) + if (radius1 == max_radius && _num_rings < 3) increment = 1.5 * (radius1 - radius2) / _num_rings; } @@ -1557,7 +1557,8 @@ std::string Cell::toString() { std::map::iterator iter; string << ", Surfaces: "; for (iter = _surfaces.begin(); iter != _surfaces.end(); ++iter) - string << iter->second->_surface->toString() << ", "; + string << "\nhalfspace = " << iter->second->_halfspace << ", " << + iter->second->_surface->toString(); return string.str(); } From d583160929e68a69657a1ea2cde7b4898ab1d25e Mon Sep 17 00:00:00 2001 From: wuwenbin2006 Date: Tue, 28 Aug 2018 12:25:15 -0400 Subject: [PATCH 3/7] Some changes in cell ringify, avoiding to add outermost zcylinder to all newly created cells --- src/Cell.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Cell.cpp b/src/Cell.cpp index ef579533f..5730142ab 100644 --- a/src/Cell.cpp +++ b/src/Cell.cpp @@ -1002,8 +1002,11 @@ void Cell::setNumRings(int num_rings) { if (num_rings < 0) log_printf(ERROR, "Unable to give %d rings to Cell %d since this is " "a negative number", num_rings, _id); - - _num_rings = num_rings;//seems no need if equals 1 + + if (num_rings == 1) + _num_rings = 0; + else + _num_rings = num_rings; } @@ -1061,7 +1064,7 @@ void Cell::addSurface(int halfspace, Surface* surface) { */ void Cell::removeSurface(Surface* surface) { - if (_surfaces.find(surface->getId()) != _surfaces.end()) { + if (surface != NULL && _surfaces.find(surface->getId()) != _surfaces.end()) { delete _surfaces[surface->getId()]; _surfaces.erase(surface->getId()); } @@ -1331,7 +1334,7 @@ void Cell::ringify(std::vector& subcells, double max_radius) { } if (num_zcylinders > 2) - log_printf(NORMAL, "Unable to ringify Cell %d since it " + log_printf(ERROR, "Unable to ringify Cell %d since it " "contains more than 2 ZCYLINDER Surfaces", _id); if (x1 != x2 && num_zcylinders == 2) @@ -1407,6 +1410,7 @@ void Cell::ringify(std::vector& subcells, double max_radius) { Cell* ring = (*iter3)->clone(); ring->setNumSectors(0); ring->setNumRings(0); + ring->removeSurface(zcylinder1); /* Add ZCylinder only if this is not the outermost ring in an * unbounded Cell (i.e. the moderator in a fuel pin cell) */ @@ -1434,6 +1438,7 @@ void Cell::ringify(std::vector& subcells, double max_radius) { Cell* ring = clone(); ring->setNumSectors(0); ring->setNumRings(0); + ring->removeSurface(zcylinder1); /* Add ZCylinder only if this is not the outermost ring in an * unbounded Cell (i.e. the moderator in a fuel pin cell) */ From 0755ce99ea29381cfd580cf654424db983c1917d Mon Sep 17 00:00:00 2001 From: wuwenbin2006 Date: Tue, 28 Aug 2018 16:58:56 -0400 Subject: [PATCH 4/7] fix a bug in LocalCoords::detectLoop --- src/LocalCoords.cpp | 6 ++++-- src/Surface.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/LocalCoords.cpp b/src/LocalCoords.cpp index c072c16ed..cb462fe1b 100644 --- a/src/LocalCoords.cpp +++ b/src/LocalCoords.cpp @@ -203,12 +203,14 @@ void LocalCoords::detectLoop() { int n = 0; LocalCoords* iter = _next; - while (_next != NULL) { + while (iter != NULL) { iter = iter->getNext(); n++; if (n > 1000) log_printf(ERROR, "Infinite loop of coords"); } + log_printf(DEBUG, "The LocalCoords is: %s\n", toString().c_str()); + log_printf(NORMAL, "The depth of the chain is %d \n", n); } @@ -413,7 +415,7 @@ LocalCoords* LocalCoords::getHighestLevel() { /** - * @brief Translate all of the x,y coordinates for each LocalCoords object in + * @brief Translate all of the x,y,z coordinates for each LocalCoords object in * the linked list. * @details This method will traverse the entire linked list and apply the * translation to each element. diff --git a/src/Surface.cpp b/src/Surface.cpp index 2ca767543..1ab36975b 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -1060,7 +1060,7 @@ std::string ZCylinder::toString() { std::stringstream string; string << "Surface ID = " << _id - << ", name " << _name + << ", name = " << _name << ", type = ZCYLINDER " << ", A = " << _A << ", B = " << _B << ", C = " << _C << ", D = " << _D << ", E = " << _E From 746a60d99f99d170e8e37f0a37f52baf1ed47a8d Mon Sep 17 00:00:00 2001 From: wuwenbin2006 Date: Tue, 4 Sep 2018 12:46:54 -0400 Subject: [PATCH 5/7] fixed some bugs for EXPLICT_3D running, but it still fails to get right solutions. --- src/Geometry.cpp | 10 +++++----- src/LocalCoords.cpp | 2 +- src/Surface.cpp | 5 ++--- src/TrackGenerator.cpp | 10 +++++++++- src/TrackGenerator3D.cpp | 29 ++++++++++++++++++++++++----- 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/Geometry.cpp b/src/Geometry.cpp index 1dab4c994..0f5fe2c6c 100644 --- a/src/Geometry.cpp +++ b/src/Geometry.cpp @@ -2045,12 +2045,12 @@ void Geometry::segmentize3D(Track3D* track, bool setup) { } /* Calculate the local centroid of the segment if available */ - if (_contains_FSR_centroids && !setup) { - Point* centroid = getFSRCentroid(fsr_id); + if (!setup) { + //Point* centroid = getFSRCentroid(fsr_id); Point* starting_point = start.getHighestLevel()->getPoint(); - double x_start = starting_point->getX() - centroid->getX(); - double y_start = starting_point->getY() - centroid->getY(); - double z_start = starting_point->getZ() - centroid->getZ(); + double x_start = starting_point->getX(); + double y_start = starting_point->getY(); + double z_start = starting_point->getZ(); new_segment->_starting_position[0] = x_start; new_segment->_starting_position[1] = y_start; new_segment->_starting_position[2] = z_start; diff --git a/src/LocalCoords.cpp b/src/LocalCoords.cpp index cb462fe1b..19c2255ae 100644 --- a/src/LocalCoords.cpp +++ b/src/LocalCoords.cpp @@ -477,7 +477,7 @@ void LocalCoords::prune() { LocalCoords* next = curr->getPrev(); /* Iterate over LocalCoords beneath this one in the linked list */ - while (curr != this) { + while (curr != this) {// it seems nothing has been down in this while loop next = curr->getPrev(); if (curr->getPosition() == -1) curr->deleteArray(); diff --git a/src/Surface.cpp b/src/Surface.cpp index 1ab36975b..d17a62d38 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -991,11 +991,9 @@ int ZCylinder::intersection(Point* point, double azim, double polar, Point* poin else { /* Determine first point of intersection */ - double interior = pow(ycurr - y0, 2.0) + pow(xcurr - x0, 2.0); - if (interior < 0.0) - interior = 0.0; xcurr = (-b + sqrt(discr)) / (2*a); ycurr = y0 + m * (xcurr - x0); + double interior = pow(ycurr - y0, 2.0) + pow(xcurr - x0, 2.0); zcurr = z0 + sqrt(interior) * tan(M_PI_2 - polar); points[num].setCoords(xcurr, ycurr, zcurr); @@ -1021,6 +1019,7 @@ int ZCylinder::intersection(Point* point, double azim, double polar, Point* poin /* Determine second point of intersection */ xcurr = (-b - sqrt(discr)) / (2*a); ycurr = y0 + m * (xcurr - x0); + interior = pow(ycurr - y0, 2.0) + pow(xcurr - x0, 2.0); zcurr = z0 + sqrt(interior) * tan(M_PI_2 - polar); points[num].setCoords(xcurr, ycurr, zcurr); diff --git a/src/TrackGenerator.cpp b/src/TrackGenerator.cpp index 6bd997c0f..b8771c850 100644 --- a/src/TrackGenerator.cpp +++ b/src/TrackGenerator.cpp @@ -1625,7 +1625,15 @@ void TrackGenerator::resetStatus() { void TrackGenerator::allocateTemporarySegments() {} -//FIXME: description +/** + * @brief Compute and return the track UID number + * @details Compute and return the track UID number based on the azimuthal + number and the xy_index. Track UID number is also the index in the + Track** TrackGenerator::_tracks_2D_array + * @param a the azimuthal number of a track + * @param x the xy_index of a track + * @return the track UID number of a track + */ int TrackGenerator::get2DTrackID(int a, int x) { int uid = 0; diff --git a/src/TrackGenerator3D.cpp b/src/TrackGenerator3D.cpp index c3d05df06..582faae54 100644 --- a/src/TrackGenerator3D.cpp +++ b/src/TrackGenerator3D.cpp @@ -908,7 +908,13 @@ void TrackGenerator3D::initialize2DTrackChains() { } -//FIXME: description +/** + * @brief Traverses all the 3D chain tracks, and split each 3D chain track into + 3D tracks belonging to the z-stacks + * @param tcis The array of track chain indices + * @param num_chains The size of the array of track chain indices + * @param save_tracks Whether or not to save the 3D tracks + */ void TrackGenerator3D::getCycleTrackData(TrackChainIndexes* tcis, int num_chains, bool save_tracks) { @@ -942,7 +948,13 @@ void TrackGenerator3D::getCycleTrackData(TrackChainIndexes* tcis, } -//FIXME: description +/** + * @brief Compute the coordinates of a 3D chain track, and the link number of + the 2D track where its start point reseide on + * @param tci the track chain index of a chain track + * @param track_3D the chain track + * @return the link number of the 2D track where its start point reseide on + */ int TrackGenerator3D::getFirst2DTrackLinkIndex(TrackChainIndexes* tci, Track3D* track_3D) { @@ -1035,7 +1047,7 @@ int TrackGenerator3D::getFirst2DTrackLinkIndex(TrackChainIndexes* tci, * boundaries is split into multiple tracks by finding those * x and y intersections. If create_tracks is set to true, the Tracks * will be altered to represent the correct 3D Tracks. If not, the - * number of tracks in the train will simply be counted. Whenever this + * number of tracks in the chain will simply be counted. Whenever this * function is called, the number of tracks in the associated z-stacks * are incremented. * @param track The 3D track to be decomposed @@ -1128,7 +1140,7 @@ void TrackGenerator3D::set3DTrackData(TrackChainIndexes* tci, break; /* If the Z boundary or last link or the desired link has been reached, - * exit */ + * exit. tci->_link appoints the desired track*/ if (dl_z < dl_xy || track_2D->getXYIndex() >= _num_y[tci->_azim] || tci->_link == link - first_link) end_of_chain = true; @@ -1258,8 +1270,15 @@ void TrackGenerator3D::segmentize() { #pragma omp parallel for for (int i=0; i < _num_x[a] + _num_y[a]; i++) { for (int p=0; p < _num_polar; p++) { - for (int z=0; z < _tracks_per_stack[a][i][p]; z++) + for (int z=0; z < _tracks_per_stack[a][i][p]; z++){ _geometry->segmentize3D(&_tracks_3D[a][i][p][z]); + TrackStackIndexes tsi; + tsi._azim = a; + tsi._xy = i; + tsi._polar = p; + tsi._z = z; + _tracks_3D[a][i][p][z].setUid(get3DTrackID(&tsi)); + } } } From 6954d5dc8f108eeef46772e9389e3e3ec4fd8dc9 Mon Sep 17 00:00:00 2001 From: wuwenbin2006 Date: Fri, 28 Sep 2018 13:40:37 -0400 Subject: [PATCH 6/7] Abundant surfaces when sectorized and ringified. --- src/Cell.cpp | 10 +++++++--- src/Geometry.cpp | 13 +++++++++++-- src/LocalCoords.cpp | 2 +- src/Surface.cpp | 6 ++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Cell.cpp b/src/Cell.cpp index 5730142ab..956f22a71 100644 --- a/src/Cell.cpp +++ b/src/Cell.cpp @@ -299,7 +299,7 @@ double* Cell::getRotationMatrix() { * @param units the angular units in "radians" or "degrees" (default) */ void Cell::retrieveRotation(double* rotations, int num_axes, - std::string units) { + std::string units) { if (num_axes != 3) log_printf(ERROR, "Unable to get rotation with %d axes for Cell %d. " "The rotation array should be length 3.", num_axes, _id); @@ -1422,8 +1422,10 @@ void Cell::ringify(std::vector& subcells, double max_radius) { rings.push_back(ring); continue; } - else + else { ring->addSurface(+1, *(iter2+1)); + ring->removeSurface(zcylinder2); + } /* Store the clone in the parent Cell's container of ring Cells */ rings.push_back(ring); @@ -1450,8 +1452,10 @@ void Cell::ringify(std::vector& subcells, double max_radius) { rings.push_back(ring); break; } - else + else { ring->addSurface(+1, *(iter2+1)); + ring->removeSurface(zcylinder2); + } /* Store the clone in the parent Cell's container of ring Cells */ rings.push_back(ring); diff --git a/src/Geometry.cpp b/src/Geometry.cpp index 0f5fe2c6c..59630711f 100644 --- a/src/Geometry.cpp +++ b/src/Geometry.cpp @@ -42,6 +42,15 @@ Geometry::Geometry() { * @brief Destructor clears FSR to Cells and Materials maps. */ Geometry::~Geometry() { + + /* Free all materials */ + if (_loaded_from_file) { + std::map materials = _root_universe->getAllMaterials(); + std::map::iterator iter; + for (iter = materials.begin(); iter != materials.end(); ++iter) + delete iter->second; + } + /* Free all surfaces */ if (_loaded_from_file) { std::map surfaces = getAllSurfaces(); @@ -415,8 +424,8 @@ std::map Geometry::getAllSurfaces() { surfs = cell->getSurfaces(); for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = (*s_iter).second->_surface; - all_surfs[surf->getId()] = surf; + surf = (*s_iter).second->_surface; + all_surfs[surf->getId()] = surf; } } } diff --git a/src/LocalCoords.cpp b/src/LocalCoords.cpp index 19c2255ae..6c8f9196c 100644 --- a/src/LocalCoords.cpp +++ b/src/LocalCoords.cpp @@ -210,7 +210,7 @@ void LocalCoords::detectLoop() { log_printf(ERROR, "Infinite loop of coords"); } log_printf(DEBUG, "The LocalCoords is: %s\n", toString().c_str()); - log_printf(NORMAL, "The depth of the chain is %d \n", n); + log_printf(DEBUG, "The depth of the chain is %d \n", n); } diff --git a/src/Surface.cpp b/src/Surface.cpp index d17a62d38..bb23d1849 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -617,7 +617,8 @@ std::string YPlane::toString() { << ", name = " << _name << ", type = YPLANE " << ", A = " << _A << ", B = " << _B - << ", C = " << _C << ", y = " << _y; + << ", C = " << _C << ", D = " << _D + << ", y = " << _y; return string.str(); } @@ -698,7 +699,8 @@ std::string ZPlane::toString() { << ", name = " << _name << ", type = ZPLANE " << ", A = " << _A << ", B = " << _B - << ", C = " << _C << ", z = " << _z; + << ", C = " << _C << ", D = " << _D + << ", z = " << _z; return string.str(); } From fca1d1c8757b872be9ea670abdb3b0c0aaa62302 Mon Sep 17 00:00:00 2001 From: wuwenbin2006 Date: Mon, 15 Oct 2018 11:20:52 -0400 Subject: [PATCH 7/7] Merge branch 'Fix-calculateBoundaries-function' into some-fixes-for-explict3D --- src/Universe.cpp | 284 ++++++++--------- .../results_true.dat | 30 ++ .../test_calculate_boundaries.py | 294 ++++++++++++++++++ tests/testing_harness.py | 7 +- 4 files changed, 455 insertions(+), 160 deletions(-) create mode 100644 tests/test_calculate_boundaries/results_true.dat create mode 100644 tests/test_calculate_boundaries/test_calculate_boundaries.py diff --git a/src/Universe.cpp b/src/Universe.cpp index 488335b63..e5eed95b6 100644 --- a/src/Universe.cpp +++ b/src/Universe.cpp @@ -694,294 +694,260 @@ void Universe::calculateBoundaries() { /* Calculate the minimum reachable x-coordinate in the geometry and store it * in _min_x */ - double min_x = -std::numeric_limits::infinity(); + double min_x = std::numeric_limits::infinity(); std::map::iterator c_iter; std::map::iterator s_iter; Surface* surf; int halfspace; + /* Calculate the boundary condition at the minimum + * reachable x-coordinate in the Universe and store it in _min_x_bound + */ + _min_x_bound = BOUNDARY_NONE; + /* Check if the universe contains a cell with an x-min boundary */ for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { std::map surfs = c_iter->second->getSurfaces(); + double cell_min_x = -std::numeric_limits::infinity(); + boundaryType cell_min_x_bound = BOUNDARY_NONE; for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { surf = s_iter->second->_surface; halfspace = s_iter->second->_halfspace; if (surf->getSurfaceType() == XPLANE && halfspace == +1 && - surf->getBoundaryType() != BOUNDARY_NONE) - min_x = surf->getMinX(halfspace); + surf->getBoundaryType() != BOUNDARY_NONE) { + if(surf->getMinX(halfspace) > cell_min_x) { + cell_min_x = surf->getMinX(halfspace); + cell_min_x_bound = surf->getBoundaryType(); + } + } + } + if(cell_min_x_bound != BOUNDARY_NONE && cell_min_x < min_x) { + min_x = cell_min_x; + _min_x_bound = cell_min_x_bound; } } /* If a x-min boundary was not found, get the x-min from the bounding boxes * of the cells */ - if (min_x == -std::numeric_limits::infinity()) + if (min_x == std::numeric_limits::infinity()) { for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) min_x = std::min(min_x, c_iter->second->getMinX()); + } _min_x = min_x; /* Calculate the maximum reachable x-coordinate in the geometry and store it * in _max_x */ - double max_x = std::numeric_limits::infinity(); + double max_x = -std::numeric_limits::infinity(); + + /* Calculate the boundary condition at the maximum + * reachable x-coordinate in the Universe and store it in _max_x_bound + */ + _max_x_bound = BOUNDARY_NONE; /* Check if the universe contains a cell with an x-max boundary */ for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { std::map surfs = c_iter->second->getSurfaces(); - + + double cell_max_x = std::numeric_limits::infinity(); + boundaryType cell_max_x_bound = BOUNDARY_NONE; for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { surf = s_iter->second->_surface; halfspace = s_iter->second->_halfspace; + if (surf->getSurfaceType() == XPLANE && halfspace == -1 && - surf->getBoundaryType() != BOUNDARY_NONE) - max_x = surf->getMaxX(halfspace); + surf->getBoundaryType() != BOUNDARY_NONE) { + if(surf->getMaxX(halfspace) < cell_max_x) { + cell_max_x = surf->getMaxX(halfspace); + cell_max_x_bound = surf->getBoundaryType(); + } + } + } + if(cell_max_x_bound != BOUNDARY_NONE && cell_max_x > max_x) { + max_x = cell_max_x; + _max_x_bound = cell_max_x_bound; } } /* If a x-max boundary was not found, get the x-max from the bounding boxes * of the cells */ - if (max_x == std::numeric_limits::infinity()) + if (max_x == -std::numeric_limits::infinity()) { for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) max_x = std::max(max_x, c_iter->second->getMaxX()); + } _max_x = max_x; /* Calculate the minimum reachable y-coordinate in the geometry and store it * in _min_y */ - double min_y = -std::numeric_limits::infinity(); + double min_y = std::numeric_limits::infinity(); + + /* Calculate the boundary condition at the minimum + * reachable y-coordinate in the Universe and store it in _min_y_bound + */ + _min_y_bound = BOUNDARY_NONE; /* Check if the universe contains a cell with an y-min boundary */ for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { std::map surfs = c_iter->second->getSurfaces(); + double cell_min_y = -std::numeric_limits::infinity(); + boundaryType cell_min_y_bound = BOUNDARY_NONE; for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { surf = s_iter->second->_surface; halfspace = s_iter->second->_halfspace; if (surf->getSurfaceType() == YPLANE && halfspace == +1 && - surf->getBoundaryType() != BOUNDARY_NONE) - min_y = surf->getMinY(halfspace); + surf->getBoundaryType() != BOUNDARY_NONE) { + if(surf->getMinY(halfspace) > cell_min_y) { + cell_min_y = surf->getMinY(halfspace); + cell_min_y_bound = surf->getBoundaryType(); + } + } + } + if(cell_min_y_bound != BOUNDARY_NONE && cell_min_y < min_y) { + min_y = cell_min_y; + _min_y_bound = cell_min_y_bound; } } /* If a y-min boundary was not found, get the y-min from the bounding boxes * of the cells */ - if (min_y == -std::numeric_limits::infinity()) + if (min_y == std::numeric_limits::infinity()) { for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) min_y = std::min(min_y, c_iter->second->getMinY()); + } _min_y = min_y; /* Calculate the maximum reachable y-coordinate in the geometry and store it * in _max_y */ - double max_y = std::numeric_limits::infinity(); + double max_y = -std::numeric_limits::infinity(); + + /* Calculate the boundary condition at the maximum + * reachable y-coordinate in the Universe and store it in _max_y_bound + */ + _max_y_bound = BOUNDARY_NONE; /* Check if the universe contains a cell with an y-max boundary */ for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { std::mapsurfs = c_iter->second->getSurfaces(); + double cell_max_y = std::numeric_limits::infinity(); + boundaryType cell_max_y_bound = BOUNDARY_NONE; for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { surf = s_iter->second->_surface; halfspace = s_iter->second->_halfspace; + if (surf->getSurfaceType() == YPLANE && halfspace == -1 && - surf->getBoundaryType() != BOUNDARY_NONE) - max_y = surf->getMaxY(halfspace); + surf->getBoundaryType() != BOUNDARY_NONE) { + if(surf->getMaxY(halfspace) < cell_max_y) { + cell_max_y = surf->getMaxY(halfspace); + cell_max_y_bound = surf->getBoundaryType(); + } + } + } + if(cell_max_y_bound != BOUNDARY_NONE && cell_max_y > max_y) { + max_y = cell_max_y; + _max_y_bound = cell_max_y_bound; } } /* If a y-max boundary was not found, get the y-max from the bounding boxes * of the cells */ - if (max_y == std::numeric_limits::infinity()) + if (max_y == -std::numeric_limits::infinity()) { for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) max_y = std::max(max_y, c_iter->second->getMaxY()); + } _max_y = max_y; /* Calculate the minimum reachable z-coordinate in the geometry and store it * in _min_z */ - double min_z = -std::numeric_limits::infinity(); + double min_z = std::numeric_limits::infinity(); + + /* Calculate the boundary condition at the minimum + * reachable z-coordinate in the Universe and store it in _min_z_bound + */ + _min_z_bound = BOUNDARY_NONE; /* Check if the universe contains a cell with an z-min boundary */ for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { std::map surfs = c_iter->second->getSurfaces(); + double cell_min_z = -std::numeric_limits::infinity(); + boundaryType cell_min_z_bound = BOUNDARY_NONE; for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { surf = s_iter->second->_surface; halfspace = s_iter->second->_halfspace; if (surf->getSurfaceType() == ZPLANE && halfspace == +1 && - surf->getBoundaryType() != BOUNDARY_NONE) - min_z = surf->getMinZ(halfspace); + surf->getBoundaryType() != BOUNDARY_NONE) { + if(surf->getMinZ(halfspace) > cell_min_z) { + cell_min_z = surf->getMinZ(halfspace); + cell_min_z_bound = surf->getBoundaryType(); + } + } + } + if(cell_min_z_bound != BOUNDARY_NONE && cell_min_z < min_z) { + min_z = cell_min_z; + _min_z_bound = cell_min_z_bound; } } /* If a z-min boundary was not found, get the z-min from the bounding boxes * of the cells */ - if (min_z == -std::numeric_limits::infinity()) + if (min_z == std::numeric_limits::infinity()) { for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) min_z = std::min(min_z, c_iter->second->getMinZ()); + } _min_z = min_z; /* Calculate the maximum reachable z-coordinate in the geometry and store it * in _max_z */ - double max_z = std::numeric_limits::infinity(); + double max_z = -std::numeric_limits::infinity(); + /* Calculate the boundary condition at the maximum + * reachable z-coordinate in the Universe and store it in _max_z_bound + */ + _max_z_bound = BOUNDARY_NONE; + /* Check if the universe contains a cell with an y-max boundary */ for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { std::mapsurfs = c_iter->second->getSurfaces(); + double cell_max_z = std::numeric_limits::infinity(); + boundaryType cell_max_z_bound = BOUNDARY_NONE; for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { surf = s_iter->second->_surface; halfspace = s_iter->second->_halfspace; - + if (surf->getSurfaceType() == ZPLANE && halfspace == -1 && - surf->getBoundaryType() != BOUNDARY_NONE) - max_z = surf->getMaxZ(halfspace); + surf->getBoundaryType() != BOUNDARY_NONE) { + if(surf->getMaxZ(halfspace) < cell_max_z) { + cell_max_z = surf->getMaxZ(halfspace); + cell_max_z_bound = surf->getBoundaryType(); + } + } + } + if(cell_max_z_bound != BOUNDARY_NONE && cell_max_z > max_z) { + max_z = cell_max_z; + _max_z_bound = cell_max_z_bound; } } - /* If a y-max boundary was not found, get the z-max from the bounding boxes + /* If a z-max boundary was not found, get the z-max from the bounding boxes * of the cells */ - if (max_z == std::numeric_limits::infinity()) + if (max_z == -std::numeric_limits::infinity()) { for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) max_z = std::max(max_z, c_iter->second->getMaxZ()); - - _max_z = max_z; - - /* Calculate the boundary condition at the minimum - * reachable x-coordinate in the Universe and store it in _min_x_bound - */ - boundaryType bc_x_min = BOUNDARY_NONE; - - /* Check if the universe contains a cell with an x-min boundary */ - for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { - std::mapsurfs = c_iter->second->getSurfaces(); - - for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = s_iter->second->_surface; - halfspace = s_iter->second->_halfspace; - - if (surf->getSurfaceType() == XPLANE && halfspace == +1 && - surf->getBoundaryType() != BOUNDARY_NONE && - surf->getMinX(halfspace) == _min_x) - bc_x_min = surf->getBoundaryType(); - } } - _min_x_bound = bc_x_min; - - /* Calculate the boundary condition at the maximum - * reachable x-coordinate in the Universe and store it in _max_x_bound - */ - boundaryType bc_x_max = BOUNDARY_NONE; - - /* Check if the universe contains a cell with an x-max boundary */ - for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { - std::mapsurfs = c_iter->second->getSurfaces(); - - for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = s_iter->second->_surface; - halfspace = s_iter->second->_halfspace; - - if (surf->getSurfaceType() == XPLANE && halfspace == -1 && - surf->getBoundaryType() != BOUNDARY_NONE && - surf->getMaxX(halfspace) == _max_x) - bc_x_max = surf->getBoundaryType(); - } - } - - _max_x_bound = bc_x_max; - - /* Calculate the boundary condition at the minimum - * reachable y-coordinate in the Universe and store it in _min_y_bound - */ - boundaryType bc_y_min = BOUNDARY_NONE; - - /* Check if the universe contains a cell with an y-min boundary */ - for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { - std::mapsurfs = c_iter->second->getSurfaces(); - - for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = s_iter->second->_surface; - halfspace = s_iter->second->_halfspace; - - if (surf->getSurfaceType() == YPLANE && halfspace == +1 && - surf->getBoundaryType() != BOUNDARY_NONE && - surf->getMinY(halfspace) == _min_y) - bc_y_min = surf->getBoundaryType(); - } - } - - _min_y_bound = bc_y_min; - - /* Calculate the boundary condition at the maximum - * reachable y-coordinate in the Universe and store it in _max_y_bound - */ - boundaryType bc_y_max = BOUNDARY_NONE; - - /* Check if the universe contains a cell with an y-max boundary */ - for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { - std::mapsurfs = c_iter->second->getSurfaces(); - - for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = s_iter->second->_surface; - halfspace = s_iter->second->_halfspace; - - if (surf->getSurfaceType() == YPLANE && halfspace == -1 && - surf->getBoundaryType() != BOUNDARY_NONE && - surf->getMaxY(halfspace) == _max_y) - bc_y_max = surf->getBoundaryType(); - } - } - - _max_y_bound = bc_y_max; - - /* Calculate the boundary condition at the minimum - * reachable z-coordinate in the Universe and store it in _min_z_bound - */ - boundaryType bc_z_min = BOUNDARY_NONE; - - /* Check if the universe contains a cell with an z-min boundary */ - for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { - std::mapsurfs = c_iter->second->getSurfaces(); - - for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = s_iter->second->_surface; - halfspace = s_iter->second->_halfspace; - - if (surf->getSurfaceType() == ZPLANE && halfspace == +1 && - surf->getBoundaryType() != BOUNDARY_NONE && - surf->getMinZ(halfspace) == _min_z) - bc_z_min = surf->getBoundaryType(); - } - } - - _min_z_bound = bc_z_min; - - /* Calculate the boundary condition at the maximum - * reachable z-coordinate in the Universe and store it in _max_z_bound - */ - boundaryType bc_z_max = BOUNDARY_NONE; - - /* Check if the universe contains a cell with an z-max boundary */ - for (c_iter = _cells.begin(); c_iter != _cells.end(); ++c_iter) { - std::mapsurfs = c_iter->second->getSurfaces(); - - for (s_iter = surfs.begin(); s_iter != surfs.end(); ++s_iter) { - surf = s_iter->second->_surface; - halfspace = s_iter->second->_halfspace; - - if (surf->getSurfaceType() == ZPLANE && halfspace == -1 && - surf->getBoundaryType() != BOUNDARY_NONE && - surf->getMaxZ(halfspace) == _max_z) - bc_z_max = surf->getBoundaryType(); - } - } - - _max_z_bound = bc_z_max; + _max_z = max_z; _boundaries_inspected = true; } diff --git a/tests/test_calculate_boundaries/results_true.dat b/tests/test_calculate_boundaries/results_true.dat new file mode 100644 index 000000000..43089f876 --- /dev/null +++ b/tests/test_calculate_boundaries/results_true.dat @@ -0,0 +1,30 @@ +[ NORMAL ] MinX: -50.000000 +[ NORMAL ] MinXBoundaryType: PERIODIC +[SEPARATOR] ******************************************************************* +[ NORMAL ] MinY: -50.000000 +[ NORMAL ] MinYBoundaryType: PERIODIC +[SEPARATOR] ******************************************************************* +[ NORMAL ] MinZ: -50.000000 +[ NORMAL ] MinZBoundaryType: PERIODIC +[SEPARATOR] ******************************************************************* +[ NORMAL ] MaxX: 50.000000 +[ NORMAL ] MaxXBoundaryType: PERIODIC +[SEPARATOR] ******************************************************************* +[ NORMAL ] MaxY: 50.000000 +[ NORMAL ] MaxYBoundaryType: PERIODIC +[SEPARATOR] ******************************************************************* +[ NORMAL ] MaxZ: 50.000000 +[ NORMAL ] MaxZBoundaryType: PERIODIC +[SEPARATOR] ******************************************************************* +[ NORMAL ] MinX: 10.000000 +[ NORMAL ] MinXBoundaryType: 0 +[ NORMAL ] MinY: 30.000000 +[ NORMAL ] MinYBoundaryType: 0 +[ NORMAL ] MinZ: 50.000000 +[ NORMAL ] MinZBoundaryType: 2 +[ NORMAL ] MaxX: 20.000000 +[ NORMAL ] MaxXBoundaryType: 1 +[ NORMAL ] MaxY: 40.000000 +[ NORMAL ] MaxYBoundaryType: 1 +[ NORMAL ] MaxZ: 60.000000 +[ NORMAL ] MaxZBoundaryType: 1 diff --git a/tests/test_calculate_boundaries/test_calculate_boundaries.py b/tests/test_calculate_boundaries/test_calculate_boundaries.py new file mode 100644 index 000000000..d0e11c4a9 --- /dev/null +++ b/tests/test_calculate_boundaries/test_calculate_boundaries.py @@ -0,0 +1,294 @@ +#!/usr/bin/env python + +import os +import sys +import glob +sys.path.insert(0, os.pardir) +sys.path.insert(0, os.path.join(os.pardir, 'openmoc')) +from testing_harness import TestHarness +import openmoc +from openmoc.log import py_printf + + +class CalculateBoundariesTestHarness(TestHarness): + """A unit test of OpenMOC's Universe::calculateBoundaries routine.""" + + def __init__(self): + super(CalculateBoundariesTestHarness, self).__init__() + + def _create_geometry(self): + pass + + def _create_trackgenerator(self): + pass + + def _generate_tracks(self): + pass + + def _creat_solver(self): + pass + + def _run_openmoc(self): + + openmoc.set_log_level('NORMAL') + + c1 = openmoc.Cell() + c2 = openmoc.Cell() + + s1 = openmoc.XPlane(-40.) + s2 = openmoc.XPlane(-50.) + s3 = openmoc.XPlane(-60.) + s1.setBoundaryType(openmoc.VACUUM) + s2.setBoundaryType(openmoc.PERIODIC) + s3.setBoundaryType(openmoc.REFLECTIVE) + + c1.addSurface(+1,s1) + c2.addSurface(+1,s2) + c2.addSurface(+1,s3) + + u = openmoc.Universe() + u.addCell(c1) + u.addCell(c2) + boundary = u.getMinXBoundaryType() + if boundary == 0: + boundary = 'VACUUM' + elif boundary == 1: + boundary = 'REFLECTIVE' + elif boundary == 2: + boundary = 'PERIODIC' + else: + boundary = 'BOUNDARY_NONE' + + py_printf('NORMAL', 'MinX: %f', u.getMinX()) + py_printf('NORMAL', 'MinXBoundaryType: %s', boundary) + py_printf('SEPARATOR','') + + c1 = openmoc.Cell() + c2 = openmoc.Cell() + + s1 = openmoc.YPlane(-40.) + s2 = openmoc.YPlane(-50.) + s3 = openmoc.YPlane(-60.) + s1.setBoundaryType(openmoc.VACUUM) + s2.setBoundaryType(openmoc.PERIODIC) + s3.setBoundaryType(openmoc.REFLECTIVE) + + c1.addSurface(+1,s1) + c2.addSurface(+1,s2) + c2.addSurface(+1,s3) + + u = openmoc.Universe() + u.addCell(c1) + u.addCell(c2) + boundary = u.getMinYBoundaryType() + if boundary == 0: + boundary = 'VACUUM' + elif boundary == 1: + boundary = 'REFLECTIVE' + elif boundary == 2: + boundary = 'PERIODIC' + else: + boundary = 'BOUNDARY_NONE' + + py_printf('NORMAL', 'MinY: %f', u.getMinY()) + py_printf('NORMAL', 'MinYBoundaryType: %s', boundary) + py_printf('SEPARATOR','') + + + c1 = openmoc.Cell() + c2 = openmoc.Cell() + + s1 = openmoc.ZPlane(-40.) + s2 = openmoc.ZPlane(-50.) + s3 = openmoc.ZPlane(-60.) + s1.setBoundaryType(openmoc.VACUUM) + s2.setBoundaryType(openmoc.PERIODIC) + s3.setBoundaryType(openmoc.REFLECTIVE) + + c1.addSurface(+1,s1) + c2.addSurface(+1,s2) + c2.addSurface(+1,s3) + + u = openmoc.Universe() + u.addCell(c1) + u.addCell(c2) + boundary = u.getMinZBoundaryType() + if boundary == 0: + boundary = 'VACUUM' + elif boundary == 1: + boundary = 'REFLECTIVE' + elif boundary == 2: + boundary = 'PERIODIC' + else: + boundary = 'BOUNDARY_NONE' + + py_printf('NORMAL', 'MinZ: %f', u.getMinZ()) + py_printf('NORMAL', 'MinZBoundaryType: %s', boundary) + py_printf('SEPARATOR','') + + + c1 = openmoc.Cell() + c2 = openmoc.Cell() + + s1 = openmoc.XPlane(40.) + s2 = openmoc.XPlane(50.) + s3 = openmoc.XPlane(60.) + s1.setBoundaryType(openmoc.VACUUM) + s2.setBoundaryType(openmoc.PERIODIC) + s3.setBoundaryType(openmoc.REFLECTIVE) + + c1.addSurface(-1,s1) + c2.addSurface(-1,s2) + c2.addSurface(-1,s3) + + u = openmoc.Universe() + u.addCell(c1) + u.addCell(c2) + boundary = u.getMaxXBoundaryType() + if boundary == 0: + boundary = 'VACUUM' + elif boundary == 1: + boundary = 'REFLECTIVE' + elif boundary == 2: + boundary = 'PERIODIC' + else: + boundary = 'BOUNDARY_NONE' + + py_printf('NORMAL', 'MaxX: %f', u.getMaxX()) + py_printf('NORMAL', 'MaxXBoundaryType: %s', boundary) + py_printf('SEPARATOR','') + + c1 = openmoc.Cell() + c2 = openmoc.Cell() + + s1 = openmoc.YPlane(40.) + s2 = openmoc.YPlane(50.) + s3 = openmoc.YPlane(60.) + s1.setBoundaryType(openmoc.VACUUM) + s2.setBoundaryType(openmoc.PERIODIC) + s3.setBoundaryType(openmoc.REFLECTIVE) + + c1.addSurface(-1,s1) + c2.addSurface(-1,s2) + c2.addSurface(-1,s3) + + u = openmoc.Universe() + u.addCell(c1) + u.addCell(c2) + boundary = u.getMaxYBoundaryType() + if boundary == 0: + boundary = 'VACUUM' + elif boundary == 1: + boundary = 'REFLECTIVE' + elif boundary == 2: + boundary = 'PERIODIC' + else: + boundary = 'BOUNDARY_NONE' + + py_printf('NORMAL', 'MaxY: %f', u.getMaxY()) + py_printf('NORMAL', 'MaxYBoundaryType: %s', boundary) + py_printf('SEPARATOR','') + + c1 = openmoc.Cell() + c2 = openmoc.Cell() + + s1 = openmoc.ZPlane(40.) + s2 = openmoc.ZPlane(50.) + s3 = openmoc.ZPlane(60.) + s1.setBoundaryType(openmoc.VACUUM) + s2.setBoundaryType(openmoc.PERIODIC) + s3.setBoundaryType(openmoc.REFLECTIVE) + + c1.addSurface(-1,s1) + c2.addSurface(-1,s2) + c2.addSurface(-1,s3) + + u = openmoc.Universe() + u.addCell(c1) + u.addCell(c2) + boundary = u.getMaxZBoundaryType() + if boundary == 0: + boundary = 'VACUUM' + elif boundary == 1: + boundary = 'REFLECTIVE' + elif boundary == 2: + boundary = 'PERIODIC' + else: + boundary = 'BOUNDARY_NONE' + + py_printf('NORMAL', 'MaxZ: %f', u.getMaxZ()) + py_printf('NORMAL', 'MaxZBoundaryType: %s', boundary) + py_printf('SEPARATOR','') + + sW = openmoc.XPlane(10) + sE = openmoc.XPlane(20) + sS = openmoc.YPlane(30) + sN = openmoc.YPlane(40) + sB = openmoc.ZPlane(50) + sT = openmoc.ZPlane(60) + sW.setBoundaryType(openmoc.VACUUM) + sE.setBoundaryType(openmoc.REFLECTIVE) + sS.setBoundaryType(openmoc.VACUUM) + sN.setBoundaryType(openmoc.REFLECTIVE) + sB.setBoundaryType(openmoc.PERIODIC) + sT.setBoundaryType(openmoc.REFLECTIVE) + + sX_mid = openmoc.XPlane(15) + sY_mid = openmoc.YPlane(35) + sZ_mid = openmoc.ZPlane(55) + sX_mid.setBoundaryType(openmoc.BOUNDARY_NONE) + sY_mid.setBoundaryType(openmoc.BOUNDARY_NONE) + sZ_mid.setBoundaryType(openmoc.BOUNDARY_NONE) + + cell = openmoc.Cell() + cell.addSurface(+1,sW) + cell.addSurface(-1,sE) + cell.addSurface(+1,sS) + cell.addSurface(-1,sN) + cell.addSurface(+1,sB) + cell.addSurface(-1,sT) + + cell.addSurface(+1,sX_mid) + cell.addSurface(-1,sX_mid) + cell.addSurface(+1,sY_mid) + cell.addSurface(-1,sY_mid) + cell.addSurface(+1,sZ_mid) + cell.addSurface(-1,sZ_mid) + + univ = openmoc.Universe() + univ.addCell(cell) + + py_printf('NORMAL', 'MinX: %f', univ.getMinX()) + py_printf('NORMAL', 'MinXBoundaryType: %s', univ.getMinXBoundaryType()) + py_printf('NORMAL', 'MinY: %f', univ.getMinY()) + py_printf('NORMAL', 'MinYBoundaryType: %s', univ.getMinYBoundaryType()) + py_printf('NORMAL', 'MinZ: %f', univ.getMinZ()) + py_printf('NORMAL', 'MinZBoundaryType: %s', univ.getMinZBoundaryType()) + py_printf('NORMAL', 'MaxX: %f', univ.getMaxX()) + py_printf('NORMAL', 'MaxXBoundaryType: %s', univ.getMaxXBoundaryType()) + py_printf('NORMAL', 'MaxY: %f', univ.getMaxY()) + py_printf('NORMAL', 'MaxYBoundaryType: %s', univ.getMaxYBoundaryType()) + py_printf('NORMAL', 'MaxZ: %f', univ.getMaxZ()) + py_printf('NORMAL', 'MaxZBoundaryType: %s', univ.getMaxZBoundaryType()) + + def _get_results(self, num_iters=False, keff=False, fluxes=False, + num_fsrs=False, num_tracks=False, num_segments=False, + hash_output=False): + """Digest info in the log file and return as a string.""" + + # Find the log filename with the time and date + logfilename = glob.glob('log/openmoc-*') + + # Read the file into a list of strings for each line + with open(logfilename[0], 'r') as myfile: + lines = myfile.readlines() + + # Concatenate all strings in the file into a single string + # Exclude the first line which is the time and date + outstr = ''.join(lines[1:]) + return outstr + + +if __name__ == '__main__': + harness = CalculateBoundariesTestHarness() + harness.main() diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 2a2e58141..a43eda340 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -49,6 +49,8 @@ def __init__(self): self.parser = OptionParser() self.parser.add_option('--update', dest='update', action='store_true', default=False) + # Add -f option to parser, as Jupyter forcedly provide this option + self.parser.add_option('-f', dest='jupyter', action='store',default=None) self._opts = None self._args = None @@ -191,7 +193,10 @@ def _overwrite_results(self): def _compare_results(self): """Make sure the current results agree with the _true standard.""" - compare = filecmp.cmp('results_test.dat', 'results_true.dat') + + # For comparison of files with different line endings + compare = (open('results_test.dat', 'r').read() == + open('results_true.dat', 'r').read()) if not compare: os.rename('results_test.dat', 'results_error.dat') assert compare, 'Results do not agree.'