35 const doublereal* step, Domain1D& r,
int loglevel=0);
37 const doublereal* step, Domain1D& r);
45 const string dashedline =
46 "-----------------------------------------------------------------";
49 const size_t NDAMP = 7;
58 MultiNewton::MultiNewton(
int sz)
65 MultiNewton::~MultiNewton()
67 for (
size_t i = 0; i < m_workarrays.size(); i++) {
68 delete[] m_workarrays[i];
78 for (
size_t i = 0; i < m_workarrays.size(); i++) {
79 delete[] m_workarrays[i];
89 const doublereal* step,
OneDim& r)
const
91 doublereal f, sum = 0.0;
93 for (
size_t n = 0; n < nd; n++) {
111 size_t sz = r.
size();
116 for (
size_t n = 0; n < sz; n++) {
121 for (
size_t n = 0; n < sz; n++) {
126 iok = jac.
solve(step, step);
133 for (n = nd-1; n !=
npos; n--)
134 if (iok >= r.
start(n)) {
138 size_t offset = iok - r.
start(n);
142 "Jacobian is singular for domain "+
143 dom.id() +
", component "
146 +
int2str(iok)+
") \nsee file bandmatrix.csv\n");
147 }
else if (
int(iok) < 0)
155 for (
size_t n = 0; n < sz; n++) {
158 int pt = (n - d->
loc())/nvd;
159 cout <<
"step: " << pt <<
" " <<
161 <<
" " << x[n] <<
" " << ssave[n] <<
" " << step[n] << endl;
174 const doublereal* step0,
const OneDim& r,
int loglevel)
176 doublereal fbound = 1.0;
177 for (
size_t i = 0; i < r.
nDomains(); i++) {
195 doublereal* x1, doublereal* step1, doublereal& s1,
200 if (loglevel > 0 && writetitle) {
201 writelog(
"\n\nDamped Newton iteration:\n");
204 sprintf(m_buf,
"\n%s %9s %9s %9s %9s %9s %5s %5s\n",
205 "m",
"F_damp",
"F_bound",
"log10(ss)",
206 "log10(s0)",
"log10(s1)",
"N_jac",
"Age");
212 doublereal s0 =
norm2(x0, step0, r);
215 doublereal fbound =
boundStep(x0, step0, r, loglevel-1);
221 if (fbound < 1.e-10) {
234 doublereal damp = 1.0;
239 for (m = 0; m <
NDAMP; m++) {
244 for (
size_t j = 0; j < m_n; j++) {
245 x1[j] = ff*step0[j] + x0[j];
250 step(x1, step1, r, jac, loglevel-1);
253 s1 =
norm2(x1, step1, r);
257 doublereal ss = r.
ssnorm(x1,step1);
258 sprintf(m_buf,
"\n%s %9.5f %9.5f %9.5f %9.5f %9.5f %4d %d/%d",
271 if (s1 < 1.0 || s1 < s0) {
301 clock_t t0 = clock();
303 bool forceNewJac =
false;
310 copy(x0, x0 + m_n, x);
313 doublereal rdt = r.
rdt();
320 if (jac.
age() > m_maxAge) {
329 jac.
eval(x, stp, 0.0);
330 jac.updateTransient(rdt,
DATA_PTR(r.transientMask()));
335 step(x, stp, r, jac, loglevel-1);
341 m =
dampStep(x, stp, x1, stp1, s1, r, jac, loglevel-1, frst);
342 if (loglevel == 1 && m >= 0) {
344 sprintf(m_buf,
"\n\n %10s %10s %5s ",
345 "log10(ss)",
"log10(s1)",
"N_jac");
347 sprintf(m_buf,
"\n ------------------------------------");
350 doublereal ss = r.
ssnorm(x, stp);
351 sprintf(m_buf,
"\n %10.4f %10.4f %d ",
352 log10(ss),log10(s1),jac.
nEvals());
360 copy(x1, x1 + m_n, x);
374 if (nJacReeval > 3) {
379 writelog(
"\nRe-evaluating Jacobian, since no damping "
380 "coefficient\ncould be found with this Jacobian.\n");
389 copy(x, x + m_n, x1);
391 if (m > 0 && jac.
nEvals() == j0) {
397 m_elapsed += (clock() - t0)/(1.0*CLOCKS_PER_SEC);
410 if (!m_workarrays.empty()) {
411 w = m_workarrays.back();
412 m_workarrays.pop_back();
414 w =
new doublereal[m_n];
425 m_workarrays.push_back(work);