18 const std::vector<double> &viscosity_for_stabilization_vector =
22 const auto &JxW_vec = scratch_data.
JxW;
23 const unsigned int n_q_points = scratch_data.
n_q_points;
24 const unsigned int n_dofs = scratch_data.
n_dofs;
33 std::vector<double> time_steps_vector =
35 const double dt = time_steps_vector[0];
36 const double sdt = 1. / dt;
40 RequiresConstantDensity(
41 "GLSNavierStokesCahnHilliardAssemblerCore<dim>::assemble_matrix"));
44 for (
unsigned int q = 0; q < n_q_points; ++q)
48 const Tensor<2, dim> velocity_gradient =
50 const Tensor<1, dim> velocity_laplacian =
52 const Tensor<3, dim> &velocity_hessian =
57 Tensor<1, dim> grad_div_velocity;
58 for (
int d = 0; d < dim; ++d)
60 for (
int k = 0; k < dim; ++k)
65 grad_div_velocity[d] += velocity_hessian[k][d][k];
69 const Tensor<1, dim> phase_order_gradient =
71 const double potential_value =
75 Tensor<1, dim> force = scratch_data.
force[q];
77 const Tensor<1, dim> pressure_gradient =
82 const double u_mag = std::max(
velocity.norm(), 1e-12);
85 const double JxW = JxW_vec[q];
88 double density_eq = scratch_data.
density[q];
99 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h) :
101 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h, sdt);
104 auto strong_residual =
105 density_eq * velocity_gradient *
velocity + pressure_gradient -
106 dynamic_viscosity_eq * velocity_laplacian -
107 dynamic_viscosity_eq * grad_div_velocity - density_eq * force -
108 potential_value * phase_order_gradient + strong_residual_vec[q];
110 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
111 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
114 const double pressure_scaling_factor =
119 for (
unsigned int j = 0; j < n_dofs; ++j)
121 const auto &phi_u_j = scratch_data.
phi_u[q][j];
122 const auto &grad_phi_u_j = scratch_data.
grad_phi_u[q][j];
125 const auto &grad_phi_p_j =
126 scratch_data.
grad_phi_p[q][j] * pressure_scaling_factor;
128 strong_jacobian_vec[q][j] +=
129 (density_eq * velocity_gradient * phi_u_j +
130 density_eq * grad_phi_u_j *
velocity + grad_phi_p_j -
131 dynamic_viscosity_eq * laplacian_phi_u_j);
134 grad_phi_u_j_x_velocity[j] = grad_phi_u_j *
velocity;
135 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
138 for (
unsigned int i = 0; i < n_dofs; ++i)
140 const auto &phi_u_i = scratch_data.
phi_u[q][i];
141 const auto &grad_phi_u_i = scratch_data.
grad_phi_u[q][i];
142 const auto &div_phi_u_i = scratch_data.
div_phi_u[q][i];
143 const auto &phi_p_i = scratch_data.
phi_p[q][i];
144 const auto &grad_phi_p_i = scratch_data.
grad_phi_p[q][i];
147 const auto grad_phi_u_i_x_velocity = grad_phi_u_i *
velocity;
148 const auto strong_residual_x_grad_phi_u_i =
149 strong_residual * grad_phi_u_i;
151 for (
unsigned int j = 0; j < n_dofs; ++j)
153 const auto &phi_u_j = scratch_data.
phi_u[q][j];
154 const auto &grad_phi_u_j = scratch_data.
grad_phi_u[q][j];
155 const auto &div_phi_u_j = scratch_data.
div_phi_u[q][j];
156 const auto &shear_rate_j = grad_phi_u_j + transpose(grad_phi_u_j);
158 const auto &phi_p_j =
159 scratch_data.
phi_p[q][j] * pressure_scaling_factor;
161 const auto &strong_jac = strong_jacobian_vec[q][j];
163 double local_matrix_ij =
165 dynamic_viscosity_eq *
166 scalar_product(shear_rate_j, grad_phi_u_i) +
167 density_eq * velocity_gradient_x_phi_u_j[j] * phi_u_i +
168 density_eq * grad_phi_u_j_x_velocity[j] * phi_u_i -
169 div_phi_u_i * phi_p_j +
171 phi_p_i * div_phi_u_j;
174 local_matrix_ij += tau / density_eq * (strong_jac * grad_phi_p_i);
178 tau * (strong_jac * grad_phi_u_i_x_velocity +
179 strong_residual_x_grad_phi_u_i * phi_u_j);
182 local_matrix_ij *= JxW;
183 local_matrix(i, j) += local_matrix_ij;
196 const std::vector<double> &viscosity_for_stabilization_vector =
202 const auto &JxW_vec = scratch_data.
JxW;
203 const unsigned int n_q_points = scratch_data.
n_q_points;
204 const unsigned int n_dofs = scratch_data.
n_dofs;
211 std::vector<double> time_steps_vector =
213 const double dt = time_steps_vector[0];
214 const double sdt = 1. / dt;
217 RequiresConstantDensity(
218 "GLSNavierStokesCahnHilliardAssemblerCore<dim>::assemble_rhs"));
221 for (
unsigned int q = 0; q < n_q_points; ++q)
224 const Tensor<1, dim> phase_order_gradient =
226 const double potential_value =
233 const Tensor<2, dim> velocity_gradient =
235 const Tensor<1, dim> velocity_laplacian =
237 const Tensor<3, dim> &velocity_hessian =
240 Tensor<1, dim> grad_div_velocity;
241 for (
int d = 0; d < dim; ++d)
243 for (
int k = 0; k < dim; ++k)
248 grad_div_velocity[d] += velocity_hessian[k][d][k];
254 velocity_gradient + transpose(velocity_gradient);
258 const Tensor<1, dim> pressure_gradient =
262 Tensor<1, dim> force = scratch_data.
force[q];
266 const double u_mag = std::max(
velocity.norm(), 1e-12);
269 const double JxW = JxW_vec[q];
272 double density_eq = scratch_data.
density[q];
283 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h) :
285 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h, sdt);
289 auto strong_residual =
290 density_eq * velocity_gradient *
velocity + pressure_gradient -
291 dynamic_viscosity_eq * velocity_laplacian -
292 dynamic_viscosity_eq * grad_div_velocity - density_eq * force -
293 potential_value * phase_order_gradient + strong_residual_vec[q];
296 for (
unsigned int i = 0; i < n_dofs; ++i)
298 const auto phi_u_i = scratch_data.
phi_u[q][i];
299 const auto grad_phi_u_i = scratch_data.
grad_phi_u[q][i];
300 const auto phi_p_i = scratch_data.
phi_p[q][i];
301 const auto grad_phi_p_i = scratch_data.
grad_phi_p[q][i];
302 const auto div_phi_u_i = scratch_data.
div_phi_u[q][i];
309 (-dynamic_viscosity_eq * scalar_product(
shear_rate, grad_phi_u_i) -
310 density_eq * velocity_gradient *
velocity * phi_u_i +
312 density_eq * force * phi_u_i
314 - velocity_divergence * phi_p_i
316 + potential_value * phase_order_gradient * phi_u_i) *
321 -tau / density_eq * (strong_residual * grad_phi_p_i) * JxW;
325 -tau * (strong_residual * (grad_phi_u_i *
velocity)) * JxW;
342 const auto &JxW = scratch_data.
JxW;
343 const unsigned int n_q_points = scratch_data.
n_q_points;
344 const unsigned int n_dofs = scratch_data.
n_dofs;
354 const Vector<double> &bdf_coefs =
356 std::vector<Tensor<1, dim>>
velocity(1 +
360 for (
unsigned int q = 0; q < n_q_points; ++q)
366 const double density = scratch_data.
density[q];
371 strong_residual[q] += density * bdf_coefs[p] *
velocity[p];
374 for (
unsigned int j = 0; j < n_dofs; ++j)
376 strong_jacobian[q][j] +=
377 density * bdf_coefs[0] * scratch_data.
phi_u[q][j];
380 for (
unsigned int i = 0; i < n_dofs; ++i)
382 const Tensor<1, dim> &phi_u_i = scratch_data.
phi_u[q][i];
383 for (
unsigned int j = 0; j < n_dofs; ++j)
385 const Tensor<1, dim> &phi_u_j = scratch_data.
phi_u[q][j];
387 local_matrix(i, j) +=
388 phi_u_j * phi_u_i * density * bdf_coefs[0] * JxW[q];