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