Skip to content

Commit

Permalink
Adapting compare.py to allow for non tipsy files
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Rey committed Oct 23, 2017
1 parent 48339c5 commit 7baec09
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
8 changes: 2 additions & 6 deletions genetIC/src/simulation/field/maskfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,15 @@ namespace fields {

// Loop over all cells and see if it is contained in the next level grid
// grid.containsPoint might be the useful method
// This loop should be easily pragma openmped

auto current_grid = this->multiLevelContext->getGridForLevel(level);
auto next_level_grid = this->multiLevelContext->getGridForLevel(level + 1);

#pragma omp parallel for
for (size_t i = 0; i < current_grid.size3; i++) {
Coordinate<int> cell_coord = current_grid.getCellCoordinate(i);

if (next_level_grid.containsCellWithCoordinate(cell_coord)) {
Coordinate<T> cell_coord(current_grid.getCellCentroid(i));
if (next_level_grid.containsPoint(cell_coord)) {
this->getFieldForLevel(level).getDataVector()[i] = 1;
} else {
this->getFieldForLevel(level).getDataVector()[i] = 0;
}
}

Expand Down
11 changes: 9 additions & 2 deletions genetIC/src/simulation/grid/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ namespace grids {
return false;
}

//! True if point in physical coordinates is on this grid
virtual bool containsPoint(const Coordinate<T> &coord) const {
return Window<T>(periodicDomainSize, offsetLower, offsetLower + thisGridSize).contains(coord);
}
Expand All @@ -183,11 +184,15 @@ namespace grids {
return pos;
}

//! True if cell with pixel coordinates is on this grid
/*! Does not take into account offset or physical coordinates
*/
virtual bool containsCellWithCoordinate(Coordinate<int> coord) const {
return coord.x >= 0 && coord.y >= 0 && coord.z >= 0 &&
(unsigned) coord.x < size && (unsigned) coord.y < size && (unsigned) coord.z < size;
}

//! True if cell number is less than Ncell cubed
virtual bool containsCell(size_t i) const {
return i < size3;
}
Expand Down Expand Up @@ -241,7 +246,7 @@ namespace grids {
return getCellIndexNoWrap(coordinate.x, coordinate.y, coordinate.z);
}


//! Returns cell id in pixel coordinates
Coordinate<int> getCellCoordinate(int id) const {
size_t x, y;

Expand All @@ -263,7 +268,9 @@ namespace grids {
return kMin;
}


//! Returns coordinate of centre of cell id, in physical box coordinates
/*! Takes into account grid offsets wrt base grid, pixel size etc
*/
Coordinate<T> getCellCentroid(size_t id) const {
Coordinate<int> coord = getCellCoordinate(id);
return getCellCentroid(coord);
Expand Down
7 changes: 4 additions & 3 deletions genetIC/tests/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def default_comparisons():
for ps, ps_test in zip(powspecs, powspecs_test):
compare_ps(ps,ps_test)

output_file = glob.glob(sys.argv[1]+"/*.tipsy")
assert len(output_file)==1, "Could not find a unique output file to test against"
compare(pynbody.load(output_file[0]),pynbody.load(sys.argv[1]+"/reference_output"))
if os.path.exists(sys.argv[1]+"/*.tipsy"):
output_file = glob.glob(sys.argv[1]+"/*.tipsy")
assert len(output_file)==1, "Could not find a unique output file to test against"
compare(pynbody.load(output_file[0]),pynbody.load(sys.argv[1]+"/reference_output"))

if __name__=="__main__":
warnings.simplefilter("ignore")
Expand Down
16 changes: 11 additions & 5 deletions genetIC/tests/test_08a_output_grafic/paramfile.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Test grafic output, especially if refinement masks are generated correctly
# Test is done on numpy arrays rather than tipsy files as usually done


# output parameters
Expand All @@ -14,26 +15,31 @@ s8 0.817
zin 99
camb ../camb_transfer_kmax40_z0_post2015.dat

# fourier seeding
seed 8896131

# basegrid 50 Mpc/h, 64^3
basegrid 50.0 64

centre 32.5 32.5 32.5
centre 49 25 25
select_nearest
zoomgrid 2 64

centre 32.5 32.5 32.5
centre 49 25 25
select_nearest
zoomgrid 2 64

# fourier seeding
seed 8896131
centre 49 25 25
select_nearest
zoomgrid 2 64

centre 49 25 25
select_sphere 2

done

dump_mask 0
dump_mask 1
dump_mask 2
dump_mask 3
dump_mask 4

0 comments on commit 7baec09

Please sign in to comment.