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