| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// LOCA: Library of Continuation Algorithms Package |
| 4 |
// |
| 5 |
// Copyright 2001-2005 NTESS and the LOCA contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef LINEARCONSTRAINT_H |
| 11 |
#define LINEARCONSTRAINT_H |
| 12 |
|
| 13 |
#include "LOCA.H" |
| 14 |
|
| 15 |
//! A simple linear constraint equation |
| 16 |
/*! |
| 17 |
* This class implements the LOCA::MultiContinuation::ConstraintInterfaceMVDX |
| 18 |
* constraint interface for a simple linear constraint: |
| 19 |
* \f[ |
| 20 |
* g(x,p) = \frac{dg}{dx}*x |
| 21 |
* \f] |
| 22 |
* where \f$x\f$ is the solution vector. |
| 23 |
*/ |
| 24 |
class LinearConstraint : |
| 25 |
public LOCA::MultiContinuation::ConstraintInterfaceMVDX { |
| 26 |
|
| 27 |
public: |
| 28 |
|
| 29 |
//! Constructor |
| 30 |
LinearConstraint(int NumConstraints, const LOCA::ParameterVector& pVec, |
| 31 |
NOX::Abstract::Vector& cloneVec); |
| 32 |
|
| 33 |
//! Copy constructor |
| 34 |
LinearConstraint(const LinearConstraint& source, |
| 35 |
NOX::CopyType type = NOX::DeepCopy); |
| 36 |
|
| 37 |
//! Destructor |
| 38 |
virtual ~LinearConstraint(); |
| 39 |
|
| 40 |
/*! |
| 41 |
* @name Implementation of LOCA::MultiContinuation::ConstraintInterfaceMVDX |
| 42 |
* virtual methods |
| 43 |
*/ |
| 44 |
//@{ |
| 45 |
|
| 46 |
//! Copy |
| 47 |
virtual void |
| 48 |
copy(const LOCA::MultiContinuation::ConstraintInterface& source); |
| 49 |
|
| 50 |
//! Cloning function |
| 51 |
virtual |
| 52 |
Teuchos::RCP<LOCA::MultiContinuation::ConstraintInterface> |
| 53 |
clone(NOX::CopyType type = NOX::DeepCopy) const; |
| 54 |
|
| 55 |
//! Return number of constraints |
| 56 |
virtual int numConstraints() const; |
| 57 |
|
| 58 |
//! Set the solution vector to y. |
| 59 |
virtual void setX(const NOX::Abstract::Vector& y); |
| 60 |
|
| 61 |
//! Sets parameter indexed by paramID |
| 62 |
virtual void setParam(int paramID, double val); |
| 63 |
|
| 64 |
//! Sets parameters indexed by paramIDs |
| 65 |
virtual void setParams(const std::vector<int>& paramIDs, |
| 66 |
const NOX::Abstract::MultiVector::DenseMatrix& vals); |
| 67 |
|
| 68 |
//! Compute continuation constraint equations |
| 69 |
virtual NOX::Abstract::Group::ReturnType |
| 70 |
computeConstraints(); |
| 71 |
|
| 72 |
//! Compute derivative of constraints w.r.t. solution vector x |
| 73 |
virtual NOX::Abstract::Group::ReturnType |
| 74 |
computeDX(); |
| 75 |
|
| 76 |
//! Compute derivative of constraints w.r.t. supplied parameters. |
| 77 |
/*! |
| 78 |
* The first column of \c dgdp should be filled with the constraint |
| 79 |
* residuals \f$g\f$ if \c isValidG is \c false. If \c isValidG is |
| 80 |
* \c true, then the \c dgdp contains \f$g\f$ on input. |
| 81 |
*/ |
| 82 |
virtual NOX::Abstract::Group::ReturnType |
| 83 |
computeDP(const std::vector<int>& paramIDs, |
| 84 |
NOX::Abstract::MultiVector::DenseMatrix& dp, |
| 85 |
bool isValidG); |
| 86 |
|
| 87 |
//! Return \c true if constraint residuals are valid |
| 88 |
virtual bool isConstraints() const; |
| 89 |
|
| 90 |
//! Return \c true if derivative of constraint w.r.t. x is valid |
| 91 |
virtual bool isDX() const; |
| 92 |
|
| 93 |
//! Return constraint residuals |
| 94 |
virtual const NOX::Abstract::MultiVector::DenseMatrix& |
| 95 |
getConstraints() const; |
| 96 |
|
| 97 |
//! Return solution component of constraint derivatives |
| 98 |
virtual const NOX::Abstract::MultiVector* |
| 99 |
getDX() const; |
| 100 |
|
| 101 |
/*! |
| 102 |
* \brief Return \c true if solution component of constraint |
| 103 |
* derivatives is zero |
| 104 |
*/ |
| 105 |
virtual bool isDXZero() const; |
| 106 |
|
| 107 |
//@} |
| 108 |
|
| 109 |
//! Set solution component of constraint derivative |
| 110 |
void setDgDx(const NOX::Abstract::MultiVector& A); |
| 111 |
|
| 112 |
//! Set parameter component of constraint derivative |
| 113 |
void setDgDp(const NOX::Abstract::MultiVector::DenseMatrix& A); |
| 114 |
|
| 115 |
/*! |
| 116 |
* \brief Set the flag determinging whether isDXZero() |
| 117 |
* returns true or false. This is for testing bordered solvers when B |
| 118 |
* is zero. |
| 119 |
*/ |
| 120 |
void setIsZeroDX(bool flag); |
| 121 |
|
| 122 |
private: |
| 123 |
|
| 124 |
//! Prohibit generation and use of operator=() |
| 125 |
LinearConstraint& operator=(const LinearConstraint& source); |
| 126 |
|
| 127 |
protected: |
| 128 |
|
| 129 |
//! Number of constraints |
| 130 |
int m; |
| 131 |
|
| 132 |
//! Constraint values |
| 133 |
NOX::Abstract::MultiVector::DenseMatrix constraints; |
| 134 |
|
| 135 |
//! Flag indicating whether constraints are valid |
| 136 |
bool isValidConstraints; |
| 137 |
|
| 138 |
//! Solution vector |
| 139 |
Teuchos::RCP<NOX::Abstract::MultiVector> x; |
| 140 |
|
| 141 |
//! Solution component of constraint derivative |
| 142 |
Teuchos::RCP<NOX::Abstract::MultiVector> dgdx; |
| 143 |
|
| 144 |
//! Flag indicating whether dgdx is zero |
| 145 |
bool isZeroDgDx; |
| 146 |
|
| 147 |
//! Parameter vector |
| 148 |
LOCA::ParameterVector p; |
| 149 |
|
| 150 |
//! Parameter vector as a DenseMatrix (view of p) |
| 151 |
NOX::Abstract::MultiVector::DenseMatrix pvec; |
| 152 |
|
| 153 |
//! Parameter component of constraint derivative |
| 154 |
NOX::Abstract::MultiVector::DenseMatrix dgdp; |
| 155 |
|
| 156 |
}; |
| 157 |
|
| 158 |
#endif |