LifeV
MonolithicBlockComposed.cpp
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 //@HEADER
3 /*
4 *******************************************************************************
5 
6  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
7  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
8 
9  This file is part of LifeV.
10 
11  LifeV is free software; you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  LifeV is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 #include <lifev/core/LifeV.hpp>
29 
30 #include <lifev/fsi/solver/MonolithicBlockComposed.hpp>
31 
32 namespace LifeV
33 {
34 
35 
36 // ===================================================
37 //! Public Methods
38 // ===================================================
39 
40 void MonolithicBlockComposed::GlobalAssemble()
41 {
42  for (UInt k = 0; k < M_blocks.size(); ++k)
43  {
44  M_blocks[k]->globalAssemble();
45  }
46  // M_blocks[0]->spy("first");
47  // M_blocks[1]->spy("second");
48  // M_blocks[2]->spy("third");
49  // M_blocks[3]->spy("fourth");
50 }
51 
52 void MonolithicBlockComposed::blockAssembling()
53 {
54  for (UInt k = 0; k < M_blocks.size(); ++k)
55  {
56  blockAssembling (k);
57  }
58  // M_coupling[0]->spy("C1");
59  // M_coupling[1]->spy("C2");
60  // M_coupling[2]->spy("C1");
61  // M_coupling[3]->spy("C2");
62 }
63 
64 
65 
66 void MonolithicBlockComposed::coupler ( mapPtr_Type& map,
67  const std::map<ID, ID>& locDofMap,
68  const vectorPtr_Type& numerationInterface,
69  const Real& timeStep,
70  const Real& coefficient,
71  const Real& rescaleFactor,
72  UInt couplingBlock)
73 {
74  matrixPtr_Type coupling (new matrix_Type (*map) );
75  couplingMatrix ( coupling, (*M_couplingFlags) [couplingBlock], M_FESpace, M_offset, locDofMap, numerationInterface, timeStep, 1., coefficient, rescaleFactor);
76  UInt totalDofs ( map->map (Unique)->NumGlobalElements() );
77 
78  coupling->insertValueDiagonal ( 1., 0 , M_offset[couplingBlock] );
79  coupling->insertValueDiagonal ( 1., M_offset[couplingBlock] + M_FESpace[couplingBlock]->map().map (Unique)->NumGlobalElements(), totalDofs );
80 
81  if (couplingBlock != M_coupling.size() + 1)
82  {
83  M_coupling.insert (M_coupling.begin() + couplingBlock, coupling);
84  }
85  else
86  {
87  M_coupling.push_back (coupling);
88  }
89 }
90 
91 void MonolithicBlockComposed::push_back_matrix (const matrixPtr_Type& Mat, const bool recompute)
92 {
93  M_blocks.push_back (Mat);
94  M_recompute[M_blocks.size() - 1] = recompute;
95 }
96 
97 void MonolithicBlockComposed::push_back_oper ( MonolithicBlockComposed& Oper)
98 {
99  super_Type::push_back_oper ( Oper );
100  M_coupling.insert (M_coupling.end(), Oper.couplingVector().begin(), Oper.couplingVector().end() );
101 }
102 
103 void
104 MonolithicBlockComposed::push_back_coupling ( matrixPtr_Type& coupling )
105 {
106  M_coupling.push_back (coupling);
107 }
108 
109 void MonolithicBlockComposed::replace_matrix ( const matrixPtr_Type& Mat, UInt position )
110 {
111  M_blocks[position] = Mat;
112 }
113 
114 void MonolithicBlockComposed::replace_coupling ( const matrixPtr_Type& Mat, UInt position )
115 {
116  M_coupling[position] = Mat;
117 }
118 
119 void MonolithicBlockComposed::addToCoupling ( const matrixPtr_Type& Mat, UInt position)
120 {
121  Mat->globalAssemble();
122  *M_coupling[position] += *Mat;
123 }
124 
125 void MonolithicBlockComposed::addToCoupling ( const Real& entry , UInt row, UInt col, UInt position )
126 {
127  if (!M_coupling[position]->matrixPtr()->Filled() )
128  {
129  M_coupling[position]->setCoefficient (row, col, entry);
130  }
131  else
132  {
133  matrixPtr_Type tmp (new matrix_Type (M_coupling[position]->map() ) );
134  *tmp += *M_coupling[position];
135  tmp->setCoefficient (row, col, entry);
136  M_coupling[position] = tmp;
137  }
138 }
139 
140 // ===================================================
141 //! Protected Methods
142 // ===================================================
143 
144 
145 void MonolithicBlockComposed::blockAssembling (const UInt k)
146 {
147  if (M_blocks[k]->matrixPtr()->Filled() )
148  {
149  matrixPtr_Type tmp (new matrix_Type (M_blocks[0]->map(), 1) );
150  *tmp += *M_blocks[k];
151  M_blocks[k] = tmp;
152  }
153  M_coupling[k]->globalAssemble();
154  *M_blocks[k] += *M_coupling[k];
155 }
156 
157 void MonolithicBlockComposed::swap (const UInt i, const UInt j)
158 {
159  super_Type::swap (M_blocks[i], M_blocks[j]);
160  super_Type::swap (M_bch[i], M_bch[j]);
161  super_Type::swap (M_FESpace[i], M_FESpace[j]);
162  super_Type::swap (M_coupling[i], M_coupling[j]);
163 
164  bool tmpRecompute = this->M_recompute[i];
165  this->M_recompute[i] = this->M_recompute[j];
166  this->M_recompute[j] = tmpRecompute;
167 
168  UInt tmpOffset = this->M_offset[i];
169  this->M_offset[i] = this->M_offset[j];
170  this->M_offset[j] = tmpOffset;
171 }
172 
173 const UInt MonolithicBlockComposed::whereIsBlock ( UInt position ) const
174 {
175  for (UInt i = 0; i < M_blockReordering->size(); i++)
176  {
177  if ( (*M_blockReordering) [i] == static_cast<Int>(position) )
178  {
179  return i;
180  }
181  }
182  ERROR_MSG ("requested a block that does not exist in MonolithicBlockComposed.cpp");
183 
184  return 0; // To suppress compiler warning.
185 }
186 
187 } // Namespace LifeV
void updateInverseJacobian(const UInt &iQuadPt)
#define ERROR_MSG(A)
Definition: LifeAssert.hpp:69
double Real
Generic real data.
Definition: LifeV.hpp:175
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191