Debian Codegraph @

packages/nox/test/epetra/LOCA_TestProblems/NormConstraint.C

raw
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 #include "NormConstraint.H"
11 #include "LOCA_Parameter_Vector.H"
12
13 NormConstraint::NormConstraint(int N, const LOCA::ParameterVector& pVec,
14 NOX::Abstract::Vector& cloneVec) :
15 n(N),
16 constraints(1,1),
17 isValidConstraints(false),
18 p(pVec),
19 x(),
20 isZeroDgDx(false)
21 {
22 constraints.putScalar(0.0);
23 x = cloneVec.createMultiVector(1);
24 }
25
26 NormConstraint::NormConstraint(const NormConstraint& source,
27 NOX::CopyType type) :
28 n(source.n),
29 constraints(source.constraints),
30 isValidConstraints(false),
31 p(source.p),
32 x(source.x->clone(type)),
33 isZeroDgDx(source.isZeroDgDx)
34 {
35 if (source.isValidConstraints && type == NOX::DeepCopy)
36 isValidConstraints = true;
37 }
38
39 NormConstraint::~NormConstraint()
40 {
41 }
42
43 void
44 NormConstraint::copy(const LOCA::MultiContinuation::ConstraintInterface& src)
45 {
46 const NormConstraint& source = dynamic_cast<const NormConstraint&>(src);
47
48 if (this != &source) {
49 n = source.n;
50 constraints = source.constraints;
51 isValidConstraints = source.isValidConstraints;
52 p = source.p;
53 *x = *source.x;
54 isZeroDgDx = source.isZeroDgDx;
55 }
56 }
57
58 Teuchos::RCP<LOCA::MultiContinuation::ConstraintInterface>
59 NormConstraint::clone(NOX::CopyType type) const
60 {
61 return Teuchos::rcp(new NormConstraint(*this, type));
62 }
63
64 int
65 NormConstraint::numConstraints() const
66 {
67 return 1;
68 }
69
70 void
71 NormConstraint::setX(const NOX::Abstract::Vector& y)
72 {
73 (*x)[0] = y;
74 x->scale(1.0/n);
75 isValidConstraints = false;
76 }
77
78 void
79 NormConstraint::setParam(int paramID, double val)
80 {
81 p[paramID] = val;
82 isValidConstraints = false;
83 }
84
85 void
86 NormConstraint::setParams(
87 const std::vector<int>& paramIDs,
88 const NOX::Abstract::MultiVector::DenseMatrix& vals)
89 {
90 for (unsigned int i=0; i<paramIDs.size(); i++)
91 p[paramIDs[i]] = vals(i,0);
92 isValidConstraints = false;
93 }
94
95 NOX::Abstract::Group::ReturnType
96 NormConstraint::computeConstraints()
97 {
98 constraints(0,0) = 0.5 * n * (*x)[0].innerProduct((*x)[0]) - p.getValue("Constraint Param");
99
100 isValidConstraints = true;
101
102 return NOX::Abstract::Group::Ok;
103 }
104
105 NOX::Abstract::Group::ReturnType
106 NormConstraint::computeDX()
107 {
108 return NOX::Abstract::Group::Ok;
109 }
110
111 NOX::Abstract::Group::ReturnType
112 NormConstraint::computeDP(const std::vector<int>& paramIDs,
113 NOX::Abstract::MultiVector::DenseMatrix& dgdp,
114 bool isValidG)
115 {
116 if (!isValidG) {
117 dgdp(0,0) = constraints(0,0);
118 }
119
120 for (unsigned int i=0; i<paramIDs.size(); i++) {
121 if (p.getLabel(paramIDs[i]) == "Constraint Param") {
122 dgdp(0,i+1) = -1.0;
123 }
124 else {
125 dgdp(0,i+1) = 0.0;
126 }
127 }
128
129 return NOX::Abstract::Group::Ok;
130 }
131
132 bool
133 NormConstraint::isConstraints() const
134 {
135 return isValidConstraints;
136 }
137
138 bool
139 NormConstraint::isDX() const
140 {
141 return true;
142 }
143
144 const NOX::Abstract::MultiVector::DenseMatrix&
145 NormConstraint::getConstraints() const
146 {
147 return constraints;
148 }
149
150 const NOX::Abstract::MultiVector*
151 NormConstraint::getDX() const
152 {
153 return x.get();
154 }
155
156 bool
157 NormConstraint::isDXZero() const
158 {
159 return isZeroDgDx;
160 }
161
162 void
163 NormConstraint::setIsZeroDX(bool flag)
164 {
165 isZeroDgDx = flag;
166 }
167