-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1848 lines (1560 loc) · 74.5 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ---------------------------------------------------------------------
*
* Copyright (C) 2012 - 2015 by the deal.II authors
*
* This file is part of the deal.II library.
*
* The deal.II library is free software; you can use it, redistribute
* it, and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* The full text of the license can be found in the file LICENSE at
* the top level of the deal.II distribution.
*
* ---------------------------------------------------------------------
*
* Author: Sven Wetterauer, University of Heidelberg, 2012
*/
// @sect3{Include files}
// The first few files have already been covered in previous examples and will
// thus not be further commented on.
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/function.h>
#include <deal.II/base/function_parser.h>
#include <deal.II/base/logstream.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/conditional_ostream.h>
#include <deal.II/base/index_set.h>
#include <deal.II/base/data_out_base.h>
#include <deal.II/base/parameter_handler.h>
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
#include <deal.II/lac/generic_linear_algebra.h>
#include <deal.II/lac/petsc_parallel_sparse_matrix.h>
#include <deal.II/lac/petsc_parallel_vector.h>
#include <deal.II/lac/petsc_solver.h>
#include <deal.II/lac/petsc_precondition.h>
#include <deal.II/lac/sparsity_tools.h>
#include <deal.II/lac/trilinos_sparsity_pattern.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/manifold_lib.h>
#include <deal.II/grid/grid_refinement.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_accessor.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/fe/fe_values.h>
#include <deal.II/fe/fe_q.h>
#include <deal.II/fe/fe_system.h>
#include <deal.II/fe/fe_values_extractors.h>
#include <deal.II/numerics/vector_tools.h>
#include <deal.II/numerics/matrix_tools.h>
#include <deal.II/numerics/data_out.h>
#include <deal.II/numerics/error_estimator.h>
#include <deal.II/numerics/solution_transfer.h>
#include <deal.II/distributed/tria.h>
#include <deal.II/distributed/grid_refinement.h>
#include <deal.II/distributed/solution_transfer.h>
#include <Sacado.hpp>
#include <boost/math/special_functions/factorials.hpp>
//namespace LA
//{
// using namespace ::LinearAlgebraTrilinos;
//}
#include <fstream>
#include <iostream>
#include <iomanip>
#include <experimental/type_traits>
//#define PULSE_LENGTH 1.5e-13
//#define PULSE_ENERGY 1.7e-6
//#define INIT_BEAM_RAD 1e-3
//#define TARGET_BEAM_RAD 1e-6
//#define PULSE_INTENSITY (INIT_BEAM_RAD*INIT_BEAM_RAD)/(TARGET_BEAM_RAD*TARGET_BEAM_RAD)*PULSE_ENERGY/PULSE_LENGTH
#define INNER_CIRCLE_RADIUS 5e-2
template < typename T >
using toDim_t = decltype(std::declval<T>().norm());
template < typename T >
using has_toDim = std::experimental::is_detected< toDim_t, T >;
template <bool, typename T = void>
struct enable_if
{};
template <typename T>
struct enable_if<true, T> {
typedef T type;
};
// We will use adaptive mesh refinement between Newton iterations. To do so,
// we need to be able to work with a solution on the new mesh, although it was
// computed on the old one. The SolutionTransfer class transfers the solution
// from the old to the new mesh:
// We then open a namespace for this program and import everything from the
// dealii namespace into it, as in previous programs:
namespace Step15
{
using namespace dealii;
// @sect3{The <code>MinimalSurfaceProblem</code> class template}
// The class template is basically the same as in step-6. Three additions
// are made:
// - There are two solution vectors, one for the Newton update
// $\delta u^n$, and one for the current iterate $u^n$.
// - The <code>setup_system</code> function takes an argument that denotes whether
// this is the first time it is called or not. The difference is that the
// first time around we need to distribute the degrees of freedom and set the
// solution vector for $u^n$ to the correct size. The following times, the
// function is called after we have already done these steps as part of
// refining the mesh in <code>refine_mesh</code>.
// - We then also need new functions: <code>set_boundary_values()</code>
// takes care of setting the boundary values on the solution vector
// correctly, as discussed at the end of the
// introduction. <code>compute_residual()</code> is a function that computes
// the norm of the nonlinear (discrete) residual. We use this function to
// monitor convergence of the Newton iteration. The function takes a step
// length $\alpha^n$ as argument to compute the residual of $u^n + \alpha^n
// \; \delta u^n$. This is something one typically needs for step length
// control, although we will not use this feature here. Finally,
// <code>determine_step_length()</code> computes the step length $\alpha^n$
// in each Newton iteration. As discussed in the introduction, we here use a
// fixed step length and leave implementing a better strategy as an
// exercise.
void print_status_update(const ConditionalOStream &pcout, const std::string input, const bool do_it = false)
{
#define PRINT_DEBUG
#ifdef PRINT_DEBUG
if(do_it)
{
pcout << input << '\n';
//getchar();
}
#endif
}
enum equation_class{carrier_density, electron_temperature, lattice_temperature};
template<int dim>
class physics_equations
{
//friend class left_right_equations;
public://Equations
physics_equations(const double wavelength);
~physics_equations();
template <typename T>
T gamma_func(const typename enable_if<has_toDim<T>::value, T>::type &N_val) const;
template <typename T>
T gamma_func(const T &N_val) const;
template <typename T>
T k_N(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T k_N(const T &TL_val) const;
template <typename T>
T k_L(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T k_L(const T &TL_val) const;
template <typename T>
T k_E(const typename enable_if<has_toDim<T>::value, T>::type &N_val, const typename enable_if<has_toDim<T>::value, T>::type &TE_val, const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T k_E(const T &N_val, const T &TE_val, const T &TL_val) const;
template <typename T>
T mu_e(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T mu_e(const T &TL_val) const;
template <typename T>
T mu_h(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T mu_h(const T TL_val) const;
template <typename T>
T E_g(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T E_g(const T &TL_val) const;
template <typename T>
T dEdT(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T dEdT(const T &TL_val) const;
template <typename T>
T free_carrier_cross_section(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T free_carrier_cross_section(const T &TL_val) const;
template <typename T>
T reflectivity(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T reflectivity(const T &TL_val) const;
template <typename T>
T impact_ionization_coefficient(const typename enable_if<has_toDim<T>::value, T>::type &TE_val, const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
// template <typename T>
// T impact_ionization_coefficient(const T &TE_val, const T &TL_val) const;
template <typename T, typename U>
T impact_ionization_coefficient(const T &TE_val, const U &TL_val) const;
double auger_recombination_coefficient(void) const;
template <typename T>
T dNdt_prefactor(const typename enable_if<has_toDim<T>::value, T>::type &TE_val, const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T dNdt_prefactor(const T &TE_val, const T &TL_val) const;
template <typename T>
T c_app_Tensor(const T &TL_val) const;
template <typename T>
T c_app(const T &TL_val) const;
template <typename T>
T c_e(const typename enable_if<has_toDim<T>::value, T>::type &N_val) const;
template <typename T>
T c_e(const T &N_val) const;
template <typename T>
T heat_capacity(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T heat_capacity(const T &TL_val) const;
template <typename T>
T integrate_heat_capacity(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const;
template <typename T>
T integrate_heat_capacity(const T &TL_val) const;
template <typename T>
T beta_f_func(const T x, const unsigned int n) const;
template <typename T>
T one_photon_absorption(const T lattice_temperature) const;//For later use of different wavelengths;
template <typename T>
T two_photon_absorption(const T lattice_temperature) const;//For later use of different wavelengths;
template <typename T>
T three_photon_absorption(const T lattice_temperature) const;//For later use of different wavelengths;
double photon_energy_func() const;
//private://constants
const double molar_mass_volume = 12.058832e-6;
const double wavelength;
const double density = 2.33e3;
const double refractive_index = 3.52;
const double hbar_val = 1.0545718e-34;
const double carrier_relaxation_time = 240e-15;
const double carrier_density = 6e26;
const double melting_temperature = 1687;
const double ambient_temperature = 293;
const double latent_heat = 48.31e3/molar_mass_volume;
const double one_photon_absorption_coefficient = 0;
const double two_photon_absorption_coefficient = 2e-11;
const double three_photon_absorption_coefficient = 0;
const double boltzmann_constant = 1.38064852e-23;
const double electron_charge = 1.60217662e-19;
const double planck_constant = 6.626069934e-34;
const double speed_of_light = 299792458;
const double w0_val = 2*M_PI*speed_of_light/wavelength;
const double initial_carrier_density = 9e9*1e6;
const double ambient_temperature_II = ambient_temperature;
const double temperature_delta_T = 50;//TBFixed
};
template<int dim>
physics_equations<dim>::physics_equations(const double wavelength) : wavelength(wavelength)
{
}
template<int dim>
physics_equations<dim>::~physics_equations()
{
}
template<int dim> template <typename T>
T physics_equations<dim>::gamma_func(const typename enable_if<has_toDim<T>::value, T>::type &N_val) const
{
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = (3*this->boltzmann_constant*N_val[i])/(this->carrier_relaxation_time*(1+pow(N_val[i]/this->carrier_density, 2)));
return return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::gamma_func(const T &N_val) const
{
return (3*this->boltzmann_constant*N_val)/(this->carrier_relaxation_time*(1+pow(N_val/this->carrier_density, 2)));
}
template<int dim> template <typename T>
T physics_equations<dim>::k_N(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = 2*this->boltzmann_constant*TL_val[i]/this->electron_charge*(this->mu_e(TL_val[i])*this->mu_h(TL_val[i])/(this->mu_e(TL_val[i])+this->mu_h(TL_val[i])));
return return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::k_N(const T &TL_val) const
{
return 2*this->boltzmann_constant*TL_val/this->electron_charge*(this->mu_e(TL_val)*this->mu_h<T>(TL_val)/(this->mu_e(TL_val)+this->mu_h<T>(TL_val)));
}
template<int dim> template <typename T>
T physics_equations<dim>::k_L(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
throw("Should not be used\n");
return 0*TL_val;//TBD
}
template<int dim> template <typename T>
T physics_equations<dim>::k_L(const T &TL_val) const
{
return 1/(1.56e-3 * TL_val + 1.65e-6 * pow(TL_val, 2) + 0.03) * 1e2;
}
template<int dim> template <typename T>
T physics_equations<dim>::k_E(const typename enable_if<has_toDim<T>::value, T>::type &N_val, const typename enable_if<has_toDim<T>::value, T>::type &TE_val, const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = -2*this->boltzmann_constant*this->boltzmann_constant*TE_val[i]*N_val[i]*(this->mu_e(TL_val[i])+this->mu_h(TL_val[i]))/this->electron_charge;
return return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::k_E(const T &N_val, const T &TE_val, const T &TL_val) const
{
return 2*this->boltzmann_constant*this->boltzmann_constant*TE_val*N_val*(this->mu_e<T>(TL_val)+this->mu_h<T>(TL_val))/this->electron_charge;//Missing the gradient of N, but that is zero atm, so I do not care
}
template<int dim> template <typename T>
T physics_equations<dim>::mu_e(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T temp_variable;
for(size_t i = 0; i < dim; ++i)
temp_variable[i] = 1.35e-1*pow(TL_val[i]/300, -2.4);
return temp_variable;
}
template<int dim> template <typename T>
T physics_equations<dim>::mu_e(const T &TL_val) const
{
return 1.35e-1*pow(TL_val/300, -2.4);
}
template<int dim> template <typename T>
T physics_equations<dim>::mu_h(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = 4.8e-2*pow(TL_val[i]/300, -2.5);
return return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::mu_h(const T TL_val) const
{
return 4.8e-2*pow(TL_val/300, -2.5);
}
template<int dim> template <typename T>
T physics_equations<dim>::E_g(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = (1.557-7.021e-4*pow(TL_val[i], 2)/(TL_val[i]+1108))*electron_charge;
return return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::E_g(const T &TL_val) const
{
return (1.557-7.021e-4*pow(TL_val, 2)/(TL_val+1108))*electron_charge;
}
template<int dim> template <typename T>
T physics_equations<dim>::dEdT(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = -7.021e-4*(pow(TL_val[i], 2)+2216*TL_val[i])/pow(TL_val[i]+1108, 2);
return return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::dEdT(const T &TL_val) const
{
return -7.021e-4*(pow(TL_val, 2)+2216*TL_val)/pow(TL_val+1108, 2);
}
template<int dim> template <typename T>
T physics_equations<dim>::free_carrier_cross_section(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
return 1.7e-24*TL_val;
}
template<int dim> template <typename T>
T physics_equations<dim>::free_carrier_cross_section(const T &TL_val) const
{
return 1.7e-24*TL_val;
}
template<int dim> template <typename T>
T physics_equations<dim>::reflectivity(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
return 0.3+5e-5*(TL_val-300);
}
template<int dim> template <typename T>
T physics_equations<dim>::reflectivity(const T &TL_val) const
{
return 0.3+5e-5*(TL_val-300);
}
template<int dim> template <typename T>
T physics_equations<dim>::impact_ionization_coefficient(const typename enable_if<has_toDim<T>::value, T>::type &TE_val, const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T bandgap_energy = E_g(TL_val);
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = 3.6e10*exp(-1.5*bandgap_energy[i]/(boltzmann_constant*TE_val[i]));
return return_value;
}
// template<int dim> template <typename T>
// T physics_equations<dim>::impact_ionization_coefficient(const T &TE_val, const T &TL_val) const
// {
// T bandgap_energy = E_g(TL_val);
// return 3.6e10*exp(-1.5*bandgap_energy/(boltzmann_constant*TE_val));
// }
template<int dim> template <typename T, typename U>
T physics_equations<dim>::impact_ionization_coefficient(const T &TE_val, const U &TL_val) const
{
U bandgap_energy = E_g(TL_val);
return 3.6e10*exp(-1.5*bandgap_energy/(boltzmann_constant * TE_val));
}
template<int dim> template <typename T>
T physics_equations<dim>::dNdt_prefactor(const typename enable_if<has_toDim<T>::value, T>::type &TE_val, const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
return this->E_g(TL_val)+this->boltzmann_constant*TE_val*3;
}
template<int dim> template <typename T>
T physics_equations<dim>::dNdt_prefactor(const T &TE_val, const T &TL_val) const
{
return this->E_g(TL_val)+this->boltzmann_constant*TE_val*3;
}
template<int dim> template <typename T>
T physics_equations<dim>::heat_capacity(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
T return_value;
for(size_t i = 0; i < dim; ++i)
return_value[i] = 22.81719 + 3.899510 * (TL_val[i]/1000) - 0.082885 * pow(TL_val[i]/1000, 2) + 0.042111 * pow(TL_val[i]/1000, 3) - 0.354063 * pow(TL_val[i]/1000, -2); //(NIST)//24.5+1.5e3*TL_val[i]/1000-4.37e-5*pow(TL_val[i]/1000, -2);
return return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::heat_capacity(const T &TL_val) const
{
T local_T_val = TL_val / 1;
return 22.81719 + 3.899510 * local_T_val - 0.082885 * pow(local_T_val, 2) + 0.042111 * pow(local_T_val, 3) - 0.354063 * pow(local_T_val, -2); //(NIST)
//24.5+1.5*TL_val/1000-4.37*pow(TL_val/1000, -2);//Temporary fix
}
template<int dim> template <typename T>
T physics_equations<dim>::integrate_heat_capacity(const typename enable_if<has_toDim<T>::value, T>::type &TL_val) const
{
double T_lower = this->melting_temperature - this->temperature_delta_T;
double T_upper = this->melting_temperature + this->temperature_delta_T;
double T_tmp = 0*TL_val*T_lower*T_upper;//TBD
(void) T_tmp;
return 28.9;//
}
template<int dim> template <typename T>
T physics_equations<dim>::integrate_heat_capacity(const T &TL_val) const
{
double T_lower = this->melting_temperature - this->temperature_delta_T;
double T_upper = this->melting_temperature + this->temperature_delta_T;
(void) T_lower;
(void) T_upper;
(void) TL_val;
//return 0*TL_val*T_lower*T_upper;//TBD
return 28.9;//TBD
}
template<int dim> template <typename T>
T physics_equations<dim>::c_app_Tensor(const T &TL_val) const
{
double T_lower = this->melting_temperature - this->temperature_delta_T;
double T_upper = this->melting_temperature + this->temperature_delta_T;
T return_value;
for(size_t i = 0; i < dim; ++i)
{
if(TL_val[i] < T_upper && TL_val[i] > T_lower)
return_value[i] = this->integrate_heat_capacity(TL_val[i]);
else
return_value[i] = this->heat_capacity(TL_val[i]);
}
return 0;//return_value;
}
template<int dim> template <typename T>
T physics_equations<dim>::c_app(const T &TL_val) const
{
T T_lower = this->melting_temperature - this->temperature_delta_T;
T T_upper = this->melting_temperature + this->temperature_delta_T;
(void) T_lower;
(void) T_upper;
if(TL_val < T_upper && TL_val > T_lower)
return this->integrate_heat_capacity(TL_val)/molar_mass_volume;
else
return this->heat_capacity(TL_val)/molar_mass_volume;
}
template<int dim> template <typename T>
T physics_equations<dim>::c_e(const typename enable_if<has_toDim<T>::value, T>::type &N_val) const
{
return boltzmann_constant*N_val*3;
}
template<int dim> template <typename T>
T physics_equations<dim>::c_e(const T &N_val) const
{
return boltzmann_constant*N_val*3;
}
template <typename T>
T alpha_1(const T energy)
{
return 0.504 * sqrt(energy) + 392 * pow(energy - 0.0055, 2);
}
template <typename T>
T alpha_2(const T energy)
{
return 18.08 * sqrt(energy) + 5760 * pow(energy - 0.0055, 2);
}
template<int dim> template<typename T>
T physics_equations<dim>::one_photon_absorption(const T lattice_temperature) const
{
// const double photon_energy = photon_energy_func() / electron_charge;
// //const double alpha_1 = 0.504 * sqrt(photon_energy) + 0.068 * pow(photon_energy - 0.0055, 2);
// const double theta_1 = 212;
// //const double alpha_2 = 18.08 * sqrt(photon_energy) + 1 * pow(photon_energy - 0.0055, 2);
// const double theta_2 = 670;
// //const double alpha[] = {alpha_1, alpha_2};
// const double theta[] = {theta_1, theta_2};
// T bandgap_energy = E_g(lattice_temperature) / electron_charge;
// //std::cout << "Alpha_1 is " << alpha_1 << " and alpha_2 is " << alpha_2 << '\n';
// std::cout << "Bandgap energy is " << bandgap_energy << '\n';
// T absorption_coefficient = 0;
// for(size_t i = 1; i <= 2; ++i)
// for(size_t l = 1; l <= 2; ++l)
// {
// T alpha_val = 0;
// if(i == 1)
// alpha_val = alpha_1(photon_energy - bandgap_energy + pow(-1, l) * theta[i-1]);
// else
// alpha_val = alpha_2(photon_energy - bandgap_energy + pow(-1, l) * theta[i-1]);
// //std::cout << "Absorption coefficient (" << i << ", " << l << ") is " << pow(-1, l) * (alpha[i-1] * (photon_energy - bandgap_energy + pow(-1, l) * theta[i-1]))/(exp(pow(-1, l) * theta[i-1]/lattice_temperature) - 1) << '\n';
// std::cout << "Absorption coefficient (" << i << ", " << l << ") is " << pow(-1, l) * (alpha_val)/(exp(pow(-1, l) * theta[i-1]/lattice_temperature) - 1) << '\n';
// }
(void) lattice_temperature;
return one_photon_absorption_coefficient;
}
template<int dim> template <typename T>
T physics_equations<dim>::beta_f_func(const T x, const unsigned int n) const
{
return (M_PI*boost::math::double_factorial<double>(2*n+1)/(pow(2, n+2)*boost::math::factorial<double>(n+2)))*pow(2*x, -5)*pow(2*x-1, n+2);
}
template<int dim> template <typename T>
T physics_equations<dim>::two_photon_absorption(const T lattice_temperature) const
{
const T E_gi = E_g(lattice_temperature);
const T beta_f_constant = hbar_val*w0_val/E_gi;
T beta_val = 2*43e-11*(beta_f_func(beta_f_constant, 0)+beta_f_func(beta_f_constant, 1)+beta_f_func(beta_f_constant, 2));
return beta_val;
}
template<int dim> template<typename T>
T physics_equations<dim>::three_photon_absorption(const T lattice_temperature) const
{
const T E_gi = E_g(lattice_temperature);
const T gamma_val = 1.54e-3*1e-6*1e-18*pow(E_gi/(hbar_val*w0_val), 9)*pow(hbar_val*w0_val/E_gi-1.0/3.0, 2);
return gamma_val;
}
template<int dim>
double physics_equations<dim>::photon_energy_func() const
{
return planck_constant*speed_of_light/wavelength;
}
template<int dim>
double physics_equations<dim>::auger_recombination_coefficient() const
{
return 0;
}
template <int dim>
double pulse_size_prefactor(const Point<dim> p)
{
return exp(-(pow(p[0], 2)/(2*pow(INNER_CIRCLE_RADIUS, 2))+pow(p[1], 2)/(2*pow(INNER_CIRCLE_RADIUS, 2))));
}
template <int dim, typename T, typename U>
T full_equation_electron_temperature(const physics_equations<dim> &local_equations, const T &val_TE, const T &val_TE_old, const T &val_TL, const T &val_TL_old, const T &val_N, const T &val_N_old,
const T &thermal_source_TE, const T &thermal_source_TE_old, const T &grad_TE, const T &grad_TE_old,
const U &fe_values, const U &fe_gradients, const double &time_step, const double &theta)
{
return (((val_TE - val_TE_old)/time_step) * fe_values
+ (theta * pow(val_TE, 2) * grad_TE + (1 - theta) * pow(val_TE_old, 2) * grad_TE_old) * fe_gradients);
}
template <typename T>
T calculate_heat_source_TE(const double wavelength, const double I_val, const T lattice_temperature, const T free_carrier_concentration, const int dim)
{
//std::cout << "Intensity is " << I_val << "\n";
physics_equations<2> local_equations(wavelength);
(void) dim;
// T TL_val = local_equations.ambient_temperature_II;
// T return_value = local_equations.impact_ionization_coefficient(electron_temperature, TL_val) * local_equations.carrier_density;
// double return_value_II = 0;
// return_value_II += local_equations.one_photon_absorption() * I_val/local_equations.photon_energy_func()
// + local_equations.two_photon_absorption() * pow(I_val, 2)/(2*local_equations.photon_energy_func())
// + local_equations.three_photon_absorption() * pow(I_val, 3)/(3*local_equations.photon_energy_func());
// return_value_II -= local_equations.auger_recombination_coefficient() * pow(local_equations.carrier_density, 3);
// return return_value + (return_value_II);
return local_equations.one_photon_absorption(lattice_temperature) * I_val
+ local_equations.two_photon_absorption(lattice_temperature) * pow(I_val, 2)
+ local_equations.three_photon_absorption(lattice_temperature) * pow(I_val, 3)
+ local_equations.free_carrier_cross_section(lattice_temperature) * free_carrier_concentration * I_val;
}
double calculate_gaussian_pulse(const double t0, const double pulse_length)
{
return exp(-pow(t0, 2)/(2 * pulse_length*pulse_length));
}
template <int dim>
class InitialValues : public Function<dim>
{
public:
InitialValues() : Function<dim>(3 * dim) {}
virtual double value(const Point<dim> &p, const unsigned int component) const;
virtual void vector_value(const Point<dim> &p, Vector<double> &values) const;
};
template <int dim>
double InitialValues<dim>::value(const Point<dim> &p, const unsigned int component) const
{
(void) p;
(void) component;
physics_equations<dim> local_equations(0);
(void) local_equations;
return 0;
if(component < dim)
return 1;
else
if(component < 2 * dim)
return 2;
else
return 3;
}
template <int dim>
void InitialValues<dim>::vector_value(const Point<dim> &p, Vector<double> &values) const
{
for(size_t i = 0; i < values.size(); ++i)
values[i] = value(p, i);
}
template <int dim>
class MinimalSurfaceProblem
{
public:
MinimalSurfaceProblem (const char * file_name);
~MinimalSurfaceProblem ();
void run ();
private:
void setup_system (const bool initial_step);
void setup_matrices(const IndexSet &partitioner, const IndexSet &relevant_partitioner);
void assemble_system (const double Light_intensity, const double Light_intensity_old);
void solve (const double I_val, const double I_val_old);
void refine_mesh ();
void set_boundary_values ();
double compute_residual (const double alpha, const double Light_intensity, const double Light_intensity_old);
double determine_step_length ();
double recalculate_step_length(const double I_val, const double I_val_old);
void output_results(const int cycle) const;
void print_usage_message(void);
void declare_parameters(void);
void parse_parameters(void);
MPI_Comm mpi_communicator;
parallel::distributed::Triangulation<dim> triangulation;
const size_t n_components;
DoFHandler<dim> dof_handler;
FESystem<dim> fe;
IndexSet locally_owned_dofs;
IndexSet locally_relevant_dofs;
ConstraintMatrix hanging_node_constraints;
ConstraintMatrix newton_constraints;
ConstraintMatrix boundary_constraints;
LinearAlgebraTrilinos::MPI::SparseMatrix system_matrix;
LinearAlgebraTrilinos::MPI::Vector present_solution;
LinearAlgebraTrilinos::MPI::Vector old_solution;
LinearAlgebraTrilinos::MPI::Vector newton_update;
LinearAlgebraTrilinos::MPI::Vector system_rhs;
LinearAlgebraTrilinos::MPI::Vector residual;
LinearAlgebraTrilinos::MPI::Vector evaluation_point;
LinearAlgebraTrilinos::MPI::Vector extension_vector;
ConditionalOStream pcout;
std::string log_file_name;
std::ofstream file_out_stream;
ParameterHandler prm;
/*const*/ size_t max_grid_level;
/*const*/ size_t min_grid_level;
/*const*/ size_t max_inner_iterations;
/*const*/ size_t max_same_res_values;
double start_time;
/*const*/ double max_time;
/*const*/ double time_step;
/*const*/ double theta;
double alpha_val;
double pulse_intensity;
double pulse_duration;
double beam_width;
double focus_width;
double pulse_wavelength;
const size_t Free_Carriers = 0;
const size_t Electron_Temperature = dim;
const size_t Lattice_Temperature = 2 * dim;
};
// @sect3{Boundary condition}
template <int dim>
class BoundaryValuesCarriers : public Function<dim>
{
public:
BoundaryValuesCarriers (const size_t n_components) : Function<dim>(dim), n_components(n_components) {}
virtual double value (const Point<dim> &p,
const unsigned int component = 0) const;
virtual void vector_value(const Point<dim> &p, Vector<double> &value) const;
private:
const size_t n_components;
};
template <int dim>
double BoundaryValuesCarriers<dim>::value (const Point<dim> &p,
const unsigned int component) const
{
(void) component;
(void) p;
physics_equations<dim> local_equations(0);
return local_equations.initial_carrier_density;
//return std::sin(2 * numbers::PI * (p[0]+p[1]));
}
template <int dim>
void BoundaryValuesCarriers<dim>::vector_value(const Point<dim> &p, Vector<double> &value) const
{
for(size_t i = 0; i < value.size(); ++i)
value[i] = BoundaryValuesCarriers<dim>::value(p, i);
}
template <int dim>
class BoundaryValuesTemperatures : public Function<dim>
{
public:
BoundaryValuesTemperatures (const size_t n_components) : Function<dim>(3 * dim), n_components(n_components) {}
virtual double value (const Point<dim> &p,
const unsigned int component = 0) const;
virtual void vector_value(const Point<dim> &p, Vector<double> &value) const;
private:
const size_t n_components;
};
template <int dim>
double BoundaryValuesTemperatures<dim>::value (const Point<dim> &p,
const unsigned int component) const
{
physics_equations<dim> local_equations(0);
(void) local_equations;
//return 0;
return std::sin(2 * numbers::PI * (p[0]+p[1]));
}
template <int dim>
void BoundaryValuesTemperatures<dim>::vector_value(const Point<dim> &p, Vector<double> &value) const
{
for(size_t i = 0; i < value.size(); ++i)
value[i] = BoundaryValuesTemperatures<dim>::value(p, i);
}
template <int dim>
MinimalSurfaceProblem<dim>::MinimalSurfaceProblem (const char *file_name)
:
mpi_communicator(MPI_COMM_WORLD),
triangulation(mpi_communicator,
typename Triangulation<dim>::MeshSmoothing(Triangulation<dim>::smoothing_on_refinement | Triangulation<dim>::smoothing_on_coarsening)),
n_components(3),
dof_handler (triangulation),
fe (FE_Q<dim>(2), n_components * dim),
pcout(std::cout, (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)),
alpha_val(0.1)
{
this->declare_parameters();
prm.parse_input(file_name);
this->parse_parameters();
}
template <int dim>
MinimalSurfaceProblem<dim>::~MinimalSurfaceProblem ()
{
file_out_stream.close();
dof_handler.clear ();
}
template <int dim>
void MinimalSurfaceProblem<dim>::print_usage_message()
{
static const char *message
=
"\n"
"TTM-calculator for SI.\n"
"\n"
"Usage:\n"
" ./main [-p parameter_file]\n"
"\n"
"The parameter file has the following format and allows the following\n"
"values (you can cut and paste this and use it for your own parameter\n"
"file):\n"
"\n";
std::cout << message;
prm.print_parameters (std::cout, ParameterHandler::Text);
}
template <int dim>
void MinimalSurfaceProblem<dim>::declare_parameters()
{
prm.enter_subsection("File processing data");
{
prm.declare_entry("Use stdcout", "true", Patterns::Bool(), "If set to true, stdcout will be used, else a file will be used");
prm.declare_entry("Log file name", "log_file.txt", Patterns::FileName(), "Name of the log file to be used. Old files will be overwritten!");
}
prm.leave_subsection();
prm.enter_subsection("Grid generation data");
{
prm.declare_entry("Minimal grid density", "2", Patterns::Integer(), "Value for the minimal grid density");
prm.declare_entry("Maximal grid density", "8", Patterns::Integer(), "Value for the maximum grid density");
}
prm.leave_subsection();
prm.enter_subsection("Pulse data");
{
prm.declare_entry("Maximum pulse energy", "1e6", Patterns::Double());
prm.declare_entry("Pulse duration", "1e-12", Patterns::Double());
prm.declare_entry("Pulse focus size", "1e-6", Patterns::Double());
prm.declare_entry("Original beam radius", "1e-3", Patterns::Double());
prm.declare_entry("Pulse wavelength", "1.2e-6", Patterns::Double());
}
prm.leave_subsection();
prm.enter_subsection("Simulation parameters");
{
prm.declare_entry("Absolute time step", "-1", Patterns::Double(), "If empty, a relative time step can be set");
prm.declare_entry("Relative time step", "-1", Patterns::Double(), "Time step relative to pulse length");
prm.declare_entry("Maximum inner iterations", "10", Patterns::Integer());
prm.declare_entry("Max equal values for residual", "10", Patterns::Integer());
prm.declare_entry("Theta", "0.5", Patterns::Double());
prm.declare_entry("Absolute starting time", "-1", Patterns::Double());
prm.declare_entry("Absolute maximum time", "-1", Patterns::Double());
prm.declare_entry("Relative starting time", "-1", Patterns::Double());
prm.declare_entry("Relative maximum time", "-1", Patterns::Double());
}
prm.leave_subsection();
}
template <int dim>
void MinimalSurfaceProblem<dim>::parse_parameters()
{
prm.enter_subsection("File processing data");
{
const bool use_stdcout = prm.get_bool("Use stdcout");
log_file_name = prm.get("Log file name");
// if(use_stdcout)
// pcout = ConditionalOStream::ConditionalOStream(std::cout, (Utilities::MPI::this_mpi_process(mpi_communicator) == 0));
// else
// {
// file_out_stream.open(log_file_name, std::ios::out | std::ios::app);
// pcout = ConditionalOStream::ConditionalOStream(file_out_stream, (Utilities::MPI::this_mpi_process(mpi_communicator) == 0));
// }
}
prm.leave_subsection();
prm.enter_subsection("Grid generation data");
{
min_grid_level = prm.get_integer("Minimal grid density");
max_grid_level = prm.get_integer("Maximal grid density");
}
prm.leave_subsection();
print_status_update(pcout, std::string("Got minimal and maximal grid level\n"), true);
prm.enter_subsection("Pulse data");
{
const double pulse_energy = prm.get_double("Maximum pulse energy");
pulse_duration = prm.get_double("Pulse duration");
focus_width = prm.get_double("Pulse focus size");
beam_width = prm.get_double("Original beam radius");
pulse_wavelength = prm.get_double("Pulse wavelength");
pulse_intensity = pow(beam_width, 2)/pow(focus_width, 2) * pulse_energy/pulse_duration;
}