272 * <a name=
"Distributed_Moving_Laser_Heating.cc-Includefiles"></a>
273 * <h3>Include files</h3>
277 * All the include files have already been discussed in previous tutorials.
280 * #include <deal.II/dofs/dof_handler.h>
281 * #include <deal.II/dofs/dof_renumbering.h>
282 * #include <deal.II/grid/grid_generator.h>
283 * #include <deal.II/grid/tria_accessor.h>
284 * #include <deal.II/grid/tria_iterator.h>
285 * #include <deal.II/dofs/dof_accessor.h>
286 * #include <deal.II/fe/fe_q.h>
287 * #include <deal.II/dofs/dof_tools.h>
288 * #include <deal.II/fe/fe_values.h>
289 * #include <deal.II/base/quadrature_lib.h>
290 * #include <deal.II/base/function.h>
291 * #include <deal.II/numerics/vector_tools.h>
292 * #include <deal.II/numerics/matrix_tools.h>
293 * #include <deal.II/lac/vector.h>
294 * #include <deal.II/lac/full_matrix.h>
295 * #include <deal.II/lac/dynamic_sparsity_pattern.h>
297 * #include <deal.II/grid/grid_in.h>
298 * #include <deal.II/grid/grid_tools.h>
299 * #include <deal.II/lac/trilinos_vector.h>
300 * #include <deal.II/lac/trilinos_sparse_matrix.h>
301 * #include <deal.II/lac/trilinos_solver.h>
302 * #include <deal.II/lac/trilinos_precondition.h>
304 * #include <deal.II/lac/sparsity_tools.h>
305 * #include <deal.II/lac/generic_linear_algebra.h>
307 * #include <deal.II/base/conditional_ostream.h>
308 * #include <deal.II/base/utilities.h>
309 * #include <deal.II/base/index_set.h>
310 * #include <deal.II/distributed/tria.h>
312 * #include <deal.II/numerics/data_out.h>
314 * #include <iostream>
317 * #include <deal.II/base/logstream.h>
318 * #include <deal.II/lac/affine_constraints.h>
319 * #include <deal.II/base/timer.h>
326 * #include <deal.II/numerics/error_estimator.h>
327 * #include <deal.II/distributed/grid_refinement.h>
328 * #include <deal.II/distributed/solution_transfer.h>
332 * remember to use the
namespace dealii before
333 * defining a
class that is inheritaged from
Function<dim>
340 * In
general, it is more clear to separate boundary and
initial condictions,
341 * as well as the right hand side function from a file holding all the things.
342 * To
do so, in
this work, the globalPara.h file defines physical constants,
343 * laser parameters, and heat characteristics of materials involved. Boundary
344 * and
initial conditions are defined in boundaryInit.h. The rightHandSide.h
345 * defines the heat source, which in
this work is a moving Gaussian beam.
351 * #ifndef GLOBAL_PARA
352 * #define GLOBAL_PARA
353 * #include
"./globalPara.h"
354 * #include
"./boundaryInit.h"
355 * #include
"./rightHandSide.h"
360 * Now the main
class is defined as following
373 *
void setup_system();
375 *
void assemble_system_matrix_init (
double time_step);
376 *
void dynamic_assemble_rhs_T (
double time,
double time_step);
380 *
void refine_mesh();
381 *
void output_results (
int output_num)
const;
408 *
for storing right
matrix
415 * System_rhs, only locally owned cells
423 * Old Solutions with ghost cells,
for output
430 * Old Solutions only with locally owned cells
437 * New Solutions only with locally owned cells
444 * Dynamic assembling of the righthandside terms
468 * LaserHeating<dim>::LaserHeating ()
470 * mpi_communicator (MPI_COMM_WORLD),
485 * LaserHeating<dim>::~LaserHeating ()
487 * dof_handler.clear();
493 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingmake_grid"></a>
494 * <h4>LaserHeating::make_grid</h4>
495 * make grid by importing msh file, and rescale
499 *
void LaserHeating<dim>::make_grid ()
505 * std::ifstream input_file (
"geometry.msh");
506 * grid_in.read_msh (input_file);
509 * pcout <<
" Number of active cells: "
512 * <<
" Total number of cells: "
520 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingsetup_system"></a>
521 * <h4>LaserHeating::setup_system</h4>
526 *
void LaserHeating<dim>::setup_system ()
531 * dof_handler.distribute_dofs (fe);
533 * pcout <<
" Number of degrees of freedom: "
534 * << dof_handler.n_dofs()
537 * locally_owned_dofs = dof_handler.locally_owned_dofs();
542 * we want to output solution, so here should have ghost cells
545 * old_solution_T.reinit (locally_owned_dofs,locally_relevant_dofs,mpi_communicator);
549 * locally owned cells
552 * old_solution_T_cal.reinit (locally_owned_dofs,mpi_communicator);
553 * new_solution_T.reinit (locally_owned_dofs,mpi_communicator);
554 * dynamic_rhs_T.reinit (locally_owned_dofs,mpi_communicator);
555 * system_rhs_T.reinit (locally_owned_dofs,mpi_communicator);
557 * constraints_T.clear();
558 * constraints_T.reinit (locally_relevant_dofs);
560 * constraints_T.close();
567 * locally_owned_dofs,
569 * locally_relevant_dofs);
571 * left_system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
572 * right_system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
573 * system_matrix_T.reinit (locally_owned_dofs,locally_owned_dofs,dsp_T,mpi_communicator);
581 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingassemble_system_matrix"></a>
582 * <h4>LaserHeating::assemble_system_matrix</h4>
589 *
void LaserHeating<dim>::assemble_system_matrix_init (
double time_step)
597 *
const InitialValues<dim> initial_value_func_T;
600 *
const RhoC<dim> rho_C_fun_T;
601 *
const K_T<dim> k_fun_T;
608 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
609 *
const unsigned int n_q_points = quadrature_formula.size();
619 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
621 * system_matrix_T = 0;
622 * left_system_matrix_T = 0;
623 * right_system_matrix_T = 0;
627 *
for (
const auto &cell : dof_handler.active_cell_iterators())
628 * if(cell->is_locally_owned())
631 * fe_values.
reinit (cell);
632 * local_init_matrix = 0;
634 * local_rho_c_T_matrix = 0;
635 * local_k_T_matrix = 0;
637 * local_init_T_rhs = 0;
639 *
for (
unsigned int q=0; q<n_q_points; ++q)
640 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
642 *
const Tensor<1,dim> div_phi_i_u = fe_values.shape_grad (i,q);
643 *
const double phi_i_u = fe_values.shape_value (i,q);
645 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
648 *
const Tensor<1,dim> div_phi_j_u = fe_values.shape_grad(j,q);
649 *
const double phi_j_u = fe_values.shape_value (j,q);
651 * local_init_matrix(i,j) += (phi_i_u *
653 * fe_values.JxW (q));
655 * local_rho_c_T_matrix(i,j) += (rho_C_fun_T.value(fe_values.quadrature_point(q)) *
660 * time_step * (theta) *
661 * (k_fun_T.value(fe_values.quadrature_point(q)) *
664 * fe_values.JxW (q));
666 * local_k_T_matrix(i,j) += (rho_C_fun_T.value(fe_values.quadrature_point(q)) *
671 * time_step * (1.0-theta) *
672 * (k_fun_T.value(fe_values.quadrature_point(q)) *
675 * fe_values.JxW (q));
679 * local_init_T_rhs(i) += (phi_i_u *
680 * initial_value_func_T.value (fe_values.quadrature_point (q)) *
681 * fe_values.JxW (q));
685 * cell->get_dof_indices (local_dof_indices);
692 * constraints_T.distribute_local_to_global(local_init_matrix,
701 * store M + dt*theta*A as the left_system_matrix
707 * constraints_T.distribute_local_to_global(local_rho_c_T_matrix,
709 * left_system_matrix_T);
713 * store M - dt*(1-theta)*A as the right_system_matrix
716 * constraints_T.distribute_local_to_global(local_k_T_matrix,
718 * right_system_matrix_T);
734 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingdynamic_assemble_rhs_T"></a>
735 * <h4>LaserHeating::dynamic_assemble_rhs_T</h4>
736 * The right hand side is assembled each time during running, which is necessary as
737 * the laser source is moving. To separate the heat source and the right hand
738 * side assembling, the right hand side function is defined as RightHandside<dim>.
742 *
void LaserHeating<dim>::dynamic_assemble_rhs_T (
double time,
double time_step)
749 * RightHandside<dim> rhs_func_T_1;
750 * rhs_func_T_1.set_time(time);
752 * RightHandside<dim> rhs_func_T_2;
753 * rhs_func_T_2.set_time(time-time_step);
760 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
761 *
const unsigned int n_q_points = quadrature_formula.size();
765 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
767 * std::vector<double> Rnp_cal_assemble (n_q_points);
770 * dynamic_rhs_T = 0 ;
773 * cell = dof_handler.begin_active(),
774 * endc = dof_handler.end();
776 *
for (; cell!=endc; ++cell)
777 *
if(cell->is_locally_owned())
779 * fe_values.reinit (cell);
780 * local_rhs_vector_T = 0;
782 *
for (
unsigned int q=0; q<n_q_points; ++q)
783 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
785 *
const double phi_i_u = fe_values.shape_value (i,q);
788 * local_rhs_vector_T(i) += time_step * theta *
790 * rhs_func_T_1.value_v2 (fe_values.quadrature_point (q)) *
793 * time_step * (1.0 - theta) *
795 * rhs_func_T_2.value_v2 (fe_values.quadrature_point (q)) *
796 * fe_values.JxW (q));
799 * cell->get_dof_indices (local_dof_indices);
802 * constraints_T.distribute_local_to_global(local_rhs_vector_T,
817 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingsolve"></a>
818 * <h4>LaserHeating::solve</h4>
819 * Solving the equation is direct. Recall that we have defined several matrices and vectors,
820 * to avoid ambiguous, here, we only use system_matrix_T as the system
matrix, system_rhs_T
821 * as the system right hand side. The vector completely_distributed_solution is used to store
822 * the obtained solution.
826 *
void LaserHeating<dim>::solve_T ()
831 *
SolverControl solver_control (1*system_rhs_T.size(),1e-12*system_rhs_T.l2_norm(),
true);
838 * preconditioner.initialize(system_matrix_T,
data);
840 * solver.solve (system_matrix_T,completely_distributed_solution,system_rhs_T,preconditioner);
845 * Print the number of iterations by hand.
851 * pcout <<
" " << solver_control.last_step()
852 * <<
" CG iterations needed to obtain convergence." << std::endl
853 * <<
"\t initial convergence value = " << solver_control.initial_value() << std::endl
854 * <<
"\t final convergence value = " << solver_control.last_value() << std::endl
857 * constraints_T.distribute (completely_distributed_solution);
858 * new_solution_T = completely_distributed_solution;
866 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingrefine_mesh"></a>
867 * <h4>LaserHeating::refine_mesh</h4>
874 *
void LaserHeating<dim>::refine_mesh()
887 * only
refine mesh 5um above the TiO2 and glass
interface
896 *
if(cell->is_locally_owned())
898 * fe_values.reinit(cell);
899 *
if(
std::abs(fe_values.quadrature_point(0)[1]) <= global_film_thickness+5
e-6)
901 * cell->set_refine_flag();
905 * cell->clear_refine_flag();
916 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatinghoutput_results"></a>
917 * <h4>LaserHeatingh::output_results</h4>
924 *
void LaserHeating<dim>::output_results (
int output_num)
const
930 * data_out.add_data_vector (old_solution_T,
"T");
934 * the length of output numbering
942 * data_out.build_patches ();
944 *
const std::string filename = (
"solution-" +
949 * std::ofstream output (filename.c_str());
950 * data_out.write_vtu (output);
955 * output the overall solution
963 * std::vector<std::string> filenames;
965 * filenames.push_back (
"solution-" +
970 * std::ofstream master_output ((
"solution-" +
973 * data_out.write_pvtu_record (master_output,filenames);
985 * <a name=
"Distributed_Moving_Laser_Heating.cc-LaserHeatingrun"></a>
986 * <h4>LaserHeating::run</h4>
990 * This is the function which has the top-
level control over everything. Apart
991 * from one line of additional output, it is the same as
for the previous
996 *
void LaserHeating<dim>::run ()
998 * pcout <<
"Solving problem in " << dim <<
" space dimensions." << std::endl;
1004 * assemble_system_matrix_init (global_simulation_time_step);
1008 * projection of
initial conditions by solving.
1009 * solution stored in new_solution_T;
1017 * old_solution_T = new_solution_T;
1018 * old_solution_T_cal = new_solution_T;
1028 * system_matrix_T = 0;
1032 *
double time_step = global_simulation_time_step;
1034 *
int timestep_number = 0;
1041 * output_results (0);
1044 *
while(time < global_simulation_end_time)
1047 * time += time_step;
1048 * timestep_number ++;
1050 * pcout <<
"Time step " << timestep_number
1051 * <<
" at t=" << time
1052 * <<
" time_step = " << time_step
1062 * right_system_matrix_T.vmult(system_rhs_T,old_solution_T_cal);
1064 * dynamic_assemble_rhs_T (time,time_step);
1065 * system_rhs_T.add(1,dynamic_rhs_T);
1067 * system_matrix_T.copy_from (left_system_matrix_T);
1070 * BoundaryValues<dim> boundary_values_function;
1071 * std::map<types::global_dof_index,double> boundary_values;
1075 * boundary_values_function,
1090 * old_solution_T is used
for output, holding ghost cells
1091 * old_solution_T_cal is used
for calculation, holding only
1092 * locally owned cells.
1095 * old_solution_T = new_solution_T;
1096 * old_solution_T_cal = new_solution_T;
1101 * output_results (timestep_number);
1104 * computing_timer.print_summary ();
1105 * computing_timer.reset();
1107 * pcout << std::endl;
1118 * <a name=
"Distributed_Moving_Laser_Heating.cc-Thecodemaincodefunction"></a>
1119 * <h3>The <code>main</code> function</h3>
1125 *
int main (
int argc,
char *argv[])
1131 * LaserHeating<2> laserHeating_2d;
1132 * laserHeating_2d.run ();
1136 *
catch (std::exception &exc)
1138 * std::cerr << std::endl
1140 * <<
"----------------------------------------------------"
1142 * std::cerr <<
"Exception on processing: " << std::endl
1143 * << exc.what() << std::endl
1144 * <<
"Aborting!" << std::endl
1145 * <<
"----------------------------------------------------"
1152 * std::cerr << std::endl
1154 * <<
"----------------------------------------------------"
1156 * std::cerr <<
"Unknown exception!" << std::endl
1157 * <<
"Aborting!" << std::endl
1158 * <<
"----------------------------------------------------"
1169<a name=
"ann-boundaryInit.h"></a>
1170<h1>Annotated version of boundaryInit.h</h1>
1189 * #----------------------------------------------------------
1191 * # This file defines the boundary and
initial conditions
1193 * #----------------------------------------------------------
1199 * #ifndef GLOBAL_PARA
1200 * #define GLOBAL_PARA
1201 * #include
"./globalPara.h"
1206 * #----------------------------------------------------------
1213 *
template <
int dim>
1214 *
class BoundaryValues :
public Function<dim>
1217 * BoundaryValues () :
Function<dim>() {}
1220 *
const unsigned int component = 0)
const override;
1223 *
template <
int dim>
1224 *
class InitialValues :
public Function<dim>
1227 * InitialValues () :
Function<dim>() {}
1230 *
const unsigned int component = 0)
const override;
1236 * #----------------------------------------------------------
1243 *
template <
int dim>
1244 *
double BoundaryValues<dim>::value (
const Point<dim> &,
1245 *
const unsigned int )
const
1251 *
template <
int dim>
1252 *
double InitialValues<dim>::value (
const Point<dim> &,
1253 *
const unsigned int )
const
1264 * #----------------------------------------------------------
1265 * # Declaration and Implementation
1266 * # mass density and heat capacity
1272 *
template <
int dim>
1273 *
class RhoC :
public Function<dim>
1279 *
const unsigned int component = 0)
const override;
1282 *
template <
int dim>
1283 *
double RhoC<dim>::value (
const Point<dim> &p,
1284 *
const unsigned int )
const
1288 * # p stores the xyz coordinates at each vertex
1289 * #
for 2D problems in xy, we assume the non-uniform is in y-axis.
1292 *
if ( p[1] >= -global_film_thickness )
1294 *
return global_rho_Tio2 * global_C_Tio2;
1297 *
return global_rho_glass * global_C_glass;
1305 * #----------------------------------------------------------
1306 * # Declaration and Implementation
1307 * # thermal conductivity
1313 *
template <
int dim>
1320 *
const unsigned int component = 0)
const override;
1323 *
template <
int dim>
1324 *
double K_T<dim>::value (
const Point<dim> &p,
1325 *
const unsigned int )
const
1329 * # p stores the xyz coordinates at each vertex
1330 * #
for 2D problems in xy, we assume the non-uniform is in y-axis.
1333 *
if ( p[1] >= -global_film_thickness)
1335 *
return global_k_Tio2;
1338 *
return global_k_glass;
1344<a name=
"ann-globalPara.h"></a>
1345<h1>Annotated version of globalPara.h</h1>
1364 * # physics constants
1367 *
double global_PI = 3.1415927;
1374 *
double global_Pow_laser = 0.4;
1375 *
double global_spotsize_at_e_2 = 20
e-6;
1376 *
double global_c_laser = global_spotsize_at_e_2 / 4.0;
1377 *
double global_c_hwhm = global_c_laser * 2.35482 / 2;
1378 *
double global_V_scan_x = 10
e-3;
1380 *
double global_init_position_x0 = -50
e-6;
1388 *
double global_rho_Tio2 = 4200;
1389 *
double global_C_Tio2 = 690;
1390 *
double global_k_Tio2 = 4.8;
1396 *
double global_rho_glass = 2200;
1397 *
double global_C_glass = 700;
1398 *
double global_k_glass = 1.8;
1400 *
double global_film_thickness = 400
e-9;
1407 *
double global_simulation_time_step = 1
e-5;
1408 *
double global_simulation_end_time = 100
e-6 / global_V_scan_x;
1415 * #define BOUNDARY_NUM 11
1419<a name=
"ann-rightHandSide.h"></a>
1420<h1>Annotated version of rightHandSide.h</h1>
1439 * #----------------------------------------------------------
1441 * # This file defines the boundary and
initial conditions
1443 * #----------------------------------------------------------
1449 * #ifndef GLOBAL_PARA
1450 * #define GLOBAL_PARA
1451 * #include
"./globalPara.h"
1456 * #----------------------------------------------------------
1463 *
template <
int dim>
1464 *
class RightHandside :
public Function<dim>
1467 * RightHandside () :
Function<dim>() {}
1474 * #----------------------------------------------------------
1481 *
template <
int dim>
1482 *
double RightHandside<dim>::value_v2 (
const Point<dim> &p)
1485 *
double alpha_abs = 1e4;
1488 *
if(p[1] >= -global_film_thickness)
1491 *
double P00 = global_Pow_laser / global_PI / global_c_laser / global_c_laser / 2.0;
1495 * (p[0] - global_V_scan_x * this->
get_time()-global_init_position_x0) *
1496 * (p[0] - global_V_scan_x * this->
get_time()-global_init_position_x0)
1498 * (2.0 * global_c_laser * global_c_laser) );
1501 *
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)
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.
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