9 #ifndef TEMPUS_TEST_HARMONIC_OSCILLATOR_MODEL_IMPL_HPP
10 #define TEMPUS_TEST_HARMONIC_OSCILLATOR_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_VectorStdOps.hpp"
24 namespace Tempus_Test {
26 template<
class Scalar>
29 out_(Teuchos::VerboseObjectBase::getDefaultOStream())
33 *
out_ <<
"\n\nDamping coeff c = " <<
c_ <<
"\n";
34 *
out_ <<
"Forcing coeff f = " <<
f_ <<
"\n";
35 *
out_ <<
"x coeff k = " <<
k_ <<
"\n";
36 *
out_ <<
"Mass coeff m = " <<
m_ <<
"\n";
46 Thyra::put_scalar(0.0, x_vec_.ptr());
48 Thyra::put_scalar(1.0, x_dot_vec_.ptr());
55 if (use_accel_IC ==
true) {
56 Thyra::put_scalar(-2.0, x_dot_dot_vec_.ptr());
61 Thyra::put_scalar(7.0, x_dot_dot_vec_.ptr());
71 template<
class Scalar>
78 "Error, setupInOutArgs_ must be called first!\n");
81 inArgs.
set_t(exact_t);
87 exact_x_view[0] = t*(1.0+0.5*f_*t);
89 exact_x_view[0] = (c_-f_)/(c_*c_)*(1.0-exp(-c_*t))
93 exact_x_view[0] = 1.0/sqrt(k_)*sin(sqrt(k_)*t) + f_/k_*(1.0-cos(sqrt(k_)*t));
96 inArgs.
set_x(exact_x);
102 exact_x_dot_view[0] = 1.0+f_*t;
104 exact_x_dot_view[0] = (c_-f_)/c_*exp(-c_*t)+f_/c_;
107 exact_x_dot_view[0] = cos(sqrt(k_)*t) + f_/sqrt(k_)*sin(sqrt(k_)*t);
116 exact_x_dot_dot_view[0] = f_;
118 exact_x_dot_dot_view[0] = (f_-c_)*exp(-c_*t);
121 exact_x_dot_dot_view[0] = f_*cos(sqrt(k_)*t) - sqrt(k_)*sin(sqrt(k_)*t);
128 template<
class Scalar>
137 template<
class Scalar>
146 template<
class Scalar>
152 "Error, setupInOutArgs_ must be called first!\n");
153 return nominalValues_;
157 template<
class Scalar>
167 matrix_view(0,0) = 1.0;
169 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix );
174 template<
class Scalar>
184 template<
class Scalar>
190 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
195 template<
class Scalar>
208 template<
class Scalar>
218 template<
class Scalar>
229 "Error, setupInOutArgs_ must be called first!\n");
235 "\n ERROR: HarmonicOscillatorModel requires x as InArgs.\n");
239 auto myVecLength = x_in_view.
subDim();
252 Scalar neg_sign = 1.0;
257 if (f_out != Teuchos::null) {
259 for (
int i=0; i<myVecLength; i++) {
262 if (x_dotdot_in != Teuchos::null) {
264 for (
int i=0; i<myVecLength; i++) {
265 f_out_view[i] = x_dotdot_in_view[i] - f_out_view[i];
268 if (x_dot_in != Teuchos::null) {
270 for (
int i=0; i<myVecLength; i++) {
271 f_out_view[i] += neg_sign*c_*x_dot_in_view[i];
274 if (x_in != Teuchos::null) {
275 for (
int i=0; i<myVecLength; i++) {
276 f_out_view[i] += neg_sign*k_*x_in_view[i];
282 if (W_out != Teuchos::null) {
287 "\n ERROR: omega = 0 in HarmonicOscillatorModel!\n");
289 matrix_view(0,0) = omega;
290 if (x_dot_in != Teuchos::null) {
291 matrix_view(0,0) += neg_sign*c_*alpha;
293 if (x_in != Teuchos::null) {
294 matrix_view(0,0) += neg_sign*k_*beta;
300 if (g_out != Teuchos::null) {
302 g_out_view[0] = Thyra::sum(*x_in)/vecLength_;
306 template<
class Scalar>
312 "\n Error! HarmonicOscillatorModel::get_p_space() is not supported!\n");
313 return Teuchos::null;
316 template<
class Scalar>
322 "\n Error! HarmonicOscillatorModel::get_p_names() is not supported!\n");
323 return Teuchos::null;
326 template<
class Scalar>
332 "\n Error! HarmonicOscillatorModel::get_g_space() only " <<
333 " supports 1 parameter vector. Supplied index l = " <<
340 template<
class Scalar>
345 if (isInitialized_)
return;
351 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x);
352 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot);
353 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot_dot);
354 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_t);
355 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_W_x_dot_dot_coeff);
356 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_alpha);
357 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_beta);
365 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_f);
366 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_W_op);
374 nominalValues_ = inArgs_;
375 nominalValues_.set_t(0.0);
376 nominalValues_.set_x(x_vec_);
377 nominalValues_.set_x_dot(x_dot_vec_);
378 nominalValues_.set_x_dot_dot(x_dot_dot_vec_);
380 isInitialized_ =
true;
384 template<
class Scalar>
393 if (paramList != Teuchos::null) tmpPL = paramList;
395 this->setMyParamList(tmpPL);
397 c_ = get<Scalar>(*pl,
"Damping coeff c");
398 f_ = get<Scalar>(*pl,
"Forcing coeff f");
399 k_ = get<Scalar>(*pl,
"x coeff k");
400 m_ = get<Scalar>(*pl,
"Mass coeff m");
403 "Error: invalid value of Mass coeff m = " << m_ <<
"! Mass coeff m must be > 0.\n");
407 "Error: invalid value of x coeff k = " << k_ <<
"! x coeff k must be >= 0.\n");
409 if ((k_ > 0.0) && (c_ != 0.0)) {
411 "Error: HarmonicOscillator model only supports x coeff k > 0 when Damping coeff c = 0. You have "
412 <<
"specified x coeff k = " << k_ <<
" and Damping coeff c = " << c_ <<
".\n");
416 template<
class Scalar>
425 Teuchos::setDoubleParameter(
426 "Damping coeff c", 0.0,
"Damping coefficient in model", &*pl);
427 Teuchos::setDoubleParameter(
428 "Forcing coeff f", -1.0,
"Forcing coefficient in model", &*pl);
429 Teuchos::setDoubleParameter(
430 "x coeff k", 0.0,
"x coefficient in model", &*pl);
431 Teuchos::setDoubleParameter(
432 "Mass coeff m", 1.0,
"Mass coefficient in model", &*pl);
438 #endif // TEMPUS_TEST_HARMONIC_OSCILLATOR_MODEL_IMPL_HPP
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
bool is_null(const boost::shared_ptr< T > &p)
void set_x_dot_dot(const RCP< const VectorBase< Scalar > > &x_dot_dot)
RCP< const VectorBase< Scalar > > get_x_dot() const
void setModelEvalDescription(const std::string &modelEvalDescription)
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_dot_vec_
void set_Np_Ng(int Np, int Ng)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > g_space_
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Evaluation< VectorBase< Scalar > > get_g(int j) const
Evaluation< VectorBase< Scalar > > get_f() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSolution(double t) const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
void setSupports(EInArgsMembers arg, bool supports=true)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
void set_x(const RCP< const VectorBase< Scalar > > &x)
Teuchos::RCP< Teuchos::FancyOStream > out_
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_dot_dot_vec_
Teuchos_Ordinal subDim() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Scalar get_W_x_dot_dot_coeff() const
void set_x_dot(const RCP< const VectorBase< Scalar > > &x_dot)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > x_space_
void setSupports(EOutArgsMembers arg, bool supports=true)
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
HarmonicOscillatorModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null, const bool use_accel_IC=false)
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_vec_
RCP< const VectorBase< Scalar > > get_x_dot_dot() const
void setupInOutArgs_() const
void setModelEvalDescription(const std::string &modelEvalDescription)
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const