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.19 $
40 //
41 // Revision Date : $Date: 2014/02/24 23:49:24 $
42 //
43 // Current Owner : $Author: tvrusso $
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  int length() const;
114 
115  //---------------------------------------------------------------------------
116  // Purpose : Initialize every entry in the vector to the given value
117  //---------------------------------------------------------------------------
118  NOX::Abstract::Vector& init(double value);
119 
120  //---------------------------------------------------------------------------
121  // Purpose : Compute the element-wise absolute value of source
122  //---------------------------------------------------------------------------
123  NOX::Abstract::Vector& abs(const Vector& source);
124  NOX::Abstract::Vector& abs(const NOX::Abstract::Vector& source);
125 
126  //---------------------------------------------------------------------------
127  // Purpose : Copy the source vector
128  //---------------------------------------------------------------------------
129  NOX::Abstract::Vector& operator=(const Vector& source);
130  NOX::Abstract::Vector& operator=(const NOX::Abstract::Vector& source);
131 
132  //---------------------------------------------------------------------------
133  // Purpose : Compute the element-wise reciprocal of source
134  //---------------------------------------------------------------------------
135  NOX::Abstract::Vector& reciprocal(const Vector& source);
136  NOX::Abstract::Vector& reciprocal(const NOX::Abstract::Vector& source);
137 
138  //---------------------------------------------------------------------------
139  // Purpose : Scale this vector by gamma
140  //---------------------------------------------------------------------------
141  NOX::Abstract::Vector& scale(double gamma);
142 
143  //---------------------------------------------------------------------------
144  // Purpose : Scale this vector element-by-element by y
145  //---------------------------------------------------------------------------
146  NOX::Abstract::Vector& scale(const Vector& y);
147  NOX::Abstract::Vector& scale(const NOX::Abstract::Vector& y);
148 
149  //---------------------------------------------------------------------------
150  // Purpose : this = alpha * a + gamma * this
151  //---------------------------------------------------------------------------
152  NOX::Abstract::Vector& update(double alpha, const Vector& a,
153  double gamma = 0.0);
154  NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a,
155  double gamma = 0.0);
156 
157  //---------------------------------------------------------------------------
158  // Purpose : this = alpha * a + beta * b + gamma * this
159  //---------------------------------------------------------------------------
160  NOX::Abstract::Vector& update(double alpha, const Vector& a,
161  double beta, const Vector& b,
162  double gamma = 0.0);
163  NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a,
164  double beta, const NOX::Abstract::Vector& b,
165  double gamma = 0.0);
166 
167  //---------------------------------------------------------------------------
168  // Purpose : this = alpha * a + beta * b + gamma * this
169  //---------------------------------------------------------------------------
170  NOX::Abstract::Vector& random(bool useSeed=false, int seed=1);
171 
172  //---------------------------------------------------------------------------
173  // Purpose : Return a pointer to a new cloned vector of this type.
174  //---------------------------------------------------------------------------
175  Teuchos::RCP<NOX::Abstract::Vector>
176  clone(NOX::CopyType type = NOX::DeepCopy) const;
177 
178  //---------------------------------------------------------------------------
179  // Purpose : Return the norm of this vector
180  //---------------------------------------------------------------------------
181  double norm(NOX::Abstract::Vector::NormType type = NOX::Abstract::Vector::TwoNorm) const;
182 
183  //---------------------------------------------------------------------------
184  // Purpose : Return the norm of weights .* this
185  // (i.e., elementwise multiplication)
186  //---------------------------------------------------------------------------
187  double norm(const Vector& weights) const;
188  double norm(const NOX::Abstract::Vector& weights) const;
189 
190  //---------------------------------------------------------------------------
191  // Purpose : Return this' * y (dot product of this with y)
192  //---------------------------------------------------------------------------
193  double innerProduct(const Vector& y) const;
194  double innerProduct(const NOX::Abstract::Vector& y) const;
195 
196  //---------------------------------------------------------------------------
197  // Purpose : Return const pointer to the underlying N_LAS_Vector
198  //---------------------------------------------------------------------------
199  const N_LAS_Vector& getNativeVectorRef() const {return *vectorPtr_;};
200 
201  //---------------------------------------------------------------------------
202  // Purpose : Return pointer to the underlying N_LAS_Vector
203  //---------------------------------------------------------------------------
204  N_LAS_Vector& getNativeVectorRef() {return *vectorPtr_;};
205 
206  N_LAS_Vector* getNativeVectorPtr() {return vectorPtr_;};
207 
208  N_LAS_Vector* getNativeVectorPtr() const {return vectorPtr_;};
209 
210  //---------------------------------------------------------------------------
211  // Purpose : Print the underlying vector
212  //---------------------------------------------------------------------------
213  void print(std::ostream &os) const;
214 
215  //---------------------------------------------------------------------------
216  // Purpose : Return the pointer to the underlying N_LAS_Vector
217  //---------------------------------------------------------------------------
218  const N_LAS_Vector& getNativeVectorRef_() const {return *vectorPtr_;};
219 
220 private:
221  // Vector stored by this object
222  N_LAS_Vector* vectorPtr_;
223 
224  // Only used in copy constructor and only because N_LAS_Vector does
225  // not have a copy constructor
226  N_LAS_System& lasSys_;
227 
228  // True is N_LAS_Vector should be deleted when this object is
229  // destructed. This is true for any Vector created by the copy
230  // constructor.
231  bool doDelete_;
232 
233 }; // class SharedSystem
234 } // namespace N_NLS_NOX
235 
236 #endif // Xyce_N_NLS_NOX_SharedSystem_h
237