Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
MultiVector_def.hpp
1#ifndef MULTIVECTOR_DEF_hpp
2#define MULTIVECTOR_DEF_hpp
3#include "MultiVector_decl.hpp"
4#include "BlockMultiVector_decl.hpp"
5
14
15namespace FEDD {
16
17template <class SC, class LO, class GO, class NO>
18MultiVector<SC,LO,GO,NO>::MultiVector():
19multiVector_(),
20map_(),
21importer_(),
22exporter_()
23{
24
25}
26
27
28template <class SC, class LO, class GO, class NO>
29MultiVector<SC,LO,GO,NO>::MultiVector( MapConstPtr_Type map, UN nmbVectors ):
30multiVector_( ),
31map_(map),
32importer_(),
33exporter_()
34{
35 multiVector_ = Teuchos::RCP( new TpetraMultiVector_Type( map->getTpetraMap(), nmbVectors ));
36}
37
38template <class SC, class LO, class GO, class NO>
39MultiVector<SC,LO,GO,NO>::MultiVector( TpetraMultiVectorPtr_Type& tpetraMVPtrIn ):
40multiVector_( tpetraMVPtrIn ),
41map_(),
42importer_(),
43exporter_()
44{
45 map_.reset( new Map_Type( tpetraMVPtrIn->getMap() ) );
46}
47
48template <class SC, class LO, class GO, class NO>
49MultiVector<SC,LO,GO,NO>::MultiVector( MultiVectorConstPtr_Type mvIn ):
50multiVector_( ),
51map_(),
52importer_(),
53exporter_()
54{
55 multiVector_ =Teuchos::RCP( new TpetraMultiVector_Type( mvIn->getMap()->getTpetraMap(), mvIn->getNumVectors() ));
56 map_.reset( new Map_Type( *mvIn->getMap() ) );
57 for (UN j=0; j<this->getNumVectors(); j++) {
58 Teuchos::ArrayRCP< const SC > valuesIn = mvIn->getData(j);
59 Teuchos::ArrayRCP< SC > valuesThis = this->getDataNonConst(j);
60 for (UN i=0; i<valuesThis.size(); i++)//can this be quicker?
61 valuesThis[i] = valuesIn[i];
62 }
63}
64
65template <class SC, class LO, class GO, class NO>
69
70template <class SC, class LO, class GO, class NO>
71typename MultiVector<SC,LO,GO,NO>::MapConstPtr_Type MultiVector<SC,LO,GO,NO>::getMap() const{
72 return map_;
73}
74
75template <class SC, class LO, class GO, class NO>
76typename MultiVector<SC,LO,GO,NO>::MapPtr_Type MultiVector<SC,LO,GO,NO>::getMapNonConst() {
77 return Teuchos::rcp_const_cast<Map_Type>( map_ );
78}
79
80template <class SC, class LO, class GO, class NO>
81typename MultiVector<SC,LO,GO,NO>::TpetraMapConstPtr_Type MultiVector<SC,LO,GO,NO>::getMapTpetra() const{
82 TEUCHOS_TEST_FOR_EXCEPTION(multiVector_.is_null(),std::runtime_error,"RCP<MultiVector> is null.")
83
84 return multiVector_->getMap();
85}
86
87// checking whether multivector is null
88template <class SC, class LO, class GO, class NO>
90 return multiVector_.is_null();
91}
92
93template <class SC, class LO, class GO, class NO>
94void MultiVector<SC,LO,GO,NO>::replaceGlobalValue (GO globalRow, UN vectorIndex, const SC &value){
95 multiVector_->replaceGlobalValue( globalRow, vectorIndex, value );
96}
97
98template <class SC, class LO, class GO, class NO>
99void MultiVector<SC,LO,GO,NO>::replaceLocalValue (LO localRow, UN vectorIndex, const SC &value){
100 multiVector_->replaceLocalValue( localRow, vectorIndex, value );
101}
102
103template <class SC, class LO, class GO, class NO>
104void MultiVector<SC,LO,GO,NO>::sumIntoGlobalValue (GO globalRow, UN vectorIndex, const SC &value){
105 multiVector_->sumIntoGlobalValue( globalRow, vectorIndex, value );
106}
108template <class SC, class LO, class GO, class NO>
109LO MultiVector<SC,LO,GO,NO>::getLocalLength() const{
110 return multiVector_->getLocalLength();
112
113template <class SC, class LO, class GO, class NO>
114Teuchos::ArrayRCP< const SC > MultiVector<SC,LO,GO,NO>::getData(UN i) const{
115 return multiVector_->getData(i);
116}
117
118template <class SC, class LO, class GO, class NO>
119Teuchos::ArrayRCP< SC > MultiVector<SC,LO,GO,NO>::getDataNonConst(UN i) const{
120 return multiVector_->getDataNonConst(i);
121}
122
123
124template <class SC, class LO, class GO, class NO>
126 return multiVector_->getNumVectors();
127}
128
129template <class SC, class LO, class GO, class NO>
130typename MultiVector<SC,LO,GO,NO>::TpetraMultiVectorConstPtr_Type MultiVector<SC,LO,GO,NO>::getTpetraMultiVector() const{
131 return multiVector_;
133
134template <class SC, class LO, class GO, class NO>
135typename MultiVector<SC,LO,GO,NO>::TpetraMultiVectorPtr_Type MultiVector<SC,LO,GO,NO>::getTpetraMultiVectorNonConst() {
136 return multiVector_;
137}
138
139template <class SC, class LO, class GO, class NO>
140void MultiVector<SC,LO,GO,NO>::print(Teuchos::EVerbosityLevel verbLevel) const{
141
142 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
143 multiVector_->describe(*out,verbLevel);
145
146#if __cplusplus >= 202002L // >= C++20
147template <typename SC, typename LO, typename GO, typename NO>
148Teuchos::RCP<Thyra::MultiVectorBase<SC> > MultiVector<SC,LO,GO,NO>::getThyraMultiVector( ) requires std::same_as<SC,double> {
149
150 auto thyTpMap = Thyra::tpetraVectorSpace<SC,LO,GO,NO>(multiVector_->getMap()); //Thyra::tpetraVectorSpace<SC,LO,GO,NO>(Teuchos::rcp_dynamic_cast<const TpetraMap_Type>(multiVector_->getMap())->getTpetraMap());
151 Teuchos::RCP<Tpetra::MultiVector<SC,LO,GO,NO>> tpMV = multiVector_;
152 auto thyDomMap =Thyra::tpetraVectorSpace<SC,LO,GO,NO>(Tpetra::createLocalMapWithNode<LO,GO,NO>(multiVector_->getNumVectors(), multiVector_->getMap()->getComm()));
153 auto thyMV = rcp(new Thyra::TpetraMultiVector<SC,LO,GO,NO>());
154 thyMV->initialize(thyTpMap, thyDomMap, tpMV);
155 return thyMV;
156}
157
158template <typename SC, typename LO, typename GO, typename NO>
159Teuchos::RCP<const Thyra::MultiVectorBase<SC> > MultiVector<SC,LO,GO,NO>::getThyraMultiVectorConst( ) const requires std::same_as<SC,double>{
160
161 auto thyTpMap = Thyra::tpetraVectorSpace<SC,LO,GO,NO>(multiVector_->getMap()); //Thyra::tpetraVectorSpace<SC,LO,GO,NO>(Teuchos::rcp_dynamic_cast<const TpetraMap_Type>(multiVector_->getMap())->getTpetraMap());
162 Teuchos::RCP<Tpetra::MultiVector<SC,LO,GO,NO>> tpMV = multiVector_;
163 auto thyDomMap =Thyra::tpetraVectorSpace<SC,LO,GO,NO>(Tpetra::createLocalMapWithNode<LO,GO,NO>(multiVector_->getNumVectors(), multiVector_->getMap()->getComm()));
164 auto thyMV = rcp(new Thyra::TpetraMultiVector<SC,LO,GO,NO>());
165 thyMV->initialize(thyTpMap, thyDomMap, tpMV);
166
167 return thyMV;
168}
169
170#else // <= C++17
172template <typename SC, typename LO, typename GO, typename NO>
173template <typename SCALAR, typename>
174Teuchos::RCP<Thyra::MultiVectorBase<SCALAR> >
175MultiVector<SC,LO,GO,NO>::getThyraMultiVector( ) {
176
177 auto thyTpMap = Thyra::tpetraVectorSpace<SCALAR,LO,GO,NO>(multiVector_->getMap()); //Thyra::tpetraVectorSpace<SC,LO,GO,NO>(Teuchos::rcp_dynamic_cast<const TpetraMap_Type>(multiVector_->getMap())->getTpetraMap());
178 Teuchos::RCP<Tpetra::MultiVector<SCALAR,LO,GO,NO>> tpMV = multiVector_;
179 auto thyDomMap =Thyra::tpetraVectorSpace<SCALAR,LO,GO,NO>(Tpetra::createLocalMapWithNode<LO,GO,NO>(multiVector_->getNumVectors(), multiVector_->getMap()->getComm()));
180 auto thyMV = rcp(new Thyra::TpetraMultiVector<SCALAR,LO,GO,NO>());
181 thyMV->initialize(thyTpMap, thyDomMap, tpMV);
182
183 return thyMV;
184}
185#ifdef HAVE_EXPLICIT_INSTANTIATION
186template Teuchos::RCP<Thyra::MultiVectorBase<double>> MultiVector<double, default_lo, default_go, default_no>::getThyraMultiVector<double, void>();
187#endif
188
189template <typename SC, typename LO, typename GO, typename NO>
190template <typename SCALAR, typename>
191Teuchos::RCP<const Thyra::MultiVectorBase<SCALAR> >
192MultiVector<SC,LO,GO,NO>::getThyraMultiVectorConst( ) const {
193
194 auto thyTpMap = Thyra::tpetraVectorSpace<SCALAR,LO,GO,NO>(multiVector_->getMap()); //Thyra::tpetraVectorSpace<SC,LO,GO,NO>(Teuchos::rcp_dynamic_cast<const TpetraMap_Type>(multiVector_->getMap())->getTpetraMap());
195 Teuchos::RCP<Tpetra::MultiVector<SCALAR,LO,GO,NO>> tpMV = multiVector_;
196 auto thyDomMap =Thyra::tpetraVectorSpace<SCALAR,LO,GO,NO>(Tpetra::createLocalMapWithNode<LO,GO,NO>(multiVector_->getNumVectors(), multiVector_->getMap()->getComm()));
197 auto thyMV = rcp(new Thyra::TpetraMultiVector<SCALAR,LO,GO,NO>());
198 thyMV->initialize(thyTpMap, thyDomMap, tpMV);
199
200 return thyMV;
201}
202#ifdef HAVE_EXPLICIT_INSTANTIATION
203template Teuchos::RCP<const Thyra::MultiVectorBase<double>> MultiVector<double, default_lo, default_go, default_no>::getThyraMultiVectorConst<double, void>() const;
204#endif
205
206#endif // __cplusplus >= 202002L
207
208
209
210
211template <class SC, class LO, class GO, class NO>
212void MultiVector<SC,LO,GO,NO>::fromThyraMultiVector( Teuchos::RCP< Thyra::MultiVectorBase<SC> > thyraMV){
213
214 typedef Thyra::TpetraOperatorVectorExtraction<SC,LO,GO,NO> TOVE_Type;
215
216 Teuchos::RCP<TpetraMultiVector_Type> tMV = TOVE_Type::getTpetraMultiVector( thyraMV );
217 multiVector_ = tMV;
218}
219
220template <class SC, class LO, class GO, class NO>
221void MultiVector<SC,LO,GO,NO>::norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms) const {
222 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,"MultiVector in norm2 is null.")
223 multiVector_->norm2(norms);
224}
225
226// Inf Norm of Multivector
227template <class SC, class LO, class GO, class NO>
228void MultiVector<SC,LO,GO,NO>::normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits<SC>::magnitudeType> &normsInf) const {
229 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,"MultiVector in normInf is null.")
230 multiVector_->normInf(normsInf);
231
232}
233
234template <class SC, class LO, class GO, class NO>
235void MultiVector<SC,LO,GO,NO>::abs(MultiVectorConstPtr_Type a) {
236 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,"MultiVector in abs is null.")
237 multiVector_->abs( *a->getTpetraMultiVector());
238}
239
240template <class SC, class LO, class GO, class NO>
241void MultiVector<SC,LO,GO,NO>::dot(MultiVectorConstPtr_Type a, const Teuchos::ArrayView< typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots) const {
242 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,"MultiVector in dot is null.")
243 multiVector_->dot( *a->getTpetraMultiVector(), dots );
244}
245
246template <class SC, class LO, class GO, class NO>
247void MultiVector<SC,LO,GO,NO>::update( const SC& alpha, const MultiVector_Type& A, const SC& beta) {
248 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,"MultiVectors for update have different number of vectors.")
249 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta );
250}
251
252template <class SC, class LO, class GO, class NO>
253void MultiVector<SC,LO,GO,NO>::update( const SC& alpha, const MultiVector_Type& A, const SC& beta , const MultiVector_Type& B, const SC& gamma) {
254 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,"MultiVectors for update have different number of vectors.")
255
256 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta, *B.getTpetraMultiVector(), gamma );
257
258}
259
260template <class SC, class LO, class GO, class NO>
261void MultiVector<SC,LO,GO,NO>::putScalar( const SC& alpha ){
262 multiVector_->putScalar( alpha );
263}
264
265template <class SC, class LO, class GO, class NO>
266void MultiVector<SC,LO,GO,NO>::scale( const SC& alpha ){
267 multiVector_->scale( alpha );
268}
269
270template <class SC, class LO, class GO, class NO>
271void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B, const SC &beta){
272 multiVector_->multiply( transA, transB, alpha, *A->getTpetraMultiVector(), *B->getTpetraMultiVector(), beta );
273}
274
275#if __cplusplus >= 202002L // >= C++20
276template <class SC, class LO, class GO, class NO>
277void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SC &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B, const SC &beta) requires std::same_as<SC,double>{
278// if (this->getMap()->getCommNonConst()->getRank()==0)
279// std::cout << "### For testing purposes only." << std::endl;
280
281 for (int i=0; i<A->size(); i++){
282 MultiVectorConstPtr_Type a = A->getBlock(i);
283 MultiVectorConstPtr_Type b = B->getBlock(i);
284 if ( i==0 )
285 this->multiply( transA, transB, alpha, a, b, beta );
286 else
287 this->multiply( transA, transB, alpha, a, b, Teuchos::ScalarTraits<SC>::one() );
288 }
289
290}
291#else // <= C++17
292template <typename SC, typename LO, typename GO, typename NO>
293template <typename SCALAR, typename>
294void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const SCALAR &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B, const SCALAR &beta) {
295// if (this->getMap()->getCommNonConst()->getRank()==0)
296// std::cout << "### For testing purposes only." << std::endl;
297
298 for (int i=0; i<A->size(); i++){
299 MultiVectorConstPtr_Type a = A->getBlock(i);
300 MultiVectorConstPtr_Type b = B->getBlock(i);
301 if ( i==0 )
302 this->multiply( transA, transB, alpha, a, b, beta );
303 else
304 this->multiply( transA, transB, alpha, a, b, Teuchos::ScalarTraits<SCALAR>::one() );
305 }
306
307}
308#ifdef HAVE_EXPLICIT_INSTANTIATION
309template void MultiVector<double, default_lo, default_go, default_no>::multiply<double, void>(Teuchos::ETransp transA, Teuchos::ETransp transB, const double &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B, const double &beta);
310#endif
311
312
313#endif
314
315template <class SC, class LO, class GO, class NO>
316void MultiVector<SC,LO,GO,NO>::importFromVector( MultiVectorConstPtr_Type mvIn, bool reuseImport, std::string combineMode, std::string type) {
317
318 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,"MultiVectors for fillFromVector have different number of vectors.")
319
320 if ( importer_.is_null() || !reuseImport) {
321 if (type=="Forward")
322 importer_ = Teuchos::RCP(new Tpetra::Import<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
323 else if(type=="Reverse")
324 importer_ = Teuchos::RCP(new Tpetra::Import<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
325 else
326 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown type for import. Choose Forward or Reverse")
327 }
328 else{
329 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getSourceMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,"Source maps of Importer and Multivector are not the same.")
330 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getTargetMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,"Target maps of Importer and Multivector are not the same.")
331 }
332
333
334 if (type=="Forward") {
335 if ( !combineMode.compare("Insert") )
336 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
337 else if ( !combineMode.compare("Add") )
338 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
339 else
340 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown combine mode.")
341 }
342 else if(type=="Reverse"){
343 if ( !combineMode.compare("Insert") )
344 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
345 else if ( !combineMode.compare("Add") )
346 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
347 else
348 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown combine mode.")
349 }
350 else
351 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown type for import. Choose Forward or Reverse")
352}
353
354template <class SC, class LO, class GO, class NO>
355void MultiVector<SC,LO,GO,NO>::exportFromVector( MultiVectorConstPtr_Type mvIn, bool reuseExport, std::string combineMode, std::string type) {
356 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,"MultiVectors for exportToVector have different number of vectors.")
357
358 if ( exporter_.is_null() || !reuseExport) {
359 if (type=="Forward")
360 exporter_ = Teuchos::RCP(new Tpetra::Export<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
361 else if(type=="Reverse")
362 exporter_ = Teuchos::RCP(new Tpetra::Export<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
363 else
364 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown type for export. Choose Forward or Reverse")
365 }
366 else{
367 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getSourceMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,"Source maps of Exporter and Multivector are not the same.")
368 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getTargetMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,"Target maps of Exporter and Multivector are not the same.")
369 }
370 if (type=="Forward") {
371 if ( !combineMode.compare("Insert") )
372 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
373 else if ( !combineMode.compare("Add") )
374 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
375 else
376 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown combine mode.")
377 }
378 else if (type=="Reverse") {
379 if ( !combineMode.compare("Insert") )
380 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
381 else if ( !combineMode.compare("Add") )
382 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
383 else
384 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown combine mode.")
385 }
386 else
387 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,"Unknown type for export. Choose Forward or Reverse")
388}
389
390template <class SC, class LO, class GO, class NO>
391void MultiVector<SC,LO,GO,NO>::writeMM(std::string fileName) const{
392 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,"MultiVector in writeMM is null.")
393
394 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
395
396 Tpetra::MatrixMarket::Writer< TpetraCrsMatrix > tpetraWriter;
397
398 tpetraWriter.writeDenseFile(fileName, multiVector_, "multivector", "");
399}
400
401
402template <class SC, class LO, class GO, class NO>
403void MultiVector<SC,LO,GO,NO>::readMM(std::string fileName) const{
404 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,"MultiVector in writeMM is null.")
405
406 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
407 typedef Teuchos::RCP<TpetraCrsMatrix> TpetraCrsMatrixPtr;
408
409 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMultiVector;
410 typedef Teuchos::RCP<TpetraMultiVector> TpetraMultiVectorPtr;
411
412 typedef Tpetra::Map<LO,GO,NO> TpetraMap;
413 typedef Teuchos::RCP<TpetraMap> TpetraMapPtr;
414
415 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
416
417 TpetraMultiVectorPtr tpetraMultiVector = multiVector_; //xTpetraMultiVector.getTpetra_MultiVector();
418
419 Teuchos::RCP<const Tpetra::Map<LO,GO,NO> > tpetraMap = tpetraMultiVector->getMap();
420
421 Tpetra::MatrixMarket::Reader< TpetraCrsMatrix > tpetraReader;
422
423 tpetraMultiVector = tpetraReader.readDenseFile(fileName, multiVector_->getMap()->getComm() ,tpetraMap);
424
425 for (UN j=0; j<this->getNumVectors(); j++) {
426 Teuchos::ArrayRCP< const SC > valuesIn = tpetraMultiVector->getData(j);
427 Teuchos::ArrayRCP< SC > valuesThis = this->getDataNonConst(j);
428 for (UN i=0; i<valuesThis.size(); i++)//can this be quicker?
429 valuesThis[i] = valuesIn[i];
430 }
431
432 //multiVector_->describe(*out,Teuchos::VERB_EXTREME);
433}
434
435
436template <class SC, class LO, class GO, class NO>
437typename MultiVector<SC,LO,GO,NO>::MultiVectorConstPtr_Type MultiVector<SC,LO,GO,NO>::getVector( int i ) const{
438
439 TpetraMultiVectorConstPtr_Type tpetraMV = multiVector_->getVector( i );
440 TpetraMultiVectorPtr_Type tpetraMVNonConst = Teuchos::rcp_const_cast<TpetraMultiVector_Type>( tpetraMV );
441 MultiVectorConstPtr_Type singleMV = Teuchos::rcp( new const MultiVector_Type ( tpetraMVNonConst ) );
442 return singleMV;
443
444}
445
446template <class SC, class LO, class GO, class NO>
447typename MultiVector<SC,LO,GO,NO>::MultiVectorPtr_Type MultiVector<SC,LO,GO,NO>::sumColumns() const{
448
449 MultiVectorPtr_Type sumMV = Teuchos::rcp( new MultiVector_Type ( map_, 1 ) );
450 sumMV->putScalar(0.);
451 for (int i=0; i<this->getNumVectors(); i++)
452 sumMV->getTpetraMultiVectorNonConst()->getVectorNonConst(0)->update( 1., *multiVector_->getVector(i), 1. );
453
454 return sumMV;
455}
456
457template <class SC, class LO, class GO, class NO>
458SC MultiVector<SC,LO,GO,NO>::getMax() const{
459 TEUCHOS_TEST_FOR_EXCEPTION( this->getNumVectors() > 1, std::runtime_error, "numMultiVector>1: max function not implemented!")
460 return multiVector_->getVector(0)->normInf();
461}
462
463//typename MultiVector<SC,LO,GO,NO>::ThyraLinOpPtr_Type MultiVector<SC,LO,GO,NO>::getThyraLinOp(){
464//
465// return ;
466//}
467
468}
469#endif
Definition Map_decl.hpp:30
Definition MultiVector_decl.hpp:61
void replaceLocalValue(LO localRow, UN vectorIndex, const SC &value)
Definition MultiVector_def.hpp:99
Teuchos::ArrayRCP< const SC > getData(UN i) const
Get data of multivector.
Definition MultiVector_def.hpp:114
Teuchos::ArrayRCP< SC > getDataNonConst(UN i) const
Get data of multivector.
Definition MultiVector_def.hpp:119
bool is_null() const
checking whether the multiVector exists
Definition MultiVector_def.hpp:89
MapPtr_Type getMapNonConst()
Return non constant version of underlying map.
Definition MultiVector_def.hpp:76
MapConstPtr_Type getMap() const
Return underlying map.
Definition MultiVector_def.hpp:71
TpetraMapConstPtr_Type getMapTpetra() const
Return direct tpetra map of underlying map.
Definition MultiVector_def.hpp:81
void replaceGlobalValue(GO globalRow, UN vectorIndex, const SC &value)
Replace global value in mv.
Definition MultiVector_def.hpp:94
void sumIntoGlobalValue(GO globalRow, UN vectorIndex, const SC &value)
Update (+=) a value in host memory, using global row index.
Definition MultiVector_def.hpp:104
~MultiVector()
Destructor.
Definition MultiVector_def.hpp:66
UN getNumVectors() const
Get number of multivector (columns)
Definition MultiVector_def.hpp:125
void print(Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_EXTREME) const
Printing mv. Depending on verbosity level, output increases.
Definition MultiVector_def.hpp:140
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36