270 * <a name=
"Distributed_Moving_Laser_Heating.cc-Includefiles"></a>
271 * <h3>Include files</h3>
275 * All the include files have already been discussed in previous tutorials.
278 *
#include <deal.II/dofs/dof_handler.h>
279 *
#include <deal.II/dofs/dof_renumbering.h>
280 *
#include <deal.II/grid/grid_generator.h>
281 *
#include <deal.II/grid/tria_accessor.h>
282 *
#include <deal.II/grid/tria_iterator.h>
283 *
#include <deal.II/dofs/dof_accessor.h>
284 *
#include <deal.II/fe/fe_q.h>
285 *
#include <deal.II/dofs/dof_tools.h>
286 *
#include <deal.II/fe/fe_values.h>
287 *
#include <deal.II/base/quadrature_lib.h>
288 *
#include <deal.II/base/function.h>
289 *
#include <deal.II/numerics/vector_tools.h>
290 *
#include <deal.II/numerics/matrix_tools.h>
291 *
#include <deal.II/lac/vector.h>
292 *
#include <deal.II/lac/full_matrix.h>
293 *
#include <deal.II/lac/dynamic_sparsity_pattern.h>
295 *
#include <deal.II/grid/grid_in.h>
296 *
#include <deal.II/grid/grid_tools.h>
297 *
#include <deal.II/lac/trilinos_vector.h>
298 *
#include <deal.II/lac/trilinos_sparse_matrix.h>
299 *
#include <deal.II/lac/trilinos_solver.h>
300 *
#include <deal.II/lac/trilinos_precondition.h>
302 *
#include <deal.II/lac/sparsity_tools.h>
303 *
#include <deal.II/lac/generic_linear_algebra.h>
305 *
#include <deal.II/base/conditional_ostream.h>
306 *
#include <deal.II/base/utilities.h>
307 *
#include <deal.II/base/index_set.h>
308 *
#include <deal.II/distributed/tria.h>
310 *
#include <deal.II/numerics/data_out.h>
312 *
#include <iostream>
315 *
#include <deal.II/base/logstream.h>
316 *
#include <deal.II/lac/affine_constraints.h>
317 *
#include <deal.II/base/timer.h>
324 *
#include <deal.II/numerics/error_estimator.h>
325 *
#include <deal.II/distributed/grid_refinement.h>
329 * remember to use the
namespace dealii before
330 * defining a
class that is inheritaged from
Function<dim>
337 * In
general, it is more clear to separate boundary and
initial condictions,
338 * as well as the right hand side function from a file holding all the things.
339 * To
do so, in
this work, the globalPara.h file defines physical constants,
340 * laser parameters, and heat characteristics of materials involved. Boundary
341 * and
initial conditions are defined in boundaryInit.h. The rightHandSide.h
342 * defines the heat source, which in
this work is a moving Gaussian beam.
348 *
#ifndef GLOBAL_PARA
349 *
#define GLOBAL_PARA
350 *
#include
"./globalPara.h"
351 *
#include
"./boundaryInit.h"
352 *
#include
"./rightHandSide.h"
357 * Now the
main class is defined as following
370 *
void setup_system();
372 *
void assemble_system_matrix_init (
double time_step);
373 *
void dynamic_assemble_rhs_T (
double time,
double time_step);
377 *
void refine_mesh();
378 *
void output_results (
int output_num)
const;
405 *
for storing right
matrix
412 * System_rhs, only locally owned cells
420 * Old Solutions with ghost cells,
for output
427 * Old Solutions only with locally owned cells
434 * New Solutions only with locally owned cells
441 * Dynamic assembling of the righthandside terms
465 *
LaserHeating<dim>::LaserHeating ()
467 *
mpi_communicator (MPI_COMM_WORLD),
468 *
triangulation (mpi_communicator),
470 *
dof_handler (triangulation),
482 *
LaserHeating<dim>::~LaserHeating ()
484 *
dof_handler.clear();
490 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingmake_grid"></a>
491 * <h4>LaserHeating::make_grid</h4>
492 * make grid by importing msh file, and rescale
496 *
void LaserHeating<dim>::make_grid ()
502 *
std::ifstream input_file (
"geometry.msh");
503 *
grid_in.read_msh (input_file);
506 *
pcout <<
" Number of active cells: "
507 *
<< triangulation.n_global_active_cells()
509 *
<<
" Total number of cells: "
510 *
<< triangulation.n_cells()
517 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingsetup_system"></a>
518 * <h4>LaserHeating::setup_system</h4>
523 *
void LaserHeating<dim>::setup_system ()
528 *
dof_handler.distribute_dofs (fe);
530 *
pcout <<
" Number of degrees of freedom: "
531 *
<< dof_handler.n_dofs()
534 *
locally_owned_dofs = dof_handler.locally_owned_dofs();
539 * we want to output solution, so here should have ghost cells
542 *
old_solution_T.reinit (locally_owned_dofs,locally_relevant_dofs,mpi_communicator);
546 * locally owned cells
549 *
old_solution_T_cal.reinit (locally_owned_dofs,mpi_communicator);
550 *
new_solution_T.reinit (locally_owned_dofs,mpi_communicator);
551 *
dynamic_rhs_T.reinit (locally_owned_dofs,mpi_communicator);
552 *
system_rhs_T.reinit (locally_owned_dofs,mpi_communicator);
554 *
constraints_T.clear();
555 *
constraints_T.reinit (locally_relevant_dofs);
557 *
constraints_T.close();
564 *
locally_owned_dofs,
566 *
locally_relevant_dofs);
568 *
left_system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
569 *
right_system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
570 *
system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
578 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingassemble_system_matrix"></a>
579 * <h4>LaserHeating::assemble_system_matrix</h4>
586 *
void LaserHeating<dim>::assemble_system_matrix_init (
double time_step)
594 *
const InitialValues<dim> initial_value_func_T;
597 *
const RhoC<dim> rho_C_fun_T;
598 *
const K_T<dim> k_fun_T;
605 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
606 *
const unsigned int n_q_points = quadrature_formula.size();
616 *
std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
618 *
system_matrix_T = 0;
619 *
left_system_matrix_T = 0;
620 *
right_system_matrix_T = 0;
624 *
for (
const auto &cell : dof_handler.active_cell_iterators())
625 *
if(cell->is_locally_owned())
628 *
fe_values.
reinit (cell);
629 *
local_init_matrix = 0;
631 *
local_rho_c_T_matrix = 0;
632 *
local_k_T_matrix = 0;
634 *
local_init_T_rhs = 0;
636 *
for (
unsigned int q=0; q<n_q_points; ++q)
637 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
639 *
const Tensor<1,dim> div_phi_i_u = fe_values.shape_grad (i,q);
640 *
const double phi_i_u = fe_values.shape_value (i,q);
642 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
645 *
const Tensor<1,dim> div_phi_j_u = fe_values.shape_grad(j,q);
646 *
const double phi_j_u = fe_values.shape_value (j,q);
648 *
local_init_matrix(i,j) += (phi_i_u *
650 *
fe_values.JxW (q));
652 *
local_rho_c_T_matrix(i,j) += (rho_C_fun_T.value(fe_values.quadrature_point(q)) *
657 *
time_step * (theta) *
658 *
(k_fun_T.value(fe_values.quadrature_point(q)) *
661 *
fe_values.JxW (q));
663 *
local_k_T_matrix(i,j) += (rho_C_fun_T.value(fe_values.quadrature_point(q)) *
668 *
time_step * (1.0-theta) *
669 *
(k_fun_T.value(fe_values.quadrature_point(q)) *
672 *
fe_values.JxW (q));
676 *
local_init_T_rhs(i) += (phi_i_u *
677 *
initial_value_func_T.value (fe_values.quadrature_point (q)) *
678 *
fe_values.JxW (q));
682 *
cell->get_dof_indices (local_dof_indices);
689 *
constraints_T.distribute_local_to_global(local_init_matrix,
698 * store M + dt*
theta*
A as the left_system_matrix
704 *
constraints_T.distribute_local_to_global(local_rho_c_T_matrix,
706 *
left_system_matrix_T);
710 * store M - dt*(1-
theta)*A as the right_system_matrix
713 *
constraints_T.distribute_local_to_global(local_k_T_matrix,
715 *
right_system_matrix_T);
731 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingdynamic_assemble_rhs_T"></a>
732 * <h4>LaserHeating::dynamic_assemble_rhs_T</h4>
733 * The right hand side is assembled each time during running, which is necessary as
734 * the laser source is moving. To separate the heat source and the right hand
735 * side assembling, the right hand side function is defined as RightHandside<dim>.
739 *
void LaserHeating<dim>::dynamic_assemble_rhs_T (
double time,
double time_step)
746 *
RightHandside<dim> rhs_func_T_1;
747 *
rhs_func_T_1.set_time(time);
749 *
RightHandside<dim> rhs_func_T_2;
750 *
rhs_func_T_2.set_time(time-time_step);
757 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
758 *
const unsigned int n_q_points = quadrature_formula.size();
762 *
std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
764 *
std::vector<double> Rnp_cal_assemble (n_q_points);
767 *
dynamic_rhs_T = 0 ;
770 *
cell = dof_handler.begin_active(),
771 *
endc = dof_handler.end();
773 *
for (; cell!=endc; ++cell)
774 *
if(cell->is_locally_owned())
776 *
fe_values.reinit (cell);
777 *
local_rhs_vector_T = 0;
779 *
for (
unsigned int q=0; q<n_q_points; ++q)
780 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
782 *
const double phi_i_u = fe_values.shape_value (i,q);
785 *
local_rhs_vector_T(i) += time_step *
theta *
787 *
rhs_func_T_1.value_v2 (fe_values.quadrature_point (q)) *
790 *
time_step * (1.0 -
theta) *
792 *
rhs_func_T_2.value_v2 (fe_values.quadrature_point (q)) *
793 *
fe_values.JxW (q));
796 *
cell->get_dof_indices (local_dof_indices);
799 *
constraints_T.distribute_local_to_global(local_rhs_vector_T,
814 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingsolve"></a>
815 * <h4>LaserHeating::solve</h4>
816 * Solving the equation is direct. Recall that we have defined several matrices and vectors,
817 * to avoid ambiguous, here, we only use system_matrix_T as the system
matrix, system_rhs_T
818 * as the system right hand side. The vector completely_distributed_solution is used to store
819 * the obtained solution.
823 *
void LaserHeating<dim>::solve_T ()
828 *
SolverControl solver_control (1*system_rhs_T.size(),1e-12*system_rhs_T.l2_norm(),
true);
835 *
preconditioner.initialize(system_matrix_T,
data);
837 *
solver.solve (system_matrix_T,completely_distributed_solution,system_rhs_T,preconditioner);
842 * Print the number of iterations by hand.
848 *
pcout <<
" " << solver_control.last_step()
849 *
<<
" CG iterations needed to obtain convergence." << std::endl
850 *
<<
"\t initial convergence value = " << solver_control.initial_value() << std::endl
851 *
<<
"\t final convergence value = " << solver_control.last_value() << std::endl
854 *
constraints_T.distribute (completely_distributed_solution);
855 *
new_solution_T = completely_distributed_solution;
863 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingrefine_mesh"></a>
864 * <h4>LaserHeating::refine_mesh</h4>
871 *
void LaserHeating<dim>::refine_mesh()
884 * only
refine mesh 5um above the TiO2 and glass
interface
891 *
cell = triangulation.begin_active();
892 *
cell != triangulation.end(); ++cell)
893 *
if(cell->is_locally_owned())
895 *
fe_values.reinit(cell);
896 *
if(
std::abs(fe_values.quadrature_point(0)[1]) <= global_film_thickness+5
e-6)
898 *
cell->set_refine_flag();
902 *
cell->clear_refine_flag();
905 *
triangulation.execute_coarsening_and_refinement();
913 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatinghoutput_results"></a>
914 * <h4>LaserHeatingh::output_results</h4>
921 *
void LaserHeating<dim>::output_results (
int output_num)
const
927 *
data_out.add_data_vector (old_solution_T,
"T");
931 * the length of output numbering
939 *
data_out.build_patches ();
941 *
const std::string filename = (
"solution-" +
946 *
std::ofstream output (filename.c_str());
947 *
data_out.write_vtu (output);
952 * output the overall solution
960 *
std::vector<std::string> filenames;
962 *
filenames.push_back (
"solution-" +
967 *
std::ofstream master_output ((
"solution-" +
970 *
data_out.write_pvtu_record (master_output,filenames);
982 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingrun"></a>
983 * <h4>LaserHeating::run</h4>
987 * This is the function which has the top-
level control over everything. Apart
988 * from
one line of additional output, it is the same as
for the previous
993 *
void LaserHeating<dim>::run ()
995 *
pcout <<
"Solving problem in " << dim <<
" space dimensions." << std::endl;
1001 *
assemble_system_matrix_init (global_simulation_time_step);
1005 * projection of
initial conditions by solving.
1006 * solution stored in new_solution_T;
1014 *
old_solution_T = new_solution_T;
1015 *
old_solution_T_cal = new_solution_T;
1025 *
system_matrix_T = 0;
1029 *
double time_step = global_simulation_time_step;
1031 *
int timestep_number = 0;
1038 *
output_results (0);
1041 *
while(time < global_simulation_end_time)
1044 *
time += time_step;
1045 *
timestep_number ++;
1047 *
pcout <<
"Time step " << timestep_number
1048 *
<<
" at t=" << time
1049 *
<<
" time_step = " << time_step
1059 *
right_system_matrix_T.vmult(system_rhs_T,old_solution_T_cal);
1061 *
dynamic_assemble_rhs_T (time,time_step);
1062 *
system_rhs_T.add(1,dynamic_rhs_T);
1064 *
system_matrix_T.copy_from (left_system_matrix_T);
1067 *
BoundaryValues<dim> boundary_values_function;
1068 *
std::map<types::global_dof_index,double> boundary_values;
1072 *
boundary_values_function,
1087 * old_solution_T is used
for output, holding ghost cells
1088 * old_solution_T_cal is used
for calculation, holding only
1089 * locally owned cells.
1092 *
old_solution_T = new_solution_T;
1093 *
old_solution_T_cal = new_solution_T;
1098 *
output_results (timestep_number);
1101 *
computing_timer.print_summary ();
1102 *
computing_timer.reset();
1104 *
pcout << std::endl;
1115 * <a name=
"Distributed_Moving_Laser_Heating.cc-Thecodemaincodefunction"></a>
1116 * <h3>The <code>
main</code> function</h3>
1122 *
int main (
int argc,
char *argv[])
1128 *
LaserHeating<2> laserHeating_2d;
1129 *
laserHeating_2d.run ();
1133 *
catch (std::exception &exc)
1135 *
std::cerr << std::endl
1137 *
<<
"----------------------------------------------------"
1139 *
std::cerr <<
"Exception on processing: " << std::endl
1140 *
<< exc.what() << std::endl
1141 *
<<
"Aborting!" << std::endl
1142 *
<<
"----------------------------------------------------"
1149 *
std::cerr << std::endl
1151 *
<<
"----------------------------------------------------"
1153 *
std::cerr <<
"Unknown exception!" << std::endl
1154 *
<<
"Aborting!" << std::endl
1155 *
<<
"----------------------------------------------------"
1166<a name=
"ann-boundaryInit.h"></a>
1167<h1>Annotated version of boundaryInit.h</h1>
1186 * #----------------------------------------------------------
1188 * # This file defines the boundary and
initial conditions
1190 * #----------------------------------------------------------
1196 *
#ifndef GLOBAL_PARA
1197 *
#define GLOBAL_PARA
1198 *
#include
"./globalPara.h"
1203 * #----------------------------------------------------------
1210 *
template <
int dim>
1211 *
class BoundaryValues :
public Function<dim>
1214 *
BoundaryValues () :
Function<dim>() {}
1217 *
const unsigned int component = 0)
const override;
1220 *
template <
int dim>
1221 *
class InitialValues :
public Function<dim>
1224 *
InitialValues () :
Function<dim>() {}
1227 *
const unsigned int component = 0)
const override;
1233 * #----------------------------------------------------------
1240 *
template <
int dim>
1241 *
double BoundaryValues<dim>::value (
const Point<dim> &,
1242 *
const unsigned int )
const
1248 *
template <
int dim>
1249 *
double InitialValues<dim>::value (
const Point<dim> &,
1250 *
const unsigned int )
const
1261 * #----------------------------------------------------------
1262 * # Declaration and Implementation
1263 * # mass density and heat capacity
1269 *
template <
int dim>
1270 *
class RhoC :
public Function<dim>
1276 *
const unsigned int component = 0)
const override;
1279 *
template <
int dim>
1280 *
double RhoC<dim>::value (
const Point<dim> &p,
1281 *
const unsigned int )
const
1285 * # p stores the xyz coordinates at each vertex
1286 * #
for 2D problems in xy, we assume the non-uniform is in y-axis.
1289 *
if ( p[1] >= -global_film_thickness )
1291 *
return global_rho_Tio2 * global_C_Tio2;
1294 *
return global_rho_glass * global_C_glass;
1302 * #----------------------------------------------------------
1303 * # Declaration and Implementation
1304 * # thermal conductivity
1310 *
template <
int dim>
1317 *
const unsigned int component = 0)
const override;
1320 *
template <
int dim>
1321 *
double K_T<dim>::value (
const Point<dim> &p,
1322 *
const unsigned int )
const
1326 * # p stores the xyz coordinates at each vertex
1327 * #
for 2D problems in xy, we assume the non-uniform is in y-axis.
1330 *
if ( p[1] >= -global_film_thickness)
1332 *
return global_k_Tio2;
1335 *
return global_k_glass;
1341<a name=
"ann-globalPara.h"></a>
1342<h1>Annotated version of globalPara.h</h1>
1361 * # physics constants
1364 *
double global_PI = 3.1415927;
1371 *
double global_Pow_laser = 0.4;
1372 *
double global_spotsize_at_e_2 = 20
e-6;
1373 *
double global_c_laser = global_spotsize_at_e_2 / 4.0;
1374 *
double global_c_hwhm = global_c_laser * 2.35482 / 2;
1375 *
double global_V_scan_x = 10
e-3;
1377 *
double global_init_position_x0 = -50
e-6;
1385 *
double global_rho_Tio2 = 4200;
1386 *
double global_C_Tio2 = 690;
1387 *
double global_k_Tio2 = 4.8;
1393 *
double global_rho_glass = 2200;
1394 *
double global_C_glass = 700;
1395 *
double global_k_glass = 1.8;
1397 *
double global_film_thickness = 400
e-9;
1404 *
double global_simulation_time_step = 1
e-5;
1405 *
double global_simulation_end_time = 100
e-6 / global_V_scan_x;
1412 *
#define BOUNDARY_NUM 11
1416<a name=
"ann-rightHandSide.h"></a>
1417<h1>Annotated version of rightHandSide.h</h1>
1436 * #----------------------------------------------------------
1438 * # This file defines the boundary and
initial conditions
1440 * #----------------------------------------------------------
1446 *
#ifndef GLOBAL_PARA
1447 *
#define GLOBAL_PARA
1448 *
#include
"./globalPara.h"
1453 * #----------------------------------------------------------
1460 *
template <
int dim>
1461 *
class RightHandside :
public Function<dim>
1464 *
RightHandside () :
Function<dim>() {}
1471 * #----------------------------------------------------------
1478 *
template <
int dim>
1479 *
double RightHandside<dim>::value_v2 (
const Point<dim> &p)
1482 *
double alpha_abs = 1e4;
1485 *
if(p[1] >= -global_film_thickness)
1488 *
double P00 = global_Pow_laser / global_PI / global_c_laser / global_c_laser / 2.0;
1492 *
(p[0] - global_V_scan_x * this->
get_time()-global_init_position_x0) *
1493 *
(p[0] - global_V_scan_x * this->
get_time()-global_init_position_x0)
1495 *
(2.0 * global_c_laser * global_c_laser) );
1498 *
return alpha_abs * I00 *
std::exp(-alpha_abs*(0 - p[1]));
* * int main(int argc, char **argv)
* * * struct InterferenceTaperTransform *
void attach_dof_handler(const DoFHandler< dim, spacedim > &)
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
void attach_triangulation(Triangulation< dim, spacedim > &tria)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void make_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
@ update_values
Shape function values.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
std::vector< index_type > data
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
@ matrix
Contents is actually a matrix.
@ general
No special properties.
constexpr types::blas_int one
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
* * if(update_pressure &update_flags) * compute_pressure(constitutive_request
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
void copy(const T *begin, const T *end, U *dest)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
::VectorizedArray< Number, width > exp(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)