00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "NOX_Thyra_Vector.H"
00043 #include "NOX_Thyra_MultiVector.H"
00044 #include "Thyra_VectorSpaceBase.hpp"
00045 #include "Thyra_VectorStdOps.hpp"
00046 #include "Thyra_MultiVectorStdOps.hpp"
00047
00048 NOX::Thyra::Vector::
00049 Vector(const Teuchos::RCP< ::Thyra::VectorBase<double> >& source) :
00050 thyraVec(source)
00051 {
00052 }
00053
00054 NOX::Thyra::Vector::
00055 Vector(const ::Thyra::VectorBase<double>& source) :
00056 thyraVec(source.clone_v())
00057 {
00058 }
00059
00060 NOX::Thyra::Vector::
00061 Vector(const NOX::Thyra::Vector& source, NOX::CopyType type) :
00062 thyraVec(source.thyraVec->clone_v())
00063 {
00064 }
00065
00066 NOX::Thyra::Vector::
00067 ~Vector()
00068 {
00069 }
00070
00071 NOX::Abstract::Vector&
00072 NOX::Thyra::Vector::
00073 operator=(const NOX::Abstract::Vector& src)
00074 {
00075 const NOX::Thyra::Vector& source =
00076 dynamic_cast<const NOX::Thyra::Vector&>(src);
00077 this->operator=(source);
00078 return *this;
00079 }
00080
00081 NOX::Abstract::Vector&
00082 NOX::Thyra::Vector::
00083 operator=(const NOX::Thyra::Vector& src)
00084 {
00085 ::Thyra::copy(*src.thyraVec, thyraVec.get());
00086 return *this;
00087 }
00088
00089 ::Thyra::VectorBase<double>&
00090 NOX::Thyra::Vector::
00091 getThyraVector()
00092 {
00093 return *thyraVec;
00094 }
00095
00096 const ::Thyra::VectorBase<double>&
00097 NOX::Thyra::Vector::
00098 getThyraVector() const
00099 {
00100 return *thyraVec;
00101 }
00102
00103 Teuchos::RCP< ::Thyra::VectorBase<double> >
00104 NOX::Thyra::Vector::
00105 getThyraRCPVector()
00106 {
00107 return thyraVec;
00108 }
00109
00110 Teuchos::RCP<const ::Thyra::VectorBase<double> >
00111 NOX::Thyra::Vector::
00112 getThyraRCPVector() const
00113 {
00114 return thyraVec;
00115 }
00116
00117 NOX::Abstract::Vector&
00118 NOX::Thyra::Vector::
00119 init(double value)
00120 {
00121 ::Thyra::put_scalar(value, thyraVec.get());
00122 return *this;
00123 }
00124
00125 NOX::Abstract::Vector&
00126 NOX::Thyra::Vector::
00127 random(bool useSeed, int seed)
00128 {
00129 if (useSeed)
00130 ::Thyra::seed_randomize<double>(seed);
00131 ::Thyra::randomize(-1.0, 1.0, thyraVec.get());
00132 return *this;
00133 }
00134
00135 NOX::Abstract::Vector&
00136 NOX::Thyra::Vector::
00137 abs(const NOX::Abstract::Vector& src)
00138 {
00139 const NOX::Thyra::Vector& source =
00140 dynamic_cast<const NOX::Thyra::Vector&>(src);
00141 ::Thyra::abs(thyraVec.get(), *source.thyraVec);
00142 return *this;
00143 }
00144
00145 NOX::Abstract::Vector&
00146 NOX::Thyra::Vector::
00147 reciprocal(const NOX::Abstract::Vector& src)
00148 {
00149 const NOX::Thyra::Vector& source =
00150 dynamic_cast<const NOX::Thyra::Vector&>(src);
00151 ::Thyra::reciprocal(thyraVec.get(), *source.thyraVec);
00152 return *this;
00153 }
00154
00155 NOX::Abstract::Vector&
00156 NOX::Thyra::Vector::
00157 scale(double alpha)
00158 {
00159 ::Thyra::scale(alpha, thyraVec.get());
00160 return *this;
00161 }
00162
00163 NOX::Abstract::Vector&
00164 NOX::Thyra::Vector::
00165 scale(const NOX::Abstract::Vector& src)
00166 {
00167 const NOX::Thyra::Vector& source =
00168 dynamic_cast<const NOX::Thyra::Vector&>(src);
00169 ::Thyra::Vt_StV(thyraVec.get(), 1.0, *source.thyraVec);
00170 return *this;
00171 }
00172
00173 NOX::Abstract::Vector&
00174 NOX::Thyra::Vector::
00175 update(double alpha, const NOX::Abstract::Vector& a, double gamma)
00176 {
00177 const NOX::Thyra::Vector& aa =
00178 dynamic_cast<const NOX::Thyra::Vector&>(a);
00179 const ::Thyra::VectorBase<double> *tv = aa.thyraVec.get();
00180 ::Thyra::linear_combination(1, &alpha, &tv, gamma, thyraVec.get());
00181 return *this;
00182 }
00183
00184 NOX::Abstract::Vector& NOX::Thyra::Vector::
00185 update(double alpha, const NOX::Abstract::Vector& x,
00186 double beta, const NOX::Abstract::Vector& y,
00187 double gamma)
00188 {
00189 const NOX::Thyra::Vector& xx =
00190 dynamic_cast<const NOX::Thyra::Vector&>(x);
00191 const NOX::Thyra::Vector& yy =
00192 dynamic_cast<const NOX::Thyra::Vector&>(y);
00193 double a[] = {alpha, beta};
00194 const ::Thyra::VectorBase<double>* z[] = {xx.thyraVec.get(),
00195 yy.thyraVec.get()};
00196 ::Thyra::linear_combination(2, a, z, gamma, thyraVec.get());
00197 return *this;
00198 }
00199
00200 Teuchos::RCP<NOX::Abstract::Vector>
00201 NOX::Thyra::Vector::
00202 clone(CopyType type) const
00203 {
00204 return Teuchos::rcp(new NOX::Thyra::Vector(*this, type));
00205 }
00206
00207 Teuchos::RCP<NOX::Abstract::MultiVector>
00208 NOX::Thyra::Vector::
00209 createMultiVector(const NOX::Abstract::Vector* const* vecs,
00210 int numVecs, NOX::CopyType type) const
00211 {
00212
00213 Teuchos::RCP<const ::Thyra::VectorSpaceBase<double> > space =
00214 thyraVec->space();
00215
00216
00217 Teuchos::RCP< ::Thyra::MultiVectorBase<double> > mv =
00218 ::Thyra::createMembers(*space, numVecs+1);
00219
00220
00221 if (type == NOX::DeepCopy) {
00222 Teuchos::RCP< ::Thyra::VectorBase<double> > v = mv->col(0);
00223 ::Thyra::copy(*thyraVec, v.get());
00224 for (int i=0; i<numVecs; i++) {
00225 const NOX::Thyra::Vector* tv =
00226 dynamic_cast<const NOX::Thyra::Vector*>(vecs[i]);
00227 v = mv->col(i+1);
00228 ::Thyra::copy(*(tv->thyraVec), v.get());
00229 }
00230 }
00231
00232
00233 Teuchos::RCP<NOX::Thyra::MultiVector> nmv =
00234 Teuchos::rcp(new NOX::Thyra::MultiVector(mv));
00235
00236 return nmv;
00237 }
00238
00239 Teuchos::RCP<NOX::Abstract::MultiVector>
00240 NOX::Thyra::Vector::
00241 createMultiVector(int numVecs, NOX::CopyType type) const
00242 {
00243
00244 Teuchos::RCP<const ::Thyra::VectorSpaceBase<double> > space =
00245 thyraVec->space();
00246
00247
00248 Teuchos::RCP< ::Thyra::MultiVectorBase<double> > mv =
00249 createMembers(*space, numVecs);
00250
00251
00252 if (type == NOX::DeepCopy) {
00253 for (int i=0; i<numVecs; i++) {
00254 Teuchos::RCP< ::Thyra::VectorBase<double> > v = mv->col(i);
00255 ::Thyra::copy(*thyraVec, v.get());
00256 }
00257 }
00258
00259
00260 Teuchos::RCP<NOX::Thyra::MultiVector> nmv =
00261 Teuchos::rcp(new NOX::Thyra::MultiVector(mv));
00262
00263 return nmv;
00264 }
00265
00266 double
00267 NOX::Thyra::Vector::
00268 norm(NOX::Abstract::Vector::NormType type) const
00269 {
00270 if (type == NOX::Abstract::Vector::TwoNorm)
00271 return ::Thyra::norm_2(*thyraVec);
00272 else if (type == NOX::Abstract::Vector::OneNorm)
00273 return ::Thyra::norm_1(*thyraVec);
00274 else
00275 return ::Thyra::norm_inf(*thyraVec);
00276 }
00277
00278 double
00279 NOX::Thyra::Vector::
00280 norm(const NOX::Abstract::Vector& weights) const
00281 {
00282 const NOX::Thyra::Vector& w =
00283 dynamic_cast<const NOX::Thyra::Vector&>(weights);
00284 return ::Thyra::norm_2(*w.thyraVec, *thyraVec);
00285 }
00286
00287 double
00288 NOX::Thyra::Vector::
00289 innerProduct(const NOX::Abstract::Vector& y) const
00290 {
00291 const NOX::Thyra::Vector& yy =
00292 dynamic_cast<const NOX::Thyra::Vector&>(y);
00293 return thyraVec->space()->scalarProd(*thyraVec, *yy.thyraVec);
00294 }
00295
00296 int
00297 NOX::Thyra::Vector::
00298 length() const
00299 {
00300 return thyraVec->space()->dim();
00301 }
00302
00303 void
00304 NOX::Thyra::Vector::
00305 print(std::ostream& stream) const
00306 {
00307
00308 thyraVec->describe(*Teuchos::fancyOStream<char>(Teuchos::rcp(&stream,false)), Teuchos::VERB_HIGH);
00309 return;
00310 }
00311