45 using namespace Input::Type;
48 =
Record(
"MassBalance",
"Balance of mass, boundary fluxes and sources for transport of substances.")
50 "If true, then balance is calculated at each computational time step, which can slow down the program.")
57 : equation_(eq), initial_time(0), last_time(-1), initial(true)
99 for (
int i=0; i<n_subst; i++)
101 for (
int j=0; j<n_bcd_reg_; j++)
107 for (
int j=0; j<n_blk_reg_; j++)
125 int buf_size = n_subst*(3*n_bcd_reg_ + 2*n_blk_reg_);
126 double sendbuffer[buf_size], recvbuffer[buf_size];
127 for (
int i=0; i<n_subst; i++)
129 for (
int j=0; j<n_bcd_reg_; j++)
135 for (
int j=0; j<n_blk_reg_; j++)
137 sendbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_ +j] =
mass[i][j];
138 sendbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_+n_blk_reg_+j] =
src_balance[i][j];
157 for (
int i=0; i<n_subst; i++)
159 for (
int j=0; j<n_bcd_reg_; j++)
165 for (
int j=0; j<n_blk_reg_; j++)
167 mass[i][j] = recvbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_ +j];
168 src_balance[i][j] = recvbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_+n_blk_reg_+j];
175 for( RegionSet::const_iterator reg = b_set.begin(); reg != b_set.end(); ++reg) {
177 for (
int sbi=0; sbi<n_subst; sbi++) {
186 for( RegionSet::const_iterator reg = bulk_set.begin(); reg != bulk_set.end(); ++reg)
188 for (
int sbi=0; sbi<n_subst; sbi++)
201 last_fluxes(n_subst, 0.);
208 for (
int i=0; i<n_subst; i++)
228 for (
int i=0; i<n_subst; i++)
235 for (
int i=0; i<n_subst; i++)
246 for (
int i=0; i<n_subst; i++)
263 if (rank != 0)
return;
270 unsigned int wl = 2*(w-5)+7;
272 string bc_head_format =
"# %-*s%-*s%-*s%-*s%-*s%-*s\n",
273 bc_format =
"%*s%-*d%-*s%-*s%-*g%-*g%-*g\n",
274 bc_total_format =
"# %-*s%-*s%-*g%-*g%-*g\n";
275 s << setw((w*c+wl-14)/2) << setfill(
'-') <<
"--";
282 w,
"[substance]",w,
"[total flux]",w,
"[outward flux]",w,
"[inward flux]");
284 s.str(std::string());
285 s << setw(w*c+wl) << setfill(
'-') <<
"-";
290 for( RegionSet::const_iterator reg = b_set.begin(); reg != b_set.end(); ++reg) {
291 for (
int sbi=0; sbi<n_subst; sbi++) {
300 for (
int sbi=0; sbi<n_subst; sbi++)
301 fprintf(
balance_output_file, bc_total_format.c_str(),w+wl,
"Total mass flux of substance [M/T]",
307 string src_head_format =
"# %-*s%-*s%-*s%-*s%-*s\n",
308 src_format =
"%*s%-*d%-*s%-*s%-*g%-*g\n",
309 src_total_format =
"# %-*s%-*s%-*g%-*g\n";
312 w,
"[substance]",w,
"[total_mass]",w,
"[total_source]");
317 for( RegionSet::const_iterator reg = bulk_set.begin(); reg != bulk_set.end(); ++reg)
319 for (
int sbi=0; sbi<n_subst; sbi++)
323 w,
mass[sbi][reg->bulk_idx()],
329 for (
int sbi=0; sbi<n_subst; sbi++)
330 fprintf(
balance_output_file, src_total_format.c_str(),w+wl,
"Total mass [M] and sources [M/T]",
339 "# Initial mass [M] + sources integrated over time [M] - flux integrated over time [M] = current mass [M]\n"
340 "# %-*s%-*s%-*s%-*s%-*s%-*s%-*s%-*s\n",
351 for (
int i=0; i<n_subst; i++)
359 w,initial_mass[i]+integrated_sources[i]-integrated_fluxes[i],
361 w,initial_mass[i]+integrated_sources[i]-integrated_fluxes[i]-mass_total[i],
362 w,fabs(initial_mass[i]+integrated_sources[i]-integrated_fluxes[i]-mass_total[i])/(denominator==0?1:denominator));