| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Panzer: A partial differential equation assembly |
| 4 |
// engine for strongly coupled complex multiphysics systems |
| 5 |
// |
| 6 |
// Copyright 2011 NTESS and the Panzer contributors. |
| 7 |
// SPDX-License-Identifier: BSD-3-Clause |
| 8 |
// ***************************************************************************** |
| 9 |
// @HEADER |
| 10 |
|
| 11 |
#include <Teuchos_ConfigDefs.hpp> |
| 12 |
#include <Teuchos_UnitTestHarness.hpp> |
| 13 |
#include <Teuchos_RCP.hpp> |
| 14 |
#include <Teuchos_TimeMonitor.hpp> |
| 15 |
|
| 16 |
using Teuchos::RCP; |
| 17 |
using Teuchos::rcp; |
| 18 |
|
| 19 |
#include "Panzer_NodeType.hpp" |
| 20 |
#include "Teuchos_DefaultComm.hpp" |
| 21 |
#include "Teuchos_GlobalMPISession.hpp" |
| 22 |
|
| 23 |
#include "Thyra_VectorStdOps.hpp" |
| 24 |
|
| 25 |
#include "Panzer_STK_Version.hpp" |
| 26 |
#include "PanzerAdaptersSTK_config.hpp" |
| 27 |
#include "Panzer_STK_Interface.hpp" |
| 28 |
#include "Panzer_STK_SquareQuadMeshFactory.hpp" |
| 29 |
#include "Panzer_STK_SetupUtilities.hpp" |
| 30 |
#include "Panzer_STK_WorksetFactory.hpp" |
| 31 |
#include "Panzer_Workset_Builder.hpp" |
| 32 |
#include "Panzer_FieldManagerBuilder.hpp" |
| 33 |
#include "Panzer_STKConnManager.hpp" |
| 34 |
#include "Panzer_TpetraLinearObjFactory.hpp" |
| 35 |
#include "Panzer_BlockedEpetraLinearObjFactory.hpp" |
| 36 |
#include "Panzer_AssemblyEngine.hpp" |
| 37 |
#include "Panzer_AssemblyEngine_TemplateManager.hpp" |
| 38 |
#include "Panzer_AssemblyEngine_TemplateBuilder.hpp" |
| 39 |
#include "Panzer_DOFManagerFactory.hpp" |
| 40 |
#include "Panzer_BlockedDOFManagerFactory.hpp" |
| 41 |
#include "Panzer_ModelEvaluator.hpp" |
| 42 |
#include "Panzer_ResponseLibrary.hpp" |
| 43 |
#include "Panzer_GlobalData.hpp" |
| 44 |
#include "Panzer_LOCPair_GlobalEvaluationData.hpp" |
| 45 |
#include "Panzer_WorksetContainer.hpp" |
| 46 |
#include "Panzer_PauseToAttach.hpp" |
| 47 |
#include "Panzer_ResponseEvaluatorFactory_Functional.hpp" |
| 48 |
#include "Panzer_ParameterLibraryUtilities.hpp" |
| 49 |
#include "Panzer_ThyraObjContainer.hpp" |
| 50 |
#include "Panzer_DOFManager.hpp" |
| 51 |
#include "Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.hpp" |
| 52 |
#include "Panzer_LinearObjFactory_Utilities.hpp" |
| 53 |
|
| 54 |
#include "user_app_EquationSetFactory.hpp" |
| 55 |
#include "user_app_ClosureModel_Factory_TemplateBuilder.hpp" |
| 56 |
#include "user_app_BCStrategy_Factory.hpp" |
| 57 |
|
| 58 |
#include "Teuchos_DefaultMpiComm.hpp" |
| 59 |
#include "Teuchos_OpaqueWrapper.hpp" |
| 60 |
|
| 61 |
#include <cstdio> // for get char |
| 62 |
#include <fstream> |
| 63 |
|
| 64 |
namespace panzer { |
| 65 |
|
| 66 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 67 |
std::vector<panzer::BC>& bcs); |
| 68 |
|
| 69 |
struct AssemblyPieces { |
| 70 |
RCP<panzer::FieldManagerBuilder> fmb; |
| 71 |
RCP<panzer::ResponseLibrary<panzer::Traits> > rLibrary; |
| 72 |
RCP<panzer::GlobalData> gd; |
| 73 |
RCP<panzer::LinearObjFactory<panzer::Traits> > lof; |
| 74 |
RCP<const panzer::LinearObjFactory<panzer::Traits> > param_lof; |
| 75 |
RCP<panzer::GlobalIndexer> dofManager; |
| 76 |
RCP<panzer::GlobalIndexer> param_dofManager; |
| 77 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer; |
| 78 |
Teuchos::ParameterList user_data; |
| 79 |
std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; |
| 80 |
Teuchos::RCP<panzer::EquationSetFactory> eqset_factory; |
| 81 |
panzer::ClosureModelFactory_TemplateManager<panzer::Traits> cm_factory; |
| 82 |
Teuchos::ParameterList closure_models; |
| 83 |
Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData> param_ged; |
| 84 |
std::vector<panzer::BC> bcs; |
| 85 |
Teuchos::RCP<panzer::BCStrategyFactory> bc_factory; |
| 86 |
}; |
| 87 |
|
| 88 |
struct RespFactoryFunc_Builder { |
| 89 |
MPI_Comm comm; |
| 90 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linearObjFactory; |
| 91 |
Teuchos::RCP<const panzer::GlobalIndexer> globalIndexer; |
| 92 |
|
| 93 |
template <typename T> |
| 94 |
Teuchos::RCP<ResponseEvaluatorFactoryBase> build() const |
| 95 |
{ return Teuchos::rcp(new ResponseEvaluatorFactory_Functional<T,int,int>(comm,1,true,"",linearObjFactory,globalIndexer)); } |
| 96 |
}; |
| 97 |
|
| 98 |
void buildAssemblyPieces(bool parameter_on,bool distr_parameter_on, |
| 99 |
AssemblyPieces & ap, |
| 100 |
const std::vector<std::string>& tangentParamNames = std::vector<std::string>(), |
| 101 |
bool useBlocking=false); |
| 102 |
|
| 103 |
bool testEqualityOfVectorValues(const Thyra::VectorBase<double> & a, |
| 104 |
const Thyra::VectorBase<double> & b, |
| 105 |
double tolerance, bool write_to_cout=false); |
| 106 |
|
| 107 |
TEUCHOS_UNIT_TEST(thyra_model_evaluator, basic) |
| 108 |
{ |
| 109 |
using Teuchos::RCP; |
| 110 |
|
| 111 |
|
| 112 |
bool parameter_on = true; |
| 113 |
AssemblyPieces ap; |
| 114 |
|
| 115 |
buildAssemblyPieces(parameter_on,false,ap); |
| 116 |
|
| 117 |
// Test a transient me |
| 118 |
{ |
| 119 |
typedef Thyra::ModelEvaluatorBase MEB; |
| 120 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 121 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 122 |
typedef Thyra::VectorBase<double> VectorType; |
| 123 |
typedef Thyra::LinearOpBase<double> OperatorType; |
| 124 |
typedef panzer::ModelEvaluator<double> PME; |
| 125 |
|
| 126 |
bool build_transient_support = true; |
| 127 |
|
| 128 |
RCP<PME> me = Teuchos::rcp(new PME(ap.lof,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 129 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 130 |
*ap.eqset_factory, |
| 131 |
*ap.bc_factory, |
| 132 |
ap.cm_factory, |
| 133 |
ap.cm_factory, |
| 134 |
ap.closure_models, |
| 135 |
ap.user_data,false,""); |
| 136 |
|
| 137 |
InArgs in_args = me->createInArgs(); |
| 138 |
OutArgs out_args = me->createOutArgs(); |
| 139 |
|
| 140 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_x)); |
| 141 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_x_dot)); |
| 142 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_alpha)); |
| 143 |
TEST_ASSERT(in_args.supports(MEB::IN_ARG_beta)); |
| 144 |
TEST_ASSERT(out_args.supports(MEB::OUT_ARG_f)); |
| 145 |
TEST_ASSERT(out_args.supports(MEB::OUT_ARG_W_op)); |
| 146 |
|
| 147 |
InArgs nomValues = me->getNominalValues(); |
| 148 |
RCP<const VectorType> x = nomValues.get_x(); |
| 149 |
RCP<VectorType> x_dot = Thyra::createMember(*me->get_x_space()); |
| 150 |
Thyra::assign(x_dot.ptr(),0.0); |
| 151 |
in_args.set_x(x); |
| 152 |
in_args.set_x_dot(x_dot); |
| 153 |
in_args.set_alpha(0.0); |
| 154 |
in_args.set_beta(1.0); |
| 155 |
|
| 156 |
RCP<VectorType> f = Thyra::createMember(*me->get_f_space()); |
| 157 |
RCP<OperatorType> J_tmp = me->create_W_op(); |
| 158 |
out_args.set_f(f); |
| 159 |
out_args.set_W_op(J_tmp); |
| 160 |
|
| 161 |
me->evalModel(in_args, out_args); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
TEUCHOS_UNIT_TEST(thyra_model_evaluator, response) |
| 166 |
{ |
| 167 |
|
| 168 |
bool parameter_on = true; |
| 169 |
AssemblyPieces ap; |
| 170 |
|
| 171 |
buildAssemblyPieces(parameter_on,false,ap); |
| 172 |
|
| 173 |
{ |
| 174 |
typedef Thyra::ModelEvaluatorBase MEB; |
| 175 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 176 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 177 |
typedef Thyra::VectorBase<double> VectorType; |
| 178 |
typedef panzer::ModelEvaluator<double> PME; |
| 179 |
|
| 180 |
bool build_transient_support = false; |
| 181 |
RCP<PME> me = Teuchos::rcp(new PME(ap.lof,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 182 |
|
| 183 |
// parameterize the builder |
| 184 |
Teuchos::RCP<panzer::FunctionalResponse_Builder<int,int> > builder |
| 185 |
= Teuchos::rcp(new panzer::FunctionalResponse_Builder<int,int>); |
| 186 |
|
| 187 |
builder->comm = MPI_COMM_WORLD; // good enough |
| 188 |
builder->cubatureDegree = 1; |
| 189 |
builder->requiresCellIntegral = true; |
| 190 |
builder->quadPointField = ""; |
| 191 |
|
| 192 |
std::vector<panzer::WorksetDescriptor> blocks; |
| 193 |
blocks.push_back(panzer::blockDescriptor("eblock-0_0")); |
| 194 |
blocks.push_back(panzer::blockDescriptor("eblock-1_0")); |
| 195 |
me->addFlexibleResponse("TEMPERATURE",blocks,builder); |
| 196 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 197 |
*ap.eqset_factory, |
| 198 |
*ap.bc_factory, |
| 199 |
ap.cm_factory, |
| 200 |
ap.cm_factory, |
| 201 |
ap.closure_models, |
| 202 |
ap.user_data,false,""); |
| 203 |
|
| 204 |
TEST_EQUALITY(me->get_g_name(0), "TEMPERATURE"); |
| 205 |
TEST_EQUALITY(me->get_g_names(0)[0], "TEMPERATURE"); |
| 206 |
|
| 207 |
InArgs nomValues = me->getNominalValues(); |
| 208 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 209 |
Thyra::assign(x.ptr(),0.0); |
| 210 |
|
| 211 |
InArgs in_args = me->createInArgs(); |
| 212 |
in_args.set_x(x); |
| 213 |
|
| 214 |
RCP<VectorType> f = Thyra::createMember(*me->get_f_space()); |
| 215 |
RCP<VectorType> g = Thyra::createMember(*me->get_g_space(0)); |
| 216 |
RCP<VectorType> DgDx = Thyra::createMember(*me->get_x_space()); |
| 217 |
OutArgs out_args = me->createOutArgs(); |
| 218 |
out_args.set_f(f); |
| 219 |
out_args.set_g(0,g); |
| 220 |
out_args.set_DgDx(0,MEB::Derivative<double>(DgDx,MEB::DERIV_MV_GRADIENT_FORM)); |
| 221 |
|
| 222 |
me->evalModel(in_args, out_args); |
| 223 |
|
| 224 |
out << "RESIDUAL = " << std::endl; |
| 225 |
out << Teuchos::describe(*f,Teuchos::VERB_EXTREME) << std::endl; |
| 226 |
|
| 227 |
out << "RESPONSE = " << std::endl; |
| 228 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 229 |
|
| 230 |
out << "RESPONSE DERIVATIVE = " << std::endl; |
| 231 |
out << Teuchos::describe(*DgDx,Teuchos::VERB_EXTREME) << std::endl; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
// Testing Parameter Support |
| 236 |
TEUCHOS_UNIT_TEST(thyra_model_evaluator, scalar_parameters) |
| 237 |
{ |
| 238 |
using Teuchos::RCP; |
| 239 |
using Teuchos::rcp_dynamic_cast; |
| 240 |
|
| 241 |
|
| 242 |
bool parameter_on = true; |
| 243 |
AssemblyPieces ap; |
| 244 |
|
| 245 |
buildAssemblyPieces(parameter_on,false,ap); |
| 246 |
|
| 247 |
panzer::registerScalarParameter("DUMMY",*ap.gd->pl,3.0); |
| 248 |
panzer::registerScalarParameter("DUMMY_A",*ap.gd->pl,4.0); |
| 249 |
panzer::registerScalarParameter("DUMMY_B",*ap.gd->pl,5.0); |
| 250 |
|
| 251 |
{ |
| 252 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 253 |
typedef Thyra::SpmdVectorBase<double> SpmdVector; |
| 254 |
typedef panzer::ModelEvaluator<double> PME; |
| 255 |
|
| 256 |
bool build_transient_support = false; |
| 257 |
RCP<PME> me = Teuchos::rcp(new PME(ap.lof,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 258 |
me->addParameter("SOURCE_TEMPERATURE",1.0); |
| 259 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 260 |
*ap.eqset_factory, |
| 261 |
*ap.bc_factory, |
| 262 |
ap.cm_factory, |
| 263 |
ap.cm_factory, |
| 264 |
ap.closure_models, |
| 265 |
ap.user_data,false,""); |
| 266 |
|
| 267 |
Teuchos::Array<std::string> params; |
| 268 |
params.push_back("DUMMY_A"); |
| 269 |
params.push_back("DUMMY_B"); |
| 270 |
Teuchos::Array<double> params_values; |
| 271 |
params_values.push_back(4.0); |
| 272 |
params_values.push_back(5.0); |
| 273 |
|
| 274 |
int index_dummy = me->addParameter("DUMMY",3.0); |
| 275 |
int index_dummy_pair = me->addParameter(params,params_values); |
| 276 |
|
| 277 |
InArgs inArgs = me->createInArgs(); |
| 278 |
|
| 279 |
// 3 model parameters + 3 tangent vectors |
| 280 |
TEST_EQUALITY(inArgs.Np(),6); |
| 281 |
|
| 282 |
RCP<const Teuchos::Array<std::string> > names_0 = me->get_p_names(0); |
| 283 |
RCP<const Teuchos::Array<std::string> > names_1 = me->get_p_names(index_dummy); |
| 284 |
RCP<const Teuchos::Array<std::string> > names_2 = me->get_p_names(index_dummy_pair); |
| 285 |
|
| 286 |
TEST_ASSERT(names_0!=Teuchos::null); |
| 287 |
TEST_ASSERT(names_1!=Teuchos::null); |
| 288 |
TEST_ASSERT(names_2!=Teuchos::null); |
| 289 |
|
| 290 |
TEST_EQUALITY(names_0->size(),1); |
| 291 |
TEST_EQUALITY(names_1->size(),1); |
| 292 |
TEST_EQUALITY(names_2->size(),2); |
| 293 |
|
| 294 |
TEST_EQUALITY((*names_0)[0],"SOURCE_TEMPERATURE"); |
| 295 |
TEST_EQUALITY((*names_1)[0],"DUMMY"); |
| 296 |
TEST_EQUALITY((*names_2)[0],"DUMMY_A"); |
| 297 |
TEST_EQUALITY((*names_2)[1],"DUMMY_B"); |
| 298 |
|
| 299 |
RCP<const Thyra::VectorSpaceBase<double> > vs_0 = me->get_p_space(0); |
| 300 |
RCP<const Thyra::VectorSpaceBase<double> > vs_1 = me->get_p_space(index_dummy); |
| 301 |
RCP<const Thyra::VectorSpaceBase<double> > vs_2 = me->get_p_space(index_dummy_pair); |
| 302 |
|
| 303 |
TEST_THROW(me->get_p_space(-1),std::runtime_error); |
| 304 |
TEST_THROW(me->get_p_space(7),std::runtime_error); |
| 305 |
|
| 306 |
TEST_THROW(me->get_p_names(-1),std::runtime_error); |
| 307 |
TEST_THROW(me->get_p_names(7),std::runtime_error); |
| 308 |
|
| 309 |
TEST_ASSERT(vs_0!=Teuchos::null); |
| 310 |
TEST_ASSERT(vs_1!=Teuchos::null); |
| 311 |
TEST_ASSERT(vs_2!=Teuchos::null); |
| 312 |
|
| 313 |
TEST_EQUALITY(vs_0->dim(),1); |
| 314 |
TEST_EQUALITY(vs_1->dim(),1); |
| 315 |
TEST_EQUALITY(vs_2->dim(),2); |
| 316 |
|
| 317 |
|
| 318 |
RCP<const Thyra::VectorBase<double> > param_0 = inArgs.get_p(0); |
| 319 |
RCP<const Thyra::VectorBase<double> > param_1 = inArgs.get_p(index_dummy); |
| 320 |
RCP<const Thyra::VectorBase<double> > param_2 = inArgs.get_p(index_dummy_pair); |
| 321 |
|
| 322 |
TEST_ASSERT(param_0!=Teuchos::null); |
| 323 |
TEST_ASSERT(param_1!=Teuchos::null); |
| 324 |
TEST_ASSERT(param_2!=Teuchos::null); |
| 325 |
|
| 326 |
RCP<const SpmdVector> spmd_0 = rcp_dynamic_cast<const SpmdVector>(param_0); |
| 327 |
RCP<const SpmdVector> spmd_1 = rcp_dynamic_cast<const SpmdVector>(param_1); |
| 328 |
RCP<const SpmdVector> spmd_2 = rcp_dynamic_cast<const SpmdVector>(param_2); |
| 329 |
|
| 330 |
TEST_ASSERT(spmd_0!=Teuchos::null); |
| 331 |
TEST_ASSERT(spmd_1!=Teuchos::null); |
| 332 |
TEST_ASSERT(spmd_2!=Teuchos::null); |
| 333 |
|
| 334 |
{ |
| 335 |
Teuchos::ArrayRCP<const double> data; |
| 336 |
spmd_0->getLocalData(Teuchos::ptrFromRef(data)); |
| 337 |
|
| 338 |
TEST_EQUALITY(data.size(),1); |
| 339 |
TEST_EQUALITY(data[0],1.0); |
| 340 |
} |
| 341 |
|
| 342 |
{ |
| 343 |
Teuchos::ArrayRCP<const double> data; |
| 344 |
spmd_1->getLocalData(Teuchos::ptrFromRef(data)); |
| 345 |
|
| 346 |
TEST_EQUALITY(data.size(),1); |
| 347 |
TEST_EQUALITY(data[0],3.0); |
| 348 |
} |
| 349 |
|
| 350 |
{ |
| 351 |
Teuchos::ArrayRCP<const double> data; |
| 352 |
spmd_2->getLocalData(Teuchos::ptrFromRef(data)); |
| 353 |
|
| 354 |
TEST_EQUALITY(data.size(),2); |
| 355 |
TEST_EQUALITY(data[0],4.0); |
| 356 |
TEST_EQUALITY(data[1],5.0); |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
// Testing Parameter Support |
| 362 |
TEUCHOS_UNIT_TEST(thyra_model_evaluator, scalar_parameters_dfdp) |
| 363 |
{ |
| 364 |
using Teuchos::RCP; |
| 365 |
using Teuchos::rcp_dynamic_cast; |
| 366 |
|
| 367 |
|
| 368 |
bool parameter_on = true; |
| 369 |
AssemblyPieces ap; |
| 370 |
|
| 371 |
buildAssemblyPieces(parameter_on,false,ap); |
| 372 |
|
| 373 |
{ |
| 374 |
typedef Thyra::ModelEvaluatorBase MEB; |
| 375 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 376 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 377 |
typedef panzer::ModelEvaluator<double> PME; |
| 378 |
|
| 379 |
bool build_transient_support = false; |
| 380 |
RCP<PME> me = Teuchos::rcp(new PME(ap.lof,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 381 |
me->addParameter("SOURCE_TEMPERATURE",1.0); |
| 382 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 383 |
*ap.eqset_factory, |
| 384 |
*ap.bc_factory, |
| 385 |
ap.cm_factory, |
| 386 |
ap.cm_factory, |
| 387 |
ap.closure_models, |
| 388 |
ap.user_data,false,""); |
| 389 |
|
| 390 |
RCP<Thyra::VectorBase<double> > x = Thyra::createMember(me->get_x_space()); |
| 391 |
Thyra::put_scalar(1.0,x.ptr()); |
| 392 |
|
| 393 |
RCP<Thyra::VectorBase<double> > p = Thyra::createMember(me->get_p_space(0)); |
| 394 |
Thyra::put_scalar(1.0,p.ptr()); |
| 395 |
|
| 396 |
RCP<Thyra::VectorBase<double> > f1 = Thyra::createMember(*me->get_f_space()); |
| 397 |
RCP<Thyra::VectorBase<double> > f2 = Thyra::createMember(*me->get_f_space()); |
| 398 |
RCP<Thyra::VectorBase<double> > f3 = Thyra::createMember(*me->get_f_space()); |
| 399 |
RCP<Thyra::VectorBase<double> > f4 = Thyra::createMember(*me->get_f_space()); |
| 400 |
|
| 401 |
InArgs inArgs = me->createInArgs(); |
| 402 |
inArgs.set_x(x); |
| 403 |
inArgs.set_p(0,p); |
| 404 |
|
| 405 |
OutArgs outArgs = me->createOutArgs(); |
| 406 |
|
| 407 |
out << "evalModel(f1)" << std::endl; |
| 408 |
Thyra::put_scalar(1.0,p.ptr()); |
| 409 |
outArgs.set_f(f1); |
| 410 |
outArgs.set_DfDp(0,MEB::Derivative<double>()); |
| 411 |
me->evalModel(inArgs,outArgs); |
| 412 |
|
| 413 |
out << "evalModel(f2)" << std::endl; |
| 414 |
Thyra::put_scalar(1.0,p.ptr()); |
| 415 |
outArgs.set_f(f2); |
| 416 |
outArgs.set_DfDp(0,MEB::Derivative<double>()); |
| 417 |
me->evalModel(inArgs,outArgs); |
| 418 |
|
| 419 |
out << "evalModel(f3)" << std::endl; |
| 420 |
Thyra::put_scalar(20.0,p.ptr()); |
| 421 |
outArgs.set_f(f3); |
| 422 |
outArgs.set_DfDp(0,MEB::Derivative<double>()); |
| 423 |
me->evalModel(inArgs,outArgs); |
| 424 |
|
| 425 |
out << "evalModel(f4)" << std::endl; |
| 426 |
Thyra::put_scalar(1.0,p.ptr()); |
| 427 |
outArgs.set_f(f4); |
| 428 |
outArgs.set_DfDp(0,MEB::Derivative<double>()); |
| 429 |
me->evalModel(inArgs,outArgs); |
| 430 |
|
| 431 |
double tol = 10.0 * Teuchos::ScalarTraits<double>::eps(); |
| 432 |
|
| 433 |
// f1 == f2 |
| 434 |
TEST_EQUALITY_CONST(testEqualityOfVectorValues(*f1,*f2,tol), true); |
| 435 |
|
| 436 |
// f2 == f4 |
| 437 |
TEST_EQUALITY_CONST(testEqualityOfVectorValues(*f2,*f4,tol), true); |
| 438 |
|
| 439 |
// f2 != f3 |
| 440 |
TEST_EQUALITY_CONST(testEqualityOfVectorValues(*f2,*f3,tol), false); |
| 441 |
|
| 442 |
// TEST DfDp |
| 443 |
///////////////////////////////////////////////////// |
| 444 |
|
| 445 |
RCP<Thyra::VectorBase<double> > dfdp = Thyra::createMember(*me->get_f_space()); |
| 446 |
Thyra::put_scalar(0.0,dfdp.ptr()); |
| 447 |
|
| 448 |
Thyra::put_scalar(0.0,x.ptr()); |
| 449 |
Thyra::put_scalar(0.0,f1.ptr()); |
| 450 |
Thyra::put_scalar(20.0,p.ptr()); |
| 451 |
|
| 452 |
out << "evalModel(dfdp)" << std::endl; |
| 453 |
outArgs.set_f(f1); |
| 454 |
outArgs.set_DfDp(0,MEB::Derivative<double>(dfdp,MEB::DERIV_MV_BY_COL)); |
| 455 |
me->evalModel(inArgs,outArgs); |
| 456 |
TEST_ASSERT(Thyra::norm_2(*dfdp)>0); |
| 457 |
|
| 458 |
Teuchos::ArrayRCP<const double> dfdp_data; |
| 459 |
Teuchos::ArrayRCP<const double> f1_data; |
| 460 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(*dfdp).getLocalData(Teuchos::ptrFromRef(dfdp_data)); |
| 461 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(*f1).getLocalData(Teuchos::ptrFromRef(f1_data)); |
| 462 |
for(int i=0;i<dfdp_data.size();i++) { |
| 463 |
if(dfdp_data[i]!=0.0) |
| 464 |
{ TEST_FLOATING_EQUALITY(f1_data[i],20.0*dfdp_data[i],1e-10); } |
| 465 |
out << f1_data[i] << " " << dfdp_data[i] << std::endl; |
| 466 |
} |
| 467 |
|
| 468 |
outArgs.set_DfDp(0,MEB::Derivative<double>(dfdp,MEB::DERIV_MV_BY_COL)); |
| 469 |
me->evalModel(inArgs,outArgs); |
| 470 |
TEST_ASSERT(Thyra::norm_2(*dfdp)>0); |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
// Testing Parameter Support |
| 475 |
TEUCHOS_UNIT_TEST(thyra_model_evaluator, scalar_parameters_dfdp_tangent) |
| 476 |
{ |
| 477 |
using Teuchos::RCP; |
| 478 |
using Teuchos::rcp_dynamic_cast; |
| 479 |
|
| 480 |
|
| 481 |
bool parameter_on = true; |
| 482 |
AssemblyPieces ap; |
| 483 |
std::vector<std::string> tangentParamNames(1); |
| 484 |
tangentParamNames[0] = "SOURCE_TEMPERATURE"; |
| 485 |
|
| 486 |
buildAssemblyPieces(parameter_on,false,ap,tangentParamNames); |
| 487 |
|
| 488 |
{ |
| 489 |
typedef Thyra::ModelEvaluatorBase MEB; |
| 490 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 491 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 492 |
typedef panzer::ModelEvaluator<double> PME; |
| 493 |
|
| 494 |
bool build_transient_support = false; |
| 495 |
RCP<PME> me = Teuchos::rcp(new PME(ap.lof,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 496 |
me->addParameter("SOURCE_TEMPERATURE",1.0); |
| 497 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 498 |
*ap.eqset_factory, |
| 499 |
*ap.bc_factory, |
| 500 |
ap.cm_factory, |
| 501 |
ap.cm_factory, |
| 502 |
ap.closure_models, |
| 503 |
ap.user_data,true,"dfdp_tangent"); |
| 504 |
|
| 505 |
InArgs inArgs = me->createInArgs(); |
| 506 |
|
| 507 |
// 1 model parameter + 1 tangent vector |
| 508 |
TEST_ASSERT(inArgs.Np() == 2); |
| 509 |
|
| 510 |
RCP<Thyra::VectorBase<double> > x = Thyra::createMember(me->get_x_space()); |
| 511 |
RCP<Thyra::VectorBase<double> > p = Thyra::createMember(me->get_p_space(0)); |
| 512 |
RCP<Thyra::VectorBase<double> > v = Thyra::createMember(me->get_p_space(1)); |
| 513 |
RCP<Thyra::VectorBase<double> > f = Thyra::createMember(me->get_f_space()); |
| 514 |
RCP<Thyra::VectorBase<double> > fd = Thyra::createMember(me->get_f_space()); |
| 515 |
RCP<Thyra::VectorBase<double> > dfdp = Thyra::createMember(me->get_f_space()); |
| 516 |
|
| 517 |
// TEST DfDp |
| 518 |
///////////////////////////////////////////////////// |
| 519 |
|
| 520 |
Thyra::seed_randomize<double>(123456u); |
| 521 |
Thyra::randomize(0.0,1.0,x.ptr()); |
| 522 |
Thyra::randomize(0.0,1.0,v.ptr()); |
| 523 |
Thyra::put_scalar(5.0,p.ptr()); |
| 524 |
Thyra::put_scalar(0.0,f.ptr()); |
| 525 |
Thyra::put_scalar(0.0,fd.ptr()); |
| 526 |
Thyra::put_scalar(0.0,dfdp.ptr()); |
| 527 |
|
| 528 |
inArgs.set_x(x); |
| 529 |
inArgs.set_p(0,p); |
| 530 |
inArgs.set_p(1,v); |
| 531 |
|
| 532 |
out << "evalModel(dfdp)" << std::endl; |
| 533 |
OutArgs outArgs = me->createOutArgs(); |
| 534 |
outArgs.set_DfDp(0,MEB::Derivative<double>(dfdp,MEB::DERIV_MV_BY_COL)); |
| 535 |
me->evalModel(inArgs,outArgs); |
| 536 |
TEST_ASSERT(Thyra::norm_2(*dfdp)>0); |
| 537 |
|
| 538 |
out << "evalModel(f)" << std::endl; |
| 539 |
OutArgs outArgs_base = me->createOutArgs(); |
| 540 |
outArgs_base.set_f(f); |
| 541 |
me->evalModel(inArgs,outArgs_base); |
| 542 |
|
| 543 |
out << "evalModel(fd)" << std::endl; |
| 544 |
OutArgs outArgs_delta = me->createOutArgs(); |
| 545 |
Thyra::Vp_StV(x.ptr(),1.0,*v); // x = x + 1 * v |
| 546 |
Thyra::put_scalar(6.0,p.ptr());// p = p + 1 |
| 547 |
outArgs_delta.set_f(fd); |
| 548 |
me->evalModel(inArgs,outArgs_delta); |
| 549 |
|
| 550 |
// (df/dx)*v + df/dp = f(x + 1 * v, p + 1) - f(x,p) |
| 551 |
// since the problem is linear |
| 552 |
Teuchos::ArrayRCP<const double> dfdp_data; |
| 553 |
Teuchos::ArrayRCP<const double> f_data; |
| 554 |
Teuchos::ArrayRCP<const double> fd_data; |
| 555 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(*dfdp).getLocalData(Teuchos::ptrFromRef(dfdp_data)); |
| 556 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(*f).getLocalData(Teuchos::ptrFromRef(f_data)); |
| 557 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(*fd).getLocalData(Teuchos::ptrFromRef(fd_data)); |
| 558 |
for(int i=0;i<dfdp_data.size();i++) { |
| 559 |
if(std::abs(dfdp_data[i]) > 1e-13) |
| 560 |
{ TEST_FLOATING_EQUALITY(fd_data[i]-f_data[i],dfdp_data[i],1e-10); } |
| 561 |
out << fd_data[i]-f_data[i] << " " << dfdp_data[i] << std::endl; |
| 562 |
} |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
// Testing Ditributed Parameter Support |
| 567 |
TEUCHOS_UNIT_TEST(model_evaluator, distributed_parameters) |
| 568 |
{ |
| 569 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 570 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 571 |
typedef panzer::ModelEvaluator<double> PME; |
| 572 |
|
| 573 |
using Teuchos::RCP; |
| 574 |
using Teuchos::rcp_dynamic_cast; |
| 575 |
|
| 576 |
|
| 577 |
bool parameter_on = true; |
| 578 |
AssemblyPieces ap; |
| 579 |
|
| 580 |
buildAssemblyPieces(parameter_on,false,ap); |
| 581 |
|
| 582 |
int distributed_parameter_index = -1; |
| 583 |
Teuchos::RCP<panzer::LOCPair_GlobalEvaluationData> dataObject; |
| 584 |
RCP<PME> me; |
| 585 |
{ |
| 586 |
bool build_transient_support = false; |
| 587 |
me = Teuchos::rcp(new PME(ap.lof,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 588 |
me->addParameter("SOURCE_TEMPERATURE",1.0); |
| 589 |
|
| 590 |
// add a distributed parameter |
| 591 |
{ |
| 592 |
// extract the vector space for the distributed parameter |
| 593 |
Teuchos::RCP<const Thyra::VectorSpaceBase<double> > vs |
| 594 |
= Teuchos::rcp_dynamic_cast<const ThyraObjFactory<double> >(ap.lof,true)->getThyraDomainSpace(); |
| 595 |
|
| 596 |
// setup an initial value for the parameter |
| 597 |
Teuchos::RCP<Thyra::VectorBase<double> > initial = Thyra::createMember(vs); |
| 598 |
Thyra::put_scalar(0.0,initial.ptr()); |
| 599 |
|
| 600 |
// this object changes the parameter from a global object to a ghosted one |
| 601 |
dataObject = Teuchos::rcp(new panzer::LOCPair_GlobalEvaluationData(ap.lof,panzer::LinearObjContainer::X)); |
| 602 |
|
| 603 |
// add the distributed parameter |
| 604 |
distributed_parameter_index = me->addDistributedParameter("Transient Predictor", |
| 605 |
vs, |
| 606 |
dataObject, |
| 607 |
initial); |
| 608 |
} |
| 609 |
|
| 610 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 611 |
*ap.eqset_factory, |
| 612 |
*ap.bc_factory, |
| 613 |
ap.cm_factory, |
| 614 |
ap.cm_factory, |
| 615 |
ap.closure_models, |
| 616 |
ap.user_data,false,""); |
| 617 |
} |
| 618 |
|
| 619 |
// build inputs |
| 620 |
//////////////////////////////////////////////////////////////////////////////////// |
| 621 |
|
| 622 |
// solution |
| 623 |
RCP<Thyra::VectorBase<double> > x = Thyra::createMember(me->get_x_space()); |
| 624 |
Thyra::put_scalar(1.0,x.ptr()); |
| 625 |
|
| 626 |
// locally replicated scalar parameter |
| 627 |
RCP<Thyra::VectorBase<double> > p = Thyra::createMember(me->get_p_space(0)); |
| 628 |
Thyra::put_scalar(1.0,p.ptr()); |
| 629 |
|
| 630 |
// distributed parameter |
| 631 |
RCP<Thyra::VectorBase<double> > distr_p = Thyra::createMember(me->get_p_space(distributed_parameter_index)); |
| 632 |
Thyra::put_scalar(3.14,distr_p.ptr()); |
| 633 |
|
| 634 |
// build outputs |
| 635 |
//////////////////////////////////////////////////////////////////////////////////// |
| 636 |
|
| 637 |
// Test that the distributed parameter is updated correctly |
| 638 |
{ |
| 639 |
RCP<Thyra::VectorBase<double> > f = Thyra::createMember(me->get_f_space()); |
| 640 |
|
| 641 |
InArgs in_args = me->createInArgs(); |
| 642 |
OutArgs out_args = me->createOutArgs(); |
| 643 |
|
| 644 |
// 1 scalar parameter + 1 tangent + 1 distributed parameter |
| 645 |
TEST_ASSERT(in_args.Np() == 3); |
| 646 |
|
| 647 |
in_args.set_x(x); |
| 648 |
in_args.set_p(0,p); |
| 649 |
in_args.set_p(distributed_parameter_index,distr_p); |
| 650 |
|
| 651 |
out_args.set_f(f); |
| 652 |
|
| 653 |
me->evalModel(in_args,out_args); |
| 654 |
|
| 655 |
// Export should have performed global to ghost, ghosted values should be 1 |
| 656 |
// Create a gold standard to compare against |
| 657 |
RCP<const Thyra::VectorBase<double> > ghosted_distr_p |
| 658 |
= Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(dataObject->getGhostedLOC())->get_x_th(); |
| 659 |
RCP<Thyra::VectorBase<double> > gold_standard = Thyra::createMember(ghosted_distr_p->range()); |
| 660 |
Thyra::put_scalar(3.14,gold_standard.ptr()); |
| 661 |
|
| 662 |
double tol = 10.0 * Teuchos::ScalarTraits<double>::eps(); |
| 663 |
|
| 664 |
// note that all this tests is that the ghosted vector is correctly populated! |
| 665 |
TEST_EQUALITY_CONST(testEqualityOfVectorValues(*ghosted_distr_p,*gold_standard,tol,true), true); |
| 666 |
} |
| 667 |
|
| 668 |
// Test that the distributed parameter is updated correctly |
| 669 |
{ |
| 670 |
RCP<Thyra::VectorBase<double> > distr_p2 = Thyra::createMember(me->get_p_space(distributed_parameter_index)); |
| 671 |
Thyra::put_scalar(6.28,distr_p2.ptr()); |
| 672 |
|
| 673 |
RCP<Thyra::VectorBase<double> > f = Thyra::createMember(me->get_f_space()); |
| 674 |
|
| 675 |
InArgs in_args = me->createInArgs(); |
| 676 |
OutArgs out_args = me->createOutArgs(); |
| 677 |
|
| 678 |
// 1 scalar parameter + 1 tangent + 1 distributed parameter |
| 679 |
TEST_ASSERT(in_args.Np() == 3); |
| 680 |
|
| 681 |
in_args.set_x(x); |
| 682 |
in_args.set_p(0,p); |
| 683 |
in_args.set_p(distributed_parameter_index,distr_p2); |
| 684 |
|
| 685 |
out_args.set_f(f); |
| 686 |
|
| 687 |
me->evalModel(in_args,out_args); |
| 688 |
|
| 689 |
// Export should have performed global to ghost, ghosted values should be 1 |
| 690 |
// Create a gold standard to compare against |
| 691 |
RCP<const Thyra::VectorBase<double> > ghosted_distr_p |
| 692 |
= Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(dataObject->getGhostedLOC())->get_x_th(); |
| 693 |
RCP<Thyra::VectorBase<double> > gold_standard = Thyra::createMember(ghosted_distr_p->range()); |
| 694 |
Thyra::put_scalar(6.28,gold_standard.ptr()); |
| 695 |
|
| 696 |
double tol = 10.0 * Teuchos::ScalarTraits<double>::eps(); |
| 697 |
|
| 698 |
// note that all this tests is that the ghosted vector is correctly populated! |
| 699 |
TEST_EQUALITY_CONST(testEqualityOfVectorValues(*ghosted_distr_p,*gold_standard,tol,true), true); |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
} |
| 704 |
|
| 705 |
// Testing Parameter Support |
| 706 |
TEUCHOS_UNIT_TEST(thyra_model_evaluator, distro_parameters_dgdp) |
| 707 |
{ |
| 708 |
typedef Thyra::ModelEvaluatorBase MEB; |
| 709 |
typedef panzer::Traits::RealType RealType; |
| 710 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 711 |
typedef Thyra::SpmdVectorBase<RealType> SpmdVectorType; |
| 712 |
|
| 713 |
using Teuchos::RCP; |
| 714 |
using Teuchos::rcp_dynamic_cast; |
| 715 |
|
| 716 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 717 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 718 |
typedef panzer::ModelEvaluator<double> PME; |
| 719 |
|
| 720 |
|
| 721 |
bool parameter_on = true; |
| 722 |
bool distr_param_on = true; |
| 723 |
AssemblyPieces ap; |
| 724 |
buildAssemblyPieces(parameter_on,distr_param_on,ap); |
| 725 |
|
| 726 |
int pIndex = -1; |
| 727 |
int rIndex = -1; |
| 728 |
|
| 729 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 730 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 731 |
bool build_transient_support = true; |
| 732 |
RCP<PME> me |
| 733 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 734 |
|
| 735 |
// add in a flexible response |
| 736 |
{ |
| 737 |
Teuchos::RCP<panzer::FunctionalResponse_Builder<int,int> > builder |
| 738 |
= Teuchos::rcp(new panzer::FunctionalResponse_Builder<int,int>); |
| 739 |
|
| 740 |
builder->comm = MPI_COMM_WORLD; // good enough |
| 741 |
builder->cubatureDegree = 1; |
| 742 |
builder->requiresCellIntegral = true; |
| 743 |
builder->quadPointField = ""; |
| 744 |
|
| 745 |
std::vector<panzer::WorksetDescriptor> blocks; |
| 746 |
blocks.push_back(panzer::blockDescriptor("eblock-0_0")); |
| 747 |
blocks.push_back(panzer::blockDescriptor("eblock-1_0")); |
| 748 |
rIndex = me->addFlexibleResponse("DENSITY",blocks,builder); // integrate the density |
| 749 |
} |
| 750 |
|
| 751 |
// add distributed parameter |
| 752 |
{ |
| 753 |
RCP<const ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<const ThyraObjFactory<double> >(ap.param_lof); |
| 754 |
|
| 755 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 756 |
Thyra::assign(param_density.ptr(),3.7); |
| 757 |
pIndex = me->addDistributedParameter("DENSITY",th_param_lof->getThyraDomainSpace(), |
| 758 |
ap.param_ged,param_density,ap.param_dofManager); |
| 759 |
} |
| 760 |
|
| 761 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 762 |
*ap.eqset_factory, |
| 763 |
*ap.bc_factory, |
| 764 |
ap.cm_factory, |
| 765 |
ap.cm_factory, |
| 766 |
ap.closure_models, |
| 767 |
ap.user_data,false,""); |
| 768 |
|
| 769 |
// check that out args support DgDp |
| 770 |
{ |
| 771 |
OutArgs outArgs = me->createOutArgs(); |
| 772 |
TEST_ASSERT(outArgs.supports(MEB::OUT_ARG_DgDp,rIndex,pIndex).supports(MEB::DERIV_MV_GRADIENT_FORM)); |
| 773 |
} |
| 774 |
|
| 775 |
// solution |
| 776 |
RCP<Thyra::VectorBase<double> > x = Thyra::createMember(me->get_x_space()); |
| 777 |
Thyra::put_scalar(1.0,x.ptr()); |
| 778 |
|
| 779 |
InArgs in_args = me->createInArgs(); |
| 780 |
|
| 781 |
RCP<VectorType> g = Thyra::createMember(*me->get_g_space(rIndex)); |
| 782 |
RCP<VectorType> DgDp = Thyra::createMember(*me->get_p_space(pIndex)); |
| 783 |
|
| 784 |
out << "DgDp = " << std::endl; |
| 785 |
|
| 786 |
{ |
| 787 |
OutArgs out_args = me->createOutArgs(); |
| 788 |
out_args.set_g(0,g); |
| 789 |
|
| 790 |
me->evalModel(in_args, out_args); |
| 791 |
|
| 792 |
out << "RESPONSE = " << std::endl; |
| 793 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 794 |
|
| 795 |
Teuchos::ArrayRCP<const double> g_data; |
| 796 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 797 |
TEST_FLOATING_EQUALITY(g_data[0],3.7,1e-12); |
| 798 |
} |
| 799 |
|
| 800 |
{ |
| 801 |
OutArgs out_args = me->createOutArgs(); |
| 802 |
out_args.set_g(0,g); |
| 803 |
out_args.set_DgDp(rIndex,pIndex,MEB::Derivative<double>(DgDp,MEB::DERIV_MV_GRADIENT_FORM)); |
| 804 |
|
| 805 |
me->evalModel(in_args, out_args); |
| 806 |
|
| 807 |
out << "RESPONSE = " << std::endl; |
| 808 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 809 |
|
| 810 |
Teuchos::ArrayRCP<const double> g_data; |
| 811 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 812 |
TEST_FLOATING_EQUALITY(g_data[0],3.7,1e-12); |
| 813 |
} |
| 814 |
|
| 815 |
Teuchos::ArrayRCP<const double> DgDp_data; |
| 816 |
RCP<const SpmdVectorType> spmd_DgDp = rcp_dynamic_cast<const SpmdVectorType>(DgDp); |
| 817 |
rcp_dynamic_cast<const SpmdVectorType>(DgDp)->getLocalData(Teuchos::ptrFromRef(DgDp_data)); |
| 818 |
double int_phi = 1.0/192.0; |
| 819 |
for(int i=0;i<DgDp_data.size();i++) { |
| 820 |
out << DgDp_data[i] << " " << int_phi << std::endl; |
| 821 |
bool a = std::fabs(DgDp_data[i]-int_phi)/int_phi <= 1e-14; |
| 822 |
bool b = std::fabs(DgDp_data[i]-2.0*int_phi)/(2.0*int_phi) <= 1e-14; |
| 823 |
bool c = std::fabs(DgDp_data[i]-4.0*int_phi)/(4.0*int_phi) <= 1e-14; |
| 824 |
|
| 825 |
TEST_ASSERT(a || b || c); |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
// Testing Parameter Support |
| 830 |
TEUCHOS_UNIT_TEST(thyra_model_evaluator, distro_blocked_parameters_dgdp) |
| 831 |
{ |
| 832 |
typedef Thyra::ModelEvaluatorBase MEB; |
| 833 |
typedef panzer::Traits::RealType RealType; |
| 834 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 835 |
typedef Thyra::SpmdVectorBase<RealType> SpmdVectorType; |
| 836 |
|
| 837 |
using Teuchos::RCP; |
| 838 |
using Teuchos::rcp_dynamic_cast; |
| 839 |
|
| 840 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 841 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 842 |
typedef panzer::ModelEvaluator<double> PME; |
| 843 |
|
| 844 |
|
| 845 |
bool parameter_on = true; |
| 846 |
bool distr_param_on = true; |
| 847 |
std::vector<std::string> tangent_names; |
| 848 |
AssemblyPieces ap; |
| 849 |
buildAssemblyPieces(parameter_on,distr_param_on,ap,tangent_names,true); |
| 850 |
|
| 851 |
int pIndex = -1; |
| 852 |
int rIndex = -1; |
| 853 |
|
| 854 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 855 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 856 |
bool build_transient_support = true; |
| 857 |
RCP<PME> me |
| 858 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 859 |
|
| 860 |
// add in a flexible response |
| 861 |
{ |
| 862 |
Teuchos::RCP<panzer::FunctionalResponse_Builder<int,int> > builder |
| 863 |
= Teuchos::rcp(new panzer::FunctionalResponse_Builder<int,int>); |
| 864 |
|
| 865 |
builder->comm = MPI_COMM_WORLD; // good enough |
| 866 |
builder->cubatureDegree = 1; |
| 867 |
builder->requiresCellIntegral = true; |
| 868 |
builder->quadPointField = ""; |
| 869 |
|
| 870 |
std::vector<panzer::WorksetDescriptor> blocks; |
| 871 |
blocks.push_back(panzer::blockDescriptor("eblock-0_0")); |
| 872 |
blocks.push_back(panzer::blockDescriptor("eblock-1_0")); |
| 873 |
rIndex = me->addFlexibleResponse("DENSITY",blocks,builder); // integrate the density |
| 874 |
} |
| 875 |
|
| 876 |
// add distributed parameter |
| 877 |
{ |
| 878 |
RCP<const ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<const ThyraObjFactory<double> >(ap.param_lof); |
| 879 |
|
| 880 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 881 |
Thyra::assign(param_density.ptr(),3.7); |
| 882 |
pIndex = me->addDistributedParameter("DENSITY",th_param_lof->getThyraDomainSpace(), |
| 883 |
ap.param_ged,param_density,ap.param_dofManager); |
| 884 |
} |
| 885 |
|
| 886 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 887 |
*ap.eqset_factory, |
| 888 |
*ap.bc_factory, |
| 889 |
ap.cm_factory, |
| 890 |
ap.cm_factory, |
| 891 |
ap.closure_models, |
| 892 |
ap.user_data,false,""); |
| 893 |
|
| 894 |
// check that out args support DgDp |
| 895 |
{ |
| 896 |
OutArgs outArgs = me->createOutArgs(); |
| 897 |
TEST_ASSERT(outArgs.supports(MEB::OUT_ARG_DgDp,rIndex,pIndex).supports(MEB::DERIV_MV_GRADIENT_FORM)); |
| 898 |
} |
| 899 |
|
| 900 |
// solution |
| 901 |
RCP<Thyra::VectorBase<double> > x = Thyra::createMember(me->get_x_space()); |
| 902 |
Thyra::put_scalar(1.0,x.ptr()); |
| 903 |
|
| 904 |
InArgs in_args = me->createInArgs(); |
| 905 |
in_args.set_x(x); |
| 906 |
in_args.set_x_dot(x); |
| 907 |
|
| 908 |
RCP<VectorType> g = Thyra::createMember(*me->get_g_space(rIndex)); |
| 909 |
RCP<VectorType> DgDp = Thyra::createMember(*me->get_p_space(pIndex)); |
| 910 |
|
| 911 |
out << "DgDp = " << std::endl; |
| 912 |
|
| 913 |
{ |
| 914 |
OutArgs out_args = me->createOutArgs(); |
| 915 |
out_args.set_g(0,g); |
| 916 |
|
| 917 |
me->evalModel(in_args, out_args); |
| 918 |
|
| 919 |
out << "RESPONSE = " << std::endl; |
| 920 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 921 |
|
| 922 |
Teuchos::ArrayRCP<const double> g_data; |
| 923 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 924 |
TEST_FLOATING_EQUALITY(g_data[0],3.7,1e-12); |
| 925 |
} |
| 926 |
|
| 927 |
{ |
| 928 |
OutArgs out_args = me->createOutArgs(); |
| 929 |
out_args.set_g(0,g); |
| 930 |
out_args.set_DgDp(rIndex,pIndex,MEB::Derivative<double>(DgDp,MEB::DERIV_MV_GRADIENT_FORM)); |
| 931 |
|
| 932 |
me->evalModel(in_args, out_args); |
| 933 |
|
| 934 |
out << "RESPONSE = " << std::endl; |
| 935 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 936 |
|
| 937 |
Teuchos::ArrayRCP<const double> g_data; |
| 938 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 939 |
TEST_FLOATING_EQUALITY(g_data[0],3.7,1e-12); |
| 940 |
} |
| 941 |
|
| 942 |
Teuchos::ArrayRCP<const double> DgDp_data; |
| 943 |
RCP<const SpmdVectorType> spmd_DgDp = rcp_dynamic_cast<const SpmdVectorType>(DgDp); |
| 944 |
rcp_dynamic_cast<const SpmdVectorType>(DgDp)->getLocalData(Teuchos::ptrFromRef(DgDp_data)); |
| 945 |
double int_phi = 1.0/192.0; |
| 946 |
for(int i=0;i<DgDp_data.size();i++) { |
| 947 |
out << DgDp_data[i] << " " << int_phi << std::endl; |
| 948 |
bool a = std::fabs(DgDp_data[i]-int_phi)/int_phi <= 1e-14; |
| 949 |
bool b = std::fabs(DgDp_data[i]-2.0*int_phi)/(2.0*int_phi) <= 1e-14; |
| 950 |
bool c = std::fabs(DgDp_data[i]-4.0*int_phi)/(4.0*int_phi) <= 1e-14; |
| 951 |
|
| 952 |
TEST_ASSERT(a || b || c); |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
// Testing that nominal values are correctly built and initialized |
| 957 |
// specifically testing that adding distributed parameters doesn't wipe out |
| 958 |
// previously set nominal values (like the inital condition) |
| 959 |
TEUCHOS_UNIT_TEST(model_evaluator, nominal_values) |
| 960 |
{ |
| 961 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 962 |
typedef panzer::ModelEvaluator<double> PME; |
| 963 |
|
| 964 |
using Teuchos::RCP; |
| 965 |
using Teuchos::rcp_dynamic_cast; |
| 966 |
using Teuchos::rcp_const_cast; |
| 967 |
|
| 968 |
|
| 969 |
double tol = 10.0 * Teuchos::ScalarTraits<double>::eps(); |
| 970 |
|
| 971 |
bool parameter_on = true; |
| 972 |
AssemblyPieces ap; |
| 973 |
|
| 974 |
buildAssemblyPieces(parameter_on,false,ap); |
| 975 |
|
| 976 |
Teuchos::RCP<panzer::LOCPair_GlobalEvaluationData> dataObject; |
| 977 |
RCP<PME> me; |
| 978 |
|
| 979 |
me = Teuchos::rcp(new PME(ap.lof,Teuchos::null,ap.gd,true,0.0)); |
| 980 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 981 |
*ap.eqset_factory, |
| 982 |
*ap.bc_factory, |
| 983 |
ap.cm_factory, |
| 984 |
ap.cm_factory, |
| 985 |
ap.closure_models, |
| 986 |
ap.user_data,false,""); |
| 987 |
|
| 988 |
// setup some initial conditions |
| 989 |
RCP<Thyra::VectorBase<double> > x0 = Thyra::createMember(me->get_x_space()); |
| 990 |
RCP<Thyra::VectorBase<double> > x0_dot = Thyra::createMember(me->get_x_space()); |
| 991 |
{ |
| 992 |
InArgs nomValues = me->getNominalValues(); |
| 993 |
|
| 994 |
// why is this const cast neccessary. What is "correct" approach to setting initial conditions |
| 995 |
Thyra::put_scalar(3.14,rcp_const_cast<Thyra::VectorBase<double> >(nomValues.get_x()).ptr()); |
| 996 |
Thyra::put_scalar(6.28,rcp_const_cast<Thyra::VectorBase<double> >(nomValues.get_x_dot()).ptr()); |
| 997 |
|
| 998 |
// setup the comparison vectors |
| 999 |
Thyra::put_scalar(3.14,x0.ptr()); |
| 1000 |
Thyra::put_scalar(6.28,x0_dot.ptr()); |
| 1001 |
} |
| 1002 |
|
| 1003 |
// check the initial conditions |
| 1004 |
{ |
| 1005 |
InArgs nomValues = me->getNominalValues(); |
| 1006 |
|
| 1007 |
RCP<const Thyra::VectorBase<double> > x0_n = nomValues.get_x(); |
| 1008 |
RCP<const Thyra::VectorBase<double> > x0_dot_n = nomValues.get_x_dot(); |
| 1009 |
|
| 1010 |
// check the error of x0 |
| 1011 |
TEST_ASSERT(testEqualityOfVectorValues( *x0_n, *x0, tol)); |
| 1012 |
TEST_ASSERT(testEqualityOfVectorValues(*x0_dot_n, *x0_dot, tol)); |
| 1013 |
} |
| 1014 |
|
| 1015 |
// add normal parameter |
| 1016 |
///////////////////////////////////////////////////////////// |
| 1017 |
int index_dummy = me->addParameter("SOURCE_TEMPERATURE",1.0); |
| 1018 |
|
| 1019 |
// check the initial conditions |
| 1020 |
{ |
| 1021 |
InArgs nomValues = me->getNominalValues(); |
| 1022 |
|
| 1023 |
RCP<const Thyra::VectorBase<double> > x0_n = nomValues.get_x(); |
| 1024 |
RCP<const Thyra::VectorBase<double> > x0_dot_n = nomValues.get_x_dot(); |
| 1025 |
|
| 1026 |
// check the error of x0 |
| 1027 |
TEST_ASSERT(testEqualityOfVectorValues( *x0_n, *x0, tol)); |
| 1028 |
TEST_ASSERT(testEqualityOfVectorValues(*x0_dot_n, *x0_dot, tol)); |
| 1029 |
} |
| 1030 |
|
| 1031 |
// set new parameter value |
| 1032 |
RCP<Thyra::VectorBase<double> > p0 = Thyra::createMember(me->get_p_space(index_dummy)); |
| 1033 |
{ |
| 1034 |
InArgs nomValues = me->getNominalValues(); |
| 1035 |
|
| 1036 |
Thyra::put_scalar(9.42,rcp_const_cast<Thyra::VectorBase<double> >(nomValues.get_p(index_dummy)).ptr()); |
| 1037 |
Thyra::put_scalar(9.42,p0.ptr()); |
| 1038 |
} |
| 1039 |
|
| 1040 |
// add first distributed parameter |
| 1041 |
///////////////////////////////////////////////////////////// |
| 1042 |
int index_distr_param1 = -1; |
| 1043 |
{ |
| 1044 |
// the vector space for the distributed parameter |
| 1045 |
Teuchos::RCP<const Thyra::VectorSpaceBase<double> > vs = me->get_x_space(); |
| 1046 |
|
| 1047 |
// setup an initial value for the parameter |
| 1048 |
Teuchos::RCP<Thyra::VectorBase<double> > initial = Thyra::createMember(vs); |
| 1049 |
Thyra::put_scalar(0.0,initial.ptr()); |
| 1050 |
|
| 1051 |
// this object changes the parameter from a global object to a ghosted one |
| 1052 |
dataObject = Teuchos::rcp(new panzer::LOCPair_GlobalEvaluationData(ap.lof,panzer::LinearObjContainer::X)); |
| 1053 |
|
| 1054 |
index_distr_param1 = me->addDistributedParameter("Distr Parameter 1", |
| 1055 |
vs, |
| 1056 |
dataObject, |
| 1057 |
initial); |
| 1058 |
} |
| 1059 |
|
| 1060 |
// check the initial conditions |
| 1061 |
{ |
| 1062 |
InArgs nomValues = me->getNominalValues(); |
| 1063 |
|
| 1064 |
RCP<const Thyra::VectorBase<double> > x0_n = nomValues.get_x(); |
| 1065 |
RCP<const Thyra::VectorBase<double> > x0_dot_n = nomValues.get_x_dot(); |
| 1066 |
RCP<const Thyra::VectorBase<double> > p0_n = nomValues.get_p(index_dummy); |
| 1067 |
|
| 1068 |
// check the error of x0 |
| 1069 |
TEST_ASSERT(testEqualityOfVectorValues( *x0_n, *x0, tol)); |
| 1070 |
TEST_ASSERT(testEqualityOfVectorValues(*x0_dot_n, *x0_dot, tol)); |
| 1071 |
TEST_ASSERT(testEqualityOfVectorValues( *p0_n, *p0, tol)); |
| 1072 |
} |
| 1073 |
|
| 1074 |
// set new parameter value |
| 1075 |
RCP<Thyra::VectorBase<double> > p1 = Thyra::createMember(me->get_p_space(index_distr_param1)); |
| 1076 |
{ |
| 1077 |
typedef Thyra::VectorBase<double> Vector; |
| 1078 |
|
| 1079 |
InArgs nomValues = me->getNominalValues(); |
| 1080 |
|
| 1081 |
Thyra::put_scalar(-3.14,rcp_const_cast<Vector>(nomValues.get_p(index_distr_param1)).ptr()); |
| 1082 |
Thyra::put_scalar(-3.14,p1.ptr()); |
| 1083 |
} |
| 1084 |
|
| 1085 |
// add second distributed parameter |
| 1086 |
///////////////////////////////////////////////////////////// |
| 1087 |
{ |
| 1088 |
// the vector space for the distributed parameter |
| 1089 |
Teuchos::RCP<const Thyra::VectorSpaceBase<double> > vs = me->get_x_space(); |
| 1090 |
|
| 1091 |
// setup an initial value for the parameter |
| 1092 |
Teuchos::RCP<Thyra::VectorBase<double> > initial = Thyra::createMember(vs); |
| 1093 |
Thyra::put_scalar(0.0,initial.ptr()); |
| 1094 |
|
| 1095 |
// this object changes the parameter from a global object to a ghosted one |
| 1096 |
dataObject = Teuchos::rcp(new panzer::LOCPair_GlobalEvaluationData(ap.lof,panzer::LinearObjContainer::X)); |
| 1097 |
|
| 1098 |
// we are really just interested in what happens when we call this |
| 1099 |
me->addDistributedParameter("Distr Parameter 2", |
| 1100 |
vs, |
| 1101 |
dataObject, |
| 1102 |
initial); |
| 1103 |
} |
| 1104 |
|
| 1105 |
// check the initial conditions |
| 1106 |
{ |
| 1107 |
InArgs nomValues = me->getNominalValues(); |
| 1108 |
|
| 1109 |
RCP<const Thyra::VectorBase<double> > x0_n = nomValues.get_x(); |
| 1110 |
RCP<const Thyra::VectorBase<double> > x0_dot_n = nomValues.get_x_dot(); |
| 1111 |
RCP<const Thyra::VectorBase<double> > p0_n = nomValues.get_p(index_dummy); |
| 1112 |
RCP<const Thyra::VectorBase<double> > p1_n = nomValues.get_p(index_distr_param1); |
| 1113 |
|
| 1114 |
// check the error of x0 |
| 1115 |
TEST_ASSERT(testEqualityOfVectorValues( *x0_n, *x0, tol)); |
| 1116 |
TEST_ASSERT(testEqualityOfVectorValues(*x0_dot_n, *x0_dot, tol)); |
| 1117 |
TEST_ASSERT(testEqualityOfVectorValues( *p0_n, *p0, tol)); |
| 1118 |
TEST_ASSERT(testEqualityOfVectorValues( *p1_n, *p1, tol)); |
| 1119 |
} |
| 1120 |
} |
| 1121 |
|
| 1122 |
bool testEqualityOfVectorValues(const Thyra::VectorBase<double> & a, |
| 1123 |
const Thyra::VectorBase<double> & b, |
| 1124 |
double tolerance, bool write_to_cout) |
| 1125 |
{ |
| 1126 |
bool is_equal = true; |
| 1127 |
|
| 1128 |
TEUCHOS_ASSERT(a.space()->dim() == b.space()->dim()); |
| 1129 |
|
| 1130 |
Teuchos::ArrayRCP<const double> a_data,b_data; |
| 1131 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(a).getLocalData(Teuchos::ptrFromRef(a_data)); |
| 1132 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(b).getLocalData(Teuchos::ptrFromRef(b_data)); |
| 1133 |
|
| 1134 |
for (int i = 0; i < a_data.size(); ++i) { |
| 1135 |
|
| 1136 |
std::string output = " equal!: "; |
| 1137 |
|
| 1138 |
if (std::fabs(a_data[i] - b_data[i]) > tolerance) { |
| 1139 |
is_equal = false; |
| 1140 |
output = "NOT equal!: "; |
| 1141 |
} |
| 1142 |
|
| 1143 |
if (write_to_cout) |
| 1144 |
std::cout << output << a_data[i] << " - " << b_data[i] << " = " << (a_data[i] - b_data[i]) << std::endl; |
| 1145 |
} |
| 1146 |
|
| 1147 |
int globalSuccess = -1; |
| 1148 |
Teuchos::RCP<const Teuchos::Comm<Teuchos::Ordinal> > comm = Teuchos::DefaultComm<Teuchos::Ordinal>::getComm(); |
| 1149 |
Teuchos::reduceAll( *comm, Teuchos::REDUCE_SUM, is_equal ? 0 : 1, Teuchos::outArg(globalSuccess) ); |
| 1150 |
return (globalSuccess==0); |
| 1151 |
} |
| 1152 |
|
| 1153 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 1154 |
std::vector<panzer::BC>& bcs) |
| 1155 |
{ |
| 1156 |
// Physics block |
| 1157 |
Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); |
| 1158 |
{ |
| 1159 |
Teuchos::ParameterList& p = physics_block.sublist("a"); |
| 1160 |
p.set("Type","Energy"); |
| 1161 |
p.set("Prefix",""); |
| 1162 |
p.set("Model ID","solid"); |
| 1163 |
p.set("Basis Type","HGrad"); |
| 1164 |
p.set("Basis Order",1); |
| 1165 |
p.set("Integration Order",1); |
| 1166 |
} |
| 1167 |
{ |
| 1168 |
Teuchos::ParameterList& p = physics_block.sublist("b"); |
| 1169 |
p.set("Type","Energy"); |
| 1170 |
p.set("Prefix","ION_"); |
| 1171 |
p.set("Model ID","ion solid"); |
| 1172 |
p.set("Basis Type","HGrad"); |
| 1173 |
p.set("Basis Order",1); |
| 1174 |
p.set("Integration Order",1); |
| 1175 |
} |
| 1176 |
|
| 1177 |
|
| 1178 |
{ |
| 1179 |
std::size_t bc_id = 0; |
| 1180 |
panzer::BCType neumann = BCT_Dirichlet; |
| 1181 |
std::string sideset_id = "left"; |
| 1182 |
std::string element_block_id = "eblock-0_0"; |
| 1183 |
std::string dof_name = "TEMPERATURE"; |
| 1184 |
std::string strategy = "Constant"; |
| 1185 |
double value = 5.0; |
| 1186 |
Teuchos::ParameterList p; |
| 1187 |
p.set("Value",value); |
| 1188 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 1189 |
strategy, p); |
| 1190 |
bcs.push_back(bc); |
| 1191 |
} |
| 1192 |
{ |
| 1193 |
std::size_t bc_id = 1; |
| 1194 |
panzer::BCType neumann = BCT_Dirichlet; |
| 1195 |
std::string sideset_id = "right"; |
| 1196 |
std::string element_block_id = "eblock-1_0"; |
| 1197 |
std::string dof_name = "TEMPERATURE"; |
| 1198 |
std::string strategy = "Constant"; |
| 1199 |
double value = 5.0; |
| 1200 |
Teuchos::ParameterList p; |
| 1201 |
p.set("Value",value); |
| 1202 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 1203 |
strategy, p); |
| 1204 |
bcs.push_back(bc); |
| 1205 |
} |
| 1206 |
{ |
| 1207 |
std::size_t bc_id = 2; |
| 1208 |
panzer::BCType neumann = BCT_Dirichlet; |
| 1209 |
std::string sideset_id = "top"; |
| 1210 |
std::string element_block_id = "eblock-1_0"; |
| 1211 |
std::string dof_name = "TEMPERATURE"; |
| 1212 |
std::string strategy = "Constant"; |
| 1213 |
double value = 5.0; |
| 1214 |
Teuchos::ParameterList p; |
| 1215 |
p.set("Value",value); |
| 1216 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 1217 |
strategy, p); |
| 1218 |
bcs.push_back(bc); |
| 1219 |
} |
| 1220 |
} |
| 1221 |
|
| 1222 |
void buildAssemblyPieces(bool parameter_on,bool distr_parameter_on, |
| 1223 |
AssemblyPieces & ap, |
| 1224 |
const std::vector<std::string>& tangentParamNames, |
| 1225 |
bool useBlocking) |
| 1226 |
{ |
| 1227 |
using Teuchos::RCP; |
| 1228 |
|
| 1229 |
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); |
| 1230 |
pl->set("X Blocks",2); |
| 1231 |
pl->set("Y Blocks",1); |
| 1232 |
pl->set("X Elements",6); |
| 1233 |
pl->set("Y Elements",4); |
| 1234 |
|
| 1235 |
panzer_stk::SquareQuadMeshFactory factory; |
| 1236 |
factory.setParameterList(pl); |
| 1237 |
RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD); |
| 1238 |
Teuchos::RCP<const Teuchos::Comm<int> > Comm = Teuchos::DefaultComm<int>::getComm(); |
| 1239 |
Teuchos::RCP<const Teuchos::MpiComm<int> > mpiComm |
| 1240 |
= Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(Comm); |
| 1241 |
|
| 1242 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks"); |
| 1243 |
std::vector<panzer::BC> bcs; |
| 1244 |
testInitialzation(ipb, bcs); |
| 1245 |
|
| 1246 |
ap.fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); |
| 1247 |
|
| 1248 |
// build physics blocks |
| 1249 |
////////////////////////////////////////////////////////////// |
| 1250 |
const std::size_t workset_size = 20; |
| 1251 |
ap.eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 1252 |
ap.bc_factory = Teuchos::rcp(new user_app::BCFactory); |
| 1253 |
ap.gd = panzer::createGlobalData(); |
| 1254 |
{ |
| 1255 |
std::map<std::string,std::string> block_ids_to_physics_ids; |
| 1256 |
block_ids_to_physics_ids["eblock-0_0"] = "test physics"; |
| 1257 |
block_ids_to_physics_ids["eblock-1_0"] = "test physics"; |
| 1258 |
|
| 1259 |
std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo; |
| 1260 |
block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); |
| 1261 |
block_ids_to_cell_topo["eblock-1_0"] = mesh->getCellTopology("eblock-1_0"); |
| 1262 |
|
| 1263 |
int default_integration_order = 1; |
| 1264 |
|
| 1265 |
bool build_transient_support = true; |
| 1266 |
panzer::buildPhysicsBlocks(block_ids_to_physics_ids, |
| 1267 |
block_ids_to_cell_topo, |
| 1268 |
ipb, |
| 1269 |
default_integration_order, |
| 1270 |
workset_size, |
| 1271 |
ap.eqset_factory, |
| 1272 |
ap.gd, |
| 1273 |
build_transient_support, |
| 1274 |
ap.physicsBlocks, |
| 1275 |
tangentParamNames); |
| 1276 |
} |
| 1277 |
|
| 1278 |
// build worksets |
| 1279 |
////////////////////////////////////////////////////////////// |
| 1280 |
// build WorksetContainer |
| 1281 |
Teuchos::RCP<panzer_stk::WorksetFactory> wkstFactory |
| 1282 |
= Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory |
| 1283 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation) |
| 1284 |
= Teuchos::rcp(new panzer::WorksetContainer); |
| 1285 |
wkstContainer->setFactory(wkstFactory); |
| 1286 |
for(size_t i=0;i<ap.physicsBlocks.size();i++) |
| 1287 |
wkstContainer->setNeeds(ap.physicsBlocks[i]->elementBlockID(),ap.physicsBlocks[i]->getWorksetNeeds()); |
| 1288 |
wkstContainer->setWorksetSize(workset_size); |
| 1289 |
ap.wkstContainer = wkstContainer; |
| 1290 |
|
| 1291 |
// build DOF Manager |
| 1292 |
///////////////////////////////////////////////////////////// |
| 1293 |
|
| 1294 |
// build the connection manager |
| 1295 |
const Teuchos::RCP<panzer::ConnManager> |
| 1296 |
conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 1297 |
|
| 1298 |
// build the state dof manager and LOF |
| 1299 |
if(!useBlocking) { |
| 1300 |
panzer::DOFManagerFactory globalIndexerFactory; |
| 1301 |
RCP<panzer::GlobalIndexer> dofManager |
| 1302 |
= globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),ap.physicsBlocks,conn_manager); |
| 1303 |
ap.dofManager = dofManager; |
| 1304 |
|
| 1305 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory |
| 1306 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,dofManager)); |
| 1307 |
ap.lof = linObjFactory; |
| 1308 |
} |
| 1309 |
else { |
| 1310 |
panzer::BlockedDOFManagerFactory globalIndexerFactory; |
| 1311 |
auto dofManager = globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),ap.physicsBlocks, |
| 1312 |
conn_manager,"blocked: TEMPERATURE ION_TEMPERATURE"); |
| 1313 |
|
| 1314 |
ap.dofManager = dofManager; |
| 1315 |
|
| 1316 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory |
| 1317 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,dofManager)); |
| 1318 |
ap.lof = linObjFactory; |
| 1319 |
} |
| 1320 |
|
| 1321 |
// build the dof manager and LOF for DENSITY control |
| 1322 |
if(distr_parameter_on) { |
| 1323 |
Teuchos::RCP<panzer::DOFManager> dofManager |
| 1324 |
= Teuchos::rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD)); |
| 1325 |
|
| 1326 |
Teuchos::RCP<Intrepid2FieldPattern> fp |
| 1327 |
= Teuchos::rcp(new Intrepid2FieldPattern(panzer::createIntrepid2Basis<PHX::exec_space,double,double>("HGrad",1,mesh->getCellTopology("eblock-0_0")))); |
| 1328 |
dofManager->addField("eblock-0_0","DENSITY",fp); |
| 1329 |
dofManager->addField("eblock-1_0","DENSITY",fp); |
| 1330 |
|
| 1331 |
dofManager->setOrientationsRequired(false); |
| 1332 |
dofManager->buildGlobalUnknowns(); |
| 1333 |
|
| 1334 |
// build a nonsquare LOF for the parameter vector |
| 1335 |
Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> > linObjFactory = panzer::cloneWithNewDomain(*ap.lof,dofManager); |
| 1336 |
|
| 1337 |
ap.param_dofManager = dofManager; |
| 1338 |
ap.param_ged = linObjFactory->buildReadOnlyDomainContainer(); |
| 1339 |
ap.param_lof = linObjFactory; |
| 1340 |
} |
| 1341 |
|
| 1342 |
ap.rLibrary = Teuchos::rcp(new panzer::ResponseLibrary<panzer::Traits>(wkstContainer,ap.dofManager,ap.lof)); |
| 1343 |
|
| 1344 |
// setup field manager build |
| 1345 |
///////////////////////////////////////////////////////////// |
| 1346 |
|
| 1347 |
// Add in the application specific closure model factory |
| 1348 |
user_app::MyModelFactory_TemplateBuilder cm_builder; |
| 1349 |
cm_builder.setDistributedParameterLOF(ap.param_lof); |
| 1350 |
ap.cm_factory.buildObjects(cm_builder); |
| 1351 |
|
| 1352 |
Teuchos::ParameterList closure_models("Closure Models"); |
| 1353 |
if(parameter_on) |
| 1354 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<std::string>("Type","Parameter"); |
| 1355 |
else |
| 1356 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<double>("Value",1.0); |
| 1357 |
if(distr_parameter_on) |
| 1358 |
closure_models.sublist("solid").sublist("DENSITY").set("Type","Distributed Parameter"); |
| 1359 |
else |
| 1360 |
closure_models.sublist("solid").sublist("DENSITY").set<double>("Value",1.0); |
| 1361 |
closure_models.sublist("solid").sublist("HEAT_CAPACITY").set<double>("Value",1.0); |
| 1362 |
closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE").set<double>("Value",1.0); |
| 1363 |
closure_models.sublist("ion solid").sublist("ION_DENSITY").set<double>("Value",1.0); |
| 1364 |
closure_models.sublist("ion solid").sublist("ION_DENSITY").set<double>("Value",1.0); |
| 1365 |
closure_models.sublist("ion solid").sublist("ION_HEAT_CAPACITY").set<double>("Value",1.0); |
| 1366 |
ap.closure_models = closure_models; |
| 1367 |
|
| 1368 |
ap.user_data = Teuchos::ParameterList("User Data"); |
| 1369 |
|
| 1370 |
ap.fmb->setWorksetContainer(wkstContainer); |
| 1371 |
ap.fmb->setupVolumeFieldManagers(ap.physicsBlocks,ap.cm_factory,closure_models,*ap.lof,ap.user_data); |
| 1372 |
ap.fmb->setupBCFieldManagers(bcs,ap.physicsBlocks,*ap.eqset_factory,ap.cm_factory,*ap.bc_factory, |
| 1373 |
closure_models,*ap.lof,ap.user_data); |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
} |