forked from CEED/Laghos
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlaghost.cpp
2997 lines (2640 loc) · 130 KB
/
laghost.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) 2017, Lawrence Livermore National Security, LLC. Produced at
// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
// reserved. See files LICENSE and NOTICE for details.
//
// This file is part of CEED, a collection of benchmarks, miniapps, software
// libraries and APIs for efficient high-order finite element and spectral
// element discretizations for exascale applications. For more information and
// source code availability see http://github.com/ceed.
//
// The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
// a collaborative effort of two U.S. Department of Energy organizations (Office
// of Science and the National Nuclear Security Administration) responsible for
// the planning and preparation of a capable exascale ecosystem, including
// software, applications, hardware, advanced system engineering and early
// testbed platforms, in support of the nation's exascale computing imperative.
//
// __ __
// / / ____ ____ / /_ ____ _____
// / / / __ `/ __ `/ __ \/ __ \/ ___/
// / /___/ /_/ / /_/ / / / / /_/ (__ )
// /_____/\__,_/\__, /_/ /_/\____/____/
// /____/
//
// High-order Lagrangian Geodynamics Solver
//
// Laghos(LAGrangian High-Order Solver) is a miniapp that solves the
// time-dependent Euler equation of compressible gas dynamics in a moving
// Lagrangian frame using unstructured high-order finite element spatial
// discretization and explicit high-order time-stepping. Laghos is based on the
// numerical algorithm described in the following article:
//
// V. Dobrev, Tz. Kolev and R. Rieben, "High-order curvilinear finite element
// methods for Lagrangian geodynamics", SIAM Journal on Scientific
// Computing, (34) 2012, pp. B606–B641, https://doi.org/10.1137/120864672.
//
// __ __ __
// / / ____ _____ _/ /_ ____ _____/ /_
// / / / __ `/ __ `/ __ \/ __ \/ ___/ __/
// / /___/ /_/ / /_/ / / / / /_/ (__ ) /_
// /_____/\__,_/\__, /_/ /_/\____/____/\__/
// /____/
// Lagrangian High-order Solver for Tectonics
//
// Laghost inherits the main structure of LAGHOS. However, it solves
// the dynamic form of the general momenntum balance equation for continnum,
// aquiring quasi-static solution with dynamic relaxation; reasonably large
// time steps with mass scaling. The target applications include long-term
// brittle and ductile deformations of rocks coupled with time-evolving
// thermal state.
//
// -- How to run LAGHOST
// mpirun -np 8 laghost -i ./defaults.cfg
#include <fstream>
#include <sys/time.h>
#include <sys/resource.h>
#include <cmath>
#include "laghost_solver.hpp"
#include "laghost_rheology.hpp"
#include "laghost_function.hpp"
#include "laghost_parameters.hpp"
#include "laghost_input.hpp"
#include "laghost_tmop.hpp"
#include "laghost_remhos.hpp"
using std::cout;
using std::endl;
using namespace mfem;
// Choice for the problem setup.
static int problem, dim;
static long GetMaxRssMB();
static void display_banner(std::ostream&);
static void Checks(const int ti, const double norm, int &checks);
class ConductionOperator : public TimeDependentOperator
{
protected:
ParFiniteElementSpace &fespace;
Array<int> ess_tdof_list; // this list remains empty for pure Neumann b.c.
ParBilinearForm *M;
ParBilinearForm *K;
HypreParMatrix Mmat;
HypreParMatrix Kmat;
HypreParMatrix *T; // T = M + dt K
double current_dt;
CGSolver M_solver; // Krylov solver for inverting the mass matrix M
HypreSmoother M_prec; // Preconditioner for the mass matrix M
CGSolver T_solver; // Implicit solver for T = M + dt K
HypreSmoother T_prec; // Preconditioner for the implicit solver
double alpha, kappa;
mutable Vector z; // auxiliary vector
public:
ConductionOperator(ParFiniteElementSpace &f, double alpha, double kappa,
const Vector &u);
virtual void Mult(const Vector &u, Vector &du_dt) const;
/** Solve the Backward-Euler equation: k = f(u + dt*k, t), for the unknown k.
This is the only requirement for high-order SDIRK implicit integration.*/
virtual void ImplicitSolve(const double dt, const Vector &u, Vector &k);
/// Update the diffusion BilinearForm K using the given true-dof vector `u`.
void SetParameters(const Vector &u);
virtual ~ConductionOperator();
};
void TMOPUpdate(BlockVector &S, BlockVector &S_old,
Array<int> &offset,
ParGridFunction &x_gf,
ParGridFunction &v_gf,
ParGridFunction &e_gf,
ParGridFunction &s_gf,
ParGridFunction &x_ini_gf,
ParGridFunction &p_gf,
ParGridFunction &n_p_gf,
ParGridFunction &ini_p_gf,
ParGridFunction &u_gf,
ParGridFunction &rho0_gf,
ParGridFunction &lambda0_gf,
ParGridFunction &mu0_gf,
ParGridFunction &mat_gf,
// ParLinearForm &flattening,
int dim, bool amr);
static void Generate_and_refine_initial_mesh(Mesh *&mesh, Param ¶m)
{
if (param.mesh.mesh_file.compare("default") != 0)
mesh = new Mesh(param.mesh.mesh_file.c_str(), true, true);
else {
switch (param.sim.dim) {
case 1:
mesh = new Mesh(Mesh::MakeCartesian1D(2));
if( mesh ) {
mesh->GetBdrElement(0)->SetAttribute(1);
mesh->GetBdrElement(1)->SetAttribute(1);
}
else
MFEM_ABORT("Failed to create 1D mesh.");
break;
case 2:
mesh = new Mesh(Mesh::MakeCartesian2D(2, 2, Element::QUADRILATERAL, true));
if( mesh ) {
const int NBE = mesh->GetNBE();
for (int b = 0; b < NBE; b++) {
Element *bel = mesh->GetBdrElement(b);
const int attr = (b < NBE / 2) ? 2 : 1;
std::cout << NBE << "," << b << "," << attr << std::endl;
bel->SetAttribute(attr);
}
}
else
MFEM_ABORT("Failed to create 2D mesh.");
break;
case 3:
mesh = new Mesh(Mesh::MakeCartesian3D(2, 2, 2, Element::HEXAHEDRON, true));
if( mesh ) {
const int NBE = mesh->GetNBE();
for (int b = 0; b < NBE; b++) {
Element *bel = mesh->GetBdrElement(b);
const int attr = (b < NBE / 3) ? 3 : (b < 2 * NBE / 3) ? 1 : 2;
bel->SetAttribute(attr);
}
}
else
MFEM_ABORT("Failed to create 3D mesh.");
break;
default:
break;
}
}
dim = mesh->Dimension();
MFEM_VERIFY( param.sim.dim == dim, "Dimension mismatch.");
// 1D vs partial assembly sanity check.
if (param.solver.p_assembly && dim == 1) {
param.solver.p_assembly = false;
if (Mpi::Root())
cout << "Laghos does not support PA in 1D. Switching to FA." << endl;
}
// Refine the mesh in serial to increase the resolution.
for (int lev = 0; lev < param.mesh.rs_levels; lev++) {
mesh->UniformRefinement();
}
if (Mpi::Root())
cout << "Number of zones in the serial mesh: " << mesh->GetNE() << endl;
// and then refine locally. Non-conforming elements might be generated at this stage.
if (param.mesh.local_refinement) {
mesh->EnsureNCMesh(true);
Array<int> refs;
for (int i = 0; i < mesh->GetNE(); i++) {
if (mesh->GetAttribute(i) >= 2)
refs.Append(i);
}
mesh->GeneralRefinement(refs, 1);
refs.DeleteAll();
for (int i = 0; i < mesh->GetNE(); i++) {
if (mesh->GetAttribute(i) >= 3)
refs.Append(i);
}
mesh->GeneralRefinement(refs, 1);
refs.DeleteAll();
mesh->Finalize(true);
}
}
static void Partition_initial_mesh(ParMesh *&pmesh, Mesh *&mesh, Param ¶m)
{
const int num_tasks = Mpi::WorldSize();
int unit = 1;
const int dim = mesh->Dimension();
int *nxyz = new int[dim];
switch (param.mesh.partition_type)
{
case 0:
for (int d = 0; d < dim; d++)
{
nxyz[d] = unit;
}
break;
case 11:
case 111:
unit = static_cast<int>(floor(pow(num_tasks, 1.0 / dim) + 1e-2));
for (int d = 0; d < dim; d++)
{
nxyz[d] = unit;
}
break;
case 21: // 2D
unit = static_cast<int>(floor(pow(num_tasks / 2, 1.0 / 2) + 1e-2));
nxyz[0] = 2 * unit;
nxyz[1] = unit;
break;
case 31: // 2D
unit = static_cast<int>(floor(pow(num_tasks / 3, 1.0 / 2) + 1e-2));
nxyz[0] = 3 * unit;
nxyz[1] = unit;
break;
case 32: // 2D
unit = static_cast<int>(floor(pow(2 * num_tasks / 3, 1.0 / 2) + 1e-2));
nxyz[0] = 3 * unit / 2;
nxyz[1] = unit;
break;
case 49: // 2D
unit = static_cast<int>(floor(pow(9 * num_tasks / 4, 1.0 / 2) + 1e-2));
nxyz[0] = 4 * unit / 9;
nxyz[1] = unit;
break;
case 51: // 2D
unit = static_cast<int>(floor(pow(num_tasks / 5, 1.0 / 2) + 1e-2));
nxyz[0] = 5 * unit;
nxyz[1] = unit;
break;
case 211: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 2, 1.0 / 3) + 1e-2));
nxyz[0] = 2 * unit;
nxyz[1] = unit;
nxyz[2] = unit;
break;
case 221: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 4, 1.0 / 3) + 1e-2));
nxyz[0] = 2 * unit;
nxyz[1] = 2 * unit;
nxyz[2] = unit;
break;
case 311: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 3, 1.0 / 3) + 1e-2));
nxyz[0] = 3 * unit;
nxyz[1] = unit;
nxyz[2] = unit;
break;
case 321: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 6, 1.0 / 3) + 1e-2));
nxyz[0] = 3 * unit;
nxyz[1] = 2 * unit;
nxyz[2] = unit;
break;
case 322: // 3D.
unit = static_cast<int>(floor(pow(2 * num_tasks / 3, 1.0 / 3) + 1e-2));
nxyz[0] = 3 * unit / 2;
nxyz[1] = unit;
nxyz[2] = unit;
break;
case 432: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 3, 1.0 / 3) + 1e-2));
nxyz[0] = 2 * unit;
nxyz[1] = 3 * unit / 2;
nxyz[2] = unit;
break;
case 511: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 5, 1.0 / 3) + 1e-2));
nxyz[0] = 5 * unit;
nxyz[1] = unit;
nxyz[2] = unit;
break;
case 521: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 10, 1.0 / 3) + 1e-2));
nxyz[0] = 5 * unit;
nxyz[1] = 2 * unit;
nxyz[2] = unit;
break;
case 522: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 20, 1.0 / 3) + 1e-2));
nxyz[0] = 5 * unit;
nxyz[1] = 2 * unit;
nxyz[2] = 2 * unit;
break;
case 911: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 9, 1.0 / 3) + 1e-2));
nxyz[0] = 9 * unit;
nxyz[1] = unit;
nxyz[2] = unit;
break;
case 921: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 18, 1.0 / 3) + 1e-2));
nxyz[0] = 9 * unit;
nxyz[1] = 2 * unit;
nxyz[2] = unit;
break;
case 922: // 3D.
unit = static_cast<int>(floor(pow(num_tasks / 36, 1.0 / 3) + 1e-2));
nxyz[0] = 9 * unit;
nxyz[1] = 2 * unit;
nxyz[2] = 2 * unit;
break;
default:
if ( Mpi::Root() )
cout << "Unknown partition type: " << param.mesh.partition_type << '\n';
delete mesh;
MPI_Finalize();
MFEM_ABORT("Unknown partition type.");
break;
}
Array<int> cxyz; // Leave undefined. It won't be used.
int product = 1;
for (int d = 0; d < dim; d++)
{
product *= nxyz[d];
}
const bool cartesian_partitioning = (cxyz.Size() > 0) ? true : false;
if (product == num_tasks || cartesian_partitioning)
{
if (cartesian_partitioning)
{
int cproduct = 1;
for (int d = 0; d < dim; d++)
{
cproduct *= cxyz[d];
}
MFEM_VERIFY(!cartesian_partitioning || cxyz.Size() == dim,
"Expected " << mesh->SpaceDimension() << " integers with the "
"option --cartesian-partitioning.");
MFEM_VERIFY(!cartesian_partitioning || num_tasks == cproduct,
"Expected cartesian partitioning product to match number of ranks.");
}
int *partitioning = cartesian_partitioning ?
mesh->CartesianPartitioning(cxyz) :
mesh->CartesianPartitioning(nxyz);
pmesh = new ParMesh(MPI_COMM_WORLD, *mesh, partitioning);
delete[] partitioning;
}
else
{
if ( Mpi::Root() )
{
cout << "Non-Cartesian partitioning through METIS will be used.\n";
#ifndef MFEM_USE_METIS
MFEM_ABORT("MFEM was built without METIS.\nAdjust the number of tasks to use a Cartesian split.");
#endif
}
pmesh = new ParMesh(MPI_COMM_WORLD, *mesh);
}
delete[] nxyz;
delete mesh;
// Refine the mesh further in parallel to increase the resolution.
for(int lev = 0; lev < param.mesh.rp_levels; lev++)
pmesh->UniformRefinement();
// pmesh->Rebalance();
int NE = pmesh->GetNE(), ne_min, ne_max;
MPI_Reduce(&NE, &ne_min, 1, MPI_INT, MPI_MIN, 0, pmesh->GetComm());
MPI_Reduce(&NE, &ne_max, 1, MPI_INT, MPI_MAX, 0, pmesh->GetComm());
if( Mpi::Root() )
cout << "Zones min/max: " << ne_min << " " << ne_max << endl;
}
static void Collect_boundingbox_info( ParMesh *pmesh, Param ¶m, Vector &bb_center, Vector &bb_length)
{
const int dim = pmesh->Dimension();
MFEM_VERIFY( bb_center.Size() == dim && bb_length.Size() == dim, "The size of bb_center and bb_length should be equal to dim.");
// Mesh bounding box
Vector bb_min(dim), bb_max(dim);
pmesh->GetBoundingBox(bb_min, bb_max, max(param.mesh.order_v, 1));
for( int i = 0; i < dim; i++)
{
bb_center[i] = (bb_min[i] + bb_max[i]) * 0.5;
bb_length[i] = (bb_max[i] - bb_min[i]);
}
}
int main(int argc, char *argv[])
{
// Initialize MPI.
Mpi::Init();
int myid = Mpi::WorldRank();
Hypre::Init();
// Print the banner.
if (Mpi::Root()) { display_banner(cout); }
// Take care of input parameters given in a file or command line.
OptionsParser args(argc, argv);
Param param;
read_and_assign_input_parameters( args, param, myid );
// Remeshing performs using the Target-Matrix Optimization Paradigm (TMOP)
bool mesh_changed = false;
bool mesh_control_side = false;
// Configure the device from the command line options
Device backend;
backend.Configure(param.sim.device, param.sim.dev);
if (Mpi::Root()) { backend.Print(); }
backend.SetGPUAwareMPI(param.sim.gpu_aware_mpi);
// Create, refine and partition the starting mesh.
Mesh *mesh = nullptr;
ParMesh *pmesh = nullptr;
// On all processors, use the default builtin 1D/2D/3D mesh or read the
// serial one given on the command line.
Generate_and_refine_initial_mesh(mesh, param);
// Parallel partitioning of the mesh.
Partition_initial_mesh(pmesh, mesh, param);
// Collect the bounding box info for the initial mesh for remeshing.
Vector bb_center(pmesh->Dimension());
Vector bb_length(pmesh->Dimension());
Collect_boundingbox_info(pmesh, param, bb_center, bb_length);
// Define the parallel finite element spaces. We use:
// - H1 (Gauss-Lobatto, continuous) for position and velocity.
// - L2 (Bernstein, discontinuous) for specific internal energy and symmetric Cauchy stress.
// L2_FECollection BasisType: Positive, GaussLegendre, GaussLobatto
L2_FECollection L2FEC(param.mesh.order_e, dim, BasisType::GaussLobatto); // Closed type.
ParFiniteElementSpace L2FESpace(pmesh, &L2FEC); // FES for energy.
ParFiniteElementSpace L2FESpace_stress(pmesh, &L2FEC, 3*(dim-1)); // FES for stress. EC: Why not of the Coefficient type?
H1_FECollection H1FEC(param.mesh.order_v, dim);
ParFiniteElementSpace H1FESpace(pmesh, &H1FEC, pmesh->Dimension());
// Non-positive basis drives oscillation while interpolation wtihin DG type elements.
L2_FECollection l2_fec(param.mesh.order_e, pmesh->Dimension(), BasisType::Positive);
ParFiniteElementSpace l2_fes(pmesh, &l2_fec);
// Boundary conditions: all tests use v.n = 0 on the boundary, and we assume
// that the boundaries are straight.
// Remove square brackets and spaces
param.bc.bc_ids.erase(std::remove(param.bc.bc_ids.begin(), param.bc.bc_ids.end(), '['), param.bc.bc_ids.end());
param.bc.bc_ids.erase(std::remove(param.bc.bc_ids.begin(), param.bc.bc_ids.end(), ']'), param.bc.bc_ids.end());
param.bc.bc_ids.erase(std::remove(param.bc.bc_ids.begin(), param.bc.bc_ids.end(), ' '), param.bc.bc_ids.end());
// Create a stringstream to tokenize the string
std::stringstream ss(param.bc.bc_ids);
std::vector<int> bc_id;
// Temporary variable to store each token
std::string token;
// std::cout <<"check point1"<<std::endl;
// Tokenize the string and convert tokens to integers
while (getline(ss, token, ','))
{bc_id.push_back(std::stoi(token)); // Convert string to int and add to vector
}
// std::cout <<"check point2"<<std::endl;
if(pmesh->bdr_attributes.Max() != bc_id.size())
{
if (myid == 0){cout << "The number of boundaries are not consistent with the given mesh. \nBC indicator from mesh is " << pmesh->bdr_attributes.Max() << " but input is " << bc_id.size() << endl; }
delete pmesh;
MPI_Finalize();
return 3;
}
// Boundary velocity of x component
param.bc.bc_vxs.erase(std::remove(param.bc.bc_vxs.begin(), param.bc.bc_vxs.end(), '['), param.bc.bc_vxs.end());
param.bc.bc_vxs.erase(std::remove(param.bc.bc_vxs.begin(), param.bc.bc_vxs.end(), ']'), param.bc.bc_vxs.end());
param.bc.bc_vxs.erase(std::remove(param.bc.bc_vxs.begin(), param.bc.bc_vxs.end(), ' '), param.bc.bc_vxs.end());
// Create a stringstream to tokenize the string
std::stringstream vxs(param.bc.bc_vxs);
std::vector<double> bc_vx;
// Tokenize the string and convert tokens to integers
while (getline(vxs, token, ','))
{bc_vx.push_back(std::stod(token)); // Convert string to int and add to vector
}
// Boundary velocity of y component
param.bc.bc_vys.erase(std::remove(param.bc.bc_vys.begin(), param.bc.bc_vys.end(), '['), param.bc.bc_vys.end());
param.bc.bc_vys.erase(std::remove(param.bc.bc_vys.begin(), param.bc.bc_vys.end(), ']'), param.bc.bc_vys.end());
param.bc.bc_vys.erase(std::remove(param.bc.bc_vys.begin(), param.bc.bc_vys.end(), ' '), param.bc.bc_vys.end());
// Create a stringstream to tokenize the string
std::stringstream vys(param.bc.bc_vys);
std::vector<double> bc_vy;
// Tokenize the string and convert tokens to integers
while (getline(vys, token, ','))
{bc_vy.push_back(std::stod(token)); // Convert string to int and add to vector
}
// Boundary velocity of z component
param.bc.bc_vzs.erase(std::remove(param.bc.bc_vzs.begin(), param.bc.bc_vzs.end(), '['), param.bc.bc_vzs.end());
param.bc.bc_vzs.erase(std::remove(param.bc.bc_vzs.begin(), param.bc.bc_vzs.end(), ']'), param.bc.bc_vzs.end());
param.bc.bc_vzs.erase(std::remove(param.bc.bc_vzs.begin(), param.bc.bc_vzs.end(), ' '), param.bc.bc_vzs.end());
// Create a stringstream to tokenize the string
std::stringstream vzs(param.bc.bc_vzs);
std::vector<double> bc_vz;
// Tokenize the string and convert tokens to integers
while (getline(vzs, token, ','))
{bc_vz.push_back(std::stod(token)); // Convert string to int and add to vector
}
// Dirichlet type boundary condition (i.e., fixing velocity component at boundaries)
Array<int> ess_tdofs, ess_vdofs;
{
Array<int> ess_bdr(pmesh->bdr_attributes.Max()), dofs_marker, dofs_list;
for (int i = 0; i < bc_id.size(); ++i)
{
ess_bdr = 0;
if(bc_id[i] > 0)
{
if(dim == 2)
{
switch (bc_id[i])
{
// case 1 : x compoent is constained
// case 2 : y compoent is constained
// case 3 : all compoents are constained
case 1: ess_bdr[i] = 1; H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,0); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list); break;
case 2: ess_bdr[i] = 1; H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,1); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list); break;
case 3: ess_bdr[i] = 1; H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list); break;
default:
if (myid == 0)
{
cout << "Unknown boundary type: " << bc_id[i] << '\n';
}
delete pmesh;
MPI_Finalize();
return 3;
}
}
else
{
switch (bc_id[i])
{
// case 1 : x compoent is constained
// case 2 : y compoent is constained
// case 3 : z compoent is constained
// case 4 : all compoents are constained
// case 5 : x and y compoents are constained
// case 6 : x and z compoents are constained
// case 7 : y and z compoents are constained
case 1: ess_bdr[i] = 1; H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,0); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list); break;
case 2: ess_bdr[i] = 1; H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,1); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list); break;
case 3: ess_bdr[i] = 1; H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,2); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,2); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list); break;
case 4: ess_bdr[i] = 1; H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list); break;
case 5:
ess_bdr[i] = 1;
H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,0); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list);
H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,1); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list);
break;
case 6:
ess_bdr[i] = 1;
H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,0); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list);
H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,2); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,2); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list);
break;
case 7:
ess_bdr[i] = 1;
H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,1); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list);
H1FESpace.GetEssentialTrueDofs(ess_bdr, dofs_list,2); ess_tdofs.Append(dofs_list); H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,2); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list); ess_vdofs.Append(dofs_list);
break;
default:
if (myid == 0)
{
cout << "Unknown boundary type: " << bc_id[i] << '\n';
}
delete pmesh;
MPI_Finalize();
return 3;
}
}
}
}
}
Vector bc_id_pa(pmesh->bdr_attributes.Max());
for (int i = 0; i < bc_id.size(); ++i){bc_id_pa[i]=bc_id[i];}
// Define the explicit ODE solver used for time integration.
ODESolver *ode_solver = NULL;
switch (param.solver.ode_solver_type)
{
case 1: ode_solver = new ForwardEulerSolver; break;
case 2: ode_solver = new RK2Solver(0.5); break;
case 3: ode_solver = new RK3SSPSolver; break;
case 4: ode_solver = new RK4Solver; break;
case 6: ode_solver = new RK6Solver; break;
case 7: ode_solver = new RK2AvgSolver; break;
default:
if (myid == 0)
{
cout << "Unknown ODE solver type: " << param.solver.ode_solver_type << '\n';
}
delete pmesh;
MPI_Finalize();
return 3;
}
// 4. Define the ODE solver for submesh used for time integration. Several implicit
// singly diagonal implicit Runge-Kutta (SDIRK) methods, as well as
// explicit Runge-Kutta methods are available.
int ode_solver_type = 12;
ODESolver *ode_solver_sub;
ODESolver *ode_solver_sub2;
switch (ode_solver_type)
{
// Implicit L-stable methods
case 1: ode_solver_sub = new BackwardEulerSolver; break;
case 2: ode_solver_sub = new SDIRK23Solver(2); break;
case 3: ode_solver_sub = new SDIRK33Solver; break;
// Explicit methods
case 11: ode_solver_sub = new ForwardEulerSolver; break;
case 12: ode_solver_sub = new RK2Solver(0.5); break; // midpoint method
case 13: ode_solver_sub = new RK3SSPSolver; break;
case 14: ode_solver_sub = new RK4Solver; break;
case 15: ode_solver_sub = new GeneralizedAlphaSolver(0.5); break;
// Implicit A-stable methods (not L-stable)
case 22: ode_solver_sub = new ImplicitMidpointSolver; break;
case 23: ode_solver_sub = new SDIRK23Solver; break;
case 24: ode_solver_sub = new SDIRK34Solver; break;
default:
if (myid == 0)
{
cout << "Unknown ODE solver type: " << ode_solver_type << '\n';
}
delete pmesh;
MPI_Finalize();
return 3;
}
switch (ode_solver_type)
{
// Implicit L-stable methods
case 1: ode_solver_sub2 = new BackwardEulerSolver; break;
case 2: ode_solver_sub2 = new SDIRK23Solver(2); break;
case 3: ode_solver_sub2 = new SDIRK33Solver; break;
// Explicit methods
case 11: ode_solver_sub2 = new ForwardEulerSolver; break;
case 12: ode_solver_sub2 = new RK2Solver(0.5); break; // midpoint method
case 13: ode_solver_sub2 = new RK3SSPSolver; break;
case 14: ode_solver_sub2 = new RK4Solver; break;
case 15: ode_solver_sub2 = new GeneralizedAlphaSolver(0.5); break;
// Implicit A-stable methods (not L-stable)
case 22: ode_solver_sub2 = new ImplicitMidpointSolver; break;
case 23: ode_solver_sub2 = new SDIRK23Solver; break;
case 24: ode_solver_sub2 = new SDIRK34Solver; break;
default:
if (myid == 0)
{
cout << "Unknown ODE solver type: " << ode_solver_type << '\n';
}
delete pmesh;
MPI_Finalize();
return 3;
}
const HYPRE_Int glob_size_l2 = L2FESpace.GlobalTrueVSize();
const HYPRE_Int glob_size_h1 = H1FESpace.GlobalTrueVSize();
if (Mpi::Root())
{
cout << "Number of kinematic (position, velocity) dofs: "
<< glob_size_h1 << endl;
cout << "Number of specific internal energy dofs: "
<< glob_size_l2 << endl;
}
// The monolithic BlockVector stores unknown fields as:
// - 0 -> position
// - 1 -> velocity
// - 2 -> specific internal energy
// - 3 -> stress
const int Vsize_l2 = L2FESpace.GetVSize();
const int Vsize_h1 = H1FESpace.GetVSize();
Array<int> offset(5); // when you change this number, you should chnage block offset in solver.cpp too
offset[0] = 0;
offset[1] = offset[0] + Vsize_h1;
offset[2] = offset[1] + Vsize_h1;
offset[3] = offset[2] + Vsize_l2;
offset[4] = offset[3] + Vsize_l2*3*(dim-1);
// offset[5] = offset[4] + Vsize_h1;
BlockVector S(offset, Device::GetMemoryType());
// Define GridFunction objects for the position, velocity and specific
// internal energy. There is no function for the density, as we can always
// compute the density values given the current mesh position, using the
// property of pointwise mass conservation.
ParGridFunction x_gf, v_gf, e_gf, s_gf;
x_gf.MakeRef(&H1FESpace, S, offset[0]);
v_gf.MakeRef(&H1FESpace, S, offset[1]);
e_gf.MakeRef(&L2FESpace, S, offset[2]);
s_gf.MakeRef(&L2FESpace_stress, S, offset[3]);
pmesh->SetNodalGridFunction(&x_gf);
// Sync the data location of x_gf with its base, S
x_gf.SyncAliasMemory(S);
// Create a "sub mesh" from the boundary elements with attribute 3 (top boundary) for Surface process
Array<int> bdr_attrs(1);
bdr_attrs[0] = 4;
ParSubMesh submesh(ParSubMesh::CreateFromBoundary(*pmesh, bdr_attrs));
ParFiniteElementSpace sub_fespace0(&submesh, &H1FEC, pmesh->Dimension()); // nodes of submesh
ParFiniteElementSpace sub_fespace1(&submesh, &H1FEC); // topography
// Solve a Poisson problem on the boundary. This just follows ex0p.
Array<int> boundary_dofs;
sub_fespace1.GetBoundaryTrueDofs(boundary_dofs);
ParGridFunction x_top(&sub_fespace0);
// ParGridFunction x_top_old(&sub_fespace0);
ParGridFunction topo(&sub_fespace1);
submesh.SetNodalGridFunction(&x_top);
// submesh.SetNodalGridFunction(&x_top_old);
for (int i = 0; i < topo.Size(); i++){topo[i] = x_top[i+topo.Size()];}
Vector topo_t, topo_t_old;
topo.GetTrueDofs(topo_t); topo_t_old=topo;
// Create a "sub mesh" from the boundary elements with attribute 2 (bottom boundary) for flattening
Array<int> bdr_attrs_b(1);
bdr_attrs_b[0] = 3;
ParSubMesh submesh_bottom(ParSubMesh::CreateFromBoundary(*pmesh, bdr_attrs_b));
ParFiniteElementSpace sub_fespace2(&submesh_bottom, &H1FEC, pmesh->Dimension()); // nodes of submesh
ParFiniteElementSpace sub_fespace3(&submesh_bottom, &H1FEC); // topography
// Solve a Poisson problem on the boundary. This just follows ex0p.
Array<int> boundary_dofs_bot;
sub_fespace2.GetBoundaryTrueDofs(boundary_dofs_bot);
ParGridFunction x_bottom(&sub_fespace2);
// ParGridFunction x_bottom_old(&sub_fespace2);
ParGridFunction bottom(&sub_fespace3);
submesh_bottom.SetNodalGridFunction(&x_bottom);
// submesh_bottom.SetNodalGridFunction(&x_bottom_old);
for (int i = 0; i < bottom.Size(); i++){bottom[i] = x_bottom[i+bottom.Size()];}
Vector bottom_t, bottom_t_old;
bottom.GetTrueDofs(bottom_t); bottom_t_old=bottom;
// Create a "sub mesh" from the boundary elements with attribute 0
Array<int> bdr_attrs_x0(1);
bdr_attrs_x0[0] = 1;
ParSubMesh submesh_x0(ParSubMesh::CreateFromBoundary(*pmesh, bdr_attrs_x0));
ParFiniteElementSpace sub_fespace4(&submesh_x0, &H1FEC, pmesh->Dimension()); // right sidewall
ParGridFunction x0_side(&sub_fespace4);
submesh_x0.SetNodalGridFunction(&x0_side);
// Create a "sub mesh" from the boundary elements with attribute 0
Array<int> bdr_attrs_x1(1);
bdr_attrs_x1[0] = 2;
ParSubMesh submesh_x1(ParSubMesh::CreateFromBoundary(*pmesh, bdr_attrs_x1));
ParFiniteElementSpace sub_fespace5(&submesh_x1, &H1FEC, pmesh->Dimension()); // right sidewall
ParGridFunction x1_side(&sub_fespace5);
submesh_x1.SetNodalGridFunction(&x1_side);
if(dim == 3)
{
// Create a "sub mesh" from the boundary elements with attribute 0
Array<int> bdr_attrs_y0(1);
bdr_attrs_y0[0] = 5;
ParSubMesh submesh_y0(ParSubMesh::CreateFromBoundary(*pmesh, bdr_attrs_y0));
ParFiniteElementSpace sub_fespace4(&submesh_y0, &H1FEC, pmesh->Dimension()); // right sidewall
ParGridFunction y0_side(&sub_fespace4);
submesh_y0.SetNodalGridFunction(&y0_side);
// Create a "sub mesh" from the boundary elements with attribute 0
Array<int> bdr_attrs_y1(1);
bdr_attrs_y1[0] = 6;
ParSubMesh submesh_y1(ParSubMesh::CreateFromBoundary(*pmesh, bdr_attrs_y1));
ParFiniteElementSpace sub_fespace5(&submesh_y1, &H1FEC, pmesh->Dimension()); // right sidewall
ParGridFunction y1_side(&sub_fespace5);
submesh_y1.SetNodalGridFunction(&y1_side);
}
//
// ParGridFunction x_bottom(&sub_fespace2);
// ParGridFunction bottom(&sub_fespace3);
// submesh_bottom.SetNodalGridFunction(&x_bottom);
// for (int i = 0; i < bottom.Size(); i++){bottom[i] = x_bottom[i+bottom.Size()];}
// 9. Initialize the conduction operator for surface diffusion
ConductionOperator oper_sub( sub_fespace1, param.bc.surf_alpha, param.bc.surf_diff, topo_t );
ConductionOperator oper_sub2( sub_fespace3, param.bc.base_alpha, param.bc.base_diff, bottom_t );
// xyz coordinates in L2 space
ParFiniteElementSpace L2FESpace_xyz(pmesh, &l2_fec, dim); //
ParGridFunction xyz_gf_l2(&L2FESpace_xyz);
VectorFunctionCoefficient xyz_coeff(pmesh->Dimension(), xyz0);
xyz_gf_l2.ProjectCoefficient(xyz_coeff);
int nSize = 1, nAspr = 1, nSkew = 1;
if (dim == 3)
{
nAspr = 2;
nSkew = 3;
}
// Total number of geometric parameters; for now we skip orientation.
const int nTotalParams = nSize + nAspr + nSkew;
// Define a GridFunction for all geometric parameters associated with the
// mesh.
ParFiniteElementSpace L2FESpace_geometric(pmesh, &L2FEC, nTotalParams); // must order byNodes
ParGridFunction quality(&L2FESpace_geometric);
// Vector quality; quality.SetSize(e_gf.Size()*nTotalParams);
DenseMatrix jacobian(dim);
Vector geomParams(nTotalParams);
Array<int> vdofs;
Vector allVals;
// Compute the geometric parameter at the dofs of each element.
for (int e = 0; e < pmesh->GetNE(); e++)
{
const FiniteElement *fe = L2FESpace_geometric.GetFE(e);
const IntegrationRule &ir = fe->GetNodes();
L2FESpace_geometric.GetElementVDofs(e, vdofs);
allVals.SetSize(vdofs.Size());
for (int q = 0; q < ir.GetNPoints(); q++)
{
const IntegrationPoint &ip = ir.IntPoint(q);
pmesh->GetElementJacobian(e, jacobian, &ip);
double sizeVal;
Vector asprVals, skewVals, oriVals;
pmesh->GetGeometricParametersFromJacobian(jacobian, sizeVal,
asprVals, skewVals, oriVals);
allVals(q + 0) = sizeVal;
for (int n = 0; n < nAspr; n++)
{
if(asprVals(n) > 1.0){allVals(q + (n+1)*ir.GetNPoints()) = asprVals(n);}
else{allVals(q + (n+1)*ir.GetNPoints()) = 1/asprVals(n);}
}
for (int n = 0; n < nSkew; n++)
{
allVals(q + (n+1+nAspr)*ir.GetNPoints()) = skewVals(n);
}
}
quality.SetSubVector(vdofs, allVals);
}
ParGridFunction vol_ini_gf(&L2FESpace);
ParGridFunction skew_ini_gf(&L2FESpace);
for (int i = 0; i < vol_ini_gf.Size(); i++){vol_ini_gf[i] = quality[i]; skew_ini_gf[i] = quality[i + e_gf.Size()];}
// Initialize the velocity.
v_gf = 0.0;
// PlasticCoefficient p_coeff(dim, xyz_gf_l2, weak_location, param.mat.weak_rad, param.mat.ini_pls);
VectorFunctionCoefficient v_coeff(pmesh->Dimension(), v0);
v_gf.ProjectCoefficient(v_coeff);
double max_vbc_val = param.control.max_vbc_val;
double v_unit = param.bc.vel_unit;
for (int i = 0; i < bc_id.size(); ++i)
// for (int i = bc_id.size() -1; i > -1; --i)
{
Array<int> ess_bdr(pmesh->bdr_attributes.Max()), dofs_marker, dofs_list1, dofs_list2, dofs_list3;
if(bc_id[i] > 0)
{
if(dim == 2)
max_vbc_val = std::max(max_vbc_val, sqrt(pow(v_unit*bc_vx[i], 2) + pow(v_unit*bc_vy[i], 2)));
else
max_vbc_val = std::max(max_vbc_val, sqrt(pow(v_unit*bc_vx[i], 2) + pow(v_unit*bc_vy[i], 2) + pow(v_unit*bc_vz[i], 2)));
ess_bdr = 0;
if(dim == 2)
{
switch (bc_id[i])
{
// case 1 : x compoent is constained
// case 2 : y compoent is constained
// case 3 : all compoents are constained
case 1: ess_bdr[i] = 1; H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list1); for (int j = 0; j < dofs_list1.Size(); j++){v_gf(dofs_list1[j]) = v_unit*bc_vx[i];} break;
case 2: ess_bdr[i] = 1; H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list2); for (int j = 0; j < dofs_list2.Size(); j++){v_gf(dofs_list2[j]) = v_unit*bc_vy[i];} break;
case 3: ess_bdr[i] = 1;
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list1); for (int j = 0; j < dofs_list1.Size(); j++){v_gf(dofs_list1[j]) = v_unit*bc_vx[i];}
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list2); for (int j = 0; j < dofs_list2.Size(); j++){v_gf(dofs_list2[j]) = v_unit*bc_vy[i];} break;
default:
if (myid == 0)
{
cout << "Unknown boundary type: " << bc_id[i] << '\n';
}
delete pmesh;
MPI_Finalize();
return 3;
}
}
else
{
switch (bc_id[i])
{
// case 1 : x compoent is constained
// case 2 : y compoent is constained
// case 3 : z compoent is constained
// case 4 : all compoents are constained
// case 5 : x and y compoents are constained
// case 6 : x and z compoents are constained
// case 7 : y and z compoents are constained
case 1: ess_bdr[i] = 1; H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list1); for (int j = 0; j < dofs_list1.Size(); j++){v_gf(dofs_list1[j]) = v_unit*bc_vx[i];} break;
case 2: ess_bdr[i] = 1; H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list2); for (int j = 0; j < dofs_list2.Size(); j++){v_gf(dofs_list2[j]) = v_unit*bc_vy[i];} break;
case 3: ess_bdr[i] = 1; H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,2); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list3); for (int j = 0; j < dofs_list3.Size(); j++){v_gf(dofs_list3[j]) = v_unit*bc_vz[i];} break;
case 4: ess_bdr[i] = 1;
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list1); for (int j = 0; j < dofs_list1.Size(); j++){v_gf(dofs_list1[j]) = v_unit*bc_vx[i];}
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list2); for (int j = 0; j < dofs_list2.Size(); j++){v_gf(dofs_list2[j]) = v_unit*bc_vy[i];}
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,2); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list3); for (int j = 0; j < dofs_list3.Size(); j++){v_gf(dofs_list3[j]) = v_unit*bc_vz[i];} break;
case 5: ess_bdr[i] = 1;
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list1); for (int j = 0; j < dofs_list1.Size(); j++){v_gf(dofs_list1[j]) = v_unit*bc_vx[i];}
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list2); for (int j = 0; j < dofs_list2.Size(); j++){v_gf(dofs_list2[j]) = v_unit*bc_vy[i];} break;
case 6: ess_bdr[i] = 1;
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,0); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list1); for (int j = 0; j < dofs_list1.Size(); j++){v_gf(dofs_list1[j]) = v_unit*bc_vx[i];}
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,2); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list3); for (int j = 0; j < dofs_list3.Size(); j++){v_gf(dofs_list3[j]) = v_unit*bc_vz[i];} break;
case 7: ess_bdr[i] = 1;
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,1); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list2); for (int j = 0; j < dofs_list2.Size(); j++){v_gf(dofs_list2[j]) = v_unit*bc_vy[i];}
H1FESpace.GetEssentialVDofs(ess_bdr, dofs_marker,2); FiniteElementSpace::MarkerToList(dofs_marker, dofs_list3); for (int j = 0; j < dofs_list3.Size(); j++){v_gf(dofs_list3[j]) = v_unit*bc_vz[i];} break;
default:
if (myid == 0)
{
cout << "Unknown boundary type: " << bc_id[i] << '\n';
}
delete pmesh;
MPI_Finalize();
return 3;
}
}
}
}
// Sync the data location of v_gf with its base, S
v_gf.SyncAliasMemory(S);
// String (Material) extraction
param.mat.rho.erase(std::remove(param.mat.rho.begin(), param.mat.rho.end(), '['), param.mat.rho.end());
param.mat.rho.erase(std::remove(param.mat.rho.begin(), param.mat.rho.end(), ']'), param.mat.rho.end());
param.mat.rho.erase(std::remove(param.mat.rho.begin(), param.mat.rho.end(), ' '), param.mat.rho.end());
// Create a stringstream to tokenize the string
std::stringstream ss2(param.mat.rho);
std::vector<double> rho_vec;
// Tokenize the string and convert tokens to integers
while (getline(ss2, token, ','))
{rho_vec.push_back(std::stod(token)); // Convert string to int and add to vector
}
param.mat.lambda.erase(std::remove(param.mat.lambda.begin(), param.mat.lambda.end(), '['), param.mat.lambda.end());
param.mat.lambda.erase(std::remove(param.mat.lambda.begin(), param.mat.lambda.end(), ']'), param.mat.lambda.end());
param.mat.lambda.erase(std::remove(param.mat.lambda.begin(), param.mat.lambda.end(), ' '), param.mat.lambda.end());
// Create a stringstream to tokenize the string
std::stringstream ss3(param.mat.lambda);
std::vector<double> lambda_vec;
// Tokenize the string and convert tokens to integers
while (getline(ss3, token, ','))
{
lambda_vec.push_back(std::stod(token)); // Convert string to int and add to vector
}
// String (Material) extraction
param.mat.mu.erase(std::remove(param.mat.mu.begin(), param.mat.mu.end(), '['), param.mat.mu.end());
param.mat.mu.erase(std::remove(param.mat.mu.begin(), param.mat.mu.end(), ']'), param.mat.mu.end());
param.mat.mu.erase(std::remove(param.mat.mu.begin(), param.mat.mu.end(), ' '), param.mat.mu.end());
// Create a stringstream to tokenize the string