-
Notifications
You must be signed in to change notification settings - Fork 0
/
llg_factories.cc
1392 lines (1222 loc) · 46.2 KB
/
llg_factories.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
#include "llg_factories.h"
#include "llg_problem.h"
#include "llg_preconditioners.h"
#include "boundary_element_handler.h"
#include "pinned_boundary_element_handler.h"
#include "nodal_quadrature.h"
#include "new_interpolators.h"
// Meshes for mesh factory
#include "../../src/meshes/simple_rectangular_quadmesh.h"
#include "../../src/meshes/rectangular_quadmesh.h"
#include "../../src/meshes/one_d_mesh.h"
#include "../../src/meshes/simple_rectangular_tri_mesh.h"
#include "../../src/meshes/simple_cubic_tet_mesh.h"
#include "../../src/meshes/simple_cubic_mesh.h"
#include "../../src/meshes/tetgen_mesh.h"
#include "../../src/meshes/triangle_mesh.h"
#include "./single_element_mesh.h"
#include "./simpler_cubic_mesh.h"
namespace oomph
{
namespace Factories
{
BoundaryElementHandlerBase* bem_handler_factory
(const Vector<Mesh*>& output_mesh_pts,
const CornerDataInput* input_corner_data_pt,
int hierarchical_bem,
bool disable_corner_angles,
int numerical_int_bem,
bool allow_pinned_boundary_values,
const std::string& bem_matrix_filename_in,
const std::string& bem_matrix_filename_out
)
{
BoundaryElementHandlerBase* bem_handler_pt = 0;
if(allow_pinned_boundary_values)
{
bem_handler_pt = new PinnedBoundaryElementHandler;
}
else
{
bem_handler_pt = new BoundaryElementHandler;
}
// Figure out what defaults to use if any bool-like options are -1
// ============================================================
// Get the first finite element we can find in the a bulk mesh on
// which we are going to construct our bem mesh. Assuimg that all
// elements in all the meshes are the same type...
FiniteElement* bulk_fe_pt = output_mesh_pts[0]->finite_element_pt(0);
// Use H-lib if possible (have it and surface mesh is triangular)
if(hierarchical_bem == -1)
{
#ifdef OOMPH_HAS_HLIB
if((bulk_fe_pt->nodal_dimension() == 3)
&& (bulk_fe_pt->nnode_1d() == 2)
&& (bulk_fe_pt->nnode() == 4))
{
hierarchical_bem = true;
}
else
{
hierarchical_bem = false;
}
#else
hierarchical_bem = false;
#endif
}
// Use analytical integation if possible, numerical otherwise
if(numerical_int_bem == -1)
{
if((bulk_fe_pt->nodal_dimension() == 3)
&& (bulk_fe_pt->nnode_1d() == 2)
&& (bulk_fe_pt->nnode() == 4))
{
numerical_int_bem = false;
}
else
{
numerical_int_bem = true;
}
}
// Next assign the parameters
// ============================================================
// Check that we can do hierarchical bem, if so set the parameter.
if(hierarchical_bem)
{
#ifndef OOMPH_HAS_HLIB
std::string err = "Hlib library required for hierarchical bem matrix";
throw OomphLibError(err, OOMPH_EXCEPTION_LOCATION,
OOMPH_CURRENT_FUNCTION);
#endif
}
bem_handler_pt->Hierarchical_bem = hierarchical_bem;
// Figure out which element type we should use in the bem mesh
// (based on the element type used in the bulk mesh) and store the
// function needed to create them.
bem_handler_pt->Bem_element_factory_fpt = Factories::
bem_element_factory_factory(bulk_fe_pt);
// Create an integration scheme
bem_handler_pt->integration_scheme_pt() = Factories::
variable_order_integrator_factory(bulk_fe_pt);
// Figure out if we are doing phi/phi1 in separate meshes (and
// problems) or all in one by checking what type of element we
// have. Set the indicies accordingly.
MicromagEquations* mele_pt = dynamic_cast<MicromagEquations*>
(output_mesh_pts[0]->element_pt(0));
TFPoissonEquations* pele_pt = dynamic_cast<TFPoissonEquations*>
(output_mesh_pts[0]->element_pt(0));
if(mele_pt != 0)
{
// Fully implicit/all in one mesh
bem_handler_pt->set_input_index(mele_pt->phi_1_index_micromag());
bem_handler_pt->set_output_index(mele_pt->phi_index_micromag());
}
else if(pele_pt != 0)
{
// Fully implicit/all in one mesh
bem_handler_pt->set_input_index(pele_pt->u_index_poisson());
bem_handler_pt->set_output_index(pele_pt->u_index_poisson());
}
// Add all boundaries of all meshes to bem boundary list. Not likely
// to want to make use of bem on only some boundaries anytime soon so
// just add them all. If you want it on only some boundaries write a
// different factory (sorry).
BemBoundaryData bem_boundaries;
for(unsigned msh=0, nmsh=output_mesh_pts.size(); msh<nmsh; msh++)
{
Mesh* mesh_pt = output_mesh_pts[msh];
for(unsigned b=0, nb=mesh_pt->nboundary(); b<nb; b++)
{
bem_boundaries.push_back(std::make_pair(b, mesh_pt));
}
}
// Copy in the list of boundaries to operate on
bem_handler_pt->Bem_boundaries = bem_boundaries;
// Set cached matrix filename
bem_handler_pt->Bem_matrix_filename_in = bem_matrix_filename_in;
bem_handler_pt->Bem_matrix_filename_out = bem_matrix_filename_out;
// Set debug parameters
bem_handler_pt->Debug_disable_corner_contributions = disable_corner_angles;
bem_handler_pt->Numerical_int_bem = numerical_int_bem;
// Now build it
if(input_corner_data_pt == 0)
{
CornerDataInput dummy;
bem_handler_pt->build(dummy);
}
else
{
bem_handler_pt->build(*input_corner_data_pt);
}
return bem_handler_pt;
}
Preconditioner* llg_sub_preconditioner_factory(const std::string& llg_sub_prec)
{
Preconditioner* llg_sub_prec_pt = 0;
if(llg_sub_prec == "block")
{
LLGSubBlockPreconditioner* _llg_sub_prec_pt = new LLGSubBlockPreconditioner;
_llg_sub_prec_pt->build();
llg_sub_prec_pt = _llg_sub_prec_pt;
}
else
{
llg_sub_prec_pt = preconditioner_factory(llg_sub_prec);
}
return llg_sub_prec_pt;
}
Preconditioner* llg_preconditioner_factory(const std::string& llg_prec,
const std::string& llg_sub_prec)
{
Preconditioner* llg_prec_pt = 0;
if(llg_prec == "block")
{
LLGBlockPreconditioner* _llg_prec_pt = new LLGBlockPreconditioner;
Preconditioner* llg_sub_prec_pt = llg_sub_preconditioner_factory(llg_sub_prec);
Vector<unsigned> master_to_subs_map(2);
master_to_subs_map[0] = 0; // mx
master_to_subs_map[1] = 1; // my
llg_sub_prec_pt->turn_into_subsidiary_block_preconditioner(_llg_prec_pt, master_to_subs_map);
_llg_prec_pt->J_aabb_prec_pt = llg_sub_prec_pt;
_llg_prec_pt->build();
llg_prec_pt = _llg_prec_pt;
}
else
{
llg_prec_pt = preconditioner_factory(llg_prec);
}
return llg_prec_pt;
}
Preconditioner* micromag_preconditioner_factory(const std::string& ms_prec,
const std::string& llg_prec,
const std::string& llg_sub_prec)
{
// Magnetostatics prec
// ============================================================
Preconditioner* ms_prec_pt = 0;
// First check if we want a sum of matrice preconditioner:
if(has_prefix("som-main-", ms_prec))
{
Preconditioner* ul_prec = micromag_preconditioner_factory
(rest_of_name("som-main-", ms_prec), llg_prec, llg_sub_prec);
MainMatrixOnlyPreconditioner* mm_prec_pt = new MainMatrixOnlyPreconditioner;
mm_prec_pt->set_underlying_prec_pt(ul_prec);
ms_prec_pt = mm_prec_pt;
}
// Make a preconditioner which only acts on the main matrix and
// diagonals of added matrices of a sum of matrices.
else if(has_prefix("som-maindiag-", ms_prec))
{
Preconditioner* ul_prec = micromag_preconditioner_factory
(rest_of_name("som-maindiag-", ms_prec), llg_prec, llg_sub_prec);
MainMatrixAndDiagsPreconditioner* mm_prec_pt
= new MainMatrixAndDiagsPreconditioner;
mm_prec_pt->set_underlying_prec_pt(ul_prec);
ms_prec_pt = mm_prec_pt;
}
else if(ms_prec == "dummy")
{
// Make preconditioners
DummyPinnedMsPreconditioner* _ms_prec_pt = new DummyPinnedMsPreconditioner;
Preconditioner* llg_prec_pt = llg_preconditioner_factory(llg_prec,
llg_sub_prec);
// Set up master/subsidiary links
Vector<unsigned> micromag_to_llg_block_map(3);
micromag_to_llg_block_map[0] = 2; // mx
micromag_to_llg_block_map[1] = 3; // my
micromag_to_llg_block_map[2] = 4; // mz
llg_prec_pt->turn_into_subsidiary_block_preconditioner
(_ms_prec_pt, micromag_to_llg_block_map);
_ms_prec_pt->Real_preconditioner_pt = llg_prec_pt;
ms_prec_pt = _ms_prec_pt;
}
else if(ms_prec == "block")
{
// Make preconditioners
MagnetostaticsBlockPreconditioner* _ms_prec_pt = new MagnetostaticsBlockPreconditioner;
Preconditioner* llg_prec_pt = llg_preconditioner_factory(llg_prec,
llg_sub_prec);
// Set up master/subsidiary links (note: different to above!)
Vector<unsigned> micromag_to_llg_block_map(3);
micromag_to_llg_block_map[0] = 2; // mx
micromag_to_llg_block_map[1] = 3; // my
micromag_to_llg_block_map[2] = 4; // mz
llg_prec_pt->turn_into_subsidiary_block_preconditioner
(_ms_prec_pt, micromag_to_llg_block_map);
_ms_prec_pt->Llg_preconditioner_pt = llg_prec_pt;
_ms_prec_pt->build();
ms_prec_pt = _ms_prec_pt;
}
else if(ms_prec == "block-drop-p")
{
// same as "block" except that we drop the P block (rather than
// Q) of the bulk-phi+llg block to get it triangular.
// Make preconditioners
MagnetostaticsBlockPreconditioner* _ms_prec_pt = new MagnetostaticsBlockPreconditioner;
Preconditioner* llg_prec_pt = llg_preconditioner_factory(llg_prec,
llg_sub_prec);
// Set up master/subsidiary links
Vector<unsigned> micromag_to_llg_block_map(3);
micromag_to_llg_block_map[0] = 2; // mx
micromag_to_llg_block_map[1] = 3; // my
micromag_to_llg_block_map[2] = 4; // mz
llg_prec_pt->turn_into_subsidiary_block_preconditioner
(_ms_prec_pt, micromag_to_llg_block_map);
_ms_prec_pt->Llg_preconditioner_pt = llg_prec_pt;
_ms_prec_pt->Drop_P = true;
_ms_prec_pt->build();
ms_prec_pt = _ms_prec_pt;
}
else
{
ms_prec_pt = preconditioner_factory(ms_prec);
}
return ms_prec_pt;
}
Vector<unsigned> dof_to_block_factory(const std::string& _name)
{
const std::string name = to_lower(_name);
// Make an element to look up indicies from
TMicromagElement<2,2> dummy_ele;
const unsigned ndof = dummy_ele.ndof_types(); //??ds unsafe?
Vector<unsigned> dof_to_block(ndof);
if(name == "none")
{
// identity mapping
for(unsigned j=0; j<ndof; j++)
{
dof_to_block[j] = j;
}
}
// All m values in one block, others left alone.
// [0, 1, 2, 2, 2, 3, 4]
else if(name == "group-m")
{
unsigned k = 0;
// Normal phi/phi1
dof_to_block[dummy_ele.phi_index_micromag()] = k++;
dof_to_block[dummy_ele.phi_1_index_micromag()] = k++;
// m all in one block
for(unsigned j=0; j<3; j++)
{
int index = dummy_ele.m_index_micromag(j);
dof_to_block[index] = k;
}
k++;
// boundary phi/phi1 ??ds assume they are at the end...
dof_to_block[5] = k++;
dof_to_block[6] = k++;
}
else if(name == "group-m-phi-phi-boundary")
{
unsigned k = 0;
// All phi into one block
dof_to_block[dummy_ele.phi_index_micromag()] = k;
dof_to_block[5] = k;
k++;
// Simiarly for phi1
dof_to_block[dummy_ele.phi_1_index_micromag()] = k;
dof_to_block[6] = k;
k++;
// m all in one block
for(unsigned j=0; j<3; j++)
{
int index = dummy_ele.m_index_micromag(j);
dof_to_block[index] = k;
}
k++;
}
else
{
std::string err = "Unrecognised blocking name";
err += name;
throw OomphLibError(err, OOMPH_EXCEPTION_LOCATION,
OOMPH_CURRENT_FUNCTION);
}
return dof_to_block;
}
/// \short Make a mesh as specified by an input argument. Refined
/// according to the given refinement level (in some way appropriate
/// for that mesh type). Assumption: this will be passed into a
/// problem, which will delete the pointer when it's done.
Mesh* llg_mesh_factory(const std::string& _mesh_name,
int refinement_level,
TimeStepper* time_stepper_pt,
double scaling_factor,
double rotate_xy_angle,
unsigned nnode1d)
{
// Ignore case in mesh names
const std::string mesh_name = to_lower(_mesh_name);
// Refinement always roughly the same for structured meshes
unsigned nx = 5 * std::pow(2, refinement_level-1);
// Make the mesh and store a pointer to it
Mesh* mesh_pt = 0;
if(mesh_name == "sq_square" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimpleRectangularQuadMesh<QMicromagElement<2,2> >
(nx, nx, lx, lx, time_stepper_pt);
}
else if(mesh_name == "set_square" && nnode1d == 2)
{
ElementFactoryFctPt f_pt =
&general_element_factory<TMicromagElement<2, 2> >;
mesh_pt = MeshCreationHelpers::equilateral_triangle_mesh
(refinement_level, time_stepper_pt, nnode1d, f_pt);
mesh_pt->setup_boundary_element_info();
// Turn off triangle refinement dump stuff (breaks Micromag
// elements).
checked_dynamic_cast<TriangleMeshBase*>(mesh_pt)->
disable_triangulateio_restart();
}
else if(mesh_name == "st_union_jack_square" && nnode1d == 2)
{
ElementFactoryFctPt f_pt =
&general_element_factory<TMicromagElement<2, 2> >;
mesh_pt = MeshCreationHelpers::union_jack_triangle_mesh
(refinement_level, time_stepper_pt, nnode1d, f_pt);
mesh_pt->setup_boundary_element_info();
// Turn off triangle refinement dump stuff (breaks Micromag
// elements).
checked_dynamic_cast<TriangleMeshBase*>(mesh_pt)->
disable_triangulateio_restart();
}
else if(mesh_name == "set_square_periodic" && nnode1d == 2)
{
mesh_pt = llg_mesh_factory("set_square", refinement_level,
time_stepper_pt, 1.0, 0.0, 2);
// Link boundary 0 to boundary 2 and boundary 1 to boundary 3
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 1, 3, 0); // x
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 0, 2, 1); // y
}
else if(mesh_name == "sq_square" && nnode1d == 3)
{
double lx = 1.0;
mesh_pt = new SimpleRectangularQuadMesh<QMicromagElement<2,3> >
(nx, nx, lx, lx, time_stepper_pt);
}
else if(mesh_name == "sq_square_xstretch" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimpleRectangularQuadMesh<QMicromagElement<2,2> >
(nx, nx, lx, lx, time_stepper_pt);
// Stretch in the x direction (for testing jacobian of
// transformation stuff).
const unsigned n_node = mesh_pt->nnode();
for(unsigned nd=0; nd<n_node; nd++)
{
Node* nd_pt = mesh_pt->node_pt(nd);
nd_pt->x(0) *= 2;
}
}
else if(mesh_name == "sq_square_periodic" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new RectangularQuadMesh<QMicromagElement<2,2> >
(nx, nx, lx, lx, time_stepper_pt);
// Link boundary 0 to boundary 2 and boundary 1 to boundary 3
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 1, 3, 0); // x
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 0, 2, 1); // y
}
else if(mesh_name == "st_square_periodic" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimpleRectangularTriMesh<TMicromagElement<2,2> >
(nx, nx, lx, lx, time_stepper_pt);
// Link boundary 0 to boundary 2 and boundary 1 to boundary 3
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 1, 3, 0); // x
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 0, 2, 1); // y
}
else if(mesh_name == "sq_line" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new OneDMesh<QMicromagElement<1,2> >
(nx, lx, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "st_line" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new OneDMesh<TMicromagElement<1,2> >
(nx, lx, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sq_cube" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimplerCubicMesh<QMicromagElement<3,2> >
(nx, nx, nx, lx, lx, lx, time_stepper_pt);
}
else if(mesh_name == "st_cube" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimpleCubicTetMesh<TMicromagElement<3,2> >
(nx, nx, nx, lx, lx, lx, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sq_cube_periodic" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimplerCubicMesh<QMicromagElement<3,2> >
(nx, nx, nx, lx, lx, lx, time_stepper_pt);
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 0, 5, 2); // x
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 1, 3, 1); // y
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 2, 4, 0); // z
}
else if(mesh_name == "sq_line_periodic" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new OneDMesh<QMicromagElement<1,2> >
(nx, lx, time_stepper_pt);
MeshCreationHelpers::slow_make_boundaries_periodic(mesh_pt, 0, 1, 0); // x
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "st_square" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimpleRectangularTriMesh<TMicromagElement<2,2> >
(nx, nx, lx, lx, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
// Turn off triangle refinement dump stuff (breaks Micromag
// elements).
checked_dynamic_cast<TriangleMeshBase*>(mesh_pt)->
disable_triangulateio_restart();
}
else if(mesh_name == "q_single_element" && nnode1d == 2)
{
mesh_pt = new QSingleElementMesh<QMicromagElement<2,2> >(time_stepper_pt);
}
else if(mesh_name == "t_single_element" && nnode1d == 2)
{
mesh_pt = new TSingleElementMesh<TMicromagElement<2,2> >(time_stepper_pt);
mesh_pt->setup_boundary_element_info();
// Turn off triangle refinement dump stuff (breaks Micromag
// elements).
checked_dynamic_cast<TriangleMeshBase*>(mesh_pt)->
disable_triangulateio_restart();
}
else if(mesh_name == "ut_square" && nnode1d == 2)
{
mesh_pt = new TriangleMesh<TMicromagElement<2, 2> >
("./meshes/square." + to_string(refinement_level) + ".node",
"./meshes/square." + to_string(refinement_level) + ".ele",
"./meshes/square." + to_string(refinement_level) + ".poly",
time_stepper_pt);
// Turn off triangle refinement dump stuff (breaks Micromag
// elements).
checked_dynamic_cast<TriangleMeshBase*>(mesh_pt)->
disable_triangulateio_restart();
}
else if(mesh_name == "st_cubeoid" && nnode1d == 2)
{
// nmag cubeoid
double lx = 1, ly = lx, lz = 3*lx;
unsigned ny = nx, nz = std::ceil(lz/lx) * nx;
mesh_pt = new SimpleCubicTetMesh<TMicromagElement<3, 2> >
(nx, ny, nz, lx, ly, lz, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sqt_cubeoid" && nnode1d == 2)
{
Mesh* qmesh_pt = llg_mesh_factory("sq_cubeoid", refinement_level,
time_stepper_pt,
1, rotate_xy_angle, nnode1d);
//??ds memory leak, fix? Can't delete this mesh or nodes will
//go...
TetMeshBase* tmesh_pt = new TetMeshBase;
ElementFactoryFctPt factory_fpt =
MeshCreationHelpers::new_element<TMicromagElement<3, 2> >;
MeshCreationHelpers::brick2tet(*qmesh_pt, factory_fpt, *tmesh_pt);
mesh_pt = tmesh_pt;
}
else if(mesh_name == "ut_cubeoid" && nnode1d == 2)
{
mesh_pt = new TetgenMesh<TMicromagElement<3, 2> >
("./meshes/cubeoid." + to_string(refinement_level) + ".node",
"./meshes/cubeoid." + to_string(refinement_level) + ".ele",
"./meshes/cubeoid." + to_string(refinement_level) + ".face",
time_stepper_pt);
}
else if(mesh_name == "ut_mumag4" && nnode1d == 2)
{
mesh_pt = new TetgenMesh<TMicromagElement<3, 2> >
("./meshes/mumag4." + to_string(refinement_level) + ".node",
"./meshes/mumag4." + to_string(refinement_level) + ".ele",
"./meshes/mumag4." + to_string(refinement_level) + ".face",
time_stepper_pt);
}
else if(mesh_name == "st_mumag4" && nnode1d == 2)
{
mesh_pt = new SimpleCubicTetMesh<TMicromagElement<3, 2> >
(5*nx, std::ceil(1.25*nx), 1, 500, 125, 3, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sq_mumag4" && nnode1d == 2)
{
unsigned this_nx = refinement_level;
mesh_pt = new SimplerCubicMesh<QMicromagElement<3, 2> >
(5*this_nx, std::ceil(1.25*this_nx), 1, 500, 125, 3, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sq_mumag4_normalised" && nnode1d == 2)
{
unsigned this_nx = refinement_level;
mesh_pt = new SimplerCubicMesh<QMicromagElement<3, 2> >
(5*this_nx, std::ceil(1.25*this_nx), 1, 500, 125, 3, time_stepper_pt);
mesh_pt->scale_mesh(1/5.6858);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sq_mumag4_normalised_zref" && nnode1d == 2)
{
unsigned this_nx = refinement_level;
mesh_pt = new SimplerCubicMesh<QMicromagElement<3, 2> >
(5*this_nx, std::ceil(1.25*this_nx), 2, 500, 125, 3, time_stepper_pt);
// two elements thick instead of 1
mesh_pt->scale_mesh(1/5.6858);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sq_mumag4_2d" && nnode1d == 2)
{
unsigned this_nx = refinement_level;
mesh_pt = new SimpleRectangularQuadMesh<QMicromagElement<2, 2> >
(5*this_nx, std::ceil(1.25*this_nx), 500, 125, time_stepper_pt);
mesh_pt->setup_boundary_element_info();
}
else if(mesh_name == "sq_mumag4+" && nnode1d == 2)
{
unsigned this_nx = refinement_level;
RefineableMeshBase* ref_mesh_pt
= new SimplerCubicMesh<QMicromagElement<3, 2> >
(5*this_nx, std::ceil(1.25*this_nx), 1, 500, 125, 3, time_stepper_pt);
// Create an "error" vector such that only one element is refined
double max_error = ref_mesh_pt->max_permitted_error();
Vector<double> fake_errors(ref_mesh_pt->nelement(), max_error/2);
fake_errors[0] = max_error*2;
// And adapt it
ref_mesh_pt->adapt(fake_errors);
ref_mesh_pt->setup_boundary_element_info();
mesh_pt = ref_mesh_pt;
}
else if(mesh_name == "sqt_mumag4" && nnode1d == 2)
{
Mesh* qmesh_pt = llg_mesh_factory("sq_mumag4", refinement_level,
time_stepper_pt,
1, rotate_xy_angle, nnode1d);
// Convert to tet mesh
TetMeshBase* tmesh_pt = new TetMeshBase;
ElementFactoryFctPt factory_fpt =
MeshCreationHelpers::new_element<TMicromagElement<3, 2> >;
MeshCreationHelpers::brick2tet(*qmesh_pt, factory_fpt, *tmesh_pt);
// delete the Q mesh without deleting the nodes/elements
qmesh_pt->flush_element_and_node_storage();
delete qmesh_pt; qmesh_pt = 0;
mesh_pt = tmesh_pt;
}
else if(mesh_name == "sq_cubeoid" && nnode1d == 2)
{
double lx = 1, ly = lx, lz = 3*lx;
mesh_pt = new SimplerCubicMesh<QMicromagElement<3, 2> >
(nx, nx, int(lz/lx)*nx, lx, ly, lz, time_stepper_pt);
}
else if(mesh_name == "ut_sphere" && nnode1d == 2)
{
mesh_pt = new TetgenMesh<TMicromagElement<3, 2> >
("./meshes/sphere." + to_string(refinement_level) + ".node",
"./meshes/sphere." + to_string(refinement_level) + ".ele",
"./meshes/sphere." + to_string(refinement_level) + ".face",
time_stepper_pt);
}
else if(mesh_name == "ut_cylinder" && nnode1d == 2)
{
mesh_pt = new TetgenMesh<TMicromagElement<3, 2> >
("./meshes/cylinder25_40." + to_string(refinement_level) + ".node",
"./meshes/cylinder25_40." + to_string(refinement_level) + ".ele",
"./meshes/cylinder25_40." + to_string(refinement_level) + ".face",
time_stepper_pt);
}
else if(mesh_name == "sq_annular" && nnode1d == 2)
{
double lx = 1.0;
mesh_pt = new SimpleRectangularQuadMesh<QMicromagElement<2,2> >
(nx, nx, lx, lx, time_stepper_pt);
const double r_min = 0.5, r_max = 1.5, phi_min = 0, phi_max = 180;
// Warp the domain as in oomph-lib website example
const unsigned n_node = mesh_pt->nnode();
for(unsigned nd=0; nd<n_node; nd++)
{
Node* nd_pt = mesh_pt->node_pt(nd);
// Get the nodal coordinates
const double x_old = nd_pt->x(0);
const double y_old = nd_pt->x(1);
// Map from the old x/y to the new r/phi:
const double r = r_min+(r_max-r_min)*x_old;
const double phi = (phi_min + (phi_max-phi_min)*y_old)*Pi/180.0;
// Set new nodal coordinates
nd_pt->x(0)=r*std::cos(phi);
nd_pt->x(1)=r*std::sin(phi);
}
}
else
{
throw OomphLibError("Unrecognised mesh name " + mesh_name,
OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}
// Check nnode1d is correct
if(mesh_pt->finite_element_pt(0)->nnode_1d() != nnode1d)
{
std::string err = "Incorrect nnode1d";
throw OomphLibError(err, OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}
// rotate the mesh if requested
if(rotate_xy_angle != 0.0)
{
MeshCreationHelpers::rotate_mesh(rotate_xy_angle, mesh_pt);
}
// Scale the mesh as requested
mesh_pt->scale_mesh(scaling_factor);
// This should go inside an element factory but our meshes don't
// allow that :(
for(unsigned ele=0, nele=mesh_pt->nelement(); ele<nele; ele++)
{
MicromagEquations* ele_pt = checked_dynamic_cast<MicromagEquations*>
(mesh_pt->element_pt(ele));
ele_pt->Ms_calc_pt = new ImplicitMagnetostaticsCalculator;
}
// Done: pass out the mesh pointer
return mesh_pt;
}
/// Pick and create a residual calculator to use
LLGResidualCalculator* residual_calculator_factory(const std::string& residual)
{
if(residual == "llg")
return new LLGResidualCalculator(true);
else if(residual == "ll")
return new LLGResidualCalculator(false);
else
throw OomphLibError("Unrecognised residual "+residual,
OOMPH_EXCEPTION_LOCATION,
OOMPH_CURRENT_FUNCTION);
}
/// \short Create a variable order quadrature object based on the
/// dimension and shape of the element.
Integral* variable_order_integrator_factory(const unsigned& dim,
const unsigned& nnode_1d,
const ElementGeometry::ElementGeometry& geom)
{
using namespace ElementGeometry;
//??ds nnnode1d doesn't matter right??
if((dim == 2) && (geom == T))
{
return new TVariableOrderGaussLegendre<1>;
}
else if((dim == 2) && (geom == Q))
{
return new QVariableOrderGaussLegendre<1>;
}
else if((dim == 3) && (geom == T))
{
return new TVariableOrderGaussLegendre<2>;
}
else if((dim == 3) && (geom == Q))
{
return new QVariableOrderGaussLegendre<2>;
}
else
{
std::string err("Cannot determine element type.\n");
throw OomphLibError(err, OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}
}
/// \short Create a variable order quadrature object based on the
/// dimension and shape of the element.
Integral* variable_order_integrator_factory(const FiniteElement* const el_pt)
{
return variable_order_integrator_factory(el_pt->dim(),
el_pt->nnode_1d(),
el_pt->element_geometry());
}
/// \short Return a function which will create the appropriate BEM face
/// element for the bulk element pointer given (should work for a
/// pointer to any bulk element type i.e., field or llg).
BEMElementFactoryFctPt bem_element_factory_factory
(const FiniteElement* bulk_ele_pt)
{
if(dynamic_cast<const TElement<1,2>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<TMicromagBEMElement<1,2> >;
}
else if(dynamic_cast<const TElement<2, 2>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<TMicromagBEMElement<2,2> >;
}
else if(dynamic_cast<const TElement<3, 2>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<TMicromagBEMElement<3,2> >;
}
else if(dynamic_cast<const QElement<1,2>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<QMicromagBEMElement<1,2> >;
}
else if(dynamic_cast<const QElement<2,2>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<QMicromagBEMElement<2,2> >;
}
else if(dynamic_cast<const QElement<3,2>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<QMicromagBEMElement<3,2> >;
}
else if(dynamic_cast<const TElement<1,3>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<TMicromagBEMElement<1,3> >;
}
else if(dynamic_cast<const TElement<2, 3>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<TMicromagBEMElement<2,3> >;
}
else if(dynamic_cast<const TElement<3, 3>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<TMicromagBEMElement<3,3> >;
}
else if(dynamic_cast<const QElement<1,3>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<QMicromagBEMElement<1,3> >;
}
else if(dynamic_cast<const QElement<2,3>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<QMicromagBEMElement<2,3> >;
}
else if(dynamic_cast<const QElement<3,3>*>(bulk_ele_pt) != 0)
{
return &bem_element_factory<QMicromagBEMElement<3,3> >;
}
else
{
throw OomphLibError("Unrecognised element type",
OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}
}
/// \short Return a factory function which will create the appropriate
/// "flux mesh" for the bulk element pointer given.
FluxMeshFactoryFctPt
mm_flux_mesh_factory_factory(const FiniteElement* bulk_ele_pt)
{
if(dynamic_cast<const TMicromagElement<1, 2>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<TMicromagElement<1, 2> > >;
}
else if(dynamic_cast<const TMicromagElement<2, 2>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<TMicromagElement<2, 2> > >;
}
else if(dynamic_cast<const TMicromagElement<3, 2>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<TMicromagElement<3, 2> > >;
}
else if(dynamic_cast<const QMicromagElement<1,2>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<QMicromagElement<1,2> > >;
}
else if(dynamic_cast<const QMicromagElement<2,2>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<QMicromagElement<2,2> > >;
}
else if(dynamic_cast<const QMicromagElement<3,2>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<QMicromagElement<3,2> > >;
}
// nnode1d =3
else if(dynamic_cast<const QMicromagElement<1,3>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<QMicromagElement<1,3> > >;
}
else if(dynamic_cast<const QMicromagElement<2,3>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<QMicromagElement<2,3> > >;
}
else if(dynamic_cast<const QMicromagElement<3,3>*>(bulk_ele_pt) != 0)
{
return Factories::surface_mesh_factory
<MicromagFluxElement<QMicromagElement<3,3> > >;
}
else
{
throw OomphLibError("Unrecognised element type",
OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}