Xyce  6.1
N_NLS_NOX_Vector.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-------------------------------------------------------------------------
26 // Filename : $RCSfile: N_NLS_NOX_Vector.C,v $
27 //
28 // Purpose : Interface to Xyce vectors for NOX.
29 //
30 // Special Notes :
31 //
32 // Creator : Tammy Kolda, NLS, 8950
33 //
34 // Creation Date : 01/31/02
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.27 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:29 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 
49 // ---------- Standard Includes ----------
50 
51 // ---------- Xyce Includes ----------
52 
53 #include "N_NLS_NOX_Vector.h"
54 #include "N_NLS_NOX.h"
55 #include "N_LAS_Vector.h"
56 #include "N_LAS_System.h"
57 #include "N_LAS_Builder.h"
58 #include "N_ERH_ErrorMgr.h"
59 
60 // ---------- Namespaces ----------
61 
62 namespace Xyce {
63 namespace Nonlinear {
64 namespace N_NLS_NOX {
65 
66 // ---------- Code ----------
67 
68 Vector::Vector(Linear::Vector& vector, Linear::System& lasSys) :
69  vectorPtr_(&vector),
70  lasSys_(lasSys),
71  doDelete_(false)
72 {
73 
74 }
75 
76 
77 Vector::Vector(const Vector& source, NOX::CopyType type) :
78  vectorPtr_(0),
79  lasSys_(source.lasSys_),
80  doDelete_(true)
81 {
82  vectorPtr_ = lasSys_.builder().createVector();
83  if (vectorPtr_ == 0) {
84  error("Vector Copy Constructor - unable to create vector");
85  }
86 
87  if (type == NOX::DeepCopy)
88  *vectorPtr_ = *(source.vectorPtr_);
89 }
90 
92 {
93  if (doDelete_)
94  delete vectorPtr_;
95 }
96 
97 #ifdef Xyce_NOX_SIZETYPE
98 NOX::size_type Vector::length() const
99 #else
100 int Vector::length() const
101 #endif
102 {
103  return vectorPtr_->globalLength();
104 }
105 
106 NOX::Abstract::Vector& Vector::init(double value)
107 {
108  vectorPtr_->putScalar(value);
109  return *this;
110 }
111 
112 NOX::Abstract::Vector& Vector::abs(const NOX::Abstract::Vector& source)
113 {
114  return abs(dynamic_cast<const Vector&>(source));
115 }
116 
117 NOX::Abstract::Vector& Vector::abs(const Vector& source)
118 {
119  vectorPtr_->absValue(source.getNativeVectorRef_());
120  return *this;
121 }
122 
123 NOX::Abstract::Vector& Vector::operator=(const NOX::Abstract::Vector& source)
124 {
125  return operator=(dynamic_cast<const Vector&>(source));
126 }
127 
128 NOX::Abstract::Vector& Vector::operator=(const Vector& source)
129 {
130  //vectorPtr_->scale(1.0, source.getNativeVectorRef_());
131  //vectorPtr_->update(1.0, source.getNativeVectorRef_(), 0.0);
132  *vectorPtr_ = *(source.vectorPtr_);
133  return *this;
134 }
135 
136 NOX::Abstract::Vector& Vector::reciprocal(const NOX::Abstract::Vector& source)
137 {
138  return reciprocal(dynamic_cast<const Vector&>(source));
139 }
140 
141 NOX::Abstract::Vector& Vector::reciprocal(const Vector& source)
142 {
143  vectorPtr_->reciprocal(source.getNativeVectorRef_());
144  return *this;
145 }
146 
147 NOX::Abstract::Vector& Vector::scale(double gamma)
148 {
149  vectorPtr_->scale(gamma);
150  return *this;
151 }
152 
153 NOX::Abstract::Vector& Vector::scale(const NOX::Abstract::Vector& y)
154 {
155  return scale(dynamic_cast<const Vector&>(y));
156 }
157 
158 NOX::Abstract::Vector& Vector::scale(const Vector& y)
159 {
160  vectorPtr_->multiply(y.getNativeVectorRef_());
161  return *this;
162 }
163 
164 NOX::Abstract::Vector& Vector::update(double alpha, const NOX::Abstract::Vector& a,
165  double gamma)
166 {
167  return update(alpha, dynamic_cast<const Vector&>(a), gamma);
168 }
169 
170 
171 NOX::Abstract::Vector& Vector::update(double alpha, const Vector& a,
172  double gamma)
173 {
174  vectorPtr_->linearCombo(alpha, a.getNativeVectorRef_(), gamma, this->getNativeVectorRef_());
175  return *this;
176 }
177 
178 NOX::Abstract::Vector& Vector::update(double alpha, const NOX::Abstract::Vector& a,
179  double beta, const NOX::Abstract::Vector& b,
180  double gamma)
181 {
182  return update(alpha, dynamic_cast<const Vector&>(a),
183  beta, dynamic_cast<const Vector&>(b),
184  gamma);
185 }
186 
187 
188 
189 NOX::Abstract::Vector& Vector::update(double alpha, const Vector& a,
190  double beta, const Vector& b,
191  double gamma)
192 {
193  vectorPtr_->linearCombo(alpha, a.getNativeVectorRef_(),
194  beta, b.getNativeVectorRef_(),
195  gamma, this->getNativeVectorRef_());
196  return *this;
197 }
198 
199 NOX::Abstract::Vector& Vector::random(bool useSeed, int seed)
200 {
201  vectorPtr_->random();
202  return *this;
203 }
204 
205 Teuchos::RCP<NOX::Abstract::Vector>
206 Vector::clone(NOX::CopyType type) const
207 {
208  Teuchos::RCP<Vector> ptr = Teuchos::rcp(new Vector(*this, type));
209  return ptr;
210 }
211 
212 double Vector::norm(NOX::Abstract::Vector::NormType type) const
213 {
214  double tmp = 0.0;
215  switch(type)
216  {
217  case NOX::Abstract::Vector::TwoNorm:
218  vectorPtr_->lpNorm(2, &tmp);
219  break;
220  case NOX::Abstract::Vector::OneNorm:
221  vectorPtr_->lpNorm(1, &tmp);
222  break;
223  case NOX::Abstract::Vector::MaxNorm:
224  vectorPtr_->infNorm(&tmp);
225  break;
226  default:
227  error("Vector::norm - invalid norm type");
228  }
229  return tmp;
230 }
231 
232 double Vector::norm(const NOX::Abstract::Vector& weights) const
233 {
234  return norm(dynamic_cast<const Vector&>(weights));
235 }
236 
237 double Vector::norm(const Vector& weights) const
238 {
239  error("N_NLS::NOX::Vector::norm with weights is not supported");
240  return 0.0;
241 }
242 
243 double Vector::innerProduct(const Vector& y) const
244 {
245  return vectorPtr_->dotProduct(y.getNativeVectorRef_());
246 }
247 
248 double Vector::innerProduct(const NOX::Abstract::Vector& y) const
249 {
250  return innerProduct(dynamic_cast<const Vector&>(y));
251 }
252 
253 void Vector::print(std::ostream &os) const
254 {
255  vectorPtr_->printPetraObject(os);
256 }
257 
258 }}}
Teuchos::RCP< NOX::Abstract::Vector > clone(NOX::CopyType type=NOX::DeepCopy) const
NOX::Abstract::Vector & reciprocal(const Vector &source)
NOX::Abstract::Vector & random(bool useSeed=false, int seed=1)
NOX::Abstract::Vector & operator=(const Vector &source)
NOX::Abstract::Vector & init(double value)
const Xyce::Linear::Vector & getNativeVectorRef_() const
Pure virtual class to augment a linear system.
const T & value(const ParameterBase &entity, const Descriptor &descriptor)
Returns the value of the parameter for the entity.
Definition: N_DEV_Pars.h:1224
NOX::Abstract::Vector & scale(double gamma)
NOX::Abstract::Vector & update(double alpha, const Vector &a, double gamma=0.0)
Vector(Xyce::Linear::Vector &vector, Xyce::Linear::System &lasSys)
double norm(NOX::Abstract::Vector::NormType type=NOX::Abstract::Vector::TwoNorm) const
void error(const std::string &msg)
Definition: N_NLS_NOX.C:61
NOX::Abstract::Vector & abs(const Vector &source)
double innerProduct(const Vector &y) const
NOX::Abstract::Vector & operator=(const NOX::Abstract::Vector &source)
void print(std::ostream &os) const