LifeV
CompositeOperator.cpp
Go to the documentation of this file.
1 /*
2  * CompositeOperator.cpp
3  *
4  * Created on: Jul 28, 2012
5  * Author: uvilla
6  */
7 
9 
10 namespace LifeV {
11 namespace Operators {
12 
15  isAlreadyInverted(false)
16 {
17  vects.push_back( static_cast<vector_Type *>(NULL) );
18 }
19 
21 {
22  for( UInt i(1); i < vects.size()-1; ++i)
23  delete vects[i];
24 }
25 
26 int CompositeOperator::pushBack( const operatorPtr_Type & op, const bool inverted_)
27 {
28  if(inverted_ && !op->OperatorDomainMap().SameAs( op->OperatorRangeMap() ) )
29  return -1;
30 
31  if(ops.size() != 0 && !op->OperatorDomainMap().SameAs( OperatorRangeMap()))
32  return -1;
33 
34  ops.push_back(op);
35  inverted.push_back(inverted_);
36  vects.push_back( static_cast<vector_Type *>(NULL) );
37 
38  return 0;
39 }
40 
42 {
43 
44  if(!X.Map().PointSameAs(OperatorDomainMap()))
45  return -2;
46  if(!Y.Map().PointSameAs(OperatorRangeMap()))
47  return -3;
48 
50  return -1;
51 
52  EPETRA_CHK_ERR( allocateTmpVects(X, Y) );
53  // Now vects[0] points to X and vects[end] points to Y
54 
55  for(UInt i(0); i < ops.size(); ++i)
56  {
57  if(!inverted[i])
58  {
59  EPETRA_CHK_ERR( ops[i]->Apply(*vects[i], *vects[i+1]) );
60  }
61  else
62  {
63  EPETRA_CHK_ERR( ops[i]->ApplyInverse(*vects[i], *vects[i+1]) );
64  }
65  }
66 
67  // since vects[end] points to Y there is nothing else to be done :)
68 
69  return 0;
70 }
71 
73 {
74  if(!X.Map().PointSameAs(OperatorDomainMap()))
75  return -2;
76  if(!Y.Map().PointSameAs(OperatorRangeMap()))
77  return -3;
78 
80  return -1;
81 
82  EPETRA_CHK_ERR( allocateTmpVects(X, Y) );
83  // Now vects[0] points to X and vects[end] points to Y
84 
85  for(UInt i(0); i < ops.size(); ++i)
86  {
87  if(!inverted[i])
88  {
89  EPETRA_CHK_ERR( ops[i]->Apply(*vects[i], *vects[i+1]) );
90  }
91  else
92  {
93  EPETRA_CHK_ERR( ops[i]->ApplyInverse(*vects[i], *vects[i+1]) );
94  }
95  }
96 
97  return 0;
98 }
99 
101 {
102  if(X.NumVectors() != Y.NumVectors())
103  return -1;
104 
105  int nVect(X.NumVectors());
106 
107  if( nAllocatedVectorsInMultVect != nVect)
108  {
110  for(UInt i(1); i<vects.size()-1; ++i)
111  vects[i] = new vector_Type(ops[i]->OperatorDomainMap(), nVect);
112  }
113 
114  vects.front() = const_cast<vector_Type *>(&X);
115  vects.back() = &Y;
116 
117  return 0;
118 
119 }
120 
122 {
123 for( UInt i(1); i < vects.size()-1; ++i)
124  delete vects[i];
125 }
126 
127 } /* namespace Operators */
128 } /* namespace LifeV */
virtual int ApplyInverse(const vector_Type &X, vector_Type &Y) const
Applies all the operator (with their flags) starting from the first that was pushed.
int pushBack(const operatorPtr_Type &op, const bool inverted)
The first operator we push is the first to be applied.
void updateInverseJacobian(const UInt &iQuadPt)
virtual int Apply(const vector_Type &X, vector_Type &Y) const
Applies all the operator (with their flags) starting from the first that was pushed.
int allocateTmpVects(const vector_Type &X, vector_Type &Y) const
std::shared_ptr< operator_Type > operatorPtr_Type