00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "ExampleApplication.hpp"
00030 #ifdef HAVE_MPI
00031 # include "Epetra_MpiComm.h"
00032 # include "mpi.h"
00033 #else
00034 # include "Epetra_SerialComm.h"
00035 #endif // HAVE_MPI
00036 #include "Epetra_CrsMatrix.h"
00037
00038 #ifdef EXAMPLEAPPLICATION_DEBUG
00039 #include <iostream>
00040 #endif
00041
00042 #include "Teuchos_dyn_cast.hpp"
00043
00044 ExampleApplication1Dfem::ExampleApplication1Dfem(Teuchos::RefCountPtr<Epetra_Comm> &epetra_comm_ptr, Teuchos::ParameterList ¶ms)
00045 {
00046 initialize(epetra_comm_ptr, params);
00047 }
00048
00049 void ExampleApplication1Dfem::initialize(Teuchos::RefCountPtr<Epetra_Comm> &epetra_comm_ptr, Teuchos::ParameterList ¶ms)
00050 {
00051 epetra_comm_ptr_ = epetra_comm_ptr;
00052 numElements_ = params.get<int>( "NumElements" );
00053
00054
00055 problemInterfacePtr_ = Teuchos::rcp(new TransientInterface(numElements_, *epetra_comm_ptr_, -20.0, 20.0));
00056
00057
00058 problemInterfacePtr_->setPDEfactor(1.0);
00059
00060
00061 epetra_map_ptr_ = Teuchos::rcp( new Epetra_Map( problemInterfacePtr_->getMap() ) );
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 W_graph_ = Teuchos::rcp(new Epetra_CrsGraph( problemInterfacePtr_->getGraph() ) );
00072
00073 }
00074
00075
00076
00077 Teuchos::RefCountPtr<const Epetra_Map>
00078 ExampleApplication1Dfem::get_x_map() const
00079 {
00080 return epetra_map_ptr_;
00081 }
00082
00083 Teuchos::RefCountPtr<const Epetra_Map>
00084 ExampleApplication1Dfem::get_f_map() const
00085 {
00086 return epetra_map_ptr_;
00087 }
00088
00089 Teuchos::RefCountPtr<const Epetra_Vector>
00090 ExampleApplication1Dfem::get_x_init() const
00091 {
00092 Epetra_Vector& soln = problemInterfacePtr_->getSolution();
00093 Teuchos::RefCountPtr<Epetra_Vector> x_init = Teuchos::rcp(new Epetra_Vector(soln));
00094 return x_init;
00095 }
00096
00097 Teuchos::RefCountPtr<const Epetra_Vector>
00098 ExampleApplication1Dfem::get_x_dot_init() const
00099 {
00100 Epetra_Vector& soln = problemInterfacePtr_->getSolution();
00101 Teuchos::RefCountPtr<Epetra_Vector> x_dot_init = Teuchos::rcp(new Epetra_Vector(soln));
00102 x_dot_init->PutScalar(0.0);
00103 return x_dot_init;
00104 }
00105
00106 Teuchos::RefCountPtr<Epetra_Operator>
00107 ExampleApplication1Dfem::create_W() const
00108 {
00109 Teuchos::RefCountPtr<Epetra_Operator> W = Teuchos::rcp(new Epetra_CrsMatrix(::Copy,*W_graph_));
00110 return W;
00111 }
00112
00113 EpetraExt::ModelEvaluator::InArgs
00114 ExampleApplication1Dfem::createInArgs() const
00115 {
00116 InArgsSetup inArgs;
00117 inArgs.setSupports(IN_ARG_x,true);
00118 inArgs.setSupports(IN_ARG_x_dot,true);
00119 inArgs.setSupports(IN_ARG_alpha,true);
00120 inArgs.setSupports(IN_ARG_beta,true);
00121 return inArgs;
00122 }
00123
00124 EpetraExt::ModelEvaluator::OutArgs
00125 ExampleApplication1Dfem::createOutArgs() const
00126 {
00127 OutArgsSetup outArgs;
00128 outArgs.setSupports(OUT_ARG_f,true);
00129 outArgs.setSupports(OUT_ARG_W,true);
00130 return outArgs;
00131 }
00132
00133 void ExampleApplication1Dfem::evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const
00134 {
00135 Teuchos::RefCountPtr<const Epetra_Vector> x = inArgs.get_x();
00136 Teuchos::RefCountPtr<const Epetra_Vector> xdot = inArgs.get_x_dot();
00137 #ifdef EXAMPLEAPPLICATION_DEBUG
00138 std::cout << "ExampleApplication1Dfem::evalModel ---------------------------{" << std::endl;
00139 std::cout << "x = " << std::endl;
00140 x->Print(std::cout);
00141 std::cout << "xdot = " << std::endl;
00142 xdot->Print(std::cout);
00143 #endif // EXAMPLEAPPLICATION_DEBUG
00144 Teuchos::RefCountPtr<Epetra_Vector> f;
00145 if( (f = outArgs.get_f()).get() )
00146 {
00147 NOX::Epetra::Interface::Required::FillType flag = NOX::Epetra::Interface::Required::Residual;
00148 problemInterfacePtr_->evaluate(flag,&*x,&*xdot,0.0,0.0,&*f,NULL);
00149 #ifdef EXAMPLEAPPLICATION_DEBUG
00150 std::cout << "f = " << std::endl;
00151 f->Print(std::cout);
00152 #endif // EXAMPLEAPPLICATION_DEBUG
00153 }
00154 Teuchos::RefCountPtr<Epetra_Operator> W;
00155 if( (W = outArgs.get_W()).get() )
00156 {
00157 const double alpha = inArgs.get_alpha();
00158 const double beta = inArgs.get_beta();
00159 NOX::Epetra::Interface::Required::FillType flag = NOX::Epetra::Interface::Required::Jac;
00160
00161 Epetra_CrsMatrix& jac = Teuchos::dyn_cast<Epetra_CrsMatrix>(*W);
00162 problemInterfacePtr_->evaluate(flag,&*x,&*xdot,alpha,beta,NULL,&jac);
00163 #ifdef EXAMPLEAPPLICATION_DEBUG
00164 std::cout << "jac = " << std::endl;
00165 jac.Print(std::cout);
00166 #endif // EXAMPLEAPPLICATION_DEBUG
00167 }
00168 #ifdef EXAMPLEAPPLICATION_DEBUG
00169 std::cout << "ExampleApplication1Dfem::evalModel ---------------------------}" << std::endl;
00170 #endif // EXAMPLEAPPLICATION_DEBUG
00171 }
00172
00173 Teuchos::RefCountPtr<Epetra_Vector> ExampleApplication1Dfem::get_exact_solution( double t ) const
00174 {
00175 Epetra_Vector& x_exact = problemInterfacePtr_->getExactSoln(t);
00176 Teuchos::RefCountPtr<Epetra_Vector> x_exact_ptr = Teuchos::rcp(&x_exact,false);
00177 return(x_exact_ptr);
00178 }