Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 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.22 $
40 //
41 // Revision Date : $Date: 2014/02/24 23:49:25 $
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 using namespace N_NLS_NOX;
63 
64 // ---------- Code ----------
65 
66 Vector::Vector(N_LAS_Vector& vector, N_LAS_System& lasSys) :
67  vectorPtr_(&vector),
68  lasSys_(lasSys),
69  doDelete_(false)
70 {
71 
72 }
73 
74 
75 Vector::Vector(const Vector& source, NOX::CopyType type) :
76  vectorPtr_(0),
77  lasSys_(source.lasSys_),
78  doDelete_(true)
79 {
80  vectorPtr_ = lasSys_.builder().createVector();
81  if (vectorPtr_ == 0) {
82  error("N_NLS_NOX::Vector Copy Constructor - unable to create vector");
83  }
84 
85  if (type == NOX::DeepCopy)
86  *vectorPtr_ = *(source.vectorPtr_);
87 }
88 
90 {
91  if (doDelete_)
92  delete vectorPtr_;
93 }
94 
95 int Vector::length() const
96 {
97  return vectorPtr_->globalLength();
98 }
99 
100 NOX::Abstract::Vector& Vector::init(double value)
101 {
102  vectorPtr_->putScalar(value);
103  return *this;
104 }
105 
106 NOX::Abstract::Vector& Vector::abs(const NOX::Abstract::Vector& source)
107 {
108  return abs(dynamic_cast<const Vector&>(source));
109 }
110 
111 NOX::Abstract::Vector& Vector::abs(const Vector& source)
112 {
113  vectorPtr_->absValue(source.getNativeVectorRef_());
114  return *this;
115 }
116 
117 NOX::Abstract::Vector& Vector::operator=(const NOX::Abstract::Vector& source)
118 {
119  return operator=(dynamic_cast<const Vector&>(source));
120 }
121 
122 NOX::Abstract::Vector& Vector::operator=(const Vector& source)
123 {
124  //vectorPtr_->scale(1.0, source.getNativeVectorRef_());
125  //vectorPtr_->update(1.0, source.getNativeVectorRef_(), 0.0);
126  *vectorPtr_ = *(source.vectorPtr_);
127  return *this;
128 }
129 
130 NOX::Abstract::Vector& Vector::reciprocal(const NOX::Abstract::Vector& source)
131 {
132  return reciprocal(dynamic_cast<const Vector&>(source));
133 }
134 
135 NOX::Abstract::Vector& Vector::reciprocal(const Vector& source)
136 {
137  vectorPtr_->reciprocal(source.getNativeVectorRef_());
138  return *this;
139 }
140 
141 NOX::Abstract::Vector& Vector::scale(double gamma)
142 {
143  vectorPtr_->scale(gamma);
144  return *this;
145 }
146 
147 NOX::Abstract::Vector& Vector::scale(const NOX::Abstract::Vector& y)
148 {
149  return scale(dynamic_cast<const Vector&>(y));
150 }
151 
152 NOX::Abstract::Vector& Vector::scale(const Vector& y)
153 {
154  vectorPtr_->multiply(y.getNativeVectorRef_());
155  return *this;
156 }
157 
158 NOX::Abstract::Vector& Vector::update(double alpha, const NOX::Abstract::Vector& a,
159  double gamma)
160 {
161  return update(alpha, dynamic_cast<const Vector&>(a), gamma);
162 }
163 
164 
165 NOX::Abstract::Vector& Vector::update(double alpha, const Vector& a,
166  double gamma)
167 {
168  vectorPtr_->linearCombo(alpha, a.getNativeVectorRef_(), gamma, this->getNativeVectorRef_());
169  return *this;
170 }
171 
172 NOX::Abstract::Vector& Vector::update(double alpha, const NOX::Abstract::Vector& a,
173  double beta, const NOX::Abstract::Vector& b,
174  double gamma)
175 {
176  return update(alpha, dynamic_cast<const Vector&>(a),
177  beta, dynamic_cast<const Vector&>(b),
178  gamma);
179 }
180 
181 
182 
183 NOX::Abstract::Vector& Vector::update(double alpha, const Vector& a,
184  double beta, const Vector& b,
185  double gamma)
186 {
187  vectorPtr_->linearCombo(alpha, a.getNativeVectorRef_(),
188  beta, b.getNativeVectorRef_(),
189  gamma, this->getNativeVectorRef_());
190  return *this;
191 }
192 
193 NOX::Abstract::Vector& Vector::random(bool useSeed, int seed)
194 {
195  vectorPtr_->random();
196  return *this;
197 }
198 
199 Teuchos::RCP<NOX::Abstract::Vector>
200 Vector::clone(NOX::CopyType type) const
201 {
202  Teuchos::RCP<Vector> ptr = Teuchos::rcp(new Vector(*this, type));
203  return ptr;
204 }
205 
206 double Vector::norm(NOX::Abstract::Vector::NormType type) const
207 {
208  double tmp = 0.0;
209  switch(type)
210  {
211  case NOX::Abstract::Vector::TwoNorm:
212  vectorPtr_->lpNorm(2, &tmp);
213  break;
214  case NOX::Abstract::Vector::OneNorm:
215  vectorPtr_->lpNorm(1, &tmp);
216  break;
217  case NOX::Abstract::Vector::MaxNorm:
218  vectorPtr_->infNorm(&tmp);
219  break;
220  default:
221  error("N_NLS_NOX::Vector::norm - invalid norm type");
222  }
223  return tmp;
224 }
225 
226 double Vector::norm(const NOX::Abstract::Vector& weights) const
227 {
228  return norm(dynamic_cast<const Vector&>(weights));
229 }
230 
231 double Vector::norm(const Vector& weights) const
232 {
233  error("N_NLS::NOX::Vector::norm with weights is not supported");
234  return 0.0;
235 }
236 
237 double Vector::innerProduct(const Vector& y) const
238 {
239  return vectorPtr_->dotProduct(y.getNativeVectorRef_());
240 }
241 
242 double Vector::innerProduct(const NOX::Abstract::Vector& y) const
243 {
244  return innerProduct(dynamic_cast<const Vector&>(y));
245 }
246 
247 void Vector::print(std::ostream &os) const
248 {
249  vectorPtr_->printPetraObject(os);
250 }
251