Project solution data between mesh levels.
Projects field data from coarse to fine mesh levels during refinement. Handles both time stepping vectors (for theta method) and regular fields. Uses L2 projection with mass matrix assembly.
1409 {
1411
1412
1413
1414
1415
1420
1421
1422
1423 auto fe_domain_lhs = pip_mng->getDomainLhsFE();
1424 auto fe_domain_rhs = pip_mng->getDomainRhsFE();
1425 auto fe_bdy_lhs = pip_mng->getBoundaryLhsFE();
1426 auto fe_bdy_rhs = pip_mng->getBoundaryRhsFE();
1427
1428 pip_mng->getDomainLhsFE().reset();
1429 pip_mng->getDomainRhsFE().reset();
1430 pip_mng->getBoundaryLhsFE().reset();
1431 pip_mng->getBoundaryRhsFE().reset();
1432
1433 using UDO = ForcesAndSourcesCore::UserDataOperator;
1434
1435
1436 auto add_parent_field_domain = [&](
auto fe,
auto op,
auto field,
auto bit) {
1439
1440 [&]() {
1441 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1443 return fe_parent;
1444 },
1445
1447 };
1448
1449
1450 auto add_parent_field_bdy = [&](
auto fe,
auto op,
auto field,
auto bit) {
1453
1454 [&]() {
1455 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1457 return fe_parent;
1458 },
1459
1461 };
1462
1463
1464
1465 auto create_run_parent_op = [&](auto parent_fe_ptr, auto this_fe_ptr,
1466 auto fe_bit) {
1467 auto parent_mask = fe_bit;
1468 parent_mask.flip();
1471 Sev::inform);
1472 };
1473
1474
1475 auto get_parents_vel_fe_ptr = [&](auto this_fe_ptr, auto fe_bit) {
1476 std::vector<boost::shared_ptr<DomainParentEle>> parents_elems_ptr_vec;
1478 parents_elems_ptr_vec.emplace_back(
1479 boost::make_shared<DomainParentEle>(
mField));
1481 parents_elems_ptr_vec[
l - 1]->getOpPtrVector().push_back(
1482 create_run_parent_op(parents_elems_ptr_vec[
l], this_fe_ptr, fe_bit));
1483 }
1484 return parents_elems_ptr_vec[0];
1485 };
1486
1487
1488 auto solve_projection = [&](auto exe_test) {
1490
1491 auto set_domain_rhs = [&](auto fe) {
1493 auto &pip = fe->getOpPtrVector();
1494
1495 auto u_ptr = boost::make_shared<MatrixDouble>();
1496 auto p_ptr = boost::make_shared<VectorDouble>();
1497 auto h_ptr = boost::make_shared<VectorDouble>();
1498 auto g_ptr = boost::make_shared<VectorDouble>();
1499
1500 auto eval_fe_ptr = boost::make_shared<DomainParentEle>(
mField);
1501 {
1502 auto &pip = eval_fe_ptr->getOpPtrVector();
1506
1507 [&]() {
1508 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1510 return fe_parent;
1511 },
1512
1514
1515
1516 CHKERR add_parent_field_domain(eval_fe_ptr, UDO::OPCOL,
"U",
1519 CHKERR add_parent_field_domain(eval_fe_ptr, UDO::OPCOL,
"P",
1522 CHKERR add_parent_field_domain(eval_fe_ptr, UDO::OPCOL,
"H",
1525 CHKERR add_parent_field_domain(eval_fe_ptr, UDO::OPCOL,
"G",
1528 }
1529 auto parent_eval_fe_ptr =
1531 pip.push_back(create_run_parent_op(parent_eval_fe_ptr, eval_fe_ptr,
1533
1534 auto assemble_fe_ptr = boost::make_shared<DomainParentEle>(
mField);
1535 {
1536 auto &pip = assemble_fe_ptr->getOpPtrVector();
1540
1541 [&]() {
1542 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1544 return fe_parent;
1545 },
1546
1548 CHKERR add_parent_field_domain(assemble_fe_ptr, UDO::OPROW,
"U",
1551 CHKERR add_parent_field_domain(assemble_fe_ptr, UDO::OPROW,
"P",
1554 CHKERR add_parent_field_domain(assemble_fe_ptr, UDO::OPROW,
"H",
1557 CHKERR add_parent_field_domain(assemble_fe_ptr, UDO::OPROW,
"G",
1560 }
1561 auto parent_assemble_fe_ptr =
1563 pip.push_back(create_run_parent_op(
1565
1567 };
1568
1569 auto set_domain_lhs = [&](auto fe) {
1571
1572 auto &pip = fe->getOpPtrVector();
1573
1575
1578
1579 [&]() {
1580 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1582 return fe_parent;
1583 },
1584
1586
1587
1588
1589 CHKERR add_parent_field_domain(fe, UDO::OPROW,
"U",
1591 CHKERR add_parent_field_domain(fe, UDO::OPCOL,
"U",
1594 CHKERR add_parent_field_domain(fe, UDO::OPROW,
"P",
1596 CHKERR add_parent_field_domain(fe, UDO::OPCOL,
"P",
1599 CHKERR add_parent_field_domain(fe, UDO::OPROW,
"H",
1601 CHKERR add_parent_field_domain(fe, UDO::OPCOL,
"H",
1604 CHKERR add_parent_field_domain(fe, UDO::OPROW,
"G",
1606 CHKERR add_parent_field_domain(fe, UDO::OPCOL,
"G",
1609
1611 };
1612
1613 auto set_bdy_rhs = [&](auto fe) {
1615 auto &pip = fe->getOpPtrVector();
1616
1617 auto l_ptr = boost::make_shared<VectorDouble>();
1618
1619 auto eval_fe_ptr = boost::make_shared<BoundaryParentEle>(
mField);
1620 {
1621 auto &pip = eval_fe_ptr->getOpPtrVector();
1624
1625 [&]() {
1626 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1628 return fe_parent;
1629 },
1630
1632
1633
1634 CHKERR add_parent_field_bdy(eval_fe_ptr, UDO::OPCOL,
"L",
1637 }
1638 auto parent_eval_fe_ptr =
1640 pip.push_back(create_run_parent_op(parent_eval_fe_ptr, eval_fe_ptr,
1642
1643 auto assemble_fe_ptr = boost::make_shared<BoundaryParentEle>(
mField);
1644 {
1645 auto &pip = assemble_fe_ptr->getOpPtrVector();
1648
1649 [&]() {
1650 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1652 return fe_parent;
1653 },
1654
1656
1658 OpLSize(boost::shared_ptr<VectorDouble> l_ptr)
1662 if (lPtr->size() != getGaussPts().size2()) {
1663 lPtr->resize(getGaussPts().size2());
1664 lPtr->clear();
1665 }
1667 }
1668
1669 private:
1670 boost::shared_ptr<VectorDouble> lPtr;
1671 };
1672
1673 pip.push_back(new OpLSize(l_ptr));
1674
1675 CHKERR add_parent_field_bdy(assemble_fe_ptr, UDO::OPROW,
"L",
1678 }
1679 auto parent_assemble_fe_ptr =
1681 pip.push_back(create_run_parent_op(
1683
1685 };
1686
1687 auto set_bdy_lhs = [&](auto fe) {
1689
1690 auto &pip = fe->getOpPtrVector();
1691
1694
1695 [&]() {
1696 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1698 return fe_parent;
1699 },
1700
1702
1703
1704
1705 CHKERR add_parent_field_bdy(fe, UDO::OPROW,
"L",
1707 CHKERR add_parent_field_bdy(fe, UDO::OPCOL,
"L",
1710
1712 };
1713
1715 auto level_ents_ptr = boost::make_shared<Range>();
1718
1719 auto get_prj_ents = [&]() {
1724 auto common_ents = intersect(prj_mesh, *level_ents_ptr);
1725 prj_mesh = subtract(unite(*level_ents_ptr, prj_mesh), common_ents)
1727
1728 return prj_mesh;
1729 };
1730
1731 auto prj_ents = get_prj_ents();
1732
1734
1735 auto rebuild = [&]() {
1738
1739 std::vector<std::string> fields{"U", "P", "H", "G", "L"};
1740 std::map<std::string, boost::shared_ptr<Range>> range_maps{
1741
1742 {"U", level_ents_ptr},
1743 {"P", level_ents_ptr},
1744 {"H", level_ents_ptr},
1745 {"G", level_ents_ptr},
1746 {"L", level_ents_ptr}
1747
1748 };
1749
1751 simple->getProblemName(), PETSC_TRUE,
1752 &range_maps, &range_maps);
1753
1754
1755 CHKERR prb_mng->partitionFiniteElements(
"SUB_SOLVER",
true, 0,
1757
1758 CHKERR prb_mng->partitionGhostDofsOnDistributedMesh(
"SUB_SOLVER");
1759
1761 };
1762
1763 MOFEM_LOG(
"FS", Sev::verbose) <<
"Create projection problem";
1764
1766
1767 auto dm =
simple->getDM();
1768 DM subdm;
1770 CHKERR DMSetType(subdm,
"DMMOFEM");
1773 }
1774
1775 MOFEM_LOG(
"FS", Sev::inform) <<
"Nothing to project";
1776
1778 };
1779
1780 auto create_dummy_dm = [&]() {
1783 simple->getProblemName().c_str(),
1785 "create dummy dm");
1786 return dummy_dm;
1787 };
1788
1789 auto subdm = create_subdm();
1790 if (subdm) {
1791
1792 pip_mng->getDomainRhsFE().reset();
1793 pip_mng->getDomainLhsFE().reset();
1794 pip_mng->getBoundaryRhsFE().reset();
1795 pip_mng->getBoundaryLhsFE().reset();
1800 pip_mng->getDomainLhsFE()->exeTestHook = exe_test;
1801 pip_mng->getDomainRhsFE()->exeTestHook = [](
FEMethod *fe_ptr) {
1803 };
1804 pip_mng->getBoundaryLhsFE()->exeTestHook = exe_test;
1805 pip_mng->getBoundaryRhsFE()->exeTestHook = [](
FEMethod *fe_ptr) {
1807 };
1808
1809 CHKERR set_domain_rhs(pip_mng->getCastDomainRhsFE());
1810 CHKERR set_domain_lhs(pip_mng->getCastDomainLhsFE());
1811 CHKERR set_bdy_rhs(pip_mng->getCastBoundaryRhsFE());
1812 CHKERR set_bdy_lhs(pip_mng->getCastBoundaryLhsFE());
1813
1816
1817 auto ksp = pip_mng->createKSP(subdm);
1820
1821
1822 auto get_norm = [&](auto x) {
1823 double nrm;
1824 CHKERR VecNorm(x, NORM_2, &nrm);
1825 return nrm;
1826 };
1827
1828
1829
1830
1831 auto zero_dofs = [](boost::shared_ptr<FieldEntity> ent_ptr) {
1833 for (
auto &
v : ent_ptr->getEntFieldData()) {
1835 }
1837 };
1838
1839 auto solve = [&](
auto S) {
1841 CHKERR VecZeroEntries(S);
1843 CHKERR VecGhostUpdateBegin(
F, INSERT_VALUES, SCATTER_FORWARD);
1844 CHKERR VecGhostUpdateEnd(
F, INSERT_VALUES, SCATTER_FORWARD);
1847 ksp,
"free surface projection");
1848 CHKERR VecGhostUpdateBegin(S, INSERT_VALUES, SCATTER_FORWARD);
1849 CHKERR VecGhostUpdateEnd(S, INSERT_VALUES, SCATTER_FORWARD);
1850
1851
1852
1854 };
1855
1856 MOFEM_LOG(
"FS", Sev::inform) <<
"Solve projection";
1858
1861 auto dummy_dm = create_dummy_dm();
1862
1863
1864
1865
1866 auto apply_restrict = [&]() {
1867 auto get_is = [](
auto v) {
1868 IS iy;
1869 auto create = [&]() {
1873 CHKERR VecGetOwnershipRange(
v, &ystart, NULL);
1874 CHKERR ISCreateStride(PETSC_COMM_SELF,
n, ystart, 1, &iy);
1876 };
1879 };
1880
1881 auto iy = get_is(glob_x);
1883
1885 DMSubDomainRestrict(
simple->getDM(), s, PETSC_NULLPTR, dummy_dm),
1886 "restrict");
1889 "get X0");
1891 DMGetNamedGlobalVector(dummy_dm, "TSTheta_Xdot", &Xdot),
1892 "get Xdot");
1893
1894 auto forward_ghost = [](
auto g) {
1896 CHKERR VecGhostUpdateBegin(
g, INSERT_VALUES, SCATTER_FORWARD);
1897 CHKERR VecGhostUpdateEnd(
g, INSERT_VALUES, SCATTER_FORWARD);
1899 };
1900
1903
1904 if constexpr (
debug) {
1906 << "Reverse restrict: X0 " << get_norm(X0) << " Xdot "
1907 << get_norm(Xdot);
1908 }
1909
1910 return std::vector<Vec>{X0, Xdot};
1911 };
1912
1913 auto ts_solver_vecs = apply_restrict();
1914
1915 if (ts_solver_vecs.size()) {
1916
1917 for (
auto v : ts_solver_vecs) {
1918 MOFEM_LOG(
"FS", Sev::inform) <<
"Solve projection vector";
1919
1921 SCATTER_REVERSE);
1923
1924 for (auto f : {"U", "P", "H", "G", "L"}) {
1925 MOFEM_LOG(
"WORLD", Sev::verbose) <<
"Zero field " <<
f;
1926 CHKERR field_blas->fieldLambdaOnEntities(zero_dofs, f);
1927 }
1928
1930 SCATTER_REVERSE);
1932 SCATTER_FORWARD);
1933
1934 MOFEM_LOG(
"FS", Sev::inform) <<
"Norm V " << get_norm(
v);
1935 }
1936
1937 CHKERR DMRestoreNamedGlobalVector(dummy_dm,
"TSTheta_X0",
1938 &ts_solver_vecs[0]);
1939 CHKERR DMRestoreNamedGlobalVector(dummy_dm,
"TSTheta_Xdot",
1940 &ts_solver_vecs[1]);
1941 }
1942
1943 for (auto f : {"U", "P", "H", "G", "L"}) {
1944 MOFEM_LOG(
"WORLD", Sev::verbose) <<
"Zero field " <<
f;
1945 CHKERR field_blas->fieldLambdaOnEntities(zero_dofs, f);
1946 }
1948 }
1949
1951 };
1952
1953
1954 auto post_proc = [&](auto exe_test) {
1956 auto post_proc_fe = boost::make_shared<PostProcEleDomain>(
mField);
1957 auto &pip = post_proc_fe->getOpPtrVector();
1958 post_proc_fe->exeTestHook = exe_test;
1959
1961
1964
1965 [&]() {
1966 boost::shared_ptr<ForcesAndSourcesCore> fe_parent(
1969 fe_parent->getOpPtrVector(), {H1});
1970 return fe_parent;
1971 },
1972
1974
1976
1977 auto u_ptr = boost::make_shared<MatrixDouble>();
1978 auto p_ptr = boost::make_shared<VectorDouble>();
1979 auto h_ptr = boost::make_shared<VectorDouble>();
1980 auto g_ptr = boost::make_shared<VectorDouble>();
1981
1982 CHKERR add_parent_field_domain(post_proc_fe, UDO::OPCOL,
"U",
1985 CHKERR add_parent_field_domain(post_proc_fe, UDO::OPCOL,
"P",
1988 CHKERR add_parent_field_domain(post_proc_fe, UDO::OPCOL,
"H",
1991 CHKERR add_parent_field_domain(post_proc_fe, UDO::OPCOL,
"G",
1994
1995 post_proc_fe->getOpPtrVector().push_back(
1996
1997 new OpPPMap(post_proc_fe->getPostProcMesh(),
1998 post_proc_fe->getMapGaussPts(),
1999
2000 {{"P", p_ptr}, {"H", h_ptr}, {"G", g_ptr}},
2001
2002 {{"U", u_ptr}},
2003
2004 {},
2005
2006 {}
2007
2008 )
2009
2010 );
2011
2012 auto dm =
simple->getDM();
2014 CHKERR post_proc_fe->writeFile(
"out_projection.h5m");
2015
2017 };
2018
2021 });
2022
2023 if constexpr (
debug) {
2026 });
2027 }
2028
2029 fe_domain_lhs.swap(pip_mng->getDomainLhsFE());
2030 fe_domain_rhs.swap(pip_mng->getDomainRhsFE());
2031 fe_bdy_lhs.swap(pip_mng->getBoundaryLhsFE());
2032 fe_bdy_rhs.swap(pip_mng->getBoundaryRhsFE());
2033
2035}
OpDomainMassH OpDomainMassG
FormsIntegrators< DomainEleOp >::Assembly< A >::LinearForm< I >::OpBaseTimesVector< BASE_DIM, SPACE_DIM, SPACE_DIM > OpDomainAssembleVector
FormsIntegrators< DomainEleOp >::Assembly< A >::BiLinearForm< I >::OpMass< BASE_DIM, 1 > OpDomainMassH
auto get_skin_projection_bit
auto get_global_size
Get global size across all processors.
FormsIntegrators< BoundaryEleOp >::Assembly< A >::BiLinearForm< I >::OpMass< BASE_DIM, 1 > OpBoundaryMassL
FormsIntegrators< BoundaryEleOp >::Assembly< A >::LinearForm< I >::OpBaseTimesScalar< BASE_DIM > OpBoundaryAssembleScalar
FormsIntegrators< DomainEleOp >::Assembly< A >::BiLinearForm< I >::OpMass< BASE_DIM, U_FIELD_DIM > OpDomainMassU
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
MoFEMErrorCode buildSubProblem(const std::string out_name, const std::vector< std::string > &fields_row, const std::vector< std::string > &fields_col, const std::string main_problem, const bool square_matrix=true, const map< std::string, boost::shared_ptr< Range > > *entityMapRow=nullptr, const map< std::string, boost::shared_ptr< Range > > *entityMapCol=nullptr, int verb=VERBOSE)
build sub problem
const double n
refractive index of diffusive medium
const FTensor::Tensor2< T, Dim, Dim > Vec
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
auto createVecScatter(Vec x, IS ix, Vec y, IS iy)
Create a Vec Scatter object.
static PetscErrorCode solve(Mat mat, Vec x, Vec y)
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
Data on single entity (This is passed as argument to DataOperator::doWork)
Operator to execute finite element instance on parent element. This operator is typically used to pro...
Problem manager is used to build and partition problems.