| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// NOX: An Object-Oriented Nonlinear Solver Package |
| 4 |
// |
| 5 |
// Copyright 2002 NTESS and the NOX contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
// Finite Element Problem Class |
| 11 |
/* Provides function (F) and Jacobian evaluations for the following equation |
| 12 |
* via a 1D linear finite element discretization with Epetra objects. |
| 13 |
* |
| 14 |
* d2u |
| 15 |
* --- - k * u**2 = 0 |
| 16 |
* dx2 |
| 17 |
* |
| 18 |
* subject to @ x=0, u=1 |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef TEST_EPETRA_1DFEM_MODELEVALUATOR_EPETRA_H |
| 22 |
#define TEST_EPETRA_1DFEM_MODELEVALUATOR_EPETRA_H |
| 23 |
|
| 24 |
#include "EpetraExt_ModelEvaluator.h" // base class |
| 25 |
#include "NOX_Epetra_Interface_Jacobian.H" // base class |
| 26 |
#include "NOX_Epetra_Interface_Preconditioner.H" // base class |
| 27 |
#include "Teuchos_RCP.hpp" |
| 28 |
|
| 29 |
// Forward Declarations |
| 30 |
class Epetra_Comm; |
| 31 |
class Epetra_Map; |
| 32 |
class Epetra_Vector; |
| 33 |
class Epetra_Import; |
| 34 |
class Epetra_Operator; |
| 35 |
class Epetra_CrsGraph; |
| 36 |
class Epetra_RowMatrix; |
| 37 |
class Epetra_CrsMatrix; |
| 38 |
namespace NOX { |
| 39 |
namespace Parameter { |
| 40 |
class List; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
// Finite Element Problem Class |
| 45 |
class ModelEvaluatorInterface : public EpetraExt::ModelEvaluator { |
| 46 |
|
| 47 |
public: |
| 48 |
|
| 49 |
// Constructor |
| 50 |
ModelEvaluatorInterface(int NumGlobalElements, Epetra_Comm& Comm, |
| 51 |
double xmin = 0.0, double xmax = 1.0 ); |
| 52 |
|
| 53 |
// Destructor |
| 54 |
virtual ~ModelEvaluatorInterface(); |
| 55 |
|
| 56 |
/** \name Overridden from EpetraExt::ModelEvaluator . */ |
| 57 |
//@{ |
| 58 |
|
| 59 |
/** \brief . */ |
| 60 |
Teuchos::RCP<const Epetra_Map> get_x_map() const; |
| 61 |
/** \brief . */ |
| 62 |
Teuchos::RCP<const Epetra_Map> get_f_map() const; |
| 63 |
/** \brief . */ |
| 64 |
Teuchos::RCP<const Epetra_Vector> get_x_init() const; |
| 65 |
/** \brief . */ |
| 66 |
Teuchos::RCP<Epetra_Operator> create_W() const; |
| 67 |
/** \brief . */ |
| 68 |
InArgs createInArgs() const; |
| 69 |
/** \brief . */ |
| 70 |
OutArgs createOutArgs() const; |
| 71 |
/** \brief . */ |
| 72 |
void evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const; |
| 73 |
|
| 74 |
//@} |
| 75 |
|
| 76 |
// Set PDE factor |
| 77 |
bool setPDEfactor(double value) { factor = value; return true; }; |
| 78 |
|
| 79 |
protected: |
| 80 |
|
| 81 |
// Evaluates the function (F) and/or the Jacobian using the solution |
| 82 |
// values in solnVector. |
| 83 |
virtual bool evaluate(const Epetra_Vector *solnVector, |
| 84 |
Epetra_Vector *rhsVector, |
| 85 |
Epetra_RowMatrix *matrix) const; |
| 86 |
|
| 87 |
// Inserts the global column indices into the Graph |
| 88 |
virtual bool createGraph(); |
| 89 |
|
| 90 |
// Set initial condition for solution vector |
| 91 |
virtual bool initializeSoln(); |
| 92 |
|
| 93 |
protected: |
| 94 |
|
| 95 |
enum TargetObjectType {FUNCTION, JACOBIAN}; |
| 96 |
|
| 97 |
int NumGlobalElements; // Total Number of elements |
| 98 |
int NumMyElements; // Number of elements owned by this process |
| 99 |
int MyPID; // Process number |
| 100 |
int NumProc; // Total number of processes |
| 101 |
|
| 102 |
double xmin; |
| 103 |
double xmax; |
| 104 |
double factor; // PDE factor |
| 105 |
|
| 106 |
Epetra_Comm* Comm; |
| 107 |
Teuchos::RCP<Epetra_Map> StandardMap; |
| 108 |
Teuchos::RCP<Epetra_Map> OverlapMap; |
| 109 |
Epetra_Import* Importer; |
| 110 |
Teuchos::RCP<Epetra_Vector> initialSolution; |
| 111 |
mutable Epetra_Vector* rhs; |
| 112 |
Epetra_CrsGraph* Graph; |
| 113 |
Teuchos::RCP<Epetra_CrsMatrix> jacobian; |
| 114 |
Teuchos::RCP<Epetra_Vector> xptr; |
| 115 |
|
| 116 |
}; |
| 117 |
|
| 118 |
//================================================================== |
| 119 |
// Finite Element Basis Object |
| 120 |
class Basis { |
| 121 |
|
| 122 |
public: |
| 123 |
// Constructor |
| 124 |
Basis(); |
| 125 |
|
| 126 |
// Destructor |
| 127 |
~Basis(); |
| 128 |
|
| 129 |
// Calculates the values of u and x at the specified gauss point |
| 130 |
void computeBasis(int gp, double *x, double *u, double *uold = 0); |
| 131 |
|
| 132 |
public: |
| 133 |
// Variables that are calculated at the gauss point |
| 134 |
double *phi, *dphide; |
| 135 |
double uu, xx, duu, eta, wt; |
| 136 |
double dx; |
| 137 |
// These are only needed for transient |
| 138 |
double uuold, duuold; |
| 139 |
}; |
| 140 |
|
| 141 |
#endif |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|