EpetraExt Package Browser (Single Doxygen Collection)
Development
Toggle main menu visibility
Loading...
Searching...
No Matches
src
transform
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
42
#include "
EpetraExt_SubCopy_CrsMatrix.h
"
43
44
#include <
Epetra_CrsMatrix.h
>
45
#include <
Epetra_Map.h
>
46
#include <
Epetra_Import.h
>
47
#include <
Epetra_IntSerialDenseVector.h
>
48
#include <
Epetra_LongLongSerialDenseVector.h
>
49
#include <
Epetra_GIDTypeSerialDenseVector.h
>
50
#include <vector>
51
52
namespace
EpetraExt
{
53
54
CrsMatrix_SubCopy::
55
~CrsMatrix_SubCopy
()
56
{
57
if
(
newObj_
)
delete
newObj_
;
58
}
59
60
template
<
typename
int
_type>
61
CrsMatrix_SubCopy::NewTypeRef
62
CrsMatrix_SubCopy::
63
transform
(
OriginalTypeRef
orig )
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
88
if
( !
newRangeMap_
.SameAs(
newDomainMap_
) ) {
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
119
Epetra_CrsMatrix
* newMatrix =
new
Epetra_CrsMatrix
(
Copy
,
newRowMap_
,
newColMap_
, 0);
120
121
newObj_
= newMatrix;
122
123
newObj_
->Import(*
origObj_
, *
importer_
,
Add
);
124
125
newObj_
->FillComplete();
126
127
return
*
newObj_
;
128
}
129
130
//==============================================================================
131
132
CrsMatrix_SubCopy::NewTypeRef
133
CrsMatrix_SubCopy::
134
operator()
(
OriginalTypeRef
orig )
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
//==============================================================================
155
bool
CrsMatrix_SubCopy::fwd
()
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
//==============================================================================
169
bool
CrsMatrix_SubCopy::rvs
()
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
EpetraExt_SubCopy_CrsMatrix.h
Add
Add
Epetra_CrsMatrix.h
Copy
Copy
Epetra_GIDTypeSerialDenseVector.h
Epetra_Import.h
Epetra_IntSerialDenseVector.h
Epetra_LongLongSerialDenseVector.h
Epetra_Map.h
EpetraExt::CrsMatrix_SubCopy::~CrsMatrix_SubCopy
~CrsMatrix_SubCopy()
Destructor.
Definition
EpetraExt_SubCopy_CrsMatrix.cpp:55
EpetraExt::CrsMatrix_SubCopy::transform
NewTypeRef transform(OriginalTypeRef orig)
Definition
EpetraExt_SubCopy_CrsMatrix.cpp:63
EpetraExt::CrsMatrix_SubCopy::fwd
bool fwd()
Forward transfer of data from orig object input in the operator() method call to the new object creat...
Definition
EpetraExt_SubCopy_CrsMatrix.cpp:155
EpetraExt::CrsMatrix_SubCopy::importer_
Epetra_Import * importer_
Definition
EpetraExt_SubCopy_CrsMatrix.h:60
EpetraExt::CrsMatrix_SubCopy::newRangeMap_
Epetra_Map newRangeMap_
Definition
EpetraExt_SubCopy_CrsMatrix.h:59
EpetraExt::CrsMatrix_SubCopy::newColMap_
Epetra_Map newColMap_
Definition
EpetraExt_SubCopy_CrsMatrix.h:57
EpetraExt::CrsMatrix_SubCopy::rvs
bool rvs()
Reverse transfer of data from new object created in the operator() method call to the orig object inp...
Definition
EpetraExt_SubCopy_CrsMatrix.cpp:169
EpetraExt::CrsMatrix_SubCopy::operator()
NewTypeRef operator()(OriginalTypeRef orig)
Transformation Operator.
Definition
EpetraExt_SubCopy_CrsMatrix.cpp:134
EpetraExt::CrsMatrix_SubCopy::newDomainMap_
Epetra_Map newDomainMap_
Definition
EpetraExt_SubCopy_CrsMatrix.h:58
EpetraExt::CrsMatrix_SubCopy::newRowMap_
Epetra_Map newRowMap_
Definition
EpetraExt_SubCopy_CrsMatrix.h:56
EpetraExt::Transform< Epetra_CrsMatrix, Epetra_CrsMatrix >::OriginalTypeRef
Epetra_CrsMatrix & OriginalTypeRef
Definition
EpetraExt_Transform.h:74
EpetraExt::Transform< Epetra_CrsMatrix, Epetra_CrsMatrix >::newObj_
NewTypePtr newObj_
Definition
EpetraExt_Transform.h:218
EpetraExt::Transform< Epetra_CrsMatrix, Epetra_CrsMatrix >::origObj_
OriginalTypePtr origObj_
Definition
EpetraExt_Transform.h:216
EpetraExt::Transform< Epetra_CrsMatrix, Epetra_CrsMatrix >::NewTypeRef
Epetra_CrsMatrix & NewTypeRef
Definition
EpetraExt_Transform.h:79
Epetra_BlockMap::RemoteIDList
int RemoteIDList(int NumIDs, const int *GIDList, int *PIDList, int *LIDList) const
Epetra_BlockMap::GlobalIndicesInt
bool GlobalIndicesInt() const
Epetra_BlockMap::Comm
const Epetra_Comm & Comm() const
Epetra_BlockMap::NumMyElements
int NumMyElements() const
Epetra_BlockMap::MyGID
bool MyGID(int GID_in) const
Epetra_BlockMap::GlobalIndicesLongLong
bool GlobalIndicesLongLong() const
Epetra_BlockMap::MyGlobalElementsPtr
int MyGlobalElementsPtr(int *&MyGlobalElementList) const
Epetra_CrsMatrix
Epetra_GIDTypeSerialDenseVector
Epetra_Import
Epetra_IntSerialDenseVector
Epetra_IntSerialDenseVector::Values
int * Values()
Epetra_Map
EpetraExt
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
Definition
EpetraExt_BlockCrsMatrix.cpp:46
Generated by
1.17.0