FEI Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
fei_Vector_Impl.hpp
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright 2005 Sandia Corporation. */
3/* Under the terms of Contract DE-AC04-94AL85000, there is a */
4/* non-exclusive license for use of this work by or on behalf */
5/* of the U.S. Government. Export of this program may require */
6/* a license from the United States Government. */
7/*--------------------------------------------------------------------*/
8
9#ifndef _fei_Vector_Impl_hpp_
10#define _fei_Vector_Impl_hpp_
11
12#include <fei_macros.hpp>
13#include <fei_VectorTraits.hpp>
14
21#include <fei_SharedIDs.hpp>
22#include <fei_VectorSpace.hpp>
23#include <fei_Reducer.hpp>
24#include <fei_Logger.hpp>
25#include <fei_Vector.hpp>
26#include <fei_Vector_core.hpp>
27#include <fei_iosfwd.hpp>
28
29#undef fei_file
30#define fei_file "fei_Vector_Impl.hpp"
31
32#include <fei_ErrMacros.hpp>
33
34namespace fei {
35
56 template<typename T>
57 class Vector_Impl : public fei::Vector, public fei::Vector_core {
58 public:
59
62 T* vector, int numLocalEqns,
63 bool isSolutionVector=false,
64 bool deleteVector=false);
65
67 virtual ~Vector_Impl();
68
72 const char* typeName() const { return(fei::VectorTraits<T>::typeName()); }
73
76 int update(double a,
77 const fei::Vector* x,
78 double b);
79
86 int scatterToOverlap();
87
88 void setCommSizes();
89
93 int gatherFromOverlap(bool accumulate = true);
94
96 int putScalar(double scalar);
97
101 int sumIn(int numValues, const int* indices, const double* values,
102 int vectorIndex=0);
103
107 int copyIn(int numValues, const int* indices, const double* values,
108 int vectorIndex=0);
109
114
118 {
119 set_vector_space( vecSpace );
120 }
121
128 int sumInFieldData(int fieldID,
129 int idType,
130 int numIDs,
131 const int* IDs,
132 const double* data,
133 int vectorIndex=0);
134
141 int copyInFieldData(int fieldID,
142 int idType,
143 int numIDs,
144 const int* IDs,
145 const double* data,
146 int vectorIndex=0);
147
148 int copyInFieldDataLocalIDs(int fieldID,
149 int idType,
150 int numIDs,
151 const int* localIDs,
152 const double* data,
153 int vectorIndex=0);
154
161 int copyOutFieldData(int fieldID,
162 int idType,
163 int numIDs,
164 const int* IDs,
165 double* data,
166 int vectorIndex=0);
167
168 int writeToFile(const char* filename,
169 bool matrixMarketFormat=true);
170
171 int writeToStream(FEI_OSTREAM& ostrm,
172 bool matrixMarketFormat=true);
173
178 {
179 vector_ = vec;
180 }
181
185 T* getUnderlyingVector() { return( vector_ ); }
186 const T* getUnderlyingVector() const { return( vector_ ); }
187
188 int copyOut(int numValues,
189 const int* indices,
190 double* values,
191 int vectorIndex=0) const;
192
195 int copyOut_FE(int nodeNumber, int dofOffset, double& value);
196
197 private:
198 int giveToUnderlyingVector(int numValues,
199 const int* indices,
200 const double* values,
201 bool sumInto=true,
202 int vectorIndex=0);
203
204 int copyOutOfUnderlyingVector(int numValues,
205 const int* indices,
206 double* values,
207 int vectorIndex=0) const;
208
209 int sumIntoFEVector(int blockID,
210 int connOffset,
211 int numNodes,
212 const int* nodeNumbers,
213 const int* numIndicesPerNode,
214 const int* dof_ids,
215 const double* values);
216
220
223 std::string dbgprefix_;
224 };//class Vector_Impl
225
226} //namespace fei
227
228//----------------------------------------------------------------------------
229template<typename T>
231 T* vector, int numLocalEqns,
232 bool isSolutionVector,
233 bool deleteVector)
234 : Vector_core(vecSpace, numLocalEqns),
235 vector_(vector),
236 isSolution_(isSolutionVector),
237 deleteVector_(deleteVector),
238 localProc_(0),
239 numProcs_(1),
240 dbgprefix_("VecImpl: ")
241{
242 if (strcmp(snl_fei::FEVectorTraits<T>::typeName(), "unsupported")) {
243 setFEVector(true);
244 }
245 else {
246 setFEVector(false);
247 }
248
249 localProc_ = fei::localProc(vecSpace->getCommunicator());
250 numProcs_ = fei::numProcs(vecSpace->getCommunicator());
251
252 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
254 os << dbgprefix_<<" ctor, numLocalEqns="<<numLocalEqns
255 <<", typeName: "<<typeName()<<FEI_ENDL;
256 }
257
258 std::vector<int> idTypes;
259 vecSpace->getIDTypes(idTypes);
260 std::vector<int> eqns;
261 std::vector<double> zeros;
262 for(size_t i=0; i<idTypes.size(); ++i) {
263 int idType = idTypes[i];
264 fei::SharedIDs<int>& sharedIDs = vecSpace->getSharedIDs(idType);
265 const fei::SharedIDs<int>::map_type& idMap = sharedIDs.getSharedIDs();
267 iter = idMap.begin(), iterEnd = idMap.end();
268 for(; iter!=iterEnd; ++iter) {
269 int ID = iter->first;
270 int eqn;
271 vecSpace->getGlobalIndex(idType, ID, eqn);
272 int ndof = vecSpace->getNumDegreesOfFreedom(idType, ID);
273 eqns.resize(ndof);
274 zeros.resize(ndof, 0.0);
275 for(int j=0; j<ndof; ++j) eqns[j] = eqn+j;
276 if (!isSolutionVector) {
277 sumIn(ndof, &eqns[0], &zeros[0]);
278 }
279 else {
280 copyIn(ndof, &eqns[0], &zeros[0]);
281 }
282 }
283 }
284
285 setCommSizes();
286 std::vector<CSVec*>& remoteVecs = remotelyOwned();
287 for(size_t i=0; i<remoteVecs.size(); ++i) {
288 remoteVecs[i]->clear();
289 }
290}
291
292//----------------------------------------------------------------------------
293template<typename T>
295{
296 if (deleteVector_) delete vector_;
297}
298
299//----------------------------------------------------------------------------
300template<typename T>
302{
303 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
304 FEI_OSTREAM& os = *output_stream_;
305 os << dbgprefix_<<"putScalar("<<scalar<<")"<<FEI_ENDL;
306 }
307
308 if (haveFEVector()) {
309 if (scalar != 0.0) return(-1);
311 }
312 else {
313 CHK_ERR( fei::VectorTraits<T>::setValues(vector_, firstLocalOffset(), scalar) );
314 }
315 for(unsigned p=0; p<remotelyOwned().size(); ++p) {
316 fei::set_values(*(remotelyOwned()[p]), scalar);
317 }
318 return(0);
319}
320
321//----------------------------------------------------------------------------
322template<typename T>
324 const fei::Vector* x,
325 double b)
326{
327 const fei::Vector_Impl<T>* sx = dynamic_cast<const fei::Vector_Impl<T>* >(x);
328 if (sx != 0) {
329 const T* tx = sx->getUnderlyingVector();
330 return( fei::VectorTraits<T>::update(vector_, a, tx, b) );
331 }
332 else {
333 return( -1 );
334 }
335}
336
337//----------------------------------------------------------------------------
338template<typename T>
340{
341 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
342 FEI_OSTREAM& os = *output_stream_;
343 os << dbgprefix_<<"scatterToOverlap"<<FEI_ENDL;
344 }
345
347}
348
349//----------------------------------------------------------------------------
350template<typename T>
352{
353 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
354 FEI_OSTREAM& os = *output_stream_;
355 os << dbgprefix_<<"setCommSizes"<<FEI_ENDL;
356 }
357
359}
360
361//----------------------------------------------------------------------------
362template<typename T>
364{
365 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
366 FEI_OSTREAM& os = *output_stream_;
367 os << dbgprefix_<<"gatherFromOverlap"<<FEI_ENDL;
368 }
369
370 return( Vector_core::gatherFromOverlap(accumulate) );
371}
372
373//----------------------------------------------------------------------------
374template<typename T>
376 const int* indices, const double* values,
377 int vectorIndex)
378{
379 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
380 FEI_OSTREAM& os = *output_stream_;
381 os << dbgprefix_<<"sumIn(n="<<numValues<<")"<<FEI_ENDL;
382 }
383
384 return( giveToVector(numValues, indices, values, true, vectorIndex) );
385}
386
387//----------------------------------------------------------------------------
388template<typename T>
390 const int* indices, const double* values,
391 int vectorIndex)
392{
393 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
394 FEI_OSTREAM& os = *output_stream_;
395 os << dbgprefix_<<"copyIn(n="<<numValues<<")"<<FEI_ENDL;
396 }
397
398 return( giveToVector(numValues, indices, values, false, vectorIndex) );
399}
400
401//----------------------------------------------------------------------------
402template<typename T>
404 const int* indices,
405 const double* values,
406 bool sumInto,
407 int vectorIndex)
408{
409 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
410 FEI_OSTREAM& os = *output_stream_;
411 os << dbgprefix_<<"giveToUnderlying(";
412 for(int i=0; i<numValues; ++i) {
413 os << "{"<<indices[i]<<","<<values[i]<<"} ";
414 }
415 os<<")"<<FEI_ENDL;
416 }
417
418 int err = fei::VectorTraits<T>::putValuesIn(vector_, firstLocalOffset(),
419 numValues, indices, values,
420 sumInto, isSolution_, vectorIndex);
421 if (err < 0) {
422 return(err);
423 }
424 return(0);
425}
426
427//----------------------------------------------------------------------------
428template<typename T>
430 const int* indices,
431 double* values,
432 int vectorIndex) const
433{
434 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
435 FEI_OSTREAM& os = *output_stream_;
436 os << dbgprefix_<<"copyOutOfUnderlying(n="<<numValues<<")"<<FEI_ENDL;
437 }
438
439 return( fei::VectorTraits<T>::copyOut(vector_, firstLocalOffset(),
440 numValues, indices, values,
441 isSolution_, vectorIndex) );
442}
443
444//----------------------------------------------------------------------------
445template<typename T>
447 int idType,
448 int numIDs,
449 const int* IDs,
450 const double* data,
451 int vectorIndex)
452{
453 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
454 FEI_OSTREAM& os = *output_stream_;
455 os << dbgprefix_<<"sumInFieldData(n="<<numIDs<<")"<<FEI_ENDL;
456 }
457
458 return( assembleFieldData(fieldID, idType, numIDs, IDs, data, true, vectorIndex));
459}
460
461//----------------------------------------------------------------------------
462template<typename T>
464 int idType,
465 int numIDs,
466 const int* IDs,
467 const double* data,
468 int vectorIndex)
469{
470 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
471 FEI_OSTREAM& os = *output_stream_;
472 os << dbgprefix_<<"copyInFieldData(n="<<numIDs<<")"<<FEI_ENDL;
473 }
474
475 return(assembleFieldData(fieldID, idType, numIDs, IDs, data, false, vectorIndex));
476}
477
478//----------------------------------------------------------------------------
479template<typename T>
481 int idType,
482 int numIDs,
483 const int* localIDs,
484 const double* data,
485 int vectorIndex)
486{
487 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
488 FEI_OSTREAM& os = *output_stream_;
489 os << dbgprefix_<<"copyInFieldDataLocalIDs(n="<<numIDs<<")"<<FEI_ENDL;
490 }
491
492 return(assembleFieldDataLocalIDs(fieldID, idType, numIDs, localIDs, data, false, vectorIndex));
493}
494
495//----------------------------------------------------------------------------
496template<typename T>
497int fei::Vector_Impl<T>::copyOut_FE(int nodeNumber, int dofOffset, double& value)
498{
499 return( snl_fei::FEVectorTraits<T>::copyOut(vector_, nodeNumber, dofOffset, value) );
500}
501
502//----------------------------------------------------------------------------
503template<typename T>
505 int idType,
506 int numIDs,
507 const int* IDs,
508 double* data,
509 int vectorIndex)
510{
511 return( Vector_core::copyOutFieldData(fieldID, idType, numIDs, IDs, data,
512 vectorIndex));
513}
514
515//----------------------------------------------------------------------------
516template<typename T>
517int fei::Vector_Impl<T>::writeToFile(const char* filename,
518 bool matrixMarketFormat)
519{
520 return( Vector_core::writeToFile(filename, matrixMarketFormat) );
521}
522
523//----------------------------------------------------------------------------
524template<typename T>
526 bool matrixMarketFormat)
527{
528 return( Vector_core::writeToStream(ostrm, matrixMarketFormat) );
529}
530
531//----------------------------------------------------------------------------
532template<typename T>
534 const int* indices,
535 double* values,
536 int vectorIndex) const
537{
538 if (output_level_ >= fei::BRIEF_LOGS && output_stream_ != NULL) {
539 FEI_OSTREAM& os = *output_stream_;
540 os << dbgprefix_<<"copyOut(n="<<numValues<<")"<<FEI_ENDL;
541 }
542
543 return( Vector_core::copyOut(numValues, indices, values, vectorIndex) );
544}
545
546//----------------------------------------------------------------------------
547template<typename T>
549 int connOffset,
550 int numNodes,
551 const int* nodeNumbers,
552 const int* numIndicesPerNode,
553 const int* dof_ids,
554 const double* values)
555{
556 return( snl_fei::FEVectorTraits<T>::sumInElemVector(vector_, blockID, connOffset,
557 numNodes, nodeNumbers,
558 numIndicesPerNode, dof_ids, values) );
559}
560
561#undef fei_file
562#define fei_file "unknown_file"
563
564#endif // _fei_Vector_Impl_hpp_
565
FEI_OSTREAM * output_stream_
OutputLevel output_level_
map_type & getSharedIDs()
std::map< T, std::set< int > > map_type
int copyInFieldData(int fieldID, int idType, int numIDs, const int *IDs, const double *data, int vectorIndex=0)
int copyOut(int numValues, const int *indices, double *values, int vectorIndex=0) const
int copyOutOfUnderlyingVector(int numValues, const int *indices, double *values, int vectorIndex=0) const
int copyIn(int numValues, const int *indices, const double *values, int vectorIndex=0)
int sumInFieldData(int fieldID, int idType, int numIDs, const int *IDs, const double *data, int vectorIndex=0)
int gatherFromOverlap(bool accumulate=true)
int copyOut_FE(int nodeNumber, int dofOffset, double &value)
int sumIntoFEVector(int blockID, int connOffset, int numNodes, const int *nodeNumbers, const int *numIndicesPerNode, const int *dof_ids, const double *values)
int update(double a, const fei::Vector *x, double b)
int copyOutFieldData(int fieldID, int idType, int numIDs, const int *IDs, double *data, int vectorIndex=0)
const char * typeName() const
void setVectorSpace(fei::SharedPtr< fei::VectorSpace > vecSpace)
Vector_Impl(fei::SharedPtr< fei::VectorSpace > vecSpace, T *vector, int numLocalEqns, bool isSolutionVector=false, bool deleteVector=false)
const T * getUnderlyingVector() const
int copyInFieldDataLocalIDs(int fieldID, int idType, int numIDs, const int *localIDs, const double *data, int vectorIndex=0)
int sumIn(int numValues, const int *indices, const double *values, int vectorIndex=0)
int putScalar(double scalar)
int writeToFile(const char *filename, bool matrixMarketFormat=true)
int giveToUnderlyingVector(int numValues, const int *indices, const double *values, bool sumInto=true, int vectorIndex=0)
fei::SharedPtr< fei::VectorSpace > getVectorSpace() const
void setUnderlyingVector(T *vec)
int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)
virtual int gatherFromOverlap(bool accumulate=true)
int copyOut(int numValues, const int *indices, double *values, int vectorIndex=0) const
virtual int writeToFile(const char *filename, bool matrixMarketFormat=true)
void set_vector_space(fei::SharedPtr< fei::VectorSpace > vspace)
virtual int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)
virtual int scatterToOverlap()
virtual int copyOutFieldData(int fieldID, int idType, int numIDs, const int *IDs, double *data, int vectorIndex=0)
std::vector< CSVec * > & remotelyOwned()
fei::SharedPtr< fei::VectorSpace > get_vector_space() const
void setFEVector(bool flag)
#define CHK_ERR(a)
#define FEI_OSTREAM
#define FEI_ENDL
int localProc(MPI_Comm comm)
@ BRIEF_LOGS
Definition fei_fwd.hpp:90
void set_values(CSVec &vec, double scalar)
int numProcs(MPI_Comm comm)
static int putValuesIn(T *vec, int firstLocalOffset, int numValues, const int *indices, const double *values, bool sum_into, bool isSolnVector=false, int vectorIndex=0)