// @HEADER // ***************************************************************************** // Panzer: A partial differential equation assembly // engine for strongly coupled complex multiphysics systems // // Copyright 2011 NTESS and the Panzer contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include #include #include #include using Teuchos::RCP; using Teuchos::rcp; #include "Teuchos_DefaultComm.hpp" #include "Teuchos_GlobalMPISession.hpp" #include "Panzer_STK_Version.hpp" #include "PanzerAdaptersSTK_config.hpp" #include "Panzer_WorksetContainer.hpp" #include "Panzer_IntrepidBasisFactory.hpp" #include "Panzer_DOFManager.hpp" #include "Panzer_STK_Interface.hpp" #include "Panzer_STK_CubeHexMeshFactory.hpp" #include "Panzer_STKConnManager.hpp" #include "Panzer_STK_WorksetFactory.hpp" namespace panzer { TEUCHOS_UNIT_TEST(hdiv_basis, check_dirac) { using Teuchos::RCP; using Teuchos::rcp; typedef Intrepid2::Basis IntrepidBasis; std::string element_block = "eblock-0_0_0"; int basis_order = 4; int workset_size = 10; RCP pl = rcp(new Teuchos::ParameterList); pl->set("X Elements",2); pl->set("Y Elements",2); pl->set("Z Elements",2); panzer_stk::CubeHexMeshFactory factory; factory.setParameterList(pl); RCP mesh = factory.buildMesh(MPI_COMM_WORLD); RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); // build DOF Manager (with a single HDiv basis) ///////////////////////////////////////////////////////////// // build the connection manager const RCP conn_manager = rcp(new panzer_stk::STKConnManager(mesh)); RCP dof_manager = rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD)); // build an intrepid basis and a related field pattern for seeding the DOFManager RCP hdiv_intrepid_basis, hcurl_intrepid_basis; { hdiv_intrepid_basis = panzer::createIntrepid2Basis("HDiv",basis_order, *mesh->getCellTopology(element_block)); hcurl_intrepid_basis = panzer::createIntrepid2Basis("HCurl",basis_order, *mesh->getCellTopology(element_block)); RCP hdiv_field_pattern = rcp(new panzer::Intrepid2FieldPattern(hdiv_intrepid_basis)); RCP hcurl_field_pattern = rcp(new panzer::Intrepid2FieldPattern(hcurl_intrepid_basis)); dof_manager->addField(element_block, "B", hdiv_field_pattern); dof_manager->addField(element_block, "E", hcurl_field_pattern); } dof_manager->buildGlobalUnknowns(); // build WorksetContainer ////////////////////////////////////////////////////////////// BasisDescriptor hdiv_basis_desc(basis_order,"HDiv"); BasisDescriptor hcurl_basis_desc(basis_order,"HCurl"); out << "workset container setup [start]" << std::endl; RCP wkstFactory = rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory RCP wkstContainer // attach it to a workset container (uses lazy evaluation) = rcp(new panzer::WorksetContainer); wkstContainer->setFactory(wkstFactory); { WorksetNeeds needs; needs.addBasis(hdiv_basis_desc); needs.addBasis(hcurl_basis_desc); needs.addPoint(hdiv_basis_desc.getPointDescriptor()); wkstContainer->setNeeds(element_block,needs); } wkstContainer->setGlobalIndexer(dof_manager); wkstContainer->setWorksetSize(workset_size); out << "workset container setup [complete]" << std::endl; // Get worksets /////////////////////////////////////////////////////////////////////// out << "getting worksets [start]" << std::endl; // this must use this descriptor! panzer::WorksetDescriptor workset_descriptor(element_block, panzer::WorksetSizeType::ALL_ELEMENTS, true,true); std::vector & worksets = *wkstContainer->getWorksets(workset_descriptor); out << "getting worksets [complete]" << std::endl; // get BasisValues2 /////////////////////////////////////////////////////////////////////// const PointValues2 & point_values = worksets[0].getPointValues(hdiv_basis_desc.getPointDescriptor()); const BasisValues2 & hdiv_basis_values = worksets[0].getBasisValues(hdiv_basis_desc,hdiv_basis_desc.getPointDescriptor()); const BasisValues2 & hcurl_basis_values = worksets[0].getBasisValues(hcurl_basis_desc,hdiv_basis_desc.getPointDescriptor()); auto hdiv_basis_vector = hdiv_basis_values.getVectorBasisValues(false); auto hcurl_curl_basis = hcurl_basis_values.getCurlVectorBasis(false); // check some sizing stuff /////////////////////////////////////////////////////////////////////// TEST_EQUALITY(Teuchos::as(hdiv_basis_vector.extent(1)),hdiv_intrepid_basis->getCardinality()); TEST_EQUALITY(hdiv_basis_vector.extent(1),hdiv_basis_vector.extent(2)); TEST_EQUALITY(Teuchos::as(hcurl_curl_basis.extent(1)),hcurl_intrepid_basis->getCardinality()); TEST_EQUALITY(hcurl_curl_basis.extent(2),hdiv_basis_vector.extent(2)); TEST_EQUALITY(Teuchos::as(point_values.coords_ref.extent(0)),hdiv_intrepid_basis->getCardinality()); TEST_EQUALITY(point_values.coords_ref.extent(1),3u); TEST_EQUALITY(Teuchos::as(point_values.point_coords.extent(1)),hdiv_intrepid_basis->getCardinality()); TEST_EQUALITY(point_values.point_coords.extent(2),3u); // print out basis values /////////////////////////////////////////////////////////////////////// auto hdiv_basis_vector_view = PHX::as_view(hdiv_basis_vector); auto hdiv_basis_vector_h = Kokkos::create_mirror_view(hdiv_basis_vector_view); Kokkos::deep_copy(hdiv_basis_vector_h, hdiv_basis_vector_view); // print out phi_i(x_j).phi_j(x_j) for(size_t c=0;c IntrepidBasis; std::string element_block = "eblock-0_0_0"; int basis_order = 1; int workset_size = 2; RCP pl = rcp(new Teuchos::ParameterList); pl->set("X Elements",2); pl->set("Y Elements",1); pl->set("Z Elements",1); panzer_stk::CubeHexMeshFactory factory; factory.setParameterList(pl); RCP mesh = factory.buildMesh(MPI_COMM_WORLD); RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); // build DOF Manager (with a single HDiv basis) ///////////////////////////////////////////////////////////// // build the connection manager const RCP conn_manager = rcp(new panzer_stk::STKConnManager(mesh)); RCP dof_manager = rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD)); // build an intrepid basis and a related field pattern for seeding the DOFManager RCP hdiv_intrepid_basis, hcurl_intrepid_basis; { hdiv_intrepid_basis = panzer::createIntrepid2Basis("HDiv",basis_order, *mesh->getCellTopology(element_block)); hcurl_intrepid_basis = panzer::createIntrepid2Basis("HCurl",basis_order, *mesh->getCellTopology(element_block)); RCP hdiv_field_pattern = rcp(new panzer::Intrepid2FieldPattern(hdiv_intrepid_basis)); RCP hcurl_field_pattern = rcp(new panzer::Intrepid2FieldPattern(hcurl_intrepid_basis)); dof_manager->addField(element_block, "B", hdiv_field_pattern); dof_manager->addField(element_block, "E", hcurl_field_pattern); } dof_manager->buildGlobalUnknowns(); // build WorksetContainer ////////////////////////////////////////////////////////////// BasisDescriptor hdiv_basis_desc(basis_order,"HDiv"); BasisDescriptor hcurl_basis_desc(basis_order,"HCurl"); IntegrationDescriptor quad_desc(2,IntegrationDescriptor::VOLUME); out << "workset container setup [start]" << std::endl; RCP wkstFactory = rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory RCP wkstContainer // attach it to a workset container (uses lazy evaluation) = rcp(new panzer::WorksetContainer); wkstContainer->setFactory(wkstFactory); { WorksetNeeds needs; needs.bases.push_back(Teuchos::rcp(new panzer::PureBasis(hdiv_basis_desc,mesh->getCellTopology(element_block),workset_size))); needs.bases.push_back(Teuchos::rcp(new panzer::PureBasis(hcurl_basis_desc,mesh->getCellTopology(element_block),workset_size))); needs.rep_field_name.push_back("B"); needs.rep_field_name.push_back("E"); needs.int_rules.push_back(Teuchos::rcp(new panzer::IntegrationRule(quad_desc,mesh->getCellTopology(element_block),workset_size))); needs.cellData = CellData(workset_size,mesh->getCellTopology(element_block)); wkstContainer->setNeeds(element_block,needs); } wkstContainer->setGlobalIndexer(dof_manager); wkstContainer->setWorksetSize(workset_size); out << "workset container setup [complete]" << std::endl; // Get worksets /////////////////////////////////////////////////////////////////////// out << "getting worksets [start]" << std::endl; // this must use this descriptor! // panzer::WorksetDescriptor workset_descriptor(element_block, panzer::WorksetSizeType::ALL_ELEMENTS, true,true); panzer::WorksetDescriptor workset_descriptor(element_block); std::vector & worksets = *wkstContainer->getWorksets(workset_descriptor); out << "getting worksets [complete]" << std::endl; // get BasisValues2 /////////////////////////////////////////////////////////////////////// out << worksets[0].bases.size() << std::endl; const BasisValues2 & hdiv_basis_values = *worksets[0].bases[0]; out << (*worksets[0].basis_names)[0] << " " << (*worksets[0].basis_names)[1] << std::endl; auto hdiv_weighted_basis_vector = hdiv_basis_values.weighted_basis_vector; auto hdiv_weighted_basis_vector_view = PHX::as_view(hdiv_weighted_basis_vector); auto hdiv_weighted_basis_vector_h = Kokkos::create_mirror_view(hdiv_weighted_basis_vector_view); Kokkos::deep_copy(hdiv_weighted_basis_vector_h, hdiv_weighted_basis_vector_view); auto hdiv_basis_vector = hdiv_basis_values.basis_vector; auto hdiv_basis_vector_view = PHX::as_view(hdiv_basis_vector); auto hdiv_basis_vector_h = Kokkos::create_mirror_view(hdiv_basis_vector_view); Kokkos::deep_copy(hdiv_basis_vector_h, hdiv_basis_vector_view); // check some sizing stuff /////////////////////////////////////////////////////////////////////// TEST_EQUALITY(worksets[0].num_cells,2); TEST_EQUALITY(Teuchos::as(hdiv_weighted_basis_vector.extent(0)),2); TEST_EQUALITY(Teuchos::as(hdiv_weighted_basis_vector.extent(1)),6); TEST_EQUALITY(Teuchos::as(hdiv_weighted_basis_vector.extent(2)),8); TEST_EQUALITY(Teuchos::as(hdiv_weighted_basis_vector.extent(3)),3); // print out basis values /////////////////////////////////////////////////////////////////////// out << "BASIS VECTOR\n" << std::endl; for(size_t c=0;c<2;c++) { out << "cell " << c << " = "; std::vector gids; dof_manager->getElementGIDs(c,gids); out << " gids = "; for(auto g : gids) out << g << " "; out << std::endl; for(size_t b=0;b