Skip to content

Commit f2f2f16

Browse files
authored
Merge pull request #1524 from knarfnitram/remove-epetra-operator-from-sparse-operator
[LinAlg] Remove the inheritance of `Epetra_Operator` from `SparseOperator`
2 parents 41766be + 08b9660 commit f2f2f16

File tree

39 files changed

+123
-463
lines changed

39 files changed

+123
-463
lines changed

src/beaminteraction/src/4C_beaminteraction_beam_to_solid_mortar_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void BeamInteraction::BeamToSolidMortarManager::add_global_force_stiffness_penal
572572
*constraint_lin_solid_, false, false, false, true);
573573

574574
// Penalty regularization linearized w.r.t. the scaling vector
575-
if (kappa_lin_beam_->NormInf() > 1e-12 && kappa_lin_solid_->NormInf() > 1e-12)
575+
if (kappa_lin_beam_->norm_inf() > 1e-12 && kappa_lin_solid_->norm_inf() > 1e-12)
576576
{
577577
Core::LinAlg::SparseMatrix penalty_regularization_lin_kappa(
578578
*std::get<2>(penalty_regularization));

src/cardiovascular0d/4C_cardiovascular0d_mor_pod.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ Cardiovascular0D::ProperOrthogonalDecomposition::reduce_diagonal(Core::LinAlg::S
9494
{
9595
// right multiply M * V
9696
Core::LinAlg::MultiVector<double> M_tmp(M.row_map(), projmatrix_->num_vectors(), true);
97-
int err = M.multiply(false, *projmatrix_, M_tmp);
98-
if (err) FOUR_C_THROW("Multiplication M * V failed.");
97+
M.multiply(false, *projmatrix_, M_tmp);
9998

10099
// left multiply V^T * (M * V)
101100
Core::LinAlg::MultiVector<double> M_red_mvec(*structmapr_, M_tmp.num_vectors(), true);
@@ -117,8 +116,7 @@ Cardiovascular0D::ProperOrthogonalDecomposition::reduce_off_diagonal(Core::LinAl
117116
{
118117
// right multiply M * V
119118
Core::LinAlg::MultiVector<double> M_tmp(M.domain_map(), projmatrix_->num_vectors(), true);
120-
int err = M.multiply(true, *projmatrix_, M_tmp);
121-
if (err) FOUR_C_THROW("Multiplication V^T * M failed.");
119+
M.multiply(true, *projmatrix_, M_tmp);
122120

123121
// convert Core::LinAlg::MultiVector<double> to Core::LinAlg::SparseMatrix
124122
Core::LinAlg::Map rangemap(M.domain_map());

src/constraint_framework/4C_constraint_framework_submodelevaluator_base.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ void Constraints::SubmodelEvaluator::ConstraintBase::evaluate_coupling_terms(
7373
ncon_ += mpc->get_number_of_constraint_equation_objects();
7474

7575
// ToDo: Add an offset to the constraint dof map.
76-
n_condition_map_ = std::make_shared<Core::LinAlg::Map>(
77-
ncon_, 0, Core::Communication::unpack_epetra_comm(stiff_ptr_->Comm()));
76+
n_condition_map_ = std::make_shared<Core::LinAlg::Map>(ncon_, 0, stiff_ptr_->get_comm());
7877

7978
// initialise all global coupling objects
8079
constraint_residual_ = std::make_shared<Core::LinAlg::Vector<double>>(*n_condition_map_, true);

src/contact/src/4C_contact_lagrange_strategy_tsi.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ void CONTACT::LagrangeStrategyTsi::update(std::shared_ptr<const Core::LinAlg::Ve
988988
Coupling::Adapter::CouplingMasterConverter(*coupST_), mThermo, false, false);
989989
mThermo.complete(
990990
*coupST_->master_to_slave_map(*gmdofrowmap_), *coupST_->master_to_slave_map(*gsdofrowmap_));
991-
mThermo.UseTranspose();
992991
tmp =
993992
std::make_shared<Core::LinAlg::Vector<double>>(*coupST_->master_to_slave_map(*gmdofrowmap_));
994993
mThermo.multiply(true, *z_thermo_, *tmp);

src/contact/src/4C_contact_meshtying_poro_lagrange_strategy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void CONTACT::PoroMtLagrangeStrategy::initialize_poro_mt(
3636
std::shared_ptr<Core::LinAlg::SparseMatrix> kteffmatrix =
3737
std::dynamic_pointer_cast<Core::LinAlg::SparseMatrix>(kteffoffdiag);
3838

39-
fvelrow_ = std::make_shared<Core::LinAlg::Map>(kteffmatrix->OperatorDomainMap());
39+
fvelrow_ = std::make_shared<Core::LinAlg::Map>(kteffmatrix->domain_map());
4040
}
4141

4242

src/core/linalg/src/sparse/4C_linalg_blocksparsematrix.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,6 @@ void Core::LinAlg::BlockSparseMatrixBase::apply_dirichlet(
186186
}
187187
}
188188

189-
190-
/*----------------------------------------------------------------------*
191-
*----------------------------------------------------------------------*/
192-
int Core::LinAlg::BlockSparseMatrixBase::SetUseTranspose(bool UseTranspose)
193-
{
194-
for (auto& block : blocks_) block.SetUseTranspose(UseTranspose);
195-
usetranspose_ = UseTranspose;
196-
return 0;
197-
}
198-
199-
200189
/*----------------------------------------------------------------------*
201190
*----------------------------------------------------------------------*/
202191
int Core::LinAlg::BlockSparseMatrixBase::Apply(
@@ -217,10 +206,7 @@ int Core::LinAlg::BlockSparseMatrixBase::Apply(
217206
std::shared_ptr<Core::LinAlg::MultiVector<double>> colx =
218207
domainmaps_.extract_vector(Core::LinAlg::MultiVector<double>(X), cblock);
219208
const Core::LinAlg::SparseMatrix& bmat = matrix(rblock, cblock);
220-
int err = bmat.Apply(colx->get_epetra_multi_vector(), rowy->get_epetra_multi_vector());
221-
if (err != 0)
222-
FOUR_C_THROW(
223-
"failed to apply vector to matrix block ({},{}): err={}", rblock, cblock, err);
209+
bmat.multiply(false, *colx, *rowy);
224210
rowresult->update(1.0, *rowy, 1.0);
225211
}
226212
View Y_view(Y);
@@ -240,8 +226,7 @@ int Core::LinAlg::BlockSparseMatrixBase::Apply(
240226
std::shared_ptr<Core::LinAlg::MultiVector<double>> colx =
241227
domainmaps_.extract_vector(Core::LinAlg::MultiVector<double>(X), cblock);
242228
const Core::LinAlg::SparseMatrix& bmat = matrix(cblock, rblock);
243-
int err = bmat.Apply(colx->get_epetra_multi_vector(), rowy->get_epetra_multi_vector());
244-
if (err != 0) FOUR_C_THROW("failed to apply vector to matrix: err={}", err);
229+
bmat.multiply(false, *colx, *rowy);
245230
rowresult->update(1.0, *rowy, 1.0);
246231
}
247232
View Y_view(Y);
@@ -310,27 +295,25 @@ void Core::LinAlg::BlockSparseMatrixBase::add(const Core::LinAlg::BlockSparseMat
310295

311296
/*----------------------------------------------------------------------*
312297
*----------------------------------------------------------------------*/
313-
int Core::LinAlg::BlockSparseMatrixBase::scale(double ScalarConstant)
298+
void Core::LinAlg::BlockSparseMatrixBase::scale(double ScalarConstant)
314299
{
315300
for (int i = 0; i < rows(); i++)
316301
{
317302
for (int j = 0; j < cols(); j++)
318303
{
319-
int err = matrix(i, j).scale(ScalarConstant);
320-
if (err != 0) FOUR_C_THROW("Scaling of matrix block ({},{}) failed", i, j);
304+
matrix(i, j).scale(ScalarConstant);
321305
}
322306
}
323-
return 0;
324307
}
325308

326309

327310
/*----------------------------------------------------------------------*
328311
*----------------------------------------------------------------------*/
329-
int Core::LinAlg::BlockSparseMatrixBase::multiply(bool TransA,
312+
void Core::LinAlg::BlockSparseMatrixBase::multiply(bool TransA,
330313
const Core::LinAlg::MultiVector<double>& X, Core::LinAlg::MultiVector<double>& Y) const
331314
{
332315
if (TransA) FOUR_C_THROW("transpose multiply not implemented for BlockSparseMatrix");
333-
return Apply(X.get_epetra_multi_vector(), Y.get_epetra_multi_vector());
316+
Apply(X.get_epetra_multi_vector(), Y.get_epetra_multi_vector());
334317
}
335318

336319

@@ -359,9 +342,9 @@ bool Core::LinAlg::BlockSparseMatrixBase::HasNormInf() const { return false; }
359342

360343
/*----------------------------------------------------------------------*
361344
*----------------------------------------------------------------------*/
362-
const Epetra_Comm& Core::LinAlg::BlockSparseMatrixBase::Comm() const
345+
MPI_Comm Core::LinAlg::BlockSparseMatrixBase::get_comm() const
363346
{
364-
return full_domain_map().get_epetra_map().Comm();
347+
return full_domain_map().get_comm();
365348
}
366349

367350

src/core/linalg/src/sparse/4C_linalg_blocksparsematrix.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Core::LinAlg
2828
implemented in terms of the matrix blocks.
2929
3030
*/
31-
class BlockSparseMatrixBase : public SparseOperator
31+
class BlockSparseMatrixBase : public SparseOperator, public Epetra_Operator
3232
{
3333
public:
3434
/// constructor
@@ -149,7 +149,7 @@ namespace Core::LinAlg
149149
//@{
150150

151151
/// If set true, transpose of this operator will be applied.
152-
int SetUseTranspose(bool UseTranspose) override;
152+
int SetUseTranspose(bool UseTranspose) override { FOUR_C_THROW("Not implemented."); }
153153

154154
//@}
155155

@@ -163,7 +163,7 @@ namespace Core::LinAlg
163163
int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const override;
164164

165165
/// Resolve virtual function of parent class
166-
int multiply(bool TransA, const Core::LinAlg::MultiVector<double>& X,
166+
void multiply(bool TransA, const Core::LinAlg::MultiVector<double>& X,
167167
Core::LinAlg::MultiVector<double>& Y) const override;
168168

169169
/// Add a (transposed) BlockSparseMatrix: (*this) = (*this)*scalarB + A(^T)*scalarA
@@ -183,7 +183,7 @@ namespace Core::LinAlg
183183
const double scalarB) const override;
184184

185185
/// Multiply all values in the matrix by a constant value (in place: A <- ScalarConstant * A).
186-
int scale(double ScalarConstant) override;
186+
void scale(double ScalarConstant) override;
187187

188188
/// Returns the infinity norm of the global matrix.
189189
double NormInf() const override;
@@ -203,7 +203,10 @@ namespace Core::LinAlg
203203
bool HasNormInf() const override;
204204

205205
/// Returns a pointer to the Epetra_Comm communicator associated with this operator.
206-
const Epetra_Comm& Comm() const override;
206+
const Epetra_Comm& Comm() const override { return full_domain_map().get_epetra_map().Comm(); }
207+
208+
MPI_Comm get_comm() const override;
209+
207210

208211
/// Returns the Core::LinAlg::Map object associated with the domain of this operator.
209212
const Epetra_Map& OperatorDomainMap() const override;

src/core/linalg/src/sparse/4C_linalg_sparsematrix.cpp

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,62 +1258,9 @@ std::shared_ptr<Core::LinAlg::SparseMatrix> Core::LinAlg::SparseMatrix::extract_
12581258

12591259
/*----------------------------------------------------------------------*
12601260
*----------------------------------------------------------------------*/
1261-
const char* Core::LinAlg::SparseMatrix::Label() const { return "Core::LinAlg::SparseMatrix"; }
1262-
1263-
1264-
/*----------------------------------------------------------------------*
1265-
*----------------------------------------------------------------------*/
1266-
int Core::LinAlg::SparseMatrix::SetUseTranspose(bool UseTranspose)
1261+
MPI_Comm Core::LinAlg::SparseMatrix::get_comm() const
12671262
{
1268-
return sysmat_->SetUseTranspose(UseTranspose);
1269-
}
1270-
1271-
1272-
/*----------------------------------------------------------------------*
1273-
*----------------------------------------------------------------------*/
1274-
int Core::LinAlg::SparseMatrix::Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
1275-
{
1276-
return sysmat_->Apply(X, Y);
1277-
}
1278-
1279-
1280-
/*----------------------------------------------------------------------*
1281-
*----------------------------------------------------------------------*/
1282-
int Core::LinAlg::SparseMatrix::ApplyInverse(
1283-
const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
1284-
{
1285-
return sysmat_->ApplyInverse(X, Y);
1286-
}
1287-
1288-
1289-
/*----------------------------------------------------------------------*
1290-
*----------------------------------------------------------------------*/
1291-
bool Core::LinAlg::SparseMatrix::UseTranspose() const { return sysmat_->UseTranspose(); }
1292-
1293-
1294-
/*----------------------------------------------------------------------*
1295-
*----------------------------------------------------------------------*/
1296-
bool Core::LinAlg::SparseMatrix::HasNormInf() const { return sysmat_->HasNormInf(); }
1297-
1298-
1299-
/*----------------------------------------------------------------------*
1300-
*----------------------------------------------------------------------*/
1301-
const Epetra_Comm& Core::LinAlg::SparseMatrix::Comm() const { return sysmat_->Comm(); }
1302-
1303-
1304-
/*----------------------------------------------------------------------*
1305-
*----------------------------------------------------------------------*/
1306-
const Epetra_Map& Core::LinAlg::SparseMatrix::OperatorDomainMap() const
1307-
{
1308-
return sysmat_->OperatorDomainMap();
1309-
}
1310-
1311-
1312-
/*----------------------------------------------------------------------*
1313-
*----------------------------------------------------------------------*/
1314-
const Epetra_Map& Core::LinAlg::SparseMatrix::OperatorRangeMap() const
1315-
{
1316-
return sysmat_->OperatorRangeMap();
1263+
return Core::Communication::unpack_epetra_comm(sysmat_->Comm());
13171264
}
13181265

13191266

@@ -1330,7 +1277,7 @@ int Core::LinAlg::SparseMatrix::global_max_num_entries() const
13301277

13311278
/*----------------------------------------------------------------------*
13321279
*----------------------------------------------------------------------*/
1333-
double Core::LinAlg::SparseMatrix::NormInf() const { return sysmat_->NormInf(); }
1280+
double Core::LinAlg::SparseMatrix::norm_inf() const { return sysmat_->NormInf(); }
13341281

13351282

13361283
/*----------------------------------------------------------------------*
@@ -1354,10 +1301,11 @@ void Core::LinAlg::SparseMatrix::multiply(
13541301

13551302
/*----------------------------------------------------------------------*
13561303
*----------------------------------------------------------------------*/
1357-
int Core::LinAlg::SparseMatrix::multiply(bool TransA, const Core::LinAlg::MultiVector<double>& X,
1304+
void Core::LinAlg::SparseMatrix::multiply(bool TransA, const Core::LinAlg::MultiVector<double>& X,
13581305
Core::LinAlg::MultiVector<double>& Y) const
13591306
{
1360-
return sysmat_->Multiply(TransA, X.get_epetra_multi_vector(), Y.get_epetra_multi_vector());
1307+
ASSERT_EPETRA_CALL(
1308+
sysmat_->Multiply(TransA, X.get_epetra_multi_vector(), Y.get_epetra_multi_vector()));
13611309
}
13621310

13631311

@@ -1400,9 +1348,9 @@ void Core::LinAlg::SparseMatrix::put_scalar(double ScalarConstant)
14001348

14011349
/*----------------------------------------------------------------------*
14021350
*----------------------------------------------------------------------*/
1403-
int Core::LinAlg::SparseMatrix::scale(double ScalarConstant)
1351+
void Core::LinAlg::SparseMatrix::scale(double ScalarConstant)
14041352
{
1405-
return sysmat_->Scale(ScalarConstant);
1353+
ASSERT_EPETRA_CALL(sysmat_->Scale(ScalarConstant));
14061354
}
14071355

14081356

src/core/linalg/src/sparse/4C_linalg_sparsematrix.hpp

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ namespace Core::LinAlg
187187
}
188188

189189
/// assemble method, if ONLY local values are assembled
190-
virtual void assemble(int eid, const Core::LinAlg::SerialDenseMatrix& Aele,
191-
const std::vector<int>& lm, const std::vector<int>& lmowner)
190+
void assemble(int eid, const Core::LinAlg::SerialDenseMatrix& Aele, const std::vector<int>& lm,
191+
const std::vector<int>& lmowner)
192192
{
193193
assemble(eid, Aele, lm, lmowner, lm);
194194
}
@@ -332,14 +332,6 @@ namespace Core::LinAlg
332332

333333
//@}
334334

335-
/** \name Attribute access functions */
336-
//@{
337-
338-
/// Returns a character string describing the operator.
339-
const char* Label() const override;
340-
341-
//@}
342-
343335
/** \name Utility functions */
344336
//@{
345337

@@ -384,14 +376,6 @@ namespace Core::LinAlg
384376
/// (down-cast from Epetra_CrsMatrix !) (you should not need this!)
385377
const Epetra_CrsMatrix& epetra_matrix() const { return *sysmat_; }
386378

387-
/** \name Attribute set methods */
388-
//@{
389-
390-
/// If set true, transpose of this operator will be applied.
391-
int SetUseTranspose(bool UseTranspose) override;
392-
393-
//@}
394-
395379
/** \name Matrix Properties Query Methods */
396380
//@{
397381

@@ -417,14 +401,8 @@ namespace Core::LinAlg
417401
/** \name Mathematical functions */
418402
//@{
419403

420-
/// Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
421-
int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const override;
422-
423-
/// Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y.
424-
int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const override;
425-
426404
/// Returns the infinity norm of the global matrix.
427-
double NormInf() const override;
405+
double norm_inf() const;
428406

429407
/// Returns the one norm of the global matrix.
430408
double norm_one() const;
@@ -486,26 +464,16 @@ namespace Core::LinAlg
486464
const Core::LinAlg::Map& col_map() const { return column_map_.sync(sysmat_->ColMap()); }
487465

488466
/// Returns the Core::LinAlg::Map object associated with the domain of this matrix operator.
489-
const Map& domain_map() const override { return domain_map_.sync(sysmat_->DomainMap()); }
467+
const Core::LinAlg::Map& domain_map() const override
468+
{
469+
return domain_map_.sync(sysmat_->DomainMap());
470+
}
490471

491472
/// Returns the Core::LinAlg::Map object associated with the range of this matrix operator.
492473
const Core::LinAlg::Map& range_map() const { return range_map_.sync(sysmat_->RangeMap()); }
493474

494-
495-
/// Returns the current UseTranspose setting.
496-
bool UseTranspose() const override;
497-
498-
/// Returns true if the this object can provide an approximate Inf-norm, false otherwise.
499-
bool HasNormInf() const override;
500-
501475
/// Returns a pointer to the Epetra_Comm communicator associated with this operator.
502-
const Epetra_Comm& Comm() const override;
503-
504-
/// Returns the Epetra_Map object associated with the domain of this operator.
505-
const Epetra_Map& OperatorDomainMap() const override;
506-
507-
/// Returns the Epetra_Map object associated with the range of this operator.
508-
const Epetra_Map& OperatorRangeMap() const override;
476+
MPI_Comm get_comm() const override;
509477

510478
//@}
511479

@@ -517,7 +485,7 @@ namespace Core::LinAlg
517485
bool TransA, const Core::LinAlg::Vector<double>& x, Core::LinAlg::Vector<double>& y) const;
518486

519487
/// Returns the result of a Epetra_CrsMatrix multiplied by a Epetra_MultiVector X in Y.
520-
int multiply(bool TransA, const Core::LinAlg::MultiVector<double>& X,
488+
void multiply(bool TransA, const Core::LinAlg::MultiVector<double>& X,
521489
Core::LinAlg::MultiVector<double>& Y) const override;
522490

523491
/// Scales the Core::LinAlg::SparseMatrix on the left with a Core::LinAlg::Vector<double> x.
@@ -541,7 +509,7 @@ namespace Core::LinAlg
541509
void put_scalar(double ScalarConstant);
542510

543511
/// Multiply all values in the matrix by a constant value (in place: A <- ScalarConstant * A).
544-
int scale(double ScalarConstant) override;
512+
void scale(double ScalarConstant) override;
545513

546514
/// Replaces diagonal values of the matrix with those in the user-provided vector.
547515
int replace_diagonal_values(const Core::LinAlg::Vector<double>& Diagonal);

0 commit comments

Comments
 (0)