@@ -91,8 +91,10 @@ const NOX::LAPACK::Vector& NoxLapackInterface::getInitialGuess()
9191
9292 if (_generateoutput) {
9393 std::cout << " Initial guess is given by " << std::endl;
94- for (int i=0 ;i<_dimSys;i++) std::cout << (*_initialGuess)(i) << " " ;
95- std::cout << std::endl;
94+ // for(int i=0;i<_dimSys;i++) std::cout << (*_initialGuess)(i) << " ";
95+ // std::cout << std::endl;
96+ // std::cout << "or" << std::endl;
97+ _initialGuess->print (std::cout);
9698 }
9799
98100 if (_useFunctionValueScaling){
@@ -132,24 +134,40 @@ bool NoxLapackInterface::computeActualF(NOX::LAPACK::Vector& f, const NOX::LAPAC
132134 }
133135 std::cout << " )" << std::endl;
134136 std::cout << " The position seen by NOX is given by x=(" ;
135- for (int i=0 ;i<_dimSys;i++){
136- std::cout << std::setprecision (std::numeric_limits<double >::digits10 + 8 ) << x (i) << " " ;
137- }
138- std::cout << " )" << std::endl;
137+ // for (int i=0;i<_dimSys;i++){
138+ // std::cout << std::setprecision (std::numeric_limits<double>::digits10 + 8) << x(i) << " ";
139+ // }
140+ // std::cout << ")" << std::endl;
141+ // std::cout << "or" << std::endl;
142+ x.print (std::cout);
139143 }
140144
141145 _algLoop->setReal (_xtemp);
142- // _algLoop->getRHS(_rhs);
146+ _algLoop->getRHS (_rhs);
143147 try {
144148 _algLoop->evaluate ();
145149 _algLoop->getRHS (_rhs);
146150 }catch (const std::exception &ex)
147151 {
148152 if (_generateoutput) std::cout << " calculating right hand side failed with error message:" << std::endl << ex.what () << std::endl;
149153 // the following should be done when some to be implemented flag like "continue if function evaluation fails" is activated.
154+
155+
156+ // even newer, experimental version. Delete comments, when this is tested.
157+ // for(int i=0;i<_dimSys;i++){
158+ // _rhs[i]=_fScale[i]*(std::abs(x(i)-(getInitialGuess())(i))+1)*((_rhs[i]<0.0) ? -1.0e6 : 1.0e6);
159+ // this has conical form.
160+ // it is based on the assumption that getInitialGuess is contained in the domain.
161+ // We have two goals: One is to ensure, that the rhs is at least 1.0e6.
162+ // The other is to make sure, that if there is an open ball around the area where we cannot evaluate, that the next newton iterate is the initial guess.
163+ // That is actually not good, the initial guess is where we started...
164+ // _rhs[i]=_fScale[i]*(std::abs(x(i))+1)*((_rhs[i]<0.0) ? -1.0e6 : 1.0e6);
165+ // this has conical form with center 0.
166+ // }
167+
150168 // new, experimental version. Delete comments, when this is tested.
151169 for (int i=0 ;i<_dimSys;i++){
152- _rhs[i]= (_rhs[i]<0.0 ) ? -1.0e6 : 1.0e6 ;
170+ _rhs[i]= (( _rhs[i]<0.0 ) ? -1.0e6 : 1.0e6 ) ;
153171 }
154172 // Maybe this should have conical form, ie. in case of high values, use 1.0e6*x+1.0e6 instead.
155173
@@ -173,7 +191,7 @@ bool NoxLapackInterface::computeActualF(NOX::LAPACK::Vector& f, const NOX::LAPAC
173191 std::cout << _rhs[i] << " " ;
174192 }
175193 std::cout << " )" << std::endl;
176- std::cout << " the right hand side seen by NOX is given by (" ;
194+ // std::cout << "the right hand side seen by NOX is given by (";
177195 }
178196 for (int i=0 ;i<_dimSys;i++){
179197
@@ -183,15 +201,17 @@ bool NoxLapackInterface::computeActualF(NOX::LAPACK::Vector& f, const NOX::LAPAC
183201 f (i)=_rhs[i];
184202 }
185203 // checking for infinity.
186- if (f (i)>=std::numeric_limits<double >::max ()) f (i)=1.0e6 ;
187- if (f (i)<=-std::numeric_limits<double >::max ()) f (i)=-1.0e6 ;
204+ if (f (i)>=std::numeric_limits<double >::max ()) f (i)=1.0e12 ;
205+ if (f (i)<=-std::numeric_limits<double >::max ()) f (i)=-1.0e12 ;
188206 // checking for NaN. Do NOT delete the next line, it makes sense.
189- if (!(f (i)==f (i))) f (i)=1.0e6 ;
190- if (_generateoutput) std::cout << f (i) << " " ;
207+ if (!(f (i)==f (i))) f (i)=1.0e12 ;
208+ // if (_generateoutput) std::cout << f(i) << " ";
191209 }
192210 if (_generateoutput){
193- std::cout << " )" << std::endl;
194- std::cout << std::endl;
211+ // std::cout << ")" << std::endl;
212+ // std::cout << std::endl;
213+ // std::cout << "or also" << std::endl;
214+ // f.print(std::cout);
195215 }
196216 return true ;
197217}
@@ -211,13 +231,16 @@ bool NoxLapackInterface::computeJacobian(NOX::LAPACK::Matrix<double>& J, const N
211231
212232 if (_generateoutput){
213233 std::cout << " we are at simtime " << _algLoop->getSimTime () << " and at position (seen by NOX) x=(" ;
214- for (int i=0 ;i<_dimSys;i++){
215- std::cout << x (i) << " " ;
216- }
217- std::cout << " )" << std::endl;
218- std::cout << std::endl;
234+ // for (int i=0;i<_dimSys;i++){
235+ // std::cout << x(i) << " ";
236+ // }
237+ // std::cout << ")" << std::endl;
238+ // std::cout << std::endl;
239+ // std::cout << "or" << std::endl;
240+ x.print (std::cout);
219241 }
220242
243+
221244 for (int i=0 ;i<_dimSys;i++){
222245 // adding the denominator of the difference quotient
223246 xplushei (i)+=alpha*std::abs (xplushei (i))+beta;
@@ -228,15 +251,19 @@ bool NoxLapackInterface::computeJacobian(NOX::LAPACK::Matrix<double>& J, const N
228251 xplushei (i)=x (i);
229252 }
230253
254+ // if (_generateoutput){
255+ // std::cout << "the Jacobian is given by (the transpose of) " << std::endl;
256+ // for (int i=0;i<_dimSys;i++){
257+ // for (int j=0;j<_dimSys;j++){
258+ // std::cout << J(j,i) << " ";
259+ // }
260+ // std::cout << std::endl;
261+ // }
262+ // std::cout << std::endl << "done computing Jacobian" << std::endl;
263+ // }
231264 if (_generateoutput){
232- std::cout << " the Jacobian is given by (the transpose of) " << std::endl;
233- for (int i=0 ;i<_dimSys;i++){
234- for (int j=0 ;j<_dimSys;j++){
235- std::cout << J (j,i) << " " ;
236- }
237- std::cout << std::endl;
238- }
239- std::cout << std::endl << " done computing Jacobian" << std::endl;
265+ std::cout << " the Jacobian is given by" << std::endl;
266+ J.print (std::cout);// is correct, no transposing necessary.
240267 }
241268 return true ;
242269}
@@ -250,8 +277,10 @@ void NoxLapackInterface::printSolution(const NOX::LAPACK::Vector &x, const doubl
250277{
251278 if (_generateoutput){
252279 std::cout << " At parameter value: " << std::setprecision (8 ) << conParam << " the solution vector (norm=" << x.norm () << " ) is" << std::endl;
253- for (int i=0 ; i<_dimSys; i++) std::cout << " " << x (i);
254- std::cout << " )" << std::endl;
280+ // for (int i=0; i<_dimSys; i++) std::cout << " " << x(i);
281+ // std::cout << ")" << std::endl;
282+ // std::cout << "or" << std::endl;
283+ x.print (std::cout);
255284 std::cout << " Simtime: " << _algLoop->getSimTime () << std::endl;
256285 }
257286}
0 commit comments