| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Trilinos: An Object-Oriented Solver Framework |
| 4 |
// |
| 5 |
// Copyright 2001-2024 NTESS and the Trilinos contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
/* ******************************************************************** */ |
| 11 |
/* See the file COPYRIGHT for a complete copyright notice, contact */ |
| 12 |
/* person and disclaimer. */ |
| 13 |
/* ******************************************************************** */ |
| 14 |
/*! |
| 15 |
* \file ml_nox_preconditioner1.cpp |
| 16 |
* |
| 17 |
* \class ML_Nox_Preconditioner |
| 18 |
* |
| 19 |
* \brief ML nonlinear preconditioner and solver |
| 20 |
* |
| 21 |
* \date Last update do Doxygen: 31-Mar-05 |
| 22 |
* |
| 23 |
*/ |
| 24 |
// ML-headers |
| 25 |
#include "ml_common.h" |
| 26 |
#include "TrilinosCouplings_config.h" |
| 27 |
|
| 28 |
#if defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA) && defined(HAVE_ML_AZTECOO) && defined(HAVE_ML_TEUCHOS) && defined(HAVE_ML_IFPACK) && defined(HAVE_ML_AMESOS) && defined(HAVE_ML_EPETRAEXT) |
| 29 |
|
| 30 |
#include <ctime> |
| 31 |
#include <cstdlib> |
| 32 |
#include <iostream> |
| 33 |
#include <string> |
| 34 |
#include <vector> |
| 35 |
|
| 36 |
#ifdef ML_MPI // FIXME: do we need this here? |
| 37 |
#include <mpi.h> |
| 38 |
#endif |
| 39 |
|
| 40 |
#ifdef HAVE_ML_MLAPI |
| 41 |
#include "MLAPI_Space.h" |
| 42 |
#include "MLAPI_Operator.h" |
| 43 |
#include "MLAPI_MultiVector.h" |
| 44 |
#include "MLAPI_Gallery.h" |
| 45 |
#include "MLAPI_Expressions.h" |
| 46 |
#include "MLAPI_MultiLevelAdaptiveSA.h" |
| 47 |
#include "MLAPI_DistributedMatrix.h" |
| 48 |
#endif |
| 49 |
|
| 50 |
// this class |
| 51 |
#include "ml_nox_preconditioner.H" |
| 52 |
|
| 53 |
/*----------------------------------------------------------------------* |
| 54 |
| the class defining the nln-ml-preconditioner m.gee 11/04| |
| 55 |
*----------------------------------------------------------------------*/ |
| 56 |
|
| 57 |
/*----------------------------------------------------------------------* |
| 58 |
| Constructor (public) m.gee 11/04| |
| 59 |
*----------------------------------------------------------------------*/ |
| 60 |
ML_NOX::ML_Nox_Preconditioner::ML_Nox_Preconditioner( |
| 61 |
ML_NOX::Ml_Nox_Fineinterface& interface, |
| 62 |
const Epetra_Comm& comm): |
| 63 |
interface_(interface), |
| 64 |
//DomainMap_(dm), |
| 65 |
//RangeMap_(rm), |
| 66 |
comm_(comm) |
| 67 |
{ |
| 68 |
Initialize(); |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
/*----------------------------------------------------------------------* |
| 73 |
| Constructor (public) m.gee 3/06| |
| 74 |
*----------------------------------------------------------------------*/ |
| 75 |
ML_NOX::ML_Nox_Preconditioner::ML_Nox_Preconditioner( |
| 76 |
ML_NOX::Ml_Nox_Fineinterface& interface, |
| 77 |
Teuchos::ParameterList& mlparams, |
| 78 |
const Epetra_Comm& comm): |
| 79 |
interface_(interface), |
| 80 |
//DomainMap_(dm), |
| 81 |
//RangeMap_(rm), |
| 82 |
comm_(comm) |
| 83 |
{ |
| 84 |
Initialize(); |
| 85 |
params_ = new Teuchos::ParameterList(mlparams); |
| 86 |
|
| 87 |
ml_printlevel_ = mlparams.get("nlnML output",6); |
| 88 |
ml_N_levels_ = mlparams.get("nlnML max levels",10); |
| 89 |
ml_maxcoarsesize_ = mlparams.get("nlnML coarse: max size",128); |
| 90 |
islinearPrec_ = mlparams.get("nlnML is linear preconditioner",false); |
| 91 |
ismatrixfree_ = mlparams.get("nlnML is matrixfree",true); |
| 92 |
matfreelev0_ = mlparams.get("nlnML finite difference fine level",true); |
| 93 |
|
| 94 |
fd_alpha_ = mlparams.get("nlnML finite difference alpha",1.0e-07); |
| 95 |
fd_beta_ = mlparams.get("nlnML finite difference beta",1.0e-06); |
| 96 |
fd_centered_ = mlparams.get("nlnML finite difference centered",false); |
| 97 |
|
| 98 |
FAS_normF_ = mlparams.get("nlnML absolute residual tolerance",1.0e-05); |
| 99 |
FAS_nupdate_ = FAS_normF_; |
| 100 |
FAS_maxcycle_ = mlparams.get("nlnML max cycles",250); |
| 101 |
adaptive_NewPrec_ = mlparams.get("nlnML adaptive recompute",0.0); |
| 102 |
offset_newPrec_ = mlparams.get("nlnML offset recompute",0); |
| 103 |
adaptns_ = mlparams.get("nlnML additional adaptive nullspace",0); |
| 104 |
|
| 105 |
ml_numPDE_ = mlparams.get("nlnML PDE equations",3); |
| 106 |
ml_dim_nullsp_ = mlparams.get("nlnML null space: dimension",3); |
| 107 |
ml_dim_nullsp2_ = ml_dim_nullsp_; |
| 108 |
ml_spatialDimension_ = mlparams.get("nlnML spatial dimension",3); |
| 109 |
|
| 110 |
ml_coarsentype_ = mlparams.get("nlnML coarse: type","Uncoupled"); |
| 111 |
ml_nnodeperagg_ = mlparams.get("nlnML nodes per aggregate",27); |
| 112 |
|
| 113 |
usenlnCG_fine_ = mlparams.get("nlnML use nlncg on fine level",true); |
| 114 |
usenlnCG_ = mlparams.get("nlnML use nlncg on medium level",true); |
| 115 |
usenlnCG_coarse_ = mlparams.get("nlnML use nlncg on coarsest level",true); |
| 116 |
|
| 117 |
nitersCG_fine_ = mlparams.get("nlnML max iterations newton-krylov fine level",5); |
| 118 |
nitersCG_ = mlparams.get("nlnML max iterations newton-krylov medium level" ,5); |
| 119 |
nitersCG_coarse_ = mlparams.get("nlnML max iterations newton-krylov coarsest level",5); |
| 120 |
|
| 121 |
ml_fsmoothertype_ = mlparams.get("nlnML linear smoother type fine level","SGS"); |
| 122 |
ml_smoothertype_ = mlparams.get("nlnML linear smoother type medium level","SGS"); |
| 123 |
ml_coarsesolve_ = mlparams.get("nlnML linear smoother type coarsest level","AmesosKLU"); |
| 124 |
nsmooth_fine_ = mlparams.get("nlnML linear smoother sweeps fine level",2); |
| 125 |
nsmooth_ = mlparams.get("nlnML linear smoother sweeps medium level",2); |
| 126 |
nsmooth_coarse_ = mlparams.get("nlnML linear smoother sweeps coarsest level",1); |
| 127 |
|
| 128 |
FAS_prefinesmooth_ = mlparams.get("nlnML nonlinear presmoothing sweeps fine level",0); |
| 129 |
FAS_presmooth_ = mlparams.get("nlnML nonlinear presmoothing sweeps medium level",0); |
| 130 |
FAS_coarsesmooth_ = mlparams.get("nlnML nonlinear smoothing sweeps coarse level",3); |
| 131 |
FAS_postsmooth_ = mlparams.get("nlnML nonlinear postsmoothing sweeps medium level",3); |
| 132 |
FAS_postfinesmooth_ = mlparams.get("nlnML nonlinear postsmoothing sweeps fine level",3); |
| 133 |
|
| 134 |
if (ml_printlevel_>5 && Comm().MyPID()==0) |
| 135 |
{ |
| 136 |
cout << "ML (level 0): Unused parameters (potential misspellings) in parameter list:\n"; |
| 137 |
fflush(stdout); |
| 138 |
mlparams.unused(cout); |
| 139 |
fflush(stdout); |
| 140 |
} |
| 141 |
|
| 142 |
return; |
| 143 |
} |
| 144 |
|
| 145 |
/*----------------------------------------------------------------------* |
| 146 |
| Initialize (private) m.gee 3/06| |
| 147 |
*----------------------------------------------------------------------*/ |
| 148 |
bool ML_NOX::ML_Nox_Preconditioner::Initialize() |
| 149 |
{ |
| 150 |
// label |
| 151 |
label_ = "ML_Nox_Preconditioner"; |
| 152 |
params_ = NULL; |
| 153 |
|
| 154 |
// some flags |
| 155 |
ismatrixfree_ = true; |
| 156 |
matfreelev0_ = true; |
| 157 |
islinearPrec_ = false; |
| 158 |
|
| 159 |
// set some default values |
| 160 |
// default values (some of them derived and not supported) |
| 161 |
usetranspose_ = false; |
| 162 |
isinit_ = false; |
| 163 |
fineJac_ = 0; |
| 164 |
destroyfineJac_ = false; |
| 165 |
fineGraph_ = 0; |
| 166 |
ml_graphwrap_ = 0; |
| 167 |
ml_linPrec_ = 0; |
| 168 |
ml_map_ = 0; |
| 169 |
nmatfreelevel_ = 0; |
| 170 |
ml_matfreelevel_ = 0; |
| 171 |
ncalls_NewPrec_ = 0; |
| 172 |
n_nlnlevel_ = 0; |
| 173 |
nlnLevel_ = 0; |
| 174 |
fd_alpha_ = 1.0e-07; |
| 175 |
fd_beta_ = 1.0e-06; |
| 176 |
fd_centered_ = false; |
| 177 |
offset_newPrec_ = 100; |
| 178 |
recompute_newPrec_ = 0; |
| 179 |
adaptive_NewPrec_ = 0.0; |
| 180 |
adaptns_ = 0; |
| 181 |
|
| 182 |
FAS_normF_ = 1.0e-05; |
| 183 |
FAS_nupdate_ = 1.0e-05; |
| 184 |
FAS_prefinesmooth_ = 3; |
| 185 |
FAS_presmooth_ = 3; |
| 186 |
FAS_coarsesmooth_ = 5; |
| 187 |
FAS_postsmooth_ = 3; |
| 188 |
FAS_postfinesmooth_ = 3; |
| 189 |
FAS_maxcycle_ = 250; |
| 190 |
noxsolver_ = 0; |
| 191 |
useBroyden_ = false; |
| 192 |
usenlnCG_fine_ = true; |
| 193 |
usenlnCG_ = true; |
| 194 |
usenlnCG_coarse_ = true; |
| 195 |
nitersCG_fine_ = 0; |
| 196 |
nitersCG_ = 0; |
| 197 |
nitersCG_coarse_ = 0; |
| 198 |
|
| 199 |
ml_ = 0; |
| 200 |
ag_ = 0; |
| 201 |
ml_coarsestlev_ = 0; |
| 202 |
ml_nlevel_ = 0; |
| 203 |
ml_nblocks_ = 0; |
| 204 |
ml_blocks_ = 0; |
| 205 |
ml_block_pde_ = 0; |
| 206 |
ml_N_levels_ = 3; |
| 207 |
ml_numPDE_ = 3; |
| 208 |
ml_dim_nullsp_ = 3; |
| 209 |
ml_dim_nullsp2_ = ml_dim_nullsp_; |
| 210 |
ml_coarsentype_ = "Uncoupled"; |
| 211 |
ml_printlevel_ = 8; |
| 212 |
ml_nnodeperagg_ = 9; |
| 213 |
ml_maxcoarsesize_ = 50; |
| 214 |
ml_smoothertype_ = "SGS"; |
| 215 |
ml_fsmoothertype_ = "SGS"; |
| 216 |
ml_coarsesolve_ = "AmesosKLU"; |
| 217 |
nsmooth_fine_ = 3; |
| 218 |
nsmooth_ = 3; |
| 219 |
nsmooth_coarse_ = 1; |
| 220 |
return true; |
| 221 |
} |
| 222 |
|
| 223 |
/*----------------------------------------------------------------------* |
| 224 |
| Set methods for flags/data (public) m.gee 03/05| |
| 225 |
*----------------------------------------------------------------------*/ |
| 226 |
bool ML_NOX::ML_Nox_Preconditioner::SetCoarsenType(string coarsentype, |
| 227 |
int maxlevel, |
| 228 |
int maxcoarsesize, |
| 229 |
int nnodeperagg) |
| 230 |
{ |
| 231 |
if (coarsentype != "Uncoupled" && coarsentype != "MIS" && |
| 232 |
coarsentype != "METIS" && coarsentype != "VBMETIS") |
| 233 |
{ |
| 234 |
cout << "**ERR**: ML_Nox_Preconditioner::SetCoarsenType:\n" |
| 235 |
<< "**ERR**: coarsen type: " << coarsentype << " not recognized!\n" |
| 236 |
<< "**ERR**: Using previously set coarsen method: " << ml_coarsentype_ << endl |
| 237 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 238 |
coarsentype = ml_coarsentype_; |
| 239 |
} |
| 240 |
|
| 241 |
if (maxlevel<2) |
| 242 |
{ |
| 243 |
cout << "**ERR**: ML_Nox_Preconditioner::SetCoarsenType:\n" |
| 244 |
<< "**ERR**: maxlevel < 2 out of range, minimum is 2 level!\n" |
| 245 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 246 |
maxlevel=2; |
| 247 |
} |
| 248 |
|
| 249 |
ml_N_levels_ = maxlevel; |
| 250 |
ml_coarsentype_ = coarsentype; |
| 251 |
ml_nnodeperagg_ = nnodeperagg; |
| 252 |
ml_maxcoarsesize_ = maxcoarsesize; |
| 253 |
|
| 254 |
return true; |
| 255 |
} |
| 256 |
/*----------------------------------------------------------------------* |
| 257 |
| Set methods for flags/data (public) m.gee 03/05| |
| 258 |
*----------------------------------------------------------------------*/ |
| 259 |
bool ML_NOX::ML_Nox_Preconditioner::SetSmoothers(string finesmoothertype, |
| 260 |
string smoothertype, |
| 261 |
string coarsesolve) |
| 262 |
{ |
| 263 |
if (smoothertype != "SGS" && |
| 264 |
smoothertype != "Jacobi" && |
| 265 |
smoothertype != "AmesosKLU" && |
| 266 |
smoothertype != "BSGS" && |
| 267 |
smoothertype != "Bcheby" && |
| 268 |
smoothertype != "Cheby" && |
| 269 |
smoothertype != "MLS") |
| 270 |
{ |
| 271 |
cout << "**ERR**: ML_Nox_Preconditioner::SetSmoothers:\n" |
| 272 |
<< "**ERR**: smoother type: " << smoothertype << " not recognized!\n" |
| 273 |
<< "**ERR**: using previous smoother: " << ml_smoothertype_ << endl |
| 274 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 275 |
} |
| 276 |
else |
| 277 |
ml_smoothertype_ = smoothertype; |
| 278 |
|
| 279 |
if (finesmoothertype != "SGS" && |
| 280 |
finesmoothertype != "Jacobi" && |
| 281 |
finesmoothertype != "AmesosKLU" && |
| 282 |
finesmoothertype != "BSGS" && |
| 283 |
finesmoothertype != "Bcheby" && |
| 284 |
finesmoothertype != "Cheby" && |
| 285 |
finesmoothertype != "MLS") |
| 286 |
{ |
| 287 |
cout << "**ERR**: ML_Nox_Preconditioner::SetSmoothers:\n" |
| 288 |
<< "**ERR**: fine level smoother type: " << finesmoothertype << " not recognized!\n" |
| 289 |
<< "**ERR**: using previous smoother: " << ml_fsmoothertype_ << endl |
| 290 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 291 |
} |
| 292 |
else |
| 293 |
ml_fsmoothertype_ = finesmoothertype; |
| 294 |
|
| 295 |
if (coarsesolve != "SGS" && |
| 296 |
coarsesolve != "Jacobi" && |
| 297 |
coarsesolve != "AmesosKLU" && |
| 298 |
coarsesolve != "BSGS" && |
| 299 |
coarsesolve != "Bcheby" && |
| 300 |
coarsesolve != "Cheby" && |
| 301 |
coarsesolve != "MLS") |
| 302 |
{ |
| 303 |
cout << "**ERR**: ML_Nox_Preconditioner::ML_Nox_Preconditioner:\n" |
| 304 |
<< "**ERR**: coarse solver: " << coarsesolve << " not recognized!\n" |
| 305 |
<< "**ERR**: using previous coarse solver: " << ml_coarsesolve_ << endl |
| 306 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 307 |
} |
| 308 |
else |
| 309 |
ml_coarsesolve_ = coarsesolve; |
| 310 |
return true; |
| 311 |
} |
| 312 |
/*----------------------------------------------------------------------* |
| 313 |
| Set methods for flags/data (public) m.gee 03/05| |
| 314 |
*----------------------------------------------------------------------*/ |
| 315 |
bool ML_NOX::ML_Nox_Preconditioner::SetPrintLevel(int printlevel) |
| 316 |
{ |
| 317 |
if (printlevel<0 || printlevel>10) |
| 318 |
{ |
| 319 |
cout << "**ERR**: ML_Nox_Preconditioner::SetPrintLevel:\n" |
| 320 |
<< "**ERR**: printlevel out of range, using previous one\n" |
| 321 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 322 |
return false; |
| 323 |
} |
| 324 |
ml_printlevel_ = printlevel; |
| 325 |
return true; |
| 326 |
} |
| 327 |
|
| 328 |
/*----------------------------------------------------------------------* |
| 329 |
| Set methods for flags/data (public) m.gee 03/05| |
| 330 |
*----------------------------------------------------------------------*/ |
| 331 |
bool ML_NOX::ML_Nox_Preconditioner::SetRecomputeOffset(int offset) |
| 332 |
{ |
| 333 |
if (offset<0) |
| 334 |
{ |
| 335 |
cout << "**ERR**: ML_Nox_Preconditioner::SetRecomputeOffset:\n" |
| 336 |
<< "**ERR**: offset out of range, using previous one\n" |
| 337 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 338 |
return false; |
| 339 |
} |
| 340 |
offset_newPrec_ = offset; |
| 341 |
return true; |
| 342 |
} |
| 343 |
|
| 344 |
/*----------------------------------------------------------------------* |
| 345 |
| Set methods for flags/data (public) m.gee 03/05| |
| 346 |
*----------------------------------------------------------------------*/ |
| 347 |
bool ML_NOX::ML_Nox_Preconditioner::SetRecomputeOffset(int offset, |
| 348 |
int recomputestep, |
| 349 |
double adaptrecompute, |
| 350 |
int adaptns) |
| 351 |
{ |
| 352 |
if (offset<0 || recomputestep<0) |
| 353 |
{ |
| 354 |
cout << "**ERR**: ML_Nox_Preconditioner::SetRecomputeOffset:\n" |
| 355 |
<< "**ERR**: offset or recomputestep out of range, using previous one\n" |
| 356 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 357 |
return false; |
| 358 |
} |
| 359 |
offset_newPrec_ = offset; |
| 360 |
recompute_newPrec_ = recomputestep; |
| 361 |
adaptive_NewPrec_ = adaptrecompute; |
| 362 |
adaptns_ = adaptns; |
| 363 |
return true; |
| 364 |
} |
| 365 |
|
| 366 |
/*----------------------------------------------------------------------* |
| 367 |
| Set methods for flags/data (public) m.gee 03/05| |
| 368 |
*----------------------------------------------------------------------*/ |
| 369 |
bool ML_NOX::ML_Nox_Preconditioner::SetDimensions(int spatialDimension, |
| 370 |
int numPDE, int dimNS) |
| 371 |
{ |
| 372 |
if (spatialDimension<1 || spatialDimension>3) |
| 373 |
{ |
| 374 |
cout << "**ERR**: ML_Nox_Preconditioner::SetDimensions:\n" |
| 375 |
<< "**ERR**: spatialDimension out of range, using previous one\n" |
| 376 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 377 |
} |
| 378 |
else |
| 379 |
ml_spatialDimension_ = spatialDimension; |
| 380 |
|
| 381 |
if (numPDE<1) |
| 382 |
{ |
| 383 |
cout << "**ERR**: ML_Nox_Preconditioner::SetDimensions:\n" |
| 384 |
<< "**ERR**: numPDE out of range, using previous one\n" |
| 385 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 386 |
} |
| 387 |
else |
| 388 |
ml_numPDE_ = numPDE; |
| 389 |
|
| 390 |
if (dimNS<0) |
| 391 |
{ |
| 392 |
cout << "**ERR**: ML_Nox_Preconditioner::SetDimensions:\n" |
| 393 |
<< "**ERR**: dimNS<0 out of range using dimNS = numPDE\n" |
| 394 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 395 |
dimNS = numPDE; |
| 396 |
} |
| 397 |
if (dimNS<numPDE) |
| 398 |
{ |
| 399 |
cout << "**ERR**: ML_Nox_Preconditioner::SetDimensions:\n" |
| 400 |
<< "**ERR**: dimNS<numPDE bad choice\n" |
| 401 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 402 |
|
| 403 |
} |
| 404 |
ml_dim_nullsp_ = dimNS; |
| 405 |
ml_dim_nullsp2_ = ml_dim_nullsp_; |
| 406 |
return true; |
| 407 |
} |
| 408 |
|
| 409 |
/*----------------------------------------------------------------------* |
| 410 |
| Set methods for flags/data (public) m.gee 03/05| |
| 411 |
*----------------------------------------------------------------------*/ |
| 412 |
bool ML_NOX::ML_Nox_Preconditioner::SetSmootherSweeps(int nsmooth_fine, |
| 413 |
int nsmooth, |
| 414 |
int nsmooth_coarse) |
| 415 |
{ |
| 416 |
nsmooth_fine_ = nsmooth_fine; |
| 417 |
nsmooth_ = nsmooth; |
| 418 |
nsmooth_coarse_ = nsmooth_coarse; |
| 419 |
return true; |
| 420 |
} |
| 421 |
|
| 422 |
/*----------------------------------------------------------------------* |
| 423 |
| Set methods for flags/data (public) m.gee 03/05| |
| 424 |
*----------------------------------------------------------------------*/ |
| 425 |
bool ML_NOX::ML_Nox_Preconditioner::SetConvergenceCriteria(double FAS_normF, |
| 426 |
double FAS_nupdate) |
| 427 |
{ |
| 428 |
FAS_normF_ = FAS_normF; |
| 429 |
FAS_nupdate_ = FAS_nupdate; |
| 430 |
return true; |
| 431 |
} |
| 432 |
|
| 433 |
/*----------------------------------------------------------------------* |
| 434 |
| Set methods for flags/data (public) m.gee 03/05| |
| 435 |
*----------------------------------------------------------------------*/ |
| 436 |
bool ML_NOX::ML_Nox_Preconditioner::SetFiniteDifferencing(bool centered, |
| 437 |
double alpha, |
| 438 |
double beta) |
| 439 |
{ |
| 440 |
fd_alpha_ = alpha; |
| 441 |
fd_beta_ = beta; |
| 442 |
fd_centered_ = centered; |
| 443 |
return true; |
| 444 |
} |
| 445 |
|
| 446 |
/*----------------------------------------------------------------------* |
| 447 |
| Set methods for flags/data (public) m.gee 03/05| |
| 448 |
*----------------------------------------------------------------------*/ |
| 449 |
bool ML_NOX::ML_Nox_Preconditioner::SetFAScycle(int prefsmooth,int presmooth, |
| 450 |
int coarsesmooth,int postsmooth, |
| 451 |
int postfsmooth,int maxcycle) |
| 452 |
{ |
| 453 |
FAS_prefinesmooth_ = prefsmooth; |
| 454 |
FAS_presmooth_ = presmooth; |
| 455 |
FAS_coarsesmooth_ = coarsesmooth; |
| 456 |
FAS_postsmooth_ = postsmooth; |
| 457 |
FAS_postfinesmooth_ = postfsmooth; |
| 458 |
FAS_maxcycle_ = maxcycle; |
| 459 |
return true; |
| 460 |
} |
| 461 |
|
| 462 |
/*----------------------------------------------------------------------* |
| 463 |
| Set methods for flags/data (public) m.gee 03/05| |
| 464 |
*----------------------------------------------------------------------*/ |
| 465 |
bool ML_NOX::ML_Nox_Preconditioner::SetNonlinearMethod(bool islinPrec, |
| 466 |
int maxlevel, |
| 467 |
bool ismatrixfree, |
| 468 |
bool ismatfreelev0, |
| 469 |
bool fixdiagonal) |
| 470 |
{ |
| 471 |
islinearPrec_ = islinPrec; |
| 472 |
ismatrixfree_ = ismatrixfree; |
| 473 |
matfreelev0_ = ismatfreelev0; |
| 474 |
fixdiagonal_ = fixdiagonal; |
| 475 |
ml_N_levels_ = maxlevel; |
| 476 |
|
| 477 |
if (islinPrec && ismatrixfree && !ismatfreelev0 && |
| 478 |
(ml_fsmoothertype_== "Jacobi" || |
| 479 |
ml_smoothertype_ == "Jacobi" || |
| 480 |
ml_coarsesolve_ == "Jacobi")) |
| 481 |
{ |
| 482 |
cout << "**ERR**: ML_Nox_Preconditioner::SetNonlinearMethod:\n" |
| 483 |
<< "**ERR**: linearPrec && matrixfree & Jacobi smoother doesn't work!\n" |
| 484 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; throw -1; |
| 485 |
} |
| 486 |
return true; |
| 487 |
} |
| 488 |
|
| 489 |
/*----------------------------------------------------------------------* |
| 490 |
| Set nonlinear solvers (public) m.gee 04/05| |
| 491 |
*----------------------------------------------------------------------*/ |
| 492 |
bool ML_NOX::ML_Nox_Preconditioner::SetNonlinearSolvers(bool usenlnCG_fine, |
| 493 |
bool usenlnCG, |
| 494 |
bool usenlnCG_coarse, |
| 495 |
bool useBroyden, |
| 496 |
int nitersCG_fine, |
| 497 |
int nitersCG, |
| 498 |
int nitersCG_coarse) |
| 499 |
{ |
| 500 |
usenlnCG_fine_ = usenlnCG_fine; |
| 501 |
usenlnCG_ = usenlnCG; |
| 502 |
usenlnCG_coarse_ = usenlnCG_coarse; |
| 503 |
|
| 504 |
useBroyden_ = useBroyden; |
| 505 |
|
| 506 |
nitersCG_fine_ = nitersCG_fine; |
| 507 |
nitersCG_ = nitersCG; |
| 508 |
nitersCG_coarse_ = nitersCG_coarse; |
| 509 |
return true; |
| 510 |
} |
| 511 |
|
| 512 |
/*----------------------------------------------------------------------* |
| 513 |
| Destructor (public) m.gee 11/04| |
| 514 |
*----------------------------------------------------------------------*/ |
| 515 |
ML_NOX::ML_Nox_Preconditioner::~ML_Nox_Preconditioner() |
| 516 |
{ |
| 517 |
if (ml_linPrec_) |
| 518 |
delete ml_linPrec_; |
| 519 |
ml_linPrec_ = 0; |
| 520 |
|
| 521 |
if (ml_map_) |
| 522 |
delete ml_map_; |
| 523 |
ml_map_ = 0; |
| 524 |
|
| 525 |
if (ml_graphwrap_) |
| 526 |
delete ml_graphwrap_; |
| 527 |
ml_graphwrap_ = 0; |
| 528 |
|
| 529 |
if (ml_matfreelevel_) |
| 530 |
destroy_matfreelevels(&ml_matfreelevel_,nmatfreelevel_); |
| 531 |
|
| 532 |
if (ml_blocks_) |
| 533 |
delete [] ml_blocks_; |
| 534 |
ml_blocks_ = 0; |
| 535 |
|
| 536 |
if (ag_) |
| 537 |
ML_Aggregate_Destroy(&ag_); |
| 538 |
ag_ = 0; |
| 539 |
|
| 540 |
if (ml_) |
| 541 |
ML_Destroy(&ml_); |
| 542 |
ml_ = 0; |
| 543 |
|
| 544 |
if (nlnLevel_) |
| 545 |
destroy_nonlinearlevels(&nlnLevel_,n_nlnlevel_); |
| 546 |
|
| 547 |
if (ml_blocks_) |
| 548 |
delete [] ml_blocks_; |
| 549 |
ml_blocks_ = 0; |
| 550 |
|
| 551 |
if (ml_block_pde_) |
| 552 |
delete [] ml_block_pde_; |
| 553 |
ml_block_pde_ = 0; |
| 554 |
|
| 555 |
if (destroyfineJac_ && fineJac_) |
| 556 |
delete fineJac_; |
| 557 |
fineJac_ = 0; |
| 558 |
|
| 559 |
return; |
| 560 |
} |
| 561 |
|
| 562 |
/*----------------------------------------------------------------------* |
| 563 |
| destroy vector of nonlinearlevels m.gee 1/05 | |
| 564 |
*----------------------------------------------------------------------*/ |
| 565 |
bool ML_NOX::ML_Nox_Preconditioner::destroy_nonlinearlevels( |
| 566 |
ML_NOX::ML_Nox_NonlinearLevel*** nln, |
| 567 |
int nlevel) |
| 568 |
{ |
| 569 |
int i; |
| 570 |
if (*nln) |
| 571 |
{ |
| 572 |
(*nln)[0]->destroyP(); |
| 573 |
for (i=0; i<nlevel; i++) |
| 574 |
{ |
| 575 |
if ((*nln)[i]) |
| 576 |
{ |
| 577 |
(*nln)[i]->setP(NULL); |
| 578 |
delete (*nln)[i]; |
| 579 |
(*nln)[i] = 0; |
| 580 |
} |
| 581 |
} |
| 582 |
delete [] (*nln); |
| 583 |
*nln = 0; |
| 584 |
n_nlnlevel_ = 0; |
| 585 |
} |
| 586 |
return true; |
| 587 |
} |
| 588 |
|
| 589 |
/*----------------------------------------------------------------------* |
| 590 |
| destroy vector of matrixfreelevels m.gee 1/05 | |
| 591 |
*----------------------------------------------------------------------*/ |
| 592 |
bool ML_NOX::ML_Nox_Preconditioner::destroy_matfreelevels( |
| 593 |
ML_NOX::ML_Nox_MatrixfreeLevel*** m, |
| 594 |
int nlevel) |
| 595 |
{ |
| 596 |
int i; |
| 597 |
if (*m) |
| 598 |
{ |
| 599 |
(*m)[0]->destroyP(); |
| 600 |
for (i=0; i<nlevel; i++) |
| 601 |
{ |
| 602 |
if ((*m)[i]) |
| 603 |
{ |
| 604 |
(*m)[i]->setP(NULL); |
| 605 |
delete (*m)[i]; |
| 606 |
(*m)[i] = 0; |
| 607 |
} |
| 608 |
} |
| 609 |
delete [] (*m); |
| 610 |
*m = 0; |
| 611 |
nmatfreelevel_ = 0; |
| 612 |
} |
| 613 |
return true; |
| 614 |
} |
| 615 |
|
| 616 |
/*----------------------------------------------------------------------* |
| 617 |
| compute the multilevel preconditioner (public) m.gee 11/04| |
| 618 |
*----------------------------------------------------------------------*/ |
| 619 |
bool ML_NOX::ML_Nox_Preconditioner::computePreconditioner( |
| 620 |
const Epetra_Vector& x, |
| 621 |
NOX::Parameter::List* precParams) |
| 622 |
{ |
| 623 |
bool flag = true; |
| 624 |
int offset = getoffset(); |
| 625 |
if (offset && ncalls_NewPrec_ != 0) |
| 626 |
if (ncalls_NewPrec_ % offset == 0) // recompute every offset |
| 627 |
setinit(false); |
| 628 |
else if (recompute_newPrec_ != 0) // recompute initially after step recompute_newPrec_ |
| 629 |
if (ncalls_NewPrec_ == recompute_newPrec_) |
| 630 |
setinit(false); |
| 631 |
else if (adaptive_NewPrec_ > 0.0 && ncalls_NewPrec_ != 0 && !islinearPrec_) |
| 632 |
{ |
| 633 |
if (!noxsolver_ && !islinearPrec_) |
| 634 |
{ |
| 635 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::computePreconditioner:\n" |
| 636 |
<< "**ERR**: noxsolver not registered, use set_nox_solver(solver)!\n" |
| 637 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 638 |
} |
| 639 |
const NOX::EpetraNew::Group& finalGroup = |
| 640 |
dynamic_cast<const NOX::EpetraNew::Group&>(noxsolver_->getSolutionGroup()); |
| 641 |
const Epetra_Vector& currentF = |
| 642 |
(dynamic_cast<const NOX::Epetra::Vector&>(finalGroup.getF())).getEpetraVector(); |
| 643 |
double norm; |
| 644 |
currentF.Norm2(&norm); |
| 645 |
if (norm>adaptive_NewPrec_) |
| 646 |
setinit(false); |
| 647 |
} |
| 648 |
if (isinit() == false) |
| 649 |
{ |
| 650 |
if (comm_.MyPID()==0 && ml_printlevel_ > 0 ) |
| 651 |
cout << "ML: ML_Nox_Preconditioner::computePreconditioner: (re)computing ML-Preconditioner\n"; |
| 652 |
|
| 653 |
// save number of calls to computeF up to now |
| 654 |
int ncalls = interface_.getnumcallscomputeF(); |
| 655 |
|
| 656 |
// reset number of calls to computeF to zero to measure number of calls in compPrec() |
| 657 |
interface_.setnumcallscomputeF(0); |
| 658 |
|
| 659 |
double t0 = GetClock(); |
| 660 |
flag = compPrec(x); |
| 661 |
double t1 = GetClock(); |
| 662 |
|
| 663 |
if (comm_.MyPID()==0 && ml_printlevel_ > 0 ) |
| 664 |
{ |
| 665 |
cout << "ML: Setup time for preconditioner: " << (t1-t0) << " sec\n"; |
| 666 |
cout << "ML: Number of calls to fineinterface.computeF() in setup: " |
| 667 |
<< interface_.getnumcallscomputeF() << endl; |
| 668 |
} |
| 669 |
|
| 670 |
// reset the number of calls to computeF to what it was before |
| 671 |
interface_.setnumcallscomputeF(ncalls); |
| 672 |
|
| 673 |
if (flag==true) |
| 674 |
setinit(true); |
| 675 |
else |
| 676 |
{ |
| 677 |
cout << "**ERR**: ML_Nox_Preconditioner::computePreconditioner:\n" |
| 678 |
<< "**ERR**: compPrec returned false\n" |
| 679 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; throw -1; |
| 680 |
} |
| 681 |
setinit(true); |
| 682 |
} |
| 683 |
++ncalls_NewPrec_; |
| 684 |
return flag; |
| 685 |
} |
| 686 |
/*----------------------------------------------------------------------* |
| 687 |
| compute the multilevel preconditioner (private) m.gee 11/04| |
| 688 |
*----------------------------------------------------------------------*/ |
| 689 |
bool ML_NOX::ML_Nox_Preconditioner::compPrec(const Epetra_Vector& x) |
| 690 |
{ |
| 691 |
int i; |
| 692 |
|
| 693 |
// when matfreelev0_==true, set ismatrixfree_=true as well |
| 694 |
if (matfreelev0_) |
| 695 |
ismatrixfree_=true; |
| 696 |
|
| 697 |
//--------------------------------------------------------------------- |
| 698 |
// build hierarchy with given Jacobian |
| 699 |
//--------------------------------------------------------------------- |
| 700 |
if (ismatrixfree_ == false) |
| 701 |
{ |
| 702 |
// recompute Jacobian |
| 703 |
if (fineJac_ && destroyfineJac_) delete fineJac_; |
| 704 |
interface_.computeJacobian(x); |
| 705 |
fineJac_ = interface_.getJacobian(); |
| 706 |
if (fineJac_ == NULL) |
| 707 |
{ |
| 708 |
cout << "**ERR**: ML_Nox_Preconditioner::compPrec:\n" |
| 709 |
<< "**ERR**: interface_.getJacobian() returned NULL\n" |
| 710 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; throw -1; |
| 711 |
} |
| 712 |
// check for zero rows and fix the main diagonal of them |
| 713 |
if (fixdiagonal_) |
| 714 |
fix_MainDiagonal(&fineJac_,0); |
| 715 |
|
| 716 |
fineJac_ = ML_NOX::StripZeros(*fineJac_,1.0e-11); |
| 717 |
destroyfineJac_ = true; |
| 718 |
} |
| 719 |
|
| 720 |
//--------------------------------------------------------------------- |
| 721 |
// build matrixfree hierachy and probe for all operators |
| 722 |
//--------------------------------------------------------------------- |
| 723 |
else if (ismatrixfree_ == true && matfreelev0_ == false ) |
| 724 |
{ |
| 725 |
// get the graph from the user-interface |
| 726 |
fineGraph_ = interface_.getGraph(); |
| 727 |
if (fineGraph_ == NULL) |
| 728 |
{ |
| 729 |
cout << "**ERR**: ML_Nox_Preconditioner::compPrec:\n" |
| 730 |
<< "**ERR**: interface_.getGraph() returned NULL\n" |
| 731 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; throw -1; |
| 732 |
} |
| 733 |
|
| 734 |
// Maybe there exists a ml_graphwrap_ from a previous call? |
| 735 |
if (ml_graphwrap_ != NULL) |
| 736 |
delete ml_graphwrap_; |
| 737 |
|
| 738 |
// this guy wraps an Epetra_CrsGraph as an Epetra_RowMatrix |
| 739 |
// (there exists a ML_Operator - wrapper for an Epetra_RowMatrix |
| 740 |
// we can then use) |
| 741 |
const Epetra_Map& map = interface_.getMap(); |
| 742 |
ml_graphwrap_ = new ML_Epetra::CrsGraphWrapper(*fineGraph_,map,map,comm_); |
| 743 |
} |
| 744 |
|
| 745 |
//--------------------------------------------------------------------- |
| 746 |
// probe for operator on level 0 and switch to ismatrixfree_==false |
| 747 |
//--------------------------------------------------------------------- |
| 748 |
else if (ismatrixfree_ == true && matfreelev0_ == true) |
| 749 |
{ |
| 750 |
if (fineJac_ && destroyfineJac_) delete fineJac_; |
| 751 |
fineJac_ = ML_Nox_computeFineLevelJacobian(x); |
| 752 |
|
| 753 |
// check for zero rows and fix the main diagonal of them |
| 754 |
if (fixdiagonal_) |
| 755 |
fix_MainDiagonal(&fineJac_,0); |
| 756 |
|
| 757 |
//cout << "the Finite Difference Jacobian:\n"; |
| 758 |
//ML_NOX::Print_Epetra_CrsMatrix(*fineJac_); |
| 759 |
//cout << "the adagio Jacobian:\n"; |
| 760 |
//Epetra_CrsMatrix* adagio = ML_NOX::StripZeros(*(interface_.getJacobian()),1.0e-11); |
| 761 |
//ML_NOX::Print_Epetra_CrsMatrix(*adagio); |
| 762 |
//exit(0); |
| 763 |
|
| 764 |
// this class is in charge of destroying the operator fineJac_ |
| 765 |
destroyfineJac_ = true; |
| 766 |
// turn to ismatrixfree_==false |
| 767 |
ismatrixfree_ = false; |
| 768 |
} |
| 769 |
|
| 770 |
//--------------------------------------------------------------------- |
| 771 |
// check whether ML and ML_Aggregate handles exist and (re)create them |
| 772 |
//--------------------------------------------------------------------- |
| 773 |
if (ag_ != NULL) ML_Aggregate_Destroy(&ag_); |
| 774 |
ML_Aggregate_Create(&ag_); |
| 775 |
|
| 776 |
if (ml_ != NULL) ML_Destroy(&ml_); |
| 777 |
ML_Create(&ml_,ml_N_levels_); |
| 778 |
|
| 779 |
//--------------------------------------------------------------------- |
| 780 |
// set matrix for fine grid |
| 781 |
// NOTE: this is either a wrapped graph or the real fine grid Jacobian |
| 782 |
//--------------------------------------------------------------------- |
| 783 |
if (ismatrixfree_ == false) |
| 784 |
EpetraMatrix2MLMatrix(ml_,0,(dynamic_cast<Epetra_RowMatrix*>(fineJac_))); |
| 785 |
else |
| 786 |
EpetraMatrix2MLMatrix(ml_,0,(dynamic_cast<Epetra_RowMatrix*>(ml_graphwrap_))); |
| 787 |
|
| 788 |
//--------------------------------------------------------------------- |
| 789 |
// set coarsening scheme |
| 790 |
//--------------------------------------------------------------------- |
| 791 |
if (ml_coarsentype_ == "Uncoupled") |
| 792 |
ML_Aggregate_Set_CoarsenScheme_Uncoupled(ag_); |
| 793 |
if (ml_coarsentype_ == "MIS") |
| 794 |
ML_Aggregate_Set_CoarsenScheme_MIS(ag_); |
| 795 |
if (ml_coarsentype_ == "METIS") |
| 796 |
{ |
| 797 |
ML_Aggregate_Set_CoarsenScheme_METIS(ag_); |
| 798 |
for (i=0; i<ml_N_levels_; i++) |
| 799 |
ML_Aggregate_Set_NodesPerAggr(ml_,ag_,i,ml_nnodeperagg_); |
| 800 |
} |
| 801 |
if (ml_coarsentype_ == "VBMETIS") |
| 802 |
{ |
| 803 |
if (ml_blocks_) delete [] ml_blocks_; ml_blocks_ = 0; |
| 804 |
if (ml_block_pde_) delete [] ml_block_pde_; ml_block_pde_ = 0; |
| 805 |
|
| 806 |
// get the block information from the application |
| 807 |
bool ok = interface_.getBlockInfo(&ml_nblocks_,&ml_blocks_,&ml_block_pde_); |
| 808 |
if (!ok) // we failed to get the blocks, do plain METIS instead |
| 809 |
{ |
| 810 |
cout << "**WRN**: ML_Nox_Preconditioner::compPrec:\n" |
| 811 |
<< "**WRN**: interface returned no blocks,\n" |
| 812 |
<< "**WRN**: using aggregation scheme METIS instead of VBMETIS\n"; |
| 813 |
ml_coarsentype_ = "METIS"; |
| 814 |
ML_Aggregate_Set_CoarsenScheme_METIS(ag_); |
| 815 |
} |
| 816 |
else |
| 817 |
{ |
| 818 |
ML_Aggregate_Set_CoarsenScheme_VBMETIS(ag_); |
| 819 |
int N_update = interface_.getMap().NumMyElements(); |
| 820 |
ML_Aggregate_Set_Vblocks_CoarsenScheme_VBMETIS(ag_,0,ml_N_levels_, |
| 821 |
ml_nblocks_,ml_blocks_, |
| 822 |
ml_block_pde_,N_update); |
| 823 |
if (ml_blocks_) delete [] ml_blocks_; ml_blocks_ = 0; |
| 824 |
if (ml_block_pde_) delete [] ml_block_pde_; ml_block_pde_ = 0; |
| 825 |
} |
| 826 |
for (i=0; i<ml_N_levels_; i++) |
| 827 |
ML_Aggregate_Set_NodesPerAggr(ml_,ag_,i,ml_nnodeperagg_); |
| 828 |
} |
| 829 |
|
| 830 |
//--------------------------------------------------------------------- |
| 831 |
// set default damping factor |
| 832 |
if (ismatrixfree_ == true) |
| 833 |
ML_Aggregate_Set_DampingFactor(ag_, 0.0); // cannot do smoothed aggregation on a graph |
| 834 |
else |
| 835 |
ML_Aggregate_Set_DampingFactor(ag_, 1.5); // do smoothed aggregation on a Jacobian |
| 836 |
|
| 837 |
//--------------------------------------------------------------------- |
| 838 |
// set default threshold to zero |
| 839 |
ML_Aggregate_Set_Threshold(ag_, 0.0); |
| 840 |
|
| 841 |
//--------------------------------------------------------------------- |
| 842 |
// set max coarsest grid size |
| 843 |
ML_Aggregate_Set_MaxCoarseSize(ag_,ml_maxcoarsesize_); |
| 844 |
|
| 845 |
//--------------------------------------------------------------------- |
| 846 |
// Calculate spectral norm |
| 847 |
ML_Set_SpectralNormScheme_Calc(ml_); |
| 848 |
|
| 849 |
//--------------------------------------------------------------------- |
| 850 |
// set ML printlevel |
| 851 |
ML_Set_PrintLevel(ml_printlevel_); |
| 852 |
|
| 853 |
//--------------------------------------------------------------------- |
| 854 |
// set the nullspace |
| 855 |
if (ismatrixfree_ == true) |
| 856 |
i = ml_graphwrap_->NumMyRows(); |
| 857 |
else |
| 858 |
i = fineJac_->NumMyRows(); |
| 859 |
// get the nullspace |
| 860 |
ml_dim_nullsp_ = ml_dim_nullsp2_; |
| 861 |
double* nullsp = interface_.Get_Nullspace(i,ml_numPDE_,ml_dim_nullsp_); |
| 862 |
|
| 863 |
//--------------------------------------------------------------------- |
| 864 |
// run adaptive setup phase |
| 865 |
if (adaptns_>0) |
| 866 |
{ |
| 867 |
Ml_Nox_adaptivesetup(&nullsp,fineJac_,ml_numPDE_,ml_dim_nullsp_); |
| 868 |
ml_dim_nullsp_ += adaptns_; |
| 869 |
} |
| 870 |
|
| 871 |
//--------------------------------------------------------------------- |
| 872 |
if (nullsp) |
| 873 |
{ |
| 874 |
#if 0 |
| 875 |
test_nullspace(ml_dim_nullsp_,nullsp,fineJac_); |
| 876 |
#endif |
| 877 |
ML_Aggregate_Set_NullSpace(ag_,ml_numPDE_,ml_dim_nullsp_,nullsp,i); |
| 878 |
delete [] nullsp; nullsp = 0; |
| 879 |
} |
| 880 |
else |
| 881 |
{ |
| 882 |
cout << "**WRN**: ML_Nox_Preconditioner::compPrec:\n" |
| 883 |
<< "**WRN**: interface returned no nullspace,\n" |
| 884 |
<< "**WRN**: using ML's default nullspace\n"; |
| 885 |
if (ml_numPDE_ != ml_dim_nullsp_) |
| 886 |
{ |
| 887 |
cout << "**WRN**: ML_Nox_Preconditioner::compPrec:\n" |
| 888 |
<< "**WRN**: with default nullspace, nullspace-dimension must match number of PDEs per node\n" |
| 889 |
<< "**WRN**: numPDE = " << ml_numPDE_ << ", dim_nullsp = " << ml_dim_nullsp_ << "\n" |
| 890 |
<< "**WRN**: continue with setting dim_nullsp = ml_numPDE_\n"; |
| 891 |
ml_dim_nullsp_ = ml_numPDE_; |
| 892 |
} |
| 893 |
ML_Aggregate_Set_NullSpace(ag_,ml_numPDE_,ml_dim_nullsp_,NULL,i); |
| 894 |
} |
| 895 |
|
| 896 |
//--------------------------------------------------------------------- |
| 897 |
// keep the aggregation information |
| 898 |
ag_->keep_agg_information = 1; |
| 899 |
|
| 900 |
//--------------------------------------------------------------------- |
| 901 |
// build hierarchy |
| 902 |
//--------------------------------------------------------------------- |
| 903 |
ml_nlevel_ = ML_Gen_MGHierarchy_UsingAggregation(ml_,0,ML_INCREASING,ag_); |
| 904 |
|
| 905 |
if (ml_nlevel_<2) |
| 906 |
{ |
| 907 |
cout << "**ERR**: ML_Nox_Preconditioner::compPrec:\n" |
| 908 |
<< "**ERR**: number of levels generated is " << ml_nlevel_ << "\n" |
| 909 |
<< "**ERR**: this algorithm relies on at least nlevel >=2 !\n" |
| 910 |
<< "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; throw -1; |
| 911 |
} |
| 912 |
|
| 913 |
ml_coarsestlev_ = ml_nlevel_-1; |
| 914 |
|
| 915 |
if (ismatrixfree_ == false && islinearPrec_ == true) |
| 916 |
{ |
| 917 |
isinit_ = ML_Nox_compute_Jacobian_Linearpreconditioner(x); |
| 918 |
if (isinit_ == true) |
| 919 |
return(true); |
| 920 |
else |
| 921 |
return(false); |
| 922 |
} |
| 923 |
else if (ismatrixfree_ == true && islinearPrec_ == true) |
| 924 |
{ |
| 925 |
isinit_ = ML_Nox_compute_Matrixfree_Linearpreconditioner(x); |
| 926 |
if (isinit_ == true) |
| 927 |
return(true); |
| 928 |
else |
| 929 |
return(false); |
| 930 |
} |
| 931 |
else if (ismatrixfree_ == false && islinearPrec_ == false) |
| 932 |
{ |
| 933 |
isinit_ = ML_Nox_compute_Jacobian_Nonlinearpreconditioner(x); |
| 934 |
if (isinit_ == true) |
| 935 |
return(true); |
| 936 |
else |
| 937 |
return(false); |
| 938 |
} |
| 939 |
else if (ismatrixfree_ == true && islinearPrec_ == false) |
| 940 |
{ |
| 941 |
isinit_ = ML_Nox_compute_Matrixfree_Nonlinearpreconditioner(x); |
| 942 |
if (isinit_ == true) |
| 943 |
return(true); |
| 944 |
else |
| 945 |
return(false); |
| 946 |
} |
| 947 |
|
| 948 |
cout << "**ERR**: ML_Nox_Preconditioner::compPrec:\n"; |
| 949 |
cout << "**ERR**: something wrong with the flags ismatrixfree_ and islinearPrec_\n"; |
| 950 |
cout << "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 951 |
isinit_ = false; |
| 952 |
return(false); |
| 953 |
} |
| 954 |
|
| 955 |
/*----------------------------------------------------------------------* |
| 956 |
| compute the linear multilevel preconditioner (private) m.gee 11/04| |
| 957 |
| with a given Jacobian | |
| 958 |
*----------------------------------------------------------------------*/ |
| 959 |
bool ML_NOX::ML_Nox_Preconditioner::ML_Nox_compute_Jacobian_Linearpreconditioner( |
| 960 |
const Epetra_Vector& x) |
| 961 |
{ |
| 962 |
// choose some smoothers |
| 963 |
Set_Smoothers(); |
| 964 |
|
| 965 |
// build the ML_MultilevelOperator |
| 966 |
//const Epetra_Map& map = interface_.getMap(); |
| 967 |
if (ml_map_) delete ml_map_; |
| 968 |
ml_map_ = new Epetra_Map(interface_.getMap()); |
| 969 |
if (ml_linPrec_) delete ml_linPrec_; |
| 970 |
ml_linPrec_ = new ML_Epetra::MultiLevelOperator(ml_,comm_,*ml_map_,*ml_map_); |
| 971 |
|
| 972 |
|
| 973 |
#if 0 // test the MultiLevelOperator and exit |
| 974 |
{ |
| 975 |
Epetra_Vector xthis(x); |
| 976 |
cout << "Test of preconditioner " << endl; |
| 977 |
Epetra_Vector *out = new Epetra_Vector(xthis); |
| 978 |
out->PutScalar(0.0); |
| 979 |
cout << "Input\n"; |
| 980 |
xthis.PutScalar(1.0); |
| 981 |
interface_.getJacobian()->Multiply(false,xthis,*out); |
| 982 |
double norm; |
| 983 |
out->Norm1(&norm); |
| 984 |
cout << "Norm = " << norm << endl; |
| 985 |
xthis.PutScalar(3.0); |
| 986 |
cout << "out between\n"; |
| 987 |
cout << *out; |
| 988 |
ml_linPrec_->ApplyInverse(*out,xthis); |
| 989 |
cout << "Output\n"; |
| 990 |
cout << xthis; |
| 991 |
delete out; out = 0; |
| 992 |
exit(0); |
| 993 |
} |
| 994 |
#endif |
| 995 |
|
| 996 |
|
| 997 |
#if 0 // print out all level's Jacobians |
| 998 |
for (i=0; i<=ml_coarsestlev_; i++) |
| 999 |
{ |
| 1000 |
cout << "Matrix on level " << i << "\n"; |
| 1001 |
Epetra_CrsMatrix* tmpMat = 0; |
| 1002 |
int maxnnz = 0; |
| 1003 |
double cputime = 0.0; |
| 1004 |
ML_Operator2EpetraCrsMatrix(&(ml_->Amat[i]), tmpMat, maxnnz, false, cputime); |
| 1005 |
cout << *tmpMat; |
| 1006 |
delete tmpMat; |
| 1007 |
tmpMat = 0; |
| 1008 |
} |
| 1009 |
exit(0); |
| 1010 |
#endif |
| 1011 |
|
| 1012 |
return (true); |
| 1013 |
} |
| 1014 |
|
| 1015 |
/*----------------------------------------------------------------------* |
| 1016 |
| compute the linear multilevel preconditioner (private) m.gee 11/04| |
| 1017 |
| without Jacobian | |
| 1018 |
*----------------------------------------------------------------------*/ |
| 1019 |
bool ML_NOX::ML_Nox_Preconditioner::ML_Nox_compute_Matrixfree_Linearpreconditioner( |
| 1020 |
const Epetra_Vector& xfine) |
| 1021 |
{ |
| 1022 |
int i; |
| 1023 |
|
| 1024 |
// extract the Prolongators from the ml-hierarchy and create Epetra_CrsMatrices from them |
| 1025 |
// NOTE: as we are doing the linear preconditioner here, we keep the P's in the hierarchy |
| 1026 |
// for further use in the MG-cycle |
| 1027 |
Epetra_CrsMatrix** P = new Epetra_CrsMatrix*[ml_nlevel_]; |
| 1028 |
for (i=0; i<ml_nlevel_; i++) |
| 1029 |
P[i] = 0; |
| 1030 |
for (i=1; i<ml_nlevel_; i++) // there is no Pmat on level 0 |
| 1031 |
{ |
| 1032 |
double t1 = GetClock(); |
| 1033 |
int maxnnz = 0; |
| 1034 |
double cputime = 0.0; |
| 1035 |
ML_Operator2EpetraCrsMatrix(&(ml_->Pmat[i]), P[i], maxnnz, false, cputime); |
| 1036 |
P[i]->OptimizeStorage(); |
| 1037 |
double t2 = GetClock() - t1; |
| 1038 |
if (ml_printlevel_>0 && 0 == comm_.MyPID()) |
| 1039 |
cout << "ML (level " << i << "): extraction of P in " << t2 << " sec\n"; |
| 1040 |
} |
| 1041 |
|
| 1042 |
// construct the vector of coarse level problems |
| 1043 |
// the coarse level problems also create the coarse level interface to the user code |
| 1044 |
if (ml_matfreelevel_) // the matfreelevels already exist, clean them for reuse |
| 1045 |
{ |
| 1046 |
ml_matfreelevel_[0]->destroyP(); |
| 1047 |
for (i=0; i<nmatfreelevel_; i++) |
| 1048 |
ml_matfreelevel_[i]->setP(NULL); |
| 1049 |
} |
| 1050 |
else // create new vector of matfreelevels |
| 1051 |
{ |
| 1052 |
nmatfreelevel_ = ml_nlevel_; |
| 1053 |
ml_matfreelevel_ = new ML_NOX::ML_Nox_MatrixfreeLevel*[nmatfreelevel_]; |
| 1054 |
for (i=0; i<nmatfreelevel_; i++) |
| 1055 |
ml_matfreelevel_[i] = 0; |
| 1056 |
} |
| 1057 |
|
| 1058 |
// loop levels and create the Operators and coarse interfaces |
| 1059 |
for (i=0; i<ml_nlevel_; i++) |
| 1060 |
{ |
| 1061 |
// choose a blocksize |
| 1062 |
int bsize; |
| 1063 |
if (i==0) bsize = ml_numPDE_; |
| 1064 |
else bsize = ml_dim_nullsp_; |
| 1065 |
|
| 1066 |
if (comm_.MyPID()==0 && ml_printlevel_ > 5 ) |
| 1067 |
cout << "\nmatrixfreeML (level " << i << "): Entering FD-coarselevel (re)construction\n"; |
| 1068 |
fflush(stdout); |
| 1069 |
|
| 1070 |
bool isJacobismoother=false; |
| 1071 |
if (i==0 && ml_fsmoothertype_ == "Jacobi") |
| 1072 |
isJacobismoother=true; |
| 1073 |
else if (i<ml_coarsestlev_ && ml_smoothertype_ == "Jacobi") |
| 1074 |
isJacobismoother=true; |
| 1075 |
else |
| 1076 |
isJacobismoother=false; |
| 1077 |
if (i==ml_coarsestlev_ && ml_coarsesolve_ == "Jacobi") |
| 1078 |
isJacobismoother=true; |
| 1079 |
|
| 1080 |
if (!(ml_matfreelevel_[i])) // create a new level |
| 1081 |
ml_matfreelevel_[i] = new ML_NOX::ML_Nox_MatrixfreeLevel(i,ml_nlevel_,ml_printlevel_,ml_, |
| 1082 |
ag_,P,interface_,comm_,xfine, |
| 1083 |
fd_alpha_,fd_beta_,fd_centered_, |
| 1084 |
isJacobismoother,bsize); |
| 1085 |
else // redo an existing level |
| 1086 |
ml_matfreelevel_[i]->recreateLevel(i,ml_nlevel_,ml_printlevel_,ml_, |
| 1087 |
ag_,P,interface_,comm_,xfine); |
| 1088 |
// get this level's operator |
| 1089 |
Epetra_CrsMatrix* tmpMat = ml_matfreelevel_[i]->getunderlyingMatrix(); |
| 1090 |
|
| 1091 |
if (!tmpMat) |
| 1092 |
{ |
| 1093 |
cout << "**ERR**: ML_Nox_Preconditioner::ML_Nox_compute_Matrixfree_Linearpreconditioner:\n" |
| 1094 |
<< "**ERR**: ML_Epetra::ML_Nox_MatrixfreeLevel::getunderlyingMatrix() on level " << i << "\n" |
| 1095 |
<< "**ERR**: returned NULL-ptr\n" |
| 1096 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1097 |
} |
| 1098 |
|
| 1099 |
// check the matrix for zero rows and fix the diagonal |
| 1100 |
if (fixdiagonal_) |
| 1101 |
fix_MainDiagonal(&tmpMat,i); |
| 1102 |
|
| 1103 |
// create a ML_Operator |
| 1104 |
// NOTE: |
| 1105 |
// As I understand this will wrap the Epetra_CrsMatrix from ML_Nox_MatrixfreeLevel, |
| 1106 |
// so we must not destroy the ML_Nox_MatrixfreeLevel class unless the ML-hierarchy |
| 1107 |
// is no longer needed |
| 1108 |
ML_Operator* tmpOperator = ML_Operator_Create(ml_->comm); |
| 1109 |
ML_Operator_WrapEpetraMatrix(tmpMat,tmpOperator); |
| 1110 |
// move it to the hierarchy, this destroys tmpOperator |
| 1111 |
ML_Operator_Move2HierarchyAndDestroy(&tmpOperator,&(ml_->Amat[i])); |
| 1112 |
} |
| 1113 |
|
| 1114 |
// the hierarchy is done, so set smoothers |
| 1115 |
|
| 1116 |
// choose some smoothers |
| 1117 |
Set_Smoothers(); |
| 1118 |
|
| 1119 |
// build the ML_MultilevelOperator |
| 1120 |
if (ml_linPrec_) |
| 1121 |
delete ml_linPrec_; |
| 1122 |
const Epetra_Map& map = interface_.getMap(); |
| 1123 |
ml_linPrec_ = new ML_Epetra::MultiLevelOperator(ml_,comm_,map,map); |
| 1124 |
|
| 1125 |
return(true); |
| 1126 |
} |
| 1127 |
|
| 1128 |
/*----------------------------------------------------------------------* |
| 1129 |
| compute Jacobian on fine level (private) m.gee 05/05| |
| 1130 |
| this version amalgamates nodal blocks in the graph first, colors | |
| 1131 |
| the amalgamated graph and then expands the colors back to the | |
| 1132 |
| full size. | |
| 1133 |
*----------------------------------------------------------------------*/ |
| 1134 |
Epetra_CrsMatrix* ML_NOX::ML_Nox_Preconditioner::ML_Nox_computeFineLevelJacobian( |
| 1135 |
const Epetra_Vector& x) |
| 1136 |
{ |
| 1137 |
// make a copy of the graph |
| 1138 |
Epetra_CrsGraph* graph = const_cast<Epetra_CrsGraph*>(interface_.getGraph()); |
| 1139 |
Epetra_CrsGraph* cgraph = const_cast<Epetra_CrsGraph*>(interface_.getModifiedGraph()); |
| 1140 |
|
| 1141 |
// the block size of the graph here |
| 1142 |
int bsize = ml_numPDE_; |
| 1143 |
|
| 1144 |
double t0 = GetClock(); |
| 1145 |
|
| 1146 |
// construct a collapsed coloring |
| 1147 |
// create coloring of the nodal graph |
| 1148 |
if (ml_printlevel_>0 && comm_.MyPID()==0) |
| 1149 |
{ |
| 1150 |
cout << "ML (level 0): Entering Coloring on level 0\n"; |
| 1151 |
fflush(stdout); |
| 1152 |
} |
| 1153 |
|
| 1154 |
#if 1 |
| 1155 |
Epetra_MapColoring* colorMap |
| 1156 |
= ML_NOX::ML_Nox_collapsedcoloring(cgraph,bsize,false,ml_printlevel_); |
| 1157 |
if (!colorMap) |
| 1158 |
colorMap = ML_NOX::ML_Nox_standardcoloring(cgraph,false); |
| 1159 |
#else |
| 1160 |
Epetra_MapColoring* colorMap = ML_NOX::ML_Nox_standardcoloring(cgraph,false); |
| 1161 |
#endif |
| 1162 |
|
| 1163 |
EpetraExt::CrsGraph_MapColoringIndex* colorMapIndex = |
| 1164 |
new EpetraExt::CrsGraph_MapColoringIndex(*colorMap); |
| 1165 |
vector<Epetra_IntVector>* colorcolumns = &(*colorMapIndex)(*graph); |
| 1166 |
|
| 1167 |
double t1 = GetClock(); |
| 1168 |
if (ml_printlevel_>0 && comm_.MyPID()==0) |
| 1169 |
{ |
| 1170 |
cout << "ML (level 0): Proc " << comm_.MyPID() <<" Coloring time is " << (t1-t0) << " sec\n"; |
| 1171 |
fflush(stdout); |
| 1172 |
} |
| 1173 |
|
| 1174 |
// construct the FiniteDifferenceColoring-Matrix |
| 1175 |
if (ml_printlevel_>0 && comm_.MyPID()==0) |
| 1176 |
{ |
| 1177 |
cout << "ML (level 0): Entering Construction FD-Operator on level 0\n"; |
| 1178 |
fflush(stdout); |
| 1179 |
} |
| 1180 |
|
| 1181 |
t0 = GetClock(); |
| 1182 |
int ncalls = interface_.getnumcallscomputeF(); |
| 1183 |
interface_.setnumcallscomputeF(0); |
| 1184 |
|
| 1185 |
#if 1 |
| 1186 |
NOX::EpetraNew::FiniteDifferenceColoring* FD = |
| 1187 |
new NOX::EpetraNew::FiniteDifferenceColoring(interface_,x,*graph, |
| 1188 |
*colorMap,*colorcolumns, |
| 1189 |
true,false, |
| 1190 |
fd_beta_,fd_alpha_); |
| 1191 |
#else |
| 1192 |
NOX::EpetraNew::FiniteDifference* FD = |
| 1193 |
new NOX::EpetraNew::FiniteDifference(interface_, |
| 1194 |
x, |
| 1195 |
*graph, |
| 1196 |
fd_beta_,fd_alpha_); |
| 1197 |
#endif |
| 1198 |
|
| 1199 |
if (fd_centered_) |
| 1200 |
FD->setDifferenceMethod(NOX::EpetraNew::FiniteDifferenceColoring::Centered); |
| 1201 |
else |
| 1202 |
FD->setDifferenceMethod(NOX::EpetraNew::FiniteDifferenceColoring::Forward); |
| 1203 |
|
| 1204 |
bool err = FD->computeJacobian(x); |
| 1205 |
if (err==false) |
| 1206 |
{ |
| 1207 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::ML_Nox_computeFineLevelJacobian:\n" |
| 1208 |
<< "**ERR**: NOX::Epetra::FiniteDifferenceColoring returned an error on level 0" |
| 1209 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1210 |
} |
| 1211 |
|
| 1212 |
t1 = GetClock(); |
| 1213 |
if (ml_printlevel_>0 && comm_.MyPID()==0) |
| 1214 |
{ |
| 1215 |
cout << "ML (level 0): colored Finite Differencing time :" << (t1-t0) << " sec\n"; |
| 1216 |
cout << "ML (level 0): colored Finite Differencing number of calls to computeF : " |
| 1217 |
<< interface_.getnumcallscomputeF() << endl; |
| 1218 |
fflush(stdout); |
| 1219 |
} |
| 1220 |
|
| 1221 |
interface_.setnumcallscomputeF(ncalls); |
| 1222 |
|
| 1223 |
Epetra_CrsMatrix* B = dynamic_cast<Epetra_CrsMatrix*>(&(FD->getUnderlyingMatrix())); |
| 1224 |
Epetra_CrsMatrix* A = ML_NOX::StripZeros(*B,1.0e-11); |
| 1225 |
//Epetra_CrsMatrix* A = new Epetra_CrsMatrix(*B); |
| 1226 |
//A->FillComplete(); |
| 1227 |
//A->OptimizeStorage(); |
| 1228 |
|
| 1229 |
// tidy up |
| 1230 |
delete FD; FD = 0; |
| 1231 |
delete colorMap; colorMap = 0; |
| 1232 |
delete colorMapIndex; colorMapIndex = 0; |
| 1233 |
colorcolumns->clear(); |
| 1234 |
delete colorcolumns; colorcolumns = 0; |
| 1235 |
return A; |
| 1236 |
} |
| 1237 |
|
| 1238 |
/*----------------------------------------------------------------------* |
| 1239 |
| fix zero main diagonal/row (private) m.gee 05/05| |
| 1240 |
*----------------------------------------------------------------------*/ |
| 1241 |
bool ML_NOX::ML_Nox_Preconditioner::fix_MainDiagonal(Epetra_CrsMatrix** A, int level) const |
| 1242 |
{ |
| 1243 |
if (!(*A)) |
| 1244 |
{ |
| 1245 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::fix_MainDiagonal: " |
| 1246 |
<< "**ERR**: A is NULL\n" |
| 1247 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1248 |
} |
| 1249 |
if (!(*A)->Filled()) (*A)->FillComplete(); |
| 1250 |
|
| 1251 |
Epetra_Vector diag((*A)->RowMap(),false); |
| 1252 |
int err = (*A)->ExtractDiagonalCopy(diag); |
| 1253 |
if (err) |
| 1254 |
{ |
| 1255 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::fix_MainDiagonal:\n" |
| 1256 |
<< "**ERR**: A->ExtractDiagonalCopy returned " << err << endl |
| 1257 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1258 |
} |
| 1259 |
|
| 1260 |
double average=0.0; |
| 1261 |
for (int i=0; i<diag.MyLength(); i++) average += diag[i]; |
| 1262 |
average /= diag.MyLength(); |
| 1263 |
|
| 1264 |
for (int i=0; i<diag.MyLength(); i++) |
| 1265 |
{ |
| 1266 |
// fix zero entries to be real dirichlet boundary constraints because they come from mesh tying |
| 1267 |
if (abs(diag[i])<1.0e-10) |
| 1268 |
{ |
| 1269 |
if (ml_printlevel_>7) |
| 1270 |
printf("found zero diagonal entry %20.12e in row %d, fixing to be %e\n",diag[i],i,average); |
| 1271 |
//check whether there are nonzero off-diagonal entries in that row |
| 1272 |
int numentries; |
| 1273 |
double* values; |
| 1274 |
err = (*A)->ExtractMyRowView(i,numentries,values); |
| 1275 |
if (err) |
| 1276 |
{ |
| 1277 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::fix_MainDiagonal:\n" |
| 1278 |
<< "**ERR**: A->ExtractMyRowView returned " << err << endl |
| 1279 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1280 |
} |
| 1281 |
double sum=0.0; |
| 1282 |
for (int j=0; j<numentries; j++) |
| 1283 |
sum += abs(values[j]); |
| 1284 |
|
| 1285 |
if (sum>1.0e-9) |
| 1286 |
{ |
| 1287 |
if (ml_printlevel_>9 && comm_.MyPID()==0) |
| 1288 |
cout << " do nothing - row is not zero\n"; |
| 1289 |
continue; |
| 1290 |
} |
| 1291 |
|
| 1292 |
//double small = 10.0; |
| 1293 |
err = (*A)->ReplaceMyValues(i,1,&average,&i); |
| 1294 |
if (err) |
| 1295 |
{ |
| 1296 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::fix_MainDiagonal:\n" |
| 1297 |
<< "**ERR**: A->ReplaceMyValues returned " << err << endl |
| 1298 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1299 |
} |
| 1300 |
} |
| 1301 |
// fix small values to be resonably sized because they come from frictionless contact |
| 1302 |
else if (abs(diag[i])<1.0) |
| 1303 |
{ |
| 1304 |
double small=10.0; |
| 1305 |
if (abs(diag[i])>small) small = abs(diag[i]); |
| 1306 |
if (ml_printlevel_>7) |
| 1307 |
printf("found tiny diagonal value %20.12e in row %d, fixing to be %e\n",diag[i],i,small); |
| 1308 |
|
| 1309 |
err = (*A)->ReplaceMyValues(i,1,&small,&i); |
| 1310 |
if (err) |
| 1311 |
{ |
| 1312 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::fix_MainDiagonal:\n" |
| 1313 |
<< "**ERR**: A->ReplaceMyValues returned " << err << endl |
| 1314 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1315 |
} |
| 1316 |
} |
| 1317 |
if (diag[i]<0.0) |
| 1318 |
{ |
| 1319 |
cout << "ML: ***WRN*** Found negative main diag entry! Fixing...\n"; fflush(stdout); |
| 1320 |
double small=10.0; |
| 1321 |
err = (*A)->ReplaceMyValues(i,1,&small,&i); |
| 1322 |
if (err) |
| 1323 |
{ |
| 1324 |
cout << "**ERR**: ML_NOX::ML_Nox_Preconditioner::fix_MainDiagonal:\n" |
| 1325 |
<< "**ERR**: A->ReplaceMyValues returned " << err << endl |
| 1326 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1327 |
} |
| 1328 |
} |
| 1329 |
} |
| 1330 |
|
| 1331 |
return true; |
| 1332 |
} |
| 1333 |
|
| 1334 |
/*----------------------------------------------------------------------* |
| 1335 |
| test the nullspace and make printout (private) m.gee 05/05| |
| 1336 |
*----------------------------------------------------------------------*/ |
| 1337 |
bool ML_NOX::ML_Nox_Preconditioner::test_nullspace(int dimns, double* nullsp, |
| 1338 |
Epetra_CrsMatrix* Jac) const |
| 1339 |
{ |
| 1340 |
if (!Jac || !nullsp) return false; |
| 1341 |
|
| 1342 |
Epetra_Vector test(Jac->OperatorRangeMap(),true); |
| 1343 |
Epetra_Vector out(Jac->OperatorRangeMap(),true); |
| 1344 |
|
| 1345 |
for (int i=0; i<dimns; ++i) |
| 1346 |
{ |
| 1347 |
for (int j=0; j<test.MyLength(); ++j) |
| 1348 |
test.ReplaceMyValue(j,0,nullsp[i*test.MyLength()+j]); |
| 1349 |
|
| 1350 |
int err = Jac->Multiply(false,test,out); |
| 1351 |
if (err) cout << "**ERR** There was an error in Multiply()\n"; |
| 1352 |
|
| 1353 |
double norm; |
| 1354 |
out.Norm2(&norm); |
| 1355 |
cout << "*******Nullspace Vector " << i << ": Norm2 " << norm << endl; |
| 1356 |
//cout << out; |
| 1357 |
} |
| 1358 |
|
| 1359 |
exit(0); |
| 1360 |
return true; |
| 1361 |
} |
| 1362 |
|
| 1363 |
/*----------------------------------------------------------------------* |
| 1364 |
| apply inverse of operator (public) m.gee 11/04| |
| 1365 |
*----------------------------------------------------------------------*/ |
| 1366 |
int ML_NOX::ML_Nox_Preconditioner::ApplyInverse( |
| 1367 |
const Epetra_MultiVector& X, |
| 1368 |
Epetra_MultiVector& Y) const |
| 1369 |
{ |
| 1370 |
if (isinit_==false) |
| 1371 |
{ |
| 1372 |
cout << "**ERR**: ML_Nox_Preconditioner::ApplyInverse:\n"; |
| 1373 |
cout << "**ERR**: tried to call ApplyInverse with isinit_ == false !\n"; |
| 1374 |
cout << "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; throw -1; |
| 1375 |
} |
| 1376 |
|
| 1377 |
double t0 = GetClock(); |
| 1378 |
int ncalls0 = interface_.getnumcallscomputeF(); |
| 1379 |
|
| 1380 |
int err = 0; |
| 1381 |
if (islinearPrec_ == true) |
| 1382 |
err = ML_Nox_ApplyInverse_Linear(X,Y); |
| 1383 |
|
| 1384 |
else if (islinearPrec_ == false) |
| 1385 |
err = ML_Nox_ApplyInverse_NonLinear(X,Y); |
| 1386 |
|
| 1387 |
// call the application to enforce constraints on the gradient |
| 1388 |
Epetra_Vector epetragradient(View,Y,0); |
| 1389 |
interface_.ApplyAllConstraints(epetragradient,0); |
| 1390 |
int ncalls1 = interface_.getnumcallscomputeF(); |
| 1391 |
|
| 1392 |
double t1 = GetClock(); |
| 1393 |
|
| 1394 |
if (comm_.MyPID()==0 && ml_printlevel_ > 7 ) |
| 1395 |
cout << "ML (level 0): Preconditioner time " << (t1-t0) |
| 1396 |
<< " sec, # evaluateF total/this " |
| 1397 |
<< ncalls1 << "/" << (ncalls1-ncalls0) << endl; |
| 1398 |
|
| 1399 |
if (!err) return (0); |
| 1400 |
else return (-1); |
| 1401 |
|
| 1402 |
cout << "**ERR**: ML_Nox_Preconditioner::ApplyInverse:\n"; |
| 1403 |
cout << "**ERR**: something wrong with the flag islinearPrec_\n"; |
| 1404 |
cout << "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; |
| 1405 |
return(-1); |
| 1406 |
} |
| 1407 |
|
| 1408 |
/*----------------------------------------------------------------------* |
| 1409 |
| apply preconditioner (private) m.gee 11/04| |
| 1410 |
| linear, with Jacobian supplied | |
| 1411 |
*----------------------------------------------------------------------*/ |
| 1412 |
int ML_NOX::ML_Nox_Preconditioner::ML_Nox_ApplyInverse_Linear( |
| 1413 |
const Epetra_MultiVector& X, |
| 1414 |
Epetra_MultiVector& Y) const |
| 1415 |
{ |
| 1416 |
int err; |
| 1417 |
if (ml_linPrec_==NULL) |
| 1418 |
{ |
| 1419 |
cout << "**ERR**: ML_Nox_Preconditioner::ML_Nox_ApplyInverse_Linear:\n"; |
| 1420 |
cout << "**ERR**: ptr to ML_Epetra::MultiLevelOperator is NULL\n"; |
| 1421 |
cout << "**ERR**: file/line: " << __FILE__ << "(" << __LINE__ << ")\n"; throw -1; |
| 1422 |
} |
| 1423 |
|
| 1424 |
// apply ML |
| 1425 |
err = ml_linPrec_->ApplyInverse(X,Y); |
| 1426 |
return(err); |
| 1427 |
} |
| 1428 |
|
| 1429 |
/*----------------------------------------------------------------------* |
| 1430 |
| use transpose (public) m.gee 11/04| |
| 1431 |
*----------------------------------------------------------------------*/ |
| 1432 |
int ML_NOX::ML_Nox_Preconditioner::SetUseTranspose(bool UseTranspose) |
| 1433 |
{ |
| 1434 |
if (UseTranspose==true) usetranspose_=true; |
| 1435 |
else usetranspose_=false; |
| 1436 |
return(-1); // the implementation does not support use of transpose |
| 1437 |
} |
| 1438 |
|
| 1439 |
|
| 1440 |
/*----------------------------------------------------------------------* |
| 1441 |
| set smoothers to hierarchy m.gee 04/05| |
| 1442 |
*----------------------------------------------------------------------*/ |
| 1443 |
bool ML_NOX::ML_Nox_Preconditioner::Set_Smoothers() |
| 1444 |
{ |
| 1445 |
// choose some smoothers on level ==0 |
| 1446 |
if (ml_fsmoothertype_ == "SGS") |
| 1447 |
ML_Gen_Smoother_SymGaussSeidel(ml_,0,ML_BOTH,nsmooth_fine_,0.2); |
| 1448 |
else if (ml_fsmoothertype_ == "Jacobi") |
| 1449 |
{ |
| 1450 |
ML_Gen_Smoother_Jacobi(ml_,0,ML_PRESMOOTHER, nsmooth_fine_,0.2); |
| 1451 |
ML_Gen_Smoother_Jacobi(ml_,0,ML_POSTSMOOTHER,nsmooth_fine_,0.2); |
| 1452 |
} |
| 1453 |
else if (ml_fsmoothertype_ == "BSGS") |
| 1454 |
{ |
| 1455 |
int nblocks = 0; |
| 1456 |
int* blocks = NULL; |
| 1457 |
int* blockpde = NULL; |
| 1458 |
bool needfree = false; |
| 1459 |
// try to get nodal blocks from the VBMETIS aggregation scheme |
| 1460 |
ML_Aggregate_Get_Vblocks_CoarsenScheme_VBMETIS(ag_,0,ml_N_levels_, |
| 1461 |
&nblocks,&blocks,&blockpde); |
| 1462 |
if (nblocks && blocks) |
| 1463 |
needfree=true; |
| 1464 |
else |
| 1465 |
ML_Gen_Blocks_Aggregates(ag_,0,&nblocks,&blocks); |
| 1466 |
|
| 1467 |
ML_Gen_Smoother_VBlockSymGaussSeidel(ml_,0,ML_BOTH,nsmooth_fine_,1., |
| 1468 |
nblocks,blocks); |
| 1469 |
if (needfree) |
| 1470 |
{ |
| 1471 |
ML_free(blocks); |
| 1472 |
ML_free(blockpde); |
| 1473 |
} |
| 1474 |
} |
| 1475 |
else if (ml_fsmoothertype_ == "Bcheby") |
| 1476 |
{ |
| 1477 |
int nblocks = 0; |
| 1478 |
int* blocks = NULL; |
| 1479 |
int* blockpde = NULL; |
| 1480 |
bool needfree = false; |
| 1481 |
// try to get nodal blocks from the VBMETIS aggregation scheme |
| 1482 |
ML_Aggregate_Get_Vblocks_CoarsenScheme_VBMETIS(ag_,0,ml_N_levels_, |
| 1483 |
&nblocks,&blocks,&blockpde); |
| 1484 |
if (nblocks && blocks) |
| 1485 |
needfree=true; |
| 1486 |
else |
| 1487 |
ML_Gen_Blocks_Aggregates(ag_,0,&nblocks,&blocks); |
| 1488 |
|
| 1489 |
ML_Gen_Smoother_BlockDiagScaledCheby(ml_,0,ML_BOTH,30.,nsmooth_fine_, |
| 1490 |
nblocks,blocks); |
| 1491 |
if (needfree) |
| 1492 |
{ |
| 1493 |
ML_free(blocks); |
| 1494 |
ML_free(blockpde); |
| 1495 |
} |
| 1496 |
} |
| 1497 |
else if ( (ml_fsmoothertype_ == "MLS") || (ml_fsmoothertype_ == "Cheby")) |
| 1498 |
ML_Gen_Smoother_Cheby(ml_,0,ML_BOTH,30.,nsmooth_fine_); |
| 1499 |
else if (ml_fsmoothertype_ == "AmesosKLU") |
| 1500 |
ML_Gen_Smoother_Amesos(ml_,0,ML_AMESOS_KLU,-1,0.0,1); |
| 1501 |
else |
| 1502 |
{ |
| 1503 |
cout << "**ERR**: ML_Nox_Preconditioner::ML_Nox_compute_Jacobian_Linearpreconditioner:\n" |
| 1504 |
<< "**ERR**: smoother " << ml_fsmoothertype_ << " not recognized\n" |
| 1505 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1506 |
} |
| 1507 |
|
| 1508 |
// choose some smoothers on level > 0 |
| 1509 |
for (int i=1; i<ml_coarsestlev_; i++) |
| 1510 |
{ |
| 1511 |
if (ml_smoothertype_ == "SGS") |
| 1512 |
{ |
| 1513 |
ML_Gen_Smoother_SymGaussSeidel(ml_,i,ML_BOTH,nsmooth_,1.); |
| 1514 |
continue; |
| 1515 |
} |
| 1516 |
else if (ml_smoothertype_ == "Jacobi") |
| 1517 |
{ |
| 1518 |
ML_Gen_Smoother_Jacobi(ml_,i,ML_PRESMOOTHER, nsmooth_,.4); |
| 1519 |
ML_Gen_Smoother_Jacobi(ml_,i,ML_POSTSMOOTHER,nsmooth_,.4); |
| 1520 |
continue; |
| 1521 |
} |
| 1522 |
else if (ml_smoothertype_ == "BSGS") |
| 1523 |
{ |
| 1524 |
int nblocks = 0; |
| 1525 |
int* blocks = NULL; |
| 1526 |
int* blockpde = NULL; |
| 1527 |
bool needfree = false; |
| 1528 |
// try to get nodal blocks from the VBMETIS aggregation scheme |
| 1529 |
ML_Aggregate_Get_Vblocks_CoarsenScheme_VBMETIS(ag_,i,ml_N_levels_, |
| 1530 |
&nblocks,&blocks,&blockpde); |
| 1531 |
if (nblocks && blocks) |
| 1532 |
needfree=true; |
| 1533 |
else |
| 1534 |
ML_Gen_Blocks_Aggregates(ag_,i,&nblocks,&blocks); |
| 1535 |
|
| 1536 |
ML_Gen_Smoother_VBlockSymGaussSeidel(ml_,i,ML_BOTH,nsmooth_,1.,nblocks,blocks); |
| 1537 |
if (needfree) |
| 1538 |
{ |
| 1539 |
ML_free(blocks); |
| 1540 |
ML_free(blockpde); |
| 1541 |
} |
| 1542 |
continue; |
| 1543 |
} |
| 1544 |
else if (ml_smoothertype_ == "Bcheby") |
| 1545 |
{ |
| 1546 |
int nblocks = 0; |
| 1547 |
int* blocks = NULL; |
| 1548 |
int* blockpde = NULL; |
| 1549 |
bool needfree = false; |
| 1550 |
// try to get nodal blocks from the VBMETIS aggregation scheme |
| 1551 |
ML_Aggregate_Get_Vblocks_CoarsenScheme_VBMETIS(ag_,i,ml_N_levels_, |
| 1552 |
&nblocks,&blocks,&blockpde); |
| 1553 |
if (nblocks && blocks) |
| 1554 |
needfree=true; |
| 1555 |
else |
| 1556 |
ML_Gen_Blocks_Aggregates(ag_,i,&nblocks,&blocks); |
| 1557 |
|
| 1558 |
ML_Gen_Smoother_BlockDiagScaledCheby(ml_,i,ML_BOTH,30.,nsmooth_, |
| 1559 |
nblocks,blocks); |
| 1560 |
if (needfree) |
| 1561 |
{ |
| 1562 |
ML_free(blocks); |
| 1563 |
ML_free(blockpde); |
| 1564 |
} |
| 1565 |
} |
| 1566 |
else if ((ml_smoothertype_ == "MLS")||(ml_smoothertype_ == "Cheby")) |
| 1567 |
ML_Gen_Smoother_Cheby(ml_,i,ML_BOTH,30.,nsmooth_); |
| 1568 |
else if (ml_smoothertype_ == "AmesosKLU") |
| 1569 |
ML_Gen_Smoother_Amesos(ml_,i,ML_AMESOS_KLU,-1,0.0,1); |
| 1570 |
else |
| 1571 |
{ |
| 1572 |
cout << "**ERR**: ML_Nox_Preconditioner::ML_Nox_compute_Jacobian_Linearpreconditioner:\n" |
| 1573 |
<< "**ERR**: smoother " << ml_smoothertype_ << " not recognized\n" |
| 1574 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1575 |
} |
| 1576 |
} |
| 1577 |
// choose a coarse grid solver |
| 1578 |
if (ml_coarsesolve_ == "AmesosKLU") |
| 1579 |
ML_Gen_Smoother_Amesos(ml_,ml_coarsestlev_,ML_AMESOS_KLU,-1,0.0,1); |
| 1580 |
else if (ml_coarsesolve_ == "SGS") |
| 1581 |
ML_Gen_Smoother_SymGaussSeidel(ml_,ml_coarsestlev_,ML_BOTH,nsmooth_coarse_,1.); |
| 1582 |
else if (ml_coarsesolve_ == "Jacobi") |
| 1583 |
{ |
| 1584 |
ML_Gen_Smoother_Jacobi(ml_,ml_coarsestlev_,ML_PRESMOOTHER, nsmooth_coarse_,.4); |
| 1585 |
ML_Gen_Smoother_Jacobi(ml_,ml_coarsestlev_,ML_POSTSMOOTHER,nsmooth_coarse_,.4); |
| 1586 |
} |
| 1587 |
else if (ml_coarsesolve_ == "BSGS") |
| 1588 |
{ |
| 1589 |
int nblocks = 0; |
| 1590 |
int* blocks = NULL; |
| 1591 |
int* blockpde = NULL; |
| 1592 |
bool needfree = false; |
| 1593 |
// try to get nodal blocks from the VBMETIS aggregation scheme |
| 1594 |
ML_Aggregate_Get_Vblocks_CoarsenScheme_VBMETIS(ag_,ml_coarsestlev_,ml_N_levels_, |
| 1595 |
&nblocks,&blocks,&blockpde); |
| 1596 |
if (nblocks && blocks) |
| 1597 |
needfree=true; |
| 1598 |
else |
| 1599 |
ML_Gen_Blocks_Aggregates(ag_,ml_coarsestlev_,&nblocks,&blocks); |
| 1600 |
|
| 1601 |
ML_Gen_Smoother_VBlockSymGaussSeidel(ml_,ml_coarsestlev_,ML_BOTH, |
| 1602 |
nsmooth_coarse_, |
| 1603 |
1.,nblocks,blocks); |
| 1604 |
if (needfree) |
| 1605 |
{ |
| 1606 |
ML_free(blocks); |
| 1607 |
ML_free(blockpde); |
| 1608 |
} |
| 1609 |
} |
| 1610 |
else if (ml_coarsesolve_ == "Bcheby") |
| 1611 |
{ |
| 1612 |
int nblocks = 0; |
| 1613 |
int* blocks = NULL; |
| 1614 |
int* blockpde = NULL; |
| 1615 |
bool needfree = false; |
| 1616 |
// try to get nodal blocks from the VBMETIS aggregation scheme |
| 1617 |
ML_Aggregate_Get_Vblocks_CoarsenScheme_VBMETIS(ag_,ml_coarsestlev_,ml_N_levels_, |
| 1618 |
&nblocks,&blocks,&blockpde); |
| 1619 |
if (nblocks && blocks) |
| 1620 |
needfree=true; |
| 1621 |
else |
| 1622 |
ML_Gen_Blocks_Aggregates(ag_,ml_coarsestlev_,&nblocks,&blocks); |
| 1623 |
|
| 1624 |
ML_Gen_Smoother_BlockDiagScaledCheby(ml_,ml_coarsestlev_,ML_BOTH,30., |
| 1625 |
nsmooth_coarse_,nblocks,blocks); |
| 1626 |
if (needfree) |
| 1627 |
{ |
| 1628 |
ML_free(blocks); |
| 1629 |
ML_free(blockpde); |
| 1630 |
} |
| 1631 |
} |
| 1632 |
else if ( (ml_smoothertype_ == "MLS") || (ml_smoothertype_ == "Cheby")) |
| 1633 |
ML_Gen_Smoother_Cheby(ml_,ml_coarsestlev_,ML_BOTH,30.,nsmooth_coarse_); |
| 1634 |
else |
| 1635 |
{ |
| 1636 |
cout << "**ERR**: ML_Nox_Preconditioner::ML_Nox_compute_Jacobian_Linearpreconditioner:\n" |
| 1637 |
<< "**ERR**: smoother " << ml_coarsesolve_ << " not recognized\n" |
| 1638 |
<< "**ERR**: file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw -1; |
| 1639 |
} |
| 1640 |
return true; |
| 1641 |
} |
| 1642 |
|
| 1643 |
/*----------------------------------------------------------------------* |
| 1644 |
| run adaptive setup m.gee 09/05| |
| 1645 |
*----------------------------------------------------------------------*/ |
| 1646 |
bool ML_NOX::ML_Nox_Preconditioner::Ml_Nox_adaptivesetup(double** oldns, |
| 1647 |
Epetra_CrsMatrix* Jac, |
| 1648 |
int oldnumpde, |
| 1649 |
int olddimns) |
| 1650 |
{ |
| 1651 |
#ifdef HAVE_ML_MLAPI |
| 1652 |
|
| 1653 |
// init the mlapi |
| 1654 |
MLAPI::Init(); |
| 1655 |
MLAPI::Space FineSpace(Jac->RowMap()); |
| 1656 |
|
| 1657 |
// fine grid operator |
| 1658 |
MLAPI::Operator A(FineSpace,FineSpace,Jac,false); |
| 1659 |
|
| 1660 |
// create the cycle options |
| 1661 |
Teuchos::ParameterList List; |
| 1662 |
List.set("PDE equations", oldnumpde); |
| 1663 |
List.set("use default null space", false); |
| 1664 |
List.set("smoother: type", "symmetric Gauss-Seidel"); |
| 1665 |
List.set("smoother: sweeps", 1); |
| 1666 |
List.set("smoother: damping factor", 1.0); |
| 1667 |
List.set("coarse: type", "Amesos-KLU"); |
| 1668 |
List.set("coarse: max size", ml_maxcoarsesize_); |
| 1669 |
List.set("max levels", ml_nlevel_); |
| 1670 |
List.set("adapt: max reduction", 0.05); |
| 1671 |
List.set("adapt: iters fine", 30); // 35 |
| 1672 |
List.set("adapt: iters coarse", 25); // 20 |
| 1673 |
List.set("aggregation: damping", 1.33); |
| 1674 |
List.set("aggregation: type", "Uncoupled"); // or "METIS", not "VBMETIS" |
| 1675 |
|
| 1676 |
|
| 1677 |
// create the adaptive class |
| 1678 |
MLAPI::MultiLevelAdaptiveSA Prec(A,List,oldnumpde,ml_N_levels_); |
| 1679 |
|
| 1680 |
// if there's no nullspace vector, create the default one |
| 1681 |
if (!(*oldns)) |
| 1682 |
{ |
| 1683 |
if (olddimns<oldnumpde) olddimns = oldnumpde; |
| 1684 |
int nmyrows = Jac->NumMyRows(); |
| 1685 |
(*oldns) = new double[olddimns*nmyrows]; |
| 1686 |
for (int v=0; v<olddimns; ++v) |
| 1687 |
{ |
| 1688 |
for (int i=0; i<nmyrows; ++i) (*oldns)[i] = 0.0; |
| 1689 |
int i=v; |
| 1690 |
for (; i<nmyrows; ) |
| 1691 |
{ |
| 1692 |
(*oldns)[i] = 1.0; |
| 1693 |
i += olddimns; |
| 1694 |
} |
| 1695 |
} |
| 1696 |
} |
| 1697 |
|
| 1698 |
// set the input nullspace |
| 1699 |
MLAPI::MultiVector NSfine(FineSpace,olddimns); |
| 1700 |
for (int v=0; v<olddimns; ++v) |
| 1701 |
for (int i=0; i<NSfine.GetMyLength(); ++i) |
| 1702 |
NSfine(i,v) = (*oldns)[v*(NSfine.GetMyLength())+i]; |
| 1703 |
Prec.SetNullSpace(NSfine); |
| 1704 |
|
| 1705 |
// set input numpde |
| 1706 |
Prec.SetInputNumPDEEqns(oldnumpde); |
| 1707 |
|
| 1708 |
// run adatpive setup |
| 1709 |
Prec.AdaptCompute(true,adaptns_); |
| 1710 |
|
| 1711 |
// get the new nullspace |
| 1712 |
MLAPI::MultiVector NSnew = Prec.GetNullSpace(); |
| 1713 |
int newdimns = NSnew.GetNumVectors(); |
| 1714 |
|
| 1715 |
// delete the old one and copy the new one |
| 1716 |
delete [] (*oldns); |
| 1717 |
(*oldns) = new double[newdimns*NSnew.GetMyLength()]; |
| 1718 |
|
| 1719 |
for (int v=0; v<newdimns; ++v) |
| 1720 |
for (int i=0; i<NSnew.GetMyLength(); ++i) |
| 1721 |
(*oldns)[v*(NSnew.GetMyLength())+i] = NSnew(i,v); |
| 1722 |
|
| 1723 |
#if 1 |
| 1724 |
// scale new candidates to reasonible size |
| 1725 |
for (int v=ml_dim_nullsp_; v<newdimns; ++v) |
| 1726 |
{ |
| 1727 |
double length = 0.; |
| 1728 |
for (int i=0; i<NSnew.GetMyLength(); ++i) |
| 1729 |
length += (*oldns)[v*(NSnew.GetMyLength())+i]*(*oldns)[v*(NSnew.GetMyLength())+i]; |
| 1730 |
length = sqrt(length); |
| 1731 |
length /= 10.; |
| 1732 |
for (int i=0; i<NSnew.GetMyLength(); ++i) |
| 1733 |
(*oldns)[v*(NSnew.GetMyLength())+i] /= length; |
| 1734 |
} |
| 1735 |
#endif |
| 1736 |
|
| 1737 |
// change the dimension of the nullspace |
| 1738 |
ml_dim_nullsp_ = newdimns; |
| 1739 |
|
| 1740 |
#if 0 |
| 1741 |
// printout the nullspace vectors to gid |
| 1742 |
const Epetra_Vector* sol = interface_.getSolution(); |
| 1743 |
double* solptr; |
| 1744 |
sol->ExtractView(&solptr); |
| 1745 |
for (int v=0; v<newdimns; ++v) |
| 1746 |
{ |
| 1747 |
for (int i=0; i<sol->MyLength(); ++i) |
| 1748 |
solptr[i] = (*oldns)[v*sol->MyLength() + i]; |
| 1749 |
Comm().Barrier(); |
| 1750 |
interface_.PrintSol(v); |
| 1751 |
} |
| 1752 |
cout << "Nullspace was printed to GID\n"; |
| 1753 |
exit(0); |
| 1754 |
#endif |
| 1755 |
|
| 1756 |
#endif |
| 1757 |
return true; |
| 1758 |
} |
| 1759 |
#endif // defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA) |