-
Notifications
You must be signed in to change notification settings - Fork 90
/
Albany_DistributedParameterDerivativeOp.hpp
116 lines (90 loc) · 3.72 KB
/
Albany_DistributedParameterDerivativeOp.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//*****************************************************************//
// Albany 3.0: Copyright 2016 Sandia Corporation //
// This Software is released under the BSD license detailed //
// in the file "license.txt" in the top-level Albany directory //
//*****************************************************************//
#ifndef ALBANY_DISTRIBUTED_PARAMETER_DERIVATIVE_OP_HPP
#define ALBANY_DISTRIBUTED_PARAMETER_DERIVATIVE_OP_HPP
#include "Albany_Application.hpp"
#include "Albany_ThyraTypes.hpp"
#include "Albany_DistributedParameterLibrary.hpp"
#include "Teuchos_RCP.hpp"
namespace Albany {
//! Thyra_LinearOp implementing the action of df/dp (transpose)
/*!
* This class implements the Thyra::LinearOpBase interface for
* op(df/dp)*v where op() is the identity or tranpose, f is the Albany
* residual vector, p is a distributed parameter vector, and v is a given
* vector.
*/
class DistributedParameterDerivativeOp : public Thyra_LinearOp {
public:
// Constructor
DistributedParameterDerivativeOp(
const Teuchos::RCP<Application>& app_,
const std::string& param_name_) :
app(app_),
param_name(param_name_) {}
//! Destructor
virtual ~DistributedParameterDerivativeOp() {}
//! Set values needed for apply()
void set(const double time_,
const Teuchos::RCP<const Thyra_Vector>& x_,
const Teuchos::RCP<const Thyra_Vector>& xdot_,
const Teuchos::RCP<const Thyra_Vector>& xdotdot_,
const Teuchos::RCP<Teuchos::Array<ParamVec> >& scalar_params_) {
time = time_;
xdot = xdot_;
xdotdot = xdotdot_;
x = x_;
scalar_params = scalar_params_;
}
//! Overrides Thyra::LinearOpBase purely virtual method
Teuchos::RCP<const Thyra_VectorSpace> domain() const {
return app->getDistributedParameterLibrary()->get(param_name)->vector_space();
}
//! Overrides Thyra::LinearOpBase purely virtual method
Teuchos::RCP<const Thyra_VectorSpace> range() const {
return app->getVectorSpace();
}
//@}
protected:
//! Overrides Thyra::LinearOpBase purely virtual method
bool opSupportedImpl(Thyra::EOpTransp /*M_trans*/) const {
// The underlying scalar type is not complex, and we support transpose, so we support everything.
return true;
}
//! Overrides Thyra::LinearOpBase purely virtual method
void applyImpl (const Thyra::EOpTransp M_trans,
const Thyra_MultiVector& X,
const Teuchos::Ptr<Thyra_MultiVector>& Y,
const ST /* alpha */,
const ST /* beta */) const {
bool use_transpose = (Thyra::real_trans(M_trans) == Thyra::TRANS);
app->applyGlobalDistParamDerivImpl(time, x, xdot, xdotdot,
*scalar_params,
param_name,
use_transpose,
Teuchos::rcpFromRef(X),
Teuchos::rcpFromPtr(Y));
}
//! Albany applications
Teuchos::RCP<Application> app;
//! Name of distributed parameter we are differentiating w.r.t.
std::string param_name;
//! @name Data needed for apply()
//@{
//! Current time
double time;
//! Velocity vector
Teuchos::RCP<const Thyra_Vector> xdot;
//! Acceleration vector
Teuchos::RCP<const Thyra_Vector> xdotdot;
//! Solution vector
Teuchos::RCP<const Thyra_Vector> x;
//! Scalar parameters
Teuchos::RCP<Teuchos::Array<ParamVec> > scalar_params;
//@}
}; // class DistributedParameterDerivativeOp
} // namespace Albany
#endif // ALBANY_DISTRIBUTED_PARAMETER_DERIVATIVE_OP_HPP