1 #ifdef OPENMC_MPI 2 #include <mpi.h> 3 #endif 4 5 #include "openmc/capi.h" 6 #include "openmc/cell.h" 7 #include "openmc/error.h" 8 #include "openmc/geometry.h" 9 #include "openmc/message_passing.h" 10 #include "openmc/summary.h" 11 #include "openmc/tallies/filter.h" 12 #include "openmc/tallies/filter_cell.h" 13 #include "openmc/tallies/tally.h" 14 15 using namespace openmc; 16 main(int argc,char ** argv)17int main(int argc, char** argv) { 18 #ifdef OPENMC_MPI 19 MPI_Comm world {MPI_COMM_WORLD}; 20 int err = openmc_init(argc, argv, &world); 21 #else 22 int err = openmc_init(argc, argv, nullptr); 23 #endif 24 if (err) fatal_error(openmc_err_msg); 25 26 // create a new cell filter 27 auto cell_filter = Filter::create<CellFilter>(); 28 29 // add all cells to the cell filter 30 std::vector<int32_t> cell_indices; 31 for (auto& entry : openmc::model::cell_map) { 32 cell_indices.push_back(entry.second); 33 } 34 // sort to make sure the cell bins appear in the same 35 // order as the test relying on the openmc exe 36 std::sort(cell_indices.begin(), cell_indices.end()); 37 cell_filter->set_cells(cell_indices); 38 39 // create a new tally 40 auto tally = Tally::create(); 41 std::vector<Filter*> filters = {cell_filter}; 42 tally->set_filters(filters); 43 tally->set_scores({"flux"}); 44 45 // set the temperature of the cell containing 46 // the lattice 47 auto& root_univ = openmc::model::universes[openmc::model::root_universe]; 48 auto& lattice_cell = openmc::model::cells[root_univ->cells_[0]]; 49 lattice_cell->set_temperature(300, 1, true); 50 51 // check that material-filled cells return no contained cells 52 for (auto& cell : openmc::model::cells) { 53 if (cell->type_ == Fill::MATERIAL) { 54 auto contained_cells = cell->get_contained_cells(); 55 assert(contained_cells.empty()); 56 } 57 } 58 59 // the summary file will be used to check that 60 // temperatures were set correctly so clear 61 // error output can be provided 62 #ifdef OPENMC_MPI 63 if (openmc::mpi::master) openmc::write_summary(); 64 #else 65 openmc::write_summary(); 66 #endif 67 68 openmc_run(); 69 openmc_finalize(); 70 71 #ifdef OPENMC_MPI 72 MPI_Finalize(); 73 #endif 74 75 return 0; 76 } 77