Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_NOX_Vector.h
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.h,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.20 $
40 //
41 // Revision Date : $Date: 2014/07/21 19:24:17 $
42 //
43 // Current Owner : $Author: hkthorn $
44 //-------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_NLS_NOX_Vector_h
47 #define Xyce_N_NLS_NOX_Vector_h
48 
49 // ---------- Standard Includes ----------
50 
51 // ---------- Xyce Includes ----------
52 #include <N_UTL_Misc.h>
53 
54 // ---------- NOX Includes ----------
55 
56 #include "NOX_Abstract_Vector.H"
57 
58 // ---------- Forward Declarations ----------
59 
60 class N_LAS_Vector;
61 class N_LAS_System;
62 
63 // ---------- Namespace Declarations ----------
64 
65 // N_NLS namespace is for the Xyce Nonlinear Solver Package
66 namespace N_NLS_NOX {
67 
68 //-----------------------------------------------------------------------------
69 // Class : N_NLS::NOX::Vector
70 //
71 // Purpose :
72 //
73 // NOX Vector Interface for Xyce vectors.
74 //
75 // Creator : Tammy Kolda, SNL, 8950
76 //
77 // Creation Date : 2/1/02
78 //-----------------------------------------------------------------------------
79 
80 class Vector : public NOX::Abstract::Vector {
81 
82 public:
83 
84  //---------------------------------------------------------------------------
85  // Function : Vector (constructor)
86  //
87  // Purpose : Constructs a NOX-compatiable vector object
88  // containing the given Xyce-compatible vector.
89  //
90  // Special Notes : The N_LAS_System pointer is only needed to
91  // support cloning. If N_LAS_Vector supported the
92  // copy constructor, this would not be necessary.
93  //---------------------------------------------------------------------------
94  Vector(N_LAS_Vector& vector, N_LAS_System& lasSys);
95 
96  //---------------------------------------------------------------------------
97  // Function : Vector (copy constructor)
98  // Purpose : Constructs a Vector using the source vector.
99  //---------------------------------------------------------------------------
100  Vector(const Vector& source, NOX::CopyType type = NOX::DeepCopy);
101 
102  //---------------------------------------------------------------------------
103  // Function : Destructor
104  //
105  // Purpose : Deletes the internal N_LAS_Vector only if that
106  // vector was created via the copy constructor.
107  //---------------------------------------------------------------------------
108  ~Vector();
109 
110  //---------------------------------------------------------------------------
111  // Purpose : Return the length (i.e., number of entries) of the vector
112  //---------------------------------------------------------------------------
113 
114 #ifdef Xyce_TRILINOS_DEV
115  NOX::size_type length() const;
116 #else
117  int length() const;
118 #endif
119 
120  //---------------------------------------------------------------------------
121  // Purpose : Initialize every entry in the vector to the given value
122  //---------------------------------------------------------------------------
123  NOX::Abstract::Vector& init(double value);
124 
125  //---------------------------------------------------------------------------
126  // Purpose : Compute the element-wise absolute value of source
127  //---------------------------------------------------------------------------
128  NOX::Abstract::Vector& abs(const Vector& source);
129  NOX::Abstract::Vector& abs(const NOX::Abstract::Vector& source);
130 
131  //---------------------------------------------------------------------------
132  // Purpose : Copy the source vector
133  //---------------------------------------------------------------------------
134  NOX::Abstract::Vector& operator=(const Vector& source);
135  NOX::Abstract::Vector& operator=(const NOX::Abstract::Vector& source);
136 
137  //---------------------------------------------------------------------------
138  // Purpose : Compute the element-wise reciprocal of source
139  //---------------------------------------------------------------------------
140  NOX::Abstract::Vector& reciprocal(const Vector& source);
141  NOX::Abstract::Vector& reciprocal(const NOX::Abstract::Vector& source);
142 
143  //---------------------------------------------------------------------------
144  // Purpose : Scale this vector by gamma
145  //---------------------------------------------------------------------------
146  NOX::Abstract::Vector& scale(double gamma);
147 
148  //---------------------------------------------------------------------------
149  // Purpose : Scale this vector element-by-element by y
150  //---------------------------------------------------------------------------
151  NOX::Abstract::Vector& scale(const Vector& y);
152  NOX::Abstract::Vector& scale(const NOX::Abstract::Vector& y);
153 
154  //---------------------------------------------------------------------------
155  // Purpose : this = alpha * a + gamma * this
156  //---------------------------------------------------------------------------
157  NOX::Abstract::Vector& update(double alpha, const Vector& a,
158  double gamma = 0.0);
159  NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a,
160  double gamma = 0.0);
161 
162  //---------------------------------------------------------------------------
163  // Purpose : this = alpha * a + beta * b + gamma * this
164  //---------------------------------------------------------------------------
165  NOX::Abstract::Vector& update(double alpha, const Vector& a,
166  double beta, const Vector& b,
167  double gamma = 0.0);
168  NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a,
169  double beta, const NOX::Abstract::Vector& b,
170  double gamma = 0.0);
171 
172  //---------------------------------------------------------------------------
173  // Purpose : this = alpha * a + beta * b + gamma * this
174  //---------------------------------------------------------------------------
175  NOX::Abstract::Vector& random(bool useSeed=false, int seed=1);
176 
177  //---------------------------------------------------------------------------
178  // Purpose : Return a pointer to a new cloned vector of this type.
179  //---------------------------------------------------------------------------
180  Teuchos::RCP<NOX::Abstract::Vector>
181  clone(NOX::CopyType type = NOX::DeepCopy) const;
182 
183  //---------------------------------------------------------------------------
184  // Purpose : Return the norm of this vector
185  //---------------------------------------------------------------------------
186  double norm(NOX::Abstract::Vector::NormType type = NOX::Abstract::Vector::TwoNorm) const;
187 
188  //---------------------------------------------------------------------------
189  // Purpose : Return the norm of weights .* this
190  // (i.e., elementwise multiplication)
191  //---------------------------------------------------------------------------
192  double norm(const Vector& weights) const;
193  double norm(const NOX::Abstract::Vector& weights) const;
194 
195  //---------------------------------------------------------------------------
196  // Purpose : Return this' * y (dot product of this with y)
197  //---------------------------------------------------------------------------
198  double innerProduct(const Vector& y) const;
199  double innerProduct(const NOX::Abstract::Vector& y) const;
200 
201  //---------------------------------------------------------------------------
202  // Purpose : Return const pointer to the underlying N_LAS_Vector
203  //---------------------------------------------------------------------------
204  const N_LAS_Vector& getNativeVectorRef() const {return *vectorPtr_;};
205 
206  //---------------------------------------------------------------------------
207  // Purpose : Return pointer to the underlying N_LAS_Vector
208  //---------------------------------------------------------------------------
209  N_LAS_Vector& getNativeVectorRef() {return *vectorPtr_;};
210 
211  N_LAS_Vector* getNativeVectorPtr() {return vectorPtr_;};
212 
213  N_LAS_Vector* getNativeVectorPtr() const {return vectorPtr_;};
214 
215  //---------------------------------------------------------------------------
216  // Purpose : Print the underlying vector
217  //---------------------------------------------------------------------------
218  void print(std::ostream &os) const;
219 
220  //---------------------------------------------------------------------------
221  // Purpose : Return the pointer to the underlying N_LAS_Vector
222  //---------------------------------------------------------------------------
223  const N_LAS_Vector& getNativeVectorRef_() const {return *vectorPtr_;};
224 
225 private:
226  // Vector stored by this object
227  N_LAS_Vector* vectorPtr_;
228 
229  // Only used in copy constructor and only because N_LAS_Vector does
230  // not have a copy constructor
231  N_LAS_System& lasSys_;
232 
233  // True is N_LAS_Vector should be deleted when this object is
234  // destructed. This is true for any Vector created by the copy
235  // constructor.
236  bool doDelete_;
237 
238 }; // class SharedSystem
239 } // namespace N_NLS_NOX
240 
241 #endif // Xyce_N_NLS_NOX_SharedSystem_h
242