9 #ifndef TEMPUS_TEST_STEADY_QUADRATIC_MODEL_IMPL_HPP
10 #define TEMPUS_TEST_STEADY_QUADRATIC_MODEL_IMPL_HPP
12 #include "Teuchos_StandardParameterEntryValidators.hpp"
14 #include "Thyra_DefaultSpmdVectorSpace.hpp"
15 #include "Thyra_DetachedVectorView.hpp"
16 #include "Thyra_DetachedMultiVectorView.hpp"
17 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
18 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
19 #include "Thyra_DefaultLinearOpSource.hpp"
20 #include "Thyra_MultiVectorStdOps.hpp"
21 #include "Thyra_VectorStdOps.hpp"
22 #include "Thyra_DefaultMultiVectorProductVector.hpp"
27 namespace Tempus_Test {
29 template<
class Scalar>
33 isInitialized_ =
false;
39 useDfDpAsTangent_ =
false;
43 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
44 f_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
46 p_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(np_);
47 g_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(ng_);
49 setParameterList(pList_);
52 DxDp_space_ = Thyra::multiVectorProductVectorSpace(x_space_, np_);
55 template<
class Scalar>
65 template<
class Scalar>
75 template<
class Scalar>
84 template<
class Scalar>
93 template<
class Scalar>
99 "Error, setupInOutArgs_ must be called first!\n");
100 return nominalValues_;
104 template<
class Scalar>
126 V_V(multivec->col(0).
ptr(),*vec);
130 Thyra::linearOpWithSolve<Scalar>(
137 template<
class Scalar>
143 Thyra::createMembers(x_space_, dim_);
148 template<
class Scalar>
154 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
159 template<
class Scalar>
172 template<
class Scalar>
182 template<
class Scalar>
194 using Teuchos::rcp_dynamic_cast;
196 "Error, setupInOutArgs_ must be called first!\n");
203 if (p_in != Teuchos::null) {
209 if (inArgs.
get_p(1) != Teuchos::null)
211 rcp_dynamic_cast<const DMVPV>(inArgs.
get_p(1))->getMultiVector();
212 if (inArgs.
get_p(2) != Teuchos::null)
214 rcp_dynamic_cast<const DMVPV>(inArgs.
get_p(2))->getMultiVector();
229 f_out_view[0] = x_in_view[0]*x_in_view[0] - b*b;
235 matrix_view(0,0) = beta*2.0*x_in_view[0];
239 DfDp_out_view(0,0) = -2.0*b;
242 if (useDfDpAsTangent_ && !
is_null(DxDp_in)) {
244 DfDp_out_view(0,0) += 2.0*x_in_view[0]*DxDp(0,0);
251 x_dot_in = inArgs.
get_x_dot().assert_not_null();
256 f_out_view[0] = x_dot_in_view[0] - (x_in_view[0]*x_in_view[0] - b*b);
262 matrix_view(0,0) = alpha - beta*2.0*x_in_view[0];
266 DfDp_out_view(0,0) = 2.0*b;
269 if (useDfDpAsTangent_ && !
is_null(DxdotDp_in)) {
271 DfDp_out_view(0,0) += DxdotDp(0,0);
273 if (useDfDpAsTangent_ && !
is_null(DxDp_in)) {
275 DfDp_out_view(0,0) += -2.0*x_in_view[0]*DxDp(0,0);
282 if (g_out != Teuchos::null)
283 Thyra::assign(g_out.
ptr(), *x_in);
286 outArgs.
get_DgDp(0,0).getMultiVector();
287 if (DgDp_out != Teuchos::null)
288 Thyra::assign(DgDp_out.ptr(), Scalar(0.0));
291 outArgs.
get_DgDx(0).getMultiVector();
292 if (DgDx_out != Teuchos::null) {
294 DgDx_out_view(0,0) = 1.0;
298 template<
class Scalar>
306 else if (l == 1 || l == 2)
308 return Teuchos::null;
311 template<
class Scalar>
320 p_strings->push_back(
"Model Coefficient: b");
323 p_strings->push_back(
"DxDp");
325 p_strings->push_back(
"Dx_dotDp");
329 template<
class Scalar>
340 template<
class Scalar>
345 if (isInitialized_) {
353 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_t );
354 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x );
355 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_beta );
356 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x_dot );
357 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_alpha );
366 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_f );
367 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_W_op );
369 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DfDp,0,
370 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM );
371 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DgDx,0,
372 Thyra::ModelEvaluatorBase::DERIV_MV_GRADIENT_FORM );
373 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DgDp,0,0,
374 Thyra::ModelEvaluatorBase::DERIV_MV_GRADIENT_FORM );
379 nominalValues_ = inArgs_;
380 nominalValues_.set_t(0.0);
386 nominalValues_.set_x(x_ic);
392 nominalValues_.set_p(0,p_ic);
395 createMember(x_space_);
398 x_dot_ic_view[0] = 0.0;
400 nominalValues_.set_x_dot(x_dot_ic);
402 isInitialized_ =
true;
406 template<
class Scalar>
415 if (paramList != Teuchos::null) tmpPL = paramList;
417 this->setMyParamList(tmpPL);
419 useDfDpAsTangent_ = get<bool>(*pl,
"Use DfDp as Tangent");
420 b_ = get<Scalar>(*pl,
"Coeff b");
421 isInitialized_ =
false;
425 template<
class Scalar>
433 pl->
set(
"Use DfDp as Tangent",
false);
434 Teuchos::setDoubleParameter(
435 "Coeff b", 1.0,
"Coefficient b in model", &*pl);
442 #endif // TEMPUS_TEST_STEADY_QUADRATIC_MODEL_IMPL_HPP
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
bool is_null(const boost::shared_ptr< T > &p)
Scalar getSteadyStateSolution() const
Derivative< Scalar > get_DfDp(int l) const
RCP< const VectorBase< Scalar > > get_x_dot() const
void setModelEvalDescription(const std::string &modelEvalDescription)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void set_Np_Ng(int Np, int Ng)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Evaluation< VectorBase< Scalar > > get_g(int j) const
Evaluation< VectorBase< Scalar > > get_f() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Derivative< Scalar > get_DgDp(int j, int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
void setSupports(EInArgsMembers arg, bool supports=true)
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
void setSupports(EOutArgsMembers arg, bool supports=true)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
void setModelEvalDescription(const std::string &modelEvalDescription)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
void setupInOutArgs_() const
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
SteadyQuadraticModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
RCP< const VectorBase< Scalar > > get_p(int l) const
RCP< MultiVectorBase< Scalar > > getMultiVector() const
Derivative< Scalar > get_DgDx(int j) const
Scalar getSteadyStateSolutionSensitivity() const