00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009 #include "Sacado_ParameterRegistration.hpp"
00010
00011
00012
00013
00014
00015 namespace PHAL {
00016
00017 template <typename EvalT, typename Traits, typename cfunc_traits>
00018 DirichletCoordFunction_Base<EvalT, Traits, cfunc_traits>::
00019 DirichletCoordFunction_Base(Teuchos::ParameterList& p) :
00020 PHAL::DirichletBase<EvalT, Traits>(p),
00021 func(p) {
00022 }
00023
00024
00025
00026
00027 template<typename Traits, typename cfunc_traits>
00028 DirichletCoordFunction<PHAL::AlbanyTraits::Residual, Traits, cfunc_traits>::
00029 DirichletCoordFunction(Teuchos::ParameterList& p) :
00030 DirichletCoordFunction_Base<PHAL::AlbanyTraits::Residual, Traits, cfunc_traits>(p) {
00031 }
00032
00033
00034 template<typename Traits, typename cfunc_traits>
00035 void
00036 DirichletCoordFunction<PHAL::AlbanyTraits::Residual, Traits, cfunc_traits>::
00037 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00038 Teuchos::RCP<Epetra_Vector> f = dirichletWorkset.f;
00039 Teuchos::RCP<const Epetra_Vector> x = dirichletWorkset.x;
00040
00041
00042 const std::vector<std::vector<int> >& nsNodes =
00043 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00044 const std::vector<double*>& nsNodeCoords =
00045 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00046
00047 RealType time = dirichletWorkset.current_time;
00048 int number_of_components = this->func.getNumComponents();
00049
00050 double* coord;
00051 std::vector<ScalarT> BCVals(number_of_components);
00052
00053 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00054
00055 coord = nsNodeCoords[inode];
00056
00057 this->func.computeBCs(coord, BCVals, time);
00058
00059 for(unsigned int j = 0; j < number_of_components; j++) {
00060 int offset = nsNodes[inode][j];
00061 (*f)[offset] = ((*x)[offset] - BCVals[j]);
00062 }
00063 }
00064 }
00065
00066
00067
00068
00069 template<typename Traits, typename cfunc_traits>
00070 DirichletCoordFunction<PHAL::AlbanyTraits::Jacobian, Traits, cfunc_traits>::
00071 DirichletCoordFunction(Teuchos::ParameterList& p) :
00072 DirichletCoordFunction_Base<PHAL::AlbanyTraits::Jacobian, Traits, cfunc_traits>(p) {
00073 }
00074
00075 template<typename Traits, typename cfunc_traits>
00076 void DirichletCoordFunction<PHAL::AlbanyTraits::Jacobian, Traits, cfunc_traits>::
00077 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00078
00079 Teuchos::RCP<Epetra_Vector> f = dirichletWorkset.f;
00080 Teuchos::RCP<Epetra_CrsMatrix> jac = dirichletWorkset.Jac;
00081 Teuchos::RCP<const Epetra_Vector> x = dirichletWorkset.x;
00082
00083 const RealType j_coeff = dirichletWorkset.j_coeff;
00084 const std::vector<std::vector<int> >& nsNodes =
00085 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00086 const std::vector<double*>& nsNodeCoords =
00087 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00088
00089 RealType* matrixEntries;
00090 int* matrixIndices;
00091 int numEntries;
00092 RealType diag = j_coeff;
00093 bool fillResid = (f != Teuchos::null);
00094
00095 RealType time = dirichletWorkset.current_time;
00096 int number_of_components = this->func.getNumComponents();
00097
00098 double* coord;
00099 std::vector<ScalarT> BCVals(number_of_components);
00100
00101 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00102 coord = nsNodeCoords[inode];
00103
00104 this->func.computeBCs(coord, BCVals, time);
00105
00106 for(unsigned int j = 0; j < number_of_components; j++) {
00107 int offset = nsNodes[inode][j];
00108
00109
00110 jac->ExtractMyRowView(offset, numEntries, matrixEntries, matrixIndices);
00111
00112 for(int i = 0; i < numEntries; i++) matrixEntries[i] = 0;
00113
00114 jac->ReplaceMyValues(offset, 1, &diag, &offset);
00115
00116 if(fillResid) {
00117 (*f)[offset] = ((*x)[offset] - BCVals[j].val());
00118 }
00119 }
00120 }
00121 }
00122
00123
00124
00125
00126 template<typename Traits, typename cfunc_traits>
00127 DirichletCoordFunction<PHAL::AlbanyTraits::Tangent, Traits, cfunc_traits>::
00128 DirichletCoordFunction(Teuchos::ParameterList& p) :
00129 DirichletCoordFunction_Base<PHAL::AlbanyTraits::Tangent, Traits, cfunc_traits>(p) {
00130 }
00131
00132 template<typename Traits, typename cfunc_traits>
00133 void DirichletCoordFunction<PHAL::AlbanyTraits::Tangent, Traits, cfunc_traits>::
00134 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00135 Teuchos::RCP<Epetra_Vector> f = dirichletWorkset.f;
00136 Teuchos::RCP<Epetra_MultiVector> fp = dirichletWorkset.fp;
00137 Teuchos::RCP<Epetra_MultiVector> JV = dirichletWorkset.JV;
00138 Teuchos::RCP<const Epetra_Vector> x = dirichletWorkset.x;
00139 Teuchos::RCP<const Epetra_MultiVector> Vx = dirichletWorkset.Vx;
00140
00141 const RealType j_coeff = dirichletWorkset.j_coeff;
00142 const std::vector<std::vector<int> >& nsNodes =
00143 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00144 const std::vector<double*>& nsNodeCoords =
00145 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00146
00147 RealType time = dirichletWorkset.current_time;
00148 int number_of_components = this->func.getNumComponents();
00149
00150 double* coord;
00151 std::vector<ScalarT> BCVals(number_of_components);
00152
00153 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00154 coord = nsNodeCoords[inode];
00155
00156 this->func.computeBCs(coord, BCVals, time);
00157
00158 for(unsigned int j = 0; j < number_of_components; j++) {
00159 int offset = nsNodes[inode][j];
00160
00161 if(f != Teuchos::null)
00162 (*f)[offset] = ((*x)[offset] - BCVals[j].val());
00163
00164 if(JV != Teuchos::null)
00165 for(int i = 0; i < dirichletWorkset.num_cols_x; i++)
00166 (*JV)[i][offset] = j_coeff * (*Vx)[i][offset];
00167
00168 if(fp != Teuchos::null)
00169 for(int i = 0; i < dirichletWorkset.num_cols_p; i++)
00170 (*fp)[i][offset] = -BCVals[j].dx(dirichletWorkset.param_offset + i);
00171
00172 }
00173 }
00174 }
00175
00176
00177
00178
00179 #ifdef ALBANY_SG_MP
00180 template<typename Traits, typename cfunc_traits>
00181 DirichletCoordFunction<PHAL::AlbanyTraits::SGResidual, Traits, cfunc_traits>::
00182 DirichletCoordFunction(Teuchos::ParameterList& p) :
00183 DirichletCoordFunction_Base<PHAL::AlbanyTraits::SGResidual, Traits, cfunc_traits>(p) {
00184 }
00185
00186 template<typename Traits, typename cfunc_traits>
00187 void DirichletCoordFunction<PHAL::AlbanyTraits::SGResidual, Traits, cfunc_traits>::
00188 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00189 Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> f =
00190 dirichletWorkset.sg_f;
00191 Teuchos::RCP<const Stokhos::EpetraVectorOrthogPoly> x =
00192 dirichletWorkset.sg_x;
00193
00194 const std::vector<std::vector<int> >& nsNodes =
00195 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00196 const std::vector<double*>& nsNodeCoords =
00197 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00198
00199 RealType time = dirichletWorkset.current_time;
00200 int number_of_components = this->func.getNumComponents();
00201
00202 double* coord;
00203 std::vector<ScalarT> BCVals(number_of_components);
00204
00205 int nblock = x->size();
00206
00207 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00208 coord = nsNodeCoords[inode];
00209
00210 this->func.computeBCs(coord, BCVals, time);
00211
00212 for(unsigned int j = 0; j < number_of_components; j++) {
00213 int offset = nsNodes[inode][j];
00214
00215 for(int block = 0; block < nblock; block++)
00216 (*f)[block][offset] = ((*x)[block][offset] - BCVals[j].coeff(block));
00217
00218 }
00219 }
00220 }
00221
00222
00223
00224
00225 template<typename Traits, typename cfunc_traits>
00226 DirichletCoordFunction<PHAL::AlbanyTraits::SGJacobian, Traits, cfunc_traits>::
00227 DirichletCoordFunction(Teuchos::ParameterList& p) :
00228 DirichletCoordFunction_Base<PHAL::AlbanyTraits::SGJacobian, Traits, cfunc_traits>(p) {
00229 }
00230
00231 template<typename Traits, typename cfunc_traits>
00232 void DirichletCoordFunction<PHAL::AlbanyTraits::SGJacobian, Traits, cfunc_traits>::
00233 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00234 Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly> f =
00235 dirichletWorkset.sg_f;
00236 Teuchos::RCP< Stokhos::VectorOrthogPoly<Epetra_CrsMatrix> > jac =
00237 dirichletWorkset.sg_Jac;
00238 Teuchos::RCP<const Stokhos::EpetraVectorOrthogPoly> x =
00239 dirichletWorkset.sg_x;
00240
00241 const RealType j_coeff = dirichletWorkset.j_coeff;
00242 const std::vector<std::vector<int> >& nsNodes =
00243 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00244 const std::vector<double*>& nsNodeCoords =
00245 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00246
00247 RealType* matrixEntries;
00248 int* matrixIndices;
00249 int numEntries;
00250 RealType diag = j_coeff;
00251 bool fillResid = (f != Teuchos::null);
00252
00253 int nblock = 0;
00254
00255 if(f != Teuchos::null)
00256 nblock = f->size();
00257
00258 int nblock_jac = jac->size();
00259
00260 RealType time = dirichletWorkset.current_time;
00261 int number_of_components = this->func.getNumComponents();
00262
00263 double* coord;
00264 std::vector<ScalarT> BCVals(number_of_components);
00265
00266 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00267 coord = nsNodeCoords[inode];
00268
00269 this->func.computeBCs(coord, BCVals, time);
00270
00271 for(unsigned int j = 0; j < number_of_components; j++) {
00272 int offset = nsNodes[inode][j];
00273
00274
00275 for(int block = 0; block < nblock_jac; block++) {
00276
00277 (*jac)[block].ExtractMyRowView(offset, numEntries, matrixEntries,
00278 matrixIndices);
00279
00280 for(int i = 0; i < numEntries; i++) matrixEntries[i] = 0;
00281
00282 }
00283
00284 (*jac)[0].ReplaceMyValues(offset, 1, &diag, &offset);
00285
00286 if(fillResid)
00287 for(int block = 0; block < nblock; block++)
00288 (*f)[block][offset] = ((*x)[block][offset] - BCVals[j].val().coeff(block));
00289
00290 }
00291 }
00292 }
00293
00294
00295
00296
00297 template<typename Traits, typename cfunc_traits>
00298 DirichletCoordFunction<PHAL::AlbanyTraits::SGTangent, Traits, cfunc_traits>::
00299 DirichletCoordFunction(Teuchos::ParameterList& p) :
00300 DirichletCoordFunction_Base<PHAL::AlbanyTraits::SGTangent, Traits, cfunc_traits>(p) {
00301 }
00302
00303 template<typename Traits, typename cfunc_traits>
00304 void DirichletCoordFunction<PHAL::AlbanyTraits::SGTangent, Traits, cfunc_traits>::
00305 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00306 Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> f =
00307 dirichletWorkset.sg_f;
00308 Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly> fp =
00309 dirichletWorkset.sg_fp;
00310 Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly> JV =
00311 dirichletWorkset.sg_JV;
00312 Teuchos::RCP<const Stokhos::EpetraVectorOrthogPoly> x =
00313 dirichletWorkset.sg_x;
00314 Teuchos::RCP<const Epetra_MultiVector> Vx = dirichletWorkset.Vx;
00315
00316 const RealType j_coeff = dirichletWorkset.j_coeff;
00317 const std::vector<std::vector<int> >& nsNodes =
00318 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00319 const std::vector<double*>& nsNodeCoords =
00320 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00321
00322 int nblock = x->size();
00323
00324 RealType time = dirichletWorkset.current_time;
00325 int number_of_components = this->func.getNumComponents();
00326
00327 double* coord;
00328 std::vector<ScalarT> BCVals(number_of_components);
00329
00330 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00331 coord = nsNodeCoords[inode];
00332
00333 this->func.computeBCs(coord, BCVals, time);
00334
00335 for(unsigned int j = 0; j < number_of_components; j++) {
00336 int offset = nsNodes[inode][j];
00337
00338 if(f != Teuchos::null)
00339 for(int block = 0; block < nblock; block++)
00340 (*f)[block][offset] = (*x)[block][offset] - BCVals[j].val().coeff(block);
00341
00342 if(JV != Teuchos::null)
00343 for(int i = 0; i < dirichletWorkset.num_cols_x; i++)
00344 (*JV)[0][i][offset] = j_coeff * (*Vx)[i][offset];
00345
00346 if(fp != Teuchos::null)
00347 for(int i = 0; i < dirichletWorkset.num_cols_p; i++)
00348 for(int block = 0; block < nblock; block++)
00349 (*fp)[block][i][offset] = -BCVals[j].dx(dirichletWorkset.param_offset + i).coeff(block);
00350
00351 }
00352 }
00353 }
00354
00355
00356
00357
00358
00359 template<typename Traits, typename cfunc_traits>
00360 DirichletCoordFunction<PHAL::AlbanyTraits::MPResidual, Traits, cfunc_traits>::
00361 DirichletCoordFunction(Teuchos::ParameterList& p) :
00362 DirichletCoordFunction_Base<PHAL::AlbanyTraits::MPResidual, Traits, cfunc_traits>(p) {
00363 }
00364
00365 template<typename Traits, typename cfunc_traits>
00366 void DirichletCoordFunction<PHAL::AlbanyTraits::MPResidual, Traits, cfunc_traits>::
00367 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00368 Teuchos::RCP<Stokhos::ProductEpetraVector> f =
00369 dirichletWorkset.mp_f;
00370 Teuchos::RCP<const Stokhos::ProductEpetraVector> x =
00371 dirichletWorkset.mp_x;
00372
00373 const std::vector<std::vector<int> >& nsNodes =
00374 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00375 const std::vector<double*>& nsNodeCoords =
00376 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00377
00378 RealType time = dirichletWorkset.current_time;
00379 int number_of_components = this->func.getNumComponents();
00380
00381 double* coord;
00382 std::vector<ScalarT> BCVals(number_of_components);
00383
00384 int nblock = x->size();
00385
00386 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00387 coord = nsNodeCoords[inode];
00388
00389 this->func.computeBCs(coord, BCVals, time);
00390
00391 for(unsigned int j = 0; j < number_of_components; j++) {
00392 int offset = nsNodes[inode][j];
00393
00394 for(int block = 0; block < nblock; block++)
00395 (*f)[block][offset] = ((*x)[block][offset] - BCVals[j].coeff(block));
00396
00397 }
00398 }
00399 }
00400
00401
00402
00403
00404 template<typename Traits, typename cfunc_traits>
00405 DirichletCoordFunction<PHAL::AlbanyTraits::MPJacobian, Traits, cfunc_traits>::
00406 DirichletCoordFunction(Teuchos::ParameterList& p) :
00407 DirichletCoordFunction_Base<PHAL::AlbanyTraits::MPJacobian, Traits, cfunc_traits>(p) {
00408 }
00409
00410 template<typename Traits, typename cfunc_traits>
00411 void DirichletCoordFunction<PHAL::AlbanyTraits::MPJacobian, Traits, cfunc_traits>::
00412 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00413 Teuchos::RCP<Stokhos::ProductEpetraVector> f =
00414 dirichletWorkset.mp_f;
00415 Teuchos::RCP< Stokhos::ProductContainer<Epetra_CrsMatrix> > jac =
00416 dirichletWorkset.mp_Jac;
00417 Teuchos::RCP<const Stokhos::ProductEpetraVector> x =
00418 dirichletWorkset.mp_x;
00419
00420 const RealType j_coeff = dirichletWorkset.j_coeff;
00421 const std::vector<std::vector<int> >& nsNodes =
00422 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00423 const std::vector<double*>& nsNodeCoords =
00424 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00425
00426 RealType* matrixEntries;
00427 int* matrixIndices;
00428 int numEntries;
00429 RealType diag = j_coeff;
00430 bool fillResid = (f != Teuchos::null);
00431
00432 int nblock = 0;
00433
00434 if(f != Teuchos::null)
00435 nblock = f->size();
00436
00437 int nblock_jac = jac->size();
00438
00439 RealType time = dirichletWorkset.current_time;
00440 int number_of_components = this->func.getNumComponents();
00441
00442 double* coord;
00443 std::vector<ScalarT> BCVals(number_of_components);
00444
00445 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00446 coord = nsNodeCoords[inode];
00447
00448 this->func.computeBCs(coord, BCVals, time);
00449
00450 for(unsigned int j = 0; j < number_of_components; j++) {
00451 int offset = nsNodes[inode][j];
00452
00453
00454 for(int block = 0; block < nblock_jac; block++) {
00455 (*jac)[block].ExtractMyRowView(offset, numEntries, matrixEntries,
00456 matrixIndices);
00457
00458 for(int i = 0; i < numEntries; i++) matrixEntries[i] = 0;
00459
00460 (*jac)[block].ReplaceMyValues(offset, 1, &diag, &offset);
00461 }
00462
00463 if(fillResid)
00464 for(int block = 0; block < nblock; block++)
00465 (*f)[block][offset] = ((*x)[block][offset] - BCVals[j].val().coeff(block));
00466
00467 }
00468 }
00469 }
00470
00471
00472
00473
00474 template<typename Traits, typename cfunc_traits>
00475 DirichletCoordFunction<PHAL::AlbanyTraits::MPTangent, Traits, cfunc_traits>::
00476 DirichletCoordFunction(Teuchos::ParameterList& p) :
00477 DirichletCoordFunction_Base<PHAL::AlbanyTraits::MPTangent, Traits, cfunc_traits>(p) {
00478 }
00479
00480 template<typename Traits, typename cfunc_traits>
00481 void DirichletCoordFunction<PHAL::AlbanyTraits::MPTangent, Traits, cfunc_traits>::
00482 evaluateFields(typename Traits::EvalData dirichletWorkset) {
00483 Teuchos::RCP<Stokhos::ProductEpetraVector> f =
00484 dirichletWorkset.mp_f;
00485 Teuchos::RCP<Stokhos::ProductEpetraMultiVector> fp =
00486 dirichletWorkset.mp_fp;
00487 Teuchos::RCP<Stokhos::ProductEpetraMultiVector> JV =
00488 dirichletWorkset.mp_JV;
00489 Teuchos::RCP<const Stokhos::ProductEpetraVector> x =
00490 dirichletWorkset.mp_x;
00491 Teuchos::RCP<const Epetra_MultiVector> Vx = dirichletWorkset.Vx;
00492
00493 const RealType j_coeff = dirichletWorkset.j_coeff;
00494 const std::vector<std::vector<int> >& nsNodes =
00495 dirichletWorkset.nodeSets->find(this->nodeSetID)->second;
00496 const std::vector<double*>& nsNodeCoords =
00497 dirichletWorkset.nodeSetCoords->find(this->nodeSetID)->second;
00498
00499 int nblock = x->size();
00500
00501 RealType time = dirichletWorkset.current_time;
00502 int number_of_components = this->func.getNumComponents();
00503
00504 double* coord;
00505 std::vector<ScalarT> BCVals(number_of_components);
00506
00507 for(unsigned int inode = 0; inode < nsNodes.size(); inode++) {
00508 coord = nsNodeCoords[inode];
00509
00510 this->func.computeBCs(coord, BCVals, time);
00511
00512 for(unsigned int j = 0; j < number_of_components; j++) {
00513 int offset = nsNodes[inode][j];
00514
00515 if(f != Teuchos::null)
00516 for(int block = 0; block < nblock; block++)
00517 (*f)[block][offset] = (*x)[block][offset] - BCVals[j].val().coeff(block);
00518
00519 if(JV != Teuchos::null)
00520 for(int i = 0; i < dirichletWorkset.num_cols_x; i++)
00521 for(int block = 0; block < nblock; block++)
00522 (*JV)[block][i][offset] = j_coeff * (*Vx)[i][offset];
00523
00524 if(fp != Teuchos::null)
00525 for(int i = 0; i < dirichletWorkset.num_cols_p; i++)
00526 for(int block = 0; block < nblock; block++)
00527 (*fp)[block][i][offset] = -BCVals[j].dx(dirichletWorkset.param_offset + i).coeff(block);
00528
00529 }
00530 }
00531 }
00532 #endif //ALBANY_SG_MP
00533
00534 }
00535