BUDEES/src/Simulateur/solver/Timestep.h

45 lines
1.9 KiB
C++

// This file is part of BUDEES, a software that allows fast simulation of bubble dynamics in electrolyzers and their interactions with electrical parameters.
//
// Copyright (C) 2024 <CNRS-ENS Rennes-Université de Rennes-CY Cergy Paris Université-Université Paris Saclay-CNAM Paris-ENS Paris-Saclay>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/
TimeSteps updateTimestep(TimeSteps& timesteps, double maxRadius, double maxVelocity, vector<Site>& Sites, bool* stopFlag) {
// Nucleation growing rate
double growingFactorMax = 0;
for (vector<Site>::iterator it = Sites.begin(); it != Sites.end(); it++)
growingFactorMax = MAX(growingFactorMax, it->growth);
double TgrowthMin = RFritzMin/growingFactorMax;
double dtMaximal1 = TgrowthMin/GROWING_TIME_COEF;
// Equilibrium buoyancy velocity
double UElec = abs(bPrefactor*mathSQ(maxRadius));
double dtElec = 2*maxRadius/(ELECTRICAL_TIME_COEF*UElec);
// Check Reynolds
double U = abs(bPrefactor*mathSQ(maxRadius));
double dtMaximal2 = 2*maxRadius/(BUOYANCY_TIME_COEF*U);
double reynolds = (rho/mu)*maxVelocity*maxRadius;
if (reynolds > 10) {
errorProgress("reynolds number too high (Re=" + std::to_string(reynolds) + ")");
*stopFlag = true;
}
// Return the smallest value
double dt = MIN(dtMaximal1, dtMaximal2);
return {dt, dtElec, timesteps.i, timesteps.iElec};
}