Go to the documentation of this file.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 #ifndef TSFPARTITIONED_TO_MONOLITHIC_CONVERTER_HPP
00030 #define TSFPARTITIONED_TO_MONOLITHIC_CONVERTER_HPP
00031
00032 #include "TSFVectorSpaceImpl.hpp"
00033 #include "TSFVectorImpl.hpp"
00034 #include "TSFVectorType.hpp"
00035 #include <set>
00036
00037 namespace TSFExtended
00038 {
00039 using namespace Teuchos;
00040 using namespace Thyra;
00041
00042
00043 class PartitionedToMonolithicConverter
00044 {
00045 public:
00046
00047
00048 PartitionedToMonolithicConverter(
00049 const VectorSpace<double>& partitionedSpace,
00050 const RCP<Array<int> >& isBCCol,
00051 const VectorSpace<double>& monolithicSpace
00052 ) : partitionedSpace_(partitionedSpace),
00053 monolithicSpace_(monolithicSpace),
00054 indices_(2)
00055 {
00056 int n = monolithicSpace.numLocalElements();
00057 int low = monolithicSpace.lowestLocallyOwnedIndex();
00058
00059 indices_[0].reserve(n);
00060 indices_[1].reserve(n);
00061
00062 const Array<int>& bc = *isBCCol;
00063
00064 for (int i=0; i<n; i++)
00065 {
00066 indices_[bc[i]].append(low+i);
00067 }
00068 }
00069
00070
00071 void convert(
00072 const Vector<double>& in,
00073 Vector<double>& out) const
00074 {
00075 TEST_FOR_EXCEPTION(in.space().numBlocks() != 2, std::runtime_error,
00076 "PartitionedToMonolithicConverter::convert() expects 2 blocks "
00077 "in input vector. Input vector has numBlocks()="
00078 << in.space().numBlocks());
00079 Array<Vector<double> > x(2);
00080 x[0] = in.getBlock(0);
00081 x[1] = in.getBlock(1);
00082
00083 cout << "index array=" << indices_ << std::endl;
00084
00085 for (int b=0; b<2; b++)
00086 {
00087 VectorSpace<double> space = x[b].space();
00088 int j=0;
00089 for (SequentialIterator<double> i=space.begin(); i!=space.end(); i++,j++)
00090 {
00091 double val = x[b][i];
00092 int globalIndex = indices_[b][j];
00093 out.setElement(globalIndex, val);
00094 }
00095 }
00096 }
00097
00098 protected:
00099
00100 private:
00101 VectorSpace<double> partitionedSpace_;
00102 VectorSpace<double> monolithicSpace_;
00103 Array<Array<int> > indices_;
00104 };
00105 }
00106
00107
00108 #endif