-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plate_with_a_hole.h
executable file
·549 lines (498 loc) · 20.6 KB
/
Plate_with_a_hole.h
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
#include <deal.II/grid/tria.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_out.h>
#include <deal.II/grid/manifold_lib.h>
#include "../MA-Code/enumerator_list.h"
#include <iostream>
#include <fstream>
#include <cmath>
using namespace dealii;
namespace PlateWithAHole
/*
* A quarter of a plate with hole in 2D or 1/8 in 3D
*
* CERTIFIED TO STANDARD numExS07 (200724)
*/
{
// Name of the numerical example
std::string numEx_name = "PlateWithAHole";
// The loading direction: \n
// In which coordinate direction the load shall be applied, so x/y/z.
const unsigned int loading_direction = enums::y;
// The loaded faces:
const enums::enum_boundary_ids id_boundary_load = enums::id_boundary_yPlus;
const enums::enum_boundary_ids id_boundary_secondaryLoad = enums::id_boundary_xPlus;
// Some internal parameters
struct parameterCollection
{
const types::boundary_id boundary_id_hole = 10;
const types::manifold_id manifold_id_hole = 10;
const double search_tolerance = 1e-12;
};
template<int dim>
void make_constraints ( AffineConstraints<double> &constraints, const FESystem<dim> &fe, DoFHandler<dim> &dof_handler_ref,
const bool &apply_dirichlet_bc, const double ¤t_load_increment,
const Parameter::GeneralParameters ¶meter )
{
// clamping on Y0 plane: set x, y and z displacements on x0 plane to zero
numEx::BC_apply_fix( enums::id_boundary_yMinus, dof_handler_ref, fe, constraints );
// // fixed node in x-direction
// // @todo Currently we fix an entire cell face at x=0 to x=0
// if (apply_dirichlet_bc == true )
// {
// VectorTools::interpolate_boundary_values(
// dof_handler_ref,
// enums::id_boundary_xMinus,
// ZeroFunction<dim> (n_components),
// constraints,
// fe.component_mask(x_displacement)
// );
// }
// else // in the exact same manner
// {
// VectorTools::interpolate_boundary_values(
// dof_handler_ref,
// enums::id_boundary_xMinus,
// ZeroFunction<dim> (n_components),
// constraints,
// fe.component_mask(x_displacement)
// );
// }
if ( parameter.driver == 2/*Dirichlet*/ )
numEx::BC_apply( id_boundary_load, loading_direction, current_load_increment, apply_dirichlet_bc, dof_handler_ref, fe, constraints );
}
// ToDo-optimize: use existing DII command void GridGenerator::plate_with_a_hole
// to see the effects of the inputs (lengths, refinements, etc) consider using the output (.eps, etc) below
void make_2d_plate_with_hole( Triangulation<2> &tria_2d_out,
const double half_length,
//const double half_width,
const double hole_radius,
//const double hole_division_fraction,
const Parameter::GeneralParameters ¶meter )
{
Triangulation<2> tria_2d;
//const double width = 2.0*half_width;
const double hole_diameter = 2.0*hole_radius;
//const double internal_width = hole_diameter + hole_division_fraction*(width - hole_diameter);
Point<2> centre_2d(0,0);
const types::manifold_id polar_manifold_id = 0;
const types::manifold_id tfi_manifold_id = 1;
const double height2Width_ratio = 3.;
GridGenerator::plate_with_a_hole ( tria_2d,
/*inner radius*/hole_radius,
/*outer radius*/half_length/height2Width_ratio, // Width of the plate is \a length, the height is 2*length
/*pad bottom */half_length*(1.-1./height2Width_ratio),
/*pad top */half_length*(1.-1./height2Width_ratio),
/*pad left */0.,
/*pad right */0.,
centre_2d,
polar_manifold_id,
tfi_manifold_id
);
// Attach a manifold to the curved boundary and refine
// @note We can only guarantee that the vertices sit on the curve, so we must test with their position instead of the cell centre.
for (typename Triangulation<2>::active_cell_iterator
cell = tria_2d.begin_active();
cell != tria_2d.end(); ++cell)
{
for (unsigned int face=0; face<GeometryInfo<2>::faces_per_cell; ++face)
if (cell->face(face)->at_boundary())
for (unsigned int vertex=0; vertex<GeometryInfo<2>::vertices_per_face; ++vertex)
{
if (std::abs(cell->face(face)->vertex(vertex).distance(centre_2d) - hole_diameter/2.0) < 1e-12)
{
cell->face(face)->set_manifold_id(10);
break;
}
}
}
SphericalManifold<2> spherical_manifold_2d (centre_2d);
tria_2d.set_manifold(10,spherical_manifold_2d);
if ( parameter.stepwise_global_refinement==true ) // for the special case of step by step global refinement ...
tria_2d.refine_global( 1 ); // ... only refine the initial grid once
else // for the standard case of AMR refine the grid as specified in the ...
tria_2d.refine_global(parameter.nbr_global_refinements); // ...Parameter.prm file; has to be refined before the manifolds are deleted again
// AssertThrow(parameter.nbr_holeEdge_refinements==0, ExcMessage("QuarterPlate mesh creation: Sorry, right now you cannot use hole edge refinements."));
tria_2d.reset_manifold(10); // Clear manifold
// For some reason the flatten_triangulation needs to be done, else we got problems for some types of local refinements
GridGenerator::flatten_triangulation(tria_2d,tria_2d_out);
// Output the triangulation as eps or inp
numEx::output_triangulation( tria_2d_out, enums::output_eps, numEx_name );
}
// 2D grid
template <int dim>
void make_grid( Triangulation<2> &triangulation, const Parameter::GeneralParameters ¶meter )
{
parameterCollection parameters_internal;
// size of the plate divided by the size of the hole
double ratio_width_To_holeRadius = parameter.width;
double hwidth = parameter.width;
double holeRadius = parameter.holeRadius;
// size of the inner mesh (hypercube with hole) relative to size of the whole plate
//double ratio_x = parameter.ratio_x;
const double search_tolerance = parameters_internal.search_tolerance;
make_2d_plate_with_hole(
triangulation,
ratio_width_To_holeRadius, // length
//ratio_width_To_holeRadius * 1.0, // width: *1.0 => square
holeRadius, // hole radius = diameter/2
//ratio_x,
parameter
);
// Clear all existing boundary ID's
numEx::clear_boundary_IDs( triangulation );
//Set boundary IDs and manifolds
const Point<dim> centre (0,0);
for ( typename Triangulation<dim>::active_cell_iterator
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell )
{
for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
{
// at boundary
if (cell->face(face)->at_boundary())
{
//Set boundary IDs
// The bottom is now all the way down to -hwidth
if (std::abs(cell->face(face)->center()[enums::y] + hwidth) < search_tolerance)
{
cell->face(face)->set_boundary_id(enums::id_boundary_yMinus); // the bottom edge
// for (unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_face; ++vertex)
// if (std::abs(cell->vertex(vertex)[enums::y] - 0) < search_tolerance)
// if (std::abs(cell->vertex(vertex)[enums::x] - parameter.holeRadius) < search_tolerance)
// {
// // We found the cell that lies at the bottom edge next to the hole (bottom left corner)
// cell->set_material_id( enums::tracked_QP );
// break;
// }
}
else if (std::abs(cell->face(face)->center()[1] - ratio_width_To_holeRadius) < search_tolerance)
{
cell->face(face)->set_boundary_id(enums::id_boundary_yPlus); // the top edge
}
else
{
// Be aware that we have to access the vertex as cell->face->vertex
for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
if (std::abs(cell->face(face)->vertex(vertex).distance(centre) - holeRadius) < search_tolerance)
{
cell->face(face)->set_boundary_id(parameters_internal.boundary_id_hole); // the hole edge
break;
}
}
// Set manifold IDs
for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
if (std::abs(cell->vertex(vertex).distance(centre) - holeRadius) < search_tolerance)
{
cell->face(face)->set_manifold_id(parameters_internal.manifold_id_hole);
break;
}
}
}
}
static SphericalManifold<dim> spherical_manifold (centre);
triangulation.set_manifold(parameters_internal.manifold_id_hole,spherical_manifold);
// refine hole boundary
// for (unsigned int refine_counter=0; refine_counter < 2; refine_counter++)
// {
// for (typename Triangulation<dim>::active_cell_iterator
// cell = triangulation.begin_active();
// cell != triangulation.end(); ++cell)
// {
// for (unsigned int face=0; face < GeometryInfo<dim>::faces_per_cell; ++face)
// if ( cell->face(face)->boundary_id() == parameters_internal.boundary_id_hole )
// {
// cell->set_refine_flag();
// break;
// }
// }
// triangulation.execute_coarsening_and_refinement();
// }
// The following does not work?
// pre-refinement of the damaged area (around y=0)
for (unsigned int refine_counter=0; refine_counter < parameter.nbr_holeEdge_refinements; refine_counter++)
{
for (typename Triangulation<dim>::active_cell_iterator
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell)
{
if ( std::abs( cell->center()[enums::y]) < holeRadius*0.9 )
cell->set_refine_flag();
}
triangulation.execute_coarsening_and_refinement();
}
// // The x-fixed faces are set now, to get the smallest possible face
// for ( typename Triangulation<dim>::active_cell_iterator
// cell = triangulation.begin_active();
// cell != triangulation.end(); ++cell )
// {
// for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
// {
// if (cell->face(face)->at_boundary() )
// {
// if ( ( cell->face(face)->center()[enums::y] + hwidth ) < search_tolerance ) // lower face
// {
// for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
// {
// //Project the cell vertex to the XY plane and test the distance from the cylinder axis
// Point<2> vertex_v = cell->face(face)->vertex(vertex);
// Point<2> desired_mid_point (0,-hwidth);
//
// if (std::abs(vertex_v.distance(desired_mid_point)) < search_tolerance)
// {
// std::cout << "found l at " << vertex_v << std::endl;
// cell->face(face)->set_boundary_id(enums::id_boundary_xMinus);
// break;
// }
// }
// }
// // We also fix some face at the top of the plate to x=0, so it does not drift/shear sidewides
// // @todo-ensure Do we create stress peaks by doing so?
// else if ( ( cell->face(face)->center()[enums::y] - hwidth ) < search_tolerance ) // upper face
// {
// for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
// {
// //Project the cell vertex to the XY plane and test the distance from the cylinder axis
// Point<2> vertex_v = cell->face(face)->vertex(vertex);
// Point<2> desired_mid_point (0,+hwidth);
//
// if (std::abs(vertex_v.distance(desired_mid_point)) < search_tolerance)
// {
// std::cout << "found u at " << vertex_v << std::endl;
// cell->face(face)->set_boundary_id(enums::id_boundary_xMinus);
// break;
// }
// }
// }
// }
// }
// }
}
/**
* Make 3D mesh of plate with a hole (only positive z-part)
*/
template <int dim>
void make_grid( Triangulation<3> &triangulation, const Parameter::GeneralParameters ¶meter )
{
parameterCollection parameters_internal;
// size of the plate divided by the size of the hole
double ratio_width_To_holeRadius = parameter.width;
double hwidth = parameter.width;
double holeRadius = parameter.holeRadius;
// size of the inner mesh (hypercube with hole) relative to size of the whole plate
//double ratio_x = parameter.ratio_x;
const double search_tolerance = parameters_internal.search_tolerance;
Triangulation<2> tria_2d;
make_2d_plate_with_hole (
tria_2d,
ratio_width_To_holeRadius, // length
//ratio_width_To_holeRadius * 1.0, // width: *1.0 => square
holeRadius, // hole radius = diameter/2
//ratio_x,
parameter
);
// only relevant for 3d grid:
const unsigned int n_repetitions_z = parameter.nbr_elementsInZ; // nbr of Unterteilungen in z-direction for 3d meshing; 1=one element in z; 2=two el.s in z; ...
GridGenerator::extrude_triangulation(tria_2d,
n_repetitions_z+1,
parameter.thickness,
triangulation);
// Clear boundary ID's
for (typename Triangulation<dim>::active_cell_iterator
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell )
{
for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
if (cell->face(face)->at_boundary())
{
cell->face(face)->set_all_boundary_ids(0);
}
}
// Set boundary IDs and and manifolds
const Point<dim> direction (0,0,1);
const Point<dim> centre (0,0,0);
for (typename Triangulation<dim>::active_cell_iterator
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell)
{
for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
{
// Set the INTERNAL (not at the boundary) face to the xminus id
// Find the cell face at x=0, containing the node (0,-hwidth,0) pointing in x-direction
// if ( (std::abs(cell->face(face)->center()[enums::x] - 0.0) < search_tolerance) )
// {
// // @todo-optimize: We only look for single cell-face, so we could stop checking this, if we found something (e.g. bool found_xMinus)
// if ( cell->face(face)->center()[enums::y] < 0 )
// {
// for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
// {
// //Project the cell vertex to the XY plane and test the distance from the cylinder axis
// Point<3> vertex_v = cell->face(face)->vertex(vertex);
// Point<3> desired_mid_point (0,-hwidth,0);
//
// if (std::abs(vertex_v.distance(desired_mid_point)) < search_tolerance)
// {
// cell->face(face)->set_boundary_id(enums::id_boundary_xMinus);
// break;
// }
// }
// }
// // We also fix some face at the top of the plate to x=0, so it does not drift/shear sidewides
// // @todo-ensure Do we create stress peaks by doing so?
// else if ( cell->face(face)->center()[enums::y] > 0 )
// {
// for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
// {
// //Project the cell vertex to the XY plane and test the distance from the cylinder axis
// Point<3> vertex_v = cell->face(face)->vertex(vertex);
// Point<3> desired_mid_point (0,+hwidth,0);
//
// if (std::abs(vertex_v.distance(desired_mid_point)) < search_tolerance)
// {
// cell->face(face)->set_boundary_id(enums::id_boundary_xMinus);
// break;
// }
// }
// }
// }
// Set boundary IDs
if ( cell->face(face)->at_boundary() )
{
// The bottom face (yMinus) is now at the negative hwidth (plate reaches from y = -hwidth to +hwidth)
if (std::abs(cell->face(face)->center()[enums::y] + hwidth) < search_tolerance)
{
cell->face(face)->set_boundary_id(enums::id_boundary_yMinus);
// // Tracked QP
// for (unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_face; ++vertex)
// {
// if (std::abs(cell->vertex(vertex)[enums::y] - 0) < search_tolerance)
// if (std::abs(cell->vertex(vertex)[enums::z] - 0) < search_tolerance)
// if (std::abs(cell->vertex(vertex)[enums::x] - parameter.holeRadius) < search_tolerance)
// {
// // We found the cell that lies at the bottom edge next to the hole (bottom left corner)
// cell->set_material_id( enums::tracked_QP );
// break;
// }
// }
}
else if (std::abs(cell->face(face)->center()[1] - ratio_width_To_holeRadius) < search_tolerance)
{
cell->face(face)->set_boundary_id(enums::id_boundary_yPlus);
}
else if (std::abs(cell->face(face)->center()[2] - 0.0) < search_tolerance)
{
cell->face(face)->set_boundary_id(enums::id_boundary_zMinus);
}
else if (std::abs(cell->face(face)->center()[2] - parameter.thickness) < search_tolerance)
{
cell->face(face)->set_boundary_id(enums::id_boundary_zPlus);
}
else
{
for (unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_face; ++vertex)
{
//Project the cell vertex to the XY plane and test the distance from the cylinder axis
Point<dim> vertex_proj = cell->vertex(vertex);
vertex_proj[2] = 0.0;
if (std::abs(vertex_proj.distance(centre) - parameter.holeRadius) < search_tolerance)
{
cell->face(face)->set_boundary_id(parameters_internal.boundary_id_hole);
break;
}
}
}
//Set manifold IDs
for (unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_face; ++vertex)
{
//Project the cell vertex to the XY plane and test the distance from the cylinder axis
Point<dim> vertex_proj = cell->vertex(vertex);
vertex_proj[2] = 0.0;
if (std::abs(vertex_proj.distance(centre) - parameter.holeRadius) < search_tolerance)
{
//Set manifold ID on face and edges
cell->face(face)->set_all_manifold_ids(parameters_internal.manifold_id_hole);
break;
}
}
}
}
}
// pre-refinement of the damaged area (around y=0)
for (unsigned int refine_counter=0; refine_counter < parameter.nbr_holeEdge_refinements; refine_counter++)
{
for (typename Triangulation<dim>::active_cell_iterator
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell)
{
if ( std::abs( cell->center()[enums::y]) < holeRadius*0.5 )
cell->set_refine_flag();
}
triangulation.execute_coarsening_and_refinement();
}
// // refine hole boundary
// for (unsigned int refine_counter=0; refine_counter<parameter.nbr_holeEdge_refinements; refine_counter++)
// {
// for (typename Triangulation<dim>::active_cell_iterator
// cell = triangulation.begin_active();
// cell != triangulation.end(); ++cell)
// {
// for (unsigned int face=0; face < GeometryInfo<dim>::faces_per_cell; ++face)
// if ( cell->face(face)->boundary_id() == parameters_internal.boundary_id_hole )
// {
// cell->set_refine_flag();
// break;
// }
// }
// triangulation.execute_coarsening_and_refinement();
// }
// The x-fixed faces are set now, to get the smallest possible face
// for ( typename Triangulation<dim>::active_cell_iterator
// cell = triangulation.begin_active();
// cell != triangulation.end(); ++cell )
// {
// for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
// {
// // Set the INTERNAL (not at the boundary) face to the xminus id
// // Find the cell face at x=0, containing the node (0,-hwidth,0) pointing in x-direction
// if ( (std::abs(cell->face(face)->center()[enums::x] - 0.0) < search_tolerance) )
// {
// // @todo-optimize: We only look for single cell-face, so we could stop checking this, if we found something (e.g. bool found_xMinus)
// if ( cell->face(face)->center()[enums::y] < 0 )
// {
// for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
// {
// //Project the cell vertex to the XY plane and test the distance from the cylinder axis
// Point<3> vertex_v = cell->face(face)->vertex(vertex);
// Point<3> desired_mid_point (0,-hwidth);
//
// if (std::abs(vertex_v.distance(desired_mid_point)) < search_tolerance)
// {
// cell->face(face)->set_boundary_id(enums::id_boundary_xMinus);
// break;
// }
// }
// }
// // We also fix some face at the top of the plate to x=0, so it does not drift/shear sidewides
// // @todo-ensure Do we create stress peaks by doing so?
// else if ( cell->face(face)->center()[enums::y] > 0 )
// {
// for (unsigned int vertex=0; vertex < GeometryInfo<dim>::vertices_per_face; ++vertex)
// {
// //Project the cell vertex to the XY plane and test the distance from the cylinder axis
// Point<3> vertex_v = cell->face(face)->vertex(vertex);
// Point<3> desired_mid_point (0,+hwidth);
//
// if (std::abs(vertex_v.distance(desired_mid_point)) < search_tolerance)
// {
// cell->face(face)->set_boundary_id(enums::id_boundary_xMinus);
// break;
// }
// }
// }
// }
// }
// }
}
}