28 #include <lifev/core/LifeV.hpp> 30 #include <lifev/fsi/solver/MonolithicBlockMatrix.hpp> 42 void MonolithicBlockMatrix::setDataFromGetPot (
const GetPot& ,
const std::string& )
46 void MonolithicBlockMatrix::setupSolver (solver_Type& solver,
const GetPot& data)
48 solver.setupPreconditioner (data,
"linear_system/prec");
52 void MonolithicBlockMatrix::GlobalAssemble()
54 M_globalMatrix->globalAssemble();
58 void MonolithicBlockMatrix::coupler (mapPtr_Type& map,
59 const std::map<ID, ID>& locDofMap,
60 const vectorPtr_Type& numerationInterface,
62 const Real& coefficient = 1.,
63 const Real& rescaleFactor = 1.
66 ASSERT (!M_coupling.get(),
"coupler must not be called twice \n");
67 M_coupling.reset (
new matrix_Type (*map) );
68 super_Type::couplingMatrix ( M_coupling, (*M_couplingFlags) [0], super_Type::M_FESpace, super_Type::M_offset, locDofMap, numerationInterface, timeStep, 1., coefficient, rescaleFactor);
72 void MonolithicBlockMatrix::coupler (mapPtr_Type& ,
73 const std::map<ID, ID>& locDofMap,
74 const vectorPtr_Type& numerationInterface,
76 const Real& coefficient,
77 const Real& rescaleFactor,
81 super_Type::couplingMatrix ( M_coupling, (*M_couplingFlags) [couplingBlock], super_Type::M_FESpace, super_Type::M_offset, locDofMap, numerationInterface, timeStep, 1., coefficient, rescaleFactor);
85 int MonolithicBlockMatrix::solveSystem (
const vector_Type& rhs, vector_Type& step, solverPtr_Type& linearSolver)
87 return linearSolver->solveSystem (rhs, step, M_globalMatrix);
90 void MonolithicBlockMatrix::push_back_matrix (
const matrixPtr_Type& Mat,
bool )
92 super_Type::M_blocks.push_back (Mat);
96 void MonolithicBlockMatrix::replace_matrix (
const matrixPtr_Type& Mat,
UInt index)
98 super_Type::M_blocks[index] = Mat;
102 void MonolithicBlockMatrix::replace_precs (
const epetraOperatorPtr_Type& ,
UInt )
108 void MonolithicBlockMatrix::blockAssembling()
110 M_coupling->globalAssemble();
111 M_globalMatrix.reset (
new matrix_Type (M_coupling->map() ) );
112 *M_globalMatrix += *M_coupling;
113 for (UInt k = 0; k < M_blocks.size(); ++k)
115 M_blocks[k]->globalAssemble();
116 *M_globalMatrix += *M_blocks[k];
122 void MonolithicBlockMatrix::applyPreconditioner (
const matrixPtr_Type matrix, vectorPtr_Type& rhsFull)
124 this->applyPreconditioner (matrix, M_globalMatrix);
125 *rhsFull = (*matrix) * (*rhsFull);
129 void MonolithicBlockMatrix::applyPreconditioner ( matrixPtr_Type robinCoupling, matrixPtr_Type prec, vectorPtr_Type& rhs)
131 applyPreconditioner (robinCoupling, prec);
132 applyPreconditioner (robinCoupling, M_globalMatrix);
133 (*rhs) = (*robinCoupling) * (*rhs);
137 void MonolithicBlockMatrix::applyPreconditioner (
const matrixPtr_Type prec, matrixPtr_Type& oper )
139 matrix_Type tmpMatrix (prec->map(), 1);
140 EpetraExt::MatrixMatrix::Multiply ( *prec->matrixPtr(),
144 *tmpMatrix.matrixPtr() );
145 oper->swapCrsMatrix (tmpMatrix);
149 void MonolithicBlockMatrix::createInterfaceMap (
const MapEpetra& interfaceMap ,
const std::map<ID, ID>& locDofMap,
const UInt subdomainMaxId,
const std::shared_ptr<Epetra_Comm> epetraWorldComm )
152 std::map<ID, ID>::const_iterator ITrow;
154 Int numtasks = epetraWorldComm->NumProc();
155 int* numInterfaceDof (
new int[numtasks]);
156 int pid = epetraWorldComm->MyPID();
157 int numMyElements = interfaceMap.map (Unique)->NumMyElements();
158 numInterfaceDof[pid] = numMyElements;
159 MapEpetra subMap (*interfaceMap.map (Unique), (UInt) 0, subdomainMaxId);
161 M_numerationInterface.reset (
new vector_Type (subMap, Unique) );
165 for (
int j = 0; j < numtasks; ++j)
167 epetraWorldComm->Broadcast ( &numInterfaceDof[j], 1, j);
170 for (
int j = numtasks - 1; j > 0 ; --j)
172 numInterfaceDof[j] = numInterfaceDof[j - 1];
174 numInterfaceDof[0] = 0;
175 for (
int j = 1; j < numtasks ; ++j)
177 numInterfaceDof[j] += numInterfaceDof[j - 1];
182 M_interface = (UInt) interfaceMap.map (Unique)->NumGlobalElements() / nDimensions;
184 for (l = 0, ITrow = locDofMap.begin(); ITrow != locDofMap.end() ; ++ITrow)
186 if (interfaceMap.map (Unique)->LID (
static_cast<EpetraInt_Type> (ITrow->second ) ) >= 0)
188 (*M_numerationInterface) [ITrow->second ] = l + (
int) (numInterfaceDof[pid] / nDimensions) ;
190 if ( (
int) (*M_numerationInterface) (ITrow->second ) != floor (l + numInterfaceDof[pid] / nDimensions + 0.2 ) )
192 std::cout <<
"ERROR! the numeration of the coupling map is not correct" << std::endl;
198 std::vector<
int> couplingVector;
199 couplingVector.reserve ( (
int) (interfaceMap.map (Unique)->NumMyElements() ) );
203 for ( ITrow = locDofMap.begin(); ITrow != locDofMap.end() ; ++ITrow)
205 if (interfaceMap.map (Unique)->LID (
static_cast<EpetraInt_Type> (ITrow->second) ) >= 0)
207 couplingVector.push_back ( (*M_numerationInterface) (ITrow->second ) + dim * M_interface );
213 M_interfaceMap.reset (
new MapEpetra (-1,
static_cast< Int> ( couplingVector.size() ), &couplingVector[0], epetraWorldComm) );
216 void MonolithicBlockMatrix::applyBoundaryConditions (
const Real& time)
218 for ( UInt i = 0; i < super_Type::M_blocks.size(); ++i )
220 applyBoundaryConditions ( time, i );
224 void MonolithicBlockMatrix::applyBoundaryConditions (
const Real& time, vectorPtr_Type& rhs)
226 for ( UInt i = 0; i < super_Type::M_blocks.size(); ++i )
228 applyBoundaryConditions ( time, rhs, i );
232 void MonolithicBlockMatrix::applyBoundaryConditions (
const Real& time, vectorPtr_Type& rhs,
const UInt block)
235 bcManage ( *M_globalMatrix , *rhs, *super_Type::M_FESpace[block]->mesh(), super_Type::M_FESpace[block]->dof(), *super_Type::M_bch[block], super_Type::M_FESpace[block]->feBd(), 1., time);
238 void MonolithicBlockMatrix::applyBoundaryConditions (
const Real& time,
const UInt block)
241 bcManageMatrix ( *M_globalMatrix , *super_Type::M_FESpace[block]->mesh(), super_Type::M_FESpace[block]->dof(), *super_Type::M_bch[block], super_Type::M_FESpace[block]->feBd(), 1., time);
244 void MonolithicBlockMatrix::addToCoupling (
const matrixPtr_Type& Mat,
UInt )
246 if (!M_coupling->matrixPtr()->Filled() )
252 matrixPtr_Type tmp (
new matrix_Type (M_coupling->map() ) );
262 if (!M_coupling->matrixPtr()->Filled() )
264 M_coupling->setCoefficient (row, col, entry);
268 matrixPtr_Type tmp (
new matrix_Type (M_coupling->map() ) );
270 tmp->setCoefficient (row, col, entry);
int32_type Int
Generic integer data.
void updateInverseJacobian(const UInt &iQuadPt)
Epetra_Import const & importer()
Getter for the Epetra_Import.
double Real
Generic real data.
const UInt nDimensions(NDIM)
uint32_type UInt
generic unsigned integer (used mainly for addressing)