00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef NOX_EPETRA_LINEARSYSTEMAZTECOO_H
00040 #define NOX_EPETRA_LINEARSYSTEMAZTECOO_H
00041
00042 #include "NOX_Epetra_LinearSystem.H"
00043 #include "NOX_Epetra_Vector.H"
00044 #include "NOX_Utils.H"
00045 #include "NOX_Common.H"
00046 #include "Teuchos_ParameterList.hpp"
00047 #include "Epetra_Time.h"
00048 #ifdef HAVE_NOX_ML_EPETRA
00049 #include "Epetra_Map.h"
00050 #include "ml_epetra_preconditioner.h"
00051 #endif
00052 #include "Teuchos_RCP.hpp"
00053 #include "Teuchos_ParameterList.hpp"
00054
00055
00056 namespace Teuchos {
00057 class ParameterList;
00058 }
00059 namespace NOX {
00060 namespace Epetra {
00061 class Scaling;
00062 namespace Interface {
00063 class Required;
00064 class Jacobian;
00065 class Preconditioner;
00066 }
00067 }
00068 }
00069 class Epetra_Vector;
00070 class Epetra_Operator;
00071 class Epetra_RowMatrix;
00072 class AztecOO;
00073 class Ifpack_IlukGraph;
00074 class Ifpack_CrsRiluk;
00075 class Ifpack_Preconditioner;
00076
00077 namespace NOX {
00079 namespace Epetra {
00080
00312 class LinearSystemAztecOO : public virtual NOX::Epetra::LinearSystem {
00313
00314 protected:
00315
00317 enum OperatorType {
00319 EpetraOperator,
00321 EpetraRowMatrix,
00323 EpetraVbrMatrix,
00325 EpetraCrsMatrix
00326 };
00327
00328 public:
00330
00334 LinearSystemAztecOO(
00335 Teuchos::ParameterList& printingParams,
00336 Teuchos::ParameterList& linearSolverParams,
00337 const Teuchos::RCP<NOX::Epetra::Interface::Required>& iReq,
00338 const NOX::Epetra::Vector& cloneVector,
00339 const Teuchos::RCP<NOX::Epetra::Scaling> scalingObject =
00340 Teuchos::null);
00341
00343
00348 LinearSystemAztecOO(
00349 Teuchos::ParameterList& printingParams,
00350 Teuchos::ParameterList& linearSolverParams,
00351 const Teuchos::RCP<NOX::Epetra::Interface::Required>& iReq,
00352 const Teuchos::RCP<NOX::Epetra::Interface::Jacobian>& iJac,
00353 const Teuchos::RCP<Epetra_Operator>& J,
00354 const NOX::Epetra::Vector& cloneVector,
00355 const Teuchos::RCP<NOX::Epetra::Scaling> scalingObject =
00356 Teuchos::null);
00357
00359
00364 LinearSystemAztecOO(
00365 Teuchos::ParameterList& printingParams,
00366 Teuchos::ParameterList& linearSolverParams,
00367 const Teuchos::RCP<NOX::Epetra::Interface::Required>& i,
00368 const Teuchos::RCP<NOX::Epetra::Interface::Preconditioner>& iPrec,
00369 const Teuchos::RCP<Epetra_Operator>& M,
00370 const NOX::Epetra::Vector& cloneVector,
00371 const Teuchos::RCP<NOX::Epetra::Scaling> scalingObject =
00372 Teuchos::null);
00373
00377 LinearSystemAztecOO(
00378 Teuchos::ParameterList& printingParams,
00379 Teuchos::ParameterList& linearSolverParams,
00380 const Teuchos::RCP<NOX::Epetra::Interface::Jacobian>& iJac,
00381 const Teuchos::RCP<Epetra_Operator>& J,
00382 const Teuchos::RCP<NOX::Epetra::Interface::Preconditioner>& iPrec,
00383 const Teuchos::RCP<Epetra_Operator>& M,
00384 const NOX::Epetra::Vector& cloneVector,
00385 const Teuchos::RCP<NOX::Epetra::Scaling> scalingObject =
00386 Teuchos::null);
00387
00389 virtual ~LinearSystemAztecOO();
00390
00391 virtual bool applyJacobian(const NOX::Epetra::Vector& input,
00392 NOX::Epetra::Vector& result) const;
00393
00394 virtual bool applyJacobianTranspose(const NOX::Epetra::Vector& input,
00395 NOX::Epetra::Vector& result) const;
00396
00397 virtual bool applyJacobianInverse(Teuchos::ParameterList& linearSolverParams,
00398 const NOX::Epetra::Vector& input,
00399 NOX::Epetra::Vector& result);
00400
00401 virtual bool applyRightPreconditioning(bool useTranspose,
00402 Teuchos::ParameterList& linearSolverParams,
00403 const NOX::Epetra::Vector& input,
00404 NOX::Epetra::Vector& result) const;
00405
00406 virtual bool createPreconditioner(const NOX::Epetra::Vector& x,
00407 Teuchos::ParameterList& linearSolverParams,
00408 bool recomputeGraph) const;
00409
00416 virtual bool destroyPreconditioner() const;
00417
00425 virtual bool recomputePreconditioner(const NOX::Epetra::Vector& x,
00426 Teuchos::ParameterList& linearSolverParams) const;
00427
00428 virtual PreconditionerReusePolicyType
00429 getPreconditionerPolicy(bool advanceReuseCounter=true);
00430
00432 virtual void reset(Teuchos::ParameterList& linearSolverParams);
00433
00435 virtual Teuchos::RCP<NOX::Epetra::Scaling> getScaling();
00436
00438 void resetScaling(const Teuchos::RCP<NOX::Epetra::Scaling>& s);
00439
00441 virtual bool computeJacobian(const NOX::Epetra::Vector& x);
00442
00444 virtual Teuchos::RCP<const NOX::Epetra::Interface::Jacobian>
00445 getJacobianInterface() const;
00446
00448 virtual Teuchos::RCP<const NOX::Epetra::Interface::Preconditioner>
00449 getPrecInterface() const;
00450
00452 virtual bool isPreconditionerConstructed() const;
00453
00455 virtual bool hasPreconditioner() const;
00456
00458 virtual Teuchos::RCP<const Epetra_Operator> getJacobianOperator() const;
00459
00461 virtual Teuchos::RCP<Epetra_Operator> getJacobianOperator();
00462
00464 virtual Teuchos::RCP<const Epetra_Operator> getPrecOperator() const;
00465
00467
00470 virtual Teuchos::RCP<const Epetra_Operator>
00471 getGeneratedPrecOperator() const;
00472
00474 virtual Teuchos::RCP<Epetra_Operator> getGeneratedPrecOperator();
00475
00476
00477
00479 double getTimeCreatePreconditioner() const;
00480
00482 double getTimeApplyJacobianInverse() const;
00483
00485 virtual void setJacobianOperatorForSolve(const Teuchos::RCP<const Epetra_Operator>& solveJacOp);
00486
00488
00491 virtual void setPrecOperatorForSolve(const Teuchos::RCP<const Epetra_Operator>& solvePrecOp);
00492
00493 protected:
00494
00496 virtual void setAztecOptions(Teuchos::ParameterList& lsParams,
00497 AztecOO& aztec) const;
00498
00500 virtual bool createJacobianOperator(
00501 Teuchos::ParameterList& printParams,
00502 Teuchos::ParameterList& lsParams,
00503 const Teuchos::RCP<NOX::Epetra::Interface::Required>& iReq,
00504 const NOX::Epetra::Vector& cloneVector);
00505
00507 virtual bool createPrecOperator(
00508 Teuchos::ParameterList& printParams,
00509 Teuchos::ParameterList& lsParams,
00510 const Teuchos::RCP<NOX::Epetra::Interface::Required>& iReq,
00511 const NOX::Epetra::Vector& cloneVector);
00512
00514 virtual bool checkPreconditionerValidity();
00515
00523 virtual bool createIfpackPreconditioner(Teuchos::ParameterList& p) const;
00524
00530 virtual bool createNewIfpackPreconditioner(Teuchos::ParameterList& p) const;
00531
00532 #ifdef HAVE_NOX_ML_EPETRA
00533
00537 virtual bool createMLPreconditioner(Teuchos::ParameterList& p) const;
00538 #endif
00539
00548
00549
00551
00552 virtual OperatorType getOperatorType(const Epetra_Operator& o);
00553
00558 virtual void setAztecOOJacobian() const;
00559
00566 virtual void setAztecOOPreconditioner() const;
00567
00568 virtual void throwError(const string& functionName,
00569 const string& errorMsg) const;
00570
00572 virtual void precError(int error_code,
00573 const std::string& nox_function,
00574 const std::string& prec_type,
00575 const std::string& prec_function) const;
00576
00577 protected:
00578
00580 NOX::Utils utils;
00581
00583 Teuchos::RCP<NOX::Epetra::Interface::Jacobian> jacInterfacePtr;
00584
00586 OperatorType jacType;
00587
00589 mutable Teuchos::RCP<Epetra_Operator> jacPtr;
00590
00592 Teuchos::RCP<NOX::Epetra::Interface::Preconditioner> precInterfacePtr;
00593
00595 OperatorType precType;
00596
00598 mutable Teuchos::RCP<Epetra_Operator> precPtr;
00599
00601 enum PreconditionerMatrixSourceType {UseJacobian,
00602 SeparateMatrix};
00603 PreconditionerMatrixSourceType precMatrixSource;
00604
00605 enum PreconditionerType {None_, AztecOO_, Ifpack_, NewIfpack_, ML_, UserDefined_};
00606 PreconditionerType precAlgorithm;
00607
00609 mutable Teuchos::RCP<AztecOO> aztecSolverPtr;
00610
00615 mutable Teuchos::RCP<Ifpack_IlukGraph> ifpackGraphPtr;
00616
00620 mutable Teuchos::RCP<Ifpack_CrsRiluk>
00621 ifpackPreconditionerPtr;
00622
00626 mutable Teuchos::RCP<Ifpack_Preconditioner>
00627 newIfpackPreconditionerPtr;
00628
00629 #ifdef HAVE_NOX_ML_EPETRA
00630
00633 mutable Teuchos::RCP<ML_Epetra::MultiLevelPreconditioner>
00634 MLPreconditionerPtr;
00635 #endif
00636
00638 Teuchos::RCP<NOX::Epetra::Scaling> scaling;
00639
00641 mutable Teuchos::RCP<NOX::Epetra::Vector> tmpVectorPtr;
00642
00643 mutable double conditionNumberEstimate;
00644
00646 mutable bool isPrecConstructed;
00647
00649 bool outputSolveDetails;
00650
00652 bool zeroInitialGuess;
00653
00655 bool manualScaling;
00656
00658 PreconditionerReusePolicyType precReusePolicy;
00659
00661 int precQueryCounter;
00662
00664 int maxAgeOfPrec;
00665
00667 Epetra_Time timer;
00668
00670 mutable double timeCreatePreconditioner;
00671
00673 mutable double timeApplyJacbianInverse;
00674
00676 mutable Teuchos::RCP<Epetra_Operator> solvePrecOpPtr;
00677
00679 bool throwErrorOnPrecFailure;
00680
00681 #ifdef HAVE_NOX_DEBUG
00682 #ifdef HAVE_NOX_EPETRAEXT
00683 mutable int linearSolveCount;
00684 #endif
00685 #endif
00686
00687 };
00688
00689 }
00690 }
00691
00692
00693 #endif