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)
97 for (
int i=0; i<n_subst; i++)
99 for (
int j=0; j<n_bcd_reg_; j++)
105 for (
int j=0; j<n_blk_reg_; j++)
123 int buf_size = n_subst*(3*n_bcd_reg_ + 2*n_blk_reg_);
124 double sendbuffer[buf_size], recvbuffer[buf_size];
125 for (
int i=0; i<n_subst; i++)
127 for (
int j=0; j<n_bcd_reg_; j++)
133 for (
int j=0; j<n_blk_reg_; j++)
135 sendbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_ +j] =
mass[i][j];
136 sendbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_+n_blk_reg_+j] =
src_balance[i][j];
155 for (
int i=0; i<n_subst; i++)
157 for (
int j=0; j<n_bcd_reg_; j++)
163 for (
int j=0; j<n_blk_reg_; j++)
165 mass[i][j] = recvbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_ +j];
166 src_balance[i][j] = recvbuffer[n_subst*3*n_bcd_reg_+i*2*n_blk_reg_+n_blk_reg_+j];
173 for( RegionSet::const_iterator reg = b_set.begin(); reg != b_set.end(); ++reg) {
174 for (
int sbi=0; sbi<n_subst; sbi++) {
183 for( RegionSet::const_iterator reg = bulk_set.begin(); reg != bulk_set.end(); ++reg)
185 for (
int sbi=0; sbi<n_subst; sbi++)
198 last_fluxes(n_subst, 0.);
205 for (
int i=0; i<n_subst; i++)
225 for (
int i=0; i<n_subst; i++)
232 for (
int i=0; i<n_subst; i++)
243 for (
int i=0; i<n_subst; i++)
260 if (rank != 0)
return;
267 unsigned int wl = 2*(w-5)+7;
269 string bc_head_format =
"# %-*s%-*s%-*s%-*s%-*s%-*s\n",
270 bc_format =
"%*s%-*d%-*s%-*s%-*g%-*g%-*g\n",
271 bc_total_format =
"# %-*s%-*s%-*g%-*g%-*g\n";
272 s << setw((w*c+wl-14)/2) << setfill(
'-') <<
"--";
279 w,
"[substance]",w,
"[total flux]",w,
"[outward flux]",w,
"[inward flux]");
281 s.str(std::string());
282 s << setw(w*c+wl) << setfill(
'-') <<
"-";
287 for( RegionSet::const_iterator reg = b_set.begin(); reg != b_set.end(); ++reg) {
288 for (
int sbi=0; sbi<n_subst; sbi++) {
297 for (
int sbi=0; sbi<n_subst; sbi++)
298 fprintf(
balance_output_file, bc_total_format.c_str(),w+wl,
"Total mass flux of substance [M/T]",
304 string src_head_format =
"# %-*s%-*s%-*s%-*s%-*s\n",
305 src_format =
"%*s%-*d%-*s%-*s%-*g%-*g\n",
306 src_total_format =
"# %-*s%-*s%-*g%-*g\n";
309 w,
"[substance]",w,
"[total_mass]",w,
"[total_source]");
314 for( RegionSet::const_iterator reg = bulk_set.begin(); reg != bulk_set.end(); ++reg)
316 for (
int sbi=0; sbi<n_subst; sbi++)
320 w,
mass[sbi][reg->bulk_idx()],
326 for (
int sbi=0; sbi<n_subst; sbi++)
327 fprintf(
balance_output_file, src_total_format.c_str(),w+wl,
"Total mass [M] and sources [M/T]",
336 "# Initial mass [M] + sources integrated over time [M] - flux integrated over time [M] = current mass [M]\n"
337 "# %-*s%-*s%-*s%-*s%-*s%-*s%-*s%-*s\n",
348 for (
int i=0; i<n_subst; i++)
356 w,initial_mass[i]+integrated_sources[i]-integrated_fluxes[i],
358 w,initial_mass[i]+integrated_sources[i]-integrated_fluxes[i]-mass_total[i],
359 w,fabs(initial_mass[i]+integrated_sources[i]-integrated_fluxes[i]-mass_total[i])/(denominator==0?1:denominator));
void calculate(double time)
vector< double > src_total_balance
static Input::Type::Record input_type
unsigned int bulk_size() const
int xfclose(FILE *stream)
FCLOSE WITH ERROR HANDLING.
RegionSet get_region_set(const string &set_name) const
vector< double > bcd_total_inflow
double initial_time
initial time
double last_time
time of last calculated balance
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
#define MPI_Reduce(sendbuf, recvbuf, count, datatype, op, root, comm)
vector< vector< double > > bcd_plus_balance
FILE * balance_output_file
Handle for output file for output of balance and total fluxes over individual regions and region sets...
EquationForMassBalance * equation_
Pointer to the class which implements calculation of mass, sources and fluxes.
bool cumulative
if true then cumulative balance is computed
MassBalance(EquationForMassBalance *eq, const Input::Record &in_rec)
vector< double > initial_mass
vector< double > integrated_sources
vector< vector< double > > bcd_balance
void output(double time)
Write computed fields to file.
vector< vector< double > > bcd_minus_balance
Dedicated class for storing path to input and output files.
vector< vector< double > > src_balance
vector< double > bcd_total_balance
unsigned int boundary_size() const
bool initial
true before calculating the mass at initial time, otherwise false
vector< double > bcd_total_outflow
vector< double > mass_total
vector< vector< double > > mass
vector< double > integrated_fluxes
FILE * xfopen(const std::string &fname, const char *mode)