| 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 |
/////////////////////////////////////////////////////////////////////////////// |
| 12 |
// |
| 13 |
// Include Files |
| 14 |
// |
| 15 |
/////////////////////////////////////////////////////////////////////////////// |
| 16 |
|
| 17 |
// C++ |
| 18 |
#include <cstdio> |
| 19 |
#include <string> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
// Epetra |
| 23 |
#include "Epetra_MpiComm.h" |
| 24 |
// Kokkos |
| 25 |
#include "Kokkos_View_Fad.hpp" |
| 26 |
|
| 27 |
// Panzer |
| 28 |
#include "PanzerAdaptersSTK_config.hpp" |
| 29 |
#include "Panzer_BasisIRLayout.hpp" |
| 30 |
#include "Panzer_BlockedDOFManager.hpp" |
| 31 |
#include "Panzer_BlockedEpetraLinearObjFactory.hpp" |
| 32 |
#include "Panzer_BlockedTpetraLinearObjFactory.hpp" |
| 33 |
#include "Panzer_DOFManager.hpp" |
| 34 |
#include "Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.hpp" |
| 35 |
#include "Panzer_Evaluator_WithBaseImpl.hpp" |
| 36 |
#include "Panzer_FieldManagerBuilder.hpp" |
| 37 |
#include "Panzer_GatherOrientation.hpp" |
| 38 |
#include "Panzer_PureBasis.hpp" |
| 39 |
#include "Panzer_STKConnManager.hpp" |
| 40 |
#include "Panzer_STK_Interface.hpp" |
| 41 |
#include "Panzer_STK_SetupUtilities.hpp" |
| 42 |
#include "Panzer_STK_SquareQuadMeshFactory.hpp" |
| 43 |
#include "Panzer_STK_Version.hpp" |
| 44 |
#include "Panzer_Workset.hpp" |
| 45 |
|
| 46 |
// Teuchos |
| 47 |
#include "Teuchos_DefaultMpiComm.hpp" |
| 48 |
#include "Teuchos_GlobalMPISession.hpp" |
| 49 |
#include "Teuchos_OpaqueWrapper.hpp" |
| 50 |
#include "Teuchos_RCP.hpp" |
| 51 |
#include "Teuchos_TimeMonitor.hpp" |
| 52 |
#include "Teuchos_UnitTestHarness.hpp" |
| 53 |
|
| 54 |
// Thyra |
| 55 |
#include "Thyra_ProductVectorBase.hpp" |
| 56 |
#include "Thyra_VectorStdOps.hpp" |
| 57 |
|
| 58 |
// user_app |
| 59 |
#include "user_app_EquationSetFactory.hpp" |
| 60 |
|
| 61 |
typedef double ScalarT; |
| 62 |
using LocalOrdinalT = panzer::LocalOrdinal; |
| 63 |
using GlobalOrdinalT = panzer::GlobalOrdinal; |
| 64 |
typedef panzer::TpetraNodeType NodeT; |
| 65 |
|
| 66 |
typedef Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> VectorType; |
| 67 |
typedef Tpetra::Operator<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> OperatorType; |
| 68 |
typedef Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> CrsMatrixType; |
| 69 |
typedef Tpetra::CrsGraph<LocalOrdinalT,GlobalOrdinalT,NodeT> CrsGraphType; |
| 70 |
typedef Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> MapType; |
| 71 |
typedef Tpetra::Import<LocalOrdinalT,GlobalOrdinalT,NodeT> ImportType; |
| 72 |
typedef Tpetra::Export<LocalOrdinalT,GlobalOrdinalT,NodeT> ExportType; |
| 73 |
|
| 74 |
typedef Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> ThyraLinearOp; |
| 75 |
|
| 76 |
typedef panzer::BlockedTpetraLinearObjContainer<double,int,int> BLOC; |
| 77 |
typedef panzer::BlockedTpetraLinearObjFactory<panzer::Traits,double,int,int> BLOFact; |
| 78 |
|
| 79 |
namespace panzer { |
| 80 |
|
| 81 |
Teuchos::RCP<panzer::PureBasis> buildBasis(std::size_t worksetSize,const std::string & basisName); |
| 82 |
void testInitialization(const Teuchos::RCP<Teuchos::ParameterList>& ipb); |
| 83 |
Teuchos::RCP<panzer_stk::STK_Interface> buildMesh(int elemX,int elemY); |
| 84 |
void testGatherScatter(const bool enable_tangents, Teuchos::FancyOStream& out, bool& success); |
| 85 |
|
| 86 |
// Test without tangent fields in gather evaluator |
| 87 |
TEUCHOS_UNIT_TEST(epetra_assembly, gather_solution_no_tangents) |
| 88 |
{ |
| 89 |
testGatherScatter(false,out,success); |
| 90 |
} |
| 91 |
|
| 92 |
// Test with tangent fields in gather evaluator |
| 93 |
TEUCHOS_UNIT_TEST(epetra_assembly, gather_solution_tangents) |
| 94 |
{ |
| 95 |
testGatherScatter(true,out,success); |
| 96 |
} |
| 97 |
|
| 98 |
// enable_tangents determines whether tangent fields dx/dp are added to gather evaluator. |
| 99 |
// These are used when computing df/dx*dx/dp with the tangent evaluation type |
| 100 |
void testGatherScatter(const bool enable_tangents, Teuchos::FancyOStream& out, bool& success) |
| 101 |
{ |
| 102 |
|
| 103 |
#ifdef HAVE_MPI |
| 104 |
Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); |
| 105 |
#else |
| 106 |
Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_SerialComm()); |
| 107 |
#endif |
| 108 |
|
| 109 |
int myRank = eComm->MyPID(); |
| 110 |
int numProcs = eComm->NumProc(); |
| 111 |
|
| 112 |
const std::size_t workset_size = 4/numProcs; |
| 113 |
const std::string fieldName1_q1 = "U"; |
| 114 |
const std::string fieldName2_q1 = "V"; |
| 115 |
const std::string fieldName_qedge1 = "B"; |
| 116 |
const int num_tangent = enable_tangents ? 5 : 0; |
| 117 |
|
| 118 |
Teuchos::RCP<panzer_stk::STK_Interface> mesh = buildMesh(2,2); |
| 119 |
|
| 120 |
// build input physics block |
| 121 |
Teuchos::RCP<panzer::PureBasis> basis_q1 = buildBasis(workset_size,"Q1"); |
| 122 |
Teuchos::RCP<panzer::PureBasis> basis_qedge1 = buildBasis(workset_size,"QEdge1"); |
| 123 |
|
| 124 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList(); |
| 125 |
testInitialization(ipb); |
| 126 |
|
| 127 |
const int default_int_order = 1; |
| 128 |
std::string eBlockID = "eblock-0_0"; |
| 129 |
Teuchos::RCP<user_app::MyFactory> eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 130 |
panzer::CellData cellData(workset_size,mesh->getCellTopology("eblock-0_0")); |
| 131 |
Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData(); |
| 132 |
Teuchos::RCP<panzer::PhysicsBlock> physicsBlock = |
| 133 |
Teuchos::rcp(new PhysicsBlock(ipb,eBlockID,default_int_order,cellData,eqset_factory,gd,false)); |
| 134 |
|
| 135 |
Teuchos::RCP<std::vector<panzer::Workset> > work_sets = panzer_stk::buildWorksets(*mesh,physicsBlock->elementBlockID(), |
| 136 |
physicsBlock->getWorksetNeeds()); |
| 137 |
TEST_EQUALITY(work_sets->size(),1); |
| 138 |
|
| 139 |
// build connection manager and field manager |
| 140 |
const Teuchos::RCP<panzer::ConnManager> conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 141 |
Teuchos::RCP<panzer::DOFManager> dofManager = Teuchos::rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD)); |
| 142 |
|
| 143 |
dofManager->addField(fieldName1_q1,Teuchos::rcp(new panzer::Intrepid2FieldPattern(basis_q1->getIntrepid2Basis()))); |
| 144 |
dofManager->addField(fieldName2_q1,Teuchos::rcp(new panzer::Intrepid2FieldPattern(basis_q1->getIntrepid2Basis()))); |
| 145 |
dofManager->addField(fieldName_qedge1,Teuchos::rcp(new panzer::Intrepid2FieldPattern(basis_qedge1->getIntrepid2Basis()))); |
| 146 |
|
| 147 |
std::vector<std::string> fieldOrder; |
| 148 |
fieldOrder.push_back(fieldName1_q1); |
| 149 |
fieldOrder.push_back(fieldName_qedge1); |
| 150 |
fieldOrder.push_back(fieldName2_q1); |
| 151 |
dofManager->setFieldOrder(fieldOrder); |
| 152 |
|
| 153 |
// dofManager->setOrientationsRequired(true); |
| 154 |
dofManager->buildGlobalUnknowns(); |
| 155 |
|
| 156 |
// setup linear object factory |
| 157 |
///////////////////////////////////////////////////////////// |
| 158 |
|
| 159 |
Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 160 |
Teuchos::RCP<BlockedEpetraLinearObjFactory<panzer::Traits,int> > e_lof |
| 161 |
= Teuchos::rcp(new BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm.getConst(),dofManager)); |
| 162 |
Teuchos::RCP<LinearObjFactory<panzer::Traits> > lof = e_lof; |
| 163 |
Teuchos::RCP<LinearObjContainer> loc = e_lof->buildGhostedLinearObjContainer(); |
| 164 |
e_lof->initializeGhostedContainer(LinearObjContainer::X,*loc); |
| 165 |
|
| 166 |
Teuchos::RCP<EpetraLinearObjContainer> e_loc |
| 167 |
= Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(loc); |
| 168 |
Teuchos::RCP<Thyra::VectorBase<double> > x_vec = e_loc->get_x_th(); |
| 169 |
Thyra::assign(x_vec.ptr(),123.0+myRank); |
| 170 |
|
| 171 |
// Set up the tangent data containers. |
| 172 |
std::vector<Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData>> |
| 173 |
tangentContainers; |
| 174 |
if (enable_tangents) |
| 175 |
{ |
| 176 |
using Teuchos::RCP; |
| 177 |
using Teuchos::rcp_dynamic_cast; |
| 178 |
using Thyra::VectorBase; |
| 179 |
using EVROGED = panzer::EpetraVector_ReadOnly_GlobalEvaluationData; |
| 180 |
using ROVGED = panzer::ReadOnlyVector_GlobalEvaluationData; |
| 181 |
for (int i(0); i < num_tangent; ++i) |
| 182 |
{ |
| 183 |
RCP<ROVGED> tangentContainer = e_lof->buildReadOnlyDomainContainer(); |
| 184 |
auto tanContainerEpetra = rcp_dynamic_cast<EVROGED>(tangentContainer); |
| 185 |
RCP<VectorBase<double>> tanVecOwned = |
| 186 |
tanContainerEpetra->getOwnedVector()->clone_v(); |
| 187 |
assign(tanVecOwned.ptr(), 0.123 + myRank + i); |
| 188 |
tanContainerEpetra->setOwnedVector(tanVecOwned); |
| 189 |
RCP<VectorBase<double>> tanVecGhosted = |
| 190 |
tanContainerEpetra->getGhostedVector(); |
| 191 |
assign(tanVecGhosted.ptr(), 0.123 + myRank + i); |
| 192 |
tangentContainers.push_back(tangentContainer); |
| 193 |
} // end loop over the tangents |
| 194 |
} // end if (enable_tangents) |
| 195 |
|
| 196 |
// setup field manager, add evaluator under test |
| 197 |
///////////////////////////////////////////////////////////// |
| 198 |
|
| 199 |
PHX::FieldManager<panzer::Traits> fm; |
| 200 |
|
| 201 |
std::vector<PHX::index_size_type> derivative_dimensions; |
| 202 |
derivative_dimensions.push_back(12); |
| 203 |
fm.setKokkosExtendedDataTypeDimensions<panzer::Traits::Jacobian>(derivative_dimensions); |
| 204 |
|
| 205 |
std::vector<PHX::index_size_type> tan_derivative_dimensions; |
| 206 |
if (enable_tangents) |
| 207 |
tan_derivative_dimensions.push_back(num_tangent); |
| 208 |
else |
| 209 |
tan_derivative_dimensions.push_back(0); |
| 210 |
fm.setKokkosExtendedDataTypeDimensions<panzer::Traits::Tangent>(tan_derivative_dimensions); |
| 211 |
|
| 212 |
Teuchos::RCP<PHX::FieldTag> evalField_q1, evalField_qedge1; |
| 213 |
{ |
| 214 |
using Teuchos::RCP; |
| 215 |
using Teuchos::rcp; |
| 216 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 217 |
names->push_back(fieldName1_q1); |
| 218 |
names->push_back(fieldName2_q1); |
| 219 |
|
| 220 |
Teuchos::ParameterList pl; |
| 221 |
pl.set("Basis", basis_q1); |
| 222 |
pl.set("DOF Names",names); |
| 223 |
pl.set("Indexer Names",names); |
| 224 |
|
| 225 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = lof->buildGather<panzer::Traits::Residual>(pl); |
| 226 |
|
| 227 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),2); |
| 228 |
|
| 229 |
fm.registerEvaluator<panzer::Traits::Residual>(evaluator); |
| 230 |
fm.requireField<panzer::Traits::Residual>(*evaluator->evaluatedFields()[0]); |
| 231 |
} |
| 232 |
{ |
| 233 |
using Teuchos::RCP; |
| 234 |
using Teuchos::rcp; |
| 235 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 236 |
names->push_back(fieldName_qedge1); |
| 237 |
|
| 238 |
Teuchos::ParameterList pl; |
| 239 |
pl.set("Basis", basis_qedge1); |
| 240 |
pl.set("DOF Names",names); |
| 241 |
pl.set("Indexer Names",names); |
| 242 |
|
| 243 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = lof->buildGather<panzer::Traits::Residual>(pl); |
| 244 |
|
| 245 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),1); |
| 246 |
|
| 247 |
fm.registerEvaluator<panzer::Traits::Residual>(evaluator); |
| 248 |
fm.requireField<panzer::Traits::Residual>(*evaluator->evaluatedFields()[0]); |
| 249 |
} |
| 250 |
|
| 251 |
{ |
| 252 |
using Teuchos::RCP; |
| 253 |
using Teuchos::rcp; |
| 254 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 255 |
names->push_back(fieldName1_q1); |
| 256 |
names->push_back(fieldName2_q1); |
| 257 |
|
| 258 |
Teuchos::ParameterList pl; |
| 259 |
pl.set("Basis", basis_q1); |
| 260 |
pl.set("DOF Names",names); |
| 261 |
pl.set("Indexer Names",names); |
| 262 |
|
| 263 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = lof->buildGather<panzer::Traits::Jacobian>(pl); |
| 264 |
|
| 265 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),2); |
| 266 |
|
| 267 |
fm.registerEvaluator<panzer::Traits::Jacobian>(evaluator); |
| 268 |
fm.requireField<panzer::Traits::Jacobian>(*evaluator->evaluatedFields()[0]); |
| 269 |
} |
| 270 |
{ |
| 271 |
using Teuchos::RCP; |
| 272 |
using Teuchos::rcp; |
| 273 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 274 |
names->push_back(fieldName_qedge1); |
| 275 |
|
| 276 |
Teuchos::ParameterList pl; |
| 277 |
pl.set("Basis", basis_qedge1); |
| 278 |
pl.set("DOF Names",names); |
| 279 |
pl.set("Indexer Names",names); |
| 280 |
|
| 281 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = lof->buildGather<panzer::Traits::Jacobian>(pl); |
| 282 |
|
| 283 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),1); |
| 284 |
|
| 285 |
fm.registerEvaluator<panzer::Traits::Jacobian>(evaluator); |
| 286 |
fm.requireField<panzer::Traits::Jacobian>(*evaluator->evaluatedFields()[0]); |
| 287 |
} |
| 288 |
|
| 289 |
{ |
| 290 |
using Teuchos::RCP; |
| 291 |
using Teuchos::rcp; |
| 292 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 293 |
names->push_back(fieldName1_q1); |
| 294 |
names->push_back(fieldName2_q1); |
| 295 |
|
| 296 |
Teuchos::ParameterList pl; |
| 297 |
pl.set("Basis", basis_q1); |
| 298 |
pl.set("DOF Names",names); |
| 299 |
pl.set("Indexer Names",names); |
| 300 |
|
| 301 |
if (enable_tangents) { |
| 302 |
RCP<std::vector< std::vector<std::string> > > tangent_names = |
| 303 |
rcp(new std::vector< std::vector<std::string> >(2)); |
| 304 |
for (int i=0; i<num_tangent; ++i) { |
| 305 |
std::stringstream ss1, ss2; |
| 306 |
ss1 << fieldName1_q1 << " Tangent " << i; |
| 307 |
ss2 << fieldName2_q1 << " Tangent " << i; |
| 308 |
(*tangent_names)[0].push_back(ss1.str()); |
| 309 |
(*tangent_names)[1].push_back(ss2.str()); |
| 310 |
} |
| 311 |
pl.set("Tangent Names", tangent_names); |
| 312 |
} |
| 313 |
|
| 314 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = lof->buildGather<panzer::Traits::Tangent>(pl); |
| 315 |
|
| 316 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),2); |
| 317 |
|
| 318 |
fm.registerEvaluator<panzer::Traits::Tangent>(evaluator); |
| 319 |
fm.requireField<panzer::Traits::Tangent>(*evaluator->evaluatedFields()[0]); |
| 320 |
} |
| 321 |
{ |
| 322 |
using Teuchos::RCP; |
| 323 |
using Teuchos::rcp; |
| 324 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 325 |
names->push_back(fieldName_qedge1); |
| 326 |
|
| 327 |
Teuchos::ParameterList pl; |
| 328 |
pl.set("Basis", basis_qedge1); |
| 329 |
pl.set("DOF Names",names); |
| 330 |
pl.set("Indexer Names",names); |
| 331 |
|
| 332 |
if (enable_tangents) { |
| 333 |
RCP<std::vector< std::vector<std::string> > > tangent_names = |
| 334 |
rcp(new std::vector< std::vector<std::string> >(1)); |
| 335 |
for (int i=0; i<num_tangent; ++i) { |
| 336 |
std::stringstream ss; |
| 337 |
ss << fieldName_qedge1 << " Tangent " << i; |
| 338 |
(*tangent_names)[0].push_back(ss.str()); |
| 339 |
} |
| 340 |
pl.set("Tangent Names", tangent_names); |
| 341 |
} |
| 342 |
|
| 343 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = lof->buildGather<panzer::Traits::Tangent>(pl); |
| 344 |
|
| 345 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),1); |
| 346 |
|
| 347 |
fm.registerEvaluator<panzer::Traits::Tangent>(evaluator); |
| 348 |
fm.requireField<panzer::Traits::Tangent>(*evaluator->evaluatedFields()[0]); |
| 349 |
} |
| 350 |
|
| 351 |
if (enable_tangents) { |
| 352 |
for (int i=0; i<num_tangent; ++i) { |
| 353 |
using Teuchos::RCP; |
| 354 |
using Teuchos::rcp; |
| 355 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 356 |
RCP<std::vector<std::string> > tangent_names = rcp(new std::vector<std::string>); |
| 357 |
names->push_back(fieldName1_q1); |
| 358 |
names->push_back(fieldName2_q1); |
| 359 |
{ |
| 360 |
std::stringstream ss1, ss2; |
| 361 |
ss1 << fieldName1_q1 << " Tangent " << i; |
| 362 |
ss2 << fieldName2_q1 << " Tangent " << i; |
| 363 |
tangent_names->push_back(ss1.str()); |
| 364 |
tangent_names->push_back(ss2.str()); |
| 365 |
} |
| 366 |
|
| 367 |
Teuchos::ParameterList pl; |
| 368 |
pl.set("Basis", basis_q1); |
| 369 |
pl.set("DOF Names",tangent_names); |
| 370 |
pl.set("Indexer Names",names); |
| 371 |
|
| 372 |
{ |
| 373 |
std::stringstream ss; |
| 374 |
ss << "Tangent Container " << i; |
| 375 |
pl.set("Global Data Key", ss.str()); |
| 376 |
} |
| 377 |
|
| 378 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = |
| 379 |
lof->buildGatherTangent<panzer::Traits::Tangent>(pl); |
| 380 |
|
| 381 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),2); |
| 382 |
|
| 383 |
fm.registerEvaluator<panzer::Traits::Tangent>(evaluator); |
| 384 |
} |
| 385 |
for (int i=0; i<num_tangent; ++i) { |
| 386 |
using Teuchos::RCP; |
| 387 |
using Teuchos::rcp; |
| 388 |
RCP<std::vector<std::string> > names = rcp(new std::vector<std::string>); |
| 389 |
RCP<std::vector<std::string> > tangent_names = rcp(new std::vector<std::string>); |
| 390 |
names->push_back(fieldName_qedge1); |
| 391 |
{ |
| 392 |
std::stringstream ss; |
| 393 |
ss << fieldName_qedge1 << " Tangent " << i; |
| 394 |
tangent_names->push_back(ss.str()); |
| 395 |
} |
| 396 |
|
| 397 |
Teuchos::ParameterList pl; |
| 398 |
pl.set("Basis", basis_qedge1); |
| 399 |
pl.set("DOF Names",tangent_names); |
| 400 |
pl.set("Indexer Names",names); |
| 401 |
|
| 402 |
{ |
| 403 |
std::stringstream ss; |
| 404 |
ss << "Tangent Container " << i; |
| 405 |
pl.set("Global Data Key", ss.str()); |
| 406 |
} |
| 407 |
|
| 408 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator = |
| 409 |
lof->buildGatherTangent<panzer::Traits::Tangent>(pl); |
| 410 |
|
| 411 |
TEST_EQUALITY(evaluator->evaluatedFields().size(),1); |
| 412 |
|
| 413 |
fm.registerEvaluator<panzer::Traits::Tangent>(evaluator); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
panzer::Traits::SD sd; |
| 418 |
fm.postRegistrationSetup(sd); |
| 419 |
|
| 420 |
panzer::Traits::PED ped; |
| 421 |
ped.gedc->addDataObject("Solution Gather Container", loc); |
| 422 |
if (enable_tangents) |
| 423 |
{ |
| 424 |
for (int i(0); i < num_tangent; ++i) |
| 425 |
{ |
| 426 |
std::stringstream ss; |
| 427 |
ss << "Tangent Container " << i; |
| 428 |
ped.gedc->addDataObject(ss.str(), tangentContainers[i]); |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
fm.preEvaluate<panzer::Traits::Residual>(ped); |
| 433 |
fm.preEvaluate<panzer::Traits::Jacobian>(ped); |
| 434 |
fm.preEvaluate<panzer::Traits::Tangent>(ped); |
| 435 |
|
| 436 |
// run tests |
| 437 |
///////////////////////////////////////////////////////////// |
| 438 |
|
| 439 |
panzer::Workset & workset = (*work_sets)[0]; |
| 440 |
workset.alpha = 0.0; |
| 441 |
workset.beta = 2.0; // derivatives multiplied by 2 |
| 442 |
workset.time = 0.0; |
| 443 |
workset.evaluate_transient_terms = false; |
| 444 |
|
| 445 |
fm.evaluateFields<panzer::Traits::Residual>(workset); |
| 446 |
fm.evaluateFields<panzer::Traits::Jacobian>(workset); |
| 447 |
fm.evaluateFields<panzer::Traits::Tangent>(workset); |
| 448 |
|
| 449 |
// test Residual fields |
| 450 |
{ |
| 451 |
PHX::MDField<panzer::Traits::Residual::ScalarT,panzer::Cell,panzer::BASIS> |
| 452 |
fieldData1_q1(fieldName1_q1,basis_q1->functional); |
| 453 |
PHX::MDField<panzer::Traits::Residual::ScalarT,panzer::Cell,panzer::BASIS> |
| 454 |
fieldData2_q1(fieldName2_q1,basis_qedge1->functional); |
| 455 |
|
| 456 |
fm.getFieldData<panzer::Traits::Residual>(fieldData1_q1); |
| 457 |
fm.getFieldData<panzer::Traits::Residual>(fieldData2_q1); |
| 458 |
|
| 459 |
TEST_EQUALITY(fieldData1_q1.extent(0),Teuchos::as<unsigned int>(4/numProcs)); |
| 460 |
TEST_EQUALITY(fieldData1_q1.extent(1),4); |
| 461 |
TEST_EQUALITY(fieldData2_q1.extent(0),Teuchos::as<unsigned int>(4/numProcs)); |
| 462 |
TEST_EQUALITY(fieldData2_q1.extent(1),4); |
| 463 |
TEST_EQUALITY(fieldData1_q1.size(),Teuchos::as<unsigned int>(4*4/numProcs)); |
| 464 |
TEST_EQUALITY(fieldData2_q1.size(),Teuchos::as<unsigned int>(4*4/numProcs)); |
| 465 |
|
| 466 |
auto fieldData1_q1_h = Kokkos::create_mirror_view(fieldData1_q1.get_static_view()); |
| 467 |
auto fieldData2_q1_h = Kokkos::create_mirror_view(fieldData2_q1.get_static_view()); |
| 468 |
Kokkos::deep_copy(fieldData1_q1_h, fieldData1_q1.get_static_view()); |
| 469 |
Kokkos::deep_copy(fieldData2_q1_h, fieldData2_q1.get_static_view()); |
| 470 |
|
| 471 |
for(unsigned int i=0;i<fieldData1_q1.extent(0);i++) |
| 472 |
for(unsigned int j=0;j<fieldData1_q1.extent(1);j++) |
| 473 |
TEST_EQUALITY(fieldData1_q1_h(i,j),123.0+myRank); |
| 474 |
|
| 475 |
for(unsigned int i=0;i<fieldData2_q1.extent(0);i++) |
| 476 |
for(unsigned int j=0;j<fieldData2_q1.extent(1);j++) |
| 477 |
TEST_EQUALITY(fieldData2_q1_h(i,j),123.0+myRank); |
| 478 |
} |
| 479 |
{ |
| 480 |
PHX::MDField<panzer::Traits::Residual::ScalarT,panzer::Cell,panzer::BASIS> |
| 481 |
fieldData_qedge1(fieldName_qedge1,basis_qedge1->functional); |
| 482 |
|
| 483 |
fm.getFieldData<panzer::Traits::Residual>(fieldData_qedge1); |
| 484 |
|
| 485 |
auto fieldData_qedge1_h = Kokkos::create_mirror_view(fieldData_qedge1.get_static_view()); |
| 486 |
Kokkos::deep_copy(fieldData_qedge1_h, fieldData_qedge1.get_static_view()); |
| 487 |
|
| 488 |
TEST_EQUALITY(fieldData_qedge1.extent(0),Teuchos::as<unsigned int>(4/numProcs)); |
| 489 |
TEST_EQUALITY(fieldData_qedge1.extent(1),4); |
| 490 |
TEST_EQUALITY(fieldData_qedge1.size(),Teuchos::as<unsigned int>(4*4/numProcs)); |
| 491 |
|
| 492 |
for(unsigned int cell=0;cell<fieldData_qedge1.extent(0);++cell) |
| 493 |
for(unsigned int pt=0;pt<fieldData_qedge1.extent(1);pt++) |
| 494 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt),123.0+myRank); |
| 495 |
} |
| 496 |
|
| 497 |
// test Jacobian fields |
| 498 |
{ |
| 499 |
PHX::MDField<panzer::Traits::Jacobian::ScalarT,panzer::Cell,panzer::BASIS> |
| 500 |
fieldData1_q1(fieldName1_q1,basis_q1->functional); |
| 501 |
PHX::MDField<panzer::Traits::Jacobian::ScalarT,panzer::Cell,panzer::BASIS> |
| 502 |
fieldData2_q1(fieldName2_q1,basis_qedge1->functional); |
| 503 |
|
| 504 |
fm.getFieldData<panzer::Traits::Jacobian>(fieldData1_q1); |
| 505 |
fm.getFieldData<panzer::Traits::Jacobian>(fieldData2_q1); |
| 506 |
|
| 507 |
auto fieldData1_q1_h = Kokkos::create_mirror_view(fieldData1_q1.get_static_view()); |
| 508 |
auto fieldData2_q1_h = Kokkos::create_mirror_view(fieldData2_q1.get_static_view()); |
| 509 |
Kokkos::deep_copy(fieldData1_q1_h, fieldData1_q1.get_static_view()); |
| 510 |
Kokkos::deep_copy(fieldData2_q1_h, fieldData2_q1.get_static_view()); |
| 511 |
|
| 512 |
for(unsigned int cell=0;cell<fieldData1_q1.extent(0);++cell) { |
| 513 |
for(unsigned int pt=0;pt<fieldData1_q1.extent(1);pt++) { |
| 514 |
TEST_EQUALITY(fieldData1_q1_h(cell,pt),123.0+myRank); |
| 515 |
TEST_EQUALITY(fieldData1_q1_h(cell,pt).availableSize(),12); |
| 516 |
} |
| 517 |
} |
| 518 |
for(unsigned int cell=0;cell<fieldData2_q1.extent(0);++cell) { |
| 519 |
for(unsigned int pt=0;pt<fieldData2_q1.extent(1);pt++) { |
| 520 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt),123.0+myRank); |
| 521 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt).availableSize(),12); |
| 522 |
} |
| 523 |
} |
| 524 |
} |
| 525 |
{ |
| 526 |
PHX::MDField<panzer::Traits::Jacobian::ScalarT,panzer::Cell,panzer::BASIS> |
| 527 |
fieldData_qedge1(fieldName_qedge1,basis_qedge1->functional); |
| 528 |
|
| 529 |
fm.getFieldData<panzer::Traits::Jacobian>(fieldData_qedge1); |
| 530 |
|
| 531 |
auto fieldData_qedge1_h = Kokkos::create_mirror_view(fieldData_qedge1.get_static_view()); |
| 532 |
Kokkos::deep_copy(fieldData_qedge1_h, fieldData_qedge1.get_static_view()); |
| 533 |
|
| 534 |
for(unsigned int cell=0;cell<fieldData_qedge1.extent(0);++cell) { |
| 535 |
for(unsigned int pt=0;pt<fieldData_qedge1.extent(1);++pt) { |
| 536 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt),123.0+myRank); |
| 537 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt).availableSize(),12); |
| 538 |
} |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
// test Tangent fields |
| 543 |
{ |
| 544 |
PHX::MDField<panzer::Traits::Tangent::ScalarT,panzer::Cell,panzer::BASIS> |
| 545 |
fieldData1_q1(fieldName1_q1,basis_q1->functional); |
| 546 |
PHX::MDField<panzer::Traits::Tangent::ScalarT,panzer::Cell,panzer::BASIS> |
| 547 |
fieldData2_q1(fieldName2_q1,basis_qedge1->functional); |
| 548 |
|
| 549 |
fm.getFieldData<panzer::Traits::Tangent>(fieldData1_q1); |
| 550 |
fm.getFieldData<panzer::Traits::Tangent>(fieldData2_q1); |
| 551 |
|
| 552 |
auto fieldData1_q1_h = Kokkos::create_mirror_view(fieldData1_q1.get_static_view()); |
| 553 |
auto fieldData2_q1_h = Kokkos::create_mirror_view(fieldData2_q1.get_static_view()); |
| 554 |
Kokkos::deep_copy(fieldData1_q1_h, fieldData1_q1.get_static_view()); |
| 555 |
Kokkos::deep_copy(fieldData2_q1_h, fieldData2_q1.get_static_view()); |
| 556 |
|
| 557 |
for(unsigned int cell=0;cell<fieldData1_q1.extent(0);++cell) { |
| 558 |
for(unsigned int pt=0;pt<fieldData1_q1.extent(1);pt++) { |
| 559 |
if (enable_tangents) { |
| 560 |
TEST_EQUALITY(fieldData1_q1_h(cell,pt).val(),123.0+myRank); |
| 561 |
TEST_EQUALITY(fieldData1_q1_h(cell,pt).availableSize(),num_tangent); |
| 562 |
for (int i=0; i<num_tangent; ++i) |
| 563 |
TEST_EQUALITY(fieldData1_q1_h(cell,pt).dx(i),0.123+myRank+i); |
| 564 |
} |
| 565 |
else { |
| 566 |
TEST_EQUALITY(fieldData1_q1_h(cell,pt),123.0+myRank); |
| 567 |
TEST_EQUALITY(fieldData1_q1_h(cell,pt).availableSize(),0); |
| 568 |
} |
| 569 |
} |
| 570 |
} |
| 571 |
for(unsigned int cell=0;cell<fieldData2_q1.extent(0);++cell) { |
| 572 |
for(unsigned int pt=0;pt<fieldData2_q1.extent(1);pt++) { |
| 573 |
if (enable_tangents) { |
| 574 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt).val(),123.0+myRank); |
| 575 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt).availableSize(),num_tangent); |
| 576 |
for (int i=0; i<num_tangent; ++i) { |
| 577 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt).dx(i),0.123+myRank+i); |
| 578 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt).dx(i),0.123+myRank+i); |
| 579 |
} |
| 580 |
} |
| 581 |
else { |
| 582 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt),123.0+myRank); |
| 583 |
TEST_EQUALITY(fieldData2_q1_h(cell,pt).availableSize(),0); |
| 584 |
} |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
{ |
| 589 |
PHX::MDField<panzer::Traits::Tangent::ScalarT,panzer::Cell,panzer::BASIS> |
| 590 |
fieldData_qedge1(fieldName_qedge1,basis_qedge1->functional); |
| 591 |
|
| 592 |
fm.getFieldData<panzer::Traits::Tangent>(fieldData_qedge1); |
| 593 |
|
| 594 |
auto fieldData_qedge1_h = Kokkos::create_mirror_view(fieldData_qedge1.get_static_view()); |
| 595 |
Kokkos::deep_copy(fieldData_qedge1_h, fieldData_qedge1.get_static_view()); |
| 596 |
|
| 597 |
for(unsigned int cell=0;cell<fieldData_qedge1.extent(0);++cell) { |
| 598 |
for(unsigned int pt=0;pt<fieldData_qedge1.extent(1);++pt) { |
| 599 |
if (enable_tangents) { |
| 600 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt).val(),123.0+myRank); |
| 601 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt).availableSize(),num_tangent); |
| 602 |
for (int i=0; i<num_tangent; ++i) |
| 603 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt).dx(i),0.123+myRank+i); |
| 604 |
} |
| 605 |
else { |
| 606 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt),123.0+myRank); |
| 607 |
TEST_EQUALITY(fieldData_qedge1_h(cell,pt).availableSize(),0); |
| 608 |
} |
| 609 |
} |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
Teuchos::RCP<panzer::PureBasis> buildBasis(std::size_t worksetSize,const std::string & basisName) |
| 616 |
{ |
| 617 |
Teuchos::RCP<shards::CellTopology> topo = |
| 618 |
Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); |
| 619 |
|
| 620 |
panzer::CellData cellData(worksetSize,topo); |
| 621 |
return Teuchos::rcp(new panzer::PureBasis(basisName,1,cellData)); |
| 622 |
} |
| 623 |
|
| 624 |
Teuchos::RCP<panzer_stk::STK_Interface> buildMesh(int elemX,int elemY) |
| 625 |
{ |
| 626 |
Teuchos::RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); |
| 627 |
pl->set("X Blocks",1); |
| 628 |
pl->set("Y Blocks",1); |
| 629 |
pl->set("X Elements",elemX); |
| 630 |
pl->set("Y Elements",elemY); |
| 631 |
|
| 632 |
panzer_stk::SquareQuadMeshFactory factory; |
| 633 |
factory.setParameterList(pl); |
| 634 |
Teuchos::RCP<panzer_stk::STK_Interface> mesh = factory.buildUncommitedMesh(MPI_COMM_WORLD); |
| 635 |
factory.completeMeshConstruction(*mesh,MPI_COMM_WORLD); |
| 636 |
|
| 637 |
return mesh; |
| 638 |
} |
| 639 |
|
| 640 |
void testInitialization(const Teuchos::RCP<Teuchos::ParameterList>& ipb) |
| 641 |
{ |
| 642 |
// Physics block |
| 643 |
ipb->setName("test physics"); |
| 644 |
{ |
| 645 |
Teuchos::ParameterList& p = ipb->sublist("a"); |
| 646 |
p.set("Type","Energy"); |
| 647 |
p.set("Prefix",""); |
| 648 |
p.set("Model ID","solid"); |
| 649 |
p.set("Basis Type","HGrad"); |
| 650 |
p.set("Basis Order",1); |
| 651 |
p.set("Integration Order",1); |
| 652 |
} |
| 653 |
{ |
| 654 |
Teuchos::ParameterList& p = ipb->sublist("b"); |
| 655 |
p.set("Type","Energy"); |
| 656 |
p.set("Prefix","ION_"); |
| 657 |
p.set("Model ID","solid"); |
| 658 |
p.set("Basis Type","HCurl"); |
| 659 |
p.set("Basis Order",1); |
| 660 |
p.set("Integration Order",1); |
| 661 |
} |
| 662 |
|
| 663 |
} |
| 664 |
|
| 665 |
} |