| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// NOX: An Object-Oriented Nonlinear Solver Package |
| 4 |
// |
| 5 |
// Copyright 2002 NTESS and the NOX contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
#ifndef NOX_THYRA_MODEL_EVALUATOR_1DFEM_DEF_HPP |
| 10 |
#define NOX_THYRA_MODEL_EVALUATOR_1DFEM_DEF_HPP |
| 11 |
|
| 12 |
// Thyra support |
| 13 |
#include "Thyra_DefaultSpmdVectorSpace.hpp" |
| 14 |
#include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp" |
| 15 |
#include "Thyra_DetachedMultiVectorView.hpp" |
| 16 |
#include "Thyra_DetachedVectorView.hpp" |
| 17 |
#include "Thyra_MultiVectorStdOps.hpp" |
| 18 |
#include "Thyra_VectorStdOps.hpp" |
| 19 |
#include "Thyra_PreconditionerBase.hpp" |
| 20 |
|
| 21 |
// Epetra support |
| 22 |
#include "Thyra_EpetraThyraWrappers.hpp" |
| 23 |
#include "Thyra_get_Epetra_Operator.hpp" |
| 24 |
#include "Epetra_Comm.h" |
| 25 |
#include "Epetra_Map.h" |
| 26 |
#include "Epetra_Vector.h" |
| 27 |
#include "Epetra_Import.h" |
| 28 |
#include "Epetra_CrsGraph.h" |
| 29 |
#include "Epetra_CrsMatrix.h" |
| 30 |
|
| 31 |
// Nonmember constuctors |
| 32 |
|
| 33 |
template<class Scalar> |
| 34 |
Teuchos::RCP<ModelEvaluator1DFEM<Scalar> > |
| 35 |
modelEvaluator1DFEM(const Teuchos::RCP<const Epetra_Comm>& comm, |
| 36 |
const int num_global_elements, |
| 37 |
const Scalar z_min, |
| 38 |
const Scalar z_max) |
| 39 |
{ |
| 40 |
return Teuchos::rcp(new ModelEvaluator1DFEM<Scalar>(comm,num_global_elements,z_min,z_max)); |
| 41 |
} |
| 42 |
|
| 43 |
// Constructor |
| 44 |
|
| 45 |
template<class Scalar> |
| 46 |
ModelEvaluator1DFEM<Scalar>:: |
| 47 |
ModelEvaluator1DFEM(const Teuchos::RCP<const Epetra_Comm>& comm, |
| 48 |
const int num_global_elements, |
| 49 |
const Scalar z_min, |
| 50 |
const Scalar z_max) : |
| 51 |
comm_(comm), |
| 52 |
num_global_elements_(num_global_elements), |
| 53 |
z_min_(z_min), |
| 54 |
z_max_(z_max), |
| 55 |
k_(0.0), |
| 56 |
showGetInvalidArg_(false) |
| 57 |
{ |
| 58 |
using Teuchos::RCP; |
| 59 |
using Teuchos::rcp; |
| 60 |
using ::Thyra::VectorBase; |
| 61 |
typedef ::Thyra::ModelEvaluatorBase MEB; |
| 62 |
typedef Teuchos::ScalarTraits<Scalar> ST; |
| 63 |
|
| 64 |
TEUCHOS_ASSERT(nonnull(comm_)); |
| 65 |
|
| 66 |
const int num_nodes = num_global_elements_ + 1; |
| 67 |
|
| 68 |
// owned space |
| 69 |
x_owned_map_ = rcp(new Epetra_Map(num_nodes,0,*comm_)); |
| 70 |
x_space_ = ::Thyra::create_VectorSpace(x_owned_map_); |
| 71 |
|
| 72 |
// ghosted space |
| 73 |
if (comm_->NumProc() == 1) { |
| 74 |
x_ghosted_map_ = x_owned_map_; |
| 75 |
} else { |
| 76 |
|
| 77 |
int OverlapNumMyElements; |
| 78 |
int OverlapMinMyGID; |
| 79 |
OverlapNumMyElements = x_owned_map_->NumMyElements() + 2; |
| 80 |
if ( (comm_->MyPID() == 0) || (comm_->MyPID() == (comm_->NumProc() - 1)) ) |
| 81 |
OverlapNumMyElements --; |
| 82 |
|
| 83 |
if (comm_->MyPID() == 0) |
| 84 |
OverlapMinMyGID = x_owned_map_->MinMyGID(); |
| 85 |
else |
| 86 |
OverlapMinMyGID = x_owned_map_->MinMyGID() - 1; |
| 87 |
|
| 88 |
int* OverlapMyGlobalElements = new int[OverlapNumMyElements]; |
| 89 |
|
| 90 |
for (int i = 0; i < OverlapNumMyElements; i ++) |
| 91 |
OverlapMyGlobalElements[i] = OverlapMinMyGID + i; |
| 92 |
|
| 93 |
x_ghosted_map_ = |
| 94 |
Teuchos::rcp(new Epetra_Map(-1, |
| 95 |
OverlapNumMyElements, |
| 96 |
OverlapMyGlobalElements, |
| 97 |
0, |
| 98 |
*comm_)); |
| 99 |
|
| 100 |
delete [] OverlapMyGlobalElements; |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
importer_ = Teuchos::rcp(new Epetra_Import(*x_ghosted_map_, *x_owned_map_)); |
| 105 |
|
| 106 |
// residual space |
| 107 |
f_owned_map_ = x_owned_map_; |
| 108 |
f_space_ = x_space_; |
| 109 |
|
| 110 |
x0_ = ::Thyra::createMember(x_space_); |
| 111 |
V_S(x0_.ptr(), ST::zero()); |
| 112 |
|
| 113 |
// set_p(Teuchos::tuple<Scalar>(p0, p1)()); |
| 114 |
// set_x0(Teuchos::tuple<Scalar>(x0, x1)()); |
| 115 |
|
| 116 |
// Initialize the graph for W CrsMatrix object |
| 117 |
W_graph_ = createGraph(); |
| 118 |
|
| 119 |
// Create the nodal coordinates |
| 120 |
{ |
| 121 |
node_coordinates_ = Teuchos::rcp(new Epetra_Vector(*x_owned_map_)); |
| 122 |
Scalar length = z_max_ - z_min_; |
| 123 |
Scalar dx = length/((double) num_global_elements_ - 1); |
| 124 |
for (int i=0; i < x_owned_map_->NumMyElements(); i++) { |
| 125 |
(*node_coordinates_)[i] = z_min_ + dx*((double) x_owned_map_->MinMyGID() + i); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
MEB::InArgsSetup<Scalar> inArgs; |
| 132 |
inArgs.setModelEvalDescription(this->description()); |
| 133 |
inArgs.setSupports(MEB::IN_ARG_x); |
| 134 |
prototypeInArgs_ = inArgs; |
| 135 |
|
| 136 |
MEB::OutArgsSetup<Scalar> outArgs; |
| 137 |
outArgs.setModelEvalDescription(this->description()); |
| 138 |
outArgs.setSupports(MEB::OUT_ARG_f); |
| 139 |
outArgs.setSupports(MEB::OUT_ARG_W_op); |
| 140 |
outArgs.setSupports(MEB::OUT_ARG_W_prec); |
| 141 |
// outArgs.set_W_properties(DerivativeProperties( |
| 142 |
// DERIV_LINEARITY_NONCONST |
| 143 |
// ,DERIV_RANK_FULL |
| 144 |
// ,true // supportsAdjoint |
| 145 |
// )); |
| 146 |
prototypeOutArgs_ = outArgs; |
| 147 |
|
| 148 |
nominalValues_ = inArgs; |
| 149 |
nominalValues_.set_x(x0_); |
| 150 |
} |
| 151 |
|
| 152 |
// Initializers/Accessors |
| 153 |
|
| 154 |
template<class Scalar> |
| 155 |
Teuchos::RCP<Epetra_CrsGraph> |
| 156 |
ModelEvaluator1DFEM<Scalar>::createGraph() |
| 157 |
{ |
| 158 |
Teuchos::RCP<Epetra_CrsGraph> W_graph; |
| 159 |
|
| 160 |
// Create the shell for the |
| 161 |
W_graph = Teuchos::rcp(new Epetra_CrsGraph(Copy, *x_owned_map_, 5)); |
| 162 |
|
| 163 |
// Declare required variables |
| 164 |
int row; |
| 165 |
int column; |
| 166 |
int OverlapNumMyElements = x_ghosted_map_->NumMyElements(); |
| 167 |
|
| 168 |
// Loop Over # of Finite Elements on Processor |
| 169 |
for (int ne=0; ne < OverlapNumMyElements-1; ne++) { |
| 170 |
|
| 171 |
// Loop over Nodes in Element |
| 172 |
for (int i=0; i< 2; i++) { |
| 173 |
row=x_ghosted_map_->GID(ne+i); |
| 174 |
|
| 175 |
// Loop over Trial Functions |
| 176 |
for(int j=0;j < 2; j++) { |
| 177 |
|
| 178 |
// If this row is owned by current processor, add the index |
| 179 |
if (x_owned_map_->MyGID(row)) { |
| 180 |
column=x_ghosted_map_->GID(ne+j); |
| 181 |
W_graph->InsertGlobalIndices(row, 1, &column); |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
W_graph->FillComplete(); |
| 187 |
return W_graph; |
| 188 |
} |
| 189 |
|
| 190 |
template<class Scalar> |
| 191 |
void ModelEvaluator1DFEM<Scalar>::set_x0(const Teuchos::ArrayView<const Scalar> &x0_in) |
| 192 |
{ |
| 193 |
#ifdef TEUCHOS_DEBUG |
| 194 |
TEUCHOS_ASSERT_EQUALITY(x_space_->dim(), x0_in.size()); |
| 195 |
#endif |
| 196 |
Thyra::DetachedVectorView<Scalar> x0(x0_); |
| 197 |
x0.sv().values()().assign(x0_in); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
template<class Scalar> |
| 202 |
void ModelEvaluator1DFEM<Scalar>::setShowGetInvalidArgs(bool showGetInvalidArg) |
| 203 |
{ |
| 204 |
showGetInvalidArg_ = showGetInvalidArg; |
| 205 |
} |
| 206 |
|
| 207 |
template<class Scalar> |
| 208 |
void ModelEvaluator1DFEM<Scalar>:: |
| 209 |
set_W_factory(const Teuchos::RCP<const ::Thyra::LinearOpWithSolveFactoryBase<Scalar> >& W_factory) |
| 210 |
{ |
| 211 |
W_factory_ = W_factory; |
| 212 |
} |
| 213 |
|
| 214 |
// Public functions overridden from ModelEvaulator |
| 215 |
|
| 216 |
|
| 217 |
template<class Scalar> |
| 218 |
Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > |
| 219 |
ModelEvaluator1DFEM<Scalar>::get_x_space() const |
| 220 |
{ |
| 221 |
return x_space_; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
template<class Scalar> |
| 226 |
Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > |
| 227 |
ModelEvaluator1DFEM<Scalar>::get_f_space() const |
| 228 |
{ |
| 229 |
return f_space_; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
template<class Scalar> |
| 234 |
Thyra::ModelEvaluatorBase::InArgs<Scalar> |
| 235 |
ModelEvaluator1DFEM<Scalar>::getNominalValues() const |
| 236 |
{ |
| 237 |
return nominalValues_; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
template<class Scalar> |
| 242 |
Teuchos::RCP<Thyra::LinearOpBase<Scalar> > |
| 243 |
ModelEvaluator1DFEM<Scalar>::create_W_op() const |
| 244 |
{ |
| 245 |
Teuchos::RCP<Epetra_CrsMatrix> W_epetra = |
| 246 |
Teuchos::rcp(new Epetra_CrsMatrix(::Copy,*W_graph_)); |
| 247 |
|
| 248 |
return Thyra::nonconstEpetraLinearOp(W_epetra); |
| 249 |
} |
| 250 |
|
| 251 |
template<class Scalar> |
| 252 |
Teuchos::RCP< ::Thyra::PreconditionerBase<Scalar> > |
| 253 |
ModelEvaluator1DFEM<Scalar>::create_W_prec() const |
| 254 |
{ |
| 255 |
Teuchos::RCP<Epetra_CrsMatrix> W_epetra = |
| 256 |
Teuchos::rcp(new Epetra_CrsMatrix(::Copy,*W_graph_)); |
| 257 |
|
| 258 |
const Teuchos::RCP<Thyra::LinearOpBase< Scalar > > W_op = |
| 259 |
Thyra::nonconstEpetraLinearOp(W_epetra); |
| 260 |
|
| 261 |
Teuchos::RCP<Thyra::DefaultPreconditioner<Scalar> > prec = |
| 262 |
Teuchos::rcp(new Thyra::DefaultPreconditioner<Scalar>); |
| 263 |
|
| 264 |
prec->initializeRight(W_op); |
| 265 |
|
| 266 |
return prec; |
| 267 |
} |
| 268 |
|
| 269 |
template<class Scalar> |
| 270 |
Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > |
| 271 |
ModelEvaluator1DFEM<Scalar>::get_W_factory() const |
| 272 |
{ |
| 273 |
return W_factory_; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
template<class Scalar> |
| 278 |
Thyra::ModelEvaluatorBase::InArgs<Scalar> |
| 279 |
ModelEvaluator1DFEM<Scalar>::createInArgs() const |
| 280 |
{ |
| 281 |
return prototypeInArgs_; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
// Private functions overridden from ModelEvaulatorDefaultBase |
| 286 |
|
| 287 |
|
| 288 |
template<class Scalar> |
| 289 |
Thyra::ModelEvaluatorBase::OutArgs<Scalar> |
| 290 |
ModelEvaluator1DFEM<Scalar>::createOutArgsImpl() const |
| 291 |
{ |
| 292 |
return prototypeOutArgs_; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
template<class Scalar> |
| 297 |
void ModelEvaluator1DFEM<Scalar>::evalModelImpl( |
| 298 |
const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs, |
| 299 |
const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs |
| 300 |
) const |
| 301 |
{ |
| 302 |
using Teuchos::RCP; |
| 303 |
using Teuchos::rcp; |
| 304 |
using Teuchos::rcp_dynamic_cast; |
| 305 |
|
| 306 |
TEUCHOS_ASSERT(nonnull(inArgs.get_x())); |
| 307 |
|
| 308 |
//const Thyra::ConstDetachedVectorView<Scalar> x(inArgs.get_x()); |
| 309 |
|
| 310 |
const RCP<Thyra::VectorBase<Scalar> > f_out = outArgs.get_f(); |
| 311 |
const RCP<Thyra::LinearOpBase<Scalar> > W_out = outArgs.get_W_op(); |
| 312 |
const RCP<Thyra::PreconditionerBase<Scalar> > W_prec_out = outArgs.get_W_prec(); |
| 313 |
|
| 314 |
|
| 315 |
if ( nonnull(f_out) || nonnull(W_out) || nonnull(W_prec_out) ) { |
| 316 |
|
| 317 |
// **************** |
| 318 |
// Get the underlying epetra objects |
| 319 |
// **************** |
| 320 |
|
| 321 |
RCP<Epetra_Vector> f; |
| 322 |
if (nonnull(f_out)) { |
| 323 |
f = Thyra::get_Epetra_Vector(*f_owned_map_,outArgs.get_f()); |
| 324 |
} |
| 325 |
|
| 326 |
RCP<Epetra_CrsMatrix> J; |
| 327 |
if (nonnull(W_out)) { |
| 328 |
RCP<Epetra_Operator> W_epetra = Thyra::get_Epetra_Operator(*W_out); |
| 329 |
J = rcp_dynamic_cast<Epetra_CrsMatrix>(W_epetra); |
| 330 |
TEUCHOS_ASSERT(nonnull(J)); |
| 331 |
} |
| 332 |
|
| 333 |
RCP<Epetra_CrsMatrix> M_inv; |
| 334 |
if (nonnull(W_prec_out)) { |
| 335 |
RCP<Epetra_Operator> M_epetra = Thyra::get_Epetra_Operator(*(W_prec_out->getNonconstRightPrecOp())); |
| 336 |
M_inv = rcp_dynamic_cast<Epetra_CrsMatrix>(M_epetra); |
| 337 |
TEUCHOS_ASSERT(nonnull(M_inv)); |
| 338 |
J_diagonal_ = Teuchos::rcp(new Epetra_Vector(*x_owned_map_)); |
| 339 |
} |
| 340 |
|
| 341 |
// **************** |
| 342 |
// Create ghosted objects |
| 343 |
// **************** |
| 344 |
|
| 345 |
if (is_null(u_ptr)) |
| 346 |
u_ptr = Teuchos::rcp(new Epetra_Vector(*x_ghosted_map_)); |
| 347 |
|
| 348 |
u_ptr->Import(*(Thyra::get_Epetra_Vector(*x_owned_map_,inArgs.get_x())), *importer_, Insert); |
| 349 |
|
| 350 |
if (is_null(x_ptr)) { |
| 351 |
x_ptr = Teuchos::rcp(new Epetra_Vector(*x_ghosted_map_)); |
| 352 |
x_ptr->Import(*node_coordinates_, *importer_, Insert); |
| 353 |
} |
| 354 |
|
| 355 |
Epetra_Vector& u = *u_ptr; |
| 356 |
Epetra_Vector& x = *x_ptr; |
| 357 |
|
| 358 |
double factor = 1.0; |
| 359 |
|
| 360 |
int ierr = 0; |
| 361 |
int OverlapNumMyElements = x_ghosted_map_->NumMyElements(); |
| 362 |
|
| 363 |
double xx[2]; |
| 364 |
double uu[2]; |
| 365 |
Basis basis; |
| 366 |
|
| 367 |
// Zero out the objects that will be filled |
| 368 |
if (nonnull(f)) |
| 369 |
f->PutScalar(0.0); |
| 370 |
if (nonnull(J)) |
| 371 |
J->PutScalar(0.0); |
| 372 |
if (nonnull(M_inv)) |
| 373 |
M_inv->PutScalar(0.0); |
| 374 |
|
| 375 |
// Loop Over # of Finite Elements on Processor |
| 376 |
for (int ne=0; ne < OverlapNumMyElements-1; ne++) { |
| 377 |
|
| 378 |
// Loop Over Gauss Points |
| 379 |
for(int gp=0; gp < 2; gp++) { |
| 380 |
// Get the solution and coordinates at the nodes |
| 381 |
xx[0]=x[ne]; |
| 382 |
xx[1]=x[ne+1]; |
| 383 |
uu[0]=u[ne]; |
| 384 |
uu[1]=u[ne+1]; |
| 385 |
// Calculate the basis function at the gauss point |
| 386 |
basis.computeBasis(gp, xx, uu); |
| 387 |
|
| 388 |
// Loop over Nodes in Element |
| 389 |
for (int i=0; i< 2; i++) { |
| 390 |
int row=x_ghosted_map_->GID(ne+i); |
| 391 |
//printf("Proc=%d GlobalRow=%d LocalRow=%d Owned=%d\n", |
| 392 |
// MyPID, row, ne+i,x_owned_map_.MyGID(row)); |
| 393 |
if (x_owned_map_->MyGID(row)) { |
| 394 |
if (nonnull(f)) { |
| 395 |
(*f)[x_owned_map_->LID(x_ghosted_map_->GID(ne+i))]+= |
| 396 |
+basis.wt*basis.dz |
| 397 |
*((1.0/(basis.dz*basis.dz))*basis.duu* |
| 398 |
basis.dphide[i]+factor*basis.uu*basis.uu*basis.phi[i]); |
| 399 |
} |
| 400 |
} |
| 401 |
// Loop over Trial Functions |
| 402 |
if (nonnull(J)) { |
| 403 |
for(int j=0;j < 2; j++) { |
| 404 |
if (x_owned_map_->MyGID(row)) { |
| 405 |
int column=x_ghosted_map_->GID(ne+j); |
| 406 |
double jac=basis.wt*basis.dz*((1.0/(basis.dz*basis.dz))* |
| 407 |
basis.dphide[j]*basis.dphide[i] |
| 408 |
+2.0*factor*basis.uu*basis.phi[j]* |
| 409 |
basis.phi[i]); |
| 410 |
ierr=J->SumIntoGlobalValues(row, 1, &jac, &column); |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
if (nonnull(M_inv)) { |
| 415 |
for(int j=0;j < 2; j++) { |
| 416 |
if (x_owned_map_->MyGID(row)) { |
| 417 |
int column=x_ghosted_map_->GID(ne+j); |
| 418 |
if (row == column) { |
| 419 |
double jac = basis.wt*basis.dz*((1.0/(basis.dz*basis.dz))* |
| 420 |
basis.dphide[j]*basis.dphide[i] |
| 421 |
+2.0*factor*basis.uu*basis.phi[j]* |
| 422 |
basis.phi[i]); |
| 423 |
ierr = M_inv->SumIntoGlobalValues(row, 1, &jac, &column); |
| 424 |
} |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
// Insert Boundary Conditions and modify Jacobian and function (F) |
| 433 |
// U(0)=1 |
| 434 |
if (comm_->MyPID() == 0) { |
| 435 |
if (nonnull(f)) |
| 436 |
(*f)[0]= u[0] - 1.0; |
| 437 |
if (nonnull(J)) { |
| 438 |
int column=0; |
| 439 |
double jac=1.0; |
| 440 |
ierr = J->ReplaceGlobalValues(0, 1, &jac, &column); |
| 441 |
column=1; |
| 442 |
jac=0.0; |
| 443 |
ierr = J->ReplaceGlobalValues(0, 1, &jac, &column); |
| 444 |
} |
| 445 |
if (nonnull(M_inv)) { |
| 446 |
int column=0; |
| 447 |
double jac=1.0; |
| 448 |
ierr = M_inv->ReplaceGlobalValues(0, 1, &jac, &column); |
| 449 |
column=1; |
| 450 |
jac=0.0; |
| 451 |
ierr = M_inv->ReplaceGlobalValues(0, 1, &jac, &column); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
if (nonnull(J)) |
| 456 |
J->FillComplete(); |
| 457 |
|
| 458 |
if (nonnull(M_inv)) { |
| 459 |
// invert the Jacobian diagonal for the preconditioner |
| 460 |
M_inv->ExtractDiagonalCopy(*J_diagonal_); |
| 461 |
|
| 462 |
for (int i=0; i < J_diagonal_->MyLength(); ++i) |
| 463 |
(*J_diagonal_)[i] = 1.0 / ((*J_diagonal_)[i]); |
| 464 |
|
| 465 |
M_inv->PutScalar(0.0); |
| 466 |
M_inv->ReplaceDiagonalValues(*J_diagonal_); |
| 467 |
M_inv->FillComplete(); |
| 468 |
} |
| 469 |
|
| 470 |
TEUCHOS_ASSERT(ierr > -1); |
| 471 |
|
| 472 |
} |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
//==================================================================== |
| 477 |
// Basis vector |
| 478 |
|
| 479 |
// Constructor |
| 480 |
Basis::Basis(): |
| 481 |
uu(0.0), |
| 482 |
zz(0.0), |
| 483 |
duu(0.0), |
| 484 |
eta(0.0), |
| 485 |
wt(0.0), |
| 486 |
dz(0.0), |
| 487 |
uuold(0.0), |
| 488 |
duuold(0.0) |
| 489 |
{ |
| 490 |
phi = new double[2]; |
| 491 |
dphide = new double[2]; |
| 492 |
} |
| 493 |
|
| 494 |
// Destructor |
| 495 |
Basis::~Basis() { |
| 496 |
delete [] phi; |
| 497 |
delete [] dphide; |
| 498 |
} |
| 499 |
|
| 500 |
// Calculates a linear 1D basis |
| 501 |
void Basis::computeBasis(int gp, double *z, double *u, double *uold) { |
| 502 |
int N = 2; |
| 503 |
if (gp==0) {eta=-1.0/sqrt(3.0); wt=1.0;} |
| 504 |
if (gp==1) {eta=1.0/sqrt(3.0); wt=1.0;} |
| 505 |
|
| 506 |
// Calculate basis function and derivatives at nodel pts |
| 507 |
phi[0]=(1.0-eta)/2.0; |
| 508 |
phi[1]=(1.0+eta)/2.0; |
| 509 |
dphide[0]=-0.5; |
| 510 |
dphide[1]=0.5; |
| 511 |
|
| 512 |
// Caculate basis function and derivative at GP. |
| 513 |
dz=0.5*(z[1]-z[0]); |
| 514 |
zz=0.0; |
| 515 |
uu=0.0; |
| 516 |
duu=0.0; |
| 517 |
uuold=0.0; |
| 518 |
duuold=0.0; |
| 519 |
for (int i=0; i < N; i++) { |
| 520 |
zz += z[i] * phi[i]; |
| 521 |
uu += u[i] * phi[i]; |
| 522 |
duu += u[i] * dphide[i]; |
| 523 |
if (uold) { |
| 524 |
uuold += uold[i] * phi[i]; |
| 525 |
duuold += uold[i] * dphide[i]; |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
return; |
| 530 |
} |
| 531 |
|
| 532 |
#endif |