17 const std::string& file_base)
19 std::string file_name =
20 file_base + std::to_string(
Chi::mpi.location_id) +
".data";
23 std::ofstream file(file_name,
24 std::ofstream::binary |
26 std::ofstream::trunc);
29 if (not file.is_open())
32 << __FUNCTION__ <<
"Failed to open " << file_name;
37 std::string header_info =
38 "Chi-Tech LinearBoltzmann::Groupset angular flux file\n"
39 "Header size: 320 bytes\n"
40 "Structure(type-info):\n"
41 "size_t-num_local_nodes\n"
44 "size_t-num_records\n"
46 "size_t-cell_global_id\n"
47 "unsigned int-node_number\n"
48 "unsigned int-angle_num_\n"
49 "unsigned int-group_num\n"
50 "double-angular_flux\n";
52 int header_size = (int)header_info.length();
54 char header_bytes[320];
55 memset(header_bytes,
'-', 320);
56 strncpy(header_bytes, header_info.c_str(),std::min(header_size,319));
57 header_bytes[319]=
'\0';
65 size_t num_angles = groupset.
quadrature_->abscissae_.size();
66 size_t num_groups = groupset.
groups_.size();
71 file.write((
char*)&num_local_nodes,
sizeof(
size_t));
72 file.write((
char*)&num_angles ,
sizeof(
size_t));
73 file.write((
char*)&num_groups ,
sizeof(
size_t));
74 file.write((
char*)&num_local_dofs ,
sizeof(
size_t));
80 for (
const auto& cell :
grid_ptr_->local_cells)
82 const size_t num_nodes = sdm->GetCellNumNodes(cell);
83 for (
unsigned int i=0; i < num_nodes; ++i)
84 for (
unsigned int n=0; n<num_angles; ++n)
85 for (
unsigned int g=0; g<num_groups; ++g)
87 if (++dof_count > num_local_dofs)
goto close_file;
89 uint64_t dof_map = sdm->MapDOFLocal(cell,i,dof_handler,n,g);
92 file.write((
char*)&cell.global_id_,
sizeof(
size_t));
93 file.write((
char*)&i ,
sizeof(
unsigned int));
94 file.write((
char*)&n ,
sizeof(
unsigned int));
95 file.write((
char*)&g ,
sizeof(
unsigned int));
96 file.write((
char*)&value ,
sizeof(
double));
109 const std::string& file_base)
111 std::string file_name =
112 file_base + std::to_string(
Chi::mpi.location_id) +
".data";
115 std::ifstream file(file_name,
116 std::ofstream::binary |
120 if (not file.is_open())
123 << __FUNCTION__ <<
"Failed to open " << file_name;
130 size_t num_local_nodes = discretization_->GetNumLocalDOFs(NODES_ONLY);
131 size_t num_angles = groupset.
quadrature_->abscissae_.size();
132 size_t num_groups = groupset.
groups_.size();
133 size_t num_local_dofs = psi_new_local_[groupset.
id_].size();
134 std::vector<double>& psi = psi_new_local_[groupset.
id_];
137 size_t file_num_local_nodes;
138 size_t file_num_angles ;
139 size_t file_num_groups ;
140 size_t file_num_local_dofs ;
144 Chi::log.
Log() <<
"Reading angular flux file " << file_name;
145 char header_bytes[320]; header_bytes[319] =
'\0';
146 file.read(header_bytes,319);
148 file.read((
char*)&file_num_local_nodes,
sizeof(
size_t));
149 file.read((
char*)&file_num_angles ,
sizeof(
size_t));
150 file.read((
char*)&file_num_groups ,
sizeof(
size_t));
151 file.read((
char*)&file_num_local_dofs ,
sizeof(
size_t));
154 if (file_num_local_nodes != num_local_nodes or
155 file_num_angles != num_angles or
156 file_num_groups != num_groups or
157 file_num_local_dofs != num_local_dofs)
159 std::stringstream outstr;
160 outstr <<
"num_local_nodes: " << file_num_local_nodes <<
"\n";
161 outstr <<
"num_angles : " << file_num_angles <<
"\n";
162 outstr <<
"num_groups : " << file_num_groups <<
"\n";
163 outstr <<
"num_local_dofs : " << file_num_local_dofs <<
"\n";
165 <<
"Incompatible DOF data found in file " << file_name <<
"\n"
171 auto& sdm = discretization_;
174 psi.reserve(file_num_local_dofs);
175 std::set<uint64_t> cells_touched;
176 for (
size_t dof=0; dof < file_num_local_dofs; ++dof)
178 uint64_t cell_global_id;
180 unsigned int angle_num;
184 file.read((
char*)&cell_global_id,
sizeof(uint64_t));
185 file.read((
char*)&node ,
sizeof(
unsigned int));
186 file.read((
char*)&angle_num ,
sizeof(
unsigned int));
187 file.read((
char*)&group ,
sizeof(
unsigned int));
188 file.read((
char*)&psi_value ,
sizeof(
double));
190 cells_touched.insert(cell_global_id);
192 const auto& cell = grid_ptr_->cells[cell_global_id];
194 size_t imap = sdm->MapDOFLocal(cell,node,dof_handler,angle_num,group);
196 psi[imap] = psi_value;
199 Chi::log.
LogAll() <<
"Number of cells read: " << cells_touched.size();
static chi::MPI_Info & mpi
LogStream Log(LOG_LVL level=LOG_0)
LogStream LogAllWarning()
static UnknownManager GetUnitaryUnknownManager()
std::shared_ptr< chi_math::AngularQuadrature > quadrature_
chi_math::UnknownManager psi_uk_man_
std::vector< LBSGroup > groups_
std::vector< std::vector< double > > psi_new_local_
chi_mesh::MeshContinuumPtr grid_ptr_
std::shared_ptr< chi_math::SpatialDiscretization > discretization_
void ReadGroupsetAngularFluxes(LBSGroupset &groupset, const std::string &file_base)
void WriteGroupsetAngularFluxes(const LBSGroupset &groupset, const std::string &file_base)