9 #ifndef NOX_THYRA_MODEL_EVALUATOR_1DFEM_DEF_HPP
10 #define NOX_THYRA_MODEL_EVALUATOR_1DFEM_DEF_HPP
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"
23 #include "Thyra_EpetraLinearOp.hpp"
24 #include "Thyra_get_Epetra_Operator.hpp"
25 #include "Epetra_Comm.h"
26 #include "Epetra_Map.h"
27 #include "Epetra_Vector.h"
28 #include "Epetra_Import.h"
29 #include "Epetra_CrsGraph.h"
30 #include "Epetra_CrsMatrix.h"
32 namespace Tempus_Test {
36 template<
class Scalar>
39 const int num_global_elements,
45 num_global_elements_(num_global_elements),
50 showGetInvalidArg_(false)
54 using ::Thyra::VectorBase;
55 typedef ::Thyra::ModelEvaluatorBase MEB;
67 if (
comm_->NumProc() == 1) {
71 int OverlapNumMyElements;
73 OverlapNumMyElements =
x_owned_map_->NumMyElements() + 2;
74 if ( (
comm_->MyPID() == 0) || (
comm_->MyPID() == (
comm_->NumProc() - 1)) )
75 OverlapNumMyElements --;
77 if (
comm_->MyPID() == 0)
82 int* OverlapMyGlobalElements =
new int[OverlapNumMyElements];
84 for (
int i = 0; i < OverlapNumMyElements; i ++)
85 OverlapMyGlobalElements[i] = OverlapMinMyGID + i;
90 OverlapMyGlobalElements,
94 delete [] OverlapMyGlobalElements;
105 V_S(
x0_.
ptr(), ST::zero());
119 (*node_coordinates_)[i] = z_min_ + dx*((double)
x_owned_map_->MinMyGID() + i);
125 MEB::InArgsSetup<Scalar> inArgs;
126 inArgs.setModelEvalDescription(this->
description());
127 inArgs.setSupports(MEB::IN_ARG_t);
128 inArgs.setSupports(MEB::IN_ARG_x);
129 inArgs.setSupports( MEB::IN_ARG_beta );
130 inArgs.setSupports( MEB::IN_ARG_x_dot );
131 inArgs.setSupports( MEB::IN_ARG_alpha );
134 MEB::OutArgsSetup<Scalar> outArgs;
135 outArgs.setModelEvalDescription(this->
description());
136 outArgs.setSupports(MEB::OUT_ARG_f);
137 outArgs.setSupports(MEB::OUT_ARG_W);
138 outArgs.setSupports(MEB::OUT_ARG_W_op);
139 outArgs.setSupports(MEB::OUT_ARG_W_prec);
150 auto x_dot_init = Thyra::createMember(this->
get_x_space());
151 Thyra::put_scalar(Scalar(0.0),x_dot_init.ptr());
157 template<
class Scalar>
169 int OverlapNumMyElements = x_ghosted_map_->NumMyElements();
172 for (
int ne=0; ne < OverlapNumMyElements-1; ne++) {
175 for (
int i=0; i< 2; i++) {
176 row=x_ghosted_map_->GID(ne+i);
179 for(
int j=0;j < 2; j++) {
182 if (x_owned_map_->MyGID(row)) {
183 column=x_ghosted_map_->GID(ne+j);
184 W_graph->InsertGlobalIndices(row, 1, &column);
189 W_graph->FillComplete();
193 template<
class Scalar>
200 x0.sv().values()().assign(x0_in);
204 template<
class Scalar>
207 showGetInvalidArg_ = showGetInvalidArg;
210 template<
class Scalar>
214 W_factory_ = W_factory;
220 template<
class Scalar>
228 template<
class Scalar>
236 template<
class Scalar>
240 return nominalValues_;
244 template<
class Scalar>
249 this->get_W_factory();
256 Thyra::linearOpWithSolve<double>(*W_factory,matrix);
261 template<
class Scalar>
268 return Thyra::nonconstEpetraLinearOp(W_epetra);
271 template<
class Scalar>
279 Thyra::nonconstEpetraLinearOp(W_epetra);
284 prec->initializeRight(W_op);
289 template<
class Scalar>
297 template<
class Scalar>
301 return prototypeInArgs_;
308 template<
class Scalar>
312 return prototypeOutArgs_;
316 template<
class Scalar>
324 using Teuchos::rcp_dynamic_cast;
350 J = rcp_dynamic_cast<Epetra_CrsMatrix>(W_epetra);
357 M_inv = rcp_dynamic_cast<Epetra_CrsMatrix>(M_epetra);
359 J_diagonal_ =
Teuchos::rcp(
new Epetra_Vector(*x_owned_map_));
367 if (comm_->MyPID() == 0) {
373 u_ptr =
Teuchos::rcp(
new Epetra_Vector(*x_ghosted_map_));
378 u_dot_ptr =
Teuchos::rcp(
new Epetra_Vector(*x_ghosted_map_));
383 x_ptr =
Teuchos::rcp(
new Epetra_Vector(*x_ghosted_map_));
384 x_ptr->Import(*node_coordinates_, *importer_, Insert);
387 Epetra_Vector& u = *u_ptr;
388 Epetra_Vector& u_dot = *u_dot_ptr;
389 Epetra_Vector& x = *x_ptr;
392 int OverlapNumMyElements = x_ghosted_map_->NumMyElements();
399 const auto beta = inArgs.
get_beta();
407 M_inv->PutScalar(0.0);
412 for (
int ne=0; ne < OverlapNumMyElements-1; ne++) {
415 for(
int gp=0; gp < 2; gp++) {
422 uu_dot[1]=u_dot[ne+1];
427 for (
int i=0; i< 2; i++) {
428 int row=x_ghosted_map_->GID(ne+i);
431 if (x_owned_map_->MyGID(row)) {
433 (*f)[x_owned_map_->LID(x_ghosted_map_->GID(ne+i))]+=
436 +(a_/basis.
dz*basis.
duu*basis.
phi[i]
438 +k_*basis.
uu*basis.
uu*basis.
phi[i] );
443 for(
int j=0;j < 2; j++) {
444 if (x_owned_map_->MyGID(row)) {
445 int column=x_ghosted_map_->GID(ne+j);
448 alpha * basis.
phi[i] * basis.
phi[j]
452 +2.0*k_*basis.
uu*basis.
phi[j]*basis.
phi[i]
455 ierr=J->SumIntoGlobalValues(row, 1, &jac, &column);
460 for(
int j=0;j < 2; j++) {
461 if (x_owned_map_->MyGID(row)) {
462 int column=x_ghosted_map_->GID(ne+j);
467 alpha * basis.
phi[i] * basis.
phi[j]
471 +2.0*k_*basis.
uu*basis.
phi[j]*basis.
phi[i]
474 ierr = M_inv->SumIntoGlobalValues(row, 1, &jac, &column);
485 if (comm_->MyPID() == 0) {
492 ierr = J->ReplaceGlobalValues(0, 1, &jac, &column);
495 ierr = J->ReplaceGlobalValues(0, 1, &jac, &column);
500 ierr = M_inv->ReplaceGlobalValues(0, 1, &jac, &column);
503 ierr = M_inv->ReplaceGlobalValues(0, 1, &jac, &column);
512 M_inv->ExtractDiagonalCopy(*J_diagonal_);
514 for (
int i=0; i < J_diagonal_->MyLength(); ++i)
515 (*J_diagonal_)[i] = 1.0 / ((*J_diagonal_)[i]);
517 M_inv->PutScalar(0.0);
518 M_inv->ReplaceDiagonalValues(*J_diagonal_);
519 M_inv->FillComplete();
555 if (gp==0) {
eta=-1.0/sqrt(3.0);
wt=1.0;}
556 if (gp==1) {
eta=1.0/sqrt(3.0);
wt=1.0;}
571 for (
int i=0; i < N; i++) {
576 uu_dot += u_dot[i] * phi[i];
577 duu_dot += u_dot[i] * dphide[i];
::Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
void evalModelImpl(const ::Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const ::Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const
Teuchos::RCP< const Epetra_Map > x_ghosted_map_
bool is_null(const boost::shared_ptr< T > &p)
Teuchos::RCP< const ::Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
CDR_Model(const Teuchos::RCP< const Epetra_Comm > &comm, const int num_global_elements, const Scalar z_min, const Scalar z_max, const Scalar a, const Scalar k)
::Thyra::ModelEvaluatorBase::OutArgs< Scalar > prototypeOutArgs_
virtual Teuchos::RCP< Epetra_CrsGraph > createGraph()
RCP< const VectorBase< Scalar > > get_x_dot() const
RCP< const VectorSpaceBase< double > > create_VectorSpace(const RCP< const Epetra_Map > &epetra_map)
Teuchos::RCP< Epetra_CrsGraph > W_graph_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< Epetra_Vector > node_coordinates_
Teuchos::RCP< const Epetra_Map > f_owned_map_
Evaluation< VectorBase< Scalar > > get_f() const
const int num_global_elements_
Teuchos::RCP< ::Thyra::VectorBase< Scalar > > x0_
Teuchos::RCP< ::Thyra::PreconditionerBase< Scalar > > create_W_prec() const
void setShowGetInvalidArgs(bool showGetInvalidArg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Epetra_Map > x_owned_map_
::Thyra::ModelEvaluatorBase::InArgs< Scalar > nominalValues_
void set_W_factory(const Teuchos::RCP< const ::Thyra::LinearOpWithSolveFactoryBase< Scalar > > &W_factory)
void set_x0(const Teuchos::ArrayView< const Scalar > &x0)
RCP< Epetra_Vector > get_Epetra_Vector(const Epetra_Map &map, const RCP< VectorBase< double > > &v)
virtual std::string description() const
void computeBasis(int gp, double *z, double *u, double *u_dot=nullptr)
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > x_space_
Teuchos::RCP< ::Thyra::LinearOpBase< Scalar > > create_W_op() const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< double > > create_W() const
::Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
bool nonnull(const boost::shared_ptr< T > &p)
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > get_f_space() const
Teuchos::RCP< Epetra_Operator > get_Epetra_Operator(LinearOpBase< Scalar > &)
::Thyra::ModelEvaluatorBase::InArgs< Scalar > prototypeInArgs_
RCP< PreconditionerBase< Scalar > > get_W_prec() const
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > get_x_space() const
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
const Teuchos::RCP< const Epetra_Comm > comm_
Teuchos::RCP< const ::Thyra::VectorSpaceBase< Scalar > > f_space_
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
::Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Teuchos::RCP< const Epetra_Import > importer_