273 * <a name=
"Distributed_Moving_Laser_Heating.cc-Includefiles"></a>
274 * <h3>Include files</h3>
278 * All the include files have already been discussed in previous tutorials.
281 * #include <deal.II/dofs/dof_handler.h>
282 * #include <deal.II/dofs/dof_renumbering.h>
283 * #include <deal.II/grid/grid_generator.h>
284 * #include <deal.II/grid/tria_accessor.h>
285 * #include <deal.II/grid/tria_iterator.h>
286 * #include <deal.II/dofs/dof_accessor.h>
287 * #include <deal.II/fe/fe_q.h>
288 * #include <deal.II/dofs/dof_tools.h>
289 * #include <deal.II/fe/fe_values.h>
290 * #include <deal.II/base/quadrature_lib.h>
291 * #include <deal.II/base/function.h>
292 * #include <deal.II/numerics/vector_tools.h>
293 * #include <deal.II/numerics/matrix_tools.h>
294 * #include <deal.II/lac/vector.h>
295 * #include <deal.II/lac/full_matrix.h>
296 * #include <deal.II/lac/dynamic_sparsity_pattern.h>
298 * #include <deal.II/grid/grid_in.h>
299 * #include <deal.II/grid/grid_tools.h>
300 * #include <deal.II/lac/trilinos_vector.h>
301 * #include <deal.II/lac/trilinos_sparse_matrix.h>
302 * #include <deal.II/lac/trilinos_solver.h>
303 * #include <deal.II/lac/trilinos_precondition.h>
305 * #include <deal.II/lac/sparsity_tools.h>
306 * #include <deal.II/lac/generic_linear_algebra.h>
308 * #include <deal.II/base/conditional_ostream.h>
309 * #include <deal.II/base/utilities.h>
310 * #include <deal.II/base/index_set.h>
311 * #include <deal.II/distributed/tria.h>
313 * #include <deal.II/numerics/data_out.h>
315 * #include <iostream>
318 * #include <deal.II/base/logstream.h>
319 * #include <deal.II/lac/affine_constraints.h>
320 * #include <deal.II/base/timer.h>
327 * #include <deal.II/numerics/error_estimator.h>
328 * #include <deal.II/distributed/grid_refinement.h>
329 * #include <deal.II/distributed/solution_transfer.h>
333 * remember to use the
namespace dealii before
334 * defining a
class that is inheritaged from
Function<dim>
341 * In
general, it is more clear to separate boundary and
initial condictions,
342 * as well as the right hand side function from a file holding all the things.
343 * To
do so, in
this work, the globalPara.h file defines physical constants,
344 * laser parameters, and heat characteristics of materials involved. Boundary
345 * and
initial conditions are defined in boundaryInit.h. The rightHandSide.h
346 * defines the heat source, which in
this work is a moving Gaussian beam.
352 * #ifndef GLOBAL_PARA
353 * #define GLOBAL_PARA
354 * #include
"./globalPara.h"
355 * #include
"./boundaryInit.h"
356 * #include
"./rightHandSide.h"
361 * Now the main
class is defined as following
374 *
void setup_system();
376 *
void assemble_system_matrix_init (
double time_step);
377 *
void dynamic_assemble_rhs_T (
double time,
double time_step);
381 *
void refine_mesh();
382 *
void output_results (
int output_num)
const;
409 *
for storing right
matrix
416 * System_rhs, only locally owned cells
424 * Old Solutions with ghost cells,
for output
431 * Old Solutions only with locally owned cells
438 * New Solutions only with locally owned cells
445 * Dynamic assembling of the righthandside terms
469 * LaserHeating<dim>::LaserHeating ()
471 * mpi_communicator (MPI_COMM_WORLD),
486 * LaserHeating<dim>::~LaserHeating ()
488 * dof_handler.
clear();
494 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingmake_grid"></a>
495 * <h4>LaserHeating::make_grid</h4>
496 * make grid by importing msh file, and rescale
500 *
void LaserHeating<dim>::make_grid ()
506 * std::ifstream input_file (
"geometry.msh");
507 * grid_in.read_msh (input_file);
510 * pcout <<
" Number of active cells: "
513 * <<
" Total number of cells: "
521 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingsetup_system"></a>
522 * <h4>LaserHeating::setup_system</h4>
527 *
void LaserHeating<dim>::setup_system ()
532 * dof_handler.distribute_dofs (fe);
534 * pcout <<
" Number of degrees of freedom: "
535 * << dof_handler.n_dofs()
538 * locally_owned_dofs = dof_handler.locally_owned_dofs();
543 * we want to output solution, so here should have ghost cells
546 * old_solution_T.reinit (locally_owned_dofs,locally_relevant_dofs,mpi_communicator);
550 * locally owned cells
553 * old_solution_T_cal.reinit (locally_owned_dofs,mpi_communicator);
554 * new_solution_T.reinit (locally_owned_dofs,mpi_communicator);
555 * dynamic_rhs_T.reinit (locally_owned_dofs,mpi_communicator);
556 * system_rhs_T.reinit (locally_owned_dofs,mpi_communicator);
558 * constraints_T.clear();
559 * constraints_T.reinit (locally_relevant_dofs);
561 * constraints_T.close();
568 * locally_owned_dofs,
570 * locally_relevant_dofs);
572 * left_system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
573 * right_system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
574 * system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
582 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingassemble_system_matrix"></a>
583 * <h4>LaserHeating::assemble_system_matrix</h4>
590 *
void LaserHeating<dim>::assemble_system_matrix_init (
double time_step)
598 *
const InitialValues<dim> initial_value_func_T;
601 *
const RhoC<dim> rho_C_fun_T;
602 *
const K_T<dim> k_fun_T;
609 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
610 *
const unsigned int n_q_points = quadrature_formula.size();
620 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
622 * system_matrix_T = 0;
623 * left_system_matrix_T = 0;
624 * right_system_matrix_T = 0;
628 *
for (
const auto &cell : dof_handler.active_cell_iterators())
629 * if(cell->is_locally_owned())
632 * fe_values.
reinit (cell);
633 * local_init_matrix = 0;
635 * local_rho_c_T_matrix = 0;
636 * local_k_T_matrix = 0;
638 * local_init_T_rhs = 0;
640 *
for (
unsigned int q=0; q<n_q_points; ++q)
641 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
643 *
const Tensor<1,dim> div_phi_i_u = fe_values.shape_grad (i,q);
644 *
const double phi_i_u = fe_values.shape_value (i,q);
646 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
649 *
const Tensor<1,dim> div_phi_j_u = fe_values.shape_grad(j,q);
650 *
const double phi_j_u = fe_values.shape_value (j,q);
652 * local_init_matrix(i,j) += (phi_i_u *
654 * fe_values.JxW (q));
656 * local_rho_c_T_matrix(i,j) += (rho_C_fun_T.value(fe_values.quadrature_point(q)) *
661 * time_step * (theta) *
662 * (k_fun_T.value(fe_values.quadrature_point(q)) *
665 * fe_values.JxW (q));
667 * local_k_T_matrix(i,j) += (rho_C_fun_T.value(fe_values.quadrature_point(q)) *
672 * time_step * (1.0-theta) *
673 * (k_fun_T.value(fe_values.quadrature_point(q)) *
676 * fe_values.JxW (q));
680 * local_init_T_rhs(i) += (phi_i_u *
681 * initial_value_func_T.value (fe_values.quadrature_point (q)) *
682 * fe_values.JxW (q));
686 * cell->get_dof_indices (local_dof_indices);
690 *
copy to system_matrix_T and system_rhs_T
for projecting
initial values
693 * constraints_T.distribute_local_to_global(local_init_matrix,
702 * store M + dt*theta*A as the left_system_matrix
708 * constraints_T.distribute_local_to_global(local_rho_c_T_matrix,
710 * left_system_matrix_T);
714 * store M - dt*(1-theta)*A as the right_system_matrix
717 * constraints_T.distribute_local_to_global(local_k_T_matrix,
719 * right_system_matrix_T);
735 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingdynamic_assemble_rhs_T"></a>
736 * <h4>LaserHeating::dynamic_assemble_rhs_T</h4>
737 * The right hand side is assembled each time during running, which is necessary as
738 * the laser source is moving. To separate the heat source and the right hand
739 * side assembling, the right hand side function is defined as RightHandside<dim>.
743 *
void LaserHeating<dim>::dynamic_assemble_rhs_T (
double time,
double time_step)
750 * RightHandside<dim> rhs_func_T_1;
751 * rhs_func_T_1.set_time(time);
753 * RightHandside<dim> rhs_func_T_2;
754 * rhs_func_T_2.set_time(time-time_step);
761 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
762 *
const unsigned int n_q_points = quadrature_formula.size();
766 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
768 * std::vector<double> Rnp_cal_assemble (n_q_points);
771 * dynamic_rhs_T = 0 ;
774 * cell = dof_handler.begin_active(),
775 * endc = dof_handler.end();
777 *
for (; cell!=endc; ++cell)
778 *
if(cell->is_locally_owned())
780 * fe_values.reinit (cell);
781 * local_rhs_vector_T = 0;
783 *
for (
unsigned int q=0; q<n_q_points; ++q)
784 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
786 *
const double phi_i_u = fe_values.shape_value (i,q);
789 * local_rhs_vector_T(i) += time_step * theta *
791 * rhs_func_T_1.value_v2 (fe_values.quadrature_point (q)) *
794 * time_step * (1.0 - theta) *
796 * rhs_func_T_2.value_v2 (fe_values.quadrature_point (q)) *
797 * fe_values.JxW (q));
800 * cell->get_dof_indices (local_dof_indices);
803 * constraints_T.distribute_local_to_global(local_rhs_vector_T,
818 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingsolve"></a>
819 * <h4>LaserHeating::solve</h4>
820 * Solving the equation is direct. Recall that we have defined several matrices and vectors,
821 * to avoid ambiguous, here, we only use system_matrix_T as the system
matrix, system_rhs_T
822 * as the system right hand side. The vector completely_distributed_solution is used to store
823 * the obtained solution.
827 *
void LaserHeating<dim>::solve_T ()
832 *
SolverControl solver_control (1*system_rhs_T.size(),1e-12*system_rhs_T.l2_norm(),
true);
839 * preconditioner.initialize(system_matrix_T,data);
841 * solver.solve (system_matrix_T,completely_distributed_solution,system_rhs_T,preconditioner);
846 * Print the number of iterations by hand.
852 * pcout <<
" " << solver_control.last_step()
853 * <<
" CG iterations needed to obtain convergence." << std::endl
854 * <<
"\t initial convergence value = " << solver_control.initial_value() << std::endl
855 * <<
"\t final convergence value = " << solver_control.last_value() << std::endl
858 * constraints_T.distribute (completely_distributed_solution);
859 * new_solution_T = completely_distributed_solution;
867 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingrefine_mesh"></a>
868 * <h4>LaserHeating::refine_mesh</h4>
875 *
void LaserHeating<dim>::refine_mesh()
888 * only
refine mesh 5um above the TiO2 and glass
interface
897 *
if(cell->is_locally_owned())
899 * fe_values.reinit(cell);
900 *
if(
std::abs(fe_values.quadrature_point(0)[1]) <= global_film_thickness+5
e-6)
902 * cell->set_refine_flag();
906 * cell->clear_refine_flag();
917 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatinghoutput_results"></a>
918 * <h4>LaserHeatingh::output_results</h4>
925 *
void LaserHeating<dim>::output_results (
int output_num)
const
931 * data_out.add_data_vector (old_solution_T,
"T");
935 * the length of output numbering
943 * data_out.build_patches ();
945 *
const std::string filename = (
"solution-" +
950 * std::ofstream output (filename.c_str());
951 * data_out.write_vtu (output);
956 * output the overall solution
964 * std::vector<std::string> filenames;
966 * filenames.push_back (
"solution-" +
971 * std::ofstream master_output ((
"solution-" +
974 * data_out.write_pvtu_record (master_output,filenames);
986 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingrun"></a>
987 * <h4>LaserHeating::run</h4>
991 * This is the function which has the top-
level control over everything. Apart
992 * from one line of additional output, it is the same as
for the previous
997 *
void LaserHeating<dim>::run ()
999 * pcout <<
"Solving problem in " << dim <<
" space dimensions." << std::endl;
1005 * assemble_system_matrix_init (global_simulation_time_step);
1009 * projection of
initial conditions by solving.
1010 * solution stored in new_solution_T;
1018 * old_solution_T = new_solution_T;
1019 * old_solution_T_cal = new_solution_T;
1029 * system_matrix_T = 0;
1033 *
double time_step = global_simulation_time_step;
1035 *
int timestep_number = 0;
1039 * output
initial values; need ghost cells
1042 * output_results (0);
1045 *
while(time < global_simulation_end_time)
1048 * time += time_step;
1049 * timestep_number ++;
1051 * pcout <<
"Time step " << timestep_number
1052 * <<
" at t=" << time
1053 * <<
" time_step = " << time_step
1063 * right_system_matrix_T.vmult(system_rhs_T,old_solution_T_cal);
1065 * dynamic_assemble_rhs_T (time,time_step);
1066 * system_rhs_T.add(1,dynamic_rhs_T);
1068 * system_matrix_T.copy_from (left_system_matrix_T);
1071 * BoundaryValues<dim> boundary_values_function;
1072 * std::map<types::global_dof_index,double> boundary_values;
1076 * boundary_values_function,
1091 * old_solution_T is used
for output, holding ghost cells
1092 * old_solution_T_cal is used
for calculation, holding only
1093 * locally owned cells.
1096 * old_solution_T = new_solution_T;
1097 * old_solution_T_cal = new_solution_T;
1102 * output_results (timestep_number);
1105 * computing_timer.print_summary ();
1106 * computing_timer.reset();
1108 * pcout << std::endl;
1119 * <a name=
"Distributed_Moving_Laser_Heating.cc-Thecodemaincodefunction"></a>
1120 * <h3>The <code>main</code> function</h3>
1126 *
int main (
int argc,
char *argv[])
1132 * LaserHeating<2> laserHeating_2d;
1133 * laserHeating_2d.run ();
1137 *
catch (std::exception &exc)
1139 * std::cerr << std::endl
1141 * <<
"----------------------------------------------------"
1143 * std::cerr <<
"Exception on processing: " << std::endl
1144 * << exc.what() << std::endl
1145 * <<
"Aborting!" << std::endl
1146 * <<
"----------------------------------------------------"
1153 * std::cerr << std::endl
1155 * <<
"----------------------------------------------------"
1157 * std::cerr <<
"Unknown exception!" << std::endl
1158 * <<
"Aborting!" << std::endl
1159 * <<
"----------------------------------------------------"
1170<a name=
"ann-boundaryInit.h"></a>
1171<h1>Annotated version of boundaryInit.h</h1>
1190 * #----------------------------------------------------------
1192 * # This file defines the boundary and
initial conditions
1194 * #----------------------------------------------------------
1200 * #ifndef GLOBAL_PARA
1201 * #define GLOBAL_PARA
1202 * #include
"./globalPara.h"
1207 * #----------------------------------------------------------
1214 *
template <
int dim>
1215 *
class BoundaryValues :
public Function<dim>
1218 * BoundaryValues () :
Function<dim>() {}
1221 *
const unsigned int component = 0)
const override;
1224 *
template <
int dim>
1225 *
class InitialValues :
public Function<dim>
1228 * InitialValues () :
Function<dim>() {}
1231 *
const unsigned int component = 0)
const override;
1237 * #----------------------------------------------------------
1244 *
template <
int dim>
1245 *
double BoundaryValues<dim>::value (
const Point<dim> &,
1246 *
const unsigned int )
const
1252 *
template <
int dim>
1253 *
double InitialValues<dim>::value (
const Point<dim> &,
1254 *
const unsigned int )
const
1265 * #----------------------------------------------------------
1266 * # Declaration and Implementation
1267 * # mass density and heat capacity
1273 *
template <
int dim>
1274 *
class RhoC :
public Function<dim>
1280 *
const unsigned int component = 0)
const override;
1283 *
template <
int dim>
1284 *
double RhoC<dim>::value (
const Point<dim> &p,
1285 *
const unsigned int )
const
1289 * # p stores the xyz coordinates at each vertex
1290 * #
for 2D problems in xy, we assume the non-uniform is in y-axis.
1293 *
if ( p[1] >= -global_film_thickness )
1295 *
return global_rho_Tio2 * global_C_Tio2;
1298 *
return global_rho_glass * global_C_glass;
1306 * #----------------------------------------------------------
1307 * # Declaration and Implementation
1308 * # thermal conductivity
1314 *
template <
int dim>
1321 *
const unsigned int component = 0)
const override;
1324 *
template <
int dim>
1325 *
double K_T<dim>::value (
const Point<dim> &p,
1326 *
const unsigned int )
const
1330 * # p stores the xyz coordinates at each vertex
1331 * #
for 2D problems in xy, we assume the non-uniform is in y-axis.
1334 *
if ( p[1] >= -global_film_thickness)
1336 *
return global_k_Tio2;
1339 *
return global_k_glass;
1345<a name=
"ann-globalPara.h"></a>
1346<h1>Annotated version of globalPara.h</h1>
1365 * # physics constants
1368 *
double global_PI = 3.1415927;
1375 *
double global_Pow_laser = 0.4;
1376 *
double global_spotsize_at_e_2 = 20
e-6;
1377 *
double global_c_laser = global_spotsize_at_e_2 / 4.0;
1378 *
double global_c_hwhm = global_c_laser * 2.35482 / 2;
1379 *
double global_V_scan_x = 10
e-3;
1381 *
double global_init_position_x0 = -50
e-6;
1389 *
double global_rho_Tio2 = 4200;
1390 *
double global_C_Tio2 = 690;
1391 *
double global_k_Tio2 = 4.8;
1397 *
double global_rho_glass = 2200;
1398 *
double global_C_glass = 700;
1399 *
double global_k_glass = 1.8;
1401 *
double global_film_thickness = 400
e-9;
1408 *
double global_simulation_time_step = 1
e-5;
1409 *
double global_simulation_end_time = 100
e-6 / global_V_scan_x;
1416 * #define BOUNDARY_NUM 11
1420<a name=
"ann-rightHandSide.h"></a>
1421<h1>Annotated version of rightHandSide.h</h1>
1440 * #----------------------------------------------------------
1442 * # This file defines the boundary and
initial conditions
1444 * #----------------------------------------------------------
1450 * #ifndef GLOBAL_PARA
1451 * #define GLOBAL_PARA
1452 * #include
"./globalPara.h"
1457 * #----------------------------------------------------------
1464 *
template <
int dim>
1465 *
class RightHandside :
public Function<dim>
1468 * RightHandside () :
Function<dim>() {}
1475 * #----------------------------------------------------------
1482 *
template <
int dim>
1483 *
double RightHandside<dim>::value_v2 (
const Point<dim> &p)
1486 *
double alpha_abs = 1e4;
1489 *
if(p[1] >= -global_film_thickness)
1492 *
double P00 = global_Pow_laser / global_PI / global_c_laser / global_c_laser / 2.0;
1496 * (p[0] - global_V_scan_x * this->
get_time()-global_init_position_x0) *
1497 * (p[0] - global_V_scan_x * this->
get_time()-global_init_position_x0)
1499 * (2.0 * global_c_laser * global_c_laser) );
1502 *
return alpha_abs * I00 *
std::exp(-alpha_abs*(0 - p[1]));
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)
cell_iterator end() const
unsigned int n_cells() const
active_cell_iterator begin_active(const unsigned int level=0) const
virtual types::global_cell_index n_global_active_cells() const override
types::subdomain_id locally_owned_subdomain() const override
virtual void execute_coarsening_and_refinement() override
virtual void clear() override
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.
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.
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
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 > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation