EpetraExt Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
EpetraExt_SubCopy_CrsMatrix.cpp
Go to the documentation of this file.
1//@HEADER
2// ***********************************************************************
3//
4// EpetraExt: Epetra Extended - Linear Algebra Services Package
5// Copyright (2011) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ***********************************************************************
40//@HEADER
41
43
44#include <Epetra_CrsMatrix.h>
45#include <Epetra_Map.h>
46#include <Epetra_Import.h>
50#include <vector>
51
52namespace EpetraExt {
53
56{
57 if( newObj_ ) delete newObj_;
58}
59
60template<typename int_type>
64{
65 origObj_ = &orig;
66
67 //Error, must be local indices
68 assert( orig.Filled() );
69
70 //test maps, new map must be subset of old
71 const Epetra_Map & oRowMap = orig.RowMap();
72 const Epetra_Map & oColMap = orig.ColMap();
73
74 int oNumRows = oRowMap.NumMyElements();
75 (void) oNumRows; // Silence "unused variable" compiler warning.
76 int oNumCols = oColMap.NumMyElements();
77 int nNumRows = newRowMap_.NumMyElements();
78 int nNumDomain = newDomainMap_.NumMyElements();
79
80 bool matched = true;
81
82 // Make sure all rows in newRowMap are already on this processor
83 for( int i = 0; i < nNumRows; ++i )
84 matched = matched && ( oRowMap.MyGID(newRowMap_.GID64(i)) );
85 if( !matched ) std::cerr << "EDT_CrsMatrix_SubCopy: Bad new_row_Map. GIDs of new row map must be GIDs of the original row map on the same processor.\n";
86
87 // Make sure all GIDs in the new domain map are GIDs in the old domain map
89 Epetra_IntSerialDenseVector pidList(nNumDomain);
90 int_type* newDomainMap_MyGlob = 0;
91 newDomainMap_.MyGlobalElementsPtr(newDomainMap_MyGlob);
92 oColMap.RemoteIDList(newDomainMap_.NumMyElements(), newDomainMap_MyGlob, pidList.Values(), 0);
93 for( int i = 0; i < nNumDomain; ++i )
94 matched = matched && ( pidList[i]>=0 );
95 }
96
97 if( !matched ) std::cout << "EDT_CrsMatrix_SubCopy: Bad newDomainMap. One or more GIDs in new domain map are not part of original domain map.\n";
98 assert( matched );
99
100
101 // Next build new column map
102 Epetra_IntSerialDenseVector pidList(oNumCols);
103 Epetra_IntSerialDenseVector lidList(oNumCols);
104 Epetra_IntSerialDenseVector sizeList(oNumCols);
105 int_type* oColMap_MyGlob = 0;
106 oColMap.MyGlobalElementsPtr(oColMap_MyGlob);
107 newDomainMap_.RemoteIDList(oColMap.NumMyElements(), oColMap_MyGlob, pidList.Values(), 0);
108 int numNewCols = 0;
109 typename Epetra_GIDTypeSerialDenseVector<int_type>::impl newColMapGidList(oNumCols);
110 int_type * origColGidList = 0;
111 oColMap.MyGlobalElementsPtr(origColGidList);
112 for( int i = 0; i < oNumCols; ++i )
113 if (pidList[i] >=0)
114 newColMapGidList[numNewCols++]= origColGidList[i];
115 newColMap_ = Epetra_Map(-1, numNewCols, newColMapGidList.Values(), 0, oColMap.Comm());
116
117 importer_ = new Epetra_Import(newRowMap_, oRowMap);
118
120
121 newObj_ = newMatrix;
122
123 newObj_->Import(*origObj_, *importer_, Add);
124
125 newObj_->FillComplete();
126
127 return *newObj_;
128}
129
130//==============================================================================
131
135{
136 const Epetra_Map & oRowMap = orig.RowMap();
137 const Epetra_Map & oColMap = orig.ColMap();
138
139#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
140 if(oRowMap.GlobalIndicesInt() && oColMap.GlobalIndicesInt()) {
141 return transform<int>(orig);
142 }
143 else
144#endif
145#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
146 if(oRowMap.GlobalIndicesLongLong() && oColMap.GlobalIndicesLongLong()) {
147 return transform<long long>(orig);
148 }
149 else
150#endif
151 throw "CrsMatrix_SubCopy::operator(): GlobalIndices type unknown";
152}
153
154//==============================================================================
156{
157
158 if (newObj_->Filled()) newObj_->PutScalar(0.0); // zero contents
159
160 newObj_->Import(*origObj_, *importer_, Add);
161
162 newObj_->FillComplete();
163
164
165 return (true);
166}
167
168//==============================================================================
170{
171 if (!newObj_->Filled()) return(false); // Must have fillCompleted
172
173 origObj_->Export(*newObj_, *importer_, Add);
174
175 origObj_->FillComplete();
176
177 return (true);
178}
179
180} // namespace EpetraExt
181
Add
Copy
NewTypeRef transform(OriginalTypeRef orig)
bool fwd()
Forward transfer of data from orig object input in the operator() method call to the new object creat...
bool rvs()
Reverse transfer of data from new object created in the operator() method call to the orig object inp...
NewTypeRef operator()(OriginalTypeRef orig)
Transformation Operator.
int RemoteIDList(int NumIDs, const int *GIDList, int *PIDList, int *LIDList) const
long long GID64(int LID) const
bool SameAs(const Epetra_BlockMap &Map) const
bool GlobalIndicesInt() const
const Epetra_Comm & Comm() const
int NumMyElements() const
bool MyGID(int GID_in) const
bool GlobalIndicesLongLong() const
int MyGlobalElementsPtr(int *&MyGlobalElementList) const
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.