-
Notifications
You must be signed in to change notification settings - Fork 47
/
cracks.cc
4700 lines (3743 loc) · 151 KB
/
cracks.cc
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
/**
This code is licensed under the "GNU GPL version 2 or later". See
LICENSE file or https://www.gnu.org/licenses/gpl-2.0.html
Copyright 2013-2020: Thomas Wick and Timo Heister
*/
// Main features of this crack phase-field program
// -----------------------------------------------
// 1. Quasi-monolithic formulation for the displacement-phase-field system
// 2. Primal dual active set strategy to treat crack irreversibility
// 3. Predictor-corrector mesh adaptivity
// 4. Parallel computing using MPI, p4est, and trilinos
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/logstream.h>
#include <deal.II/base/function.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/timer.h>
#include <deal.II/base/table_handler.h>
#include <deal.II/base/parameter_handler.h>
#include <deal.II/base/function_parser.h>
#include <deal.II/lac/block_vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/block_sparse_matrix.h>
#include <deal.II/lac/sparse_direct.h>
#if DEAL_II_VERSION_GTE(9,1,0)
# include <deal.II/lac/affine_constraints.h>
using ConstraintMatrix = dealii::AffineConstraints<double>;
#else
# include <deal.II/lac/constraint_matrix.h>
# include <deal.II/grid/tria_boundary_lib.h>
#endif
namespace compatibility
{
template<int dim>
using ZeroFunction = dealii::Functions::ZeroFunction<dim>;
}
// This makes IDEs like QtCreator happy (note that this is defined in cmake):
#ifndef SOURCE_DIR
#define SOURCE_DIR ""
#endif
#include <deal.II/lac/solver_gmres.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/grid_tools.h>
#include <deal.II/grid/grid_in.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_renumbering.h>
#include <deal.II/dofs/dof_accessor.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/fe/fe_q.h>
#include <deal.II/fe/fe_dgq.h>
#include <deal.II/fe/fe_dgp.h>
#include <deal.II/fe/fe_system.h>
#include <deal.II/fe/fe_values.h>
#include <deal.II/fe/mapping_q1.h>
#include <deal.II/numerics/error_estimator.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/solution_transfer.h>
#include <deal.II/lac/generic_linear_algebra.h>
namespace LA
{
using namespace dealii::LinearAlgebraTrilinos;
}
#include <deal.II/distributed/tria.h>
#include <deal.II/distributed/grid_refinement.h>
#include <deal.II/distributed/solution_transfer.h>
#include <fstream>
#include <sstream>
#include <sys/stat.h> // for mkdir
#define CATCH_CONFIG_RUNNER
#include "contrib/catch.hpp"
using namespace dealii;
namespace compatibility
{
/**
* Split the set of DoFs (typically locally owned or relevant) in @p whole_set into blocks
* given by the @p dofs_per_block structure.
*/
void split_by_block (const std::vector<types::global_dof_index> &dofs_per_block,
const IndexSet &whole_set,
std::vector<IndexSet> &partitioned)
{
const unsigned int n_blocks = dofs_per_block.size();
partitioned.clear();
partitioned.resize(n_blocks);
types::global_dof_index start = 0;
for (unsigned int i=0; i<n_blocks; ++i)
{
partitioned[i] = whole_set.get_view(start, start + dofs_per_block[i]);
start += dofs_per_block[i];
}
}
}
// For Example 3 (multiple cracks in a heterogenous medium)
// reads .pgm file and returns it as floating point values
// taken from step-42
class BitmapFile
{
public:
BitmapFile(const std::string &name);
double
get_value(const double x, const double y) const;
private:
std::vector<double> image_data;
double hx, hy;
int nx, ny;
double
get_pixel_value(const int i, const int j) const;
};
// The constructor of this class reads in the data that describes
// the obstacle from the given file name.
BitmapFile::BitmapFile(const std::string &name)
:
image_data(0),
hx(0),
hy(0),
nx(0),
ny(0)
{
std::ifstream f(name.c_str());
AssertThrow (f, ExcMessage (std::string("Can't read from file <") +
name + ">!"));
std::string temp;
getline(f, temp);
f >> temp;
if (temp[0]=='#')
getline(f, temp);
f >> nx >> ny;
AssertThrow(nx > 0 && ny > 0, ExcMessage("Invalid file format."));
for (int k = 0; k < nx * ny; k++)
{
unsigned int val;
f >> val;
image_data.push_back(val / 255.0);
}
hx = 1.0 / (nx - 1);
hy = 1.0 / (ny - 1);
}
// The following two functions return the value of a given pixel with
// coordinates $i,j$, which we identify with the values of a function
// defined at positions <code>i*hx, j*hy</code>, and at arbitrary
// coordinates $x,y$ where we do a bilinear interpolation between
// point values returned by the first of the two functions. In the
// second function, for each $x,y$, we first compute the (integer)
// location of the nearest pixel coordinate to the bottom left of
// $x,y$, and then compute the coordinates $\xi,\eta$ within this
// pixel. We truncate both kinds of variables from both below
// and above to avoid problems when evaluating the function outside
// of its defined range as may happen due to roundoff errors.
double
BitmapFile::get_pixel_value(const int i,
const int j) const
{
assert(i >= 0 && i < nx);
assert(j >= 0 && j < ny);
return image_data[nx * (ny - 1 - j) + i];
}
double
BitmapFile::get_value(const double x,
const double y) const
{
const int ix = std::min(std::max((int) (x / hx), 0), nx - 2);
const int iy = std::min(std::max((int) (y / hy), 0), ny - 2);
const double xi = std::min(std::max((x-ix*hx)/hx, 1.), 0.);
const double eta = std::min(std::max((y-iy*hy)/hy, 1.), 0.);
return ((1-xi)*(1-eta)*get_pixel_value(ix,iy)
+
xi*(1-eta)*get_pixel_value(ix+1,iy)
+
(1-xi)*eta*get_pixel_value(ix,iy+1)
+
xi*eta*get_pixel_value(ix+1,iy+1));
}
template <int dim>
class BitmapFunction : public Function<dim>
{
public:
BitmapFunction(const std::string &filename,
double x1_, double x2_, double y1_, double y2_, double minvalue_, double maxvalue_)
: Function<dim>(1),
f(filename), x1(x1_), x2(x2_), y1(y1_), y2(y2_), minvalue(minvalue_), maxvalue(maxvalue_)
{}
virtual
double value (const Point<dim> &p,
const unsigned int /*component*/) const
{
double x = (p(0)-x1)/(x2-x1);
double y = (p(1)-y1)/(y2-y1);
if (dim == 2)
return minvalue + f.get_value(x,y)*(maxvalue-minvalue);
else if (dim == 3)
{
double z = (p(2)-y1)/(y2-y1);
return minvalue + (
f.get_value(x/10.0,(y-z)/10.0)
+0.5*f.get_value((x+y)/2.0,(z+x)/2.0)
+0.25*f.get_value(fmod(z+x-y,10.0), fmod(y+x,10.0))
)*(maxvalue-minvalue)/2.25;
}
}
private:
BitmapFile f;
double x1,x2,y1,y2;
double minvalue, maxvalue;
};
// Define some tensors for cleaner notation later.
namespace Tensors
{
template <int dim>
inline Tensor<1, dim>
get_grad_pf (
unsigned int q,
const std::vector<std::vector<Tensor<1, dim> > > &old_solution_grads)
{
Tensor<1, dim> grad_pf;
grad_pf[0] = old_solution_grads[q][dim][0];
grad_pf[1] = old_solution_grads[q][dim][1];
if (dim == 3)
grad_pf[2] = old_solution_grads[q][dim][2];
return grad_pf;
}
template <int dim>
inline Tensor<2, dim>
get_grad_u (
unsigned int q,
const std::vector<std::vector<Tensor<1, dim> > > &old_solution_grads)
{
Tensor<2,dim> grad_u;
grad_u[0][0] = old_solution_grads[q][0][0];
grad_u[0][1] = old_solution_grads[q][0][1];
grad_u[1][0] = old_solution_grads[q][1][0];
grad_u[1][1] = old_solution_grads[q][1][1];
if (dim == 3)
{
grad_u[0][2] = old_solution_grads[q][0][2];
grad_u[1][2] = old_solution_grads[q][1][2];
grad_u[2][0] = old_solution_grads[q][2][0];
grad_u[2][1] = old_solution_grads[q][2][1];
grad_u[2][2] = old_solution_grads[q][2][2];
}
return grad_u;
}
template <int dim>
inline Tensor<2, dim>
get_Identity ()
{
Tensor<2, dim> identity;
identity[0][0] = 1.0;
identity[1][1] = 1.0;
if (dim == 3)
identity[2][2] = 1.0;
return identity;
}
template <int dim>
inline Tensor<1, dim>
get_u (
unsigned int q,
const std::vector<Vector<double> > &old_solution_values)
{
Tensor<1, dim> u;
u[0] = old_solution_values[q](0);
u[1] = old_solution_values[q](1);
if (dim == 3)
u[2] = old_solution_values[q](2);
return u;
}
template <int dim>
inline Tensor<1, dim>
get_u_LinU (
const Tensor<1, dim> &phi_i_u)
{
Tensor<1, dim> tmp;
tmp[0] = phi_i_u[0];
tmp[1] = phi_i_u[1];
if (dim == 3)
tmp[2] = phi_i_u[2];
return tmp;
}
template <int dim>
inline
double
get_divergence_u (const Tensor<2,dim> grad_u)
{
double tmp;
if (dim == 2)
{
tmp = grad_u[0][0] + grad_u[1][1];
}
else if (dim == 3)
{
tmp = grad_u[0][0] + grad_u[1][1] + grad_u[2][2];
}
return tmp;
}
}
// Several classes for initial (phase-field) values
// Here, we prescribe initial (multiple) cracks
template <int dim>
class InitialValuesSneddon : public Function<dim>
{
public:
InitialValuesSneddon (const unsigned int n_components, const double min_cell_diameter)
:
Function<dim>(n_components),
n_components (n_components),
_min_cell_diameter(min_cell_diameter)
{}
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 unsigned int n_components;
double _min_cell_diameter;
};
template <int dim>
double
InitialValuesSneddon<dim>::value (
const Point<dim> &p, const unsigned int component) const
{
// impose crack [-1,1]x[-h,h]
double l_0 = 1.0;
double thickness = 2.0*_min_cell_diameter;
double r_squared;
if (dim == 2)
r_squared = p(0)*p(0);
else
r_squared = p(0)*p(0)+p(2)*p(2);
if (component == dim)
{
if ( (r_squared <= l_0*l_0)
&&
(abs(2.0*p(1)) <= thickness) )
return 0.0;
else
return 1.0;
}
else
return 0.0;
}
template <int dim>
void
InitialValuesSneddon<dim>::vector_value (
const Point<dim> &p, Vector<double> &values) const
{
for (unsigned int comp = 0; comp < this->n_components; ++comp)
values(comp) = InitialValuesSneddon<dim>::value(p, comp);
}
template <int dim>
class ExactPhiSneddon : public Function<dim>
{
public:
ExactPhiSneddon (const int n_components, const double eps_)
:
Function<dim>(n_components),
eps(eps_)
{
}
virtual double
value (
const Point<dim> &p, const unsigned int component = 0) const
{
(void)component;
double l_0 = 1.0;
Point<dim> left;
left(0)=-l_0;
Point<dim> right;
right(0)=l_0;
double dist;
if (p(0)<left(0))
dist = left.distance(p);
else if (p(0)>right(0))
dist = right.distance(p);
else
dist = (dim==2)? (std::sqrt(p(1)*p(1))) : (std::sqrt(p(1)*p(1)+p(2)*p(2)));
return 1.0 - std::exp(-dist/eps);
}
private:
double eps;
};
template <int dim>
class SneddonExactPostProc : public DataPostprocessorScalar<dim>
{
public:
SneddonExactPostProc (const unsigned int n_components, const double eps)
:
DataPostprocessorScalar<dim> ("exact_phi", update_quadrature_points),
exact(n_components, eps)
{}
void evaluate_vector_field (const DataPostprocessorInputs::Vector<dim> &input_data,
std::vector<Vector<double> > &computed_quantities) const
{
for (unsigned int i=0; i<computed_quantities.size(); ++i)
computed_quantities[i][0] = exact.value(input_data.evaluation_points[i]);
}
private:
ExactPhiSneddon<dim> exact;
};
// Class for initial values multiple fractures in a homogeneous material
template <int dim>
class InitialValuesMultipleHomo : public Function<dim>
{
public:
InitialValuesMultipleHomo (const unsigned int n_components, const double min_cell_diameter)
:
Function<dim> (n_components),
n_components (n_components),
_min_cell_diameter (min_cell_diameter)
{}
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 unsigned int n_components;
double _min_cell_diameter;
};
template <int dim>
double
InitialValuesMultipleHomo<dim>::value (
const Point<dim> &p, const unsigned int component) const
{
double width = _min_cell_diameter;
double height = _min_cell_diameter;
// Defining the initial crack(s)
// 0 = crack
// 1 = no crack
bool example_3 = true;
if (component == n_components-1)
{
if (example_3)
{
// Example 3 of our paper
if (((p(0) >= 2.5 - width/2.0) && (p(0) <= 2.5 + width/2.0))
&& ((p(1) >= 0.8) && (p(1) <= 1.5)))
return 0.0;
else if (((p(0) >= 0.5) && (p(0) <= 1.5))
&& ((p(1) >= 3.0 - height/2.0) && (p(1) <= 3.0 + height/2.0)))
return 0.0;
else
return 1.0;
}
else
{
// Two parallel fractures
if (((p(0) >= 1.6 - width) && (p(0) <= 2.4 + width))
&& ((p(1) >= 2.75 - height) && (p(1) <= 2.75 + height)))
return 0.0;
else if (((p(0) >= 1.6 - width) && (p(0) <= 2.4 + width))
&& ((p(1) >= 1.25 - height) && (p(1) <= 1.25 + height)))
return 0.0;
else
return 1.0;
}
}
return 0.0;
}
template <int dim>
void
InitialValuesMultipleHomo<dim>::vector_value (
const Point<dim> &p, Vector<double> &values) const
{
for (unsigned int comp = 0; comp < this->n_components; ++comp)
values(comp) = InitialValuesMultipleHomo<dim>::value(p, comp);
}
// Class for initial values multiple fractures in a heterogeneous material
template <int dim>
class InitialValuesMultipleHet : public Function<dim>
{
public:
InitialValuesMultipleHet (const unsigned int n_components, const double min_cell_diameter)
:
Function<dim> (n_components),
n_components (n_components),
_min_cell_diameter (min_cell_diameter)
{}
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 unsigned int n_components;
double _min_cell_diameter;
};
template <int dim>
double
InitialValuesMultipleHet<dim>::value (
const Point<dim> &p, const unsigned int component) const
{
double width = _min_cell_diameter;
double height = _min_cell_diameter;
// Defining the initial crack(s)
// 0 = crack
// 1 = no crack
bool example_3 = true;
if (component == n_components-1)
{
if (dim == 3)
{
if (((p(0) >= 2.6 - width/2.0) && (p(0) <= 2.6 + width/2.0))
&& ((p(1) >= 3.8 - width/2.0) && (p(1) <= 5.5 + width/2.0))
&& (p(2) >= 4.0 - width/2.0) && (p(2) <= 4.0 + width/2.0)
)
return 0.0;
else if (((p(0) >= 5.5 - width/2.0) && (p(0) <= 7.0 + width/2.0))
&& ((p(1) >= 4.0 - width/2.0) && (p(1) <= 4.0 + width/2.0))
&& (p(2) >= 6.0 - width/2.0) && (p(2) <= 6.0 + width/2.0)
)
return 0.0;
else
return 1.0;
}
else if (example_3)
{
// Example 3 of our paper
if (((p(0) >= 2.5 - width/2.0) && (p(0) <= 2.5 + width/2.0))
&& ((p(1) >= 0.8) && (p(1) <= 1.5)))
return 0.0;
else if (((p(0) >= 0.5) && (p(0) <= 1.5))
&& ((p(1) >= 3.0 - height/2.0) && (p(1) <= 3.0 + height/2.0)))
return 0.0;
else
return 1.0;
}
else
{
// Two parallel fractures
if (((p(0) >= 1.6 - width) && (p(0) <= 2.4 + width))
&& ((p(1) >= 2.75 - height) && (p(1) <= 2.75 + height)))
return 0.0;
else if (((p(0) >= 1.6 - width) && (p(0) <= 2.4 + width))
&& ((p(1) >= 1.25 - height) && (p(1) <= 1.25 + height)))
return 0.0;
else
return 1.0;
}
}
return 0.0;
}
template <int dim>
void
InitialValuesMultipleHet<dim>::vector_value (
const Point<dim> &p, Vector<double> &values) const
{
for (unsigned int comp = 0; comp < this->n_components; ++comp)
values(comp) = InitialValuesMultipleHet<dim>::value(p, comp);
}
template <int dim>
class InitialValuesTensionOrShear : public Function<dim>
{
public:
InitialValuesTensionOrShear (const unsigned int n_components,
const double min_cell_diameter)
:
Function<dim> (n_components),
n_components (n_components),
_min_cell_diameter (min_cell_diameter)
{}
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 unsigned int n_components;
double _min_cell_diameter;
};
template <int dim>
double
InitialValuesTensionOrShear<dim>::value (
const Point<dim> & /*p*/, const unsigned int component) const
{
// Defining the initial crack(s)
// 0 = crack
// 1 = no crack
if (component == n_components-1)
{
return 1.0;
}
return 0.0;
}
template <int dim>
void
InitialValuesTensionOrShear<dim>::vector_value (
const Point<dim> &p, Vector<double> &values) const
{
for (unsigned int comp = 0; comp < this->n_components; ++comp)
values(comp) = InitialValuesTensionOrShear<dim>::value(p, comp);
}
template <int dim>
class InitialValuesNoCrack : public Function<dim>
{
public:
InitialValuesNoCrack (const unsigned int n_components)
:
Function<dim> (n_components),
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 unsigned int n_components;
};
template <int dim>
double
InitialValuesNoCrack<dim>::value (
const Point<dim> & /*p*/, const unsigned int component) const
{
if (component == n_components-1)
{
return 1.0;
}
return 0.0;
}
template <int dim>
void
InitialValuesNoCrack<dim>::vector_value (
const Point<dim> &p, Vector<double> &values) const
{
for (unsigned int comp = 0; comp < this->n_components; ++comp)
values(comp) = InitialValuesNoCrack<dim>::value(p, comp);
}
// Several classes for Dirichlet boundary conditions
// for displacements for the single-edge notched test (for phase-field see Miehe et al. 2010)
// Example 2a (tension test)
// Example 2b (shear test; see below)
template <int dim>
class BoundaryTensionTest : public Function<dim>
{
public:
BoundaryTensionTest (const unsigned int n_components, const double time)
: Function<dim>(n_components),
n_components (n_components),
_time (time)
{}
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 unsigned int n_components;
double _time;
};
template <int dim>
double
BoundaryTensionTest<dim>::value (const Point<dim> &p,
const unsigned int component) const
{
Assert (component < this->n_components,
ExcIndexRange (component, 0, this->n_components));
Assert(dim==2, ExcNotImplemented());
double dis_step_per_timestep = 1.0;
if (component == 1) // u_y
{
return ( ((p(1) == 1.0) && (p(0) <= 1.0) && (p(0) >= 0.0))
?
(1.0) * _time *dis_step_per_timestep : 0 );
}
return 0;
}
template <int dim>
void
BoundaryTensionTest<dim>::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
for (unsigned int c=0; c<this->n_components; ++c)
values (c) = BoundaryTensionTest<dim>::value (p, c);
}
// Dirichlet boundary conditions for
// Miehe's et al. shear test 2010
// Example 2b
template <int dim>
class BoundaryShearTest : public Function<dim>
{
public:
BoundaryShearTest (const unsigned int n_components, const double time)
: Function<dim>(n_components),
_time (time)
{}
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:
double _time;
};
template <int dim>
double
BoundaryShearTest<dim>::value (const Point<dim> &p,
const unsigned int component) const
{
Assert (component < this->n_components,
ExcIndexRange (component, 0, this->n_components));
double dis_step_per_timestep = -1.0;
if (component == 0)
{
return ( ((p(1) == 1.0) )
?
(1.0) * _time *dis_step_per_timestep : 0 );
}
return 0;
}
template <int dim>
void
BoundaryShearTest<dim>::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
for (unsigned int c=0; c<this->n_components; ++c)
values (c) = BoundaryShearTest<dim>::value (p, c);
}
template <int dim>
class BoundaryThreePoint : public Function<dim>
{
public:
BoundaryThreePoint (const unsigned int n_components, const double time)
: Function<dim>(n_components),
_time (time)
{}
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:
double _time;
};
// The boundary values are given to component
// with number 0.
template <int dim>
double
BoundaryThreePoint<dim>::value (const Point<dim> &/*p*/,
const unsigned int component) const
{
Assert (component < this->n_components,
ExcIndexRange (component, 0, this->n_components));
double dis_step_per_timestep = -1.0;
if (component == 1)
{
return 1.0 * _time *dis_step_per_timestep;
}
return 0;
}
template <int dim>
void
BoundaryThreePoint<dim>::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
for (unsigned int c=0; c<this->n_components; ++c)
values (c) = BoundaryThreePoint<dim>::value (p, c);
}
template <int dim>
struct Introspection
{
Introspection(ParameterHandler &prm);
unsigned int displacement_degree;
unsigned int n_components;
unsigned int n_blocks;
struct ComponentMasks
{
ComponentMask displacements;
ComponentMask displacement[dim];
ComponentMask phase_field;
};
ComponentMasks component_masks;
struct ComponentIndices
{
unsigned int displacement[dim];
unsigned int velocity[dim];
unsigned int phase_field;
};
ComponentIndices component_indices;
struct Extractors
{
FEValuesExtractors::Vector displacement;
FEValuesExtractors::Vector velocity;
FEValuesExtractors::Scalar phase_field;
};
Extractors extractors;
std::vector<unsigned int> components_to_blocks;
std::vector<const FiniteElement<dim,dim>*> fes;
std::vector<unsigned int> multiplicities;
};
template <int dim>
Introspection<dim>::Introspection(ParameterHandler &prm)
{
prm.enter_subsection("Global parameters");
const unsigned int degree = prm.get_integer("FE degree");
this->displacement_degree = degree;
prm.leave_subsection();
prm.enter_subsection("Solver parameters");
const bool direct_solver = prm.get_bool("Use Direct Inner Solver");
prm.leave_subsection();
fes.push_back(new FE_Q<dim>(degree));
multiplicities.push_back(dim);
fes.push_back(new FE_Q<dim>(degree));
multiplicities.push_back(1);
n_components = dim + 1;
if (direct_solver)
n_blocks = 1;
else
n_blocks = 1 + 1;
{
unsigned int c = 0;
for (unsigned int d=0; d<dim; ++d)
component_indices.displacement[d] = c++;
component_indices.phase_field = c++;
}
{
component_masks.displacements = ComponentMask(n_components, false);