LifeV
ConfinedOperator.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but 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.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief BelosOperator
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@gmail.com>
32 
33  @date 21-08-2012
34  */
35 
36 #include<lifev/core/operator/ConfinedOperator.hpp>
37 
38 namespace LifeV
39 {
40 namespace Operators
41 {
42 
43 ConfinedOperator::ConfinedOperator ( std::shared_ptr<Epetra_Comm> comm ) :
44  M_oper(),
45  M_blockStructure(),
46  M_blockIndex ( 0 ),
47  M_comm ( comm ),
48  M_map()
49 {
50 
51 }
52 
54 {
55 
56 }
57 
58 
59 int
60 ConfinedOperator::SetUseTranspose ( bool useTranspose )
61 {
62  ASSERT ( M_oper.get() != 0, "ConfinedOperator::SetUseTranspose: Error: M_oper pointer is null" );
63  return M_oper->SetUseTranspose ( useTranspose );
64 }
65 
66 void
68 {
69  M_oper = oper;
70 }
71 
72 void
74 {
75  M_map.reset ( new Epetra_Map ( * ( map.map (Unique) ) ) );
76 }
77 
78 void
80 {
81  M_blockStructure.setBlockStructure ( blockStructure );
82 }
83 
84 void
86 {
87  ASSERT ( M_blockStructure.numBlocks() > 0, "ConfinedOperator::setBlockIndex: Error: M_structure is not initialized" );
88  ASSERT ( index < M_blockStructure.numBlocks(), "ConfinedOperator::setBlockIndex: Error: index out of range" );
89  M_blockIndex = index;
90 }
91 
92 int
94 {
95  ASSERT ( M_oper.get() != 0, "ConfinedOperator::Apply: Error: M_oper pointer is null" );
96  ASSERT ( M_blockStructure.numBlocks() > 0, "ConfinedOperator::Apply: Error: M_structure is not initialized" );
97  ASSERT ( X.MyLength() == Y.MyLength(), "ConfinedOperator::Apply: Error: X and Y must have the same length" );
98 
99  int firstIndex = M_blockStructure.blockFirstIndex ( M_blockIndex );
100  Epetra_MultiVector xtmp ( M_oper->OperatorDomainMap(), 1 );
101  Epetra_MultiVector ytmp ( M_oper->OperatorRangeMap() , 1 );
102 
103  // Extract the values from the vector
104  const Int* gids = M_oper->OperatorDomainMap().MyGlobalElements();
105  const UInt numMyEntries = M_oper->OperatorDomainMap().NumMyElements();
106  Int lid1;
107  Int lid2;
108  for ( UInt i = 0; i < numMyEntries; ++i )
109  {
110  lid1 = X.Map().LID ( gids[i] + firstIndex );
111  lid2 = M_oper->OperatorDomainMap().LID ( gids[i] );
112  ASSERT ( ( lid2 >= 0 ) && ( lid1 >= 0 ), "ConfinedOperator::Apply: Error: lid < 0" );
113  xtmp[0][lid2] = X[0][lid1];
114  }
115 
116  // Apply the operator
117  int result = M_oper->Apply ( xtmp, ytmp );
118 
119  // Copy back the result in the Y vector;
120  Y = X;
121  const Int* gids2 = M_oper->OperatorRangeMap().MyGlobalElements();
122  const UInt numMyEntries2 = M_oper->OperatorRangeMap().NumMyElements();
123  for ( UInt i = 0; i < numMyEntries2; ++i )
124  {
125  lid1 = Y.Map().LID ( gids2[i] + firstIndex );
126  lid2 = M_oper->OperatorRangeMap().LID ( gids2[i] );
127  ASSERT ( ( lid2 >= 0 ) && ( lid1 >= 0 ), "ConfinedOperator::Apply: Error: lid < 0" );
128  Y[0][lid1] = ytmp[0][lid2];
129  }
130 
131  return result;
132 }
133 
134 int
136 {
137  ASSERT ( M_oper.get() != 0, "ConfinedOperator::ApplyInverse: Error: M_oper pointer is null" );
138  ASSERT ( M_blockStructure.numBlocks() > 0, "ConfinedOperator::ApplyInverse: Error: M_structure is not initialized" );
139  ASSERT ( X.MyLength() == Y.MyLength(), "ConfinedOperator::ApplyInverse: Error: X and Y must have the same length" );
140 
141  int firstIndex = M_blockStructure.blockFirstIndex ( M_blockIndex );
142  Epetra_MultiVector xtmp ( M_oper->OperatorRangeMap() , 1 );
143  Epetra_MultiVector ytmp ( M_oper->OperatorDomainMap(), 1 );
144 
145  // Extract the values from the vector
146  const Int* gids = M_oper->OperatorRangeMap().MyGlobalElements();
147  const UInt numMyEntries = M_oper->OperatorRangeMap().NumMyElements();
148  Int lid1;
149  Int lid2;
150  for ( UInt i = 0; i < numMyEntries; ++i )
151  {
152  lid1 = X.Map().LID ( gids[i] + firstIndex );
153  lid2 = M_oper->OperatorRangeMap().LID ( gids[i] );
154  ASSERT ( ( lid2 >= 0 ) && ( lid1 >= 0 ), "ConfinedOperator::ApplyInverse: Error: lid < 0" );
155  xtmp[0][lid2] = X[0][lid1];
156  }
157 
158  // Apply the operator
159  int result = M_oper->ApplyInverse ( xtmp, ytmp );
160 
161  // Copy back the result in the Y vector;
162  Y = X;
163  const Int* gids2 = M_oper->OperatorDomainMap().MyGlobalElements();
164  const UInt numMyEntries2 = M_oper->OperatorDomainMap().NumMyElements();
165  for ( UInt i = 0; i < numMyEntries2; ++i )
166  {
167  lid1 = Y.Map().LID ( gids2[i] + firstIndex );
168  lid2 = M_oper->OperatorDomainMap().LID ( gids2[i] );
169  ASSERT ( ( lid2 >= 0 ) && ( lid1 >= 0 ), "ConfinedOperator::Apply: Error: lid < 0" );
170  Y[0][lid1] = ytmp[0][lid2];
171  }
172 
173  return result;
174 }
175 
176 double
178 {
179  ASSERT ( M_oper.get() != 0, "ConfinedOperator::NormInf: Error: M_oper pointer is null" );
180  return M_oper->NormInf();
181 }
182 
183 const char*
185 {
186  ASSERT ( M_oper.get() != 0, "ConfinedOperator::Label: Error: M_oper pointer is null" );
187  return M_oper->Label();
188 }
189 
190 bool
192 {
193  ASSERT ( M_oper.get() != 0, "ConfinedOperator::UseTranspose: Error: M_oper pointer is null" );
194  return M_oper->UseTranspose();
195 }
196 
197 bool
199 {
200  ASSERT ( M_oper.get() != 0, "ConfinedOperator::HasNormInf: Error: M_oper pointer is null" );
201  return M_oper->HasNormInf();
202 }
203 
206 {
207  ASSERT ( M_oper.get() != 0, "ConfinedOperator::Comm: Error: M_oper pointer is null" );
208  return M_oper->Comm();
209 }
210 
213 {
214  ASSERT ( M_blockStructure.numBlocks() > 0, "ConfinedOperator::OperatorDomainMap: Error: the structure is not known" );
215  return *M_map;
216 }
217 
220 {
221  ASSERT ( M_blockStructure.numBlocks() > 0, "ConfinedOperator::OperatorRangeMap: Error: the structure is not known" );
222  return *M_map;
223 }
224 
225 
226 } // Namespace Operators
227 } // Namespace LifeV
void setBlockStructure(const blockStructure_Type &blockStructure)
double NormInf() const
Returns the infinity norm of the global matrix.
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
virtual const map_Type & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
void updateInverseJacobian(const UInt &iQuadPt)
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
VectorBlockStructure blockStructure_Type
void setOperator(operatorPtr_Type oper)
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
std::shared_ptr< operator_Type > operatorPtr_Type
void setFullMap(const MapEpetra &map)
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual const comm_Type & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
virtual const map_Type & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
virtual const char * Label() const
Returns a character string describing the operator.
ConfinedOperator(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
null constructor and destructor
virtual int Apply(const vector_Type &X, vector_Type &Y) const
Returns the result of a Epetra_Operator applied to a vector_Type X in Y.
virtual int SetUseTranspose(bool useTranspose)
If set true, transpose of this operator will be applied.
virtual int ApplyInverse(const vector_Type &X, vector_Type &Y) const
Returns the result of a Epetra_Operator inverse applied to an vector_Type X in Y. ...
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191