| 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 |
|
| 16 |
using Teuchos::RCP; |
| 17 |
using Teuchos::rcp; |
| 18 |
|
| 19 |
#include "Panzer_NodeType.hpp" |
| 20 |
#include "Teuchos_DefaultComm.hpp" |
| 21 |
#include "Teuchos_GlobalMPISession.hpp" |
| 22 |
#include "Panzer_STK_Version.hpp" |
| 23 |
#include "PanzerAdaptersSTK_config.hpp" |
| 24 |
#include "Panzer_STK_Interface.hpp" |
| 25 |
#include "Panzer_STK_SquareQuadMeshFactory.hpp" |
| 26 |
#include "Panzer_STK_SetupUtilities.hpp" |
| 27 |
#include "Panzer_STK_WorksetFactory.hpp" |
| 28 |
#include "Panzer_Workset_Builder.hpp" |
| 29 |
#include "Panzer_FieldManagerBuilder.hpp" |
| 30 |
#include "Panzer_STKConnManager.hpp" |
| 31 |
#include "Panzer_TpetraLinearObjFactory.hpp" |
| 32 |
#include "Panzer_BlockedEpetraLinearObjFactory.hpp" |
| 33 |
#include "Panzer_AssemblyEngine.hpp" |
| 34 |
#include "Panzer_AssemblyEngine_TemplateManager.hpp" |
| 35 |
#include "Panzer_AssemblyEngine_TemplateBuilder.hpp" |
| 36 |
#include "Panzer_DOFManagerFactory.hpp" |
| 37 |
#include "Panzer_ModelEvaluator.hpp" |
| 38 |
#include "Panzer_ResponseLibrary.hpp" |
| 39 |
#include "Panzer_GlobalData.hpp" |
| 40 |
#include "Panzer_WorksetContainer.hpp" |
| 41 |
#include "Panzer_PauseToAttach.hpp" |
| 42 |
#include "Panzer_ExplicitModelEvaluator.hpp" |
| 43 |
|
| 44 |
#include "Stratimikos_DefaultLinearSolverBuilder.hpp" |
| 45 |
|
| 46 |
#include "user_app_EquationSetFactory.hpp" |
| 47 |
#include "user_app_ClosureModel_Factory_TemplateBuilder.hpp" |
| 48 |
#include "user_app_BCStrategy_Factory.hpp" |
| 49 |
|
| 50 |
#include "Epetra_MpiComm.h" |
| 51 |
|
| 52 |
#include "Teuchos_DefaultMpiComm.hpp" |
| 53 |
#include "Teuchos_OpaqueWrapper.hpp" |
| 54 |
|
| 55 |
#include <cstdio> // for get char |
| 56 |
#include <fstream> |
| 57 |
|
| 58 |
namespace panzer { |
| 59 |
|
| 60 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 61 |
std::vector<panzer::BC>& bcs); |
| 62 |
|
| 63 |
void buildAssemblyPieces(bool parameter_on, |
| 64 |
Teuchos::RCP<panzer::FieldManagerBuilder> & fmb, |
| 65 |
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > & rLibrary, |
| 66 |
Teuchos::RCP<panzer::GlobalData> & gd, |
| 67 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > & lof); |
| 68 |
|
| 69 |
TEUCHOS_UNIT_TEST(explicit_model_evaluator, basic) |
| 70 |
{ |
| 71 |
using Teuchos::RCP; |
| 72 |
|
| 73 |
|
| 74 |
bool parameter_on = true; |
| 75 |
Teuchos::RCP<panzer::FieldManagerBuilder> fmb; |
| 76 |
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > rLibrary; |
| 77 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > lof; |
| 78 |
Teuchos::RCP<panzer::GlobalData> gd; |
| 79 |
|
| 80 |
buildAssemblyPieces(parameter_on,fmb,rLibrary,gd,lof); |
| 81 |
|
| 82 |
// Test a transient me |
| 83 |
{ |
| 84 |
typedef Thyra::ModelEvaluatorBase MEB; |
| 85 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 86 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 87 |
typedef Thyra::VectorBase<double> VectorType; |
| 88 |
typedef Thyra::LinearOpBase<double> OperatorType; |
| 89 |
typedef panzer::ModelEvaluator<double> PME; |
| 90 |
typedef panzer::ExplicitModelEvaluator<double> ExpPME; |
| 91 |
|
| 92 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 93 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 94 |
bool build_transient_support = true; |
| 95 |
|
| 96 |
Stratimikos::DefaultLinearSolverBuilder builder; |
| 97 |
Teuchos::RCP<Teuchos::ParameterList> validList = Teuchos::rcp(new Teuchos::ParameterList(*builder.getValidParameters())); |
| 98 |
builder.setParameterList(validList); |
| 99 |
RCP<const Thyra::LinearOpWithSolveFactoryBase<double> > lowsFactory = builder.createLinearSolveStrategy("Amesos"); |
| 100 |
|
| 101 |
RCP<PME> me = Teuchos::rcp(new PME(fmb,rLibrary,lof,p_names,p_values,lowsFactory,gd,build_transient_support,0.0)); |
| 102 |
RCP<ExpPME> exp_me = Teuchos::rcp(new ExpPME(me,true,false)); // constant mass, use lumped |
| 103 |
|
| 104 |
RCP<VectorType> exp_f, f; |
| 105 |
|
| 106 |
// explicit evaluation |
| 107 |
{ |
| 108 |
// set the nominal values |
| 109 |
InArgs nom_vals = exp_me->getNominalValues(); |
| 110 |
TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_x)); |
| 111 |
TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_x_dot)); // this is supported for stabilization purposes |
| 112 |
TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_alpha)); // alpha and beta support needed for outputting responses |
| 113 |
TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_beta)); |
| 114 |
|
| 115 |
// create in args |
| 116 |
InArgs in_args = exp_me->createInArgs(); |
| 117 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_x)); |
| 118 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_x_dot)); // this is supported for stabilization purposes |
| 119 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_alpha)); // alpha and beta support needed for outputting responses |
| 120 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_beta)); |
| 121 |
InArgs nomValues = exp_me->getNominalValues(); |
| 122 |
RCP<VectorType> x = Thyra::createMember(*exp_me->get_x_space()); |
| 123 |
RCP<VectorType> x_dot = Thyra::createMember(*exp_me->get_x_space()); |
| 124 |
Thyra::assign(x_dot.ptr(),0.0); |
| 125 |
Thyra::assign(x.ptr(),5.0); |
| 126 |
in_args.set_x(x); |
| 127 |
in_args.set_x_dot(x_dot); |
| 128 |
|
| 129 |
// create out args |
| 130 |
OutArgs out_args = exp_me->createOutArgs(); |
| 131 |
TEST_ASSERT(out_args.supports(MEB::OUT_ARG_f)); |
| 132 |
TEST_ASSERT(!out_args.supports(MEB::OUT_ARG_W_op)); |
| 133 |
TEST_ASSERT(!out_args.supports(MEB::OUT_ARG_W)); |
| 134 |
exp_f = Thyra::createMember(*exp_me->get_f_space()); |
| 135 |
out_args.set_f(exp_f); |
| 136 |
|
| 137 |
exp_me->evalModel(in_args, out_args); |
| 138 |
} |
| 139 |
|
| 140 |
// implicit evaluation |
| 141 |
RCP<OperatorType> mass = me->create_W_op(); |
| 142 |
{ |
| 143 |
// create in args |
| 144 |
InArgs in_args = me->createInArgs(); |
| 145 |
InArgs nomValues = me->getNominalValues(); |
| 146 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 147 |
RCP<VectorType> x_dot = Thyra::createMember(*me->get_x_space()); |
| 148 |
Thyra::assign(x_dot.ptr(),0.0); |
| 149 |
Thyra::assign(x.ptr(),5.0); |
| 150 |
in_args.set_x(x); |
| 151 |
in_args.set_x_dot(x_dot); |
| 152 |
|
| 153 |
// create out args |
| 154 |
OutArgs out_args = me->createOutArgs(); |
| 155 |
f = Thyra::createMember(*me->get_f_space()); |
| 156 |
out_args.set_f(f); |
| 157 |
|
| 158 |
me->evalModel(in_args, out_args); |
| 159 |
|
| 160 |
in_args.set_x(x); |
| 161 |
in_args.set_x_dot(x_dot); |
| 162 |
in_args.set_alpha(1.0); |
| 163 |
in_args.set_beta(0.0); |
| 164 |
|
| 165 |
out_args.set_f(Teuchos::null); |
| 166 |
out_args.set_W_op(mass); |
| 167 |
|
| 168 |
me->setOneTimeDirichletBeta(1.0); |
| 169 |
me->evalModel(in_args, out_args); |
| 170 |
} |
| 171 |
|
| 172 |
Teuchos::RCP<Thyra::VectorBase<double> > mass_exp_f = Thyra::createMember(*exp_me->get_f_space()); |
| 173 |
Thyra::apply(*mass,Thyra::NOTRANS,*exp_f,mass_exp_f.ptr()); |
| 174 |
|
| 175 |
out << "f_i = \n" << Teuchos::describe(*f,Teuchos::VERB_EXTREME) << std::endl; |
| 176 |
out << "f_e = \n" << Teuchos::describe(*mass_exp_f,Teuchos::VERB_EXTREME) << std::endl; |
| 177 |
|
| 178 |
// it should be that exp_f = -f b/c x_dot=0 in the evaluation |
| 179 |
Thyra::Vp_StV(mass_exp_f.ptr(),1.0,*f); |
| 180 |
|
| 181 |
out << "Error = " << Thyra::norm_2(*mass_exp_f) << std::endl; |
| 182 |
TEST_ASSERT(Thyra::norm_2(*mass_exp_f)<=1e-16); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 187 |
std::vector<panzer::BC>& bcs) |
| 188 |
{ |
| 189 |
// Physics block |
| 190 |
Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); |
| 191 |
{ |
| 192 |
Teuchos::ParameterList& p = physics_block.sublist("a"); |
| 193 |
p.set("Type","Energy"); |
| 194 |
p.set("Prefix",""); |
| 195 |
p.set("Model ID","solid"); |
| 196 |
p.set("Basis Type","HGrad"); |
| 197 |
p.set("Basis Order",1); |
| 198 |
p.set("Integration Order",2); |
| 199 |
} |
| 200 |
{ |
| 201 |
Teuchos::ParameterList& p = physics_block.sublist("b"); |
| 202 |
p.set("Type","Energy"); |
| 203 |
p.set("Prefix","ION_"); |
| 204 |
p.set("Model ID","ion solid"); |
| 205 |
p.set("Basis Type","HGrad"); |
| 206 |
p.set("Basis Order",1); |
| 207 |
p.set("Integration Order",2); |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
{ |
| 212 |
std::size_t bc_id = 0; |
| 213 |
panzer::BCType neumann = BCT_Dirichlet; |
| 214 |
std::string sideset_id = "left"; |
| 215 |
std::string element_block_id = "eblock-0_0"; |
| 216 |
std::string dof_name = "TEMPERATURE"; |
| 217 |
std::string strategy = "Constant"; |
| 218 |
double value = 5.0; |
| 219 |
Teuchos::ParameterList p; |
| 220 |
p.set("Value",value); |
| 221 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 222 |
strategy, p); |
| 223 |
bcs.push_back(bc); |
| 224 |
} |
| 225 |
{ |
| 226 |
std::size_t bc_id = 1; |
| 227 |
panzer::BCType neumann = BCT_Dirichlet; |
| 228 |
std::string sideset_id = "right"; |
| 229 |
std::string element_block_id = "eblock-1_0"; |
| 230 |
std::string dof_name = "TEMPERATURE"; |
| 231 |
std::string strategy = "Constant"; |
| 232 |
double value = 5.0; |
| 233 |
Teuchos::ParameterList p; |
| 234 |
p.set("Value",value); |
| 235 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 236 |
strategy, p); |
| 237 |
bcs.push_back(bc); |
| 238 |
} |
| 239 |
{ |
| 240 |
std::size_t bc_id = 2; |
| 241 |
panzer::BCType neumann = BCT_Dirichlet; |
| 242 |
std::string sideset_id = "top"; |
| 243 |
std::string element_block_id = "eblock-1_0"; |
| 244 |
std::string dof_name = "TEMPERATURE"; |
| 245 |
std::string strategy = "Constant"; |
| 246 |
double value = 5.0; |
| 247 |
Teuchos::ParameterList p; |
| 248 |
p.set("Value",value); |
| 249 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 250 |
strategy, p); |
| 251 |
bcs.push_back(bc); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
void buildAssemblyPieces(bool parameter_on, |
| 256 |
Teuchos::RCP<panzer::FieldManagerBuilder> & fmb, |
| 257 |
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > & rLibrary, |
| 258 |
Teuchos::RCP<panzer::GlobalData> & gd, |
| 259 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > & lof |
| 260 |
) |
| 261 |
{ |
| 262 |
using Teuchos::RCP; |
| 263 |
|
| 264 |
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); |
| 265 |
pl->set("X Blocks",2); |
| 266 |
pl->set("Y Blocks",1); |
| 267 |
pl->set("X Elements",4); |
| 268 |
pl->set("Y Elements",4); |
| 269 |
|
| 270 |
panzer_stk::SquareQuadMeshFactory factory; |
| 271 |
factory.setParameterList(pl); |
| 272 |
RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD); |
| 273 |
Teuchos::RCP<const Teuchos::Comm<int> > Comm = Teuchos::DefaultComm<int>::getComm(); |
| 274 |
Teuchos::RCP<const Teuchos::MpiComm<int> > mpiComm = Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(Comm); |
| 275 |
|
| 276 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks"); |
| 277 |
std::vector<panzer::BC> bcs; |
| 278 |
testInitialzation(ipb, bcs); |
| 279 |
|
| 280 |
fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); |
| 281 |
|
| 282 |
// build physics blocks |
| 283 |
////////////////////////////////////////////////////////////// |
| 284 |
const std::size_t workset_size = 20; |
| 285 |
Teuchos::RCP<user_app::MyFactory> eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 286 |
user_app::BCFactory bc_factory; |
| 287 |
gd = panzer::createGlobalData(); |
| 288 |
std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; |
| 289 |
{ |
| 290 |
std::map<std::string,std::string> block_ids_to_physics_ids; |
| 291 |
block_ids_to_physics_ids["eblock-0_0"] = "test physics"; |
| 292 |
block_ids_to_physics_ids["eblock-1_0"] = "test physics"; |
| 293 |
|
| 294 |
std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo; |
| 295 |
block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); |
| 296 |
block_ids_to_cell_topo["eblock-1_0"] = mesh->getCellTopology("eblock-1_0"); |
| 297 |
|
| 298 |
const int default_integration_order = 1; |
| 299 |
|
| 300 |
bool build_transient_support = true; |
| 301 |
panzer::buildPhysicsBlocks(block_ids_to_physics_ids, |
| 302 |
block_ids_to_cell_topo, |
| 303 |
ipb, |
| 304 |
default_integration_order, |
| 305 |
workset_size, |
| 306 |
eqset_factory, |
| 307 |
gd, |
| 308 |
build_transient_support, |
| 309 |
physicsBlocks); |
| 310 |
} |
| 311 |
|
| 312 |
// build worksets |
| 313 |
////////////////////////////////////////////////////////////// |
| 314 |
// build WorksetContainer |
| 315 |
Teuchos::RCP<panzer_stk::WorksetFactory> wkstFactory |
| 316 |
= Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory |
| 317 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation) |
| 318 |
= Teuchos::rcp(new panzer::WorksetContainer); |
| 319 |
wkstContainer->setFactory(wkstFactory); |
| 320 |
for(size_t i=0;i<physicsBlocks.size();i++) |
| 321 |
wkstContainer->setNeeds(physicsBlocks[i]->elementBlockID(),physicsBlocks[i]->getWorksetNeeds()); |
| 322 |
wkstContainer->setWorksetSize(workset_size); |
| 323 |
|
| 324 |
// build DOF Manager |
| 325 |
///////////////////////////////////////////////////////////// |
| 326 |
|
| 327 |
// build the connection manager |
| 328 |
const Teuchos::RCP<panzer::ConnManager> |
| 329 |
conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 330 |
|
| 331 |
panzer::DOFManagerFactory globalIndexerFactory; |
| 332 |
RCP<panzer::GlobalIndexer> dofManager |
| 333 |
= globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),physicsBlocks,conn_manager); |
| 334 |
|
| 335 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory |
| 336 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,dofManager,false)); |
| 337 |
lof = linObjFactory; |
| 338 |
|
| 339 |
rLibrary = Teuchos::rcp(new panzer::ResponseLibrary<panzer::Traits>(wkstContainer,dofManager,linObjFactory)); |
| 340 |
|
| 341 |
// setup field manager build |
| 342 |
///////////////////////////////////////////////////////////// |
| 343 |
|
| 344 |
// Add in the application specific closure model factory |
| 345 |
user_app::MyModelFactory_TemplateBuilder cm_builder; |
| 346 |
panzer::ClosureModelFactory_TemplateManager<panzer::Traits> cm_factory; |
| 347 |
cm_factory.buildObjects(cm_builder); |
| 348 |
|
| 349 |
Teuchos::ParameterList closure_models("Closure Models"); |
| 350 |
if (parameter_on) |
| 351 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE"). |
| 352 |
set<std::string>("Type", "Parameter"); |
| 353 |
else |
| 354 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE"). |
| 355 |
set<double>("Value", 1.0); |
| 356 |
|
| 357 |
closure_models.sublist("solid").sublist("DENSITY"). |
| 358 |
set<double>("Value", 1.0); |
| 359 |
closure_models.sublist("solid").sublist("HEAT_CAPACITY"). |
| 360 |
set<double>("Value", 1.0); |
| 361 |
closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE"). |
| 362 |
set<double>("Value", 1.0); |
| 363 |
closure_models.sublist("ion solid").sublist("ION_DENSITY"). |
| 364 |
set<double>("Value", 1.0); |
| 365 |
closure_models.sublist("ion solid").sublist("ION_HEAT_CAPACITY"). |
| 366 |
set<double>("Value", 1.0); |
| 367 |
|
| 368 |
Teuchos::ParameterList user_data("User Data"); |
| 369 |
|
| 370 |
fmb->setWorksetContainer(wkstContainer); |
| 371 |
fmb->setupVolumeFieldManagers(physicsBlocks,cm_factory,closure_models,*linObjFactory,user_data); |
| 372 |
fmb->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory,user_data); |
| 373 |
|
| 374 |
if (parameter_on) |
| 375 |
gd->pl->setRealValueForAllTypes(std::string("SOURCE_TEMPERATURE"), 1.0); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
} |