10 #ifndef MUELU_IPCFACTORY_DEF_HPP
11 #define MUELU_IPCFACTORY_DEF_HPP
23 #include "MueLu_PerfUtils.hpp"
24 #include "MueLu_Utilities.hpp"
34 #include "Intrepid2_HGRAD_LINE_C1_FEM.hpp"
35 #include "Intrepid2_HGRAD_LINE_Cn_FEM.hpp"
40 #include "Intrepid2_HGRAD_QUAD_C1_FEM.hpp"
42 #include "Intrepid2_HGRAD_QUAD_Cn_FEM.hpp"
57 #define MUELU_LEVEL_SET_IF_REQUESTED_OR_KEPT(level, ename, entry) \
59 if (level.IsRequested(ename, this) || level.GetKeepFlag(ename, this) != 0) this->Set(level, ename, entry); \
65 namespace MueLuIntrepid {
66 inline std::string
tolower(
const std::string &str) {
67 std::string data(str);
68 std::transform(data.begin(), data.end(), data.begin(),
::tolower);
73 template <
class Basis,
class LOFieldContainer,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 std::vector<std::vector<LocalOrdinal>> &seeds,
87 shards::CellTopology cellTopo = basis->getBaseCellTopology();
88 int spaceDim = cellTopo.getDimension();
90 seeds.resize(spaceDim + 1);
97 std::vector<std::set<LocalOrdinal>> seedSets(spaceDim + 1);
99 int numCells = elementToNodeMap.extent(0);
100 auto elementToNodeMap_host = Kokkos::create_mirror_view(elementToNodeMap);
101 Kokkos::deep_copy(elementToNodeMap_host, elementToNodeMap);
102 for (
int cellOrdinal = 0; cellOrdinal < numCells; cellOrdinal++) {
103 for (
int d = 0; d <= spaceDim; d++) {
104 int subcellCount = cellTopo.getSubcellCount(d);
105 for (
int subcord = 0; subcord < subcellCount; subcord++) {
106 int dofCount = basis->getDofCount(d, subcord);
107 if (dofCount == 0)
continue;
109 GO leastGlobalDofOrdinal = go_invalid;
110 LO LID_leastGlobalDofOrdinal = lo_invalid;
111 for (
int basisOrdinalOrdinal = 0; basisOrdinalOrdinal < dofCount; basisOrdinalOrdinal++) {
112 int basisOrdinal = basis->getDofOrdinal(d, subcord, basisOrdinalOrdinal);
113 int colLID = elementToNodeMap_host(cellOrdinal, basisOrdinal);
117 if (rowLID != lo_invalid) {
118 if ((leastGlobalDofOrdinal == go_invalid) || (colGID < leastGlobalDofOrdinal)) {
120 leastGlobalDofOrdinal = colGID;
121 LID_leastGlobalDofOrdinal = rowLID;
126 if (leastGlobalDofOrdinal != go_invalid) {
127 seedSets[d].insert(LID_leastGlobalDofOrdinal);
132 for (
int d = 0; d <= spaceDim; d++) {
133 seeds[d] = std::vector<LocalOrdinal>(seedSets[d].begin(), seedSets[d].end());
144 template <
class Scalar,
class KokkosExecutionSpace>
148 string myerror(
"IntrepidBasisFactory: cannot parse string name '" + name +
"'");
153 size_t pos1 = name.find_first_of(
" _");
154 if (pos1 == 0)
throw std::runtime_error(myerror);
155 string deriv =
tolower(name.substr(0, pos1));
156 if (deriv !=
"hgrad" && deriv !=
"hcurl" && deriv !=
"hdiv")
throw std::runtime_error(myerror);
160 size_t pos2 = name.find_first_of(
" _", pos1);
161 if (pos2 == 0)
throw std::runtime_error(myerror);
162 string el =
tolower(name.substr(pos1, pos2 - pos1));
163 if (el !=
"hex" && el !=
"line" && el !=
"poly" && el !=
"pyr" && el !=
"quad" && el !=
"tet" && el !=
"tri" && el !=
"wedge")
throw std::runtime_error(myerror);
167 string poly =
tolower(name.substr(pos2, 1));
168 if (poly !=
"c" && poly !=
"i")
throw std::runtime_error(myerror);
172 degree = std::stoi(name.substr(pos2, 1));
173 if (degree <= 0)
throw std::runtime_error(myerror);
176 if (deriv ==
"hgrad" && el ==
"quad" && poly ==
"c") {
178 return rcp(
new Intrepid2::Basis_HGRAD_QUAD_C1_FEM<KokkosExecutionSpace, Scalar, Scalar>());
180 return rcp(
new Intrepid2::Basis_HGRAD_QUAD_Cn_FEM<KokkosExecutionSpace, Scalar, Scalar>(degree, Intrepid2::POINTTYPE_EQUISPACED));
181 }
else if (deriv ==
"hgrad" && el ==
"line" && poly ==
"c") {
183 return rcp(
new Intrepid2::Basis_HGRAD_LINE_C1_FEM<KokkosExecutionSpace, Scalar, Scalar>());
185 return rcp(
new Intrepid2::Basis_HGRAD_LINE_Cn_FEM<KokkosExecutionSpace, Scalar, Scalar>(degree, Intrepid2::POINTTYPE_EQUISPACED));
189 throw std::runtime_error(myerror);
200 template <
class Scalar,
class KokkosDeviceType>
202 std::vector<size_t> &lo_node_in_hi,
203 Kokkos::DynRankView<Scalar, KokkosDeviceType> &hi_DofCoords) {
204 typedef typename KokkosDeviceType::execution_space KokkosExecutionSpace;
206 size_t degree = hi_basis->getDegree();
207 lo_node_in_hi.resize(0);
209 if (!rcp_dynamic_cast<Intrepid2::Basis_HGRAD_QUAD_Cn_FEM<KokkosExecutionSpace, Scalar, Scalar>>(hi_basis).
is_null()) {
211 lo_node_in_hi.insert(lo_node_in_hi.end(), {0, degree, (degree + 1) * (degree + 1) - 1, degree * (degree + 1)});
212 }
else if (!rcp_dynamic_cast<Intrepid2::Basis_HGRAD_LINE_Cn_FEM<KokkosExecutionSpace, Scalar, Scalar>>(hi_basis).is_null()) {
214 lo_node_in_hi.insert(lo_node_in_hi.end(), {0, degree});
216 throw std::runtime_error(
"IntrepidPCoarsenFactory: Unknown element type");
219 Kokkos::resize(hi_DofCoords, hi_basis->getCardinality(), hi_basis->getBaseCellTopology().getDimension());
220 hi_basis->getDofCoords(hi_DofCoords);
231 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LOFieldContainer>
234 LOFieldContainer &lo_elemToHiRepresentativeNode) {
240 size_t numElem = hi_elemToNode.extent(0);
241 size_t lo_nperel = candidates.size();
242 Kokkos::resize(lo_elemToHiRepresentativeNode, numElem, lo_nperel);
244 auto lo_elemToHiRepresentativeNode_host = Kokkos::create_mirror_view(lo_elemToHiRepresentativeNode);
245 auto hi_elemToNode_host = Kokkos::create_mirror_view(hi_elemToNode);
246 Kokkos::deep_copy(hi_elemToNode_host, hi_elemToNode);
247 for (
size_t i = 0; i < numElem; i++)
248 for (
size_t j = 0; j < lo_nperel; j++) {
249 if (candidates[j].size() == 1)
250 lo_elemToHiRepresentativeNode_host(i, j) = hi_elemToNode_host(i, candidates[j][0]);
253 std::vector<GO> GID(candidates[j].size());
254 for (
size_t k = 0; k < (size_t)candidates[j].size(); k++)
255 GID[k] = hi_columnMap->getGlobalElement(hi_elemToNode_host(i, candidates[j][k]));
258 size_t which = std::distance(GID.begin(), std::min_element(GID.begin(), GID.end()));
261 lo_elemToHiRepresentativeNode_host(i, j) = hi_elemToNode_host(i, candidates[j][which]);
264 Kokkos::deep_copy(lo_elemToHiRepresentativeNode, lo_elemToHiRepresentativeNode_host);
277 template <
class LocalOrdinal,
class LOFieldContainer>
279 const std::vector<bool> &hi_nodeIsOwned,
280 const LOFieldContainer &lo_elemToHiRepresentativeNode,
281 LOFieldContainer &lo_elemToNode,
282 std::vector<bool> &lo_nodeIsOwned,
283 std::vector<LocalOrdinal> &hi_to_lo_map,
284 int &lo_numOwnedNodes) {
288 size_t numElem = hi_elemToNode.extent(0);
289 size_t hi_numNodes = hi_nodeIsOwned.size();
290 size_t lo_nperel = lo_elemToHiRepresentativeNode.extent(1);
291 Kokkos::resize(lo_elemToNode, numElem, lo_nperel);
294 auto lo_elemToHiRepresentativeNode_host = Kokkos::create_mirror_view(lo_elemToHiRepresentativeNode);
295 Kokkos::deep_copy(lo_elemToHiRepresentativeNode_host, lo_elemToHiRepresentativeNode);
296 std::vector<bool> is_low_order(hi_numNodes,
false);
297 for (
size_t i = 0; i < numElem; i++)
298 for (
size_t j = 0; j < lo_nperel; j++) {
299 LO
id = lo_elemToHiRepresentativeNode_host(i, j);
300 is_low_order[id] =
true;
304 lo_numOwnedNodes = 0;
305 size_t lo_numNodes = 0;
308 for (
size_t i = 0; i < hi_numNodes; i++)
309 if (is_low_order[i]) {
310 hi_to_lo_map[i] = lo_numNodes;
312 if (hi_nodeIsOwned[i]) lo_numOwnedNodes++;
316 lo_nodeIsOwned.resize(lo_numNodes,
false);
317 for (
size_t i = 0; i < hi_numNodes; i++) {
318 if (is_low_order[i] && hi_nodeIsOwned[i])
319 lo_nodeIsOwned[hi_to_lo_map[i]] =
true;
323 auto lo_elemToNode_host = Kokkos::create_mirror_view(lo_elemToNode);
324 for (
size_t i = 0; i < numElem; i++)
325 for (
size_t j = 0; j < lo_nperel; j++)
326 lo_elemToNode_host(i, j) = hi_to_lo_map[lo_elemToHiRepresentativeNode_host(i, j)];
330 bool map_ordering_test_passed =
true;
331 for (
size_t i = 0; i < lo_numNodes - 1; i++)
332 if (!lo_nodeIsOwned[i] && lo_nodeIsOwned[i + 1])
333 map_ordering_test_passed =
false;
335 if (!map_ordering_test_passed)
336 throw std::runtime_error(
"MueLu::MueLuIntrepid::BuildLoElemToNodeViaRepresentatives failed map ordering test");
337 Kokkos::deep_copy(lo_elemToNode, lo_elemToNode_host);
351 template <
class LocalOrdinal,
class LOFieldContainer>
353 const std::vector<bool> &hi_nodeIsOwned,
354 const std::vector<size_t> &lo_node_in_hi,
356 LOFieldContainer &lo_elemToNode,
357 std::vector<bool> &lo_nodeIsOwned,
358 std::vector<LocalOrdinal> &hi_to_lo_map,
359 int &lo_numOwnedNodes) {
365 size_t numElem = hi_elemToNode.extent(0);
366 size_t hi_numNodes = hi_nodeIsOwned.size();
368 size_t lo_nperel = lo_node_in_hi.size();
369 Kokkos::resize(lo_elemToNode, numElem, lo_nperel);
372 std::vector<bool> is_low_order(hi_numNodes,
false);
373 auto hi_elemToNode_host = Kokkos::create_mirror_view(hi_elemToNode);
374 Kokkos::deep_copy(hi_elemToNode_host, hi_elemToNode);
375 auto lo_elemToNode_host = Kokkos::create_mirror_view(lo_elemToNode);
376 for (
size_t i = 0; i < numElem; i++)
377 for (
size_t j = 0; j < lo_nperel; j++) {
378 LO lid = hi_elemToNode_host(i, lo_node_in_hi[j]);
381 if (hi_isDirichlet[lid])
382 lo_elemToNode_host(i, j) = LOINVALID;
384 lo_elemToNode_host(i, j) = lid;
385 is_low_order[hi_elemToNode_host(i, lo_node_in_hi[j])] =
true;
390 lo_numOwnedNodes = 0;
391 size_t lo_numNodes = 0;
394 for (
size_t i = 0; i < hi_numNodes; i++)
395 if (is_low_order[i]) {
396 hi_to_lo_map[i] = lo_numNodes;
398 if (hi_nodeIsOwned[i]) lo_numOwnedNodes++;
402 lo_nodeIsOwned.resize(lo_numNodes,
false);
403 for (
size_t i = 0; i < hi_numNodes; i++) {
404 if (is_low_order[i] && hi_nodeIsOwned[i])
405 lo_nodeIsOwned[hi_to_lo_map[i]] =
true;
409 for (
size_t i = 0; i < numElem; i++)
410 for (
size_t j = 0; j < lo_nperel; j++) {
411 if (lo_elemToNode_host(i, j) != LOINVALID)
412 lo_elemToNode_host(i, j) = hi_to_lo_map[lo_elemToNode_host(i, j)];
414 Kokkos::deep_copy(lo_elemToNode, lo_elemToNode_host);
418 bool map_ordering_test_passed =
true;
419 for (
size_t i = 0; i < lo_numNodes - 1; i++)
420 if (!lo_nodeIsOwned[i] && lo_nodeIsOwned[i + 1])
421 map_ordering_test_passed =
false;
423 if (!map_ordering_test_passed)
424 throw std::runtime_error(
"MueLu::MueLuIntrepid::BuildLoElemToNode failed map ordering test");
436 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
437 void GenerateColMapFromImport(
const Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> &hi_importer,
const std::vector<LocalOrdinal> &hi_to_lo_map,
const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> &lo_domainMap,
const size_t &lo_columnMapLength,
RCP<
const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> &lo_columnMap) {
457 for (
size_t i = 0; i < hi_domainMap->getLocalNumElements(); i++) {
458 if (hi_to_lo_map[i] != lo_invalid)
461 dvec_data[i] = go_invalid;
470 Array<GO> lo_col_data(lo_columnMapLength);
473 for (
size_t i = 0, idx = 0; i < hi_columnMap->getLocalNumElements(); i++) {
474 if (hi_to_lo_map[i] != lo_invalid) {
475 lo_col_data[idx] = cvec_data[i];
492 template <
class Basis,
class SCFieldContainer>
493 void GenerateRepresentativeBasisNodes(
const Basis &basis,
const SCFieldContainer &ReferenceNodeLocations,
const double threshold, std::vector<std::vector<size_t>> &representative_node_candidates) {
494 typedef SCFieldContainer FC;
495 typedef typename FC::data_type
SC;
498 size_t numFieldsHi = ReferenceNodeLocations.extent(0);
500 size_t numFieldsLo = basis.getCardinality();
502 FC LoValues(
"LoValues", numFieldsLo, numFieldsHi);
504 basis.getValues(LoValues, ReferenceNodeLocations, Intrepid2::OPERATOR_VALUE);
509 printf(
"** LoValues[%d,%d] **\n",(
int)numFieldsLo,(
int)numFieldsHi);
510 for(
size_t i=0; i<numFieldsLo; i++) {
511 for(
size_t j=0; j<numFieldsHi; j++)
512 printf(
"%6.4e ",LoValues(i,j));
515 printf(
"**************\n");fflush(stdout);
518 representative_node_candidates.resize(numFieldsLo);
519 auto LoValues_host = Kokkos::create_mirror_view(LoValues);
520 Kokkos::deep_copy(LoValues_host, LoValues);
521 for (
size_t i = 0; i < numFieldsLo; i++) {
524 for (
size_t j = 0; j < numFieldsHi; j++)
528 for (
size_t j = 0; j < numFieldsHi; j++) {
530 representative_node_candidates[i].push_back(j);
535 for (
size_t i = 0; i < numFieldsLo; i++)
536 if (!representative_node_candidates[i].size())
537 throw std::runtime_error(
"ERROR: GenerateRepresentativeBasisNodes: No candidates found!");
545 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
547 const std::vector<bool> &hi_nodeIsOwned,
549 const std::vector<size_t> &lo_node_in_hi,
550 const Basis &lo_basis,
551 const std::vector<LocalOrdinal> &hi_to_lo_map,
558 size_t numFieldsHi = hi_elemToNode.extent(1);
559 size_t numFieldsLo = lo_basis.getCardinality();
561 FC LoValues_at_HiDofs(
"LoValues_at_HiDofs", numFieldsLo, numFieldsHi);
562 lo_basis.getValues(LoValues_at_HiDofs, hi_DofCoords, Intrepid2::OPERATOR_VALUE);
563 auto LoValues_at_HiDofs_host = Kokkos::create_mirror_view(LoValues_at_HiDofs);
564 Kokkos::deep_copy(LoValues_at_HiDofs_host, LoValues_at_HiDofs);
572 P =
rcp(
new CrsMatrixWrap(hi_map, lo_colMap, numFieldsHi));
573 RCP<CrsMatrix> Pcrs = rcp_dynamic_cast<CrsMatrixWrap>(P)->getCrsMatrix();
576 size_t Nelem = hi_elemToNode.extent(0);
577 std::vector<bool> touched(hi_map->getLocalNumElements(),
false);
580 auto hi_elemToNode_host = Kokkos::create_mirror_view(hi_elemToNode);
581 Kokkos::deep_copy(hi_elemToNode_host, hi_elemToNode);
582 for (
size_t i = 0; i < Nelem; i++) {
583 for (
size_t j = 0; j < numFieldsHi; j++) {
584 LO row_lid = hi_elemToNode_host(i, j);
585 GO row_gid = hi_map->getGlobalElement(row_lid);
586 if (hi_nodeIsOwned[row_lid] && !touched[row_lid]) {
587 for (
size_t k = 0; k < numFieldsLo; k++) {
589 LO col_lid = hi_to_lo_map[hi_elemToNode_host(i, lo_node_in_hi[k])];
590 if (col_lid == LOINVALID)
continue;
592 col_gid[0] = {lo_colMap->getGlobalElement(col_lid)};
593 val[0] = LoValues_at_HiDofs_host(k, j);
597 P->insertGlobalValues(row_gid, col_gid(), val());
599 touched[row_lid] =
true;
603 P->fillComplete(lo_domainMap, hi_map);
607 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
609 const std::vector<bool> &hi_nodeIsOwned,
612 const Basis &lo_basis,
613 const std::vector<LocalOrdinal> &hi_to_lo_map,
620 size_t numFieldsHi = hi_elemToNode.extent(1);
621 size_t numFieldsLo = lo_basis.getCardinality();
622 FC LoValues_at_HiDofs(
"LoValues_at_HiDofs", numFieldsLo, numFieldsHi);
623 lo_basis.getValues(LoValues_at_HiDofs, hi_DofCoords, Intrepid2::OPERATOR_VALUE);
624 auto LoValues_at_HiDofs_host = Kokkos::create_mirror_view(LoValues_at_HiDofs);
625 auto hi_elemToNode_host = Kokkos::create_mirror_view(hi_elemToNode);
626 auto lo_elemToHiRepresentativeNode_host = Kokkos::create_mirror_view(lo_elemToHiRepresentativeNode);
627 Kokkos::deep_copy(LoValues_at_HiDofs_host, LoValues_at_HiDofs);
628 Kokkos::deep_copy(hi_elemToNode_host, hi_elemToNode);
629 Kokkos::deep_copy(lo_elemToHiRepresentativeNode_host, lo_elemToHiRepresentativeNode);
637 P =
rcp(
new CrsMatrixWrap(hi_map, lo_colMap, numFieldsHi));
638 RCP<CrsMatrix> Pcrs = rcp_dynamic_cast<CrsMatrixWrap>(P)->getCrsMatrix();
641 size_t Nelem = hi_elemToNode.extent(0);
642 std::vector<bool> touched(hi_map->getLocalNumElements(),
false);
645 for (
size_t i = 0; i < Nelem; i++) {
646 for (
size_t j = 0; j < numFieldsHi; j++) {
647 LO row_lid = hi_elemToNode_host(i, j);
648 GO row_gid = hi_map->getGlobalElement(row_lid);
649 if (hi_nodeIsOwned[row_lid] && !touched[row_lid]) {
650 for (
size_t k = 0; k < numFieldsLo; k++) {
652 LO col_lid = hi_to_lo_map[lo_elemToHiRepresentativeNode_host(i, k)];
653 col_gid[0] = {lo_colMap->getGlobalElement(col_lid)};
654 val[0] = LoValues_at_HiDofs_host(k, j);
658 P->insertGlobalValues(row_gid, col_gid(), val());
660 touched[row_lid] =
true;
664 P->fillComplete(lo_domainMap, hi_map);
668 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
672 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
675 #undef SET_VALID_ENTRY
677 validParamList->set<
RCP<const FactoryBase>>(
"A", Teuchos::null,
"Generating factory of the matrix A used during the prolongator smoothing process");
679 validParamList->set<
RCP<const FactoryBase>>(
"Nullspace", Teuchos::null,
"Generating factory of the nullspace");
680 validParamList->set<
RCP<const FactoryBase>>(
"pcoarsen: element to node map", Teuchos::null,
"Generating factory of the element to node map");
681 return validParamList;
685 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
687 Input(fineLevel,
"A");
688 Input(fineLevel,
"pcoarsen: element to node map");
689 Input(fineLevel,
"Nullspace");
693 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
695 return BuildP(fineLevel, coarseLevel);
699 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
703 const std::string prefix =
"MueLu::IntrepidPCoarsenFactory(" + levelIDs +
"): ";
706 typedef Kokkos::DynRankView<LocalOrdinal, typename Node::device_type> FCi;
707 typedef Kokkos::DynRankView<double, typename Node::device_type> FC;
711 RCP<MultiVector> fineNullspace = Get<RCP<MultiVector>>(fineLevel,
"Nullspace");
714 if (restrictionMode_) {
720 std::vector<LocalOrdinal> A_dirichletRows;
728 if (coarseLevel.
IsAvailable(
"AP reuse data",
this)) {
729 GetOStream(static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous AP data" << std::endl;
733 if (APparams->isParameter(
"graph"))
743 int lo_degree, hi_degree;
744 RCP<Basis> hi_basis = MueLuIntrepid::BasisFactory<double, typename Node::device_type::execution_space>(pL.
get<std::string>(
"pcoarsen: hi basis"), hi_degree);
745 RCP<Basis> lo_basis = MueLuIntrepid::BasisFactory<double, typename Node::device_type::execution_space>(pL.
get<std::string>(
"pcoarsen: lo basis"), lo_degree);
748 GetOStream(
Statistics1) <<
"P-Coarsening from basis " << pL.
get<std::string>(
"pcoarsen: hi basis") <<
" to " << pL.
get<std::string>(
"pcoarsen: lo basis") << std::endl;
752 const Teuchos::RCP<FCi> Pn_elemToNode = Get<Teuchos::RCP<FCi>>(fineLevel,
"pcoarsen: element to node map");
762 int NumProc = rowMap->getComm()->getSize();
763 assert(rowMap->isSameAs(*domainMap));
764 std::vector<bool> Pn_nodeIsOwned(colMap->getLocalNumElements(),
false);
765 LO num_owned_rows = 0;
766 for (
size_t i = 0; i < rowMap->getLocalNumElements(); i++) {
767 if (rowMap->getGlobalElement(i) == colMap->getGlobalElement(i)) {
768 Pn_nodeIsOwned[i] =
true;
777 std::vector<bool> P1_nodeIsOwned;
778 int P1_numOwnedNodes;
779 std::vector<LO> hi_to_lo_map;
782 std::vector<size_t> lo_node_in_hi;
785 FCi lo_elemToHiRepresentativeNode;
792 printf(
"[%d] isDirichletRow = ",A->getRowMap()->getComm()->getRank());
793 for(
size_t i=0;i<hi_isDirichletRow->getMap()->getLocalNumElements(); i++)
794 printf(
"%d ",hi_isDirichletRow->getData(0)[i]);
796 printf(
"[%d] isDirichletCol = ",A->getRowMap()->getComm()->getRank());
797 for(
size_t i=0;i<hi_isDirichletCol->getMap()->getLocalNumElements(); i++)
798 printf(
"%d ",hi_isDirichletCol->getData(0)[i]);
804 if (lo_degree == 1) {
809 MueLuIntrepid::BuildLoElemToNode(*Pn_elemToNode, Pn_nodeIsOwned, lo_node_in_hi, hi_isDirichletCol->getData(0), *P1_elemToNode, P1_nodeIsOwned, hi_to_lo_map, P1_numOwnedNodes);
810 assert(hi_to_lo_map.size() == colMap->getLocalNumElements());
813 double threshold = 1e-10;
814 std::vector<std::vector<size_t>> candidates;
815 Kokkos::resize(hi_DofCoords, hi_basis->getCardinality(), hi_basis->getBaseCellTopology().getDimension());
816 hi_basis->getDofCoords(hi_DofCoords);
818 MueLu::MueLuIntrepid::GenerateRepresentativeBasisNodes<Basis, FC>(*lo_basis, hi_DofCoords, threshold, candidates);
835 P1_colMap = P1_domainMap;
837 MueLuIntrepid::GenerateColMapFromImport<LO, GO, NO>(*Acrs.getCrsGraph()->getImporter(), hi_to_lo_map, *P1_domainMap, P1_nodeIsOwned.size(), P1_colMap);
842 GenerateLinearCoarsening_pn_kirby_to_p1(*Pn_elemToNode, Pn_nodeIsOwned, hi_DofCoords, lo_node_in_hi, *lo_basis, hi_to_lo_map, P1_colMap, P1_domainMap, A->getRowMap(), finalP);
844 GenerateLinearCoarsening_pn_kirby_to_pm(*Pn_elemToNode, Pn_nodeIsOwned, hi_DofCoords, lo_elemToHiRepresentativeNode, *lo_basis, hi_to_lo_map, P1_colMap, P1_domainMap, A->getRowMap(), finalP);
852 RCP<MultiVector> coarseNullspace = MultiVectorFactory::Build(P1_domainMap, fineNullspace->getNumVectors());
854 Set(coarseLevel,
"Nullspace", coarseNullspace);
857 if (!restrictionMode_) {
859 Set(coarseLevel,
"P", finalP);
861 APparams->set(
"graph", finalP);
866 params->set(
"printLoadBalancingInfo",
true);
867 params->set(
"printCommInfo",
true);
878 Set(coarseLevel,
"R", R);
882 params->set(
"printLoadBalancingInfo",
true);
883 params->set(
"printCommInfo",
true);
892 #endif // MUELU_IPCFACTORY_DEF_HPP
void GenerateLoNodeInHiViaGIDs(const std::vector< std::vector< size_t > > &candidates, const LOFieldContainer &hi_elemToNode, RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &hi_columnMap, LOFieldContainer &lo_elemToHiRepresentativeNode)
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const =0
MueLu::DefaultLocalOrdinal LocalOrdinal
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level->Get< RCP<Matrix> >("A", factory) if factory == NULL => use default factory.
Teuchos::RCP< Intrepid2::Basis< KokkosExecutionSpace, Scalar, Scalar > > BasisFactory(const std::string &name, int °ree)
bool is_null(const boost::shared_ptr< T > &p)
void FindGeometricSeedOrdinals(Teuchos::RCP< Basis > basis, const LOFieldContainer &elementToNodeMap, std::vector< std::vector< LocalOrdinal > > &seeds, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &rowMap, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &columnMap)
static void FindDirichletRowsAndPropagateToCols(Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &A, Teuchos::RCP< Xpetra::Vector< int, LocalOrdinal, GlobalOrdinal, Node >> &isDirichletRow, Teuchos::RCP< Xpetra::Vector< int, LocalOrdinal, GlobalOrdinal, Node >> &isDirichletCol)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
static magnitudeType eps()
T & get(const std::string &name, T def_value)
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
Timer to be used in factories. Similar to Monitor but with additional timers.
void IntrepidGetP1NodeInHi(const Teuchos::RCP< Intrepid2::Basis< typename KokkosDeviceType::execution_space, Scalar, Scalar >> &hi_basis, std::vector< size_t > &lo_node_in_hi, Kokkos::DynRankView< Scalar, KokkosDeviceType > &hi_DofCoords)
One-liner description of what is happening.
static void ZeroDirichletRows(Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &A, const std::vector< LocalOrdinal > &dirichletRows, Scalar replaceWith=Teuchos::ScalarTraits< Scalar >::zero())
virtual LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const =0
std::string tolower(const std::string &str)
virtual GlobalOrdinal getIndexBase() const =0
Kokkos::DynRankView< LocalOrdinal, typename Node::device_type > LOFieldContainer
Print even more statistics.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getTargetMap() const =0
static void FindDirichletRows(Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &A, std::vector< LocalOrdinal > &dirichletRows, bool count_twos_as_dirichlet=false)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
void BuildLoElemToNode(const LOFieldContainer &hi_elemToNode, const std::vector< bool > &hi_nodeIsOwned, const std::vector< size_t > &lo_node_in_hi, const Teuchos::ArrayRCP< const int > &hi_isDirichlet, LOFieldContainer &lo_elemToNode, std::vector< bool > &lo_nodeIsOwned, std::vector< LocalOrdinal > &hi_to_lo_map, int &lo_numOwnedNodes)
Kokkos::DynRankView< double, typename Node::device_type > SCFieldContainer
void BuildLoElemToNodeViaRepresentatives(const LOFieldContainer &hi_elemToNode, const std::vector< bool > &hi_nodeIsOwned, const LOFieldContainer &lo_elemToHiRepresentativeNode, LOFieldContainer &lo_elemToNode, std::vector< bool > &lo_nodeIsOwned, std::vector< LocalOrdinal > &hi_to_lo_map, int &lo_numOwnedNodes)
#define MUELU_LEVEL_SET_IF_REQUESTED_OR_KEPT(level, ename, entry)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Transpose(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, bool optimizeTranspose=false, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void GenerateLinearCoarsening_pn_kirby_to_p1(const LOFieldContainer &hi_elemToNode, const std::vector< bool > &hi_nodeIsOwned, const SCFieldContainer &hi_DofCoords, const std::vector< size_t > &lo_node_in_hi, const Basis &lo_Basis, const std::vector< LocalOrdinal > &hi_to_lo_map, const Teuchos::RCP< const Map > &lo_colMap, const Teuchos::RCP< const Map > &lo_domainMap, const Teuchos::RCP< const Map > &hi_map, Teuchos::RCP< Matrix > &P) const
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const =0
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
void GenerateColMapFromImport(const Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > &hi_importer, const std::vector< LocalOrdinal > &hi_to_lo_map, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &lo_domainMap, const size_t &lo_columnMapLength, RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &lo_columnMap)
Intrepid2::Basis< typename Node::device_type::execution_space, double, double > Basis
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
void Build(Level &fineLevel, Level &coarseLevel) const
Build method.
void GenerateRepresentativeBasisNodes(const Basis &basis, const SCFieldContainer &ReferenceNodeLocations, const double threshold, std::vector< std::vector< size_t > > &representative_node_candidates)
int GetLevelID() const
Return level number.
void GenerateLinearCoarsening_pn_kirby_to_pm(const LOFieldContainer &hi_elemToNode, const std::vector< bool > &hi_nodeIsOwned, const SCFieldContainer &hi_DofCoords, const LOFieldContainer &lo_elemToHiRepresentativeNode, const Basis &lo_basis, const std::vector< LocalOrdinal > &hi_to_lo_map, const Teuchos::RCP< const Map > &lo_colMap, const Teuchos::RCP< const Map > &lo_domainMap, const Teuchos::RCP< const Map > &hi_map, Teuchos::RCP< Matrix > &P) const
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getSourceMap() const =0
virtual UnderlyingLib lib() const =0
#define SET_VALID_ENTRY(name)
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.