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