| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Panzer: A partial differential equation assembly |
| 4 |
// engine for strongly coupled complex multiphysics systems |
| 5 |
// |
| 6 |
// Copyright 2011 NTESS and the Panzer contributors. |
| 7 |
// SPDX-License-Identifier: BSD-3-Clause |
| 8 |
// ***************************************************************************** |
| 9 |
// @HEADER |
| 10 |
|
| 11 |
#include <Teuchos_ConfigDefs.hpp> |
| 12 |
#include <Teuchos_UnitTestHarness.hpp> |
| 13 |
#include <Teuchos_RCP.hpp> |
| 14 |
#include <Teuchos_TimeMonitor.hpp> |
| 15 |
#include <Teuchos_ParameterList.hpp> |
| 16 |
#include <Teuchos_Assert.hpp> |
| 17 |
|
| 18 |
#include "Panzer_Traits.hpp" |
| 19 |
#include "Panzer_BC.hpp" |
| 20 |
#include "Panzer_BCStrategy.hpp" |
| 21 |
#include "user_app_BCStrategy_Factory.hpp" |
| 22 |
#include <iostream> |
| 23 |
|
| 24 |
#include "PanzerAdaptersSTK_config.hpp" |
| 25 |
#include "Panzer_STK_Interface.hpp" |
| 26 |
#include "Panzer_STK_SquareQuadMeshFactory.hpp" |
| 27 |
#include "Panzer_STK_SetupUtilities.hpp" |
| 28 |
#include "Panzer_STK_WorksetFactory.hpp" |
| 29 |
#include "Panzer_Workset_Builder.hpp" |
| 30 |
#include "Panzer_WorksetContainer.hpp" |
| 31 |
#include "Panzer_FieldManagerBuilder.hpp" |
| 32 |
#include "Panzer_STKConnManager.hpp" |
| 33 |
#include "Panzer_BlockedEpetraLinearObjFactory.hpp" |
| 34 |
#include "Panzer_AssemblyEngine.hpp" |
| 35 |
#include "Panzer_AssemblyEngine_InArgs.hpp" |
| 36 |
#include "Panzer_AssemblyEngine_TemplateManager.hpp" |
| 37 |
#include "Panzer_AssemblyEngine_TemplateBuilder.hpp" |
| 38 |
#include "Panzer_DOFManagerFactory.hpp" |
| 39 |
#include "Panzer_GlobalData.hpp" |
| 40 |
#include "user_app_EquationSetFactory.hpp" |
| 41 |
#include "user_app_ClosureModel_Factory_TemplateBuilder.hpp" |
| 42 |
|
| 43 |
#include "Epetra_MpiComm.h" |
| 44 |
|
| 45 |
namespace panzer { |
| 46 |
|
| 47 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 48 |
std::vector<panzer::BC>& bcs); |
| 49 |
|
| 50 |
TEUCHOS_UNIT_TEST(bcstrategy, basic_construction) |
| 51 |
{ |
| 52 |
|
| 53 |
std::size_t bc_id = 0; |
| 54 |
panzer::BCType dirichlet = BCT_Dirichlet; |
| 55 |
std::string sideset_id = "4"; |
| 56 |
std::string element_block_id = "fluid"; |
| 57 |
std::string dof_name = "UX"; |
| 58 |
std::string strategy = "Constant"; |
| 59 |
double value = 5.0; |
| 60 |
Teuchos::ParameterList p; |
| 61 |
p.set("Value",value); |
| 62 |
panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, |
| 63 |
strategy, p); |
| 64 |
|
| 65 |
Teuchos::RCP<panzer::BCStrategy_TemplateManager<panzer::Traits> > bcs; |
| 66 |
|
| 67 |
Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData(); |
| 68 |
|
| 69 |
user_app::BCFactory my_factory; |
| 70 |
bcs = my_factory.buildBCStrategy(bc,gd); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
TEUCHOS_UNIT_TEST(bcstrategy, constant_bc_strategy) |
| 75 |
{ |
| 76 |
|
| 77 |
using std::cout; |
| 78 |
using std::endl; |
| 79 |
using Teuchos::RCP; |
| 80 |
|
| 81 |
// pause_to_attach(); |
| 82 |
|
| 83 |
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); |
| 84 |
pl->set("X Blocks",1); |
| 85 |
pl->set("Y Blocks",1); |
| 86 |
pl->set("X Elements",1); |
| 87 |
pl->set("Y Elements",1); |
| 88 |
|
| 89 |
panzer_stk::SquareQuadMeshFactory factory; |
| 90 |
factory.setParameterList(pl); |
| 91 |
RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD); |
| 92 |
RCP<Epetra_Comm> Comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); |
| 93 |
|
| 94 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks"); |
| 95 |
std::vector<panzer::BC> bcs; |
| 96 |
testInitialzation(ipb, bcs); |
| 97 |
|
| 98 |
Teuchos::RCP<panzer::FieldManagerBuilder> fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); |
| 99 |
|
| 100 |
// build physics blocks |
| 101 |
////////////////////////////////////////////////////////////// |
| 102 |
const std::size_t workset_size = 1; |
| 103 |
Teuchos::RCP<user_app::MyFactory> eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 104 |
user_app::BCFactory bc_factory; |
| 105 |
std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; |
| 106 |
{ |
| 107 |
std::map<std::string,std::string> block_ids_to_physics_ids; |
| 108 |
block_ids_to_physics_ids["eblock-0_0"] = "test physics"; |
| 109 |
|
| 110 |
std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo; |
| 111 |
block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); |
| 112 |
|
| 113 |
Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData(); |
| 114 |
|
| 115 |
const int default_integration_order = 1; |
| 116 |
|
| 117 |
panzer::buildPhysicsBlocks(block_ids_to_physics_ids, |
| 118 |
block_ids_to_cell_topo, |
| 119 |
ipb, |
| 120 |
default_integration_order, |
| 121 |
workset_size, |
| 122 |
eqset_factory, |
| 123 |
gd, |
| 124 |
false, |
| 125 |
physicsBlocks); |
| 126 |
} |
| 127 |
|
| 128 |
// build worksets |
| 129 |
////////////////////////////////////////////////////////////// |
| 130 |
Teuchos::RCP<panzer_stk::WorksetFactory> wkstFactory |
| 131 |
= Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory |
| 132 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation) |
| 133 |
= Teuchos::rcp(new panzer::WorksetContainer); |
| 134 |
wkstContainer->setFactory(wkstFactory); |
| 135 |
for(size_t i=0;i<physicsBlocks.size();i++) |
| 136 |
wkstContainer->setNeeds(physicsBlocks[i]->elementBlockID(),physicsBlocks[i]->getWorksetNeeds()); |
| 137 |
wkstContainer->setWorksetSize(workset_size); |
| 138 |
|
| 139 |
// build DOF Manager |
| 140 |
///////////////////////////////////////////////////////////// |
| 141 |
|
| 142 |
// build the connection manager |
| 143 |
const Teuchos::RCP<panzer::ConnManager> |
| 144 |
conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 145 |
|
| 146 |
panzer::DOFManagerFactory globalIndexerFactory; |
| 147 |
RCP<panzer::GlobalIndexer> dofManager |
| 148 |
= globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),physicsBlocks,conn_manager); |
| 149 |
|
| 150 |
Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 151 |
Teuchos::RCP<panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int> > eLinObjFactory |
| 152 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm.getConst(),dofManager)); |
| 153 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory = eLinObjFactory; |
| 154 |
|
| 155 |
// setup field manager build |
| 156 |
///////////////////////////////////////////////////////////// |
| 157 |
|
| 158 |
// Add in the application specific closure model factory |
| 159 |
panzer::ClosureModelFactory_TemplateManager<panzer::Traits> cm_factory; |
| 160 |
user_app::MyModelFactory_TemplateBuilder cm_builder; |
| 161 |
cm_factory.buildObjects(cm_builder); |
| 162 |
|
| 163 |
Teuchos::ParameterList closure_models("Closure Models"); |
| 164 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<double>("Value",1.0); |
| 165 |
closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE").set<double>("Value",1.0); |
| 166 |
|
| 167 |
Teuchos::ParameterList user_data("User Data"); |
| 168 |
|
| 169 |
fmb->setWorksetContainer(wkstContainer); |
| 170 |
fmb->setupVolumeFieldManagers(physicsBlocks,cm_factory,closure_models,*linObjFactory,user_data); |
| 171 |
fmb->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory,user_data); |
| 172 |
|
| 173 |
panzer::AssemblyEngine_TemplateManager<panzer::Traits> ae_tm; |
| 174 |
panzer::AssemblyEngine_TemplateBuilder builder(fmb,linObjFactory); |
| 175 |
ae_tm.buildObjects(builder); |
| 176 |
|
| 177 |
RCP<panzer::EpetraLinearObjContainer> eGhosted |
| 178 |
= Teuchos::rcp_dynamic_cast<panzer::EpetraLinearObjContainer>(linObjFactory->buildGhostedLinearObjContainer()); |
| 179 |
RCP<panzer::EpetraLinearObjContainer> eGlobal |
| 180 |
= Teuchos::rcp_dynamic_cast<panzer::EpetraLinearObjContainer>(linObjFactory->buildLinearObjContainer()); |
| 181 |
eLinObjFactory->initializeGhostedContainer(panzer::EpetraLinearObjContainer::X | |
| 182 |
panzer::EpetraLinearObjContainer::DxDt | |
| 183 |
panzer::EpetraLinearObjContainer::F | |
| 184 |
panzer::EpetraLinearObjContainer::Mat,*eGhosted); |
| 185 |
eLinObjFactory->initializeContainer(panzer::EpetraLinearObjContainer::X | |
| 186 |
panzer::EpetraLinearObjContainer::DxDt | |
| 187 |
panzer::EpetraLinearObjContainer::F | |
| 188 |
panzer::EpetraLinearObjContainer::Mat,*eGlobal); |
| 189 |
panzer::AssemblyEngineInArgs input(eGhosted,eGlobal); |
| 190 |
|
| 191 |
RCP<Epetra_Vector> x = Teuchos::rcp_dynamic_cast<panzer::EpetraLinearObjContainer>(input.container_)->get_x(); |
| 192 |
|
| 193 |
x->PutScalar(1.0); |
| 194 |
input.beta = 1.0; |
| 195 |
|
| 196 |
ae_tm.getAsObject<panzer::Traits::Residual>()->evaluate(input); |
| 197 |
ae_tm.getAsObject<panzer::Traits::Jacobian>()->evaluate(input); |
| 198 |
|
| 199 |
// Check residual values. Evaluation should have put (x - 5.0) |
| 200 |
// into each residual. With initial guess of 1.0, check to make |
| 201 |
// sure each entry in residual has -4.0. Note that we are using |
| 202 |
// one element with same dirichlet bc on each side, so all nodes |
| 203 |
// have same dirichlet bc applied to it. |
| 204 |
|
| 205 |
RCP<Epetra_Vector> f = Teuchos::rcp_dynamic_cast<panzer::EpetraLinearObjContainer>(input.container_)->get_f(); |
| 206 |
double tol = 10.0*std::numeric_limits<double>::epsilon(); |
| 207 |
for (int i=0; i < f->MyLength(); ++i) { |
| 208 |
TEST_FLOATING_EQUALITY((*f)[i], -4.0, tol ); |
| 209 |
} |
| 210 |
|
| 211 |
// Check Jacobian values. Should have one on diagonal and zero |
| 212 |
// elsewhere. |
| 213 |
RCP<Epetra_CrsMatrix> jac = Teuchos::rcp_dynamic_cast<panzer::EpetraLinearObjContainer>(input.container_)->get_A(); |
| 214 |
for (int i=0; i < jac->NumMyRows(); ++i) { |
| 215 |
int num_indices = -1; |
| 216 |
double* values = NULL; |
| 217 |
int* local_column_indices = NULL; |
| 218 |
jac->ExtractMyRowView(i, num_indices, values, local_column_indices); |
| 219 |
for (int j=0; j < num_indices; j++) { |
| 220 |
std::cout << "J(" <<jac->GRID(i) << "," << jac->GCID(local_column_indices[j]) << ") = " << values[j] << std::endl; |
| 221 |
if (jac->GRID(i) == jac->GCID(local_column_indices[j])) { |
| 222 |
TEST_FLOATING_EQUALITY(values[j], 1.0, tol); |
| 223 |
} |
| 224 |
else { |
| 225 |
TEST_FLOATING_EQUALITY(values[j], 0.0, tol); |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
jac->Print(std::cout); |
| 231 |
|
| 232 |
} |
| 233 |
|
| 234 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 235 |
std::vector<panzer::BC>& bcs) |
| 236 |
{ |
| 237 |
// Physics block |
| 238 |
Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); |
| 239 |
{ |
| 240 |
Teuchos::ParameterList& p = physics_block.sublist("a"); |
| 241 |
p.set("Type","Energy"); |
| 242 |
p.set("Prefix",""); |
| 243 |
p.set("Model ID","solid"); |
| 244 |
p.set("Basis Type","HGrad"); |
| 245 |
p.set("Basis Order",1); |
| 246 |
} |
| 247 |
|
| 248 |
{ |
| 249 |
std::size_t bc_id = 0; |
| 250 |
panzer::BCType dirichlet = BCT_Dirichlet; |
| 251 |
std::string sideset_id = "left"; |
| 252 |
std::string element_block_id = "eblock-0_0"; |
| 253 |
std::string dof_name = "TEMPERATURE"; |
| 254 |
std::string strategy = "Constant"; |
| 255 |
double value = 5.0; |
| 256 |
Teuchos::ParameterList p; |
| 257 |
p.set("Value",value); |
| 258 |
panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, |
| 259 |
strategy, p); |
| 260 |
bcs.push_back(bc); |
| 261 |
} |
| 262 |
{ |
| 263 |
std::size_t bc_id = 1; |
| 264 |
panzer::BCType dirichlet = BCT_Dirichlet; |
| 265 |
std::string sideset_id = "right"; |
| 266 |
std::string element_block_id = "eblock-0_0"; |
| 267 |
std::string dof_name = "TEMPERATURE"; |
| 268 |
std::string strategy = "Constant"; |
| 269 |
double value = 5.0; |
| 270 |
Teuchos::ParameterList p; |
| 271 |
p.set("Value",value); |
| 272 |
panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, |
| 273 |
strategy, p); |
| 274 |
bcs.push_back(bc); |
| 275 |
} |
| 276 |
{ |
| 277 |
std::size_t bc_id = 2; |
| 278 |
panzer::BCType dirichlet = BCT_Dirichlet; |
| 279 |
std::string sideset_id = "top"; |
| 280 |
std::string element_block_id = "eblock-0_0"; |
| 281 |
std::string dof_name = "TEMPERATURE"; |
| 282 |
std::string strategy = "Constant"; |
| 283 |
double value = 5.0; |
| 284 |
Teuchos::ParameterList p; |
| 285 |
p.set("Value",value); |
| 286 |
panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, |
| 287 |
strategy, p); |
| 288 |
bcs.push_back(bc); |
| 289 |
} |
| 290 |
{ |
| 291 |
std::size_t bc_id = 3; |
| 292 |
panzer::BCType dirichlet = BCT_Dirichlet; |
| 293 |
std::string sideset_id = "bottom"; |
| 294 |
std::string element_block_id = "eblock-0_0"; |
| 295 |
std::string dof_name = "TEMPERATURE"; |
| 296 |
std::string strategy = "Constant"; |
| 297 |
double value = 5.0; |
| 298 |
Teuchos::ParameterList p; |
| 299 |
p.set("Value",value); |
| 300 |
panzer::BC bc(bc_id, dirichlet, sideset_id, element_block_id, dof_name, |
| 301 |
strategy, p); |
| 302 |
bcs.push_back(bc); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
} |