|
29 | 29 | #include <aspect/heating_model/interface.h> |
30 | 30 | #include <aspect/gravity_model/interface.h> |
31 | 31 | #include <aspect/simulator/assemblers/stokes.h> |
| 32 | +#include <aspect/simulator/assemblers/stokes_anisotropic_viscosity.h> |
32 | 33 | #include <aspect/simulator_signals.h> |
33 | 34 | #include <aspect/postprocess/particles.h> |
34 | 35 | #include <aspect/introspection.h> |
@@ -79,254 +80,6 @@ namespace aspect |
79 | 80 | namespace MaterialModel |
80 | 81 | { |
81 | 82 | using namespace dealii; |
82 | | - |
83 | | - /** |
84 | | - * Additional output fields for anisotropic viscosities to be added to |
85 | | - * the MaterialModel::MaterialModelOutputs structure and filled in the |
86 | | - * MaterialModel::Interface::evaluate() function. |
87 | | - */ |
88 | | - |
89 | | - |
90 | | - |
91 | | - namespace |
92 | | - { |
93 | | - |
94 | | - template <int dim> |
95 | | - std::vector<std::string> make_AV_additional_outputs_names() |
96 | | - { |
97 | | - std::vector<std::string> names; |
98 | | - |
99 | | - for (unsigned int i = 0; i < Tensor<4,dim>::n_independent_components ; ++i) |
100 | | - { |
101 | | - TableIndices<4> indices(Tensor<4,dim>::unrolled_to_component_indices(i)); |
102 | | - names.push_back("anisotropic_viscosity"+std::to_string(indices[0]+1)+std::to_string(indices[1]+1)+std::to_string(indices[2]+1)+std::to_string(indices[3]+1)); |
103 | | - } |
104 | | - return names; |
105 | | - } |
106 | | - } |
107 | | - |
108 | | - |
109 | | - |
110 | | - template <int dim> |
111 | | - AnisotropicViscosity<dim>::AnisotropicViscosity (const unsigned int n_points) |
112 | | - : |
113 | | - NamedAdditionalMaterialOutputs<dim>(make_AV_additional_outputs_names<dim>()), |
114 | | - stress_strain_directors(n_points, dealii::identity_tensor<dim> ()) |
115 | | - {} |
116 | | - |
117 | | - |
118 | | - |
119 | | - template <int dim> |
120 | | - std::vector<double> |
121 | | - AnisotropicViscosity<dim>::get_nth_output(const unsigned int idx) const |
122 | | - { |
123 | | - std::vector<double> output(stress_strain_directors.size()); |
124 | | - for (unsigned int i = 0; i < stress_strain_directors.size() ; ++i) |
125 | | - { |
126 | | - output[i]= stress_strain_directors[i][Tensor<4,dim>::unrolled_to_component_indices(idx)]; |
127 | | - } |
128 | | - return output; |
129 | | - } |
130 | | - } |
131 | | -} |
132 | | - |
133 | | -namespace aspect |
134 | | -{ |
135 | | - namespace Assemblers |
136 | | - { |
137 | | - template <int dim> |
138 | | - void |
139 | | - StokesPreconditionerAnisotropicViscosity<dim>:: |
140 | | - execute (internal::Assembly::Scratch::ScratchBase<dim> &scratch_base, |
141 | | - internal::Assembly::CopyData::CopyDataBase<dim> &data_base) const |
142 | | - { |
143 | | - internal::Assembly::Scratch::StokesPreconditioner<dim> &scratch = dynamic_cast<internal::Assembly::Scratch::StokesPreconditioner<dim>&> (scratch_base); |
144 | | - internal::Assembly::CopyData::StokesPreconditioner<dim> &data = dynamic_cast<internal::Assembly::CopyData::StokesPreconditioner<dim>&> (data_base); |
145 | | - |
146 | | - const std::shared_ptr<const MaterialModel::AnisotropicViscosity<dim>> anisotropic_viscosity |
147 | | - = scratch.material_model_outputs.template get_additional_output_object<MaterialModel::AnisotropicViscosity<dim>>(); |
148 | | - |
149 | | - const Introspection<dim> &introspection = this->introspection(); |
150 | | - const FiniteElement<dim> &fe = this->get_fe(); |
151 | | - const unsigned int stokes_dofs_per_cell = data.local_dof_indices.size(); |
152 | | - const unsigned int n_q_points = scratch.finite_element_values.n_quadrature_points; |
153 | | - const double pressure_scaling = this->get_pressure_scaling(); |
154 | | - |
155 | | - // First loop over all dofs and find those that are in the Stokes system |
156 | | - // save the component (pressure and dim velocities) each belongs to. |
157 | | - for (unsigned int i = 0, i_stokes = 0; i_stokes < stokes_dofs_per_cell; /*increment at end of loop*/) |
158 | | - { |
159 | | - if (introspection.is_stokes_component(fe.system_to_component_index(i).first)) |
160 | | - { |
161 | | - scratch.dof_component_indices[i_stokes] = fe.system_to_component_index(i).first; |
162 | | - ++i_stokes; |
163 | | - } |
164 | | - ++i; |
165 | | - } |
166 | | - |
167 | | - // Loop over all quadrature points and assemble their contributions to |
168 | | - // the preconditioner matrix |
169 | | - for (unsigned int q = 0; q < n_q_points; ++q) |
170 | | - { |
171 | | - for (unsigned int i = 0, i_stokes = 0; i_stokes < stokes_dofs_per_cell; /*increment at end of loop*/) |
172 | | - { |
173 | | - if (introspection.is_stokes_component(fe.system_to_component_index(i).first)) |
174 | | - { |
175 | | - scratch.grads_phi_u[i_stokes] = |
176 | | - scratch.finite_element_values[introspection.extractors |
177 | | - .velocities].symmetric_gradient(i, q); |
178 | | - scratch.phi_p[i_stokes] = scratch.finite_element_values[introspection |
179 | | - .extractors.pressure].value(i, q); |
180 | | - ++i_stokes; |
181 | | - } |
182 | | - ++i; |
183 | | - } |
184 | | - |
185 | | - const double eta = scratch.material_model_outputs.viscosities[q]; |
186 | | - const double one_over_eta = 1. / eta; |
187 | | - const SymmetricTensor<4, dim> &stress_strain_director = anisotropic_viscosity->stress_strain_directors[q]; |
188 | | - const double JxW = scratch.finite_element_values.JxW(q); |
189 | | - |
190 | | - for (unsigned int i = 0; i < stokes_dofs_per_cell; ++i) |
191 | | - for (unsigned int j = 0; j < stokes_dofs_per_cell; ++j) |
192 | | - if (scratch.dof_component_indices[i] == |
193 | | - scratch.dof_component_indices[j]) |
194 | | - data.local_matrix(i, j) += (2.0 * eta * (scratch.grads_phi_u[i] |
195 | | - * stress_strain_director |
196 | | - * scratch.grads_phi_u[j]) |
197 | | - + one_over_eta * pressure_scaling |
198 | | - * pressure_scaling |
199 | | - * (scratch.phi_p[i] |
200 | | - * scratch.phi_p[j])) |
201 | | - * JxW; |
202 | | - } |
203 | | - } |
204 | | - |
205 | | - |
206 | | - |
207 | | - template <int dim> |
208 | | - void |
209 | | - StokesPreconditionerAnisotropicViscosity<dim>:: |
210 | | - create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &outputs) const |
211 | | - { |
212 | | - const unsigned int n_points = outputs.viscosities.size(); |
213 | | - |
214 | | - if (outputs.template has_additional_output_object<MaterialModel::AnisotropicViscosity<dim>>() == false) |
215 | | - { |
216 | | - outputs.additional_outputs.push_back( |
217 | | - std::make_unique<MaterialModel::AnisotropicViscosity<dim>> (n_points)); |
218 | | - } |
219 | | - } |
220 | | - |
221 | | - |
222 | | - |
223 | | - template <int dim> |
224 | | - void |
225 | | - StokesIncompressibleTermsAnisotropicViscosity<dim>:: |
226 | | - execute (internal::Assembly::Scratch::ScratchBase<dim> &scratch_base, |
227 | | - internal::Assembly::CopyData::CopyDataBase<dim> &data_base) const |
228 | | - { |
229 | | - internal::Assembly::Scratch::StokesSystem<dim> &scratch = dynamic_cast<internal::Assembly::Scratch::StokesSystem<dim>&> (scratch_base); |
230 | | - internal::Assembly::CopyData::StokesSystem<dim> &data = dynamic_cast<internal::Assembly::CopyData::StokesSystem<dim>&> (data_base); |
231 | | - |
232 | | - const std::shared_ptr<const MaterialModel::AnisotropicViscosity<dim>> anisotropic_viscosity |
233 | | - = scratch.material_model_outputs.template get_additional_output_object<MaterialModel::AnisotropicViscosity<dim>>(); |
234 | | - |
235 | | - const Introspection<dim> &introspection = this->introspection(); |
236 | | - const FiniteElement<dim> &fe = this->get_fe(); |
237 | | - const unsigned int stokes_dofs_per_cell = data.local_dof_indices.size(); |
238 | | - const unsigned int n_q_points = scratch.finite_element_values.n_quadrature_points; |
239 | | - const double pressure_scaling = this->get_pressure_scaling(); |
240 | | - |
241 | | - const std::shared_ptr<const MaterialModel::AdditionalMaterialOutputsStokesRHS<dim>> force |
242 | | - = scratch.material_model_outputs.template get_additional_output_object<MaterialModel::AdditionalMaterialOutputsStokesRHS<dim>>(); |
243 | | - |
244 | | - for (unsigned int q=0; q<n_q_points; ++q) |
245 | | - { |
246 | | - for (unsigned int i=0, i_stokes=0; i_stokes<stokes_dofs_per_cell; /*increment at end of loop*/) |
247 | | - { |
248 | | - if (introspection.is_stokes_component(fe.system_to_component_index(i).first)) |
249 | | - { |
250 | | - scratch.phi_u[i_stokes] = scratch.finite_element_values[introspection.extractors.velocities].value (i,q); |
251 | | - scratch.phi_p[i_stokes] = scratch.finite_element_values[introspection.extractors.pressure].value (i, q); |
252 | | - if (scratch.rebuild_stokes_matrix) |
253 | | - { |
254 | | - scratch.grads_phi_u[i_stokes] = scratch.finite_element_values[introspection.extractors.velocities].symmetric_gradient(i,q); |
255 | | - scratch.div_phi_u[i_stokes] = scratch.finite_element_values[introspection.extractors.velocities].divergence (i, q); |
256 | | - } |
257 | | - ++i_stokes; |
258 | | - } |
259 | | - ++i; |
260 | | - } |
261 | | - // Viscosity scalar |
262 | | - const double eta = (scratch.rebuild_stokes_matrix |
263 | | - ? |
264 | | - scratch.material_model_outputs.viscosities[q] |
265 | | - : |
266 | | - numbers::signaling_nan<double>()); |
267 | | - |
268 | | - const SymmetricTensor<4, dim> &stress_strain_director = anisotropic_viscosity->stress_strain_directors[q]; |
269 | | - |
270 | | - const Tensor<1,dim> |
271 | | - gravity = this->get_gravity_model().gravity_vector (scratch.finite_element_values.quadrature_point(q)); |
272 | | - |
273 | | - const double density = scratch.material_model_outputs.densities[q]; |
274 | | - const double JxW = scratch.finite_element_values.JxW(q); |
275 | | - |
276 | | - for (unsigned int i=0; i<stokes_dofs_per_cell; ++i) |
277 | | - { |
278 | | - data.local_rhs(i) += (density * gravity * scratch.phi_u[i]) |
279 | | - * JxW; |
280 | | - |
281 | | - if (force != nullptr) |
282 | | - data.local_rhs(i) += (force->rhs_u[q] * scratch.phi_u[i] |
283 | | - + pressure_scaling * force->rhs_p[q] * scratch.phi_p[i]) |
284 | | - * JxW; |
285 | | - |
286 | | - if (scratch.rebuild_stokes_matrix) |
287 | | - for (unsigned int j=0; j<stokes_dofs_per_cell; ++j) |
288 | | - { |
289 | | - data.local_matrix(i,j) += ( eta * 2.0 * (scratch.grads_phi_u[i] * stress_strain_director * scratch.grads_phi_u[j]) |
290 | | - // assemble \nabla p as -(p, div v): |
291 | | - - (pressure_scaling * |
292 | | - scratch.div_phi_u[i] * scratch.phi_p[j]) |
293 | | - // assemble the term -div(u) as -(div u, q). |
294 | | - // Note the negative sign to make this |
295 | | - // operator adjoint to the grad p term: |
296 | | - - (pressure_scaling * |
297 | | - scratch.phi_p[i] * scratch.div_phi_u[j])) |
298 | | - * JxW; |
299 | | - } |
300 | | - } |
301 | | - } |
302 | | - } |
303 | | - |
304 | | - |
305 | | - |
306 | | - template <int dim> |
307 | | - void |
308 | | - StokesIncompressibleTermsAnisotropicViscosity<dim>:: |
309 | | - create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &outputs) const |
310 | | - { |
311 | | - const unsigned int n_points = outputs.viscosities.size(); |
312 | | - |
313 | | - if (outputs.template has_additional_output_object<MaterialModel::AnisotropicViscosity<dim>>() == false) |
314 | | - { |
315 | | - outputs.additional_outputs.push_back( |
316 | | - std::make_unique<MaterialModel::AnisotropicViscosity<dim>> (n_points)); |
317 | | - } |
318 | | - |
319 | | - if (this->get_parameters().enable_additional_stokes_rhs |
320 | | - && outputs.template has_additional_output_object<MaterialModel::AdditionalMaterialOutputsStokesRHS<dim>>() == false) |
321 | | - { |
322 | | - outputs.additional_outputs.push_back( |
323 | | - std::make_unique<MaterialModel::AdditionalMaterialOutputsStokesRHS<dim>> (n_points)); |
324 | | - } |
325 | | - Assert(!this->get_parameters().enable_additional_stokes_rhs |
326 | | - || |
327 | | - outputs.template get_additional_output_object<MaterialModel::AdditionalMaterialOutputsStokesRHS<dim>>()->rhs_u.size() |
328 | | - == n_points, ExcInternalError()); |
329 | | - } |
330 | 83 | } |
331 | 84 |
|
332 | 85 | namespace HeatingModel |
|
0 commit comments