| 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 "Teuchos_DefaultComm.hpp" |
| 20 |
#include "Teuchos_GlobalMPISession.hpp" |
| 21 |
|
| 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_BlockedDOFManagerFactory.hpp" |
| 38 |
#include "Panzer_LinearObjFactory_Utilities.hpp" |
| 39 |
#include "Panzer_ModelEvaluator.hpp" |
| 40 |
#include "Panzer_ResponseLibrary.hpp" |
| 41 |
#include "Panzer_GlobalData.hpp" |
| 42 |
#include "Panzer_WorksetContainer.hpp" |
| 43 |
#include "Panzer_PauseToAttach.hpp" |
| 44 |
#include "Panzer_ResponseEvaluatorFactory_Functional.hpp" |
| 45 |
#include "Panzer_ParameterLibraryUtilities.hpp" |
| 46 |
#include "Panzer_ThyraObjContainer.hpp" |
| 47 |
#include "Panzer_ThyraObjFactory.hpp" |
| 48 |
#include "Panzer_Response_Residual.hpp" |
| 49 |
#include "Panzer_DOFManager.hpp" |
| 50 |
#include "Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.hpp" |
| 51 |
|
| 52 |
#include "user_app_EquationSetFactory.hpp" |
| 53 |
#include "user_app_ClosureModel_Factory_TemplateBuilder.hpp" |
| 54 |
#include "user_app_BCStrategy_Factory.hpp" |
| 55 |
|
| 56 |
#include "Epetra_MpiComm.h" |
| 57 |
|
| 58 |
#include "Teuchos_DefaultMpiComm.hpp" |
| 59 |
#include "Teuchos_OpaqueWrapper.hpp" |
| 60 |
|
| 61 |
#include "Thyra_LinearOpTester.hpp" |
| 62 |
#include "Thyra_get_Epetra_Operator.hpp" |
| 63 |
|
| 64 |
#include <limits> |
| 65 |
|
| 66 |
namespace panzer { |
| 67 |
|
| 68 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 69 |
std::vector<panzer::BC>& bcs); |
| 70 |
|
| 71 |
struct AssemblyPieces { |
| 72 |
RCP<panzer::FieldManagerBuilder> fmb; |
| 73 |
RCP<panzer::ResponseLibrary<panzer::Traits> > rLibrary; |
| 74 |
RCP<panzer::GlobalData> gd; |
| 75 |
RCP<panzer::LinearObjFactory<panzer::Traits> > lof; |
| 76 |
RCP<const panzer::LinearObjFactory<panzer::Traits> > param_lof; |
| 77 |
RCP<const panzer::GlobalIndexer> dofManager; |
| 78 |
RCP<panzer::GlobalIndexer> param_dofManager; |
| 79 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer; |
| 80 |
Teuchos::ParameterList user_data; |
| 81 |
std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; |
| 82 |
Teuchos::RCP<panzer::EquationSetFactory> eqset_factory; |
| 83 |
panzer::ClosureModelFactory_TemplateManager<panzer::Traits> cm_factory; |
| 84 |
Teuchos::ParameterList closure_models; |
| 85 |
std::vector<panzer::BC> bcs; |
| 86 |
Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData> param_ged; |
| 87 |
}; |
| 88 |
|
| 89 |
void buildAssemblyPieces(bool parameter_on,bool distr_parameter_on, |
| 90 |
AssemblyPieces & ap, |
| 91 |
bool useBlocking=false); |
| 92 |
|
| 93 |
bool testEqualityOfVectorValues(const Thyra::VectorBase<double> & a, |
| 94 |
const Thyra::VectorBase<double> & b, |
| 95 |
double tolerance, bool write_to_cout=false); |
| 96 |
|
| 97 |
// Test that the response library can build the correct residual and jacobian |
| 98 |
TEUCHOS_UNIT_TEST(response_residual, basic) |
| 99 |
{ |
| 100 |
typedef panzer::Traits::RealType RealType; |
| 101 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 102 |
typedef Thyra::LinearOpBase<RealType> OperatorType; |
| 103 |
|
| 104 |
using Teuchos::RCP; |
| 105 |
using Teuchos::rcp_dynamic_cast; |
| 106 |
|
| 107 |
bool parameter_on = false; |
| 108 |
bool distr_param_on = true; |
| 109 |
AssemblyPieces ap; |
| 110 |
buildAssemblyPieces(parameter_on,distr_param_on,ap); |
| 111 |
|
| 112 |
// Use the model evaluator to setup a bunch of comparisons |
| 113 |
/////////////////////////////////////////////////////////////////////// |
| 114 |
RCP<VectorType> x; |
| 115 |
RCP<VectorType> x_dot; |
| 116 |
RCP<VectorType> f_me; |
| 117 |
RCP<OperatorType> J_me; |
| 118 |
double alpha = 1.3, beta = 0.2; |
| 119 |
|
| 120 |
RCP<const ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<const ThyraObjFactory<double> >(ap.param_lof); |
| 121 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 122 |
std::cout << Teuchos::describe(*param_density,Teuchos::VERB_MEDIUM) << std::endl; |
| 123 |
Thyra::assign(param_density.ptr(),3.7); |
| 124 |
|
| 125 |
{ |
| 126 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 127 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 128 |
typedef panzer::ModelEvaluator<double> PME; |
| 129 |
|
| 130 |
|
| 131 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 132 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 133 |
bool build_transient_support = true; |
| 134 |
|
| 135 |
RCP<PME> me = Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 136 |
me->addDistributedParameter("DENSITY",th_param_lof->getThyraDomainSpace(),ap.param_ged,param_density); |
| 137 |
|
| 138 |
x = Thyra::createMember(*me->get_x_space()); |
| 139 |
x_dot = Thyra::createMember(*me->get_x_space()); |
| 140 |
|
| 141 |
Thyra::randomize(-1.0,1.0,x.ptr()); |
| 142 |
Thyra::randomize(-1.0,1.0,x_dot.ptr()); |
| 143 |
|
| 144 |
InArgs in_args = me->createInArgs(); |
| 145 |
in_args.set_x(x); |
| 146 |
in_args.set_x_dot(x_dot); |
| 147 |
in_args.set_alpha(alpha); |
| 148 |
in_args.set_beta(beta); |
| 149 |
|
| 150 |
OutArgs out_args = me->createOutArgs(); |
| 151 |
f_me = Thyra::createMember(*me->get_f_space()); |
| 152 |
J_me = me->create_W_op(); |
| 153 |
out_args.set_f(f_me); |
| 154 |
out_args.set_W_op(J_me); |
| 155 |
|
| 156 |
me->evalModel(in_args, out_args); |
| 157 |
} |
| 158 |
|
| 159 |
bool residualType = true; |
| 160 |
RCP<ResponseLibrary<Traits> > rLibrary |
| 161 |
= Teuchos::rcp(new ResponseLibrary<Traits>(ap.wkstContainer,ap.dofManager,ap.lof,residualType)); |
| 162 |
|
| 163 |
// verify the residual type |
| 164 |
TEST_ASSERT(rLibrary->isResidualType()); |
| 165 |
|
| 166 |
// test that responses are the right type |
| 167 |
{ |
| 168 |
RCP<ResponseBase> response_residual = rLibrary->getResponse<Traits::Residual>("RESIDUAL"); |
| 169 |
RCP<ResponseBase> response_jacobian = rLibrary->getResponse<Traits::Jacobian>("RESIDUAL"); |
| 170 |
|
| 171 |
TEST_ASSERT(response_residual!=Teuchos::null); |
| 172 |
TEST_ASSERT(response_jacobian!=Teuchos::null); |
| 173 |
|
| 174 |
TEST_NOTHROW(Teuchos::rcp_dynamic_cast<Response_Residual<Traits::Residual> >(response_residual,true)); |
| 175 |
TEST_NOTHROW(Teuchos::rcp_dynamic_cast<Response_Residual<Traits::Jacobian> >(response_jacobian,true)); |
| 176 |
} |
| 177 |
|
| 178 |
// build residual response evaluators |
| 179 |
{ |
| 180 |
user_app::BCFactory bc_factory; |
| 181 |
|
| 182 |
TEST_ASSERT(!rLibrary->responseEvaluatorsBuilt()); |
| 183 |
|
| 184 |
rLibrary->buildResidualResponseEvaluators(ap.physicsBlocks,*ap.eqset_factory,ap.bcs,bc_factory, |
| 185 |
ap.cm_factory,ap.closure_models,ap.user_data); |
| 186 |
|
| 187 |
TEST_ASSERT(rLibrary->responseEvaluatorsBuilt()); |
| 188 |
} |
| 189 |
|
| 190 |
RCP<Response_Residual<Traits::Residual> > response_residual = |
| 191 |
rcp_dynamic_cast<Response_Residual<Traits::Residual> >(rLibrary->getResponse<Traits::Residual>("RESIDUAL")); |
| 192 |
RCP<Response_Residual<Traits::Jacobian> > response_jacobian = |
| 193 |
rcp_dynamic_cast<Response_Residual<Traits::Jacobian> >(rLibrary->getResponse<Traits::Jacobian>("RESIDUAL")); |
| 194 |
|
| 195 |
Teuchos::RCP<panzer::ReadOnlyVector_GlobalEvaluationData> resp_param_ged = ap.param_lof->buildReadOnlyDomainContainer(); |
| 196 |
resp_param_ged->setOwnedVector(param_density); |
| 197 |
|
| 198 |
// evaluate residual responses |
| 199 |
{ |
| 200 |
// set solution vectors |
| 201 |
RCP<LinearObjContainer> loc = ap.lof->buildLinearObjContainer(); |
| 202 |
RCP<LinearObjContainer> gloc = ap.lof->buildGhostedLinearObjContainer(); |
| 203 |
|
| 204 |
RCP<ReadOnlyVector_GlobalEvaluationData> xContainer = ap.lof->buildReadOnlyDomainContainer(); |
| 205 |
RCP<ReadOnlyVector_GlobalEvaluationData> xdotContainer = ap.lof->buildReadOnlyDomainContainer(); |
| 206 |
|
| 207 |
xContainer->setOwnedVector(x); |
| 208 |
xdotContainer->setOwnedVector(x_dot); |
| 209 |
|
| 210 |
// setup output arguments for the residual response |
| 211 |
response_residual->setResidual(response_residual->allocateResidualVector()); |
| 212 |
|
| 213 |
// setup in arguments |
| 214 |
AssemblyEngineInArgs ae_inargs(gloc,loc); |
| 215 |
ae_inargs.addGlobalEvaluationData("DENSITY",resp_param_ged); |
| 216 |
ae_inargs.addGlobalEvaluationData("Solution Gather Container - X",xContainer); |
| 217 |
ae_inargs.addGlobalEvaluationData("Solution Gather Container - Xdot",xdotContainer); |
| 218 |
ae_inargs.alpha = alpha; |
| 219 |
ae_inargs.beta = beta; |
| 220 |
ae_inargs.time = 0.0; |
| 221 |
ae_inargs.evaluate_transient_terms = true; |
| 222 |
|
| 223 |
rLibrary->addResponsesToInArgs<Traits::Residual>(ae_inargs); |
| 224 |
|
| 225 |
// evaluate |
| 226 |
rLibrary->evaluate<Traits::Residual>(ae_inargs); |
| 227 |
|
| 228 |
TEST_ASSERT(testEqualityOfVectorValues(*response_residual->getResidual(),*f_me,1e-15,true)); |
| 229 |
} |
| 230 |
|
| 231 |
// evaluate jacobian responses |
| 232 |
{ |
| 233 |
// set solution vectors |
| 234 |
RCP<LinearObjContainer> loc = ap.lof->buildLinearObjContainer(); |
| 235 |
rcp_dynamic_cast<ThyraObjContainer<RealType> >(loc)->set_x_th(x); |
| 236 |
rcp_dynamic_cast<ThyraObjContainer<RealType> >(loc)->set_dxdt_th(x_dot); |
| 237 |
|
| 238 |
// allocate fill vectors |
| 239 |
RCP<LinearObjContainer> gloc = ap.lof->buildGhostedLinearObjContainer(); |
| 240 |
|
| 241 |
RCP<ReadOnlyVector_GlobalEvaluationData> xContainer = ap.lof->buildReadOnlyDomainContainer(); |
| 242 |
RCP<ReadOnlyVector_GlobalEvaluationData> xdotContainer = ap.lof->buildReadOnlyDomainContainer(); |
| 243 |
|
| 244 |
xContainer->setOwnedVector(x); |
| 245 |
xdotContainer->setOwnedVector(x_dot); |
| 246 |
|
| 247 |
// setup output arguments for the residual response |
| 248 |
response_jacobian->setJacobian(response_jacobian->allocateJacobian()); |
| 249 |
|
| 250 |
// setup in arguments |
| 251 |
AssemblyEngineInArgs ae_inargs(gloc,loc); |
| 252 |
ae_inargs.addGlobalEvaluationData("DENSITY",resp_param_ged); |
| 253 |
ae_inargs.addGlobalEvaluationData("Solution Gather Container - X",xContainer); |
| 254 |
ae_inargs.addGlobalEvaluationData("Solution Gather Container - Xdot",xdotContainer); |
| 255 |
|
| 256 |
ae_inargs.alpha = alpha; |
| 257 |
ae_inargs.beta = beta; |
| 258 |
ae_inargs.evaluate_transient_terms = true; |
| 259 |
rLibrary->addResponsesToInArgs<Traits::Jacobian>(ae_inargs); |
| 260 |
|
| 261 |
// evaluate |
| 262 |
rLibrary->evaluate<Traits::Jacobian>(ae_inargs); |
| 263 |
|
| 264 |
Thyra::LinearOpTester<double> tester; |
| 265 |
tester.show_all_tests(true); |
| 266 |
tester.set_all_error_tol(10.0 * std::numeric_limits<double>::epsilon()); |
| 267 |
tester.num_random_vectors(20); |
| 268 |
|
| 269 |
Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout)); |
| 270 |
const bool op_cmp = tester.compare( *J_me, *response_jacobian->getJacobian(), Teuchos::ptrFromRef(fout)); |
| 271 |
TEST_ASSERT(op_cmp); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
bool comparison(double a,double b) |
| 276 |
{ |
| 277 |
double exact = std::fabs(a+b)/2.0; |
| 278 |
|
| 279 |
if(exact>1e-12) |
| 280 |
return (std::fabs(a-b)/exact) < 1e-12; |
| 281 |
else |
| 282 |
return (std::fabs(a-b)) < 1e-12; |
| 283 |
} |
| 284 |
|
| 285 |
// Test that the response library can build the correct residual and jacobian |
| 286 |
TEUCHOS_UNIT_TEST(response_residual, distr_parameter) |
| 287 |
{ |
| 288 |
typedef panzer::Traits::RealType RealType; |
| 289 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 290 |
typedef Thyra::LinearOpBase<RealType> OperatorType; |
| 291 |
|
| 292 |
using Teuchos::RCP; |
| 293 |
using Teuchos::rcp_dynamic_cast; |
| 294 |
|
| 295 |
bool parameter_on = false; |
| 296 |
bool distr_param_on = true; |
| 297 |
AssemblyPieces ap; |
| 298 |
buildAssemblyPieces(parameter_on,distr_param_on,ap); |
| 299 |
|
| 300 |
RCP<ThyraObjFactory<double> > th_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.lof); |
| 301 |
RCP<const ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<const ThyraObjFactory<double> >(ap.param_lof); |
| 302 |
|
| 303 |
// Use the model evaluator to setup a bunch of comparisons |
| 304 |
/////////////////////////////////////////////////////////////////////// |
| 305 |
RCP<VectorType> x = Thyra::createMember(th_lof->getThyraDomainSpace()); |
| 306 |
RCP<VectorType> x_dot = Thyra::createMember(th_lof->getThyraDomainSpace()); |
| 307 |
RCP<VectorType> f = Thyra::createMember(th_lof->getThyraRangeSpace()); |
| 308 |
|
| 309 |
RCP<OperatorType> J = th_param_lof->getThyraMatrix(); |
| 310 |
|
| 311 |
Thyra::randomize(-1.0,1.0,x.ptr()); |
| 312 |
Thyra::put_scalar(1.0,x_dot.ptr()); |
| 313 |
|
| 314 |
double alpha = Teuchos::ScalarTraits<double>::nan(); |
| 315 |
double beta = Teuchos::ScalarTraits<double>::nan(); |
| 316 |
|
| 317 |
bool residualType = true; |
| 318 |
RCP<ResponseLibrary<Traits> > rLibrary |
| 319 |
= Teuchos::rcp(new ResponseLibrary<Traits>(ap.wkstContainer,ap.dofManager,ap.param_lof,residualType)); |
| 320 |
|
| 321 |
// verify the residual type |
| 322 |
TEST_ASSERT(rLibrary->isResidualType()); |
| 323 |
|
| 324 |
// test that responses are the right type |
| 325 |
{ |
| 326 |
RCP<ResponseBase> response_jacobian = rLibrary->getResponse<Traits::Jacobian>("RESIDUAL"); |
| 327 |
|
| 328 |
TEST_ASSERT(response_jacobian!=Teuchos::null); |
| 329 |
|
| 330 |
TEST_NOTHROW(Teuchos::rcp_dynamic_cast<Response_Residual<Traits::Jacobian> >(response_jacobian,true)); |
| 331 |
} |
| 332 |
|
| 333 |
// build residual response evaluators |
| 334 |
{ |
| 335 |
user_app::BCFactory bc_factory; |
| 336 |
|
| 337 |
TEST_ASSERT(!rLibrary->responseEvaluatorsBuilt()); |
| 338 |
|
| 339 |
rLibrary->buildResidualResponseEvaluators(ap.physicsBlocks,*ap.eqset_factory,ap.bcs,bc_factory, |
| 340 |
ap.cm_factory,ap.closure_models,ap.user_data); |
| 341 |
|
| 342 |
TEST_ASSERT(rLibrary->responseEvaluatorsBuilt()); |
| 343 |
} |
| 344 |
|
| 345 |
RCP<Response_Residual<Traits::Jacobian> > response_jacobian = |
| 346 |
rcp_dynamic_cast<Response_Residual<Traits::Jacobian> >(rLibrary->getResponse<Traits::Jacobian>("RESIDUAL")); |
| 347 |
|
| 348 |
Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData> resp_param_ged = ap.param_lof->buildReadOnlyDomainContainer(); |
| 349 |
|
| 350 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 351 |
Thyra::assign(param_density.ptr(),3.7); |
| 352 |
resp_param_ged->setOwnedVector(param_density); |
| 353 |
|
| 354 |
// evaluate residual responses |
| 355 |
{ |
| 356 |
// set solution vectors |
| 357 |
RCP<LinearObjContainer> loc = ap.lof->buildLinearObjContainer(); |
| 358 |
RCP<LinearObjContainer> gloc = ap.param_lof->buildGhostedLinearObjContainer(); |
| 359 |
|
| 360 |
RCP<ReadOnlyVector_GlobalEvaluationData> xContainer = ap.lof->buildReadOnlyDomainContainer(); |
| 361 |
RCP<ReadOnlyVector_GlobalEvaluationData> xdotContainer = ap.lof->buildReadOnlyDomainContainer(); |
| 362 |
|
| 363 |
xContainer->setOwnedVector(x); |
| 364 |
xdotContainer->setOwnedVector(x_dot); |
| 365 |
|
| 366 |
// setup output arguments for the residual response |
| 367 |
response_jacobian->setJacobian(response_jacobian->allocateJacobian()); |
| 368 |
|
| 369 |
// setup in arguments |
| 370 |
AssemblyEngineInArgs ae_inargs(gloc,loc); |
| 371 |
ae_inargs.addGlobalEvaluationData("DENSITY",resp_param_ged); |
| 372 |
ae_inargs.addGlobalEvaluationData("Solution Gather Container - X",xContainer); |
| 373 |
ae_inargs.addGlobalEvaluationData("Solution Gather Container - Xdot",xdotContainer); |
| 374 |
ae_inargs.alpha = alpha; |
| 375 |
ae_inargs.beta = beta; |
| 376 |
ae_inargs.evaluate_transient_terms = true; |
| 377 |
ae_inargs.first_sensitivities_name = "DENSITY"; |
| 378 |
ae_inargs.gather_seeds.push_back(1.0); // gather seed index 0 (see closure model) |
| 379 |
rLibrary->addResponsesToInArgs<Traits::Jacobian>(ae_inargs); |
| 380 |
|
| 381 |
// evaluate |
| 382 |
rLibrary->evaluate<Traits::Jacobian>(ae_inargs); |
| 383 |
|
| 384 |
// std::cout << Teuchos::describe(*response_jacobian->getJacobian(),Teuchos::VERB_EXTREME) << std::endl; |
| 385 |
} |
| 386 |
|
| 387 |
// test the jacobian for correctness |
| 388 |
{ |
| 389 |
|
| 390 |
// build vectors for each type of node |
| 391 |
std::vector<double> corner(4); |
| 392 |
corner[0] = 1./1152.; corner[1] = 1./576.; |
| 393 |
corner[2] = 1./288.; corner[3] = 1./128.; |
| 394 |
|
| 395 |
std::vector<double> edge(6); |
| 396 |
edge[0] = 1./1152.; edge[1] = 1./1152.; edge[2] = 1./576.; |
| 397 |
edge[3] = 1./576.; edge[4] = 1./288.; edge[5] = 1./144.; |
| 398 |
|
| 399 |
std::vector<double> volume(9); |
| 400 |
volume[0] = 1./1152.; volume[1] = 1./1152.; volume[2] = 1./1152.; |
| 401 |
volume[3] = 1./1152.; volume[4] = 1./288.; volume[5] = 1./288.; |
| 402 |
volume[6] = 1./288.; volume[7] = 1./288.; volume[8] = 1./72.; |
| 403 |
|
| 404 |
RCP<const Thyra::LinearOpBase<double> > thJac = response_jacobian->getJacobian(); |
| 405 |
RCP<const Epetra_CrsMatrix> jac = rcp_dynamic_cast<const Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*thJac)); |
| 406 |
|
| 407 |
TEUCHOS_ASSERT(jac!=Teuchos::null); |
| 408 |
|
| 409 |
for(int i=0;i<jac->NumMyRows();i++) { |
| 410 |
int numEntries = -1; |
| 411 |
int * indices = 0; |
| 412 |
double * values = 0; |
| 413 |
|
| 414 |
// get a view of the row entries |
| 415 |
jac->ExtractMyRowView(i,numEntries,values,indices); |
| 416 |
|
| 417 |
TEUCHOS_ASSERT(numEntries>0); |
| 418 |
|
| 419 |
// sort the row entries |
| 420 |
std::vector<double> sorted_values(numEntries); |
| 421 |
for(int j=0;j<numEntries;j++) |
| 422 |
sorted_values.push_back(values[j]); |
| 423 |
std::sort(sorted_values.begin(),sorted_values.end()); |
| 424 |
|
| 425 |
if(sorted_values[0]!=sorted_values[sorted_values.size()-1]) { |
| 426 |
std::vector<double>::const_iterator found_itr; |
| 427 |
|
| 428 |
/////////////////////////////////////////////////////////////////////// |
| 429 |
|
| 430 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 431 |
corner.begin(),corner.end(),comparison); |
| 432 |
|
| 433 |
// test passed this row corresponds to a corner |
| 434 |
if(found_itr!=corner.end()) |
| 435 |
continue; |
| 436 |
|
| 437 |
/////////////////////////////////////////////////////////////////////// |
| 438 |
|
| 439 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 440 |
edge.begin(),edge.end(),comparison); |
| 441 |
|
| 442 |
// test passed this row corresponds to a edge |
| 443 |
if(found_itr!=edge.end()) |
| 444 |
continue; |
| 445 |
|
| 446 |
/////////////////////////////////////////////////////////////////////// |
| 447 |
|
| 448 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 449 |
volume.begin(),volume.end(),comparison); |
| 450 |
|
| 451 |
// test passed this row corresponds to a volume |
| 452 |
if(found_itr!=volume.end()) |
| 453 |
continue; |
| 454 |
|
| 455 |
/////////////////////////////////////////////////////////////////////// |
| 456 |
|
| 457 |
TEST_ASSERT(false); // non of the required row types were found |
| 458 |
|
| 459 |
out << "Row didn't match expectation " << i << ": "; |
| 460 |
for(std::size_t si=0;si<sorted_values.size();++si) |
| 461 |
out << sorted_values[si] << " "; |
| 462 |
out << std::endl; |
| 463 |
} |
| 464 |
else { |
| 465 |
TEST_ASSERT(sorted_values[0]==0.0); |
| 466 |
TEST_ASSERT(sorted_values[sorted_values.size()-1]==0.0); |
| 467 |
} |
| 468 |
|
| 469 |
} |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
// Test that the response library can build the correct residual and jacobian |
| 474 |
TEUCHOS_UNIT_TEST(response_residual, dfdp_in_model_eval) |
| 475 |
{ |
| 476 |
typedef panzer::Traits::RealType RealType; |
| 477 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 478 |
|
| 479 |
using Teuchos::RCP; |
| 480 |
using Teuchos::rcp_dynamic_cast; |
| 481 |
|
| 482 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 483 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 484 |
typedef panzer::ModelEvaluator<double> PME; |
| 485 |
|
| 486 |
bool parameter_on = false; |
| 487 |
bool distr_param_on = true; |
| 488 |
AssemblyPieces ap; |
| 489 |
buildAssemblyPieces(parameter_on,distr_param_on,ap); |
| 490 |
|
| 491 |
RCP<const ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<const ThyraObjFactory<double> >(ap.param_lof); |
| 492 |
|
| 493 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 494 |
std::cout << Teuchos::describe(*param_density,Teuchos::VERB_MEDIUM) << std::endl; |
| 495 |
Thyra::assign(param_density.ptr(),3.7); |
| 496 |
int pIndex = -1; |
| 497 |
|
| 498 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 499 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 500 |
bool build_transient_support = true; |
| 501 |
|
| 502 |
user_app::BCFactory bc_factory; |
| 503 |
RCP<PME> me |
| 504 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 505 |
pIndex = me->addDistributedParameter("DENSITY",th_param_lof->getThyraDomainSpace(), |
| 506 |
ap.param_ged,param_density,ap.param_dofManager); |
| 507 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 508 |
*ap.eqset_factory, |
| 509 |
bc_factory, |
| 510 |
ap.cm_factory, |
| 511 |
ap.cm_factory, |
| 512 |
ap.closure_models, |
| 513 |
ap.user_data,false,""); |
| 514 |
|
| 515 |
RCP<Thyra::LinearOpBase<double> > DfDp = me->create_DfDp_op(pIndex); |
| 516 |
|
| 517 |
TEST_ASSERT(DfDp!=Teuchos::null); |
| 518 |
TEST_ASSERT(DfDp->range()->isCompatible(*me->get_f_space())); |
| 519 |
TEST_ASSERT(DfDp->domain()->isCompatible(*th_param_lof->getThyraDomainSpace())); |
| 520 |
|
| 521 |
RCP<Thyra::VectorBase<double> > x = Thyra::createMember(*me->get_x_space()); |
| 522 |
RCP<Thyra::VectorBase<double> > x_dot = Thyra::createMember(*me->get_x_space()); |
| 523 |
Thyra::randomize(-1.0,1.0,x.ptr()); |
| 524 |
Thyra::randomize(-1.0,1.0,x_dot.ptr()); |
| 525 |
|
| 526 |
InArgs inArgs = me->createInArgs(); |
| 527 |
inArgs.set_x(x); |
| 528 |
inArgs.set_x_dot(x_dot); |
| 529 |
inArgs.set_alpha(Teuchos::ScalarTraits<double>::nan()); // make sure these don't percolate through! |
| 530 |
inArgs.set_beta(Teuchos::ScalarTraits<double>::nan()); // make sure these don't percolate through! |
| 531 |
|
| 532 |
OutArgs outArgs = me->createOutArgs(); |
| 533 |
outArgs.set_DfDp(pIndex,DfDp); |
| 534 |
|
| 535 |
me->evalModel(inArgs,outArgs); |
| 536 |
|
| 537 |
// test the jacobian for correctness |
| 538 |
{ |
| 539 |
|
| 540 |
// build vectors for each type of node |
| 541 |
std::vector<double> corner(4); |
| 542 |
corner[0] = 1./1152.; corner[1] = 1./576.; |
| 543 |
corner[2] = 1./288.; corner[3] = 1./128.; |
| 544 |
|
| 545 |
std::vector<double> edge(6); |
| 546 |
edge[0] = 1./1152.; edge[1] = 1./1152.; edge[2] = 1./576.; |
| 547 |
edge[3] = 1./576.; edge[4] = 1./288.; edge[5] = 1./144.; |
| 548 |
|
| 549 |
std::vector<double> volume(9); |
| 550 |
volume[0] = 1./1152.; volume[1] = 1./1152.; volume[2] = 1./1152.; |
| 551 |
volume[3] = 1./1152.; volume[4] = 1./288.; volume[5] = 1./288.; |
| 552 |
volume[6] = 1./288.; volume[7] = 1./288.; volume[8] = 1./72.; |
| 553 |
|
| 554 |
RCP<const Epetra_CrsMatrix> jac = rcp_dynamic_cast<const Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*DfDp)); |
| 555 |
|
| 556 |
TEUCHOS_ASSERT(jac!=Teuchos::null); |
| 557 |
|
| 558 |
for(int i=0;i<jac->NumMyRows();i++) { |
| 559 |
int numEntries = -1; |
| 560 |
int * indices = 0; |
| 561 |
double * values = 0; |
| 562 |
|
| 563 |
// get a view of the row entries |
| 564 |
jac->ExtractMyRowView(i,numEntries,values,indices); |
| 565 |
|
| 566 |
TEUCHOS_ASSERT(numEntries>0); |
| 567 |
|
| 568 |
// sort the row entries |
| 569 |
std::vector<double> sorted_values(numEntries); |
| 570 |
for(int j=0;j<numEntries;j++) |
| 571 |
sorted_values.push_back(values[j]); |
| 572 |
std::sort(sorted_values.begin(),sorted_values.end()); |
| 573 |
|
| 574 |
if(sorted_values[0]!=sorted_values[sorted_values.size()-1]) { |
| 575 |
std::vector<double>::const_iterator found_itr; |
| 576 |
|
| 577 |
/////////////////////////////////////////////////////////////////////// |
| 578 |
|
| 579 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 580 |
corner.begin(),corner.end(),comparison); |
| 581 |
|
| 582 |
// test passed this row corresponds to a corner |
| 583 |
if(found_itr!=corner.end()) |
| 584 |
continue; |
| 585 |
|
| 586 |
/////////////////////////////////////////////////////////////////////// |
| 587 |
|
| 588 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 589 |
edge.begin(),edge.end(),comparison); |
| 590 |
|
| 591 |
// test passed this row corresponds to a edge |
| 592 |
if(found_itr!=edge.end()) |
| 593 |
continue; |
| 594 |
|
| 595 |
/////////////////////////////////////////////////////////////////////// |
| 596 |
|
| 597 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 598 |
volume.begin(),volume.end(),comparison); |
| 599 |
|
| 600 |
// test passed this row corresponds to a volume |
| 601 |
if(found_itr!=volume.end()) |
| 602 |
continue; |
| 603 |
|
| 604 |
/////////////////////////////////////////////////////////////////////// |
| 605 |
|
| 606 |
TEST_ASSERT(false); // non of the required row types were found |
| 607 |
|
| 608 |
out << "Row didn't match expectation " << i << ": "; |
| 609 |
for(std::size_t j=0;j<sorted_values.size();++j) |
| 610 |
out << sorted_values[j] << " "; |
| 611 |
out << std::endl; |
| 612 |
} |
| 613 |
else { |
| 614 |
TEST_ASSERT(sorted_values[0]==0.0); |
| 615 |
TEST_ASSERT(sorted_values[sorted_values.size()-1]==0.0); |
| 616 |
} |
| 617 |
|
| 618 |
} |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
// Test that the response library can build the correct residual and jacobian |
| 623 |
TEUCHOS_UNIT_TEST(response_residual, blocked_dfdp_in_model_eval) |
| 624 |
{ |
| 625 |
typedef panzer::Traits::RealType RealType; |
| 626 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 627 |
|
| 628 |
using Teuchos::RCP; |
| 629 |
using Teuchos::rcp_dynamic_cast; |
| 630 |
|
| 631 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 632 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 633 |
typedef panzer::ModelEvaluator<double> PME; |
| 634 |
|
| 635 |
bool parameter_on = false; |
| 636 |
bool distr_param_on = true; |
| 637 |
AssemblyPieces ap; |
| 638 |
buildAssemblyPieces(parameter_on,distr_param_on,ap,true); |
| 639 |
|
| 640 |
RCP<const ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<const ThyraObjFactory<double> >(ap.param_lof); |
| 641 |
|
| 642 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 643 |
std::cout << Teuchos::describe(*param_density,Teuchos::VERB_MEDIUM) << std::endl; |
| 644 |
Thyra::assign(param_density.ptr(),3.7); |
| 645 |
int pIndex = -1; |
| 646 |
|
| 647 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 648 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 649 |
bool build_transient_support = true; |
| 650 |
|
| 651 |
user_app::BCFactory bc_factory; |
| 652 |
RCP<PME> me |
| 653 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 654 |
pIndex = me->addDistributedParameter("DENSITY",th_param_lof->getThyraDomainSpace(), |
| 655 |
ap.param_ged,param_density,ap.param_dofManager); |
| 656 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 657 |
*ap.eqset_factory, |
| 658 |
bc_factory, |
| 659 |
ap.cm_factory, |
| 660 |
ap.cm_factory, |
| 661 |
ap.closure_models, |
| 662 |
ap.user_data,false,""); |
| 663 |
|
| 664 |
RCP<Thyra::LinearOpBase<double> > DfDp = me->create_DfDp_op(pIndex); |
| 665 |
|
| 666 |
TEST_ASSERT(DfDp!=Teuchos::null); |
| 667 |
TEST_ASSERT(DfDp->range()->isCompatible(*me->get_f_space())); |
| 668 |
TEST_ASSERT(DfDp->domain()->isCompatible(*th_param_lof->getThyraDomainSpace())); |
| 669 |
|
| 670 |
RCP<Thyra::VectorBase<double> > x = Thyra::createMember(*me->get_x_space()); |
| 671 |
RCP<Thyra::VectorBase<double> > x_dot = Thyra::createMember(*me->get_x_space()); |
| 672 |
Thyra::randomize(-1.0,1.0,x.ptr()); |
| 673 |
Thyra::randomize(-1.0,1.0,x_dot.ptr()); |
| 674 |
|
| 675 |
InArgs inArgs = me->createInArgs(); |
| 676 |
inArgs.set_x(x); |
| 677 |
inArgs.set_x_dot(x_dot); |
| 678 |
inArgs.set_alpha(Teuchos::ScalarTraits<double>::nan()); // make sure these don't percolate through! |
| 679 |
inArgs.set_beta(Teuchos::ScalarTraits<double>::nan()); // make sure these don't percolate through! |
| 680 |
|
| 681 |
OutArgs outArgs = me->createOutArgs(); |
| 682 |
outArgs.set_DfDp(pIndex,DfDp); |
| 683 |
|
| 684 |
me->evalModel(inArgs,outArgs); |
| 685 |
|
| 686 |
// test the jacobian for correctness |
| 687 |
{ |
| 688 |
|
| 689 |
// build vectors for each type of node |
| 690 |
std::vector<double> corner(4); |
| 691 |
corner[0] = 1./1152.; corner[1] = 1./576.; |
| 692 |
corner[2] = 1./288.; corner[3] = 1./128.; |
| 693 |
|
| 694 |
std::vector<double> edge(6); |
| 695 |
edge[0] = 1./1152.; edge[1] = 1./1152.; edge[2] = 1./576.; |
| 696 |
edge[3] = 1./576.; edge[4] = 1./288.; edge[5] = 1./144.; |
| 697 |
|
| 698 |
std::vector<double> volume(9); |
| 699 |
volume[0] = 1./1152.; volume[1] = 1./1152.; volume[2] = 1./1152.; |
| 700 |
volume[3] = 1./1152.; volume[4] = 1./288.; volume[5] = 1./288.; |
| 701 |
volume[6] = 1./288.; volume[7] = 1./288.; volume[8] = 1./72.; |
| 702 |
|
| 703 |
auto DfDp_blocked = rcp_dynamic_cast<const Thyra::BlockedLinearOpBase<double> >(DfDp); |
| 704 |
TEST_ASSERT(DfDp_blocked!=Teuchos::null); |
| 705 |
TEST_EQUALITY(DfDp_blocked->productRange()->numBlocks(),2); |
| 706 |
TEST_EQUALITY(DfDp_blocked->productDomain()->numBlocks(),1); |
| 707 |
|
| 708 |
{ |
| 709 |
TEUCHOS_ASSERT(DfDp_blocked->getBlock(1,0)!=Teuchos::null); |
| 710 |
auto J_10 = rcp_dynamic_cast<const Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*DfDp_blocked->getBlock(1,0))); |
| 711 |
TEST_ASSERT(J_10!=Teuchos::null); |
| 712 |
|
| 713 |
TEST_EQUALITY(J_10->NormInf(),0.0); |
| 714 |
} |
| 715 |
|
| 716 |
RCP<const Epetra_CrsMatrix> jac = rcp_dynamic_cast<const Epetra_CrsMatrix>(Thyra::get_Epetra_Operator(*DfDp_blocked->getBlock(0,0))); |
| 717 |
|
| 718 |
TEST_ASSERT(jac!=Teuchos::null); |
| 719 |
|
| 720 |
for(int i=0;i<jac->NumMyRows();i++) { |
| 721 |
int numEntries = -1; |
| 722 |
int * indices = 0; |
| 723 |
double * values = 0; |
| 724 |
|
| 725 |
// get a view of the row entries |
| 726 |
jac->ExtractMyRowView(i,numEntries,values,indices); |
| 727 |
|
| 728 |
TEUCHOS_ASSERT(numEntries>0); |
| 729 |
|
| 730 |
// sort the row entries |
| 731 |
std::vector<double> sorted_values(numEntries); |
| 732 |
for(int j=0;j<numEntries;j++) |
| 733 |
sorted_values.push_back(values[j]); |
| 734 |
std::sort(sorted_values.begin(),sorted_values.end()); |
| 735 |
|
| 736 |
if(sorted_values[0]!=sorted_values[sorted_values.size()-1]) { |
| 737 |
std::vector<double>::const_iterator found_itr; |
| 738 |
|
| 739 |
/////////////////////////////////////////////////////////////////////// |
| 740 |
|
| 741 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 742 |
corner.begin(),corner.end(),comparison); |
| 743 |
|
| 744 |
// test passed this row corresponds to a corner |
| 745 |
if(found_itr!=corner.end()) |
| 746 |
continue; |
| 747 |
|
| 748 |
/////////////////////////////////////////////////////////////////////// |
| 749 |
|
| 750 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 751 |
edge.begin(),edge.end(),comparison); |
| 752 |
|
| 753 |
// test passed this row corresponds to a edge |
| 754 |
if(found_itr!=edge.end()) |
| 755 |
continue; |
| 756 |
|
| 757 |
/////////////////////////////////////////////////////////////////////// |
| 758 |
|
| 759 |
found_itr = std::find_end(sorted_values.begin(),sorted_values.end(), |
| 760 |
volume.begin(),volume.end(),comparison); |
| 761 |
|
| 762 |
// test passed this row corresponds to a volume |
| 763 |
if(found_itr!=volume.end()) |
| 764 |
continue; |
| 765 |
|
| 766 |
/////////////////////////////////////////////////////////////////////// |
| 767 |
|
| 768 |
TEST_ASSERT(false); // non of the required row types were found |
| 769 |
|
| 770 |
out << "Row didn't match expectation " << i << ": "; |
| 771 |
for(std::size_t j=0;j<sorted_values.size();++j) |
| 772 |
out << sorted_values[j] << " "; |
| 773 |
out << std::endl; |
| 774 |
} |
| 775 |
else { |
| 776 |
TEST_ASSERT(sorted_values[0]==0.0); |
| 777 |
TEST_ASSERT(sorted_values[sorted_values.size()-1]==0.0); |
| 778 |
} |
| 779 |
|
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
bool testEqualityOfVectorValues(const Thyra::VectorBase<double> & a, |
| 785 |
const Thyra::VectorBase<double> & b, |
| 786 |
double tolerance, bool write_to_cout) |
| 787 |
{ |
| 788 |
bool is_equal = true; |
| 789 |
|
| 790 |
TEUCHOS_ASSERT(a.space()->dim() == b.space()->dim()); |
| 791 |
|
| 792 |
|
| 793 |
std::cout << "Size = " << a.space()->dim() << ", " << b.space()->dim() << std::endl; |
| 794 |
|
| 795 |
Teuchos::ArrayRCP<const double> a_data,b_data; |
| 796 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(a).getLocalData(Teuchos::ptrFromRef(a_data)); |
| 797 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(b).getLocalData(Teuchos::ptrFromRef(b_data)); |
| 798 |
|
| 799 |
for (int i = 0; i < a_data.size(); ++i) { |
| 800 |
|
| 801 |
std::string output = " equal!: "; |
| 802 |
|
| 803 |
if (std::fabs(a_data[i] - b_data[i]) > tolerance) { |
| 804 |
is_equal = false; |
| 805 |
output = "NOT equal!: "; |
| 806 |
} |
| 807 |
|
| 808 |
if (write_to_cout) |
| 809 |
std::cout << output << a_data[i] << " - " << b_data[i] << " = " << (a_data[i] - b_data[i]) << std::endl; |
| 810 |
} |
| 811 |
|
| 812 |
int globalSuccess = -1; |
| 813 |
Teuchos::RCP<const Teuchos::Comm<Teuchos::Ordinal> > comm = Teuchos::DefaultComm<Teuchos::Ordinal>::getComm(); |
| 814 |
Teuchos::reduceAll( *comm, Teuchos::REDUCE_SUM, is_equal ? 0 : 1, Teuchos::outArg(globalSuccess) ); |
| 815 |
return (globalSuccess==0); |
| 816 |
} |
| 817 |
|
| 818 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 819 |
std::vector<panzer::BC>& bcs) |
| 820 |
{ |
| 821 |
// Physics block |
| 822 |
Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); |
| 823 |
{ |
| 824 |
Teuchos::ParameterList& p = physics_block.sublist("a"); |
| 825 |
p.set("Type","Energy"); |
| 826 |
p.set("Prefix",""); |
| 827 |
p.set("Model ID","solid"); |
| 828 |
p.set("Basis Type","HGrad"); |
| 829 |
p.set("Basis Order",1); |
| 830 |
p.set("Integration Order",2); |
| 831 |
} |
| 832 |
|
| 833 |
{ |
| 834 |
Teuchos::ParameterList& p = physics_block.sublist("b"); |
| 835 |
p.set("Type","Energy"); |
| 836 |
p.set("Prefix","ION_"); |
| 837 |
p.set("Model ID","ion solid"); |
| 838 |
p.set("Basis Type","HGrad"); |
| 839 |
p.set("Basis Order",1); |
| 840 |
p.set("Integration Order",2); |
| 841 |
} |
| 842 |
|
| 843 |
{ |
| 844 |
std::size_t bc_id = 0; |
| 845 |
panzer::BCType neumann = BCT_Dirichlet; |
| 846 |
std::string sideset_id = "left"; |
| 847 |
std::string element_block_id = "eblock-0_0"; |
| 848 |
std::string dof_name = "TEMPERATURE"; |
| 849 |
std::string strategy = "Constant"; |
| 850 |
double value = 5.0; |
| 851 |
Teuchos::ParameterList p; |
| 852 |
p.set("Value",value); |
| 853 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 854 |
strategy, p); |
| 855 |
bcs.push_back(bc); |
| 856 |
} |
| 857 |
{ |
| 858 |
std::size_t bc_id = 1; |
| 859 |
panzer::BCType neumann = BCT_Dirichlet; |
| 860 |
std::string sideset_id = "right"; |
| 861 |
std::string element_block_id = "eblock-1_0"; |
| 862 |
std::string dof_name = "TEMPERATURE"; |
| 863 |
std::string strategy = "Constant"; |
| 864 |
double value = 5.0; |
| 865 |
Teuchos::ParameterList p; |
| 866 |
p.set("Value",value); |
| 867 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 868 |
strategy, p); |
| 869 |
bcs.push_back(bc); |
| 870 |
} |
| 871 |
{ |
| 872 |
std::size_t bc_id = 2; |
| 873 |
panzer::BCType neumann = BCT_Dirichlet; |
| 874 |
std::string sideset_id = "top"; |
| 875 |
std::string element_block_id = "eblock-1_0"; |
| 876 |
std::string dof_name = "TEMPERATURE"; |
| 877 |
std::string strategy = "Constant"; |
| 878 |
double value = 5.0; |
| 879 |
Teuchos::ParameterList p; |
| 880 |
p.set("Value",value); |
| 881 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 882 |
strategy, p); |
| 883 |
bcs.push_back(bc); |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
void buildAssemblyPieces(bool parameter_on,bool distr_parameter_on, |
| 888 |
AssemblyPieces & ap, |
| 889 |
bool useBlocking) |
| 890 |
{ |
| 891 |
using Teuchos::RCP; |
| 892 |
|
| 893 |
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); |
| 894 |
pl->set("X Blocks",2); |
| 895 |
pl->set("Y Blocks",1); |
| 896 |
pl->set("X Elements",4); |
| 897 |
pl->set("Y Elements",4); |
| 898 |
|
| 899 |
panzer_stk::SquareQuadMeshFactory factory; |
| 900 |
factory.setParameterList(pl); |
| 901 |
RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD); |
| 902 |
Teuchos::RCP<const Teuchos::Comm<int> > Comm = Teuchos::DefaultComm<int>::getComm(); |
| 903 |
Teuchos::RCP<const Teuchos::MpiComm<int> > mpiComm = Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(Comm); |
| 904 |
|
| 905 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks"); |
| 906 |
std::vector<panzer::BC> & bcs = ap.bcs; |
| 907 |
testInitialzation(ipb, bcs); |
| 908 |
|
| 909 |
|
| 910 |
ap.fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); |
| 911 |
|
| 912 |
// build physics blocks |
| 913 |
////////////////////////////////////////////////////////////// |
| 914 |
const std::size_t workset_size = 16; |
| 915 |
ap.eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 916 |
user_app::BCFactory bc_factory; |
| 917 |
ap.gd = panzer::createGlobalData(); |
| 918 |
{ |
| 919 |
std::map<std::string,std::string> block_ids_to_physics_ids; |
| 920 |
block_ids_to_physics_ids["eblock-0_0"] = "test physics"; |
| 921 |
block_ids_to_physics_ids["eblock-1_0"] = "test physics"; |
| 922 |
|
| 923 |
std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo; |
| 924 |
block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); |
| 925 |
block_ids_to_cell_topo["eblock-1_0"] = mesh->getCellTopology("eblock-1_0"); |
| 926 |
|
| 927 |
int default_integration_order = 1; |
| 928 |
|
| 929 |
bool build_transient_support = true; |
| 930 |
panzer::buildPhysicsBlocks(block_ids_to_physics_ids, |
| 931 |
block_ids_to_cell_topo, |
| 932 |
ipb, |
| 933 |
default_integration_order, |
| 934 |
workset_size, |
| 935 |
ap.eqset_factory, |
| 936 |
ap.gd, |
| 937 |
build_transient_support, |
| 938 |
ap.physicsBlocks); |
| 939 |
} |
| 940 |
|
| 941 |
// build worksets |
| 942 |
////////////////////////////////////////////////////////////// |
| 943 |
// build WorksetContainer |
| 944 |
Teuchos::RCP<panzer_stk::WorksetFactory> wkstFactory |
| 945 |
= Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory |
| 946 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation) |
| 947 |
= Teuchos::rcp(new panzer::WorksetContainer); |
| 948 |
wkstContainer->setFactory(wkstFactory); |
| 949 |
for(size_t i=0;i<ap.physicsBlocks.size();i++) |
| 950 |
wkstContainer->setNeeds(ap.physicsBlocks[i]->elementBlockID(),ap.physicsBlocks[i]->getWorksetNeeds()); |
| 951 |
wkstContainer->setWorksetSize(workset_size); |
| 952 |
ap.wkstContainer = wkstContainer; |
| 953 |
|
| 954 |
// build DOF Manager |
| 955 |
///////////////////////////////////////////////////////////// |
| 956 |
|
| 957 |
// build the connection manager |
| 958 |
const Teuchos::RCP<panzer::ConnManager> |
| 959 |
conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 960 |
|
| 961 |
// build the state dof manager and LOF |
| 962 |
if(!useBlocking) { |
| 963 |
panzer::DOFManagerFactory globalIndexerFactory; |
| 964 |
RCP<panzer::GlobalIndexer> dofManager |
| 965 |
= globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),ap.physicsBlocks,conn_manager); |
| 966 |
ap.dofManager = dofManager; |
| 967 |
|
| 968 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory |
| 969 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,dofManager)); |
| 970 |
ap.lof = linObjFactory; |
| 971 |
} |
| 972 |
else { |
| 973 |
panzer::BlockedDOFManagerFactory globalIndexerFactory; |
| 974 |
auto dofManager = globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),ap.physicsBlocks, |
| 975 |
conn_manager,"blocked: TEMPERATURE ION_TEMPERATURE"); |
| 976 |
|
| 977 |
ap.dofManager = dofManager; |
| 978 |
|
| 979 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory |
| 980 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,dofManager)); |
| 981 |
ap.lof = linObjFactory; |
| 982 |
} |
| 983 |
|
| 984 |
// build the dof manager and LOF for DENSITY control |
| 985 |
if(distr_parameter_on) { |
| 986 |
Teuchos::RCP<panzer::DOFManager> dofManager |
| 987 |
= Teuchos::rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD)); |
| 988 |
|
| 989 |
Teuchos::RCP<Intrepid2FieldPattern> fp |
| 990 |
= Teuchos::rcp(new Intrepid2FieldPattern(panzer::createIntrepid2Basis<PHX::exec_space,double,double>("HGrad",1,mesh->getCellTopology("eblock-0_0")))); |
| 991 |
dofManager->addField("eblock-0_0","DENSITY",fp); |
| 992 |
dofManager->addField("eblock-1_0","DENSITY",fp); |
| 993 |
|
| 994 |
dofManager->setOrientationsRequired(false); |
| 995 |
dofManager->buildGlobalUnknowns(); |
| 996 |
|
| 997 |
// build a nonsquare LOF for the parameter vector |
| 998 |
Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> > linObjFactory = panzer::cloneWithNewDomain(*ap.lof,dofManager); |
| 999 |
|
| 1000 |
ap.param_dofManager = dofManager; |
| 1001 |
ap.param_ged = linObjFactory->buildReadOnlyDomainContainer(); |
| 1002 |
ap.param_lof = linObjFactory; |
| 1003 |
} |
| 1004 |
|
| 1005 |
ap.rLibrary = Teuchos::rcp(new panzer::ResponseLibrary<panzer::Traits>(wkstContainer,ap.dofManager,ap.lof)); |
| 1006 |
|
| 1007 |
// setup field manager build |
| 1008 |
///////////////////////////////////////////////////////////// |
| 1009 |
|
| 1010 |
// Add in the application specific closure model factory |
| 1011 |
user_app::MyModelFactory_TemplateBuilder cm_builder; |
| 1012 |
cm_builder.setDistributedParameterLOF(ap.param_lof); |
| 1013 |
ap.cm_factory.buildObjects(cm_builder); |
| 1014 |
|
| 1015 |
Teuchos::ParameterList closure_models("Closure Models"); |
| 1016 |
if(parameter_on) |
| 1017 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<std::string>("Type","Parameter"); |
| 1018 |
else |
| 1019 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<double>("Value",1.0); |
| 1020 |
|
| 1021 |
if(distr_parameter_on) |
| 1022 |
closure_models.sublist("solid").sublist("DENSITY").set("Type","Distributed Parameter"); |
| 1023 |
else |
| 1024 |
closure_models.sublist("solid").sublist("DENSITY").set<double>("Value",1.0); |
| 1025 |
closure_models.sublist("solid").sublist("HEAT_CAPACITY").set<double>("Value",1.0); |
| 1026 |
|
| 1027 |
closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE").set<double>("Value",1.0); |
| 1028 |
closure_models.sublist("ion solid").sublist("ION_DENSITY").set<double>("Value",1.0); |
| 1029 |
closure_models.sublist("ion solid").sublist("ION_HEAT_CAPACITY").set<double>("Value",1.0); |
| 1030 |
/* |
| 1031 |
closure_models.sublist("ion solid").sublist("SPY_A").set<std::string>("Value","Field Spy"); |
| 1032 |
closure_models.sublist("ion solid").sublist("SPY_A").set<std::string>("Source Field","ION_TEMPERATURE"); |
| 1033 |
closure_models.sublist("ion solid").sublist("SPY_B").set<std::string>("Value","Field Spy"); |
| 1034 |
closure_models.sublist("ion solid").sublist("SPY_B").set<std::string>("Source Field","DXDT_ION_TEMPERATURE"); |
| 1035 |
closure_models.sublist("ion solid").sublist("SPY_D").set<std::string>("Value","Field Spy Basis"); |
| 1036 |
closure_models.sublist("ion solid").sublist("SPY_D").set<std::string>("Source Field","RESIDUAL_ION_TEMPERATURE"); |
| 1037 |
closure_models.sublist("ion solid").sublist("SPY_E").set<std::string>("Value","Field Spy Basis"); |
| 1038 |
closure_models.sublist("ion solid").sublist("SPY_E").set<std::string>("Source Field","RESIDUAL_ION_TEMPERATURE_SOURCE_OP"); |
| 1039 |
closure_models.sublist("ion solid").sublist("SPY_F").set<std::string>("Value","Field Spy Basis"); |
| 1040 |
closure_models.sublist("ion solid").sublist("SPY_F").set<std::string>("Source Field","RESIDUAL_ION_TEMPERATURE_TRANSIENT_OP"); |
| 1041 |
closure_models.sublist("ion solid").sublist("SPY_G").set<std::string>("Value","Field Spy Basis"); |
| 1042 |
closure_models.sublist("ion solid").sublist("SPY_G").set<std::string>("Source Field","RESIDUAL_ION_TEMPERATURE_DIFFUSION_OP"); |
| 1043 |
*/ |
| 1044 |
|
| 1045 |
ap.closure_models = closure_models; |
| 1046 |
|
| 1047 |
ap.user_data = Teuchos::ParameterList("User Data"); |
| 1048 |
|
| 1049 |
ap.fmb->setWorksetContainer(wkstContainer); |
| 1050 |
ap.fmb->setupVolumeFieldManagers(ap.physicsBlocks,ap.cm_factory,ap.closure_models,*ap.lof,ap.user_data); |
| 1051 |
ap.fmb->setupBCFieldManagers(bcs,ap.physicsBlocks,*ap.eqset_factory,ap.cm_factory,bc_factory,ap.closure_models, |
| 1052 |
*ap.lof,ap.user_data); |
| 1053 |
} |
| 1054 |
|
| 1055 |
|
| 1056 |
} |