Skip to content

Commit

Permalink
FEBioModel now also tracks stats per step.
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMaas1978 committed Sep 24, 2024
1 parent 1ba2f26 commit 0d56b45
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
57 changes: 39 additions & 18 deletions FEBioLib/FEBioModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ FEBioModel::FEBioModel()
m_writeMesh = false;
m_createReport = false;

m_stats.ntimeSteps = 0;
m_stats.ntotalIters = 0;
m_stats.ntotalRHS = 0;
m_stats.ntotalReforms = 0;

m_pltAppendOnRestart = true;

m_lastUpdate = -1;
Expand Down Expand Up @@ -190,7 +185,18 @@ void FEBioModel::SetLogLevel(int logLevel) { m_logLevel = logLevel; }
//! Get the stats
ModelStats FEBioModel::GetModelStats() const
{
return m_stats;
return m_modelStats;
}

ModelStats FEBioModel::GetStepStats(size_t n) const
{
assert((n >= 0) && (n < Steps()));
return m_stepStats[n];
}

std::vector<ModelStats> FEBioModel::GetStepStats() const
{
return m_stepStats;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1541,6 +1547,7 @@ bool FEBioModel::Init()
}

m_report.clear();
m_stepStats.resize(Steps());

FEBioPlotFile* pplt = nullptr;
m_lastUpdate = -1;
Expand Down Expand Up @@ -1682,10 +1689,18 @@ bool FEBioModel::Reset()
}
}

m_stats.ntimeSteps = 0;
m_stats.ntotalIters = 0;
m_stats.ntotalRHS = 0;
m_stats.ntotalReforms = 0;
// reset stats
m_modelStats.ntimeSteps = 0;
m_modelStats.ntotalIters = 0;
m_modelStats.ntotalRHS = 0;
m_modelStats.ntotalReforms = 0;
for (auto& s : m_stepStats)
{
s.ntimeSteps = 0;
s.ntotalIters = 0;
s.ntotalRHS = 0;
s.ntotalReforms = 0;
}

// do the callback
DoCallback(CB_INIT);
Expand Down Expand Up @@ -1735,10 +1750,10 @@ void FEBioModel::on_cb_solved()
if (Steps() > 1)
{
feLog("\n\n N O N L I N E A R I T E R A T I O N S U M M A R Y\n\n");
feLog("\tNumber of time steps completed .................... : %d\n\n", m_stats.ntimeSteps);
feLog("\tTotal number of equilibrium iterations ............ : %d\n\n", m_stats.ntotalIters);
feLog("\tTotal number of right hand evaluations ............ : %d\n\n", m_stats.ntotalRHS);
feLog("\tTotal number of stiffness reformations ............ : %d\n\n", m_stats.ntotalReforms);
feLog("\tNumber of time steps completed .................... : %d\n\n", m_modelStats.ntimeSteps);
feLog("\tTotal number of equilibrium iterations ............ : %d\n\n", m_modelStats.ntotalIters);
feLog("\tTotal number of right hand evaluations ............ : %d\n\n", m_modelStats.ntotalRHS);
feLog("\tTotal number of stiffness reformations ............ : %d\n\n", m_modelStats.ntotalReforms);
}

// get timing info
Expand Down Expand Up @@ -1841,10 +1856,16 @@ void FEBioModel::on_cb_stepSolved()
}

// add to stats
m_stats.ntimeSteps += step->m_ntimesteps;
m_stats.ntotalIters += step->m_ntotiter;
m_stats.ntotalRHS += step->m_ntotrhs;
m_stats.ntotalReforms += step->m_ntotref;
ModelStats stats;
stats.ntimeSteps = step->m_ntimesteps;
stats.ntotalIters = step->m_ntotiter;
stats.ntotalRHS = step->m_ntotrhs;
stats.ntotalReforms = step->m_ntotref;
m_stepStats[GetCurrentStepIndex()] = stats;
m_modelStats.ntimeSteps += stats.ntimeSteps;
m_modelStats.ntotalIters += stats.ntotalIters;
m_modelStats.ntotalRHS += stats.ntotalRHS;
m_modelStats.ntotalReforms += stats.ntotalReforms;
}

bool FEBioModel::Restart(const char* szfile)
Expand Down
5 changes: 4 additions & 1 deletion FEBioLib/FEBioModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class FEBIOLIB_API FEBioModel : public FEMechModel

//! Get the stats
ModelStats GetModelStats() const;
ModelStats GetStepStats(size_t n) const;
std::vector<ModelStats> GetStepStats() const;

// flag to show warnings and errors
void ShowWarningsAndErrors(bool b);
Expand Down Expand Up @@ -224,7 +226,8 @@ class FEBIOLIB_API FEBioModel : public FEMechModel

private:
// accumulative statistics
ModelStats m_stats;
ModelStats m_modelStats;
std::vector<ModelStats> m_stepStats;

protected: // file names
std::string m_sfile_title; //!< input file title
Expand Down
8 changes: 4 additions & 4 deletions FEBioLib/febiolib_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ SOFTWARE.*/
#pragma once

struct ModelStats {
int ntimeSteps; //!< total nr of time steps
int ntotalIters; //!< total nr of equilibrium iterations
int ntotalRHS; //!< total nr of right hand side evaluations
int ntotalReforms; //!< total nr of stiffness reformations
int ntimeSteps = 0; //!< total nr of time steps
int ntotalIters = 0; //!< total nr of equilibrium iterations
int ntotalRHS = 0; //!< total nr of right hand side evaluations
int ntotalReforms = 0; //!< total nr of stiffness reformations
};

struct TimingInfo {
Expand Down
2 changes: 1 addition & 1 deletion FECore/FEModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void FEModel::AddInitialCondition(FEInitialCondition* pbc) { m_imp->m_IC.push_ba

//-----------------------------------------------------------------------------
//! retrieve the number of steps
int FEModel::Steps() { return (int)m_imp->m_Step.size(); }
int FEModel::Steps() const { return (int)m_imp->m_Step.size(); }

//-----------------------------------------------------------------------------
//! clear the steps
Expand Down
2 changes: 1 addition & 1 deletion FECore/FEModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class FECORE_API FEModel : public FECoreBase, public CallbackHandler
public: // --- Analysis steps functions ---

//! retrieve the number of steps
int Steps();
int Steps() const;

//! clear the steps
void ClearSteps();
Expand Down

0 comments on commit 0d56b45

Please sign in to comment.