49 return ::MatSetValues(
51 S, row_ind.size(), &*row_ind.begin(), col_ind.size(), &*col_ind.begin(),
52 &*
m.data().begin(), iora
72 boost::shared_ptr<std::vector<unsigned char>> marker_ptr,
79 boost::shared_ptr<std::vector<unsigned char>>
markerPtr;
87template <
typename OP_SCHUR_ASSEMBLE_BASE>
105 std::vector<std::string> fields_name,
106 std::vector<boost::shared_ptr<Range>> field_ents,
110 bool sym_schur,
bool symm_op);
113 template <
typename I>
161struct SchurElemMats :
public boost::enable_shared_from_this<SchurElemMats> {
187 template <
typename OP_SCHUR_ASSEMBLE_BASE>
202 member<SchurElemMats, const UId, &SchurElemMats::uidRow>,
203 member<SchurElemMats, const UId, &SchurElemMats::uidCol>
212 static boost::ptr_vector<MatrixDouble>
locMats;
278 inline void setStorage(
size_t shift,
int leading_dim,
int element) {
372 inline int mLd(
int a,
int b)
const {
return sLd(b,
a); }
411 std::vector<std::pair<UId, int>>
row,
col;
463 "A00 factorisation failed and block matrix data is corrupted, "
464 "call MatZeroEntries and assemble again");
474 "A00 element matrices are factorised in place, call "
475 "MatZeroEntries before assembling or modifying block matrix");
481 for (
auto &e :
elems) {
482 e.factorised =
false;
486 std::vector<double>().swap(
d);
504 auto it = std::lower_bound(
506 [](
const Indexes &
a,
const std::pair<UId, UId> &p) {
507 if (a.getRowUId() != p.first)
508 return a.getRowUId() < p.first;
509 return a.getColUId() < p.second;
512 it->getColUId() ==
col)
523 return a.getRowUId() < b;
538 auto lo = std::lower_bound(
540 [
this](
int i,
const UId &
c) { return blockIndex[i].getColUId() < c; });
541 auto hi = std::upper_bound(
543 [
this](
const UId &
c,
int i) { return c < blockIndex[i].getColUId(); });
544 return std::make_pair(lo, hi);
617 : iDX(idx), uidRow(uid_row), uidCol(uid_col) {}
631 auto get_row_indices = [&]() ->
const VectorInt & {
633 if (
auto stored_data_ptr =
635 return stored_data_ptr->entityIndices;
641 const auto &row_ind = get_row_indices();
644 const auto nb_rows = row_ind.size();
645 const auto nb_cols = col_ind.size();
648 if (mat.size1() != nb_rows) {
650 "Wrong mat size %zu != %zu", mat.size1(), nb_rows);
652 if (mat.size2() != nb_cols) {
654 "Wrong mat size %zu != %zu", mat.size2(), nb_cols);
659 auto get_uid = [](
auto &data) {
660 if (data.getFieldEntities().size() == 1) {
662 return data.getFieldEntities()[0]->getLocalUniqueId();
671 auto &uid0 = data.getFieldEntities()[0]->getLocalUniqueId();
677 for (
auto i = 1;
i < data.getFieldEntities().
size(); ++
i) {
684 data.getFieldEntities()[
i]->getLocalUniqueId())
698 auto uid_row = get_uid(row_data);
699 auto uid_col = get_uid(col_data);
703 .find(boost::make_tuple(uid_row, uid_col));
735 auto asmb = [&](
auto &sm) {
736 sm.resize(nb_rows, nb_cols,
false);
740 asmb((*p.first)->getMat());
742 auto add_indices = [](
auto &storage,
auto &ind) {
743 storage.resize(ind.size(),
false);
744 noalias(storage) = ind;
747 add_indices((*p.first)->getRowInd(), row_ind);
748 add_indices((*p.first)->getColInd(), col_ind);
753 auto asmb = [&](
auto &sm) {
757 if (sm.size1() != nb_rows) {
759 "Wrong mat or storage size %zu != %zu", sm.size1(), nb_rows);
761 if (sm.size2() != nb_cols) {
763 "Wrong mat or storage size %zu != %zu", sm.size2(), nb_cols);
776 "Assembly type not implemented");
781 CHKERR asmb((*it)->getMat());
801 MOFEM_LOG(
"SELF", Sev::noisy) <<
"Schur assemble begin";
810 boost::shared_ptr<std::vector<unsigned char>> marker_ptr,
double diag_val)
820 auto prb_ptr = fe_ptr->problemPtr;
823 auto find_loc_dof_index = [&](
auto glob) {
825 if (
it != dof.end()) {
826 return (*it)->getPetscLocalDofIdx();
831 "Global dof index not found in local numered dofs storage");
837 auto zero_ind = [&](
auto &ind) {
838 for (
auto i = 0;
i < ind.size(); ++
i) {
840 if ((*
markerPtr)[find_loc_dof_index(ind[
i])]) {
847 zero_ind(
s->getRowInd());
848 zero_ind(
s->getColInd());
854template <
typename OP_SCHUR_ASSEMBLE_BASE>
856 std::vector<std::string> fields_name,
857 std::vector<boost::shared_ptr<Range>> field_ents,
860 :
OP(
NOSPACE,
OP::OPSPACE, symm_op), fieldsName(fields_name),
861 fieldEnts(field_ents), schurAO(schur_ao), schurMat(schur_mat),
862 symSchur(sym_schur) {}
864template <
typename OP_SCHUR_ASSEMBLE_BASE>
877 MOFEM_LOG(
"SELF", Sev::noisy) <<
"Schur assemble begin -> end";
880 auto get_a00_uids = [&]() {
881 auto get_field_bit = [&](
auto &
name) {
882 return OP::getPtrFE()->mField.get_field_bit_number(
name);
885 std::vector<std::pair<UId, UId>> a00_uids;
886 a00_uids.reserve(fieldsName.size());
887 for (
auto ss = 0; ss != fieldsName.size(); ++ss) {
888 auto field_bit = get_field_bit(fieldsName[ss]);
889 auto row_ents = fieldEnts[ss];
891 for (
auto p = row_ents->pair_begin(); p != row_ents->pair_end(); ++p) {
896 a00_uids.push_back(std::make_pair(lo_uid, hi_uid));
900 field_bit, get_id_for_min_type<MBVERTEX>());
902 field_bit, get_id_for_max_type<MBENTITYSET>());
903 a00_uids.push_back(std::make_pair(lo_uid, hi_uid));
910 auto get_field_name = [&](
auto uid) {
914 auto list_storage = [&](
auto &storage) {
917 for (
auto &p : storage) {
919 <<
"List schur storage: " <<
i <<
" " << p->iDX <<
": "
920 << get_field_name(p->uidRow) <<
" " << get_field_name(p->uidCol)
921 <<
" : " << p->getMat().size1() <<
" " << p->getMat().size2();
928 auto assemble_dense_blocks = [&]() {
929 using matrix_range = ublas::matrix_range<MatrixDouble>;
930 using range = ublas::range;
934 auto assemble_schur = [
this](
auto &
m,
auto &uid_row,
auto &uid_col,
935 auto *row_ind_ptr,
auto *col_ind_ptr) {
940 if (
auto ierr = this->assembleSchurMat(
942 schurMat, uid_row, *row_ind_ptr, uid_col, *col_ind_ptr,
m,
947 auto field_ents = OP::getPtrFE()->mField.get_field_ents();
948 auto row_ent_it = field_ents->find(uid_row);
949 auto col_ent_it = field_ents->find(uid_col);
951 if (row_ent_it != field_ents->end())
953 <<
"Assemble row entity: " << (*row_ent_it)->getName() <<
" "
954 << (*col_ent_it)->getEntTypeName() <<
" side "
955 << (*row_ent_it)->getSideNumber();
956 if (col_ent_it != field_ents->end())
958 <<
"Assemble col entity: " << (*col_ent_it)->getName() <<
" "
959 << (*col_ent_it)->getEntTypeName() <<
" side "
960 << (*col_ent_it)->getSideNumber();
969 auto a00_uids = get_a00_uids();
971 auto get_block_indexing = [&](
auto &a00_uids) {
973 std::vector<const SchurElemMats *> block_list;
974 block_list.reserve(storage.size());
975 for (
auto &rp_uid : a00_uids) {
976 auto [rlo_uid, rhi_uid] = rp_uid;
977 for (
auto &cp_uid : a00_uids) {
978 auto [clo_uid, chi_uid] = cp_uid;
981 storage.template get<SchurElemMats::uid_mi_tag>().lower_bound(
982 boost::make_tuple(rlo_uid, clo_uid));
984 storage.template get<SchurElemMats::uid_mi_tag>().upper_bound(
985 boost::make_tuple(rhi_uid, chi_uid));
987 for (;
it != hi_it; ++
it) {
988 if ((*it)->uidRow >= rlo_uid && (*it)->uidRow < rhi_uid &&
989 (*it)->uidCol >= clo_uid && (*it)->uidCol < chi_uid) {
990 block_list.push_back(*
it);
997 std::map<UId, std::pair<size_t, const VectorInt *>>
999 for (
auto d : block_list) {
1000 if (block_indexing.find(
d->uidRow) == block_indexing.end()) {
1001 block_indexing[
d->uidRow] =
1002 std::make_pair(
d->getRowInd().size(), &(
d->getRowInd()));
1007 int mat_block_size = 0;
1008 for (
auto &p_uid : a00_uids) {
1009 auto [lo_uid, hi_uid] = p_uid;
1010 auto lo = block_indexing.lower_bound(lo_uid);
1011 auto up = block_indexing.upper_bound(hi_uid);
1012 for (; lo != up; ++lo) {
1013 lo->second.first = mat_block_size;
1014 mat_block_size += lo->second.second->size();
1018 return std::make_tuple(block_list, block_indexing, mat_block_size);
1021 auto get_schur_block_list = [&](
auto &block_indexing) {
1022 std::vector<const SchurElemMats *> block_list;
1023 block_list.reserve(storage.size());
1024 for (
auto &
s : storage) {
1025 if (block_indexing.find(
s->uidRow) == block_indexing.end() &&
1026 block_indexing.find(
s->uidCol) == block_indexing.end()) {
1027 block_list.push_back(
s);
1033 auto bi = get_block_indexing(a00_uids);
1034 auto &[block_list, block_indexing, block_mat_size] = bi;
1036 if (block_mat_size == 0) {
1039 for (
auto &
s : storage) {
1040 CHKERR AOApplicationToPetsc(schurAO,
s->getRowInd().size(),
1041 &*
s->getRowInd().begin());
1042 CHKERR AOApplicationToPetsc(schurAO,
s->getColInd().size(),
1043 &*
s->getColInd().begin());
1047 for (
auto &
s : storage) {
1048 auto &
m =
s->getMat();
1049 CHKERR assemble_schur(
m,
s->uidRow,
s->uidCol, &(
s->getRowInd()),
1055 blockMat.resize(block_mat_size, block_mat_size,
false);
1058 auto get_range = [](
auto &bi) {
1059 return range(bi.first, bi.first + bi.second->size());
1062 for (
auto &
s : block_list) {
1063 auto &
m =
s->getMat();
1065 if (block_indexing.find(
s->uidRow) == block_indexing.end())
1067 if (block_indexing.find(
s->uidCol) == block_indexing.end())
1071 auto &rbi = block_indexing.at(
s->uidRow);
1072 auto &cbi = block_indexing.at(
s->uidCol);
1074 auto sub_mat = matrix_range(blockMat, get_range(rbi), get_range(cbi));
1078 auto get_zeroed_indices = [&](
auto extractor_uid,
auto extractor_ind) {
1079 auto &[block_list, block_indexing, block_mat_size] = bi;
1080 std::vector<int> zeroed_indices;
1081 zeroed_indices.reserve(block_mat_size);
1082 for (
auto &
s : block_list) {
1083 auto &bi = block_indexing.at(extractor_uid(
s));
1084 auto &ind = extractor_ind(
s);
1085 for (
auto it = ind.begin();
it != ind.end(); ++
it) {
1087 auto idx = bi.first + std::distance(ind.begin(),
it);
1088 zeroed_indices.push_back(idx);
1092 std::sort(zeroed_indices.begin(), zeroed_indices.end());
1093 auto it = std::unique(zeroed_indices.begin(), zeroed_indices.end());
1094 zeroed_indices.resize(std::distance(zeroed_indices.begin(),
it));
1095 return zeroed_indices;
1097 auto zero_rows = get_zeroed_indices(
1098 [](
auto &
s) {
return s->uidRow; },
1099 [](
auto &
s) ->
VectorInt & {
return s->getRowInd(); });
1100 auto zero_cols = get_zeroed_indices(
1101 [](
auto &
s) {
return s->uidCol; },
1102 [](
auto &
s) ->
VectorInt & {
return s->getColInd(); });
1104 for (
auto i : zero_rows) {
1105 for (
auto j = 0;
j != blockMat.size2(); ++
j) {
1109 for (
auto j : zero_cols) {
1110 for (
auto i = 0;
i != blockMat.size1(); ++
i) {
1114 for (
auto i : zero_rows) {
1118 CHKERR I::invertMat(blockMat, invMat);
1121 for (
auto &
s : block_list) {
1122 auto it = storage.template get<SchurElemMats::uid_mi_tag>().find(
1123 boost::make_tuple(
s->uidRow,
s->uidCol));
1124 storage.template get<SchurElemMats::uid_mi_tag>().erase(
it);
1129 for (
auto &
s : storage) {
1130 if (block_indexing.find(
s->uidRow) == block_indexing.end()) {
1131 CHKERR AOApplicationToPetsc(schurAO,
s->getRowInd().size(),
1132 &*
s->getRowInd().begin());
1134 if (block_indexing.find(
s->uidCol) == block_indexing.end()) {
1135 CHKERR AOApplicationToPetsc(schurAO,
s->getColInd().size(),
1136 &*
s->getColInd().begin());
1141 auto schur_block_list = get_schur_block_list(block_indexing);
1142 for (
auto &
s : schur_block_list) {
1143 auto &
m =
s->getMat();
1144 CHKERR assemble_schur(
m,
s->uidRow,
s->uidCol, &(
s->getRowInd()),
1147 for (
auto &
s : schur_block_list) {
1148 auto it = storage.template get<SchurElemMats::uid_mi_tag>().find(
1149 boost::make_tuple(
s->uidRow,
s->uidCol));
1150 storage.template get<SchurElemMats::uid_mi_tag>().erase(
it);
1152 schur_block_list.clear();
1156 auto rp_uid_it = a00_uids.begin(); rp_uid_it != a00_uids.end();
1160 auto [rlo_uid, rhi_uid] = *rp_uid_it;
1161 for (
auto rm = block_indexing.lower_bound(rlo_uid);
1162 rm != block_indexing.upper_bound(rhi_uid); ++rm) {
1163 auto &rbi = rm->second;
1166 storage.template get<SchurElemMats::col_mi_tag>().lower_bound(
1169 storage.template get<SchurElemMats::col_mi_tag>().upper_bound(
1174 auto cp_uid_it = (symSchur) ? rp_uid_it : a00_uids.begin();
1175 cp_uid_it != a00_uids.end(); ++cp_uid_it
1178 auto [clo_uid, chi_uid] = *cp_uid_it;
1179 for (
auto cm = block_indexing.lower_bound(clo_uid);
1180 cm != block_indexing.upper_bound(chi_uid); ++cm) {
1181 auto &cbi = cm->second;
1184 storage.template get<SchurElemMats::uid_mi_tag>().lower_bound(
1185 boost::make_tuple(cm->first, 0));
1187 storage.template get<SchurElemMats::uid_mi_tag>().upper_bound(
1192 matrix_range(invMat, get_range(rbi), get_range(cbi));
1193 bM.resize(sub_inv_mat.size1(), sub_inv_mat.size2());
1194 noalias(bM) = sub_inv_mat;
1196 for (
auto a_lo = a_lo_tmp; a_lo != a_hi; ++a_lo) {
1198 if (block_indexing.find((*a_lo)->uidRow) != block_indexing.end())
1200 "Wrong a_lo->uidRow");
1203 auto &
a = (*a_lo)->getMat();
1204 abM.resize(
a.size1(), bM.size2(),
false);
1206 cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
1208 a.size1(), bM.size2(),
a.size2(), 1.,
1210 &*
a.data().begin(),
a.size2(),
1212 &*bM.data().begin(), bM.size2(), 0.,
1214 &*abM.data().begin(), abM.size2());
1216 for (
auto c_lo = c_lo_tmp; c_lo != c_hi; ++c_lo) {
1218 if (block_indexing.find((*c_lo)->uidCol) !=
1219 block_indexing.end())
1221 "Wrong a_lo->uidRow");
1224 auto &
c = (*c_lo)->getMat();
1226 abcM.resize(abM.size1(),
c.size2(),
false);
1229 cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
1230 abM.size1(),
c.size2(), abM.size2(), -1.,
1232 &*abM.data().begin(), abM.size2(),
1234 &*
c.data().begin(),
c.size2(), 0.,
1236 &*abcM.data().begin(), abcM.size2());
1238 CHKERR assemble_schur(abcM, (*a_lo)->uidRow, (*c_lo)->uidCol,
1239 &((*a_lo)->getRowInd()),
1240 &((*c_lo)->getColInd()));
1242 if (symSchur && rp_uid_it != cp_uid_it) {
1244 CHKERR assemble_schur(abcM, (*c_lo)->uidCol, (*a_lo)->uidRow,
1245 &((*c_lo)->getColInd()),
1246 &((*a_lo)->getRowInd()));
1259 CHKERR assemble_dense_blocks();
1263 MOFEM_LOG(
"SELF", Sev::noisy) <<
"Schur assemble done";
1278 const auto nb =
m.size1();
1280 if (
nb !=
m.size2()) {
1282 "It should be square matrix %zu != %zu",
nb,
m.size2());
1286 inv.resize(
nb,
nb,
false);
1288 m.resize(2 *
nb, 2 *
nb,
false);
1298 "lapack error info = %d", info);
1300 &*
m.data().begin(),
m.data().size());
1303 "lapack error info = %d", info);
1314 const auto nb =
m.size1();
1316 if (
nb !=
m.size2()) {
1318 "It should be square matrix %zu != %zu",
nb,
m.size2());
1322 inv.resize(
nb,
nb,
false);
1331 "lapack error info = %d", info);
1333 &*
m.data().begin(),
m.data().size());
1336 "lapack error info = %d", info);
1345 return doWorkImpl<SchurDSYSV>(side,
type, data);
1351 return doWorkImpl<SchurDGESV>(side,
type, data);
1367 for (
int k = 0;
k !=
n; ++
k) {
1368 const int p = ipiv[
k] - 1;
1370 std::swap(
t[
k],
t[p]);
1372 cblas_dtrmv(CblasColMajor, CblasLower, CblasTrans, CblasUnit,
n, lu,
n,
t,
1374 cblas_dtrmv(CblasColMajor, CblasUpper, CblasTrans, CblasNonUnit,
n, lu,
n,
1377 cblas_dtrmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit,
n, lu,
n,
1379 cblas_dtrmv(CblasColMajor, CblasLower, CblasNoTrans, CblasUnit,
n, lu,
n,
t,
1381 for (
int k =
n - 1;
k >= 0; --
k) {
1382 const int p = ipiv[
k] - 1;
1384 std::swap(
t[
k],
t[p]);
1390static inline void copy_block(
double *dst,
int ld_dst,
int ridx,
int cidx,
1391 const double *src,
int ld_src,
int nb_rows,
1393 for (
int i = 0;
i != nb_rows; ++
i)
1394 cblas_dcopy(nb_cols, src +
static_cast<size_t>(
i) * ld_src, 1,
1395 dst +
static_cast<size_t>(ridx +
i) * ld_dst + cidx, 1);
1399 return std::all_of(ptr, ptr +
size, [](
double v) {
return v == 0.; });
1412 for (
int j = 0;
j !=
n; ++
j) {
1414 const double s = cblas_dasum(
m,
a +
static_cast<size_t>(
j) * ld, 1);
1415 if (!std::isfinite(
s))
1416 return std::numeric_limits<double>::infinity();
1423static inline void add_gemv(
bool trans_a,
int m,
int kk,
const double *
a,
1424 int lda,
const double *x,
double *y) {
1427 cblas_dgemv(CblasColMajor, trans_a ? CblasTrans : CblasNoTrans,
1428 trans_a ? kk :
m, trans_a ?
m : kk, 1.,
a, lda, x, 1, 1., y, 1);
1432static inline void sub_gemm(
bool trans_a,
int m,
int kk,
int nrhs,
1433 const double *
a,
int lda,
const double *b,
int ldb,
1434 double *
c,
int ldc) {
1435 if (!
m || !kk || !nrhs)
1438 cblas_dgemv(CblasColMajor, trans_a ? CblasTrans : CblasNoTrans,
1439 trans_a ? kk :
m, trans_a ?
m : kk, -1.,
a, lda, b, 1, 1.,
c,
1442 cblas_dgemm(CblasColMajor, trans_a ? CblasTrans : CblasNoTrans,
1443 CblasNoTrans,
m, nrhs, kk, -1.,
a, lda, b, ldb, 1.,
c, ldc);
1458 double coupling,
double u,
double rcond_min,
1459 std::vector<double> &
work,
1460 std::vector<__CLPK_integer> &iwork,
1461 double *rcond_out =
nullptr,
1462 double *anorm_out =
nullptr) {
1469 if (anorm == 0 || !std::isfinite(anorm))
1478 dgecon_(&norm, &nn,
d, &lda, &an, &rcond,
work.data(), iwork.data(), &info);
1481 if (info != 0 || !std::isfinite(rcond))
1483 if (rcond < rcond_min)
1485 if (u > 0 && rcond * anorm < u * coupling)
1494 std::vector<int> off(p.
nbNodes);
1496 for (
int r = 0; r != p.
nbNodes; ++r) {
1506 for (
int r = 0; r != p.
nbNodes; ++r)
1523 for (
int r = 0; r !=
k; ++r)
1524 for (
int c = 0;
c !=
k; ++
c)
1542 const std::vector<int> &
order) {
1544 std::vector<char> pm(
k *
k, 0);
1545 for (
int r = 0; r !=
k; ++r)
1546 for (
int c = 0;
c !=
k; ++
c)
1548 std::vector<char> done(
k, 0);
1549 for (
auto e :
order) {
1551 for (
int i = 0;
i !=
k; ++
i)
1552 if (!done[
i] && pm[
i *
k + e])
1553 for (
int j = 0;
j !=
k; ++
j)
1554 if (!done[
j] && pm[e *
k +
j])
1573 std::vector<char> in_core(
k, 1);
1574 for (
auto e :
order)
1578 for (
int i = 0;
i !=
k; ++
i)
1580 p.
core.push_back(
i);
1583 std::vector<int> pos(
k);
1585 for (
auto e : p.
order) {
1591 for (
auto c : p.
core) {
1599 std::vector<std::array<int, 4>> slots;
1600 for (
int r = 0; r !=
k; ++r)
1601 for (
int c = 0;
c !=
k; ++
c)
1602 if (!(in_core[r] && in_core[
c]) && pm[
c *
k + r])
1603 slots.push_back({std::min(pos[r], pos[
c]), pos[r], pos[
c], r *
k +
c});
1604 std::sort(slots.begin(), slots.end());
1606 p.slotShift.assign(
k *
k, -1);
1607 p.slotLd.assign(
k *
k, 0);
1609 for (
auto &
s : slots) {
1610 const int r =
s[3] /
k,
c =
s[3] %
k;
1611 p.slotShift[
s[3]] = shift;
1612 p.slotLd[
s[3]] = p.nodeSize[
c];
1613 shift +=
static_cast<size_t>(p.nodeSize[r]) * p.nodeSize[
c];
1615 p.coreShift = shift;
1616 for (
auto r : p.core)
1617 for (auto
c : p.core) {
1618 p.slotShift[
r *
k +
c] =
1620 static_cast<size_t>(p.nodeOffset[
r] - p.coreOffset) * p.coreSize +
1621 (p.nodeOffset[
c] - p.coreOffset);
1622 p.slotLd[
r *
k +
c] = p.coreSize;
1624 p.elemSize = p.coreShift +
static_cast<size_t>(p.coreSize) * p.coreSize;
1632 std::vector<char> rem(
k, 1);
1633 std::vector<int>
order;
1636 double best_fill = 0;
1637 for (
int e = 0; e !=
k; ++e) {
1638 if (!rem[e] || !pm[e *
k + e])
1641 for (
int i = 0;
i !=
k; ++
i)
1642 if (rem[
i] &&
i != e && pm[
i *
k + e])
1643 for (
int j = 0;
j !=
k; ++
j)
1644 if (rem[
j] &&
j != e && pm[e *
k +
j] && !pm[
i *
k +
j])
1646 if (
best < 0 || fill < best_fill) {
1653 for (
int i = 0;
i !=
k; ++
i)
1655 for (
int j = 0;
j !=
k; ++
j)
1676 double u,
double rcond_min) {
1681 auto mb = [&](
int a,
int b) {
1682 return w +
static_cast<size_t>(off[b]) *
n + off[
a];
1685 std::vector<char> rem(
k, 1);
1686 std::vector<int>
order;
1687 std::vector<double> tmp,
work;
1688 std::vector<__CLPK_integer> piv, iwork;
1692 double best_fill = 0;
1693 for (
int e = 0; e !=
k; ++e) {
1694 if (!rem[e] || !pm[e *
k + e])
1696 const int ne = ns[e];
1697 double coupling = 0;
1698 for (
int j = 0;
j !=
k; ++
j) {
1699 if (!rem[
j] ||
j == e)
1706 tmp.resize(
static_cast<size_t>(ne) * ne);
1707 for (
int c = 0;
c != ne; ++
c)
1708 cblas_dcopy(ne,
mb(e, e) +
static_cast<size_t>(
c) *
n, 1,
1709 tmp.data() +
static_cast<size_t>(
c) * ne, 1);
1711 double rcond, anorm;
1712 const bool admissible =
1714 rcond_min,
work, iwork, &rcond, &anorm);
1716 <<
"A00 analysis step " <<
order.size() <<
" node " << p.
nodeName[e]
1717 <<
"(" << ne <<
") rcond " << rcond <<
" smin " << rcond * anorm
1718 <<
" norm " << anorm <<
" coupling " << coupling
1719 << (admissible ?
" admissible" :
" rejected");
1723 for (
int i = 0;
i !=
k; ++
i)
1724 if (rem[
i] &&
i != e && pm[
i *
k + e])
1725 for (
int j = 0;
j !=
k; ++
j)
1726 if (rem[
j] &&
j != e && pm[e *
k +
j] && !pm[
i *
k +
j])
1727 fill +=
static_cast<double>(ns[
i]) * ns[
j];
1728 if (
best < 0 || fill < best_fill) {
1736 const int e =
best, ne = ns[e];
1739 for (
int j = 0;
j !=
k; ++
j)
1740 if (rem[
j] &&
j != e && pm[e *
k +
j])
1742 for (
int i = 0;
i !=
k; ++
i)
1743 if (rem[
i] &&
i != e && pm[
i *
k + e])
1744 for (
int j = 0;
j !=
k; ++
j)
1745 if (rem[
j] &&
j != e && pm[e *
k +
j]) {
1746 cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, ns[
i], ns[
j],
1747 ne, -1.,
mb(
i, e),
n,
mb(e,
j),
n, 1.,
mb(
i,
j),
n);
1759 for (
int r = 0; r != from.
nbNodes; ++r)
1770 const int n = p.
size;
1771 for (
int r = 0; r != p.
nbNodes; ++r)
1781 const double *x,
double *y,
bool trans) {
1782 for (
int r = 0; r != p.
nbNodes; ++r)
1786 const double *
a = buf + p.
sShift(r,
c);
1788 cblas_dgemv(CblasRowMajor, CblasNoTrans, nr, nc, 1.,
a, p.
sLd(r,
c),
1791 cblas_dgemv(CblasRowMajor, CblasTrans, nr, nc, 1.,
a, p.
sLd(r,
c),
1809 std::vector<double> &
work,
1810 std::vector<__CLPK_integer> &iwork) {
1811 const int m = p.
order.size();
1812 std::vector<int> seq(p.
order);
1813 seq.insert(seq.end(), p.
core.begin(), p.
core.end());
1816 for (
int t = 0;
t !=
m; ++
t) {
1817 const int e = seq[
t], ne = ns[e];
1818 double *
d = buf + p.
mShift(e, e);
1819 const int ldd = p.
mLd(e, e);
1821 double coupling = 0;
1822 for (
int q =
t + 1; u > 0 && q < static_cast<int>(seq.size()); ++
q) {
1823 const int j = seq[
q];
1834 rcond_min,
work, iwork))
1837 for (
int q =
t + 1; q < static_cast<int>(seq.size()); ++
q) {
1838 const int j = seq[
q];
1843 for (
int qi =
t + 1; qi < static_cast<int>(seq.size()); ++qi) {
1844 const int i = seq[qi];
1847 for (
int qj =
t + 1; qj < static_cast<int>(seq.size()); ++qj) {
1848 const int j = seq[qj];
1851 cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, ns[
i], ns[
j], ne,
1879 int nrhs,
bool trans,
1880 const std::vector<char> *nz_in) {
1883 std::vector<int> seq(p.
order);
1884 seq.insert(seq.end(), p.
core.begin(), p.
core.end());
1887 std::vector<char> nz = nz_in ? *nz_in : std::vector<char>(
k, 1);
1888 auto blk = [&](
int a,
int b) {
return buf + p.
mShift(
a, b); };
1889 auto rr = [&](
int a) {
return r + off[
a]; };
1890 auto lu = [&](
int e) {
return const_cast<double *
>(blk(e, e)); };
1891 auto pv = [&](
int e) {
return const_cast<__CLPK_integer *
>(piv + off[e]); };
1892 auto core_solve = [&](
char t) {
1897 for (
auto c : p.
core)
1907 "error lapack dgetrs info = %d",
static_cast<int>(info));
1908 for (
auto c : p.
core)
1912 auto diag_solve = [&](
int e,
char t) {
1920 "error lapack dgetrs info = %d",
static_cast<int>(info));
1926 for (
int t = 0;
t !=
static_cast<int>(seq.size()); ++
t) {
1927 const int e = seq[
t];
1928 for (
int q = 0;
q != std::min(
t,
m); ++
q) {
1929 const int j = seq[
q];
1930 if (nz[
j] && p.
mShift(
j, e) >= 0) {
1931 sub_gemm(
true, ns[e], ns[
j], nrhs, blk(
j, e), p.
mLd(
j, e), rr(
j), ldr,
1939 for (
int t =
m - 1;
t >= 0; --
t) {
1940 const int e = seq[
t];
1941 for (
int q =
t + 1;
q !=
static_cast<int>(seq.size()); ++
q) {
1942 const int i = seq[
q];
1943 if (nz[
i] && p.
mShift(
i, e) >= 0) {
1944 sub_gemm(
true, ns[e], ns[
i], nrhs, blk(
i, e), p.
mLd(
i, e), rr(
i), ldr,
1949 CHKERR diag_solve(e,
'T');
1953 for (
int t = 0;
t !=
static_cast<int>(seq.size()); ++
t) {
1954 const int e = seq[
t];
1955 for (
int q = 0;
q != std::min(
t,
m); ++
q) {
1956 const int i = seq[
q];
1957 if (nz[
i] && p.
mShift(e,
i) >= 0) {
1964 CHKERR diag_solve(e,
'N');
1968 for (
int t =
m - 1;
t >= 0; --
t) {
1969 const int e = seq[
t];
1970 for (
int q =
t + 1;
q !=
static_cast<int>(seq.size()); ++
q) {
1971 const int j = seq[
q];
1972 if (nz[
j] && p.
mShift(e,
j) >= 0) {
1992 const int m = p.
order.size();
1993 std::vector<int> seq(p.
order);
1994 seq.insert(seq.end(), p.
core.begin(), p.
core.end());
1995 const int nseq = seq.size();
1998 auto blk = [&](
int a,
int b) {
return buf + p.
mShift(
a, b); };
1999 auto vv = [&](
int a) {
return v + off[
a]; };
2003 for (
int t = 0;
t !=
m; ++
t) {
2004 const int e = seq[
t];
2006 for (
int q =
t + 1;
q != nseq; ++
q) {
2007 const int i = seq[
q];
2015 for (
int t = nseq - 1;
t >= 0; --
t) {
2016 const int e = seq[
t];
2017 for (
int q = 0;
q != std::min(
t,
m); ++
q) {
2018 const int j = seq[
q];
2025 for (
int t = 0;
t !=
m; ++
t) {
2026 const int e = seq[
t];
2027 for (
int q =
t + 1;
q != nseq; ++
q) {
2028 const int j = seq[
q];
2036 for (
int t = nseq - 1;
t >= 0; --
t) {
2037 const int e = seq[
t];
2040 for (
int q = 0;
q != std::min(
t,
m); ++
q) {
2041 const int i = seq[
q];
2054 return 1. + 0.5 * std::sin(1. +
i);
2067 std::vector<double> &x,
2068 std::vector<double> &r,
2069 std::vector<double> &rs) {
2070 const int n = p.
size;
2075 for (
int i = 0;
i !=
n; ++
i) {
2078 b_norm = std::max(b_norm, std::abs(x[
i]));
2080 constexpr double inf = std::numeric_limits<double>::infinity();
2081 if (
elem_solve(p, lu, piv, x.data(),
n, 1,
false,
nullptr))
2085 for (
int i = 0;
i !=
n; ++
i)
2086 if (!std::isfinite(x[
i]))
2093 const double *blk = orig + p.
sShift(
a,
c);
2098 double r_norm = 0, x_norm = 0, a_norm = 0;
2099 for (
int i = 0;
i !=
n; ++
i) {
2100 if (!std::isfinite(r[
i]) || !std::isfinite(rs[
i]))
2102 r_norm = std::max(r_norm, std::abs(r[
i]));
2103 x_norm = std::max(x_norm, std::abs(x[
i]));
2104 a_norm = std::max(a_norm, rs[
i]);
2106 const double den = a_norm * x_norm + b_norm;
2107 if (!std::isfinite(den) || !(den > 0))
2109 const double be = r_norm / den;
2110 return std::isfinite(be) ? be : inf;
2115 return std::isfinite(be_dense)
2137 double u,
double rcond_min,
double be_tol,
2138 double &be_block,
double &be_dense) {
2139 const int n = nl.
size;
2140 std::vector<double> x, r, rs,
f,
work;
2141 std::vector<__CLPK_integer> piv(
n), iwork;
2146 std::vector<double> dense(dl.
elemSize, 0.);
2149 be_dense = std::numeric_limits<double>::infinity();
2154 be_block = std::numeric_limits<double>::infinity();
2164 const std::vector<int> &nodes) {
2166 for (
auto r : nodes) {
2171 return s.empty() ? std::string(
"none") :
s;
2183 auto &p =
s.patterns[pi];
2184 const int k = p.nbNodes;
2185 std::vector<double> scratch;
2186 for (
int ei = 0; ei !=
static_cast<int>(
s.elems.size()); ++ei) {
2187 auto &e =
s.elems[ei];
2188 if (e.pattern != pi)
2190 auto relayout_buf = [&](std::vector<double> &buf) {
2191 scratch.assign(buf.begin(), buf.end());
2193 buf.reserve(
static_cast<size_t>(nl.
size) * nl.
size);
2195 std::fill(buf.begin(), buf.end(), 0.);
2198 relayout_buf(
s.elemData[ei]);
2199 if (
s.hasPreconditioner)
2200 relayout_buf(
s.elemPrec[ei]);
2201 for (
int r = 0; r !=
k; ++r)
2202 for (
int c = 0;
c !=
k; ++
c)
2203 if (p.isListed(r,
c)) {
2204 auto idx =
s.findMutable(
s.elemEntities[e.entBegin + r].uid,
2205 s.elemEntities[e.entBegin +
c].uid);
2206 idx->setStorage(nl.
sShift(r,
c), nl.
sLd(r,
c), ei);
2208 for (
int r = 0; r !=
k; ++r)
2209 s.elemEntities[e.entBegin + r].offset = nl.
nodeOffset[r];
2212 s.maxElemBuffer = 0;
2213 for (
auto &
q :
s.patterns)
2214 s.maxElemBuffer = std::max(
s.maxElemBuffer,
q.elemSize);
2232 "A00 element matrices are already factorised in other storage");
2234 const bool in_prec = where == BlockStorage::FACTOR_IN_PRECONDITIONER;
2237 "No preconditioner blocks");
2243 auto get_matrix = [&](
int ei, std::vector<double> &out) {
2246 cblas_daxpy(out.size(), 1., storage.
elemPrec[ei].data(), 1, out.data(),
2250 std::vector<double> mat,
w;
2251 for (
int pi = 0; pi !=
static_cast<int>(storage.
patterns.size()); ++pi) {
2253 if (p.state != BlockPattern::LISTED)
2258 for (
int pass = 0; pass != 2 && probe < 0; ++pass)
2259 for (
int ei = 0; ei !=
static_cast<int>(storage.
elems.size()); ++ei) {
2260 auto &e = storage.
elems[ei];
2261 if (e.pattern != pi || !e.local || (pass == 0 && !e.owned))
2263 get_matrix(ei, mat);
2272 const int n = p.size;
2273 w.assign(
static_cast<size_t>(
n) *
n, 0.);
2278 double be_block = 0, be_dense = 0;
2279 bool verified =
true;
2280 if (nl.
state == BlockPattern::BLOCK) {
2281 std::vector<double> probe_mat(nl.
elemSize, 0.);
2285 nl.
beRef = be_dense;
2288 <<
"A00 pattern " << pi <<
": block elimination rejected on probe "
2289 <<
"(backward error " << be_block <<
", dense " << be_dense
2290 <<
"), element matrices are dense";
2296 <<
"A00 pattern " << pi <<
" (" << p.nbElems
2299 <<
"; doubles per element: listed " <<
listed_size(p) <<
", layout "
2300 << nl.
elemSize <<
", dense " <<
static_cast<size_t>(
n) *
n
2301 <<
"; probe backward error " << be_block <<
" (dense " << be_dense
2313 std::vector<double> scratch,
work, be_x, be_r, be_rs;
2314 std::vector<__CLPK_integer> iwork;
2315 for (
int ei = 0; ei !=
static_cast<int>(storage.
elems.size()); ++ei) {
2316 auto &e = storage.
elems[ei];
2317 e.factorised =
false;
2319 std::vector<double>().swap(storage.
elemDense[ei]);
2320 if (!e.size || !e.local)
2322 auto &p = storage.
patterns[e.pattern];
2325 cblas_daxpy(buf.size(), 1., storage.
elemData[ei].data(), 1, buf.data(),
2332 "A00 element matrix is zero (not assembled or singular)");
2335 if (p.state == BlockPattern::LISTED)
2337 "A00 pattern not analysed");
2339 auto piv = storage.
pivots.data() + e.pivShift;
2340 if (p.state == BlockPattern::BLOCK)
2341 scratch.assign(buf.begin(), buf.end());
2343 if (!ret && p.state == BlockPattern::BLOCK) {
2347 p.beMax = std::max(p.beMax, be);
2352 if (p.state != BlockPattern::BLOCK)
2354 "error lapack dgetrf, A00 element matrix is singular");
2357 dense.assign(
static_cast<size_t>(e.size) * e.size, 0.);
2359 if (
lapack_dgetrf(e.size, e.size, dense.data(), e.size, piv) != 0)
2361 "error lapack dgetrf, A00 element matrix is singular");
2365 e.factorised =
true;
2367 for (
int pi = 0; pi !=
static_cast<int>(storage.
patterns.size()); ++pi) {
2373 <<
"A00 pattern " << pi <<
": " << p.nbFallback <<
" of " << p.nbElems
2374 <<
" elements failed block pivot or backward error test and are "
2378 for (
int pi = 0; pi !=
static_cast<int>(storage.
patterns.size()); ++pi) {
2380 if (p.state == BlockPattern::BLOCK) {
2382 <<
"A00 pattern " << pi <<
": largest backward error " << p.beMax
2383 <<
" (dense on probe " << p.beRef <<
"), dense fallback "
2394 auto &fe_order = storage.
feOrder;
2395 fe_order.resize(
index.size());
2396 std::iota(fe_order.begin(), fe_order.end(), 0);
2397 std::sort(fe_order.begin(), fe_order.end(), [&
index](
int a,
int b) {
2398 if (index[a].getFEUId() != index[b].getFEUId())
2399 return index[a].getFEUId() < index[b].getFEUId();
2402 auto &col_order = storage.
colOrder;
2403 col_order.resize(
index.size());
2404 std::iota(col_order.begin(), col_order.end(), 0);
2405 std::sort(col_order.begin(), col_order.end(), [&
index](
int a,
int b) {
2406 if (index[a].getColUId() != index[b].getColUId())
2407 return index[a].getColUId() < index[b].getColUId();
2415 for (
auto &
d :
s.storage->blockIndex) {
2416 if (
d.getElem() == -1)
2417 s.blocks.push_back({
d.getMatShift(),
d.getLd(),
d.getRow(),
d.getCol(),
2418 d.getNbRows(),
d.getNbCols(),
d.getLocRow(),
2421 s.blocks.shrink_to_fit();
2422 s.hasElems = !
s.storage->elems.empty();
2423 s.numbering = BlockStructure::PARENT;
2432template <
typename FUN>
2435 double *data = storage.data.data();
2436 for (
auto &b : ctx.
blocks)
2437 fun(data + b.shift, b.ld, b.row, b.col, b.nbRows, b.nbCols, b.locRow,
2440 for (
int ei = 0; ei !=
static_cast<int>(storage.elems.size()); ++ei) {
2441 auto &e = storage.elems[ei];
2442 auto &p = storage.patterns[e.pattern];
2443 double *buf = storage.elemData[ei].data();
2444 for (
int r = 0; r != p.nbNodes; ++r) {
2445 auto &re = storage.elemEntities[e.entBegin + r];
2446 for (
int c = 0;
c != p.nbNodes; ++
c) {
2447 if (!p.isListed(r,
c))
2449 auto &ce = storage.elemEntities[e.entBegin +
c];
2450 fun(buf + p.sShift(r,
c), p.sLd(r,
c), ctx.
globIdx(re),
2461std::pair<FieldEntity_vector_view::const_iterator,
2462 FieldEntity_vector_view::const_iterator>
2463field_ents_range(
const FieldEntity_vector_view &field_ents,
2464 const FieldBitNumber bit_number) {
2465 auto cmp_uid_lo = [](
const boost::weak_ptr<FieldEntity> &
a,
const UId &b) {
2466 if (
auto a_ptr =
a.lock())
2467 return a_ptr->getLocalUniqueId() < b;
2470 auto cmp_uid_hi = [](
const UId &b,
const boost::weak_ptr<FieldEntity> &
a) {
2471 if (
auto a_ptr =
a.lock())
2472 return b < a_ptr->getLocalUniqueId();
2475 const auto lo_uid = FieldEntity::getLocalUniqueIdCalculate(
2476 bit_number, get_id_for_min_type<MBVERTEX>());
2477 const auto hi_uid = FieldEntity::getLocalUniqueIdCalculate(
2478 bit_number, get_id_for_max_type<MBENTITYSET>());
2479 return std::make_pair(
2480 std::lower_bound(field_ents.begin(), field_ents.end(), lo_uid,
2482 std::upper_bound(field_ents.begin(), field_ents.end(), hi_uid,
2492 const SchurFEOpsFEandFields &ops) {
2493 std::vector<OpBits> bits(ops.size());
2494 for (
size_t op = 0; op != ops.size(); ++op)
2495 for (
auto &p : ops[op].second) {
2513 auto lo = dofs.lower_bound(uid);
2516 for (; lo != hi; ++lo) {
2517 const auto glob = (*lo)->getPetscGlobalDofIdx();
2522 r.loc = (*lo)->getPetscLocalDofIdx();
2530template <
typename IT> EntDofs ent_dofs(
IT lo,
const IT hi) {
2532 for (; lo != hi; ++lo) {
2533 const auto glob = (*lo)->getPetscGlobalDofIdx();
2538 r.loc = (*lo)->getPetscLocalDofIdx();
2553 using It = NumeredDofEntity_multiIndex::const_iterator;
2555 :
it(dofs.begin()),
end(dofs.
end()) {}
2557 std::pair<It, It> operator()(
const UId &uid) {
2559 while (
it !=
end && (*it)->getLocalUniqueId() < uid)
2562 while (
it !=
end && (*it)->getLocalUniqueId() <= hi_uid)
2564 return std::make_pair(lo,
it);
2571bool same_fe_connectivity(
const FieldEntity_vector_view &entities,
2572 const std::vector<std::pair<UId, int>> &record) {
2574 for (
const auto &entity : entities)
2575 if (
auto entity_ptr = entity.lock()) {
2576 if (
i == record.size() ||
2577 record[
i] != std::make_pair(entity_ptr->getLocalUniqueId(),
2578 entity_ptr->getNbDofsOnEnt()))
2582 return i == record.size();
2585BlockStorage::FeConnectivity
2586record_fe_connectivity(std::pair<UId, int>
key,
2587 const FieldEntity_vector_view &
rows,
2588 const FieldEntity_vector_view &cols,
2589 BlockStorage::FeConnectivity record = {}) {
2593 auto collect = [](
const auto &entities,
auto &
result) {
2594 result.reserve(entities.size());
2595 for (
const auto &entity : entities)
2596 if (auto entity_ptr = entity.lock())
2597 result.emplace_back(entity_ptr->getLocalUniqueId(),
2598 entity_ptr->getNbDofsOnEnt());
2600 collect(
rows, record.row);
2601 record.sameFields = same_fe_connectivity(cols, record.row);
2602 if (!record.sameFields)
2603 collect(cols, record.col);
2610MoFEMErrorCode build_block_index(DM dm,
const SchurFEOpsFEandFields &ops,
2611 BlockStorage &storage) {
2616 auto row_extractor = [](
auto &e) {
return e->entityCacheRowDofs; };
2617 auto col_extractor = [](
auto &e) {
return e->entityCacheColDofs; };
2619 auto extract_data = [](
auto &&its,
auto extractor) {
2620 std::vector<std::tuple<UId, int, int, int>> data;
2621 data.reserve(std::distance(its.first, its.second));
2623 for (; its.first != its.second; ++its.first) {
2624 if (
auto e = its.first->lock()) {
2625 if (
auto cache = extractor(e).lock()) {
2627 for (
auto dof = cache->loHi[0]; dof != cache->loHi[1]; ++dof) {
2628 if ((*dof)->getPetscGlobalDofIdx() != -1)
2631 auto uid = e->getLocalUniqueId();
2634 auto glob = (*cache->loHi[0])->getPetscGlobalDofIdx();
2635 auto loc = (*cache->loHi[0])->getPetscLocalDofIdx();
2636 while (
glob == -1 && cache->loHi[0] != cache->loHi[1]) {
2638 glob = (*cache->loHi[0])->getPetscGlobalDofIdx();
2639 loc = (*cache->loHi[0])->getPetscLocalDofIdx();
2641 data.emplace_back(uid,
glob, nb_dofs,
loc);
2645 for (
auto lo = cache->loHi[0]; lo != cache->loHi[1]; ++lo) {
2646 auto glob = (*lo)->getPetscGlobalDofIdx();
2649 "Wrong global index");
2655 data.emplace_back(uid, -1, 0, -1);
2663 auto &
index = storage.blockIndex;
2665 storage.feList.clear();
2666 storage.feConnectivity.clear();
2667 storage.feOps = ops;
2669 const auto bits = get_op_bits(*m_field_ptr, ops);
2672 const Problem *problem_ptr;
2674 auto cache_ptr = boost::make_shared<CacheTuple>();
2675 CHKERR m_field_ptr->cache_problem_entities(problem_ptr->getName(), cache_ptr);
2678 auto fe_method = boost::shared_ptr<MoFEM::FEMethod>(
new MoFEM::FEMethod());
2682 size_t nb_pairs = 0;
2683 for (
auto count_only : {
true,
false}) {
2686 index.reserve(nb_pairs);
2688 for (
int op = 0; op !=
static_cast<int>(ops.size()); ++op) {
2690 const auto &row_bit_numbers = bits[op].row;
2691 const auto &col_bit_numbers = bits[op].col;
2693 fe_method->preProcessHook = []() {
return 0; };
2694 fe_method->postProcessHook = []() {
return 0; };
2695 fe_method->operatorHook = [&]() {
2698 auto fe_uid = fe_method->numeredEntFiniteElementPtr->getLocalUniqueId();
2700 storage.feList.emplace_back(fe_uid, op);
2701 storage.feConnectivity.push_back(
2702 record_fe_connectivity({fe_uid, op}, fe_method->getRowFieldEnts(),
2703 fe_method->getColFieldEnts()));
2706 for (
size_t f = 0;
f != row_bit_numbers.size(); ++
f) {
2709 extract_data(field_ents_range(fe_method->getRowFieldEnts(),
2710 row_bit_numbers[
f]),
2712 auto col_data = extract_data(
2713 field_ents_range(fe_method->getColFieldEnts(),
2714 col_bit_numbers[
f]),
2717 for (
auto &r : row_data) {
2718 auto [r_uid, r_glob, r_nb_dofs, r_loc] =
r;
2721 for (
auto &
c : col_data) {
2722 auto [c_uid, c_glob, c_nb_dofs, c_loc] =
c;
2728 index.emplace_back(r_uid, c_uid, fe_uid, r_glob, c_glob,
2729 r_nb_dofs, c_nb_dofs, r_loc, c_loc);
2738 dm, ops[op].first, fe_method, 0, m_field_ptr->get_comm_size(),
2744 std::stable_sort(
index.begin(),
index.end(), BlockStorage::lessRowCol);
2746 [](
auto &
a,
auto &b) {
2747 return a.getRowUId() == b.getRowUId() &&
2748 a.getColUId() == b.getColUId();
2751 index.shrink_to_fit();
2753 std::sort(storage.feList.begin(), storage.feList.end());
2754 storage.feList.erase(
2755 std::unique(storage.feList.begin(), storage.feList.end()),
2756 storage.feList.end());
2757 std::sort(storage.feConnectivity.begin(), storage.feConnectivity.end(),
2758 [](
const auto &
a,
const auto &b) { return a.key < b.key; });
2766 auto &storage = *
s.storage;
2767 auto &
index = storage.blockIndex;
2770 size_t mem_size = 0;
2772 v.setStorage(mem_size,
v.getNbCols(), -1);
2773 mem_size +=
static_cast<size_t>(
v.getNbRows()) *
v.getNbCols();
2776 if (mem_size > storage.data.max_size())
2778 storage.dataSize = mem_size;
2782 if (!storage.data.empty())
2783 storage.data.assign(mem_size, 0.);
2790 CHKERR VecSetDM(ghost_x, PETSC_NULLPTR);
2791 CHKERR VecSetDM(ghost_y, PETSC_NULLPTR);
2797 CHKERR PetscObjectGetComm((PetscObject)dm, &
comm);
2798 std::array<size_t, 2> loc_stats = {
index.size(), mem_size *
sizeof(
double)};
2799 std::array<size_t, 2> sum_stats, max_stats;
2800 MPI_Allreduce(loc_stats.data(), sum_stats.data(), 2, MPIU_SIZE_T, MPI_SUM,
2802 MPI_Allreduce(loc_stats.data(), max_stats.data(), 2, MPIU_SIZE_T, MPI_MAX,
2804 constexpr double mb = 1024. * 1024.;
2806 <<
"Blocks " << sum_stats[0] <<
" (max per process " << max_stats[0]
2807 <<
"), data " << sum_stats[1] /
mb <<
" MB (max per process "
2808 << max_stats[1] /
mb <<
" MB), index "
2809 << (sum_stats[0] * (
sizeof(BlockStorage::Indexes) + 2 *
sizeof(
int) +
2810 sizeof(BlockStructure::Block))) /
2825 auto data_ptr = boost::make_shared<BlockStructure>();
2826 data_ptr->storage = boost::make_shared<BlockStorage>();
2827 CHKERR build_block_index(dm, schur_fe_op_vec, *data_ptr->storage);
2828 CHKERR finalise_block_structure(dm, *data_ptr);
2834 boost::shared_ptr<BlockStructure> data_ptr) {
2836 if (!data_ptr || !data_ptr->storage)
2838 auto &storage = *data_ptr->storage;
2839 if (schur_fe_op_vec != storage.feOps)
2841 "A block structure is rebuilt with the elements and field pairs "
2842 "it was created with; create a new one for other pairs");
2847 if (storage.nested) {
2848 storage.patternCache = std::move(storage.patterns);
2849 storage.patterns.clear();
2852 storage.elemDataCache.clear();
2853 storage.elemPrecCache.clear();
2854 for (
size_t ei = 0; ei != storage.elems.size(); ++ei) {
2855 const auto uid = storage.elems[ei].feUId;
2856 storage.elemDataCache.emplace_back(uid, std::move(storage.elemData[ei]));
2857 if (storage.hasPreconditioner)
2858 storage.elemPrecCache.emplace_back(uid,
2859 std::move(storage.elemPrec[ei]));
2861 storage.elems.clear();
2862 storage.elemEntities.clear();
2863 storage.elemData.clear();
2864 storage.elemPrec.clear();
2865 storage.elemDense.clear();
2866 storage.pivots.clear();
2867 storage.maxElemSize = 0;
2868 storage.maxElemBuffer = 0;
2869 storage.dataCache.swap(storage.data);
2870 std::vector<double>().swap(storage.data);
2871 storage.nested =
false;
2873 storage.resetFactors();
2887 bool changed =
false;
2889 std::vector<FeRecord> current;
2893 const int comm_size = m_field_ptr->get_comm_size();
2895 for (
int op = 0; op !=
static_cast<int>(schur_fe_op_vec.size()); ++op) {
2896 const auto &
name = schur_fe_op_vec[op].first;
2897 auto lo = fes.lower_bound(boost::make_tuple(
name, 0));
2898 auto hi = fes.upper_bound(boost::make_tuple(
name, comm_size));
2899 for (; lo != hi; ++lo)
2900 current.push_back({(*lo)->getLocalUniqueId(), op, seq++, lo->get()});
2902 std::sort(current.begin(), current.end(), [](
auto &
a,
auto &b) {
2904 return a.uid < b.uid;
2908 std::vector<std::pair<UId, int>> current_keys;
2909 current_keys.reserve(current.size());
2910 for (
auto &
c : current)
2911 current_keys.emplace_back(
c.uid,
c.op);
2912 std::vector<std::pair<UId, int>>
removed, added;
2913 std::set_difference(storage.feList.begin(), storage.feList.end(),
2914 current_keys.begin(), current_keys.end(),
2916 std::set_difference(current_keys.begin(), current_keys.end(),
2917 storage.feList.begin(), storage.feList.end(),
2918 std::back_inserter(added));
2922 auto previous = storage.feConnectivity.begin();
2923 for (
auto &record : current) {
2924 const auto key = std::make_pair(record.uid, record.op);
2928 (!same_fe_connectivity(record.fe->getRowFieldEnts(),
previous->row) ||
2929 !same_fe_connectivity(record.fe->getColFieldEnts(),
2932 record.changed =
true;
2934 added.push_back(
key);
2938 std::sort(added.begin(), added.end());
2942 PetscReal patch_fraction = 0.25;
2943 CHKERR ::PetscOptionsGetReal(PETSC_NULLPTR,
"",
2944 "-schur_rebuild_patch_fraction", &patch_fraction,
2946 const bool patch =
removed.size() + added.size() <=
2947 patch_fraction * std::max<size_t>(current.size(), 1);
2949 size_t nb_patch_ents = 0, nb_visited = 0;
2952 CHKERR build_block_index(dm, schur_fe_op_vec, storage);
2956 auto &
index = storage.blockIndex;
2957 const auto bits = get_op_bits(*m_field_ptr, schur_fe_op_vec);
2958 auto find_current = [&](
const UId &uid) {
2959 return std::lower_bound(
2960 current.begin(), current.end(), uid,
2961 [](
const FeRecord &
a,
const UId &u) { return a.uid < u; });
2967 std::vector<UId> ents;
2969 auto &fe_order = storage.feOrder;
2971 auto lo = std::lower_bound(
2972 fe_order.begin(), fe_order.end(),
r.first,
2973 [&
index](
int i,
const UId &u) { return index[i].getFEUId() < u; });
2974 for (; lo != fe_order.end() &&
index[*lo].getFEUId() ==
r.first;
2976 ents.push_back(
index[*lo].getRowUId());
2977 ents.push_back(
index[*lo].getColUId());
2980 for (
auto &
a : added) {
2981 auto it = find_current(
a.first);
2982 while (
it->op !=
a.second)
2985 auto &op_bits = bits[
a.second];
2986 for (
size_t f = 0;
f != op_bits.row.size(); ++
f) {
2987 auto rr = field_ents_range(fe.getRowFieldEnts(), op_bits.row[
f]);
2988 for (; rr.first != rr.second; ++rr.first)
2989 if (
auto e = rr.first->lock())
2990 ents.push_back(e->getLocalUniqueId());
2991 auto cr = field_ents_range(fe.getColFieldEnts(), op_bits.col[
f]);
2992 for (; cr.first != cr.second; ++cr.first)
2993 if (
auto e = cr.first->lock())
2994 ents.push_back(e->getLocalUniqueId());
2997 std::sort(ents.begin(), ents.end());
2998 ents.erase(std::unique(ents.begin(), ents.end()), ents.end());
3000 nb_patch_ents = ents.size();
3001 auto ent_pos = [&ents](
const UId &u) {
3002 auto it = std::lower_bound(ents.begin(), ents.end(), u);
3003 return (
it != ents.end() && *
it == u)
3004 ?
static_cast<int>(
it - ents.begin())
3010 std::vector<int> visit;
3013 m_field_ptr->get_ents_elements_adjacency()->get<Unique_mi_tag>();
3014 for (
auto &u : ents) {
3015 auto r = adj.equal_range(u);
3016 for (;
r.first !=
r.second; ++
r.first) {
3017 const auto fe_uid =
r.first->getFeUniqueId();
3018 for (
auto it = find_current(fe_uid);
3019 it != current.end() &&
it->uid == fe_uid; ++
it)
3020 visit.push_back(
static_cast<int>(
it - current.begin()));
3023 std::sort(visit.begin(), visit.end(), [¤t](
int a,
int b) {
3024 return current[a].seq < current[b].seq;
3026 visit.erase(std::unique(visit.begin(), visit.end()), visit.end());
3028 nb_visited = visit.size();
3030 const auto &row_dofs = *problem_ptr->getNumeredRowDofsPtr();
3031 const auto &col_dofs = *problem_ptr->getNumeredColDofsPtr();
3032 std::vector<EntDofs> row_info(ents.size()), col_info(ents.size());
3033 for (
size_t i = 0;
i != ents.size(); ++
i) {
3034 row_info[
i] = ent_dofs(row_dofs, ents[
i]);
3035 col_info[
i] = ent_dofs(col_dofs, ents[
i]);
3040 std::vector<BlockStorage::Indexes> fresh;
3041 std::vector<std::pair<UId, const EntDofs *>>
rows, cols;
3042 for (
auto ci : visit) {
3043 auto &rec = current[ci];
3044 auto &op_bits = bits[rec.op];
3045 for (
size_t f = 0;
f != op_bits.row.size(); ++
f) {
3048 auto rr = field_ents_range(rec.fe->getRowFieldEnts(), op_bits.row[
f]);
3049 for (; rr.first != rr.second; ++rr.first)
3050 if (
auto e = rr.first->lock()) {
3051 const auto u = e->getLocalUniqueId();
3052 const int p = ent_pos(u);
3053 if (p >= 0 && row_info[p].
nb)
3054 rows.emplace_back(u, &row_info[p]);
3056 auto cr = field_ents_range(rec.fe->getColFieldEnts(), op_bits.col[
f]);
3057 for (; cr.first != cr.second; ++cr.first)
3058 if (
auto e = cr.first->lock()) {
3059 const auto u = e->getLocalUniqueId();
3060 const int p = ent_pos(u);
3061 if (p >= 0 && col_info[p].
nb)
3062 cols.emplace_back(u, &col_info[p]);
3064 for (
auto &r :
rows)
3065 for (auto &
c : cols)
3066 fresh.emplace_back(
r.first,
c.first, rec.uid,
r.second->
glob,
3071 std::stable_sort(fresh.begin(), fresh.end(), BlockStorage::lessRowCol);
3072 fresh.erase(std::unique(fresh.begin(), fresh.end(),
3073 [](
auto &
a,
auto &b) {
3074 return a.getRowUId() == b.getRowUId() &&
3075 a.getColUId() == b.getColUId();
3082 std::vector<char> keep(
index.size(), 1);
3083 for (
auto &u : ents) {
3084 auto range = storage.rowRange(u);
3085 for (
auto it = range.first;
it != range.second; ++
it)
3086 if (std::binary_search(ents.begin(), ents.end(),
it->getColUId()))
3089 DofRangeWalk row_walk(row_dofs), col_walk(col_dofs);
3090 for (
size_t i = 0;
i !=
index.size();) {
3091 const auto uid =
index[
i].getRowUId();
3093 while (e !=
index.size() &&
index[e].getRowUId() == uid)
3095 if (std::any_of(keep.begin() +
i, keep.begin() + e,
3096 [](
char k) { return k; })) {
3097 const auto range = row_walk(uid);
3098 const auto d = ent_dofs(range.first, range.second);
3109 auto &col_order = storage.colOrder;
3110 for (
size_t p = 0; p != col_order.size();) {
3111 const auto uid =
index[col_order[p]].getColUId();
3113 while (e != col_order.size() &&
index[col_order[e]].getColUId() == uid)
3115 if (std::any_of(col_order.begin() + p, col_order.begin() + e,
3116 [&keep](
int i) { return keep[i]; })) {
3117 const auto range = col_walk(uid);
3118 const auto d = ent_dofs(range.first, range.second);
3119 for (; p != e; ++p) {
3120 const int i = col_order[p];
3133 std::vector<BlockStorage::Indexes> merged;
3134 merged.reserve(std::count(keep.begin(), keep.end(), 1) + fresh.size());
3135 auto f = fresh.begin();
3136 for (
size_t i = 0;
i !=
index.size(); ++
i) {
3139 while (
f != fresh.end() && BlockStorage::lessRowCol(*
f,
index[
i]))
3140 merged.push_back(*
f++);
3141 merged.push_back(
index[
i]);
3143 merged.insert(merged.end(),
f, fresh.end());
3145 storage.feList.swap(current_keys);
3148 std::vector<BlockStorage::FeConnectivity> current_connectivity;
3149 current_connectivity.reserve(current.size());
3150 previous = storage.feConnectivity.begin();
3151 for (
const auto &record : current) {
3152 const auto key = std::make_pair(record.uid, record.op);
3155 BlockStorage::FeConnectivity next;
3160 if (!found || record.changed)
3161 next = record_fe_connectivity(
key, record.fe->getRowFieldEnts(),
3162 record.fe->getColFieldEnts(),
3164 current_connectivity.push_back(std::move(next));
3166 storage.feConnectivity.swap(current_connectivity);
3169 CHKERR finalise_block_structure(dm, *data_ptr);
3172 <<
"Rebuilt block structure (" << (patch ?
"patch" :
"full")
3173 <<
"): removed elements " <<
removed.size() <<
", added elements "
3174 << added.size() <<
", patch entities " << nb_patch_ents
3175 <<
", elements visited " << nb_visited <<
", blocks "
3176 << storage.blockIndex.size();
3178 CHKERR PetscObjectGetComm((PetscObject)dm, &
comm);
3192 InsertMode iora,
bool trans) {
3195 CHKERR MatShellGetContext(mat, (
void **)&ctx);
3196 auto &storage = *ctx->
storage;
3197 storage.ensureAllocated();
3199 PetscLogEventBegin(SchurEvents::MOFEM_EVENT_BlockStructureMult, 0, 0, 0, 0);
3202 CHKERR VecGetLocalSize(x, &x_loc_size);
3204 Vec ghost_x = ctx->
ghostX;
3205 Vec ghost_y = ctx->
ghostY;
3207 std::swap(ghost_x, ghost_y);
3209 CHKERR storage.checkNotFailed();
3211 if (with_p && !storage.hasPreconditioner)
3213 "No preconditioner blocks");
3215 ctx->
hasElems && storage.isFactorised() &&
3216 (storage.factorStorage == BlockStorage::FACTOR_IN_DATA || with_p);
3218 storage.factorStorage == BlockStorage::FACTOR_IN_PRECONDITIONER
3222 CHKERR VecCopy(x, ghost_x);
3225 CHKERR VecGhostGetLocalForm(ghost_y, &loc_ghost_y);
3226 CHKERR VecSet(loc_ghost_y, 0.);
3227 CHKERR VecGhostRestoreLocalForm(ghost_y, &loc_ghost_y);
3230 std::vector<double> xe, ye;
3232 xe.resize(storage.maxElemSize);
3233 ye.resize(storage.maxElemSize);
3236 auto mult_pass = [&](
bool ghost_pass) {
3239 const double *x_array;
3241 CHKERR VecGhostGetLocalForm(ghost_x, &loc_ghost_x);
3242 CHKERR VecGetArrayRead(loc_ghost_x, &x_array);
3246 CHKERR VecGhostGetLocalForm(ghost_y, &loc_ghost_y);
3247 CHKERR VecGetArray(loc_ghost_y, &y_array);
3249 const double *data = storage.data.data();
3250 const auto cblas_trans = trans ? CblasTrans : CblasNoTrans;
3252 for (
auto &b : ctx->
blocks) {
3253 const int x_loc = trans ? b.locRow : b.locCol;
3254 const int y_loc = trans ? b.locCol : b.locRow;
3256 if (x_loc < 0 || y_loc < 0)
3258 if ((x_loc >= x_loc_size) != ghost_pass)
3260 cblas_dgemv(CblasRowMajor, cblas_trans, b.nbRows, b.nbCols, 1.0,
3261 data + b.shift, b.ld, x_array + x_loc, 1, 1.0,
3262 y_array + y_loc, 1);
3266 for (
int ei = 0; ei !=
static_cast<int>(storage.elems.size()); ++ei) {
3267 auto &e = storage.elems[ei];
3268 const int n = e.size;
3273 if (use_lu && !e.factorised)
3275 auto ent_begin = storage.elemEntities.data() + e.entBegin;
3276 auto ent_end = storage.elemEntities.data() + e.entEnd;
3280 bool any_ghost =
false;
3281 bool available =
true;
3282 for (
auto ent = ent_begin; ent != ent_end; ++ent) {
3288 else if (
loc >= x_loc_size)
3291 if (!available || any_ghost != ghost_pass)
3294 for (
auto ent = ent_begin; ent != ent_end; ++ent)
3296 cblas_dcopy(ent->nb, x_array + ctx->
locIdx(*ent), 1,
3297 xe.data() + ent->offset, 1);
3299 auto &p = storage.patterns[e.pattern];
3300 auto piv = storage.pivots.data() + e.pivShift;
3310 std::fill(ye.begin(), ye.begin() +
n, 0.);
3319 for (
auto ent = ent_begin; ent != ent_end; ++ent)
3321 cblas_daxpy(ent->nb, 1.0, y_e + ent->offset, 1,
3322 y_array + ctx->
locIdx(*ent), 1);
3326 CHKERR VecRestoreArrayRead(loc_ghost_x, &x_array);
3327 CHKERR VecRestoreArray(loc_ghost_y, &y_array);
3328 CHKERR VecGhostRestoreLocalForm(ghost_x, &loc_ghost_x);
3329 CHKERR VecGhostRestoreLocalForm(ghost_y, &loc_ghost_y);
3333 CHKERR VecGhostUpdateBegin(ghost_x, INSERT_VALUES, SCATTER_FORWARD);
3335 CHKERR VecGhostUpdateEnd(ghost_x, INSERT_VALUES, SCATTER_FORWARD);
3338 CHKERR VecGhostUpdateBegin(ghost_y, ADD_VALUES, SCATTER_REVERSE);
3339 CHKERR VecGhostUpdateEnd(ghost_y, ADD_VALUES, SCATTER_REVERSE);
3343 CHKERR VecCopy(ghost_y, y);
3346 CHKERR VecAXPY(y, 1., ghost_y);
3352 PetscLogEventEnd(SchurEvents::MOFEM_EVENT_BlockStructureMult, 0, 0, 0, 0);
3364 InsertMode iora,
bool trans) {
3367 CHKERR MatShellGetContext(mat, (
void **)&ctx);
3368 auto &storage = *ctx->
storage;
3369 storage.ensureAllocated();
3371 PetscLogEventBegin(SchurEvents::MOFEM_EVENT_BlockStructureSolve, 0, 0, 0, 0);
3373 if (ctx->
numbering != BlockStructure::BLOCK)
3375 "Solve is implemented only for A00 block of nested Schur matrix, "
3376 "see createSchurNestedMatrixStruture");
3378 CHKERR storage.checkNotFailed();
3380 if (with_p && !storage.hasPreconditioner)
3382 "No preconditioner blocks");
3387 }
else if (!storage.hasPreconditioner) {
3394 auto &lu_bufs = with_p ? storage.elemPrec : storage.elemData;
3397 CHKERR VecGetLocalSize(x, &nb_local);
3399 if (iora == INSERT_VALUES)
3400 CHKERR VecZeroEntries(x);
3403 CHKERR VecGetArray(x, &x_array);
3404 const double *f_array;
3405 CHKERR VecGetArrayRead(
f, &f_array);
3407 std::vector<double>
t(storage.maxElemSize);
3408 std::vector<double> scratch;
3409 std::vector<__CLPK_integer> scratch_piv;
3411 scratch.resize(
static_cast<size_t>(storage.maxElemSize) *
3412 storage.maxElemSize);
3413 scratch_piv.resize(storage.maxElemSize);
3416 const char lapack_trans = trans ?
'N' :
'T';
3418 for (
int ei = 0; ei !=
static_cast<int>(storage.elems.size()); ++ei) {
3419 auto &e = storage.elems[ei];
3420 const int n = e.size;
3423 if (use_lu && !e.factorised)
3425 auto ent_begin = storage.elemEntities.data() + e.entBegin;
3426 auto ent_end = storage.elemEntities.data() + e.entEnd;
3430 for (
auto ent = ent_begin; ent != ent_end; ++ent) {
3431 if (ent->nb && (ent->locBlock < 0 || ent->locBlock >= nb_local)) {
3439 for (
auto ent = ent_begin; ent != ent_end; ++ent)
3441 cblas_dcopy(ent->nb, f_array + ent->locBlock, 1,
t.data() + ent->offset,
3444 auto &p = storage.patterns[e.pattern];
3445 auto piv = storage.pivots.data() + e.pivShift;
3449 info =
lapack_dgetrs(lapack_trans,
n, 1, storage.elemDense[ei].data(),
3450 n, piv,
t.data(),
n);
3455 std::fill(scratch.begin(), scratch.begin() +
static_cast<size_t>(
n) *
n,
3461 scratch_piv.data(),
t.data(),
n);
3465 "error lapack solve info = %d",
static_cast<int>(info));
3467 for (
auto ent = ent_begin; ent != ent_end; ++ent)
3469 cblas_daxpy(ent->nb, 1.0,
t.data() + ent->offset, 1,
3470 x_array + ent->locBlock, 1);
3473 CHKERR VecRestoreArray(x, &x_array);
3474 CHKERR VecRestoreArrayRead(
f, &f_array);
3476 PetscLogEventEnd(SchurEvents::MOFEM_EVENT_BlockStructureSolve, 0, 0, 0, 0);
3481static PetscErrorCode
mult(Mat mat, Vec x, Vec y) {
3494static PetscErrorCode
solve(Mat mat, Vec x, Vec y) {
3508 const PetscInt
rows[], PetscScalar diag,
3513 CHKERR MatShellGetContext(
A, (
void **)&ctx);
3514 auto &storage = *ctx->
storage;
3515 CHKERR storage.modified();
3516 storage.ensureAllocated();
3518 PetscLogEventBegin(SchurEvents::MOFEM_EVENT_zeroRowsAndCols, 0, 0, 0, 0);
3522 std::vector<int> zero_idx;
3532 CHKERR ISGetSize(is_local, &is_nb_rows);
3534 CHKERR ISGetIndices(is_local, &ptr);
3535 zero_idx.assign(ptr, ptr + is_nb_rows);
3536 CHKERR ISRestoreIndices(is_local, &ptr);
3541 std::sort(zero_idx.begin(), zero_idx.end());
3542 zero_idx.erase(std::unique(zero_idx.begin(), zero_idx.end()), zero_idx.end());
3545 CHKERR MatGetLocalSize(
A, &loc_m, &loc_n);
3548 int nb_cols,
int loc_row,
int loc_col) {
3549 if (!nb_rows || !nb_cols)
3552 auto lo = std::lower_bound(zero_idx.begin(), zero_idx.end(),
row);
3553 for (; lo != zero_idx.end() && *lo <
row + nb_rows; ++lo) {
3554 auto *row_ptr = ptr +
static_cast<size_t>(*lo -
row) * ld;
3555 std::fill(row_ptr, row_ptr + nb_cols, 0.);
3558 const bool diag_block =
row ==
col && loc_row >= 0 && loc_row < loc_m &&
3559 loc_col >= 0 && loc_col < loc_n;
3560 lo = std::lower_bound(zero_idx.begin(), zero_idx.end(),
col);
3561 for (; lo != zero_idx.end() && *lo <
col + nb_cols; ++lo) {
3562 const int c = *lo -
col;
3563 for (
int i = 0;
i != nb_rows; ++
i)
3564 ptr[
static_cast<size_t>(
i) * ld +
c] = 0.;
3565 if (diag_block &&
c < nb_rows)
3566 ptr[
static_cast<size_t>(
c) * ld +
c] = diag;
3570 PetscLogEventEnd(SchurEvents::MOFEM_EVENT_zeroRowsAndCols, 0, 0, 0, 0);
3578 CHKERR MatShellGetContext(
m, (
void **)&ctx);
3579 auto &storage = *ctx->
storage;
3580 storage.ensureAllocated();
3581 std::fill(storage.data.begin(), storage.data.end(), 0.);
3582 for (
auto &buf : storage.elemData)
3583 std::fill(buf.begin(), buf.end(), 0.);
3584 for (
auto &buf : storage.elemPrec)
3585 std::fill(buf.begin(), buf.end(), 0.);
3586 storage.resetFactors();
3592 CHKERR MatShellSetManageScalingShifts(mat_raw);
3593 CHKERR MatShellSetOperation(mat_raw, MATOP_MULT, (
void (*)(
void))
mult);
3594 CHKERR MatShellSetOperation(mat_raw, MATOP_MULT_ADD,
3596 CHKERR MatShellSetOperation(mat_raw, MATOP_MULT_TRANSPOSE,
3598 CHKERR MatShellSetOperation(mat_raw, MATOP_MULT_TRANSPOSE_ADD,
3600 CHKERR MatShellSetOperation(mat_raw, MATOP_SOLVE, (
void (*)(
void))
solve);
3601 CHKERR MatShellSetOperation(mat_raw, MATOP_SOLVE_ADD,
3603 CHKERR MatShellSetOperation(mat_raw, MATOP_SOLVE_TRANSPOSE,
3605 CHKERR MatShellSetOperation(mat_raw, MATOP_SOLVE_TRANSPOSE_ADD,
3607 CHKERR MatShellSetOperation(mat_raw, MATOP_ZERO_ENTRIES,
3609 CHKERR MatShellSetOperation(mat_raw, MATOP_ZERO_ROWS_COLUMNS,
3616 boost::shared_ptr<BlockStructure> data) {
3619 auto nb_local = problem_ptr->nbLocDofsRow;
3620 auto nb_global = problem_ptr->nbDofsRow;
3623 if (nb_local != problem_ptr->nbLocDofsCol) {
3625 <<
"Wrong size " << nb_local <<
" != " << problem_ptr->nbLocDofsCol;
3627 "nb. cols is inconsistent with nb. rows");
3629 if (nb_global != problem_ptr->nbDofsCol) {
3631 <<
"Wrong size " << nb_global <<
" != " << problem_ptr->nbDofsCol;
3633 "nb. cols is inconsistent with nb. rows");
3638 CHKERR PetscObjectGetComm((PetscObject)dm, &
comm);
3641 CHKERR MatCreateShell(
comm, nb_local, nb_local, nb_global, nb_global,
3642 (
void *)data.get(), &mat_raw);
3651 std::vector<std::string> fields_name,
3652 std::vector<boost::shared_ptr<Range>> field_ents,
3656 CHKERR MatShellGetContext(
B, (
void **)&ctx);
3657 auto &storage = *ctx->
storage;
3658 auto &
index = storage.blockIndex;
3659 storage.ensureAllocated();
3661 PetscLogEventBegin(SchurEvents::MOFEM_EVENT_AssembleSchurMat, 0, 0, 0, 0);
3666 CHKERR storage.checkNotFailed();
3669 if (with_p && !storage.hasPreconditioner)
3671 "No preconditioner blocks");
3673 if (fields_name.size() != field_ents.size()) {
3675 "fields_name.size() != field_ents.size()");
3678 std::vector<std::pair<UId, UId>> a00_fields_uids;
3679 a00_fields_uids.reserve(fields_name.size());
3680 auto it_field_ents = field_ents.begin();
3681 for (
auto &
f : fields_name) {
3683 if (*it_field_ents) {
3684 for (
auto p = (*it_field_ents)->pair_begin();
3685 p != (*it_field_ents)->pair_end(); ++p) {
3686 a00_fields_uids.emplace_back(
3687 DofEntity::getLoFieldEntityUId(bn, p->first),
3688 DofEntity::getHiFieldEntityUId(bn, p->second));
3691 a00_fields_uids.emplace_back(FieldEntity::getLoBitNumberUId(bn),
3692 FieldEntity::getHiBitNumberUId(bn));
3697 auto is_a00 = [&](
const UId &uid) {
3698 for (
auto &uid_pair : a00_fields_uids) {
3699 if (uid >= uid_pair.first && uid < uid_pair.second)
3706 std::vector<const Idx *> a00_blocks, a01_blocks, a10_blocks, a11_blocks;
3712 std::map<UId, LocIdx> a00_indexing, a11_indexing;
3713 std::vector<UId> col_uids;
3714 std::vector<double> a00_mat, a01t_mat, a10_mat, s_mat, tmp_block;
3715 std::vector<__CLPK_integer> ipiv;
3716 std::vector<int> glob_idx, row_glob_idx, col_glob_idx;
3717 std::vector<char> nz;
3720 auto set_values_block = [&](
const Idx *b) {
3722 const int nb_rows = b->getNbRows();
3723 const int nb_cols = b->getNbCols();
3724 row_glob_idx.resize(nb_rows);
3725 col_glob_idx.resize(nb_cols);
3726 std::iota(row_glob_idx.begin(), row_glob_idx.end(), b->getRow());
3727 std::iota(col_glob_idx.begin(), col_glob_idx.end(), b->getCol());
3728 CHKERR AOApplicationToPetsc(ao, nb_rows, row_glob_idx.data());
3729 CHKERR AOApplicationToPetsc(ao, nb_cols, col_glob_idx.data());
3730 const double *ptr = storage.blockPtr(*b);
3731 if (b->getLd() != nb_cols) {
3732 tmp_block.resize(
static_cast<size_t>(nb_rows) * nb_cols);
3733 copy_block(tmp_block.data(), nb_cols, 0, 0, ptr, b->getLd(), nb_rows,
3735 ptr = tmp_block.data();
3738 col_glob_idx.data(), ptr, ADD_VALUES);
3743 auto set_local_indices = [](
auto &indexing,
auto &row_blocks,
3746 for (
auto b : row_blocks)
3747 indexing.emplace(b->getRowUId(), LocIdx{0, b->getNbRows(), b->getRow()});
3748 for (
auto b : col_blocks)
3749 indexing.emplace(b->getColUId(), LocIdx{0, b->getNbCols(), b->getCol()});
3751 for (
auto &p : indexing) {
3752 p.second.index =
size;
3753 size += p.second.size;
3758 const auto &fe_order = storage.feOrder;
3762 auto classify_fe = [&](
size_t &p) {
3767 const auto fe_uid =
index[fe_order[p]].getFEUId();
3768 for (; p != fe_order.size() &&
index[fe_order[p]].getFEUId() == fe_uid;
3770 auto b = &
index[fe_order[p]];
3771 const bool r00 = is_a00(b->getRowUId());
3772 const bool c00 = is_a00(b->getColUId());
3774 a00_blocks.push_back(b);
3776 a01_blocks.push_back(b);
3778 a10_blocks.push_back(b);
3780 a11_blocks.push_back(b);
3787 auto element_of = [&]() {
3788 const int elem = a00_blocks.front()->getElem();
3791 auto &p = storage.patterns[storage.elems[elem].pattern];
3792 if (
static_cast<int>(a00_blocks.size()) != p.nbListed)
3794 for (
auto b : a00_blocks)
3795 if (b->getElem() != elem)
3804 bool all_consistent = storage.nested;
3805 for (
size_t p = 0; all_consistent && p != fe_order.size();) {
3809 for (
auto blocks : {&a01_blocks, &a10_blocks, &a11_blocks})
3810 for (
auto b : *blocks)
3811 if (b->getElem() >= 0)
3812 all_consistent =
false;
3813 if (!a00_blocks.empty() && element_of() < 0)
3814 all_consistent =
false;
3817 enum Mode { SCRATCH, DATA_FACTORS, PRECONDITIONER_FACTORS } mode = SCRATCH;
3819 if (!all_consistent)
3821 "Schur complement with preconditioner blocks requires eliminated "
3822 "fields equal to A00 of nested matrix");
3824 mode = PRECONDITIONER_FACTORS;
3825 }
else if (storage.nested && !storage.hasPreconditioner) {
3826 if (all_consistent) {
3828 mode = DATA_FACTORS;
3829 }
else if (storage.isFactorised()) {
3831 "A00 is factorised in place, eliminated fields have to be equal "
3832 "to A00 of nested matrix");
3836 for (
size_t p = 0; p != fe_order.size();) {
3838 const auto fe_uid = classify_fe(p);
3840 for (
auto b : a11_blocks)
3841 CHKERR set_values_block(b);
3843 if (a00_blocks.empty())
3848 for (
size_t i = 0;
i != a00_blocks.size(); ++
i) {
3849 const auto r_uid = a00_blocks[
i]->getRowUId();
3850 if (
i && a00_blocks[
i - 1]->getRowUId() == r_uid)
3852 auto range = storage.rowRange(r_uid);
3853 for (
auto it = range.first;
it != range.second; ++
it) {
3854 if (
it->getFEUId() != fe_uid && !is_a00(
it->getColUId()))
3855 a01_blocks.push_back(&*
it);
3859 for (
auto b : a00_blocks)
3860 col_uids.push_back(b->getColUId());
3861 std::sort(col_uids.begin(), col_uids.end());
3862 col_uids.erase(std::unique(col_uids.begin(), col_uids.end()),
3864 for (
auto &c_uid : col_uids) {
3865 auto range = storage.colRange(c_uid);
3866 for (
auto it = range.first;
it != range.second; ++
it) {
3868 if (b.getFEUId() != fe_uid && !is_a00(b.getRowUId()))
3869 a10_blocks.push_back(&b);
3873 const int a11_size =
3874 set_local_indices(a11_indexing, a10_blocks, a01_blocks);
3880 auto gather_a01t = [&](
int a00_size) {
3881 a01t_mat.assign(
static_cast<size_t>(a11_size) * a00_size, 0.);
3882 for (
auto b : a01_blocks) {
3883 const auto &ri = a00_indexing.at(b->getRowUId());
3884 const auto &ci = a11_indexing.at(b->getColUId());
3885 const double *ptr = storage.blockPtr(*b);
3886 const int ld = b->getLd();
3887 for (
int i = 0;
i != b->getNbRows(); ++
i)
3888 for (
int j = 0;
j != b->getNbCols(); ++
j)
3889 a01t_mat[
static_cast<size_t>(ci.index +
j) * a00_size + ri.index +
3890 i] = ptr[
static_cast<size_t>(
i) * ld +
j];
3895 if (mode != SCRATCH) {
3896 const int elem = element_of();
3899 "Inconsistent A00 element");
3900 auto &e = storage.elems[elem];
3904 auto &pat = storage.patterns[e.pattern];
3906 a00_indexing.clear();
3907 for (
int r = e.entBegin; r != e.entEnd; ++r) {
3908 auto &ent = storage.elemEntities[r];
3909 a00_indexing.emplace(ent.uid,
3910 LocIdx{ent.offset, ent.nb, ent.globParent});
3913 gather_a01t(a00_size);
3914 auto piv = storage.pivots.data() + e.pivShift;
3917 storage.elemDense[elem].data(), a00_size, piv,
3918 a01t_mat.data(), a00_size);
3921 "error lapack dgetrs info = %d",
static_cast<int>(info));
3924 nz.assign(pat.nbNodes, 0);
3925 for (
auto b : a01_blocks)
3926 for (
int r = 0; r != pat.nbNodes; ++r)
3927 if (storage.elemEntities[e.entBegin + r].uid == b->getRowUId())
3929 auto &buf = mode == DATA_FACTORS ? storage.elemData[elem]
3930 : storage.elemPrec[elem];
3932 a11_size,
false, &nz);
3935 a00_size = set_local_indices(a00_indexing, a00_blocks, a00_blocks);
3936 const int elem = a00_blocks.front()->getElem();
3937 if (elem >= 0 && !storage.elems[elem].local)
3939 a00_mat.assign(
static_cast<size_t>(a00_size) * a00_size, 0.);
3940 for (
auto b : a00_blocks) {
3941 const auto &ri = a00_indexing.at(b->getRowUId());
3942 const auto &ci = a00_indexing.at(b->getColUId());
3943 copy_block(a00_mat.data(), a00_size, ri.index, ci.index,
3944 storage.blockPtr(*b), b->getLd(), b->getNbRows(),
3948 if (elem >= 0 && !storage.elems[elem].owned &&
3951 ipiv.resize(a00_size);
3952 auto info =
lapack_dgetrf(a00_size, a00_size, a00_mat.data(), a00_size,
3956 "error lapack dgetrf info = %d",
static_cast<int>(info));
3957 gather_a01t(a00_size);
3958 info =
lapack_dgetrs(
'T', a00_size, a11_size, a00_mat.data(), a00_size,
3959 ipiv.data(), a01t_mat.data(), a00_size);
3962 "error lapack dgetrs info = %d",
static_cast<int>(info));
3965 a10_mat.assign(
static_cast<size_t>(a11_size) * a00_size, 0.);
3966 for (
auto b : a10_blocks) {
3967 const auto &ri = a11_indexing.at(b->getRowUId());
3968 const auto &ci = a00_indexing.at(b->getColUId());
3969 copy_block(a10_mat.data(), a00_size, ri.index, ci.index,
3970 storage.blockPtr(*b), b->getLd(), b->getNbRows(),
3975 s_mat.resize(
static_cast<size_t>(a11_size) * a11_size);
3976 cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans, a11_size, a11_size,
3977 a00_size, -1., a10_mat.data(), a00_size, a01t_mat.data(),
3978 a00_size, 0., s_mat.data(), a11_size);
3980 glob_idx.resize(a11_size);
3981 for (
auto &pi : a11_indexing) {
3982 auto &[idx,
size,
glob] = pi.second;
3983 std::iota(glob_idx.begin() + idx, glob_idx.begin() + idx +
size,
glob);
3985 CHKERR AOApplicationToPetsc(ao, a11_size, glob_idx.data());
3987 s_mat.data(), ADD_VALUES);
3990 PetscLogEventEnd(SchurEvents::MOFEM_EVENT_AssembleSchurMat, 0, 0, 0, 0);
3997 CHKERR MatShellGetContext(
B, (
void **)&ctx);
3998 ctx->
storage->ensureAllocated();
3999 return boost::shared_ptr<std::vector<double>>(ctx->
storage,
4003boost::shared_ptr<std::vector<double>>
4006 return boost::make_shared<std::vector<double>>();
4012 InsertMode iora,
bool is_preconditioner) {
4023 PetscLogEventBegin(SchurEvents::MOFEM_EVENT_BlockStructureSetValues, 0, 0, 0,
4036 auto &storage = *ctx->
storage;
4037 CHKERR storage.modified();
4038 storage.ensureAllocated();
4040 auto get_row_data = [&]() -> std::pair<bool, VectorInt> {
4042 if (
auto stored_data_ptr =
4044 MOFEM_LOG(
"SELF", Sev::warning) <<
"Can lead to unhandled behaviour";
4045 return std::make_pair(
true, stored_data_ptr->entityIndices);
4048 return std::make_pair(
false, row_data.
getIndices());
4051 auto row_indices = get_row_data();
4052 const auto &row_ind = row_indices.second;
4055 std::vector<int> ent_row_indices;
4056 std::vector<int> ent_col_indices;
4058 auto get_ent_indices = [](
auto &cache,
auto &ind) {
4060 ind.reserve(std::distance(cache->loHi[0], cache->loHi[1]));
4061 for (
auto e = cache->loHi[0]; e != cache->loHi[1]; ++e) {
4062 auto glob = (*e)->getPetscGlobalDofIdx();
4064 ind.push_back(
glob);
4069 auto r_cache = rent->entityCacheRowDofs.lock();
4072 get_ent_indices(r_cache, ent_row_indices);
4073 if (ent_row_indices.empty())
4075 const auto &row_uid = rent->getLocalUniqueId();
4078 auto c_cache = cent->entityCacheColDofs.lock();
4081 get_ent_indices(c_cache, ent_col_indices);
4082 if (ent_col_indices.empty())
4084 const auto &col_uid = cent->getLocalUniqueId();
4086 auto idx = storage.find(row_uid, col_uid);
4090 <<
"missing block: row " << row_data.
getFieldDofs()[0]->getName()
4093 "Block not allocated");
4095 if (is_preconditioner && idx->getElem() == -1)
4097 "Preconditioner blocks are allocated only for A00 element "
4100 const int nb_rows = idx->getNbRows();
4101 const int nb_cols = idx->getNbCols();
4102 const int ld = idx->getLd();
4103 double *s_mat = storage.blockPtr(*idx, is_preconditioner);
4105 if (mat.size1() == ent_row_indices.size() &&
4106 mat.size2() == ent_col_indices.size()) {
4108 const double *
m = mat.data().data();
4109 if (ld == nb_cols) {
4110 if (iora == ADD_VALUES)
4111 cblas_daxpy(nb_rows * nb_cols, 1.0,
m, 1, s_mat, 1);
4113 cblas_dcopy(nb_rows * nb_cols,
m, 1, s_mat, 1);
4115 for (
int i = 0;
i != nb_rows; ++
i) {
4116 if (iora == ADD_VALUES)
4117 cblas_daxpy(nb_cols, 1.0,
m +
static_cast<size_t>(
i) * nb_cols, 1,
4118 s_mat +
static_cast<size_t>(
i) * ld, 1);
4120 cblas_dcopy(nb_cols,
m +
static_cast<size_t>(
i) * nb_cols, 1,
4121 s_mat +
static_cast<size_t>(
i) * ld, 1);
4127 auto ri = row_ind.begin();
4128 auto rie = row_ind.end();
4131 for (
auto re : ent_row_indices) {
4132 ri = std::find(ri, rie, re);
4135 auto ci = col_ind.begin();
4136 auto cie = col_ind.end();
4139 for (
auto ce : ent_col_indices) {
4140 ci = std::find(ci, cie, ce);
4142 auto &
m = s_mat[
static_cast<size_t>(
row) * ld +
col];
4143 if (iora == ADD_VALUES) {
4144 m += mat(std::distance(row_ind.begin(), ri),
4145 std::distance(col_ind.begin(), ci));
4147 m = mat(std::distance(row_ind.begin(), ri),
4148 std::distance(col_ind.begin(), ci));
4162 PetscLogEventEnd(SchurEvents::MOFEM_EVENT_BlockStructureSetValues, 0, 0, 0,
4174 PetscBool is_mat_shell = PETSC_FALSE;
4175 PetscObjectTypeCompare((PetscObject)
M, MATSHELL, &is_mat_shell);
4178 CHKERR MatShellGetContext(
M, (
void **)&ctx);
4182 CHKERR MatSetValues<AssemblyTypeSelector<PETSC>>(
M, row_data, col_data, mat,
4193 PetscBool is_mat_shell = PETSC_FALSE;
4194 PetscObjectTypeCompare((PetscObject)
M, MATSHELL, &is_mat_shell);
4197 CHKERR MatShellGetContext(
M, (
void **)&ctx);
4198 if (!ctx->
storage->hasPreconditioner)
4200 "No preconditioner blocks");
4204 CHKERR MatSetValues<AssemblyTypeSelector<PETSC>>(
M, row_data, col_data, mat,
4221 boost::shared_ptr<BlockStructure> block_mat_data_ptr,
4222 bool add_preconditioner_block,
4223 std::array<boost::shared_ptr<BlockStructure>, 4> data_ptrs) {
4225 auto &storage = *block_mat_data_ptr->storage;
4226 auto &
index = storage.blockIndex;
4227 const int nb_blocks =
index.size();
4229 if (storage.isFactorised())
4231 "Block matrix is factorised in place");
4236 "Nested Schur structure already created for this block "
4237 "matrix, create new one with createBlockMatStructure");
4239 int nb_local_parent;
4240 CHKERR VecGetLocalSize(block_mat_data_ptr->ghostX, &nb_local_parent);
4242 auto [schur_dm, block_dm] = dms;
4251 CHKERR VecSetDM(schur_vec_x, PETSC_NULLPTR);
4252 CHKERR VecSetDM(block_vec_x, PETSC_NULLPTR);
4253 CHKERR VecSetDM(schur_vec_y, PETSC_NULLPTR);
4254 CHKERR VecSetDM(block_vec_y, PETSC_NULLPTR);
4256 auto find_field_ent = [&](
auto uid,
auto prb,
auto rc) {
4257 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
4261 dofs = prb->getNumeredRowDofsPtr();
4264 dofs = prb->getNumeredColDofsPtr();
4273 return boost::shared_ptr<NumeredDofEntity>();
4279 return boost::shared_ptr<NumeredDofEntity>();
4289 SubIdx schurRow, schurCol, blockRow, blockCol;
4291 std::vector<SubIdxs> sub(nb_blocks);
4292 auto get_sub = [&](
auto uid,
auto prb,
auto rc) {
4294 if (
auto dof = find_field_ent(uid, prb, rc)) {
4295 s.glob = dof->getPetscGlobalDofIdx();
4296 s.loc = dof->getPetscLocalDofIdx();
4303 auto walk_sub = [](DofRangeWalk &walk,
const UId &uid) {
4305 const auto range = walk(uid);
4306 if (range.first != range.second) {
4307 s.glob = (*range.first)->getPetscGlobalDofIdx();
4308 s.loc = (*range.first)->getPetscLocalDofIdx();
4313 DofRangeWalk schur_row_walk(*schur_prb->getNumeredRowDofsPtr());
4314 DofRangeWalk block_row_walk(*block_prb->getNumeredRowDofsPtr());
4315 DofRangeWalk schur_col_walk(*schur_prb->getNumeredColDofsPtr());
4316 DofRangeWalk block_col_walk(*block_prb->getNumeredColDofsPtr());
4317 for (
int i = 0;
i != nb_blocks;) {
4318 const auto uid =
index[
i].getRowUId();
4319 const auto schur_row = walk_sub(schur_row_walk, uid);
4320 const auto block_row = walk_sub(block_row_walk, uid);
4321 for (;
i != nb_blocks &&
index[
i].getRowUId() == uid; ++
i) {
4322 sub[
i].schurRow = schur_row;
4323 sub[
i].blockRow = block_row;
4327 auto &col_order = storage.colOrder;
4328 for (
size_t p = 0; p != col_order.size();) {
4329 const auto uid =
index[col_order[p]].getColUId();
4330 const auto schur_col = walk_sub(schur_col_walk, uid);
4331 const auto block_col = walk_sub(block_col_walk, uid);
4332 for (; p != col_order.size() &&
index[col_order[p]].getColUId() == uid;
4334 sub[col_order[p]].schurCol = schur_col;
4335 sub[col_order[p]].blockCol = block_col;
4342 std::vector<std::pair<size_t, int>> old_layout(nb_blocks);
4343 for (
int i = 0;
i != nb_blocks; ++
i) {
4344 old_layout[
i] = std::make_pair(
index[
i].getMatShift(),
index[
i].getLd());
4348 std::vector<int> a00;
4349 for (
int i = 0;
i != nb_blocks; ++
i) {
4350 if (sub[
i].blockRow.glob != -1 && sub[
i].blockCol.glob != -1)
4353 std::sort(a00.begin(), a00.end(), [&
index](
int a,
int b) {
4354 if (index[a].getFEUId() != index[b].getFEUId())
4355 return index[a].getFEUId() < index[b].getFEUId();
4359 storage.patterns.clear();
4360 storage.elems.clear();
4361 storage.elemEntities.clear();
4362 storage.maxElemSize = 0;
4364 std::map<std::vector<long>,
int> pattern_map;
4365 std::map<std::vector<long>,
int> cache_map;
4366 for (
int ci = 0; ci !=
static_cast<int>(storage.patternCache.size()); ++ci)
4367 cache_map.emplace(storage.patternCache[ci].key, ci);
4368 std::vector<BlockStorage::ElemEntity> ents;
4369 std::vector<long>
key;
4371 for (
size_t p = 0; p != a00.size();) {
4372 const auto fe_uid =
index[a00[p]].getFEUId();
4373 const size_t p_begin = p;
4375 for (; p != a00.size() &&
index[a00[p]].getFEUId() == fe_uid; ++p) {
4376 const auto i = a00[p];
4378 ents.push_back({
d.getRowUId(),
d.getNbRows(), 0,
d.getLocRow(),
4379 d.getRow(), sub[
i].blockRow.loc, sub[
i].blockRow.glob});
4380 ents.push_back({
d.getColUId(),
d.getNbCols(), 0,
d.getLocCol(),
4381 d.getCol(), sub[
i].blockCol.loc, sub[
i].blockCol.glob});
4383 std::sort(ents.begin(), ents.end(),
4384 [](
auto &
a,
auto &b) { return a.uid < b.uid; });
4385 ents.erase(std::unique(ents.begin(), ents.end(),
4386 [](
auto &
a,
auto &b) { return a.uid == b.uid; }),
4388 const int k = ents.size();
4389 auto node_of = [&](
const UId &uid) {
4390 return static_cast<int>(
4391 std::lower_bound(ents.begin(), ents.end(), uid,
4392 [](
auto &e,
auto &u) { return e.uid < u; }) -
4397 std::vector<char> listed(
k *
k, 0);
4398 for (
size_t q = p_begin;
q != p; ++
q) {
4400 listed[node_of(
d.getRowUId()) *
k + node_of(
d.getColUId())] = 1;
4405 for (
auto &e : ents) {
4406 key.push_back(FieldEntity::getFieldBitNumberFromUniqueId(e.uid));
4409 key.push_back(e.nb);
4412 key.insert(
key.end(), listed.begin(), listed.end());
4413 auto pit = pattern_map.find(
key);
4414 if (pit == pattern_map.end()) {
4416 auto cit = cache_map.find(
key);
4417 if (cit != cache_map.end()) {
4420 pat = storage.patternCache[cit->second];
4430 pat.
nbListed = std::count(listed.begin(), listed.end(), 1);
4431 for (
auto &e : ents) {
4435 FieldEntity::getFieldBitNumberFromUniqueId(e.uid))));
4437 if (storage.optDense)
4442 pit = pattern_map.emplace(
key, storage.patterns.size()).first;
4443 storage.patterns.push_back(pat);
4445 const int pi = pit->second;
4446 auto &pat = storage.patterns[pi];
4449 const int elem_idx = storage.elems.size();
4450 const int ent_begin = storage.elemEntities.size();
4451 for (
int r = 0; r !=
k; ++r)
4452 ents[r].offset = pat.nodeOffset[r];
4453 storage.elems.push_back({pi,
n, ent_begin, ent_begin +
k, nb_pivots});
4454 storage.elems.back().feUId = fe_uid;
4455 storage.elemEntities.insert(storage.elemEntities.end(), ents.begin(),
4457 for (
size_t q = p_begin;
q != p; ++
q) {
4459 const int r = node_of(
d.getRowUId()),
c = node_of(
d.getColUId());
4460 d.setStorage(pat.sShift(r,
c), pat.sLd(r,
c), elem_idx);
4464 storage.maxElemSize = std::max(storage.maxElemSize,
n);
4466 auto &elem = storage.elems.back();
4469 for (
auto &e : ents) {
4472 if (e.locParent < 0)
4474 if (e.locParent < 0 || e.locParent >= nb_local_parent)
4482 std::vector<UId> uids;
4483 uids.reserve(storage.elemEntities.size());
4484 for (
auto &e : storage.elemEntities)
4485 uids.push_back(e.uid);
4486 std::sort(uids.begin(), uids.end());
4487 if (std::adjacent_find(uids.begin(), uids.end()) != uids.end())
4489 "Entity of A00 field is shared by more than one "
4490 "element, eliminated fields have to be element local "
4491 "(L2, broken spaces, or interior DOFs)");
4495 size_t mem_size = 0;
4497 if (
d.getElem() == -1) {
4498 d.setStorage(mem_size,
d.getNbCols(), -1);
4499 mem_size +=
static_cast<size_t>(
d.getNbRows()) *
d.getNbCols();
4503 const int nb_elems = storage.elems.size();
4504 storage.hasPreconditioner = add_preconditioner_block;
4505 storage.elemData.assign(nb_elems, std::vector<double>());
4506 storage.elemPrec.assign(add_preconditioner_block ? nb_elems : 0,
4507 std::vector<double>());
4508 storage.elemDense.assign(nb_elems, std::vector<double>());
4509 storage.maxElemBuffer = 0;
4512 auto take_cached = [](
auto &cache,
size_t &pos,
const UId &uid,
4513 std::vector<double> &buf) {
4514 while (pos != cache.size() && cache[pos].first < uid)
4516 if (pos != cache.size() && cache[pos].first == uid)
4517 buf.swap(cache[pos].second);
4519 size_t data_pos = 0, prec_pos = 0;
4520 for (
int ei = 0; ei != nb_elems; ++ei) {
4521 const auto sz = storage.patterns[storage.elems[ei].pattern].elemSize;
4524 const auto n = storage.elems[ei].size;
4525 const auto uid = storage.elems[ei].feUId;
4526 take_cached(storage.elemDataCache, data_pos, uid, storage.elemData[ei]);
4527 storage.elemData[ei].reserve(
static_cast<size_t>(
n) *
n);
4528 storage.elemData[ei].assign(sz, 0.);
4529 if (add_preconditioner_block) {
4530 take_cached(storage.elemPrecCache, prec_pos, uid, storage.elemPrec[ei]);
4531 storage.elemPrec[ei].reserve(
static_cast<size_t>(
n) *
n);
4532 storage.elemPrec[ei].assign(sz, 0.);
4534 storage.maxElemBuffer = std::max(storage.maxElemBuffer, sz);
4536 decltype(storage.elemDataCache)().swap(storage.elemDataCache);
4537 decltype(storage.elemPrecCache)().swap(storage.elemPrecCache);
4541 auto &data = storage.data;
4542 const bool has_values =
4543 std::any_of(data.begin(), data.end(), [](
double v) { return v != 0.; });
4545 std::vector<double> new_data(mem_size, 0.);
4546 for (
int i = 0;
i != nb_blocks; ++
i) {
4548 auto [old_shift, old_ld] = old_layout[
i];
4549 double *dst =
d.getElem() >= 0
4550 ? storage.elemData[
d.getElem()].data() +
d.getMatShift()
4551 : new_data.data() +
d.getMatShift();
4552 copy_block(dst,
d.getLd(), 0, 0, data.data() + old_shift, old_ld,
4553 d.getNbRows(),
d.getNbCols());
4555 data.swap(new_data);
4557 std::vector<double>().swap(data);
4559 storage.dataSize = mem_size;
4560 storage.ensureAllocated();
4561 storage.pivots.assign(nb_pivots, 0);
4562 storage.factorStorage = BlockStorage::FACTOR_NONE;
4568 for (
auto r = 0; r != 4; ++r) {
4570 data_ptrs[r] = boost::make_shared<BlockStructure>();
4571 auto &
d = *data_ptrs[r];
4572 d.storage = block_mat_data_ptr->storage;
4575 d.numbering = BlockStructure::PARENT;
4576 d.multiplyByPreconditioner =
false;
4580 data_ptrs[3]->hasElems = !storage.elems.empty();
4581 data_ptrs[3]->numbering = BlockStructure::BLOCK;
4583 for (
int i = 0;
i != nb_blocks; ++
i) {
4586 auto add = [&](
auto &
m,
const SubIdx &r,
const SubIdx &
c) {
4587 m->blocks.push_back({
d.getMatShift(),
d.getLd(), r.glob,
c.glob,
4588 d.getNbRows(),
d.getNbCols(), r.loc,
c.loc});
4590 if (
s.schurRow.glob != -1 &&
s.schurCol.glob != -1)
4591 add(data_ptrs[0],
s.schurRow,
s.schurCol);
4592 if (
s.schurRow.glob != -1 &&
s.blockCol.glob != -1)
4593 add(data_ptrs[1],
s.schurRow,
s.blockCol);
4594 if (
s.blockRow.glob != -1 &&
s.schurCol.glob != -1)
4595 add(data_ptrs[2],
s.blockRow,
s.schurCol);
4597 if (
s.blockRow.glob != -1 &&
s.blockCol.glob != -1 &&
d.getElem() == -1)
4600 for (
auto r = 0; r != 3; ++r)
4601 data_ptrs[r]->blocks.shrink_to_fit();
4603 data_ptrs[0]->ghostX = schur_vec_x;
4604 data_ptrs[0]->ghostY = schur_vec_y;
4605 data_ptrs[1]->ghostX = block_vec_x;
4606 data_ptrs[1]->ghostY = schur_vec_y;
4607 data_ptrs[2]->ghostX = schur_vec_x;
4608 data_ptrs[2]->ghostY = block_vec_y;
4609 data_ptrs[3]->ghostX = block_vec_x;
4610 data_ptrs[3]->ghostY = block_vec_y;
4612 if (add_preconditioner_block) {
4613 data_ptrs[3]->multiplyByPreconditioner =
true;
4614 block_mat_data_ptr->multiplyByPreconditioner =
false;
4618 CHKERR PetscObjectGetComm((PetscObject)schur_dm, &
comm);
4620 auto create_shell_mat = [&](
auto nb_r_loc,
auto nb_c_loc,
auto nb_r_glob,
4621 auto nb_c_glob,
auto data_ptr) {
4623 CHKERR MatCreateShell(
comm, nb_r_loc, nb_c_loc, nb_r_glob, nb_c_glob,
4624 (
void *)data_ptr.get(), &mat_raw);
4629 auto schur_nb_global = schur_prb->getNbDofsRow();
4630 auto block_nb_global = block_prb->getNbDofsRow();
4631 auto schur_nb_local = schur_prb->getNbLocalDofsRow();
4632 auto block_nb_local = block_prb->getNbLocalDofsRow();
4634 std::array<SmartPetscObj<Mat>, 4> mats_array;
4636 create_shell_mat(schur_nb_local, schur_nb_local, schur_nb_global,
4637 schur_nb_global, data_ptrs[0]);
4639 create_shell_mat(schur_nb_local, block_nb_local, schur_nb_global,
4640 block_nb_global, data_ptrs[1]);
4642 create_shell_mat(block_nb_local, schur_nb_local, block_nb_global,
4643 schur_nb_global, data_ptrs[2]);
4645 create_shell_mat(block_nb_local, block_nb_local, block_nb_global,
4646 block_nb_global, data_ptrs[3]);
4649 <<
"(0, 0) " << schur_nb_local <<
" " << schur_nb_global <<
" "
4650 << data_ptrs[0]->blocks.size();
4652 <<
"(0, 1) " << schur_nb_local <<
" " << block_nb_local <<
" "
4653 << schur_nb_global <<
" " << block_nb_global <<
" "
4654 << data_ptrs[1]->blocks.size();
4656 <<
"(1, 0) " << block_nb_local <<
" " << schur_nb_local <<
" "
4657 << block_nb_global <<
" " << schur_nb_global <<
" "
4658 << data_ptrs[2]->blocks.size();
4660 <<
"(1, 1) " << block_nb_local <<
" " << block_nb_global <<
" "
4661 << storage.elems.size() <<
" elements (" << a00.size() <<
" blocks, "
4662 << storage.patterns.size() <<
" patterns) max size "
4663 << storage.maxElemSize;
4670 size_t listed_d = 0, dense_d = 0, struct_d = 0, buffers_d = 0;
4671 for (
auto &pat : storage.patterns) {
4675 dense_d += pat.nbElems *
static_cast<size_t>(pat.size) * pat.size;
4676 struct_d += pat.nbElems * est.elemSize;
4677 buffers_d += pat.nbElems * pat.elemSize;
4679 <<
"A00 pattern (" << pat.nbElems <<
" elements): "
4682 std::vector<int> all(pat.nbNodes);
4683 std::iota(all.begin(), all.end(), 0);
4686 <<
"; listed pairs " << pat.nbListed <<
" of "
4687 << pat.nbNodes * pat.nbNodes <<
"; doubles per element: listed "
4689 <<
static_cast<size_t>(pat.size) * pat.size
4690 <<
", structural estimate " << est.elemSize <<
" (eliminated "
4695 size_t ghost_elems = 0, ghost_elems_data = 0, ghost_blocks_data = 0;
4696 for (
int ei = 0; ei != nb_elems; ++ei) {
4697 auto &e = storage.elems[ei];
4698 bool all_ghost =
true;
4699 for (
int k = e.entBegin;
k != e.entEnd; ++
k)
4700 if (storage.elemEntities[
k].locParent < nb_local_parent)
4704 ghost_elems_data += storage.elemData[ei].size();
4708 if (
d.getElem() == -1 &&
d.getLocRow() >= nb_local_parent &&
4709 d.getLocCol() >= nb_local_parent)
4710 ghost_blocks_data +=
static_cast<size_t>(
d.getNbRows()) *
d.getNbCols();
4712 constexpr size_t dsz =
sizeof(
double);
4713 std::array<size_t, 10> loc_stats = {
4714 storage.elems.size(),
4720 (add_preconditioner_block ? buffers_d : 0) * dsz,
4722 ghost_elems_data * dsz,
4723 ghost_blocks_data * dsz};
4724 std::array<size_t, 10> sum_stats, max_stats;
4725 MPI_Allreduce(loc_stats.data(), sum_stats.data(), 10, MPIU_SIZE_T, MPI_SUM,
4727 MPI_Allreduce(loc_stats.data(), max_stats.data(), 10, MPIU_SIZE_T, MPI_MAX,
4729 constexpr double mb = 1024. * 1024.;
4731 <<
"A00 elements " << sum_stats[0] <<
" (max per process "
4732 << max_stats[0] <<
"), element buffers " << sum_stats[1] /
mb
4733 <<
" MB (max per process " << max_stats[1] /
mb
4734 <<
" MB); listed blocks " << sum_stats[2] /
mb
4735 <<
" MB, dense element matrices would be " << sum_stats[3] /
mb
4736 <<
" MB, structural estimate of block elimination " << sum_stats[4] /
mb
4737 <<
" MB; other blocks data " << sum_stats[5] /
mb
4738 <<
" MB (max per process " << max_stats[5] /
mb
4739 <<
" MB); preconditioner blocks " << sum_stats[6] /
mb <<
" MB";
4741 <<
"Not owned (ghost) elements " << sum_stats[7] <<
" data "
4742 << sum_stats[8] /
mb <<
" MB, not owned other blocks data "
4743 << sum_stats[9] /
mb <<
" MB";
4746 auto schur_is = schur_prb->getSubData()->getSmartRowIs();
4747 auto block_is = block_prb->getSubData()->getSmartRowIs();
4749 storage.nested =
true;
4750 std::vector<BlockStorage::Pattern>().swap(storage.patternCache);
4752 return boost::make_shared<NestSchurData>(
4754 mats_array, data_ptrs, block_mat_data_ptr,
4755 std::make_pair(schur_is, block_is)
4763 boost::shared_ptr<BlockStructure> block_mat_data_ptr,
4765 std::vector<std::string> fields_names,
4766 std::vector<boost::shared_ptr<Range>>
4768 bool add_preconditioner_block) {
4770 if (!block_mat_data_ptr) {
4774 if (fields_names.size() != field_ents.size())
4776 "fields_names.size() != field_ents.size()");
4778 auto &storage = *block_mat_data_ptr->storage;
4780 PetscBool dense = PETSC_FALSE;
4783 storage.optDense = dense == PETSC_TRUE;
4784 CHKERR ::PetscOptionsGetReal(PETSC_NULLPTR,
"",
4785 "-schur_a00_pivot_threshold",
4786 &storage.optPivotThreshold, PETSC_NULLPTR);
4787 CHKERR ::PetscOptionsGetReal(PETSC_NULLPTR,
"",
"-schur_a00_rcond_min",
4788 &storage.optRcondMin, PETSC_NULLPTR);
4789 CHKERR ::PetscOptionsGetReal(PETSC_NULLPTR,
"",
"-schur_a00_backward_error",
4790 &storage.optBackwardError, PETSC_NULLPTR);
4792 if (!storage.nested)
4793 std::vector<BlockStorage::Pattern>().swap(storage.patternCache);
4796 add_preconditioner_block, {});
4801 boost::shared_ptr<NestSchurData> nest_data_ptr) {
4805 auto block_mat_data_ptr = std::get<2>(*nest_data_ptr);
4806 if (!block_mat_data_ptr || !block_mat_data_ptr->storage)
4808 auto &storage = *block_mat_data_ptr->storage;
4811 "Block structure has not been rebuilt: call "
4812 "rebuildBlockMatStructure before rebuildSchurNestedMatrixStruture");
4815 std::get<1>(*nest_data_ptr));
4816 *nest_data_ptr = *rebuilt;
4820SchurBlockStructureDigest
4823 if (!data_ptr || !data_ptr->storage)
4825 auto &
s = *data_ptr->storage;
4826 auto add_uid = [](std::size_t &
h,
const UId &u) {
4827 boost::hash_combine(
h,
static_cast<unsigned long long>(u));
4828 boost::hash_combine(
h,
static_cast<unsigned long long>(u >> 64));
4830 d.nbBlocks =
s.blockIndex.size();
4831 d.nbElems =
s.elems.size();
4832 d.nbPatterns =
s.patterns.size();
4833 for (
auto &b :
s.blockIndex) {
4834 add_uid(
d.indexHash, b.getRowUId());
4835 add_uid(
d.indexHash, b.getColUId());
4836 add_uid(
d.indexHash, b.getFEUId());
4837 for (
int v : {b.getRow(), b.getCol(), b.getNbRows(), b.getNbCols(),
4838 b.getLocRow(), b.getLocCol(), b.getElem() >= 0 ? 1 : 0})
4839 boost::hash_combine(
d.indexHash,
v);
4841 for (
auto &b : data_ptr->blocks)
4842 for (
int v : {b.row, b.col, b.nbRows, b.nbCols, b.locRow, b.locCol})
4843 boost::hash_combine(
d.blocksHash,
v);
4844 for (
auto &e :
s.elems) {
4845 for (
auto v :
s.patterns[e.pattern].key)
4846 boost::hash_combine(
d.elemsHash,
v);
4847 for (
int k = e.entBegin;
k != e.entEnd; ++
k) {
4848 auto &ent =
s.elemEntities[
k];
4849 add_uid(
d.elemsHash, ent.uid);
4850 for (
int v : {ent.nb, ent.locParent, ent.globParent, ent.locBlock,
4852 boost::hash_combine(
d.elemsHash,
v);
4858std::pair<SmartPetscObj<Mat>, boost::shared_ptr<NestSchurData>>
4861 if (!schur_net_data_ptr)
4864 auto [mat_arrays, data_ptrs, block_mat_data_ptr, iss] = *schur_net_data_ptr;
4865 auto [schur_is, block_is] = iss;
4867 std::array<IS, 2> is_a = {schur_is, block_is};
4868 std::array<Mat, 4> mats_a = {
4870 mat_arrays[0], mat_arrays[1], mat_arrays[2], mat_arrays[3]
4875 CHKERR PetscObjectGetComm((PetscObject)mat_arrays[0], &
comm);
4880 comm, 2, is_a.data(), 2, is_a.data(), mats_a.data(), &mat_raw
4891OpSchurAssembleBase *
4893 std::vector<boost::shared_ptr<Range>> field_ents,
4895 bool sym_schur,
bool symm_op) {
4898 schur, sym_schur, symm_op);
4901 schur, sym_schur, symm_op);
4905 boost::shared_ptr<std::vector<unsigned char>> marker_ptr,
double diag_val) {
4909OpSchurAssembleBase *
4911 std::vector<boost::shared_ptr<Range>> field_ents,
4914 std::vector<bool> sym_schur,
bool symm_op,
4915 boost::shared_ptr<BlockStructure> diag_blocks) {
4917 fields_name, field_ents, sequence_of_aos.back(), sequence_of_mats.back(),
4918 sym_schur.back(), symm_op);
4921OpSchurAssembleBase *
4923 std::vector<boost::shared_ptr<Range>> field_ents,
4926 std::vector<bool> sym_schur,
4927 std::vector<double> diag_eps,
bool symm_op,
4928 boost::shared_ptr<BlockStructure> diag_blocks) {
4930 fields_name, field_ents, sequence_of_aos.back(), sequence_of_mats.back(),
4931 sym_schur.back(), symm_op);
4937 auto apply = [](PC pc, Vec
f, Vec x) {
4940 CHKERR PCGetOperators(pc, &
A, &P);
4945 auto apply_transpose = [](PC pc, Vec
f, Vec x) {
4948 CHKERR PCGetOperators(pc, &
A, &P);
4949 CHKERR MatSolveTranspose(P,
f, x);
4953 CHKERR PCSetType(pc, PCSHELL);
4954 CHKERR PCShellSetApply(pc, apply);
4955 CHKERR PCShellSetApplyTranspose(pc, apply_transpose);
4956 CHKERR PCShellSetName(pc,
"MoFEMSchurBlockPC");
4968 return SchurElemMats::MatSetValues(
M, row_data, col_data, mat, iora);
4975 return MatSetValues<AssemblyTypeSelector<PETSC>>(
M, row_data, col_data, mat,
4980SchurBackendMatSetValuesPtr::MatSetValuesPtr
4981 SchurBackendMatSetValuesPtr::matSetValuesPtr = schur_mat_set_values_wrap;
4990 CHKERR assembleStorage(row_data, col_data, mat, iora);
4991 CHKERR SchurBackendMatSetValuesPtr::matSetValuesPtr(
M, row_data, col_data,
5003 return MatSetValues<SchurElemMats>(
M, row_data, col_data, mat, iora);
5024 SchurBackendMatSetValuesPtr::matSetValuesBlockPtr =
5028SchurElemMatsBlock::MatSetValues(Mat
M,
5033 CHKERR assembleStorage(row_data, col_data, mat, iora);
5034 CHKERR SchurBackendMatSetValuesPtr::matSetValuesBlockPtr(
M, row_data,
5035 col_data, mat, iora);
5041MatSetValues<SchurElemMatsBlock>(Mat
M,
5045 return SchurElemMatsBlock::MatSetValues(
M, row_data, col_data, mat, iora);
5057 SchurBackendMatSetValuesPtr::matSetValuesPreconditionedBlockPtr =
5065 CHKERR assembleStorage(row_data, col_data, mat, iora);
5066 CHKERR SchurBackendMatSetValuesPtr::matSetValuesPreconditionedBlockPtr(
5067 M, row_data, col_data, mat, iora);
5076 return SchurElemMatsPreconditionedBlock::MatSetValues(
M, row_data, col_data,
5083 if (block_mat_data->multiplyByPreconditioner) {
5084 block_mat_data->multiplyByPreconditioner =
false;
5086 if (!block_mat_data->storage->hasPreconditioner) {
5088 "preconditioner blocks not set");
5090 block_mat_data->multiplyByPreconditioner =
true;
5097 std::string filename) {
5101 moab::Interface &moab = core;
5103 ReadUtilIface *iface;
5104 CHKERR moab.query_interface(iface);
5108 [&](
double *,
int,
int,
int,
int,
int,
int,
int) { ++
size; });
5110 EntityHandle starting_vertex;
5111 vector<double *> arrays_coord;
5112 CHKERR iface->get_node_coords(3, 4 *
size, 0, starting_vertex, arrays_coord);
5113 EntityHandle starting_handle;
5114 EntityHandle *array;
5115 CHKERR iface->get_element_connect(
size, 4, MBQUAD, 0, starting_handle, array);
5117 double def_val_nrm2 = 0;
5119 CHKERR moab.tag_get_handle(
"nrm2", 1, MB_TYPE_DOUBLE, th_nrm2,
5120 MB_TAG_CREAT | MB_TAG_DENSE, &def_val_nrm2);
5122 int def_val_mat_shift = 0;
5124 CHKERR moab.tag_get_handle(
"mat_shift", 1, MB_TYPE_INTEGER, th_mat_shift,
5125 MB_TAG_CREAT | MB_TAG_DENSE, &def_val_mat_shift);
5127 block_mat_data->storage->ensureAllocated();
5131 int nb_rows,
int nb_cols,
int,
int) {
5133 arrays_coord[0][4 *
i + 0] =
row;
5134 arrays_coord[1][4 *
i + 0] =
col;
5135 arrays_coord[2][4 *
i + 0] = 0;
5138 arrays_coord[0][4 *
i + 1] =
row + nb_rows;
5139 arrays_coord[1][4 *
i + 1] =
col;
5140 arrays_coord[2][4 *
i + 1] = 0;
5143 arrays_coord[0][4 *
i + 2] =
row + nb_rows;
5144 arrays_coord[1][4 *
i + 2] =
col + nb_cols;
5145 arrays_coord[2][4 *
i + 2] = 0;
5148 arrays_coord[0][4 *
i + 3] =
row;
5149 arrays_coord[1][4 *
i + 3] =
col + nb_cols;
5150 arrays_coord[2][4 *
i + 3] = 0;
5153 array[4 *
i + 0] = starting_vertex + 4 *
i + 0;
5154 array[4 *
i + 1] = starting_vertex + 4 *
i + 1;
5155 array[4 *
i + 2] = starting_vertex + 4 *
i + 2;
5156 array[4 *
i + 3] = starting_vertex + 4 *
i + 3;
5159 for (
int r = 0; r != nb_rows; ++r) {
5161 cblas_dnrm2(nb_cols, ptr +
static_cast<size_t>(r) * ld, 1);
5162 nrm2 += row_nrm2 * row_nrm2;
5164 nrm2 = std::sqrt(nrm2);
5166 EntityHandle ele = starting_handle +
i;
5167 CHKERR moab.tag_set_data(th_nrm2, &ele, 1, &nrm2);
5168 CHKERR moab.tag_set_data(th_mat_shift, &ele, 1, &mat_shift);
5173 CHKERR iface->update_adjacencies(starting_handle,
size, 4, array);
5174 CHKERR moab.write_file(filename.c_str(),
"VTK",
"");
std::map< EntityHandle, int > index
int h
Corner vertex and its two front neighbours.
std::vector< int > removed
Vec t
Removal: the ring edge.
std::map< EntityHandle, std::pair< bool, std::vector< double > > > previous
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
std::vector< FieldBitNumber > row
int glob
global index of first DOF
int loc
local index of first DOF
std::vector< FieldBitNumber > col
SmartPetscObj< Vec > work
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define BITFIELDID_SIZE
max number of fields
@ MOFEM_OPERATION_UNSUCCESSFUL
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
PetscErrorCode DMoFEMLoopFiniteElementsUpAndLowRank(DM dm, const char fe_name[], MoFEM::FEMethod *method, int low_rank, int up_rank, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, UId, &NumeredDofEntity::getLocalUniqueId > >, ordered_non_unique< tag< Part_mi_tag >, member< NumeredDofEntity, unsigned int, &NumeredDofEntity::pArt > >, ordered_non_unique< tag< PetscGlobalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscGloablDofIdx > >, ordered_non_unique< tag< PetscLocalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscLocalDofIdx > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, EntityHandle, &NumeredDofEntity::getEnt > > > > NumeredDofEntity_multiIndex
MultiIndex container keeps NumeredDofEntity.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
static __CLPK_integer lapack_dgetrf(__CLPK_integer m, __CLPK_integer n, __CLPK_doublereal *a, __CLPK_integer lda, __CLPK_integer *ipiv)
static __CLPK_integer lapack_dgetri(__CLPK_integer n, __CLPK_doublereal *a, __CLPK_integer lda, __CLPK_integer *ipiv, __CLPK_doublereal *work, __CLPK_integer lwork)
static __CLPK_integer lapack_dgetrs(char trans, __CLPK_integer n, __CLPK_integer nrhs, __CLPK_doublereal *a, __CLPK_integer lda, __CLPK_integer *ipiv, __CLPK_doublereal *b, __CLPK_integer ldb)
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
UBlasVector< int > VectorInt
implementation of Data Operators for Forces and Sources
SchurBlockStructureDigest schurBlockStructureDigest(boost::shared_ptr< BlockStructure > data_ptr)
auto type_from_handle(const EntityHandle h)
get type from entity handle
MoFEMErrorCode schur_mat_set_values_wrap(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
static void add_gemv(bool trans_a, int m, int kk, const double *a, int lda, const double *x, double *y)
y += op(A) x, op(A) is m x kk, A is column-major
MoFEMErrorCode shell_block_mat_asmb_wrap_impl(BlockStructure *ctx, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora, bool is_preconditioner)
static void elem_mult_listed(const BlockPattern &p, const double *buf, const double *x, double *y, bool trans)
y += A x (trans false) or y += A^T x (trans true) from listed blocks
static PetscErrorCode solve_add(Mat mat, Vec x, Vec y)
OpSchurAssembleBase * createOpSchurAssembleEnd(std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range > > field_ents, SmartPetscObj< AO > ao, SmartPetscObj< Mat > schur, bool sym_schur, bool symm_op)
Construct a new Op Schur Assemble End object.
static MoFEMErrorCode mult_block_structure(Mat mat, Vec x, Vec y, InsertMode iora, bool trans)
Matrix-vector product of block matrix.
static bool verify_probe(const BlockPattern &nl, const std::vector< double > &mat, double u, double rcond_min, double be_tol, double &be_block, double &be_dense)
Verify block layout on probe element.
auto isAllGather(IS is)
IS All gather.
static void apply_lu_factors(int n, const double *lu, const __CLPK_integer *ipiv, double *t, bool trans)
Apply in place LU factors of element matrix.
MoFEMErrorCode schurSwitchPreconditioner(boost::shared_ptr< BlockStructure > block_mat_data)
Switch preconditioner.
static void for_each_block(const BlockStructure &ctx, FUN &&fun)
Iterate all blocks of matrix, including listed blocks of A00 elements.
MoFEMErrorCode setSchurA00MatSolvePC(SmartPetscObj< PC > pc)
Set PC for A00 block.
constexpr bool debug_schur
static PetscErrorCode solve_transpose_add(Mat mat, Vec x, Vec y)
static int elem_factorise(const BlockPattern &p, double *buf, __CLPK_integer *piv, double u, double rcond_min, std::vector< double > &work, std::vector< __CLPK_integer > &iwork)
Factorise element buffer in place.
auto id_from_handle(const EntityHandle h)
static void elem_gather_dense(const BlockPattern &p, const double *buf, double *dense)
dense element matrix (row-major A, size x size) from listed blocks
static size_t listed_size(const BlockPattern &p)
doubles in listed blocks of one element
std::pair< SmartPetscObj< Mat >, boost::shared_ptr< BlockStructure > > SchurShellMatData
static std::vector< int > analyse_pattern(const BlockPattern &p, double *w, double u, double rcond_min)
Decide elimination order on probe element.
std::pair< SmartPetscObj< Mat >, boost::shared_ptr< NestSchurData > > createSchurNestedMatrix(boost::shared_ptr< NestSchurData > schur_net_data_ptr)
Create a Mat Diag Blocks object.
static PetscErrorCode mult_transpose_add(Mat mat, Vec x, Vec y)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
MoFEMErrorCode shell_block_mat_asmb_wrap(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
static double accepted_backward_error(double be_dense, double be_tol)
backward error accepted for block factors, given dense backward error
static void sub_gemm(bool trans_a, int m, int kk, int nrhs, const double *a, int lda, const double *b, int ldb, double *c, int ldc)
C -= op(A) B, op(A) is m x kk, A, B and C are column-major.
static MoFEMErrorCode factorise_elems(BlockStorage &storage, BlockStorage::FactorStorage where)
Factorise A00 elements in place.
static bool is_zero_matrix(const double *ptr, size_t size)
auto createISGeneral(MPI_Comm comm, PetscInt n, const PetscInt idx[], PetscCopyMode mode)
Creates a data structure for an index set containing a list of integers.
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
static std::vector< char > symbolic_elimination(const BlockPattern &p, const std::vector< int > &order)
Blocks of M = A^T present after eliminating nodes in given order.
static void copy_block(double *dst, int ld_dst, int ridx, int cidx, const double *src, int ld_src, int nb_rows, int nb_cols)
copy row-major block into row-major matrix at (ridx, cidx)
static bool factorise_pivot_block(int n, double *d, int ld, __CLPK_integer *piv, double coupling, double u, double rcond_min, std::vector< double > &work, std::vector< __CLPK_integer > &iwork, double *rcond_out=nullptr, double *anorm_out=nullptr)
Factorise diagonal block in place and test it as block pivot.
void dgecon_(char *norm, __CLPK_integer *n, __CLPK_doublereal *a, __CLPK_integer *lda, __CLPK_doublereal *anorm, __CLPK_doublereal *rcond, __CLPK_doublereal *work, __CLPK_integer *iwork, __CLPK_integer *info)
static PetscErrorCode solve(Mat mat, Vec x, Vec y)
static MoFEMErrorCode elem_solve(const BlockPattern &p, const double *buf, const __CLPK_integer *piv, double *r, int ldr, int nrhs, bool trans, const std::vector< char > *nz_in)
Solve with factorised element buffer.
boost::shared_ptr< std::vector< double > > getBlockMatPrconditionerStorageMat(Mat B)
Get preconditioner blocks storage.
static MoFEMErrorCode solve_block_structure(Mat mat, Vec f, Vec x, InsertMode iora, bool trans)
Solve with A00, i.e. x = A00^{-1} f, element by element.
static double elem_backward_error(const BlockPattern &p, const double *orig, const double *lu, const __CLPK_integer *piv, std::vector< double > &x, std::vector< double > &r, std::vector< double > &rs)
Normwise backward error of solve with factors of element.
static bool backward_error_accepted(double be, double be_dense, double be_tol)
true if backward error is finite and not larger than accepted
static std::string describe_nodes(const BlockPattern &p, const std::vector< int > &nodes)
static void make_block_layout(BlockPattern &p, const std::vector< int > &order)
Layout for block elimination of nodes in order, followed by dense core of remaining nodes.
static PetscErrorCode zero_rows_columns(Mat A, PetscInt N, const PetscInt rows[], PetscScalar diag, Vec x, Vec b)
static std::vector< int > natural_offsets(const BlockPattern &p)
offsets of nodes in element vector in order of nodes
boost::shared_ptr< BlockStructure > createBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec)
Create block matrix structure.
boost::shared_ptr< NestSchurData > createSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< BlockStructure > block_mat_data_ptr, std::vector< std::string > fields_names, std::vector< boost::shared_ptr< Range > > field_ents, bool add_preconditioner_block)
Create structure of nested matrix [A11 A10; A01 A00].
static PetscErrorCode mult_add(Mat mat, Vec x, Vec y)
MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
static void set_block_orders(BlockStorage &storage)
set orders of blocks by finite element and by column entity
static PetscErrorCode mult_transpose(Mat mat, Vec x, Vec y)
auto field_bit_from_bit_number(const int bit_number)
get field bit id from bit number
OpSchurAssembleBase * createOpSchurZeroRowsAndCols(boost::shared_ptr< std::vector< unsigned char > > marker_ptr, double diag_val)
Create a Op Schur Zero Rows And Cols object.
static PetscErrorCode mat_zero(Mat m)
MoFEMErrorCode schurSaveBlockMesh(boost::shared_ptr< BlockStructure > block_mat_data, std::string filename)
Save block matrix as a mesh.
auto getInterfacePtr(DM dm)
Get the Interface Ptr object.
MoFEMErrorCode rebuildSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< NestSchurData > nest_data_ptr)
Rebuild a nested Schur structure after rebuildBlockMatStructure.
static PetscErrorCode mult(Mat mat, Vec x, Vec y)
static PetscErrorCode solve_transpose(Mat mat, Vec x, Vec y)
static double norm1_block(int m, int n, const double *a, int ld)
1-norm of column-major m x n block, infinity if block is not finite
static double backward_error_rhs(int i)
right-hand side used to measure backward error
static void copy_listed(const BlockPattern &from, const double *src, const BlockPattern &to, double *dst)
copy listed blocks of element buffer from one layout to another
static void elem_mult_factors(const BlockPattern &p, const double *buf, const __CLPK_integer *piv, double *v, bool trans)
Product with factorised element buffer, in place.
MoFEMErrorCode rebuildBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec, boost::shared_ptr< BlockStructure > data_ptr)
Rebuild a block matrix structure after its problem changed.
static boost::shared_ptr< NestSchurData > nest_block_structure(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< BlockStructure > block_mat_data_ptr, bool add_preconditioner_block, std::array< boost::shared_ptr< BlockStructure >, 4 > data_ptrs)
Lay A00 blocks out in element buffers and make the nested matrices.
static void set_parent_blocks(BlockStructure &s)
set blocks of block matrix (parent numbering)
static void make_listed_layout(BlockPattern &p)
layout with listed blocks only
constexpr double backward_error_factor
factor of dense backward error accepted for block factors
std::vector< std::pair< std::string, std::vector< SchurFieldPair > > > SchurFEOpsFEandFields
static MoFEMErrorCode setSchurBlockMatOps(Mat mat_raw)
MoFEMErrorCode shell_block_preconditioner_mat_asmb_wrap(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
auto getProblemPtr(DM dm)
get problem pointer from DM
static void relayout_pattern(BlockStorage &s, int pi, BlockPattern nl)
Relayout element buffers of pattern pi, element by element, in place.
static std::vector< int > structural_order(const BlockPattern &p)
elimination order by structure only (minimal fill, diagonal present)
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
MoFEMErrorCode assembleBlockMatSchur(MoFEM::Interface &m_field, Mat B, Mat S, std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range > > field_ents, SmartPetscObj< AO > ao)
Assemble Schur complement S = A11 - A10 A00^{-1} A01 from block matrix.
OpSchurAssembleBase * createOpSchurAssembleBegin()
auto ent_form_type_and_id(const EntityType type, const EntityID id)
get entity handle from type and id
boost::shared_ptr< std::vector< double > > getBlockMatStorageMat(Mat B)
Get block values storage.
FTensor::Index< 'm', 3 > m
DOFs on one entity (node) of A00 element.
int globParent
global index in block matrix numbering
int offset
offset in element vector (layout of pattern)
int locParent
local index in block matrix numbering
int locBlock
local index in A00 sub-problem numbering
int globBlock
global index in A00 sub-problem numbering
bool local
all entities have local index on this process
int entBegin
first entity in elemEntities
bool owned
all entities are owned by this process
int pivShift
shift in pivots
UId feUId
uid of the finite element
int entEnd
one past last entity in elemEntities
int pattern
index of pattern
bool factorised
factors are stored for this element
bool dense
factors are in elemDense (pivot test failed)
std::vector< std::pair< UId, int > > col
std::vector< std::pair< UId, int > > row
std::pair< UId, int > key
void setRow(int glob, int nb, int loc)
row entity numbering: global and local index of first DOF, DOFs
Indexes(UId uid_row, UId uid_col, UId uid_fe, int row, int col, int nb_rows, int nb_cols, int loc_row, int loc_col)
size_t mat_shift
shift in data, or in element buffer if elem >= 0
void setStorage(size_t shift, int leading_dim, int element)
size_t getMatShift() const
int ld
leading dimension of block in storage
void setCol(int glob, int nb, int loc)
column entity numbering: global and local index of first DOF, DOFs
int elem
index of A00 element, -1 if none
Block pattern of A00 element and layout of element buffer.
long mShift(int a, int b) const
shift of block (a, b) of M = A^T, column-major
int coreOffset
offset of core DOFs in element vector
long sShift(int r, int c) const
int size
DOFs per element.
std::vector< int > nodeSize
double beRef
backward error of dense solve on probe
std::vector< std::string > nodeName
int coreSize
DOFs in dense core.
std::vector< char > listed
nbNodes x nbNodes, slot (r, c) is listed
int nbFallback
elements factorised dense in last factorisation
int mLd(int a, int b) const
leading dimension of block (a, b) of M = A^T
@ LISTED
listed blocks only, not analysed
@ DENSE
dense element matrix (core contains all nodes)
@ BLOCK
block elimination of order nodes, then dense core
size_t coreShift
shift of dense core in element buffer
size_t elemSize
doubles in element buffer
int sLd(int r, int c) const
std::vector< int > order
nodes eliminated block by block
bool isListed(int r, int c) const
std::vector< long > key
nodes (field, type, DOFs) and listed slots
std::vector< long > slotShift
nbNodes x nbNodes, -1 if not stored
double beMax
largest backward error in last factorisation
std::vector< int > core
nodes of dense core
std::vector< int > nodeOffset
offset of node DOFs in element vector
std::vector< int > slotLd
bool operator()(const UId &a, const Indexes &b) const
bool operator()(const Indexes &a, const UId &b) const
Storage of block matrix, shared by block matrix and its nested (Schur) sub-matrices.
bool hasPreconditioner
preconditioner blocks are enabled
MoFEMErrorCode modified() const
Call before modification of data, fails if factors are stored in place.
size_t maxElemBuffer
maximal size of element buffer
double optRcondMin
-schur_a00_rcond_min
auto rowRange(const UId &row) const
range of blocks with given row entity uid
std::vector< std::pair< UId, std::vector< double > > > elemDataCache
SchurFEOpsFEandFields feOps
bool isFactorised() const
std::vector< FeConnectivity > feConnectivity
Surviving elements can acquire different field entities after local flips.
double * blockPtr(const Indexes &b, bool prec=false)
values of block, preconditioner buffer if prec is true
std::vector< ElemEntity > elemEntities
std::vector< int > feOrder
blocks sorted by (fe uid, row uid, col uid)
std::vector< int > colOrder
blocks sorted by (col uid, row uid)
std::vector< Elem > elems
std::vector< std::pair< UId, int > > feList
(element uid, index in feOps) of elements of the last build, sorted
bool optDense
-schur_a00_dense
FactorStorage factorStorage
std::vector< double > data
blocks not in A00, allocated on first use
std::vector< std::vector< double > > elemPrec
preconditioner buffers
std::vector< std::vector< double > > elemDense
dense factors (fallback)
double optBackwardError
-schur_a00_backward_error
std::vector< std::vector< double > > elemData
A00 element buffers.
MoFEMErrorCode checkNotFailed() const
Fails if factorisation failed, storage has to be zeroed.
std::vector< Indexes > blockIndex
blocks sorted by (row uid, col uid)
double optPivotThreshold
-schur_a00_pivot_threshold
size_t dataSize
required size of data
@ FACTOR_IN_PRECONDITIONER
@ FACTOR_FAILED
factorisation failed, data is corrupted
std::vector< double > dataCache
int maxElemSize
maximal DOFs of element
static bool lessRowCol(const Indexes &a, const Indexes &b)
const Indexes * find(const UId &row, const UId &col) const
find block by row and column entity uid, return nullptr if not found
Indexes * findMutable(const UId &row, const UId &col)
std::vector< Pattern > patternCache
std::vector< Pattern > patterns
std::vector< __CLPK_integer > pivots
bool nested
nested Schur structure has been created
std::vector< std::pair< UId, std::vector< double > > > elemPrecCache
auto colRange(const UId &col) const
range (in colOrder) of blocks with given column entity uid
block in numbering of this matrix (blocks not stored in element buffers)
Context of block matrix shell.
std::vector< Block > blocks
Numbering
numbering of A00 element matrix entities used by this matrix
bool multiplyByPreconditioner
boost::shared_ptr< BlockStorage > storage
int locIdx(const BlockStorage::ElemEntity &e) const
SmartPetscObj< Vec > ghostX
SmartPetscObj< Vec > ghostY
int globIdx(const BlockStorage::ElemEntity &e) const
bool hasElems
A00 elements are part of this matrix.
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
const VectorFieldEntities & getFieldEntities() const
Get field entities (const version)
const VectorDofs & getFieldDofs() const
Get DOF data structures (const version)
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
[Storage and set boundary conditions]
Structure for user loop methods on finite elements.
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static auto getHandleFromUniqueId(const UId uid)
Get the Handle From Unique Id.
static auto getFieldBitNumberFromUniqueId(const UId uid)
Get the Field Bit Number From Unique Id.
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
static UId getLoLocalEntityBitNumber(const char bit_number, const EntityHandle ent)
static UId getHiLocalEntityBitNumber(const char bit_number, const EntityHandle ent)
const FEMethod * getFEMethod() const
Return raw pointer to Finite Element Method object.
Partitioned (Indexed) Finite Element in Problem.
OpSchurAssembleBaseImpl()=delete
MoFEMErrorCode assembleSchurMat(Mat S, const UId &uid_row, VectorInt &row_ind, const UId &uid_col, VectorInt &col_ind, MatrixDouble &m, InsertMode iora)
Assemble Schur complement.
OpSchurAssembleBase()=delete
Clear Schur complement internal data.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Assemble Schur complement (Implementation)
SmartPetscObj< AO > schurAO
MoFEMErrorCode doWorkImpl(int side, EntityType type, EntitiesFieldData::EntData &data)
SmartPetscObj< Mat > schurMat
std::vector< boost::shared_ptr< Range > > fieldEnts
OpSchurAssembleEndImpl(std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range > > field_ents, SmartPetscObj< AO > schur_ao, SmartPetscObj< Mat > schur_mat, bool sym_schur, bool symm_op)
Construct a new Op Schur Assemble End object.
std::vector< std::string > fieldsName
Assemble Schur complement.
OpSchurZeroRowsAndCols(boost::shared_ptr< std::vector< unsigned char > > marker_ptr, double diag_val)
boost::shared_ptr< std::vector< unsigned char > > markerPtr
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Index tags of the numbered DOF containers that also read the index.
keeps basic data about problem
boost::shared_ptr< NumeredEntFiniteElement_multiIndex > numeredFiniteElementsPtr
store finite elements
boost::function< MoFEMErrorCode(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)> MatSetValuesPtr
Digest of a block structure, for tests.
static auto invertMat(MatrixDouble &m, MatrixDouble &inv)
static auto invertMat(MatrixDouble &m, MatrixDouble &inv)
Schur complement data storage.
static MoFEMErrorCode assembleStorage(const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
static boost::ptr_vector< VectorInt > colIndices
static boost::ptr_vector< MatrixDouble > locMats
SchurElemMats(const size_t idx, const UId uid_row, const UId uid_col)
virtual ~SchurElemMats()=default
static size_t maxIndexCounter
static boost::ptr_vector< VectorInt > rowIndices
static MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
static boost::ptr_vector< SchurElemMats > schurElemMats
static SchurElemStorage schurL2Storage
multi_index_container< const SchurElemMats *, indexed_by< ordered_unique< tag< uid_mi_tag >, composite_key< SchurElemMats, member< SchurElemMats, const UId, &SchurElemMats::uidRow >, member< SchurElemMats, const UId, &SchurElemMats::uidCol > > >, ordered_non_unique< tag< col_mi_tag >, member< SchurElemMats, const UId, &SchurElemMats::uidCol > > > > SchurElemStorage
static PetscLogEvent MOFEM_EVENT_BlockStructureSetValues
static PetscLogEvent MOFEM_EVENT_BlockStructureMult
static PetscLogEvent MOFEM_EVENT_zeroRowsAndCols
static PetscLogEvent MOFEM_EVENT_opSchurAssembleEnd
static PetscLogEvent MOFEM_EVENT_BlockStructureSolve
static PetscLogEvent MOFEM_EVENT_schurMatSetValues
static PetscLogEvent MOFEM_EVENT_AssembleSchurMat
intrusive_ptr for managing petsc objects
constexpr IntegrationType IT