Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a042bb8

Browse files
committed
Added possibility to continue simulation, this can be useful for issue #1
1 parent 7ecbc18 commit a042bb8

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/solver.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ void Solver::operator()(state_type &x)
4444
TimeIntegrator ti(m_rhs, m_jac, m_mass, m_opt, size);
4545

4646
// Initial time
47-
double t = 0.0;
47+
double t = (m_t_last > 0) ? m_t_last : 0.0;
48+
const double t0 = t;
4849

4950
// Time step
5051
double dt[2];
51-
dt[0] = m_opt.dt_init;
52+
dt[0] = (m_dt_last > 0) ? m_dt_last : m_opt.dt_init;
5253
dt[1] = dt[0];
5354

5455
// Initial output
55-
if(m_opt.verbosity > 0)
56+
if(m_opt.verbosity > 1)
5657
{
5758
std::cout << "Number of equations: " << size << std::endl;
5859
std::cout << "Float precision: " << 8 * sizeof(float_type)
@@ -144,7 +145,7 @@ void Solver::operator()(state_type &x)
144145
bool final_time_step = false;
145146
int step_counter = 0;
146147

147-
while(t < (m_t1 + dt[0] * 0.5))
148+
while(t < (t0 + m_t1 + dt[0] * 0.5))
148149
{
149150
step_counter++;
150151

@@ -417,14 +418,14 @@ void Solver::operator()(state_type &x)
417418
if(m_opt.verbosity > 0)
418419
std::cout << '>';
419420
}
420-
}
421+
} // SATS
421422

422423
// Looks like the solver has reached the target time t1
423-
if(t + dt[0] > m_t1)
424+
if(t - t0 + dt[0] > m_t1)
424425
{
425426
final_time_step = true;
426427
// Adjust the last time step size
427-
dt[0] = m_t1 - t;
428+
dt[0] = m_t1 - (t - t0);
428429
}
429430

430431
// Rewrite solution history
@@ -438,6 +439,9 @@ void Solver::operator()(state_type &x)
438439

439440
} // while t
440441

442+
m_t_last = t;
443+
m_dt_last = dt[1];
444+
441445
if(m_opt.verbosity > 0)
442446
std::cout << "\nLinear algebra solver calls: " << calls << '\n';
443447

src/solver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Solver
2626

2727
const double m_t1;
2828

29+
double m_dt_last = -1.0; // Stores the last time step size
30+
double m_t_last = -1.0; // Stores the final solution time
31+
2932
void check_pardiso_error(MKL_INT err);
3033

3134
public:

0 commit comments

Comments
 (0)