// @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 #include #include #include "Panzer_Traits.hpp" #include "Panzer_BC.hpp" #include "Panzer_BCStrategy.hpp" #include "user_app_BCStrategy_Factory.hpp" #include #include "PanzerAdaptersSTK_config.hpp" #include "Panzer_STK_Interface.hpp" #include "Panzer_STK_SquareQuadMeshFactory.hpp" #include "Panzer_STK_SetupUtilities.hpp" #include "Panzer_STK_WorksetFactory.hpp" #include "Panzer_Workset_Builder.hpp" #include "Panzer_WorksetContainer.hpp" #include "Panzer_FieldManagerBuilder.hpp" #include "Panzer_STKConnManager.hpp" #include "Panzer_BlockedEpetraLinearObjFactory.hpp" #include "Panzer_AssemblyEngine.hpp" #include "Panzer_AssemblyEngine_InArgs.hpp" #include "Panzer_AssemblyEngine_TemplateManager.hpp" #include "Panzer_AssemblyEngine_TemplateBuilder.hpp" #include "Panzer_DOFManagerFactory.hpp" #include "Panzer_GlobalData.hpp" #include "user_app_EquationSetFactory.hpp" #include "user_app_ClosureModel_Factory_TemplateBuilder.hpp" #include "Epetra_MpiComm.h" namespace panzer { void testInitialzation(const Teuchos::RCP& ipb, std::vector& bcs); TEUCHOS_UNIT_TEST(bcstrategy, basic_construction) { std::size_t bc_id = 0; panzer::BCType dirichlet = BCT_Dirichlet; std::string sideset_id = "4"; std::string element_block_id = "fluid"; std::string dof_name = "UX"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, strategy, p); Teuchos::RCP > bcs; Teuchos::RCP gd = panzer::createGlobalData(); user_app::BCFactory my_factory; bcs = my_factory.buildBCStrategy(bc,gd); } TEUCHOS_UNIT_TEST(bcstrategy, constant_bc_strategy) { using std::cout; using std::endl; using Teuchos::RCP; // pause_to_attach(); RCP pl = rcp(new Teuchos::ParameterList); pl->set("X Blocks",1); pl->set("Y Blocks",1); pl->set("X Elements",1); pl->set("Y Elements",1); panzer_stk::SquareQuadMeshFactory factory; factory.setParameterList(pl); RCP mesh = factory.buildMesh(MPI_COMM_WORLD); RCP Comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); Teuchos::RCP ipb = Teuchos::parameterList("Physics Blocks"); std::vector bcs; testInitialzation(ipb, bcs); Teuchos::RCP fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); // build physics blocks ////////////////////////////////////////////////////////////// const std::size_t workset_size = 1; Teuchos::RCP eqset_factory = Teuchos::rcp(new user_app::MyFactory); user_app::BCFactory bc_factory; std::vector > physicsBlocks; { std::map block_ids_to_physics_ids; block_ids_to_physics_ids["eblock-0_0"] = "test physics"; std::map > block_ids_to_cell_topo; block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); Teuchos::RCP gd = panzer::createGlobalData(); const int default_integration_order = 1; panzer::buildPhysicsBlocks(block_ids_to_physics_ids, block_ids_to_cell_topo, ipb, default_integration_order, workset_size, eqset_factory, gd, false, physicsBlocks); } // build worksets ////////////////////////////////////////////////////////////// Teuchos::RCP wkstFactory = Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory Teuchos::RCP wkstContainer // attach it to a workset container (uses lazy evaluation) = Teuchos::rcp(new panzer::WorksetContainer); wkstContainer->setFactory(wkstFactory); for(size_t i=0;isetNeeds(physicsBlocks[i]->elementBlockID(),physicsBlocks[i]->getWorksetNeeds()); wkstContainer->setWorksetSize(workset_size); // build DOF Manager ///////////////////////////////////////////////////////////// // build the connection manager const Teuchos::RCP conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); panzer::DOFManagerFactory globalIndexerFactory; RCP dofManager = globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),physicsBlocks,conn_manager); Teuchos::RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); Teuchos::RCP > eLinObjFactory = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory(tComm.getConst(),dofManager)); Teuchos::RCP > linObjFactory = eLinObjFactory; // setup field manager build ///////////////////////////////////////////////////////////// // Add in the application specific closure model factory panzer::ClosureModelFactory_TemplateManager cm_factory; user_app::MyModelFactory_TemplateBuilder cm_builder; cm_factory.buildObjects(cm_builder); Teuchos::ParameterList closure_models("Closure Models"); closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set("Value",1.0); closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE").set("Value",1.0); Teuchos::ParameterList user_data("User Data"); fmb->setWorksetContainer(wkstContainer); fmb->setupVolumeFieldManagers(physicsBlocks,cm_factory,closure_models,*linObjFactory,user_data); fmb->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory,user_data); panzer::AssemblyEngine_TemplateManager ae_tm; panzer::AssemblyEngine_TemplateBuilder builder(fmb,linObjFactory); ae_tm.buildObjects(builder); RCP eGhosted = Teuchos::rcp_dynamic_cast(linObjFactory->buildGhostedLinearObjContainer()); RCP eGlobal = Teuchos::rcp_dynamic_cast(linObjFactory->buildLinearObjContainer()); eLinObjFactory->initializeGhostedContainer(panzer::EpetraLinearObjContainer::X | panzer::EpetraLinearObjContainer::DxDt | panzer::EpetraLinearObjContainer::F | panzer::EpetraLinearObjContainer::Mat,*eGhosted); eLinObjFactory->initializeContainer(panzer::EpetraLinearObjContainer::X | panzer::EpetraLinearObjContainer::DxDt | panzer::EpetraLinearObjContainer::F | panzer::EpetraLinearObjContainer::Mat,*eGlobal); panzer::AssemblyEngineInArgs input(eGhosted,eGlobal); RCP x = Teuchos::rcp_dynamic_cast(input.container_)->get_x(); x->PutScalar(1.0); input.beta = 1.0; ae_tm.getAsObject()->evaluate(input); ae_tm.getAsObject()->evaluate(input); // Check residual values. Evaluation should have put (x - 5.0) // into each residual. With initial guess of 1.0, check to make // sure each entry in residual has -4.0. Note that we are using // one element with same dirichlet bc on each side, so all nodes // have same dirichlet bc applied to it. RCP f = Teuchos::rcp_dynamic_cast(input.container_)->get_f(); double tol = 10.0*std::numeric_limits::epsilon(); for (int i=0; i < f->MyLength(); ++i) { TEST_FLOATING_EQUALITY((*f)[i], -4.0, tol ); } // Check Jacobian values. Should have one on diagonal and zero // elsewhere. RCP jac = Teuchos::rcp_dynamic_cast(input.container_)->get_A(); for (int i=0; i < jac->NumMyRows(); ++i) { int num_indices = -1; double* values = NULL; int* local_column_indices = NULL; jac->ExtractMyRowView(i, num_indices, values, local_column_indices); for (int j=0; j < num_indices; j++) { std::cout << "J(" <GRID(i) << "," << jac->GCID(local_column_indices[j]) << ") = " << values[j] << std::endl; if (jac->GRID(i) == jac->GCID(local_column_indices[j])) { TEST_FLOATING_EQUALITY(values[j], 1.0, tol); } else { TEST_FLOATING_EQUALITY(values[j], 0.0, tol); } } } jac->Print(std::cout); } void testInitialzation(const Teuchos::RCP& ipb, std::vector& bcs) { // Physics block Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); { Teuchos::ParameterList& p = physics_block.sublist("a"); p.set("Type","Energy"); p.set("Prefix",""); p.set("Model ID","solid"); p.set("Basis Type","HGrad"); p.set("Basis Order",1); } { std::size_t bc_id = 0; panzer::BCType dirichlet = BCT_Dirichlet; std::string sideset_id = "left"; std::string element_block_id = "eblock-0_0"; std::string dof_name = "TEMPERATURE"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, strategy, p); bcs.push_back(bc); } { std::size_t bc_id = 1; panzer::BCType dirichlet = BCT_Dirichlet; std::string sideset_id = "right"; std::string element_block_id = "eblock-0_0"; std::string dof_name = "TEMPERATURE"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, strategy, p); bcs.push_back(bc); } { std::size_t bc_id = 2; panzer::BCType dirichlet = BCT_Dirichlet; std::string sideset_id = "top"; std::string element_block_id = "eblock-0_0"; std::string dof_name = "TEMPERATURE"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, strategy, p); bcs.push_back(bc); } { std::size_t bc_id = 3; panzer::BCType dirichlet = BCT_Dirichlet; std::string sideset_id = "bottom"; std::string element_block_id = "eblock-0_0"; std::string dof_name = "TEMPERATURE"; std::string strategy = "Constant"; double value = 5.0; Teuchos::ParameterList p; p.set("Value",value); panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, strategy, p); bcs.push_back(bc); } } }