why does method sparse need converge?

Anything that doesn't fit elsewhere.
Post Reply
tianyizh
Posts: 2
Joined: Mon Mar 22, 2021 6:03 am

why does method sparse need converge?

Post by tianyizh »

When using method sparse to solve kinetic schame, I found that the code in scopemath/sparse.c solved the coefficient matrix several times to get converge when linflag=0. I am really confused with that. If you call the (*fun) which is the state function in the c file compiled from mod file N times, doesn't that mean you go through N*dt time?

Code: Select all

for (err=1, j=0; err > CONVERGE; j++) {
	init_coef_list();
	(*fun)();
	if((ierr = spar_matsol())) {
		return ierr;
	}
	for (err=0.,i=1; i<=n; i++) {
		s_(i-1) += rhs[i];
#if 1
if (!linflag && s_(i-1) < 0.) { s_(i-1) = 0.; }
#endif
		err += fabs(rhs[i]);
	}
	if (j > MAXSTEPS) {
		return EXCEED_ITERS;
	}
	if (linflag) break;
}
tianyizh
Posts: 2
Joined: Mon Mar 22, 2021 6:03 am

Re: why does method sparse need converge?

Post by tianyizh »

I guess I understand why sparse needs converge and the stop condition is |rhs| = 0 (L1 norm of rhs equals to zero).
Sparse method uses "backward eular" to solve equations to get new state at t+dt. What's more, instead of setting the nonlinear system like "AX = b"(both A and b are related to X, so it is nonlinear), sparse method sets the system like A_old(X_new - X_old) = b_new - b_old. So after running functions like matsol, rhs = (X_new - X_old) = 0 means we get the new steady state.
Am I right? I Hope so.
Post Reply