35 #include "libmesh/quadrature.h"
36 #include "libmesh/boundary_info.h"
51 context.get_element_fe(this->_flow_vars.u())->get_xyz();
52 context.get_element_fe(this->_flow_vars.u())->get_phi();
61 const std::vector<libMesh::Real> &JxW =
62 context.get_element_fe(this->_flow_vars.u())->get_JxW();
65 const std::vector<std::vector<libMesh::Real> >& u_phi =
66 context.get_element_fe(this->_flow_vars.u())->get_phi();
68 const std::vector<libMesh::Point>& u_qpoint =
69 context.get_element_fe(this->_flow_vars.u())->get_xyz();
72 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
75 libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.u());
76 libMesh::DenseSubMatrix<libMesh::Number> &Kuv = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.v());
77 libMesh::DenseSubMatrix<libMesh::Number> &Kvu = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.u());
78 libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.v());
80 libMesh::DenseSubMatrix<libMesh::Number> &Kus =
81 context.get_elem_jacobian(this->_flow_vars.u(),
82 this->fan_speed_var());
83 libMesh::DenseSubMatrix<libMesh::Number> &Ksu =
84 context.get_elem_jacobian(this->fan_speed_var(),
85 this->_flow_vars.u());
86 libMesh::DenseSubMatrix<libMesh::Number> &Kvs =
87 context.get_elem_jacobian(this->_flow_vars.v(),
88 this->fan_speed_var());
89 libMesh::DenseSubMatrix<libMesh::Number> &Ksv =
90 context.get_elem_jacobian(this->fan_speed_var(),
91 this->_flow_vars.v());
92 libMesh::DenseSubMatrix<libMesh::Number> &Kss =
93 context.get_elem_jacobian(this->fan_speed_var(),
94 this->fan_speed_var());
96 libMesh::DenseSubMatrix<libMesh::Number>* Kwu = NULL;
97 libMesh::DenseSubMatrix<libMesh::Number>* Kwv = NULL;
98 libMesh::DenseSubMatrix<libMesh::Number>* Kww = NULL;
99 libMesh::DenseSubMatrix<libMesh::Number>* Kuw = NULL;
100 libMesh::DenseSubMatrix<libMesh::Number>* Kvw = NULL;
102 libMesh::DenseSubMatrix<libMesh::Number>* Ksw = NULL;
103 libMesh::DenseSubMatrix<libMesh::Number>* Kws = NULL;
105 libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u());
106 libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v());
107 libMesh::DenseSubVector<libMesh::Number>* Fw = NULL;
109 libMesh::DenseSubVector<libMesh::Number> &Fs = context.get_elem_residual(this->fan_speed_var());
111 if( this->_flow_vars.dim() == 3 )
113 Kuw = &context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.w());
114 Kvw = &context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.w());
116 Kwu = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.u());
117 Kwv = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.v());
118 Kww = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.w());
119 Fw = &context.get_elem_residual(this->_flow_vars.w());
121 Ksw = &context.get_elem_jacobian(this->fan_speed_var(), this->_flow_vars.w());
122 Kws = &context.get_elem_jacobian(this->_flow_vars.w(), this->fan_speed_var());
124 Fw = &context.get_elem_residual(this->_flow_vars.w());
127 unsigned int n_qpoints = context.get_element_qrule().n_points();
129 for (
unsigned int qp=0; qp != n_qpoints; qp++)
132 libMesh::Number u, v, s;
133 u = context.interior_value(this->_flow_vars.u(), qp);
134 v = context.interior_value(this->_flow_vars.v(), qp);
135 s = context.interior_value(this->fan_speed_var(), qp);
137 libMesh::NumberVectorValue U(u,v);
138 if (this->_flow_vars.dim() == 3)
139 U(2) = context.interior_value(this->_flow_vars.w(), qp);
141 libMesh::NumberVectorValue U_B_1;
142 libMesh::NumberVectorValue F;
143 libMesh::NumberTensorValue dFdU;
144 libMesh::NumberTensorValue* dFdU_ptr =
145 compute_jacobian ? &dFdU : NULL;
146 libMesh::NumberVectorValue dFds;
147 libMesh::NumberVectorValue* dFds_ptr =
148 compute_jacobian ? &dFds : NULL;
149 if (!this->compute_force(u_qpoint[qp], context.time, U, s,
150 U_B_1, F, dFdU_ptr, dFds_ptr))
153 libMesh::Real jac = JxW[qp];
161 Fs(0) -= U_B_1 * F * jac;
163 if (compute_jacobian)
165 Kss(0,0) -= U_B_1 * dFds * jac;
167 for (
unsigned int j=0; j != n_u_dofs; j++)
169 libMesh::Real jac_j = JxW[qp] * u_phi[j][qp];
171 for (
unsigned int d=0; d != 3; ++d)
173 Ksu(0,j) -= jac_j * U_B_1(d) * dFdU(d,0);
174 Ksv(0,j) -= jac_j * U_B_1(d) * dFdU(d,1);
177 if (this->_flow_vars.dim() == 3)
179 for (
unsigned int d=0; d != 3; ++d)
180 (*Ksw)(0,j) -= jac_j * U_B_1(d) * dFdU(d,2);
186 for (
unsigned int i=0; i != n_u_dofs; i++)
188 const libMesh::Number jac_i = jac * u_phi[i][qp];
193 if( this->_flow_vars.dim() == 3 )
194 (*Fw)(i) += F(2)*jac_i;
196 if( compute_jacobian )
198 Kus(i,0) += dFds(0) * jac_i;
199 Kvs(i,0) += dFds(1) * jac_i;
200 if( this->_flow_vars.dim() == 3 )
201 (*Kws)(i,0) += dFds(2) * jac_i;
203 for (
unsigned int j=0; j != n_u_dofs; j++)
205 const libMesh::Number jac_ij = jac_i * u_phi[j][qp];
206 Kuu(i,j) += jac_ij * dFdU(0,0);
207 Kuv(i,j) += jac_ij * dFdU(0,1);
208 Kvu(i,j) += jac_ij * dFdU(1,0);
209 Kvv(i,j) += jac_ij * dFdU(1,1);
211 if( this->_flow_vars.dim() == 3 )
213 (*Kuw)(i,j) += jac_ij * dFdU(0,2);
214 (*Kvw)(i,j) += jac_ij * dFdU(1,2);
215 (*Kwu)(i,j) += jac_ij * dFdU(2,0);
216 (*Kwv)(i,j) += jac_ij * dFdU(2,1);
217 (*Kww)(i,j) += jac_ij * dFdU(2,2);
231 libMesh::DenseSubMatrix<libMesh::Number> &Kss =
232 context.get_elem_jacobian(this->fan_speed_var(), this->fan_speed_var());
234 libMesh::DenseSubVector<libMesh::Number> &Fs =
235 context.get_elem_residual(this->fan_speed_var());
237 const std::vector<libMesh::dof_id_type>& dof_indices =
238 context.get_dof_indices(this->fan_speed_var());
240 const libMesh::Number fan_speed =
241 context.get_system().current_solution(dof_indices[0]);
243 const libMesh::Number output_torque =
244 this->torque_function(libMesh::Point(0), fan_speed);
246 Fs(0) += output_torque;
248 if (compute_jacobian)
251 const libMesh::Number epsilon = 1e-6;
252 const libMesh::Number output_torque_deriv =
253 (this->torque_function(libMesh::Point(0), fan_speed+epsilon) -
254 this->torque_function(libMesh::Point(0), fan_speed-epsilon)) / (2*epsilon);
256 Kss(0,0) += output_torque_deriv * context.get_elem_solution_derivative();
268 libMesh::DenseSubMatrix<libMesh::Number> &Kss =
269 context.get_elem_jacobian(this->fan_speed_var(), this->fan_speed_var());
271 libMesh::DenseSubVector<libMesh::Number> &Fs =
272 context.get_elem_residual(this->fan_speed_var());
274 const libMesh::DenseSubVector<libMesh::Number> &Us =
275 context.get_elem_solution_rate(this->fan_speed_var());
277 const libMesh::Number& fan_speed = Us(0);
279 Fs(0) -= this->moment_of_inertia * fan_speed;
281 if (compute_jacobian)
283 Kss(0,0) -= this->moment_of_inertia * context.get_elem_solution_rate_derivative();
GRINS::ICHandlingBase * _ic_handler
Base class for reading and handling initial conditions for physics classes.
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context)
Time dependent part(s) of physics for element interiors.
INSTANTIATE_INC_NS_SUBCLASS(AveragedTurbine)
virtual void nonlocal_time_derivative(bool compute_jacobian, AssemblyContext &context)
Time dependent part(s) of physics for scalar variables.
virtual void nonlocal_mass_residual(bool compute_jacobian, AssemblyContext &context)
Mass matrix part(s) for scalar variables.
virtual void init_context(AssemblyContext &context)
Initialize context for added physics variables.