2
/* ***********************************************************************
4
// TSFExtended: Trilinos Solver Framework Extended
5
// Copyright (2004) Sandia Corporation
7
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8
// license for use of this work by or on behalf of the U.S. Government.
10
// This library is free software; you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as
12
// published by the Free Software Foundation; either version 2.1 of the
13
// License, or (at your option) any later version.
15
// This library is distributed in the hope that it will be useful, but
16
// WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
// Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public
21
// License along with this library; if not, write to the Free Software
22
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
26
// **********************************************************************/
29
#ifndef TSFLOADABLEBLOCKOPERATOR_IMPL_HPP
30
#define TSFLOADABLEBLOCKOPERATOR_IMPL_HPP
32
#include "SundanceDefs.hpp"
33
#include "TSFLoadableBlockOperatorDecl.hpp"
35
#ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
36
#include "TSFSimpleBlockOpImpl.hpp"
43
using namespace Teuchos;
45
template <class Scalar> inline
46
LoadableBlockOperator<Scalar>:: LoadableBlockOperator(
47
const VectorSpace<Scalar>& domain,
49
const RefCountPtr<Array<int> >& isBCCol,
50
const RefCountPtr<std::set<int> >& remoteBCCols,
51
const VectorSpace<Scalar>& range,
53
const RefCountPtr<Array<int> >& isBCRow)
54
: SimpleBlockOp<Scalar>(domain, range),
57
remoteBCCols_(remoteBCCols),
58
lowestLocalRow_(lowestLocalRow),
59
lowestLocalCol_(lowestLocalCol),
60
highestLocalRow_(lowestLocalRow + range.numLocalElements()),
61
highestLocalCol_(lowestLocalCol + domain.numLocalElements())
65
template <class Scalar> inline
66
void LoadableBlockOperator<Scalar>::addToRow(int globalRowIndex,
68
const int* globalColumnIndices,
69
const Scalar* elementValues)
71
if (globalRowIndex < lowestLocalRow_ || globalRowIndex >= highestLocalRow_) return;
75
Array<Scalar> intVals;
76
bcCols.reserve(nElemsToInsert);
77
intCols.reserve(nElemsToInsert);
78
bcVals.reserve(nElemsToInsert);
79
intVals.reserve(nElemsToInsert);
81
const Array<int>& isBCCol = *isBCCol_;
83
for (int i=0; i<nElemsToInsert; i++)
85
int g = globalColumnIndices[i];
86
if (g < lowestLocalCol_ || g >= highestLocalCol_)
88
if (remoteBCCols_->find(g) != remoteBCCols_->end()) bcCols.append(g);
89
else intCols.append(g);
93
int localCol = g - lowestLocalCol_;
94
if (isBCCol[localCol])
97
bcVals.append(elementValues[i]);
102
intVals.append(elementValues[i]);
107
if ((*isBCRow_)[globalRowIndex - lowestLocalRow_])
109
if (intCols.size() > 0U) /* do (BC, internal) block */
111
TEST_FOR_EXCEPTION(true, std::logic_error,
112
"There should be no entries in the (BC, internal) block");
114
if (bcCols.size() > 0U) /* do (BC, BC) block */
116
loadableBlock(1,1)->addToRow(globalRowIndex, bcCols.size(),
117
&(bcCols[0]), &(bcVals[0]));
122
if (intCols.size() > 0U) /* do (internal, internal) block */
124
loadableBlock(0,0)->addToRow(globalRowIndex, intCols.size(),
125
&(intCols[0]), &(intVals[0]));
127
if (bcCols.size() > 0U) /* do (internal, BC) block */
129
loadableBlock(0,1)->addToRow(globalRowIndex, bcCols.size(),
130
&(bcCols[0]), &(bcVals[0]));
136
template <class Scalar> inline
137
void LoadableBlockOperator<Scalar>::zero()
139
for (int i=0; i<this->numBlockRows(); i++)
141
for (int j=0; j<this->numBlockCols(); j++)
143
if (i==1 && j==0) continue;
144
this->loadableBlock(i,j)->zero();
151
template <class Scalar> inline
152
RCP<LoadableMatrix<Scalar> >
153
LoadableBlockOperator<Scalar>::loadableBlock(int i, int j)
155
return this->getNonconstBlock(i,j).matrix();