| 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 <Tpetra_KokkosCompat_DefaultNode.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 "Thyra_get_Epetra_Operator.hpp" |
| 56 |
|
| 57 |
#include "Epetra_CrsMatrix.h" |
| 58 |
|
| 59 |
#include <cstdio> // for get char |
| 60 |
#include <fstream> |
| 61 |
|
| 62 |
namespace panzer { |
| 63 |
|
| 64 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 65 |
std::vector<panzer::BC>& bcs); |
| 66 |
|
| 67 |
void buildAssemblyPieces(bool parameter_on, |
| 68 |
Teuchos::RCP<panzer::FieldManagerBuilder> & fmb, |
| 69 |
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > & rLibrary, |
| 70 |
Teuchos::RCP<panzer::GlobalData> & gd, |
| 71 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > & lof); |
| 72 |
|
| 73 |
/** This test builds the full model evaluator and tests that the mass matrix component is |
| 74 |
* correct. While this is only for one element, it seems fundamental and useful to have |
| 75 |
* this simple and fast test. |
| 76 |
* |
| 77 |
* Note: This only runs on one processor |
| 78 |
*/ |
| 79 |
TEUCHOS_UNIT_TEST(model_evaluator_mass_check, basic) |
| 80 |
{ |
| 81 |
using Teuchos::RCP; |
| 82 |
|
| 83 |
|
| 84 |
bool parameter_on = false; |
| 85 |
Teuchos::RCP<panzer::FieldManagerBuilder> fmb; |
| 86 |
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > rLibrary; |
| 87 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > lof; |
| 88 |
Teuchos::RCP<panzer::GlobalData> gd; |
| 89 |
|
| 90 |
buildAssemblyPieces(parameter_on,fmb,rLibrary,gd,lof); |
| 91 |
|
| 92 |
// Test a transient me |
| 93 |
{ |
| 94 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 95 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 96 |
typedef Thyra::VectorBase<double> VectorType; |
| 97 |
typedef Thyra::LinearOpBase<double> OperatorType; |
| 98 |
typedef panzer::ModelEvaluator<double> PME; |
| 99 |
|
| 100 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 101 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 102 |
bool build_transient_support = true; |
| 103 |
|
| 104 |
Stratimikos::DefaultLinearSolverBuilder builder; |
| 105 |
Teuchos::RCP<Teuchos::ParameterList> validList = Teuchos::rcp(new Teuchos::ParameterList(*builder.getValidParameters())); |
| 106 |
builder.setParameterList(validList); |
| 107 |
RCP<const Thyra::LinearOpWithSolveFactoryBase<double> > lowsFactory = builder.createLinearSolveStrategy("Amesos"); |
| 108 |
|
| 109 |
RCP<PME> me = Teuchos::rcp(new PME(fmb,rLibrary,lof,p_names,p_values,lowsFactory,gd,build_transient_support,0.0)); |
| 110 |
|
| 111 |
// implicit evaluation |
| 112 |
RCP<VectorType> f; |
| 113 |
RCP<OperatorType> mass = me->create_W_op(); |
| 114 |
{ |
| 115 |
// create in args |
| 116 |
InArgs in_args = me->createInArgs(); |
| 117 |
InArgs nomValues = me->getNominalValues(); |
| 118 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 119 |
RCP<VectorType> x_dot = Thyra::createMember(*me->get_x_space()); |
| 120 |
Thyra::assign(x_dot.ptr(),0.0); |
| 121 |
Thyra::assign(x.ptr(),5.0); |
| 122 |
in_args.set_x(x); |
| 123 |
in_args.set_x_dot(x_dot); |
| 124 |
|
| 125 |
// create out args |
| 126 |
OutArgs out_args = me->createOutArgs(); |
| 127 |
f = Thyra::createMember(*me->get_f_space()); |
| 128 |
out_args.set_f(f); |
| 129 |
|
| 130 |
me->evalModel(in_args, out_args); |
| 131 |
|
| 132 |
in_args.set_x(x); |
| 133 |
in_args.set_x_dot(x_dot); |
| 134 |
in_args.set_alpha(1.0); |
| 135 |
in_args.set_beta(0.0); |
| 136 |
|
| 137 |
out_args.set_f(Teuchos::null); |
| 138 |
out_args.set_W_op(mass); |
| 139 |
|
| 140 |
me->setOneTimeDirichletBeta(1.0); |
| 141 |
me->evalModel(in_args, out_args); |
| 142 |
} |
| 143 |
|
| 144 |
out << "mass = \n" << Teuchos::describe(*mass,Teuchos::VERB_EXTREME) << std::endl; |
| 145 |
|
| 146 |
Teuchos::RCP<const Epetra_Operator> e_op = Thyra::get_Epetra_Operator(*mass); |
| 147 |
Teuchos::RCP<const Epetra_CrsMatrix> ecrs_op = Teuchos::rcp_dynamic_cast<const Epetra_CrsMatrix>(e_op); |
| 148 |
|
| 149 |
double *values[4]; |
| 150 |
int *indices[4]; |
| 151 |
int numEntries[4]; |
| 152 |
ecrs_op->ExtractMyRowView(0,numEntries[0],values[0],indices[0]); |
| 153 |
ecrs_op->ExtractMyRowView(1,numEntries[1],values[1],indices[1]); |
| 154 |
ecrs_op->ExtractMyRowView(2,numEntries[2],values[2],indices[2]); |
| 155 |
ecrs_op->ExtractMyRowView(3,numEntries[3],values[3],indices[3]); |
| 156 |
|
| 157 |
TEST_ASSERT(numEntries[0]==4); |
| 158 |
TEST_ASSERT(numEntries[1]==4); |
| 159 |
TEST_ASSERT(numEntries[2]==4); |
| 160 |
TEST_ASSERT(numEntries[3]==4); |
| 161 |
|
| 162 |
for(int i=0;i<4;i++) { |
| 163 |
for(int j=0;j<4;j++) { |
| 164 |
int ind = indices[i][j]; |
| 165 |
|
| 166 |
out << "Testing: " << i << ", " << ind << std::endl; |
| 167 |
|
| 168 |
// this is a weird test. But the idea is to check |
| 169 |
// each component of the matrix. The 0 and 2 index are |
| 170 |
// opposite each other (as are 1 and 3), they are 0.25 |
| 171 |
// as large as the diagonal entries |
| 172 |
if(ind==i) |
| 173 |
{ TEST_FLOATING_EQUALITY(values[i][j],1.0/9.0,1e-15); } |
| 174 |
else if( (ind==2 && i==0) |
| 175 |
|| (i==2 && ind==0)) |
| 176 |
{ TEST_FLOATING_EQUALITY(values[i][j],1.0/36.0,1e-15); } |
| 177 |
else if( (ind==1 && i==3) |
| 178 |
|| (i==1 && ind==3)) |
| 179 |
{ TEST_FLOATING_EQUALITY(values[i][j],1.0/36.0,1e-15); } |
| 180 |
else |
| 181 |
{ TEST_FLOATING_EQUALITY(values[i][j],1.0/18.0,1e-15); } |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 188 |
std::vector<panzer::BC>& /* bcs */) |
| 189 |
{ |
| 190 |
// Physics block |
| 191 |
Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); |
| 192 |
{ |
| 193 |
Teuchos::ParameterList& p = physics_block.sublist("a"); |
| 194 |
p.set("Type","Energy"); |
| 195 |
p.set("Prefix",""); |
| 196 |
p.set("Model ID","solid"); |
| 197 |
p.set("Basis Type","HGrad"); |
| 198 |
p.set("Basis Order",1); |
| 199 |
p.set("Integration Order",2); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
void buildAssemblyPieces(bool parameter_on, |
| 204 |
Teuchos::RCP<panzer::FieldManagerBuilder> & fmb, |
| 205 |
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > & rLibrary, |
| 206 |
Teuchos::RCP<panzer::GlobalData> & gd, |
| 207 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > & lof |
| 208 |
) |
| 209 |
{ |
| 210 |
using Teuchos::RCP; |
| 211 |
|
| 212 |
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); |
| 213 |
pl->set("X Blocks",1); |
| 214 |
pl->set("Y Blocks",1); |
| 215 |
pl->set("X Elements",1); |
| 216 |
pl->set("Y Elements",1); |
| 217 |
pl->set("X0",0.0); |
| 218 |
pl->set("Xf",1.0); |
| 219 |
pl->set("Y0",0.0); |
| 220 |
pl->set("Yf",1.0); |
| 221 |
|
| 222 |
panzer_stk::SquareQuadMeshFactory factory; |
| 223 |
factory.setParameterList(pl); |
| 224 |
RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD); |
| 225 |
Teuchos::RCP<const Teuchos::Comm<int> > Comm = Teuchos::DefaultComm<int>::getComm(); |
| 226 |
Teuchos::RCP<const Teuchos::MpiComm<int> > mpiComm = Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(Comm); |
| 227 |
|
| 228 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks"); |
| 229 |
std::vector<panzer::BC> bcs; |
| 230 |
testInitialzation(ipb, bcs); |
| 231 |
|
| 232 |
fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); |
| 233 |
|
| 234 |
// build physics blocks |
| 235 |
////////////////////////////////////////////////////////////// |
| 236 |
const std::size_t workset_size = 1; |
| 237 |
Teuchos::RCP<user_app::MyFactory> eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 238 |
user_app::BCFactory bc_factory; |
| 239 |
gd = panzer::createGlobalData(); |
| 240 |
std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; |
| 241 |
{ |
| 242 |
std::map<std::string,std::string> block_ids_to_physics_ids; |
| 243 |
block_ids_to_physics_ids["eblock-0_0"] = "test physics"; |
| 244 |
|
| 245 |
std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo; |
| 246 |
block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); |
| 247 |
|
| 248 |
const int default_integration_order = 1; |
| 249 |
|
| 250 |
bool build_transient_support = true; |
| 251 |
panzer::buildPhysicsBlocks(block_ids_to_physics_ids, |
| 252 |
block_ids_to_cell_topo, |
| 253 |
ipb, |
| 254 |
default_integration_order, |
| 255 |
workset_size, |
| 256 |
eqset_factory, |
| 257 |
gd, |
| 258 |
build_transient_support, |
| 259 |
physicsBlocks); |
| 260 |
} |
| 261 |
|
| 262 |
// build worksets |
| 263 |
////////////////////////////////////////////////////////////// |
| 264 |
// build WorksetContainer |
| 265 |
Teuchos::RCP<panzer_stk::WorksetFactory> wkstFactory |
| 266 |
= Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory |
| 267 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation) |
| 268 |
= Teuchos::rcp(new panzer::WorksetContainer); |
| 269 |
wkstContainer->setFactory(wkstFactory); |
| 270 |
for(size_t i=0;i<physicsBlocks.size();i++) |
| 271 |
wkstContainer->setNeeds(physicsBlocks[i]->elementBlockID(),physicsBlocks[i]->getWorksetNeeds()); |
| 272 |
wkstContainer->setWorksetSize(workset_size); |
| 273 |
|
| 274 |
// build DOF Manager |
| 275 |
///////////////////////////////////////////////////////////// |
| 276 |
|
| 277 |
// build the connection manager |
| 278 |
const Teuchos::RCP<panzer::ConnManager> |
| 279 |
conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 280 |
|
| 281 |
panzer::DOFManagerFactory globalIndexerFactory; |
| 282 |
RCP<panzer::GlobalIndexer> dofManager |
| 283 |
= globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),physicsBlocks,conn_manager); |
| 284 |
|
| 285 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory |
| 286 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,dofManager,false)); |
| 287 |
lof = linObjFactory; |
| 288 |
|
| 289 |
rLibrary = Teuchos::rcp(new panzer::ResponseLibrary<panzer::Traits>(wkstContainer,dofManager,linObjFactory)); |
| 290 |
|
| 291 |
// setup field manager build |
| 292 |
///////////////////////////////////////////////////////////// |
| 293 |
|
| 294 |
// Add in the application specific closure model factory |
| 295 |
user_app::MyModelFactory_TemplateBuilder cm_builder; |
| 296 |
panzer::ClosureModelFactory_TemplateManager<panzer::Traits> cm_factory; |
| 297 |
cm_factory.buildObjects(cm_builder); |
| 298 |
|
| 299 |
Teuchos::ParameterList closure_models("Closure Models"); |
| 300 |
if(parameter_on) |
| 301 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<std::string>("Type","Parameter"); |
| 302 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<double>("Value",0.0); |
| 303 |
closure_models.sublist("solid").sublist("DENSITY").set<double>("Value",1.0); |
| 304 |
closure_models.sublist("solid").sublist("HEAT_CAPACITY").set<double>("Value",1.0); |
| 305 |
|
| 306 |
Teuchos::ParameterList user_data("User Data"); |
| 307 |
|
| 308 |
fmb->setWorksetContainer(wkstContainer); |
| 309 |
fmb->setupVolumeFieldManagers(physicsBlocks,cm_factory,closure_models,*linObjFactory,user_data); |
| 310 |
fmb->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory,user_data); |
| 311 |
fmb->writeVolumeGraphvizDependencyFiles("test",physicsBlocks); |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
} |