function mass_balance = check_mass_balance(t, initial_fluid_mass, rho, is_fluid) %%%% This function checks to see if the total fluid mass in a lattice %%%% Boltzmann simulation is within 10% of the initial fluid mass. If %%%% the code is running properly, then the fluid mass should not change %%%% over time. Sometimes, depending on the boundary conditions %%%% employed, there might be slight changes in the fluid mass %%%% (compressibility effects). If the fluid mass is within 10% of its %%%% initial value, then a value of TRUE is returned for the boolean %%%% variable mass_balance. If the fluid mass is not within 10% of its %%%% initial value, then a value of FALSE is returned. mass_balance = true; total_fluid_mass = sum(sum( is_fluid .* rho )); display([t total_fluid_mass]); if ((total_fluid_mass > 1.1*initial_fluid_mass) || (total_fluid_mass < 0.9*initial_fluid_mass)) mass_balance = false; end end