| 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 |
#include "Panzer_NodeType.hpp" |
| 17 |
#include "Teuchos_DefaultComm.hpp" |
| 18 |
#include "Teuchos_GlobalMPISession.hpp" |
| 19 |
|
| 20 |
#include "Thyra_VectorStdOps.hpp" |
| 21 |
#include "Thyra_LinearOpTester.hpp" |
| 22 |
#include "Thyra_DefaultScaledAdjointLinearOp.hpp" |
| 23 |
|
| 24 |
#include "Panzer_STK_Version.hpp" |
| 25 |
#include "PanzerAdaptersSTK_config.hpp" |
| 26 |
#include "Panzer_STK_Interface.hpp" |
| 27 |
#include "Panzer_STK_SquareQuadMeshFactory.hpp" |
| 28 |
#include "Panzer_STK_SetupUtilities.hpp" |
| 29 |
#include "Panzer_STK_WorksetFactory.hpp" |
| 30 |
#include "Panzer_Workset_Builder.hpp" |
| 31 |
#include "Panzer_FieldManagerBuilder.hpp" |
| 32 |
#include "Panzer_STKConnManager.hpp" |
| 33 |
#include "Panzer_TpetraLinearObjFactory.hpp" |
| 34 |
#include "Panzer_BlockedEpetraLinearObjFactory.hpp" |
| 35 |
#include "Panzer_AssemblyEngine.hpp" |
| 36 |
#include "Panzer_AssemblyEngine_TemplateManager.hpp" |
| 37 |
#include "Panzer_AssemblyEngine_TemplateBuilder.hpp" |
| 38 |
#include "Panzer_DOFManagerFactory.hpp" |
| 39 |
#include "Panzer_BlockedDOFManagerFactory.hpp" |
| 40 |
#include "Panzer_ModelEvaluator.hpp" |
| 41 |
#include "Panzer_ResponseLibrary.hpp" |
| 42 |
#include "Panzer_GlobalData.hpp" |
| 43 |
#include "Panzer_LOCPair_GlobalEvaluationData.hpp" |
| 44 |
#include "Panzer_WorksetContainer.hpp" |
| 45 |
#include "Panzer_PauseToAttach.hpp" |
| 46 |
#include "Panzer_ResponseEvaluatorFactory_Functional.hpp" |
| 47 |
#include "Panzer_ParameterLibraryUtilities.hpp" |
| 48 |
#include "Panzer_ThyraObjContainer.hpp" |
| 49 |
#include "Panzer_DOFManager.hpp" |
| 50 |
#include "Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.hpp" |
| 51 |
#include "Panzer_GlobalIndexer_Utilities.hpp" |
| 52 |
|
| 53 |
#include "user_app_EquationSetFactory.hpp" |
| 54 |
#include "user_app_ClosureModel_Factory_TemplateBuilder.hpp" |
| 55 |
#include "user_app_BCStrategy_Factory.hpp" |
| 56 |
|
| 57 |
#include "Epetra_MpiComm.h" |
| 58 |
|
| 59 |
#include "Teuchos_DefaultMpiComm.hpp" |
| 60 |
#include "Teuchos_OpaqueWrapper.hpp" |
| 61 |
|
| 62 |
#include <cstdio> // for get char |
| 63 |
#include <fstream> |
| 64 |
|
| 65 |
namespace panzer { |
| 66 |
|
| 67 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 68 |
std::vector<panzer::BC>& bcs); |
| 69 |
|
| 70 |
struct AssemblyPieces { |
| 71 |
Teuchos::RCP<panzer::FieldManagerBuilder> fmb; |
| 72 |
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > rLibrary; |
| 73 |
Teuchos::RCP<panzer::GlobalData> gd; |
| 74 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > lof; |
| 75 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > param_lof; |
| 76 |
Teuchos::RCP<panzer::GlobalIndexer> dofManager; |
| 77 |
Teuchos::RCP<panzer::GlobalIndexer> param_dofManager; |
| 78 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer; |
| 79 |
Teuchos::ParameterList user_data; |
| 80 |
std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; |
| 81 |
Teuchos::RCP<panzer::EquationSetFactory> eqset_factory; |
| 82 |
panzer::ClosureModelFactory_TemplateManager<panzer::Traits> cm_factory; |
| 83 |
Teuchos::ParameterList closure_models; |
| 84 |
Teuchos::RCP<EpetraVector_ReadOnly_GlobalEvaluationData> param_ged; |
| 85 |
std::vector<panzer::BC> bcs; |
| 86 |
Teuchos::RCP<panzer::BCStrategyFactory> bc_factory; |
| 87 |
}; |
| 88 |
|
| 89 |
void buildAssemblyPieces(bool distr_parameter_on, |
| 90 |
AssemblyPieces & ap, |
| 91 |
const std::vector<std::string>& tangentParamNames = std::vector<std::string>()); |
| 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 |
// Testing Parameter Support |
| 98 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2g_dx2) |
| 99 |
{ |
| 100 |
typedef panzer::Traits::RealType RealType; |
| 101 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 102 |
typedef Thyra::SpmdVectorBase<RealType> SpmdVectorType; |
| 103 |
typedef Thyra::ProductVectorBase<RealType> ProductVectorType; |
| 104 |
|
| 105 |
using Teuchos::RCP; |
| 106 |
using Teuchos::rcp_dynamic_cast; |
| 107 |
|
| 108 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 109 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 110 |
typedef panzer::ModelEvaluator<double> PME; |
| 111 |
|
| 112 |
|
| 113 |
bool distr_param_on = true; |
| 114 |
AssemblyPieces ap; |
| 115 |
buildAssemblyPieces(distr_param_on,ap); |
| 116 |
|
| 117 |
int rIndex = -1; |
| 118 |
|
| 119 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 120 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 121 |
bool build_transient_support = true; |
| 122 |
RCP<PME> me |
| 123 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 124 |
|
| 125 |
const double DENSITY_VALUE = 3.7; |
| 126 |
const double TEMPERATURE_VALUE = 2.0; |
| 127 |
const double PERTURB_VALUE = 0.1; |
| 128 |
|
| 129 |
// add in a flexible response |
| 130 |
{ |
| 131 |
Teuchos::RCP<panzer::FunctionalResponse_Builder<int,int> > builder |
| 132 |
= Teuchos::rcp(new panzer::FunctionalResponse_Builder<int,int>); |
| 133 |
|
| 134 |
builder->comm = MPI_COMM_WORLD; // good enough |
| 135 |
builder->cubatureDegree = 1; |
| 136 |
builder->requiresCellIntegral = true; |
| 137 |
builder->quadPointField = ""; |
| 138 |
|
| 139 |
std::vector<panzer::WorksetDescriptor> blocks; |
| 140 |
blocks.push_back(panzer::blockDescriptor("eblock-0_0")); |
| 141 |
blocks.push_back(panzer::blockDescriptor("eblock-1_0")); |
| 142 |
rIndex = me->addFlexibleResponse("INTEGRAND",blocks,builder); // integrate the density |
| 143 |
} |
| 144 |
|
| 145 |
// add distributed parameter |
| 146 |
{ |
| 147 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 148 |
|
| 149 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 150 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 151 |
me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 152 |
ap.param_ged,param_density,ap.param_dofManager); |
| 153 |
} |
| 154 |
|
| 155 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 156 |
*ap.eqset_factory, |
| 157 |
*ap.bc_factory, |
| 158 |
ap.cm_factory, |
| 159 |
ap.cm_factory, |
| 160 |
ap.closure_models, |
| 161 |
ap.user_data,false,""); |
| 162 |
|
| 163 |
// test value |
| 164 |
{ |
| 165 |
RCP<VectorType> g = Thyra::createMember(*me->get_g_space(rIndex)); |
| 166 |
|
| 167 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 168 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 169 |
|
| 170 |
InArgs in_args = me->createInArgs(); |
| 171 |
in_args.set_x(x); |
| 172 |
|
| 173 |
OutArgs out_args = me->createOutArgs(); |
| 174 |
out_args.set_g(0,g); |
| 175 |
|
| 176 |
me->evalModel(in_args, out_args); |
| 177 |
|
| 178 |
out << "RESPONSE = " << std::endl; |
| 179 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 180 |
|
| 181 |
Teuchos::ArrayRCP<const double> g_data; |
| 182 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 183 |
TEST_FLOATING_EQUALITY(g_data[0],TEMPERATURE_VALUE*TEMPERATURE_VALUE*DENSITY_VALUE*DENSITY_VALUE*DENSITY_VALUE,1e-12); |
| 184 |
// Volume of integral is 1.0, then just compute the integrand |
| 185 |
} |
| 186 |
|
| 187 |
RCP<VectorType> D2gDx2 = Thyra::createMember(*me->get_x_space()); |
| 188 |
|
| 189 |
// test hessian |
| 190 |
{ |
| 191 |
|
| 192 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 193 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 194 |
|
| 195 |
RCP<VectorType> dx = Thyra::createMember(*me->get_x_space()); |
| 196 |
Thyra::assign(dx.ptr(),PERTURB_VALUE); |
| 197 |
|
| 198 |
InArgs in_args = me->createInArgs(); |
| 199 |
in_args.set_x(x); |
| 200 |
|
| 201 |
me->evalModel_D2gDx2(rIndex,in_args,dx,D2gDx2); |
| 202 |
|
| 203 |
out << "D2gDx2 = \n" << Teuchos::describe(*D2gDx2,Teuchos::VERB_EXTREME) << std::endl; |
| 204 |
} |
| 205 |
|
| 206 |
for(int b=0;b<2;b++) { |
| 207 |
out << "checking vector: " << b << std::endl; |
| 208 |
Teuchos::ArrayRCP<const double> D2gDx2_data; |
| 209 |
|
| 210 |
RCP<const ProductVectorType> product_D2gDx2 = rcp_dynamic_cast<const ProductVectorType>(D2gDx2,true); |
| 211 |
RCP<const SpmdVectorType> spmd_D2gDx2 = rcp_dynamic_cast<const SpmdVectorType>(product_D2gDx2->getVectorBlock(b),true); |
| 212 |
spmd_D2gDx2->getLocalData(Teuchos::ptrFromRef(D2gDx2_data)); |
| 213 |
double scale = 2.0*DENSITY_VALUE*DENSITY_VALUE*DENSITY_VALUE*PERTURB_VALUE; |
| 214 |
double int_phi = 1.0/192.0; |
| 215 |
for(int i=0;i<D2gDx2_data.size();i++) { |
| 216 |
out << D2gDx2_data[i] << " " << D2gDx2_data[i]/(scale*int_phi) << std::endl; |
| 217 |
bool a = std::fabs(D2gDx2_data[i]-scale*int_phi)/(scale*int_phi) <= 1e-14; |
| 218 |
bool b = std::fabs(D2gDx2_data[i]-2.0*scale*int_phi)/(2.0*scale*int_phi) <= 1e-14; |
| 219 |
bool c = std::fabs(D2gDx2_data[i]-4.0*scale*int_phi)/(4.0*scale*int_phi) <= 1e-14; |
| 220 |
bool d = (D2gDx2_data[i]==0.0); |
| 221 |
|
| 222 |
TEST_ASSERT(a || b || c || d); |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
// Testing Parameter Support |
| 228 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2g_dp2) |
| 229 |
{ |
| 230 |
typedef panzer::Traits::RealType RealType; |
| 231 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 232 |
typedef Thyra::SpmdVectorBase<RealType> SpmdVectorType; |
| 233 |
|
| 234 |
using Teuchos::RCP; |
| 235 |
using Teuchos::rcp_dynamic_cast; |
| 236 |
|
| 237 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 238 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 239 |
typedef panzer::ModelEvaluator<double> PME; |
| 240 |
|
| 241 |
|
| 242 |
bool distr_param_on = true; |
| 243 |
AssemblyPieces ap; |
| 244 |
buildAssemblyPieces(distr_param_on,ap); |
| 245 |
|
| 246 |
int pIndex = -1; |
| 247 |
int rIndex = -1; |
| 248 |
|
| 249 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 250 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 251 |
bool build_transient_support = true; |
| 252 |
RCP<PME> me |
| 253 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 254 |
|
| 255 |
const double DENSITY_VALUE = 3.7; |
| 256 |
const double TEMPERATURE_VALUE = 2.0; |
| 257 |
const double PERTURB_VALUE = 0.1; |
| 258 |
|
| 259 |
// add in a flexible response |
| 260 |
{ |
| 261 |
Teuchos::RCP<panzer::FunctionalResponse_Builder<int,int> > builder |
| 262 |
= Teuchos::rcp(new panzer::FunctionalResponse_Builder<int,int>); |
| 263 |
|
| 264 |
builder->comm = MPI_COMM_WORLD; // good enough |
| 265 |
builder->cubatureDegree = 1; |
| 266 |
builder->requiresCellIntegral = true; |
| 267 |
builder->quadPointField = ""; |
| 268 |
|
| 269 |
std::vector<panzer::WorksetDescriptor> blocks; |
| 270 |
blocks.push_back(panzer::blockDescriptor("eblock-0_0")); |
| 271 |
blocks.push_back(panzer::blockDescriptor("eblock-1_0")); |
| 272 |
rIndex = me->addFlexibleResponse("INTEGRAND",blocks,builder); // integrate the density |
| 273 |
} |
| 274 |
|
| 275 |
// add distributed parameter |
| 276 |
{ |
| 277 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 278 |
|
| 279 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 280 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 281 |
pIndex = me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 282 |
ap.param_ged,param_density,ap.param_dofManager); |
| 283 |
} |
| 284 |
|
| 285 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 286 |
*ap.eqset_factory, |
| 287 |
*ap.bc_factory, |
| 288 |
ap.cm_factory, |
| 289 |
ap.cm_factory, |
| 290 |
ap.closure_models, |
| 291 |
ap.user_data,false,""); |
| 292 |
|
| 293 |
// test value |
| 294 |
{ |
| 295 |
RCP<VectorType> g = Thyra::createMember(*me->get_g_space(rIndex)); |
| 296 |
|
| 297 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 298 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 299 |
|
| 300 |
InArgs in_args = me->createInArgs(); |
| 301 |
in_args.set_x(x); |
| 302 |
|
| 303 |
OutArgs out_args = me->createOutArgs(); |
| 304 |
out_args.set_g(0,g); |
| 305 |
|
| 306 |
me->evalModel(in_args, out_args); |
| 307 |
|
| 308 |
out << "RESPONSE = " << std::endl; |
| 309 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 310 |
|
| 311 |
Teuchos::ArrayRCP<const double> g_data; |
| 312 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 313 |
TEST_FLOATING_EQUALITY(g_data[0],TEMPERATURE_VALUE*TEMPERATURE_VALUE*DENSITY_VALUE*DENSITY_VALUE*DENSITY_VALUE,1e-12); |
| 314 |
// Volume of integral is 1.0, then just compute the integrand |
| 315 |
} |
| 316 |
|
| 317 |
RCP<VectorType> D2gDp2 = Thyra::createMember(*me->get_p_space(pIndex)); |
| 318 |
|
| 319 |
// test hessian |
| 320 |
{ |
| 321 |
|
| 322 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 323 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 324 |
|
| 325 |
RCP<VectorType> dp = Thyra::createMember(*me->get_p_space(pIndex)); |
| 326 |
Thyra::assign(dp.ptr(),PERTURB_VALUE); |
| 327 |
|
| 328 |
InArgs in_args = me->createInArgs(); |
| 329 |
in_args.set_x(x); |
| 330 |
|
| 331 |
me->evalModel_D2gDp2(rIndex,pIndex,in_args,dp,D2gDp2); |
| 332 |
|
| 333 |
out << "D2gDp2 = \n" << Teuchos::describe(*D2gDp2,Teuchos::VERB_EXTREME) << std::endl; |
| 334 |
} |
| 335 |
|
| 336 |
Teuchos::ArrayRCP<const double> D2gDp2_data; |
| 337 |
RCP<const SpmdVectorType> spmd_D2gDp2 = rcp_dynamic_cast<const SpmdVectorType>(D2gDp2); |
| 338 |
rcp_dynamic_cast<const SpmdVectorType>(D2gDp2)->getLocalData(Teuchos::ptrFromRef(D2gDp2_data)); |
| 339 |
double scale = 6.0*TEMPERATURE_VALUE*TEMPERATURE_VALUE*DENSITY_VALUE*PERTURB_VALUE; |
| 340 |
double int_phi = 1.0/192.0; |
| 341 |
for(int i=0;i<D2gDp2_data.size();i++) { |
| 342 |
out << D2gDp2_data[i] << " " << D2gDp2_data[i]/(scale*int_phi) << std::endl; |
| 343 |
bool a = std::fabs(D2gDp2_data[i]-scale*int_phi)/(scale*int_phi) <= 1e-14; |
| 344 |
bool b = std::fabs(D2gDp2_data[i]-2.0*scale*int_phi)/(2.0*scale*int_phi) <= 1e-14; |
| 345 |
bool c = std::fabs(D2gDp2_data[i]-4.0*scale*int_phi)/(4.0*scale*int_phi) <= 1e-14; |
| 346 |
bool d = (D2gDp2_data[i]==0.0); |
| 347 |
|
| 348 |
TEST_ASSERT(a || b || c || d); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
// Testing Parameter Support |
| 353 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2g_dpdx) |
| 354 |
{ |
| 355 |
typedef panzer::Traits::RealType RealType; |
| 356 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 357 |
typedef Thyra::SpmdVectorBase<RealType> SpmdVectorType; |
| 358 |
|
| 359 |
using Teuchos::RCP; |
| 360 |
using Teuchos::rcp_dynamic_cast; |
| 361 |
|
| 362 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 363 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 364 |
typedef panzer::ModelEvaluator<double> PME; |
| 365 |
|
| 366 |
|
| 367 |
bool distr_param_on = true; |
| 368 |
AssemblyPieces ap; |
| 369 |
buildAssemblyPieces(distr_param_on,ap); |
| 370 |
|
| 371 |
int pIndex = -1; |
| 372 |
int rIndex = -1; |
| 373 |
|
| 374 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 375 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 376 |
bool build_transient_support = true; |
| 377 |
RCP<PME> me |
| 378 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 379 |
|
| 380 |
const double DENSITY_VALUE = 3.7; |
| 381 |
const double TEMPERATURE_VALUE = 2.0; |
| 382 |
const double PERTURB_VALUE = 0.1; |
| 383 |
|
| 384 |
// add in a flexible response |
| 385 |
{ |
| 386 |
Teuchos::RCP<panzer::FunctionalResponse_Builder<int,int> > builder |
| 387 |
= Teuchos::rcp(new panzer::FunctionalResponse_Builder<int,int>); |
| 388 |
|
| 389 |
builder->comm = MPI_COMM_WORLD; // good enough |
| 390 |
builder->cubatureDegree = 1; |
| 391 |
builder->requiresCellIntegral = true; |
| 392 |
builder->quadPointField = ""; |
| 393 |
|
| 394 |
std::vector<panzer::WorksetDescriptor> blocks; |
| 395 |
blocks.push_back(panzer::blockDescriptor("eblock-0_0")); |
| 396 |
blocks.push_back(panzer::blockDescriptor("eblock-1_0")); |
| 397 |
rIndex = me->addFlexibleResponse("INTEGRAND",blocks,builder); // integrate the density |
| 398 |
} |
| 399 |
|
| 400 |
// add distributed parameter |
| 401 |
{ |
| 402 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 403 |
|
| 404 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 405 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 406 |
pIndex = me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 407 |
ap.param_ged,param_density,ap.param_dofManager); |
| 408 |
} |
| 409 |
|
| 410 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 411 |
*ap.eqset_factory, |
| 412 |
*ap.bc_factory, |
| 413 |
ap.cm_factory, |
| 414 |
ap.cm_factory, |
| 415 |
ap.closure_models, |
| 416 |
ap.user_data,false,""); |
| 417 |
|
| 418 |
// test value |
| 419 |
{ |
| 420 |
RCP<VectorType> g = Thyra::createMember(*me->get_g_space(rIndex)); |
| 421 |
|
| 422 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 423 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 424 |
|
| 425 |
InArgs in_args = me->createInArgs(); |
| 426 |
in_args.set_x(x); |
| 427 |
|
| 428 |
OutArgs out_args = me->createOutArgs(); |
| 429 |
out_args.set_g(0,g); |
| 430 |
|
| 431 |
me->evalModel(in_args, out_args); |
| 432 |
|
| 433 |
out << "RESPONSE = " << std::endl; |
| 434 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 435 |
|
| 436 |
Teuchos::ArrayRCP<const double> g_data; |
| 437 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 438 |
TEST_FLOATING_EQUALITY(g_data[0],TEMPERATURE_VALUE*TEMPERATURE_VALUE*DENSITY_VALUE*DENSITY_VALUE*DENSITY_VALUE,1e-12); |
| 439 |
// Volume of integral is 1.0, then just compute the integrand |
| 440 |
} |
| 441 |
|
| 442 |
RCP<VectorType> D2gDpDx = Thyra::createMember(*me->get_p_space(pIndex)); |
| 443 |
|
| 444 |
// test hessian |
| 445 |
{ |
| 446 |
|
| 447 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 448 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 449 |
|
| 450 |
RCP<VectorType> dx = Thyra::createMember(*me->get_x_space()); |
| 451 |
Thyra::assign(dx.ptr(),PERTURB_VALUE); |
| 452 |
|
| 453 |
InArgs in_args = me->createInArgs(); |
| 454 |
in_args.set_x(x); |
| 455 |
|
| 456 |
me->evalModel_D2gDpDx(rIndex,pIndex,in_args,dx,D2gDpDx); |
| 457 |
|
| 458 |
out << "D2gDpDx = \n" << Teuchos::describe(*D2gDpDx,Teuchos::VERB_EXTREME) << std::endl; |
| 459 |
} |
| 460 |
|
| 461 |
Teuchos::ArrayRCP<const double> D2gDpDx_data; |
| 462 |
|
| 463 |
RCP<const SpmdVectorType> spmd_D2gDpDx = rcp_dynamic_cast<const SpmdVectorType>(D2gDpDx); |
| 464 |
spmd_D2gDpDx->getLocalData(Teuchos::ptrFromRef(D2gDpDx_data)); |
| 465 |
double scale = 6.0*TEMPERATURE_VALUE*DENSITY_VALUE*DENSITY_VALUE*PERTURB_VALUE; |
| 466 |
double int_phi = 1.0/192.0; |
| 467 |
for(int i=0;i<D2gDpDx_data.size();i++) { |
| 468 |
out << D2gDpDx_data[i] << " " << D2gDpDx_data[i]/(scale*int_phi) << std::endl; |
| 469 |
bool a = std::fabs(D2gDpDx_data[i]-scale*int_phi)/(scale*int_phi) <= 1e-14; |
| 470 |
bool b = std::fabs(D2gDpDx_data[i]-2.0*scale*int_phi)/(2.0*scale*int_phi) <= 1e-14; |
| 471 |
bool c = std::fabs(D2gDpDx_data[i]-4.0*scale*int_phi)/(4.0*scale*int_phi) <= 1e-14; |
| 472 |
bool d = (D2gDpDx_data[i]==0.0); |
| 473 |
|
| 474 |
TEST_ASSERT(a || b || c || d); |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
// Testing Parameter Support |
| 479 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2g_dxdp) |
| 480 |
{ |
| 481 |
typedef panzer::Traits::RealType RealType; |
| 482 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 483 |
typedef Thyra::SpmdVectorBase<RealType> SpmdVectorType; |
| 484 |
typedef Thyra::ProductVectorBase<RealType> ProductVectorType; |
| 485 |
|
| 486 |
using Teuchos::RCP; |
| 487 |
using Teuchos::rcp_dynamic_cast; |
| 488 |
|
| 489 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 490 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 491 |
typedef panzer::ModelEvaluator<double> PME; |
| 492 |
|
| 493 |
|
| 494 |
bool distr_param_on = true; |
| 495 |
AssemblyPieces ap; |
| 496 |
buildAssemblyPieces(distr_param_on,ap); |
| 497 |
|
| 498 |
int pIndex = -1; |
| 499 |
int rIndex = -1; |
| 500 |
|
| 501 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 502 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 503 |
bool build_transient_support = true; |
| 504 |
RCP<PME> me |
| 505 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 506 |
|
| 507 |
const double DENSITY_VALUE = 3.7; |
| 508 |
const double TEMPERATURE_VALUE = 2.0; |
| 509 |
const double PERTURB_VALUE = 0.1; |
| 510 |
|
| 511 |
// add in a flexible response |
| 512 |
{ |
| 513 |
Teuchos::RCP<panzer::FunctionalResponse_Builder<int,int> > builder |
| 514 |
= Teuchos::rcp(new panzer::FunctionalResponse_Builder<int,int>); |
| 515 |
|
| 516 |
builder->comm = MPI_COMM_WORLD; // good enough |
| 517 |
builder->cubatureDegree = 1; |
| 518 |
builder->requiresCellIntegral = true; |
| 519 |
builder->quadPointField = ""; |
| 520 |
|
| 521 |
std::vector<panzer::WorksetDescriptor> blocks; |
| 522 |
blocks.push_back(panzer::blockDescriptor("eblock-0_0")); |
| 523 |
blocks.push_back(panzer::blockDescriptor("eblock-1_0")); |
| 524 |
rIndex = me->addFlexibleResponse("INTEGRAND",blocks,builder); // integrate the density |
| 525 |
} |
| 526 |
|
| 527 |
// add distributed parameter |
| 528 |
{ |
| 529 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 530 |
|
| 531 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 532 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 533 |
pIndex = me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 534 |
ap.param_ged,param_density,ap.param_dofManager); |
| 535 |
} |
| 536 |
|
| 537 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 538 |
*ap.eqset_factory, |
| 539 |
*ap.bc_factory, |
| 540 |
ap.cm_factory, |
| 541 |
ap.cm_factory, |
| 542 |
ap.closure_models, |
| 543 |
ap.user_data,false,""); |
| 544 |
|
| 545 |
// test value |
| 546 |
{ |
| 547 |
RCP<VectorType> g = Thyra::createMember(*me->get_g_space(rIndex)); |
| 548 |
|
| 549 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 550 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 551 |
|
| 552 |
InArgs in_args = me->createInArgs(); |
| 553 |
in_args.set_x(x); |
| 554 |
|
| 555 |
OutArgs out_args = me->createOutArgs(); |
| 556 |
out_args.set_g(0,g); |
| 557 |
|
| 558 |
me->evalModel(in_args, out_args); |
| 559 |
|
| 560 |
out << "RESPONSE = " << std::endl; |
| 561 |
out << Teuchos::describe(*g,Teuchos::VERB_EXTREME) << std::endl; |
| 562 |
|
| 563 |
Teuchos::ArrayRCP<const double> g_data; |
| 564 |
rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(g)->getLocalData(Teuchos::ptrFromRef(g_data)); |
| 565 |
TEST_FLOATING_EQUALITY(g_data[0],TEMPERATURE_VALUE*TEMPERATURE_VALUE*DENSITY_VALUE*DENSITY_VALUE*DENSITY_VALUE,1e-12); |
| 566 |
// Volume of integral is 1.0, then just compute the integrand |
| 567 |
} |
| 568 |
|
| 569 |
RCP<VectorType> D2gDxDp = Thyra::createMember(*me->get_x_space()); |
| 570 |
|
| 571 |
// test hessian |
| 572 |
{ |
| 573 |
|
| 574 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 575 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 576 |
|
| 577 |
RCP<VectorType> dp = Thyra::createMember(*me->get_p_space(pIndex)); |
| 578 |
Thyra::assign(dp.ptr(),PERTURB_VALUE); |
| 579 |
|
| 580 |
InArgs in_args = me->createInArgs(); |
| 581 |
in_args.set_x(x); |
| 582 |
|
| 583 |
me->evalModel_D2gDxDp(rIndex,pIndex,in_args,dp,D2gDxDp); |
| 584 |
|
| 585 |
out << "D2gDxDp = \n" << Teuchos::describe(*D2gDxDp,Teuchos::VERB_EXTREME) << std::endl; |
| 586 |
} |
| 587 |
|
| 588 |
for(int b=0;b<2;b++) { |
| 589 |
out << "checking vector: " << b << std::endl; |
| 590 |
Teuchos::ArrayRCP<const double> D2gDxDp_data; |
| 591 |
|
| 592 |
RCP<const ProductVectorType> product_D2gDxDp = rcp_dynamic_cast<const ProductVectorType>(D2gDxDp,true); |
| 593 |
RCP<const SpmdVectorType> spmd_D2gDxDp = rcp_dynamic_cast<const SpmdVectorType>(product_D2gDxDp->getVectorBlock(b)); |
| 594 |
spmd_D2gDxDp->getLocalData(Teuchos::ptrFromRef(D2gDxDp_data)); |
| 595 |
double scale = 6.0*TEMPERATURE_VALUE*DENSITY_VALUE*DENSITY_VALUE*PERTURB_VALUE; |
| 596 |
double int_phi = 1.0/192.0; |
| 597 |
for(int i=0;i<D2gDxDp_data.size();i++) { |
| 598 |
out << D2gDxDp_data[i] << " " << D2gDxDp_data[i]/(scale*int_phi) << std::endl; |
| 599 |
bool a = std::fabs(D2gDxDp_data[i]-scale*int_phi)/(scale*int_phi) <= 1e-14; |
| 600 |
bool b = std::fabs(D2gDxDp_data[i]-2.0*scale*int_phi)/(2.0*scale*int_phi) <= 1e-14; |
| 601 |
bool c = std::fabs(D2gDxDp_data[i]-4.0*scale*int_phi)/(4.0*scale*int_phi) <= 1e-14; |
| 602 |
bool d = (D2gDxDp_data[i]==0.0); |
| 603 |
|
| 604 |
TEST_ASSERT(a || b || c || d); |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
// Testing Parameter Support |
| 610 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2f_dx2) |
| 611 |
{ |
| 612 |
typedef panzer::Traits::RealType RealType; |
| 613 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 614 |
typedef Thyra::LinearOpBase<RealType> OperatorType; |
| 615 |
|
| 616 |
using Teuchos::RCP; |
| 617 |
using Teuchos::rcp_dynamic_cast; |
| 618 |
|
| 619 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 620 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 621 |
typedef panzer::ModelEvaluator<double> PME; |
| 622 |
|
| 623 |
|
| 624 |
bool distr_param_on = true; |
| 625 |
AssemblyPieces ap; |
| 626 |
buildAssemblyPieces(distr_param_on,ap); |
| 627 |
|
| 628 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 629 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 630 |
bool build_transient_support = true; |
| 631 |
RCP<PME> me |
| 632 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 633 |
|
| 634 |
const double DENSITY_VALUE = 3.7; |
| 635 |
const double TEMPERATURE_VALUE = 2.0; |
| 636 |
const double PERTURB_VALUE = 0.1; |
| 637 |
|
| 638 |
// add distributed parameter |
| 639 |
{ |
| 640 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 641 |
|
| 642 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 643 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 644 |
me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 645 |
ap.param_ged,param_density,ap.param_dofManager); |
| 646 |
} |
| 647 |
|
| 648 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 649 |
*ap.eqset_factory, |
| 650 |
*ap.bc_factory, |
| 651 |
ap.cm_factory, |
| 652 |
ap.cm_factory, |
| 653 |
ap.closure_models, |
| 654 |
ap.user_data,false,""); |
| 655 |
|
| 656 |
// panzer::printMeshTopology(out,*ap.dofManager); |
| 657 |
|
| 658 |
|
| 659 |
RCP<OperatorType> D2fDx2 = me->create_W_op(); |
| 660 |
|
| 661 |
// test hessian |
| 662 |
{ |
| 663 |
|
| 664 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 665 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 666 |
|
| 667 |
RCP<VectorType> dx = Thyra::createMember(*me->get_x_space()); |
| 668 |
Thyra::assign(dx.ptr(),PERTURB_VALUE); |
| 669 |
|
| 670 |
InArgs in_args = me->createInArgs(); |
| 671 |
in_args.set_x(x); |
| 672 |
in_args.set_alpha(1.0/0.1); |
| 673 |
in_args.set_beta(1.0); |
| 674 |
|
| 675 |
me->evalModel_D2fDx2(in_args,dx,D2fDx2); |
| 676 |
|
| 677 |
out << "D2fDx2 = \n" << Teuchos::describe(*D2fDx2,Teuchos::VERB_EXTREME) << std::endl; |
| 678 |
} |
| 679 |
|
| 680 |
RCP<OperatorType> W = me->create_W_op(); |
| 681 |
{ |
| 682 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 683 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 684 |
|
| 685 |
InArgs in_args = me->createInArgs(); |
| 686 |
in_args.set_x(x); |
| 687 |
in_args.set_alpha(1.0); |
| 688 |
in_args.set_beta(0.0); |
| 689 |
|
| 690 |
OutArgs out_args = me->createOutArgs(); |
| 691 |
out_args.set_W_op(W); |
| 692 |
|
| 693 |
me->evalModel(in_args,out_args); |
| 694 |
|
| 695 |
out << "W = \n" << Teuchos::describe(*W,Teuchos::VERB_EXTREME) << std::endl; |
| 696 |
} |
| 697 |
|
| 698 |
Thyra::LinearOpTester<double> tester; |
| 699 |
tester.show_all_tests(true); |
| 700 |
tester.set_all_error_tol(1e-15); |
| 701 |
tester.num_random_vectors(20); |
| 702 |
|
| 703 |
double scaling_of_mass_matrix = -2.0*PERTURB_VALUE*DENSITY_VALUE*DENSITY_VALUE; |
| 704 |
|
| 705 |
Teuchos::FancyOStream fout(Teuchos::rcpFromRef(out)); |
| 706 |
const bool op_cmp = tester.compare( *Thyra::scaleAndAdjoint(scaling_of_mass_matrix,Thyra::NOTRANS,W.getConst()), *D2fDx2, Teuchos::ptrFromRef(fout)); |
| 707 |
TEST_ASSERT(op_cmp); |
| 708 |
} |
| 709 |
|
| 710 |
// Testing Parameter Support |
| 711 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2f_dxdp) |
| 712 |
{ |
| 713 |
typedef panzer::Traits::RealType RealType; |
| 714 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 715 |
typedef Thyra::LinearOpBase<RealType> OperatorType; |
| 716 |
|
| 717 |
using Teuchos::RCP; |
| 718 |
using Teuchos::rcp_dynamic_cast; |
| 719 |
|
| 720 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 721 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 722 |
typedef panzer::ModelEvaluator<double> PME; |
| 723 |
|
| 724 |
|
| 725 |
bool distr_param_on = true; |
| 726 |
AssemblyPieces ap; |
| 727 |
buildAssemblyPieces(distr_param_on,ap); |
| 728 |
|
| 729 |
int pIndex = -1; |
| 730 |
|
| 731 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 732 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 733 |
bool build_transient_support = true; |
| 734 |
RCP<PME> me |
| 735 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 736 |
|
| 737 |
const double DENSITY_VALUE = 3.7; |
| 738 |
const double TEMPERATURE_VALUE = 2.0; |
| 739 |
const double PERTURB_VALUE = 0.1; |
| 740 |
|
| 741 |
// add distributed parameter |
| 742 |
{ |
| 743 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 744 |
|
| 745 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 746 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 747 |
pIndex = me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 748 |
ap.param_ged,param_density,ap.param_dofManager); |
| 749 |
} |
| 750 |
|
| 751 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 752 |
*ap.eqset_factory, |
| 753 |
*ap.bc_factory, |
| 754 |
ap.cm_factory, |
| 755 |
ap.cm_factory, |
| 756 |
ap.closure_models, |
| 757 |
ap.user_data,false,""); |
| 758 |
|
| 759 |
// panzer::printMeshTopology(out,*ap.dofManager); |
| 760 |
|
| 761 |
|
| 762 |
RCP<OperatorType> D2fDxDp = me->create_W_op(); |
| 763 |
|
| 764 |
// test hessian |
| 765 |
{ |
| 766 |
|
| 767 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 768 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 769 |
|
| 770 |
RCP<VectorType> dp = Thyra::createMember(*me->get_p_space(0)); |
| 771 |
Thyra::assign(dp.ptr(),PERTURB_VALUE); |
| 772 |
|
| 773 |
InArgs in_args = me->createInArgs(); |
| 774 |
in_args.set_x(x); |
| 775 |
in_args.set_alpha(1.0/0.1); |
| 776 |
in_args.set_beta(1.0); |
| 777 |
|
| 778 |
me->evalModel_D2fDxDp(pIndex,in_args,dp,D2fDxDp); |
| 779 |
|
| 780 |
out << "D2fDxDp = \n" << Teuchos::describe(*D2fDxDp,Teuchos::VERB_EXTREME) << std::endl; |
| 781 |
} |
| 782 |
|
| 783 |
RCP<OperatorType> W = me->create_W_op(); |
| 784 |
{ |
| 785 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 786 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 787 |
|
| 788 |
InArgs in_args = me->createInArgs(); |
| 789 |
in_args.set_x(x); |
| 790 |
in_args.set_alpha(1.0); |
| 791 |
in_args.set_beta(0.0); |
| 792 |
|
| 793 |
OutArgs out_args = me->createOutArgs(); |
| 794 |
out_args.set_W_op(W); |
| 795 |
|
| 796 |
me->evalModel(in_args,out_args); |
| 797 |
|
| 798 |
out << "W = \n" << Teuchos::describe(*W,Teuchos::VERB_EXTREME) << std::endl; |
| 799 |
} |
| 800 |
|
| 801 |
Thyra::LinearOpTester<double> tester; |
| 802 |
tester.show_all_tests(true); |
| 803 |
tester.set_all_error_tol(1e-15); |
| 804 |
tester.num_random_vectors(20); |
| 805 |
|
| 806 |
double scaling_of_mass_matrix = -2.0*TEMPERATURE_VALUE*2.0*DENSITY_VALUE*PERTURB_VALUE; |
| 807 |
|
| 808 |
Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout)); |
| 809 |
const bool op_cmp = tester.compare( *Thyra::scaleAndAdjoint(scaling_of_mass_matrix,Thyra::NOTRANS,W.getConst()), *D2fDxDp, Teuchos::ptrFromRef(fout)); |
| 810 |
TEST_ASSERT(op_cmp); |
| 811 |
} |
| 812 |
|
| 813 |
// Testing Parameter Support |
| 814 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2f_dpdx) |
| 815 |
{ |
| 816 |
typedef panzer::Traits::RealType RealType; |
| 817 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 818 |
typedef Thyra::LinearOpBase<RealType> OperatorType; |
| 819 |
|
| 820 |
using Teuchos::RCP; |
| 821 |
using Teuchos::rcp_dynamic_cast; |
| 822 |
|
| 823 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 824 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 825 |
typedef panzer::ModelEvaluator<double> PME; |
| 826 |
|
| 827 |
|
| 828 |
bool distr_param_on = true; |
| 829 |
AssemblyPieces ap; |
| 830 |
buildAssemblyPieces(distr_param_on,ap); |
| 831 |
|
| 832 |
int pIndex = -1; |
| 833 |
|
| 834 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 835 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 836 |
bool build_transient_support = true; |
| 837 |
RCP<PME> me |
| 838 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 839 |
|
| 840 |
const double DENSITY_VALUE = 3.7; |
| 841 |
const double TEMPERATURE_VALUE = 2.0; |
| 842 |
const double PERTURB_VALUE = 0.1; |
| 843 |
|
| 844 |
// add distributed parameter |
| 845 |
{ |
| 846 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 847 |
|
| 848 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 849 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 850 |
pIndex = me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 851 |
ap.param_ged,param_density,ap.param_dofManager); |
| 852 |
} |
| 853 |
|
| 854 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 855 |
*ap.eqset_factory, |
| 856 |
*ap.bc_factory, |
| 857 |
ap.cm_factory, |
| 858 |
ap.cm_factory, |
| 859 |
ap.closure_models, |
| 860 |
ap.user_data,false,""); |
| 861 |
|
| 862 |
// panzer::printMeshTopology(out,*ap.dofManager); |
| 863 |
|
| 864 |
|
| 865 |
RCP<OperatorType> D2fDpDx = me->create_DfDp_op(pIndex); |
| 866 |
|
| 867 |
// test hessian |
| 868 |
{ |
| 869 |
|
| 870 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 871 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 872 |
|
| 873 |
RCP<VectorType> dx = Thyra::createMember(*me->get_x_space()); |
| 874 |
Thyra::assign(dx.ptr(),PERTURB_VALUE); |
| 875 |
|
| 876 |
InArgs in_args = me->createInArgs(); |
| 877 |
in_args.set_x(x); |
| 878 |
in_args.set_alpha(1.0/0.1); |
| 879 |
in_args.set_beta(1.0); |
| 880 |
|
| 881 |
me->evalModel_D2fDpDx(pIndex,in_args,dx,D2fDpDx); |
| 882 |
|
| 883 |
out << "D2fDpDx = \n" << Teuchos::describe(*D2fDpDx,Teuchos::VERB_EXTREME) << std::endl; |
| 884 |
} |
| 885 |
|
| 886 |
RCP<OperatorType> W = me->create_DfDp_op(pIndex); |
| 887 |
{ |
| 888 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 889 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 890 |
|
| 891 |
InArgs in_args = me->createInArgs(); |
| 892 |
in_args.set_x(x); |
| 893 |
in_args.set_alpha(1.0); |
| 894 |
in_args.set_beta(0.0); |
| 895 |
|
| 896 |
OutArgs out_args = me->createOutArgs(); |
| 897 |
out_args.set_DfDp(pIndex,W); |
| 898 |
|
| 899 |
me->evalModel(in_args,out_args); |
| 900 |
|
| 901 |
out << "W = \n" << Teuchos::describe(*W,Teuchos::VERB_EXTREME) << std::endl; |
| 902 |
} |
| 903 |
|
| 904 |
Thyra::LinearOpTester<double> tester; |
| 905 |
tester.show_all_tests(true); |
| 906 |
tester.set_all_error_tol(1e-15); |
| 907 |
tester.num_random_vectors(20); |
| 908 |
|
| 909 |
double scaling_of_dfdp = 2.0*PERTURB_VALUE/TEMPERATURE_VALUE; |
| 910 |
|
| 911 |
Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout)); |
| 912 |
const bool op_cmp = tester.compare( *Thyra::scaleAndAdjoint(scaling_of_dfdp,Thyra::NOTRANS,W.getConst()), *D2fDpDx, Teuchos::ptrFromRef(fout)); |
| 913 |
TEST_ASSERT(op_cmp); |
| 914 |
} |
| 915 |
|
| 916 |
// Testing Parameter Support |
| 917 |
TEUCHOS_UNIT_TEST(model_evaluator_blocked_hessians, d2f_dp2) |
| 918 |
{ |
| 919 |
typedef panzer::Traits::RealType RealType; |
| 920 |
typedef Thyra::VectorBase<RealType> VectorType; |
| 921 |
typedef Thyra::LinearOpBase<RealType> OperatorType; |
| 922 |
|
| 923 |
using Teuchos::RCP; |
| 924 |
using Teuchos::rcp_dynamic_cast; |
| 925 |
|
| 926 |
typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; |
| 927 |
typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; |
| 928 |
typedef panzer::ModelEvaluator<double> PME; |
| 929 |
|
| 930 |
|
| 931 |
bool distr_param_on = true; |
| 932 |
AssemblyPieces ap; |
| 933 |
buildAssemblyPieces(distr_param_on,ap); |
| 934 |
|
| 935 |
int pIndex = -1; |
| 936 |
|
| 937 |
std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; |
| 938 |
std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; |
| 939 |
bool build_transient_support = true; |
| 940 |
RCP<PME> me |
| 941 |
= Teuchos::rcp(new PME(ap.fmb,ap.rLibrary,ap.lof,p_names,p_values,Teuchos::null,ap.gd,build_transient_support,0.0)); |
| 942 |
|
| 943 |
const double DENSITY_VALUE = 3.7; |
| 944 |
const double TEMPERATURE_VALUE = 2.0; |
| 945 |
const double PERTURB_VALUE = 0.1; |
| 946 |
|
| 947 |
// add distributed parameter |
| 948 |
{ |
| 949 |
RCP<ThyraObjFactory<double> > th_param_lof = rcp_dynamic_cast<ThyraObjFactory<double> >(ap.param_lof); |
| 950 |
|
| 951 |
RCP<VectorType> param_density = Thyra::createMember(th_param_lof->getThyraDomainSpace()); |
| 952 |
Thyra::assign(param_density.ptr(),DENSITY_VALUE); |
| 953 |
pIndex = me->addDistributedParameter("DENSITY_P",th_param_lof->getThyraDomainSpace(), |
| 954 |
ap.param_ged,param_density,ap.param_dofManager); |
| 955 |
} |
| 956 |
|
| 957 |
me->setupModel(ap.wkstContainer,ap.physicsBlocks,ap.bcs, |
| 958 |
*ap.eqset_factory, |
| 959 |
*ap.bc_factory, |
| 960 |
ap.cm_factory, |
| 961 |
ap.cm_factory, |
| 962 |
ap.closure_models, |
| 963 |
ap.user_data,false,""); |
| 964 |
|
| 965 |
// panzer::printMeshTopology(out,*ap.dofManager); |
| 966 |
|
| 967 |
|
| 968 |
RCP<OperatorType> D2fDp2 = me->create_DfDp_op(pIndex); |
| 969 |
|
| 970 |
// test hessian |
| 971 |
{ |
| 972 |
|
| 973 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 974 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 975 |
|
| 976 |
RCP<VectorType> dp = Thyra::createMember(*me->get_p_space(0)); |
| 977 |
Thyra::assign(dp.ptr(),PERTURB_VALUE); |
| 978 |
|
| 979 |
InArgs in_args = me->createInArgs(); |
| 980 |
in_args.set_x(x); |
| 981 |
in_args.set_alpha(1.0/0.1); |
| 982 |
in_args.set_beta(1.0); |
| 983 |
|
| 984 |
me->evalModel_D2fDp2(pIndex,in_args,dp,D2fDp2); |
| 985 |
|
| 986 |
out << "D2fDp2 = \n" << Teuchos::describe(*D2fDp2,Teuchos::VERB_EXTREME) << std::endl; |
| 987 |
} |
| 988 |
|
| 989 |
RCP<OperatorType> W = me->create_DfDp_op(pIndex); |
| 990 |
{ |
| 991 |
RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); |
| 992 |
Thyra::assign(x.ptr(),TEMPERATURE_VALUE); |
| 993 |
|
| 994 |
InArgs in_args = me->createInArgs(); |
| 995 |
in_args.set_x(x); |
| 996 |
in_args.set_alpha(1.0); |
| 997 |
in_args.set_beta(0.0); |
| 998 |
|
| 999 |
OutArgs out_args = me->createOutArgs(); |
| 1000 |
out_args.set_DfDp(pIndex,W); |
| 1001 |
|
| 1002 |
me->evalModel(in_args,out_args); |
| 1003 |
|
| 1004 |
out << "W = \n" << Teuchos::describe(*W,Teuchos::VERB_EXTREME) << std::endl; |
| 1005 |
} |
| 1006 |
|
| 1007 |
Thyra::LinearOpTester<double> tester; |
| 1008 |
tester.show_all_tests(true); |
| 1009 |
tester.set_all_error_tol(1e-15); |
| 1010 |
tester.num_random_vectors(20); |
| 1011 |
|
| 1012 |
double scaling_of_dfdp = PERTURB_VALUE/DENSITY_VALUE; |
| 1013 |
|
| 1014 |
Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout)); |
| 1015 |
const bool op_cmp = tester.compare( *Thyra::scaleAndAdjoint(scaling_of_dfdp,Thyra::NOTRANS,W.getConst()), *D2fDp2, Teuchos::ptrFromRef(fout)); |
| 1016 |
TEST_ASSERT(op_cmp); |
| 1017 |
} |
| 1018 |
|
| 1019 |
bool testEqualityOfVectorValues(const Thyra::VectorBase<double> & a, |
| 1020 |
const Thyra::VectorBase<double> & b, |
| 1021 |
double tolerance, bool write_to_cout) |
| 1022 |
{ |
| 1023 |
bool is_equal = true; |
| 1024 |
|
| 1025 |
TEUCHOS_ASSERT(a.space()->dim() == b.space()->dim()); |
| 1026 |
|
| 1027 |
Teuchos::ArrayRCP<const double> a_data,b_data; |
| 1028 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(a).getLocalData(Teuchos::ptrFromRef(a_data)); |
| 1029 |
dynamic_cast<const Thyra::SpmdVectorBase<double> &>(b).getLocalData(Teuchos::ptrFromRef(b_data)); |
| 1030 |
|
| 1031 |
for (int i = 0; i < a_data.size(); ++i) { |
| 1032 |
|
| 1033 |
std::string output = " equal!: "; |
| 1034 |
|
| 1035 |
if (std::fabs(a_data[i] - b_data[i]) > tolerance) { |
| 1036 |
is_equal = false; |
| 1037 |
output = "NOT equal!: "; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (write_to_cout) |
| 1041 |
std::cout << output << a_data[i] << " - " << b_data[i] << " = " << (a_data[i] - b_data[i]) << std::endl; |
| 1042 |
} |
| 1043 |
|
| 1044 |
int globalSuccess = -1; |
| 1045 |
Teuchos::RCP<const Teuchos::Comm<Teuchos::Ordinal> > comm = Teuchos::DefaultComm<Teuchos::Ordinal>::getComm(); |
| 1046 |
Teuchos::reduceAll( *comm, Teuchos::REDUCE_SUM, is_equal ? 0 : 1, Teuchos::outArg(globalSuccess) ); |
| 1047 |
return (globalSuccess==0); |
| 1048 |
} |
| 1049 |
|
| 1050 |
|
| 1051 |
void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb, |
| 1052 |
std::vector<panzer::BC>& bcs) |
| 1053 |
{ |
| 1054 |
// Physics block |
| 1055 |
Teuchos::ParameterList& physics_block = ipb->sublist("test physics"); |
| 1056 |
{ |
| 1057 |
Teuchos::ParameterList& p = physics_block.sublist("a"); |
| 1058 |
p.set("Type","Energy"); |
| 1059 |
p.set("Prefix",""); |
| 1060 |
p.set("Model ID","solid"); |
| 1061 |
p.set("Basis Type","HGrad"); |
| 1062 |
p.set("Basis Order",1); |
| 1063 |
p.set("Integration Order",1); |
| 1064 |
} |
| 1065 |
{ |
| 1066 |
Teuchos::ParameterList& p = physics_block.sublist("b"); |
| 1067 |
p.set("Type","Energy"); |
| 1068 |
p.set("Prefix","ION_"); |
| 1069 |
p.set("Model ID","ion solid"); |
| 1070 |
p.set("Basis Type","HGrad"); |
| 1071 |
p.set("Basis Order",1); |
| 1072 |
p.set("Integration Order",1); |
| 1073 |
} |
| 1074 |
|
| 1075 |
{ |
| 1076 |
std::size_t bc_id = 0; |
| 1077 |
panzer::BCType neumann = BCT_Dirichlet; |
| 1078 |
std::string sideset_id = "left"; |
| 1079 |
std::string element_block_id = "eblock-0_0"; |
| 1080 |
std::string dof_name = "TEMPERATURE"; |
| 1081 |
std::string strategy = "Constant"; |
| 1082 |
double value = 5.0; |
| 1083 |
Teuchos::ParameterList p; |
| 1084 |
p.set("Value",value); |
| 1085 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 1086 |
strategy, p); |
| 1087 |
bcs.push_back(bc); |
| 1088 |
} |
| 1089 |
{ |
| 1090 |
std::size_t bc_id = 1; |
| 1091 |
panzer::BCType neumann = BCT_Dirichlet; |
| 1092 |
std::string sideset_id = "right"; |
| 1093 |
std::string element_block_id = "eblock-1_0"; |
| 1094 |
std::string dof_name = "TEMPERATURE"; |
| 1095 |
std::string strategy = "Constant"; |
| 1096 |
double value = 5.0; |
| 1097 |
Teuchos::ParameterList p; |
| 1098 |
p.set("Value",value); |
| 1099 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 1100 |
strategy, p); |
| 1101 |
bcs.push_back(bc); |
| 1102 |
} |
| 1103 |
{ |
| 1104 |
std::size_t bc_id = 2; |
| 1105 |
panzer::BCType neumann = BCT_Dirichlet; |
| 1106 |
std::string sideset_id = "top"; |
| 1107 |
std::string element_block_id = "eblock-1_0"; |
| 1108 |
std::string dof_name = "TEMPERATURE"; |
| 1109 |
std::string strategy = "Constant"; |
| 1110 |
double value = 5.0; |
| 1111 |
Teuchos::ParameterList p; |
| 1112 |
p.set("Value",value); |
| 1113 |
panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name, |
| 1114 |
strategy, p); |
| 1115 |
bcs.push_back(bc); |
| 1116 |
} |
| 1117 |
} |
| 1118 |
|
| 1119 |
void buildAssemblyPieces(bool distr_parameter_on, |
| 1120 |
AssemblyPieces & ap, |
| 1121 |
const std::vector<std::string>& tangentParamNames) |
| 1122 |
{ |
| 1123 |
using Teuchos::RCP; |
| 1124 |
|
| 1125 |
RCP<Teuchos::ParameterList> pl = Teuchos::rcp(new Teuchos::ParameterList); |
| 1126 |
pl->set("X Blocks",2); |
| 1127 |
pl->set("Y Blocks",1); |
| 1128 |
pl->set("X Elements",6); |
| 1129 |
pl->set("Y Elements",4); |
| 1130 |
|
| 1131 |
panzer_stk::SquareQuadMeshFactory factory; |
| 1132 |
factory.setParameterList(pl); |
| 1133 |
RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD); |
| 1134 |
Teuchos::RCP<const Teuchos::Comm<int> > Comm = Teuchos::DefaultComm<int>::getComm(); |
| 1135 |
Teuchos::RCP<const Teuchos::MpiComm<int> > mpiComm |
| 1136 |
= Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(Comm); |
| 1137 |
|
| 1138 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks"); |
| 1139 |
std::vector<panzer::BC> bcs; |
| 1140 |
testInitialzation(ipb, bcs); |
| 1141 |
|
| 1142 |
ap.fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); |
| 1143 |
ap.bcs = bcs; |
| 1144 |
|
| 1145 |
// build physics blocks |
| 1146 |
////////////////////////////////////////////////////////////// |
| 1147 |
const std::size_t workset_size = 20; |
| 1148 |
ap.eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 1149 |
ap.bc_factory = Teuchos::rcp(new user_app::BCFactory); |
| 1150 |
ap.gd = panzer::createGlobalData(); |
| 1151 |
{ |
| 1152 |
std::map<std::string,std::string> block_ids_to_physics_ids; |
| 1153 |
block_ids_to_physics_ids["eblock-0_0"] = "test physics"; |
| 1154 |
block_ids_to_physics_ids["eblock-1_0"] = "test physics"; |
| 1155 |
|
| 1156 |
std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo; |
| 1157 |
block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); |
| 1158 |
block_ids_to_cell_topo["eblock-1_0"] = mesh->getCellTopology("eblock-1_0"); |
| 1159 |
|
| 1160 |
int default_integration_order = 1; |
| 1161 |
|
| 1162 |
bool build_transient_support = true; |
| 1163 |
panzer::buildPhysicsBlocks(block_ids_to_physics_ids, |
| 1164 |
block_ids_to_cell_topo, |
| 1165 |
ipb, |
| 1166 |
default_integration_order, |
| 1167 |
workset_size, |
| 1168 |
ap.eqset_factory, |
| 1169 |
ap.gd, |
| 1170 |
build_transient_support, |
| 1171 |
ap.physicsBlocks, |
| 1172 |
tangentParamNames); |
| 1173 |
} |
| 1174 |
|
| 1175 |
// build worksets |
| 1176 |
////////////////////////////////////////////////////////////// |
| 1177 |
// build WorksetContainer |
| 1178 |
Teuchos::RCP<panzer_stk::WorksetFactory> wkstFactory |
| 1179 |
= Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory |
| 1180 |
Teuchos::RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation) |
| 1181 |
= Teuchos::rcp(new panzer::WorksetContainer); |
| 1182 |
wkstContainer->setFactory(wkstFactory); |
| 1183 |
for(size_t i=0;i<ap.physicsBlocks.size();i++) |
| 1184 |
wkstContainer->setNeeds(ap.physicsBlocks[i]->elementBlockID(),ap.physicsBlocks[i]->getWorksetNeeds()); |
| 1185 |
wkstContainer->setWorksetSize(workset_size); |
| 1186 |
ap.wkstContainer = wkstContainer; |
| 1187 |
|
| 1188 |
// build DOF Manager |
| 1189 |
///////////////////////////////////////////////////////////// |
| 1190 |
|
| 1191 |
// build the connection manager |
| 1192 |
const Teuchos::RCP<panzer::ConnManager> |
| 1193 |
conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 1194 |
|
| 1195 |
// build the state dof manager and LOF |
| 1196 |
{ |
| 1197 |
panzer::BlockedDOFManagerFactory globalIndexerFactory; |
| 1198 |
auto dofManager = globalIndexerFactory.buildGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),ap.physicsBlocks, |
| 1199 |
conn_manager,"blocked: TEMPERATURE ION_TEMPERATURE"); |
| 1200 |
ap.dofManager = dofManager; |
| 1201 |
|
| 1202 |
Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory |
| 1203 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,dofManager)); |
| 1204 |
ap.lof = linObjFactory; |
| 1205 |
} |
| 1206 |
|
| 1207 |
// build the dof manager and LOF for DENSITY control |
| 1208 |
if(distr_parameter_on) { |
| 1209 |
Teuchos::RCP<panzer::DOFManager> dofManager |
| 1210 |
= Teuchos::rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD)); |
| 1211 |
|
| 1212 |
Teuchos::RCP<Intrepid2FieldPattern> fp |
| 1213 |
= Teuchos::rcp(new Intrepid2FieldPattern(panzer::createIntrepid2Basis<PHX::exec_space,double,double>("HGrad",1,mesh->getCellTopology("eblock-0_0")))); |
| 1214 |
dofManager->addField("eblock-0_0","DENSITY_P",fp); |
| 1215 |
dofManager->addField("eblock-1_0","DENSITY_P",fp); |
| 1216 |
|
| 1217 |
dofManager->setOrientationsRequired(false); |
| 1218 |
dofManager->buildGlobalUnknowns(); |
| 1219 |
|
| 1220 |
// build a nonsquare LOF for the parameter vector |
| 1221 |
Teuchos::RCP<panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int> > linObjFactory |
| 1222 |
= Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(mpiComm,ap.dofManager,dofManager)); |
| 1223 |
|
| 1224 |
Teuchos::RCP<Epetra_Map> ownedMap = linObjFactory->getColMap(0); |
| 1225 |
Teuchos::RCP<Epetra_Map> ghostedMap = linObjFactory->getGhostedColMap(0); |
| 1226 |
Teuchos::RCP<Epetra_Import> importer = Teuchos::rcp(new Epetra_Import(*ghostedMap,*ownedMap)); |
| 1227 |
|
| 1228 |
ap.param_dofManager = dofManager; |
| 1229 |
ap.param_ged = Teuchos::rcp(new EpetraVector_ReadOnly_GlobalEvaluationData(importer,ghostedMap,ownedMap)); |
| 1230 |
ap.param_lof = linObjFactory; |
| 1231 |
} |
| 1232 |
|
| 1233 |
ap.rLibrary = Teuchos::rcp(new panzer::ResponseLibrary<panzer::Traits>(wkstContainer,ap.dofManager,ap.lof)); |
| 1234 |
|
| 1235 |
// setup field manager build |
| 1236 |
///////////////////////////////////////////////////////////// |
| 1237 |
|
| 1238 |
// Add in the application specific closure model factory |
| 1239 |
user_app::MyModelFactory_TemplateBuilder cm_builder; |
| 1240 |
cm_builder.setDistributedParameterLOF(ap.param_lof); |
| 1241 |
ap.cm_factory.buildObjects(cm_builder); |
| 1242 |
|
| 1243 |
Teuchos::ParameterList closure_models("Closure Models"); |
| 1244 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<std::string>("Type","Product"); |
| 1245 |
closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<std::string>("Term Names","TEMPERATURE,TEMPERATURE,DENSITY_P,DENSITY_P"); |
| 1246 |
closure_models.sublist("solid").sublist("DENSITY").set<double>("Value",1.0); |
| 1247 |
closure_models.sublist("solid").sublist("HEAT_CAPACITY").set<double>("Value",1.0); |
| 1248 |
closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE").set<std::string>("Type","Product"); |
| 1249 |
closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE").set<std::string>("Term Names","ION_TEMPERATURE,ION_TEMPERATURE,DENSITY_P,DENSITY_P"); |
| 1250 |
closure_models.sublist("ion solid").sublist("ION_DENSITY").set<double>("Value",1.0); |
| 1251 |
closure_models.sublist("ion solid").sublist("ION_DENSITY").set<double>("Value",1.0); |
| 1252 |
closure_models.sublist("ion solid").sublist("ION_HEAT_CAPACITY").set<double>("Value",1.0); |
| 1253 |
|
| 1254 |
closure_models.sublist("solid").sublist("DENSITY_P").set("Type","Distributed Parameter"); |
| 1255 |
closure_models.sublist("solid").sublist("INTEGRAND").set<std::string>("Type","Product"); |
| 1256 |
closure_models.sublist("solid").sublist("INTEGRAND").set<std::string>("Term Names","TEMPERATURE,TEMPERATURE,DENSITY_P,DENSITY_P,DENSITY_P"); |
| 1257 |
|
| 1258 |
ap.closure_models = closure_models; |
| 1259 |
|
| 1260 |
ap.user_data = Teuchos::ParameterList("User Data"); |
| 1261 |
|
| 1262 |
ap.fmb->setWorksetContainer(wkstContainer); |
| 1263 |
ap.fmb->setupVolumeFieldManagers(ap.physicsBlocks,ap.cm_factory,closure_models,*ap.lof,ap.user_data); |
| 1264 |
ap.fmb->setupBCFieldManagers(bcs,ap.physicsBlocks,*ap.eqset_factory,ap.cm_factory,*ap.bc_factory, |
| 1265 |
closure_models,*ap.lof,ap.user_data); |
| 1266 |
} |
| 1267 |
|
| 1268 |
|
| 1269 |
} |