Commit 1562b40b authored by Kirill Terekhov's avatar Kirill Terekhov

functions for update constraint and time step adjustment in models

parent 760ca043
......@@ -188,15 +188,15 @@ namespace INMOST
return success;
}
bool Model::UpdateSolution(const Sparse::Vector & sol)
bool Model::UpdateSolution(const Sparse::Vector & sol, double alpha)
{
bool success = true;
for(std::vector< std::pair<std::string, AbstractSubModel *> >::const_iterator it = SubModels.begin();
it != SubModels.end(); ++it)
success &= it->second->UpdateSolution(sol);
success &= it->second->UpdateSolution(sol,alpha);
for(std::vector< std::pair<std::string, AbstractOperator *> >::const_iterator it = Operators.begin();
it != Operators.end(); ++it)
success &= it->second->UpdateSolution(sol);
success &= it->second->UpdateSolution(sol,alpha);
return success;
}
......@@ -230,4 +230,30 @@ namespace INMOST
success &= it->second->RestoreTimeStep();
return success;
}
double Model::UpdateMultiplier(const Sparse::Vector & sol) const
{
double alpha = 1;
for(std::vector< std::pair<std::string, AbstractSubModel *> >::const_iterator it = SubModels.begin();
it != SubModels.end(); ++it)
alpha = std::min(alpha,it->second->UpdateMultiplier(sol));
#if defined(USE_MPI)
double tmp = alpha;
MPI_Allreduce(&tmp,&alpha,1,MPI_DOUBLE,MPI_MIN,MPI_COMM_WORLD);
#endif
return alpha;
}
double Model::AdjustTimeStep(double dt) const
{
double ret = dt;
for(std::vector< std::pair<std::string, AbstractSubModel *> >::const_iterator it = SubModels.begin();
it != SubModels.end(); ++it)
ret = std::min(ret,it->second->AdjustTimeStep(dt));
#if defined(USE_MPI)
double tmp = ret;
MPI_Allreduce(&tmp,&ret,1,MPI_DOUBLE,MPI_MIN,MPI_COMM_WORLD);
#endif
return ret;
}
}
......@@ -27,13 +27,17 @@ namespace INMOST
/// Fill part of the residual related to my unknowns.
virtual bool FillResidual(Residual & R) const = 0;
/// Update solution.
virtual bool UpdateSolution(const Sparse::Vector & sol) = 0;
virtual bool UpdateSolution(const Sparse::Vector & sol, double alpha) = 0;
/// Update time step.
virtual bool UpdateTimeStep() = 0;
/// Provide time step.
virtual bool SetTimeStep(double dt) = 0;
/// Roll back to previous step.
virtual bool RestoreTimeStep() = 0;
/// Calculate multiplier for update for this model. Can simply return 1.
virtual double UpdateMultiplier(const Sparse::Vector & sol) const {return 1;}
/// Calculate time step for this model. Can simply return dt.
virtual double AdjustTimeStep(double dt) const {return dt;}
};
/// A class to organize a model.
......@@ -107,7 +111,9 @@ namespace INMOST
/// Compute the residual of the model.
bool FillResidual(Residual & R) const;
/// Update solution.
bool UpdateSolution(const Sparse::Vector & sol);
/// alpha is the parameter that scales the update solution.
/// Usually calculated with UpdateMultiplier.
bool UpdateSolution(const Sparse::Vector & sol, double alpha);
/// Move to the next time step
bool UpdateTimeStep();
/// Provide new time step.
......@@ -119,6 +125,10 @@ namespace INMOST
/// Update variables contained in all block of automatizator on ghost elements of the grid.
/// For synchronization of data in individual blocks see AbstractEntry::SynhronizeData.
void SynchronizeData() { aut.SynchronizeData(); }
/// Calculate multiplier for update.
double UpdateMultiplier(const Sparse::Vector & sol) const;
/// Calculate optimal time step for submodels.
double AdjustTimeStep(double dt) const;
};
}
......
......@@ -37,7 +37,7 @@ namespace INMOST
virtual bool Prepare() = 0;
/// This allows operator to update introduced variables.
/// May be useful for mimetic finite differences operators.
virtual bool UpdateSolution(const Sparse::Vector & V) = 0;
virtual bool UpdateSolution(const Sparse::Vector & V, double alpha) = 0;
/// This allows operator to update time-dependent variables.
virtual bool UpdateTimeStep() = 0;
/// Check, whether we need to compute operator on this element.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment