-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathProblemManager.cpp
More file actions
1313 lines (1078 loc) · 54.9 KB
/
ProblemManager.cpp
File metadata and controls
1313 lines (1078 loc) · 54.9 KB
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
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2024 TotalEnergies
* Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2023-2024 Chevron
* Copyright (c) 2019- GEOS/GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/
#define GEOS_DISPATCH_VEM /// enables VEM in FiniteElementDispatch
// Source includes
#include "ProblemManager.hpp"
#include "GeosxState.hpp"
#include "initialization.hpp"
#include "common/format/StringUtilities.hpp"
#include "common/Path.hpp"
#include "common/TimingMacros.hpp"
#include "constitutive/ConstitutiveManager.hpp"
#include "constitutiveDrivers/solid/TriaxialDriver.hpp"
#include "dataRepository/ConduitRestart.hpp"
#include "dataRepository/RestartFlags.hpp"
#include "dataRepository/KeyNames.hpp"
#include "discretizationMethods/NumericalMethodsManager.hpp"
#include "events/tasks/TasksManager.hpp"
#include "events/EventManager.hpp"
#include "finiteElement/FiniteElementDiscretization.hpp"
#include "common/format/LogPart.hpp"
#include "finiteElement/FiniteElementDiscretizationManager.hpp"
#include "finiteVolume/FluxApproximationBase.hpp"
#include "finiteVolume/HybridMimeticDiscretization.hpp"
#include "fieldSpecification/FieldSpecificationManager.hpp"
#include "fileIO/Outputs/OutputBase.hpp"
#include "fileIO/Outputs/OutputManager.hpp"
#include "functions/FunctionManager.hpp"
#include "linearAlgebra/DofManager.hpp"
#include "mesh/ExternalDataSourceManager.hpp"
#include "mesh/DomainPartition.hpp"
#include "mesh/MeshBody.hpp"
#include "mesh/MeshManager.hpp"
#include "mesh/generators/MeshGeneratorBase.hpp"
#include "mesh/simpleGeometricObjects/GeometricObjectManager.hpp"
#include "mesh/mpiCommunications/CommunicationTools.hpp"
#include "mesh/mpiCommunications/SpatialPartition.hpp"
#include "physicsSolvers/PhysicsSolverManager.hpp"
#include "physicsSolvers/PhysicsSolverBase.hpp"
#ifdef GEOS_USE_HYPREDRV
#include "linearAlgebra/interfaces/hypre/hypredrive.hpp"
#endif
#include "schema/schemaUtilities.hpp"
// System includes
#include <algorithm>
#include <vector>
#include <regex>
#include <sstream>
namespace geos
{
using namespace dataRepository;
using namespace constitutive;
#ifdef GEOS_USE_HYPREDRV
namespace
{
std::string formatDelimitedHypredriveYamlBlock( std::string const & title,
std::string const & yaml )
{
size_t const innerWidth = std::max< size_t >( title.size() + 2, 83 );
size_t const totalWidth = innerWidth + 4;
size_t const padding = innerWidth > title.size() ? innerWidth - title.size() : 0;
size_t const leftPadding = padding / 2;
size_t const rightPadding = padding - leftPadding;
std::ostringstream output;
std::string const border( totalWidth, '-' );
output << border << '\n';
output << "| "
<< std::string( leftPadding, ' ' )
<< title
<< std::string( rightPadding, ' ' )
<< " |\n";
output << border << '\n';
output << yaml;
if( yaml.empty() || yaml.back() != '\n' )
{
output << '\n';
}
output << border << '\n';
return output.str();
}
void logHypredriveInputs( PhysicsSolverManager & physicsSolverManager,
DomainPartition & domain )
{
Group const & meshBodies = domain.getMeshBodies();
physicsSolverManager.forSubGroups< PhysicsSolverBase >( [&]( PhysicsSolverBase & solver )
{
LinearSolverParameters const & params = solver.getLinearSolverParameters();
if( params.logLevel < 1 || !solver.deferLinearSolverParametersPrint() )
{
return;
}
// Sequentially coupled solvers do not assemble a solver-owned coupled system.
// Previewing their DOFs here can force unsupported fully implicit coupling paths.
if( solver.getNonlinearSolverParameters().couplingType() == NonlinearSolverParameters::CouplingType::Sequential )
{
return;
}
hypre::hypredrive::InputArgsParseTarget target;
if( !params.hypredriveInputFile.empty() )
{
if( !hypre::hypredrive::buildInputArgsParseTarget( params, target ) )
{
return;
}
}
else
{
if( solver.getMeshTargets().empty() )
{
solver.generateMeshTargetsFromTargetRegions( meshBodies );
}
DofManager previewDofManager( GEOS_FMT( "{}_hypredrivePreview", solver.getName() ) );
previewDofManager.setDomain( domain );
solver.setupDofs( domain, previewDofManager );
stdVector< string > const fieldNames = previewDofManager.fieldNames();
array1d< integer > const numComponentsPerField = previewDofManager.numComponentsPerField();
if( !hypre::hypredrive::buildInputArgsParseTarget( params,
fieldNames,
numComponentsPerField.toViewConst(),
target ) )
{
return;
}
}
GEOS_LOG_RANK_0( formatDelimitedHypredriveYamlBlock( GEOS_FMT( "{}: hypredrive input (YAML)", solver.getName() ),
hypre::hypredrive::formatInputArgsParseTargetYaml( target ) ) );
hypre::hypredrive::markInputArgsParseTargetLogged( target );
} );
}
}
#endif
ProblemManager::ProblemManager( conduit::Node & root ):
Group( keys::ProblemManager, root ),
m_physicsSolverManager( nullptr ),
m_eventManager( nullptr ),
m_functionManager( nullptr ),
m_fieldSpecificationManager( nullptr )
{
// Groups that do not read from the xml
registerGroup< DomainPartition >( groupKeys.domain );
Group & commandLine = registerGroup< Group >( groupKeys.commandLine );
commandLine.setRestartFlags( RestartFlags::WRITE );
setInputFlags( InputFlags::PROBLEM_ROOT );
registerGroup< ExternalDataSourceManager >( groupKeys.externalDataSourceManager );
m_fieldSpecificationManager = ®isterGroup< FieldSpecificationManager >( groupKeys.fieldSpecificationManager );
m_eventManager = ®isterGroup< EventManager >( groupKeys.eventManager );
registerGroup< NumericalMethodsManager >( groupKeys.numericalMethodsManager );
registerGroup< GeometricObjectManager >( groupKeys.geometricObjectManager );
registerGroup< MeshManager >( groupKeys.meshManager );
registerGroup< OutputManager >( groupKeys.outputManager );
m_physicsSolverManager = ®isterGroup< PhysicsSolverManager >( groupKeys.physicsSolverManager );
m_tasksManager = ®isterGroup< TasksManager >( groupKeys.tasksManager );
m_functionManager = ®isterGroup< FunctionManager >( groupKeys.functionManager );
// Command line entries
commandLine.registerWrapper< string >( viewKeys.inputFileName.key() ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Name of the input xml file." );
commandLine.registerWrapper< string >( viewKeys.restartFileName.key() ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Name of the restart file." );
commandLine.registerWrapper< integer >( viewKeys.beginFromRestart.key() ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Flag to indicate restart run." );
commandLine.registerWrapper< string >( viewKeys.problemName.key() ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Used in writing the output files, if not specified defaults to the name of the input file." );
commandLine.registerWrapper< string >( viewKeys.outputDirectory.key() ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Directory in which to put the output files, if not specified defaults to the current directory." );
commandLine.registerWrapper< integer >( viewKeys.xPartitionsOverride.key() ).
setApplyDefaultValue( 1 ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Number of partitions in the x-direction" );
commandLine.registerWrapper< integer >( viewKeys.yPartitionsOverride.key() ).
setApplyDefaultValue( 1 ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Number of partitions in the y-direction" );
commandLine.registerWrapper< integer >( viewKeys.zPartitionsOverride.key() ).
setApplyDefaultValue( 1 ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Number of partitions in the z-direction" );
commandLine.registerWrapper< integer >( viewKeys.overridePartitionNumbers.key() ).
setApplyDefaultValue( 0 ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Flag to indicate partition number override" );
commandLine.registerWrapper< string >( viewKeys.schemaFileName.key() ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Name of the output schema" );
commandLine.registerWrapper< integer >( viewKeys.useNonblockingMPI.key() ).
setApplyDefaultValue( 0 ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Whether to prefer using non-blocking MPI communication where implemented (results in non-deterministic DOF numbering)." );
commandLine.registerWrapper< integer >( viewKeys.suppressPinned.key( ) ).
setApplyDefaultValue( 0 ).
setRestartFlags( RestartFlags::WRITE ).
setDescription( "Whether to disallow using pinned memory allocations for MPI communication buffers." );
}
ProblemManager::~ProblemManager()
{
{
// This is a dummy to force the inclusion of constitutiveDrivers in the linking process for systems that have "--no-as-needed" as a
// default.
// The "correct" way to do this is in cmake using:
// target_link_options(constitutiveDrivers INTERFACE "SHELL:LINKER:--no-as-needed")
// but this applies "--no-as-needed" to all targets that link to constitutiveDrivers, which is not what we want.
// Also "--no-as-needed" is not supported on all platforms, so we have to guard the use of it.
// This is a workaround until we can figure out in cmake without too much trouble.
TriaxialDriver dummy( "dummy", this );
}
}
Group * ProblemManager::createChild( string const & GEOS_UNUSED_PARAM( childKey ), string const & GEOS_UNUSED_PARAM( childName ) )
{
// Unused as all children are created within the constructor
return nullptr;
}
void ProblemManager::problemSetup()
{
GEOS_MARK_FUNCTION;
postInputInitializationRecursive();
LogPart meshGenerationLog( "Mesh Generation", MpiWrapper::commRank() == 0 );
meshGenerationLog.begin();
generateMesh();
meshGenerationLog.end();
// initialize_postMeshGeneration();
{
LogPart numericalMethodLog( "Numerical Methods", MpiWrapper::commRank() == 0 );
numericalMethodLog.begin();
applyNumericalMethods();
numericalMethodLog.end();
}
registerDataOnMeshRecursive( getDomainPartition().getMeshBodies() );
initialize();
#ifdef GEOS_USE_HYPREDRV
logHypredriveInputs( *m_physicsSolverManager, getDomainPartition() );
#endif
LogPart importFieldsLog( "Import Fields", MpiWrapper::commRank() == 0 );
importFieldsLog.begin();
importFields();
importFieldsLog.end();
}
void ProblemManager::parseCommandLineInput()
{
Group & commandLine = getGroup< Group >( groupKeys.commandLine );
CommandLineOptions const & opts = getGlobalState().getCommandLineOptions();
commandLine.getReference< string >( viewKeys.restartFileName ) = opts.restartFileName;
commandLine.getReference< integer >( viewKeys.beginFromRestart ) = opts.beginFromRestart;
commandLine.getReference< integer >( viewKeys.xPartitionsOverride ) = opts.xPartitionsOverride;
commandLine.getReference< integer >( viewKeys.yPartitionsOverride ) = opts.yPartitionsOverride;
commandLine.getReference< integer >( viewKeys.zPartitionsOverride ) = opts.zPartitionsOverride;
commandLine.getReference< integer >( viewKeys.overridePartitionNumbers ) = opts.overridePartitionNumbers;
commandLine.getReference< integer >( viewKeys.useNonblockingMPI ) = opts.useNonblockingMPI;
commandLine.getReference< integer >( viewKeys.suppressPinned ) = opts.suppressPinned;
string & outputDirectory = commandLine.getReference< string >( viewKeys.outputDirectory );
outputDirectory = opts.outputDirectory;
OutputBase::setOutputDirectory( outputDirectory );
TaskBase::setOutputDirectory( outputDirectory );
string & inputFileName = commandLine.getReference< string >( viewKeys.inputFileName );
for( string const & xmlFile : opts.inputFileNames )
{
string const absPath = getAbsolutePath( xmlFile );
GEOS_LOG_RANK_0( "Opened XML file: " << absPath );
}
inputFileName = xmlWrapper::buildMultipleInputXML( opts.inputFileNames, outputDirectory );
string & schemaName = commandLine.getReference< string >( viewKeys.schemaFileName );
schemaName = opts.schemaName;
string & problemName = commandLine.getReference< string >( viewKeys.problemName );
problemName = opts.problemName;
OutputBase::setFileNameRoot( problemName );
if( schemaName.empty())
{
inputFileName = getAbsolutePath( inputFileName );
Path::setPathPrefix( splitPath( inputFileName ).first );
}
if( opts.traceDataMigration )
{
chai::ArrayManager::getInstance()->enableCallbacks();
}
else
{
chai::ArrayManager::getInstance()->disableCallbacks();
}
}
bool ProblemManager::parseRestart( string & restartFileName, CommandLineOptions const & options )
{
bool const beginFromRestart = options.beginFromRestart;
restartFileName = options.restartFileName;
if( beginFromRestart == 1 )
{
string dirname, basename;
std::tie( dirname, basename ) = splitPath( restartFileName );
stdVector< string > dir_contents = readDirectory( dirname );
GEOS_THROW_IF( dir_contents.empty(),
GEOS_FMT( "Directory gotten from {} {} is empty.", restartFileName, dirname ),
InputError );
std::regex basename_regex( basename );
string min_str;
string & max_match = min_str;
bool match_found = false;
for( string & s : dir_contents )
{
if( std::regex_match( s, basename_regex ))
{
match_found = true;
max_match = (s > max_match)? s : max_match;
}
}
GEOS_THROW_IF( !match_found,
GEOS_FMT( "No matches found for pattern {} in directory {}.", basename, dirname ),
InputError );
restartFileName = getAbsolutePath( dirname + "/" + max_match );
}
return beginFromRestart;
}
void ProblemManager::generateDocumentation()
{
// Documentation output
GEOS_LOG_RANK_0( "Trying to generate schema..." );
Group & commandLine = getGroup< Group >( groupKeys.commandLine );
string const & schemaName = commandLine.getReference< string >( viewKeys.schemaFileName );
if( !schemaName.empty() )
{
// Generate an extensive data structure
generateDataStructureSkeleton( 0 );
MeshManager & meshManager = this->getGroup< MeshManager >( groupKeys.meshManager );
DomainPartition & domain = getDomainPartition();
meshManager.generateMeshLevels( domain );
registerDataOnMeshRecursive( domain.getMeshBodies() );
// Generate schema
schemaUtilities::ConvertDocumentationToSchema( schemaName.c_str(), this, 0 );
// Generate non-schema documentation
schemaUtilities::ConvertDocumentationToSchema((schemaName + ".other").c_str(), this, 1 );
}
}
void ProblemManager::setSchemaDeviations( xmlWrapper::xmlNode schemaRoot,
xmlWrapper::xmlNode schemaParent,
integer documentationType )
{
xmlWrapper::xmlNode targetChoiceNode = schemaParent.child( "xsd:choice" );
if( targetChoiceNode.empty() )
{
targetChoiceNode = schemaParent.prepend_child( "xsd:choice" );
targetChoiceNode.append_attribute( "minOccurs" ) = "0";
targetChoiceNode.append_attribute( "maxOccurs" ) = "unbounded";
}
// These objects are handled differently during the xml read step,
// so we need to explicitly add them into the schema structure
DomainPartition & domain = getDomainPartition();
m_functionManager->generateDataStructureSkeleton( 0 );
schemaUtilities::SchemaConstruction( *m_functionManager, schemaRoot, targetChoiceNode, documentationType );
m_fieldSpecificationManager->generateDataStructureSkeleton( 0 );
schemaUtilities::SchemaConstruction( *m_fieldSpecificationManager, schemaRoot, targetChoiceNode, documentationType );
ConstitutiveManager & constitutiveManager = domain.getGroup< ConstitutiveManager >( groupKeys.constitutiveManager );
schemaUtilities::SchemaConstruction( constitutiveManager, schemaRoot, targetChoiceNode, documentationType );
MeshManager & meshManager = this->getGroup< MeshManager >( groupKeys.meshManager );
meshManager.generateMeshLevels( domain );
ElementRegionManager & elementManager = domain.getMeshBody( 0 ).getBaseDiscretization().getElemManager();
elementManager.generateDataStructureSkeleton( 0 );
schemaUtilities::SchemaConstruction( elementManager, schemaRoot, targetChoiceNode, documentationType );
ParticleManager & particleManager = domain.getMeshBody( 0 ).getBaseDiscretization().getParticleManager(); // TODO is this necessary? SJP
particleManager.generateDataStructureSkeleton( 0 );
schemaUtilities::SchemaConstruction( particleManager, schemaRoot, targetChoiceNode, documentationType );
// Add entries that are only used in the pre-processor
Group & IncludedList = this->registerGroup< Group >( xmlWrapper::includedListTag );
IncludedList.setInputFlags( InputFlags::OPTIONAL );
Group & includedFile = IncludedList.registerGroup< Group >( xmlWrapper::includedFileTag );
includedFile.setInputFlags( InputFlags::OPTIONAL_NONUNIQUE );
// the name of includedFile is actually a Path.
includedFile.registerWrapper< string >( "name" ).
setInputFlag( InputFlags::REQUIRED ).
setRTTypeName( rtTypes::getTypeName( typeid( Path ) ) ).
setDescription( "The relative file path." );
schemaUtilities::SchemaConstruction( IncludedList, schemaRoot, targetChoiceNode, documentationType );
Group & parameterList = this->registerGroup< Group >( "Parameters" );
parameterList.setInputFlags( InputFlags::OPTIONAL );
Group & parameter = parameterList.registerGroup< Group >( "Parameter" );
parameter.setInputFlags( InputFlags::OPTIONAL_NONUNIQUE );
parameter.registerWrapper< string >( "value" ).
setInputFlag( InputFlags::REQUIRED ).
setDescription( "Input parameter definition for the preprocessor" );
schemaUtilities::SchemaConstruction( parameterList, schemaRoot, targetChoiceNode, documentationType );
Group & benchmarks = this->registerGroup< Group >( "Benchmarks" );
benchmarks.setInputFlags( InputFlags::OPTIONAL );
for( string const machineName : {"quartz", "lassen", "crusher" } )
{
Group & machine = benchmarks.registerGroup< Group >( machineName );
machine.setInputFlags( InputFlags::OPTIONAL );
Group & run = machine.registerGroup< Group >( "Run" );
run.setInputFlags( InputFlags::OPTIONAL );
run.registerWrapper< string >( "name" ).setInputFlag( InputFlags::REQUIRED ).
setDescription( "The name of this benchmark." );
run.registerWrapper< int >( "timeLimit" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "The time limit of the benchmark." );
run.registerWrapper< string >( "args" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Any extra command line arguments to pass to GEOSX." );
run.registerWrapper< string >( "autoPartition" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "May be 'Off' or 'On', if 'On' partitioning arguments are created automatically. Default is Off." );
run.registerWrapper< string >( "scaling" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Whether to run a scaling, and which type of scaling to run." );
run.registerWrapper< int >( "nodes" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "The number of nodes needed to run the base benchmark, default is 1." );
run.registerWrapper< int >( "tasksPerNode" ).setInputFlag( InputFlags::REQUIRED ).
setDescription( "The number of tasks per node to run the benchmark with." );
run.registerWrapper< int >( "threadsPerTask" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "The number of threads per task to run the benchmark with." );
run.registerWrapper< array1d< int > >( "meshSizes" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "The target number of elements in the internal mesh (per-process for weak scaling, globally for strong scaling) default doesn't modify the internalMesh." );
run.registerWrapper< array1d< int > >( "scaleList" ).setInputFlag( InputFlags::OPTIONAL ).
setDescription( "The scales at which to run the problem ( scale * nodes * tasksPerNode )." );
}
schemaUtilities::SchemaConstruction( benchmarks, schemaRoot, targetChoiceNode, documentationType );
}
void ProblemManager::parseInputFile()
{
Group & commandLine = getGroup( groupKeys.commandLine );
string const & inputFileName = commandLine.getReference< string >( viewKeys.inputFileName );
// Load preprocessed xml file
xmlWrapper::xmlDocument xmlDocument;
xmlWrapper::xmlResult const xmlResult = xmlDocument.loadFile( inputFileName, true );
GEOS_THROW_IF( !xmlResult, GEOS_FMT( "Errors found while parsing XML file {}\nDescription: {}\nOffset: {}",
inputFileName, xmlResult.description(), xmlResult.offset ), InputError );
// Parse the results
parseXMLDocument( xmlDocument );
}
void ProblemManager::parseInputString( string const & xmlString )
{
// Load preprocessed xml file
xmlWrapper::xmlDocument xmlDocument;
xmlWrapper::xmlResult xmlResult = xmlDocument.loadString( xmlString, true );
GEOS_THROW_IF( !xmlResult, GEOS_FMT( "Errors found while parsing XML string\nDescription: {}\nOffset: {}",
xmlResult.description(), xmlResult.offset ), InputError );
// Parse the results
parseXMLDocument( xmlDocument );
}
void ProblemManager::parseXMLDocument( xmlWrapper::xmlDocument & xmlDocument )
{
// Extract the problem node and begin processing the user inputs
xmlWrapper::xmlNode xmlProblemNode = xmlDocument.getChild( this->getName().c_str() );
processInputFileRecursive( xmlDocument, xmlProblemNode );
// The objects in domain are handled separately for now
{
DomainPartition & domain = getDomainPartition();
ConstitutiveManager & constitutiveManager = domain.getGroup< ConstitutiveManager >( groupKeys.constitutiveManager );
xmlWrapper::xmlNode topLevelNode = xmlProblemNode.child( constitutiveManager.getName().c_str());
constitutiveManager.processInputFileRecursive( xmlDocument, topLevelNode );
// Open mesh levels
MeshManager & meshManager = this->getGroup< MeshManager >( groupKeys.meshManager );
meshManager.generateMeshLevels( domain );
Group & meshBodies = domain.getMeshBodies();
auto parseRegions = [&]( string_view regionManagerKey, bool const hasParticles )
{
xmlWrapper::xmlNode regionsNode = xmlProblemNode.child( regionManagerKey.data() );
xmlWrapper::xmlNodePos regionsNodePos = xmlDocument.getNodePosition( regionsNode );
std::set< string > regionNames;
for( xmlWrapper::xmlNode regionNode : regionsNode.children() )
{
auto const regionNodePos = xmlDocument.getNodePosition( regionNode );
string const regionName = Group::processInputName( regionNode, regionNodePos,
regionsNode.name(), regionsNodePos, regionNames );
try
{
string const regionMeshBodyName =
ElementRegionBase::verifyMeshBodyName( meshBodies,
regionNode.attribute( "meshBody" ).value() );
MeshBody & meshBody = domain.getMeshBody( regionMeshBodyName );
meshBody.setHasParticles( hasParticles );
meshBody.forMeshLevels( [&]( MeshLevel & meshLevel )
{
ObjectManagerBase & elementManager = hasParticles ?
static_cast< ObjectManagerBase & >( meshLevel.getParticleManager() ):
static_cast< ObjectManagerBase & >( meshLevel.getElemManager() );
Group * newRegion = elementManager.createChild( regionNode.name(), regionName );
newRegion->processInputFileRecursive( xmlDocument, regionNode );
} );
}
catch( InputError const & e )
{
string const errorMsg = GEOS_FMT( "Error while parsing region {} ({}):\n",
regionName, regionNodePos.toString() );
ErrorLogger::global().modifyCurrentExceptionMessage()
.addToMsg( errorMsg )
.addContextInfo( getDataContext().getContextInfo().setPriority( -1 ) );
throw InputError( e, errorMsg );
}
}
};
parseRegions( MeshLevel::groupStructKeys::elemManagerString(), false );
parseRegions( MeshLevel::groupStructKeys::particleManagerString(), true );
}
}
void ProblemManager::postInputInitialization()
{
DomainPartition & domain = getDomainPartition();
Group const & commandLine = getGroup< Group >( groupKeys.commandLine );
integer const & xparCL = commandLine.getReference< integer >( viewKeys.xPartitionsOverride );
integer const & yparCL = commandLine.getReference< integer >( viewKeys.yPartitionsOverride );
integer const & zparCL = commandLine.getReference< integer >( viewKeys.zPartitionsOverride );
integer const & suppressPinned = commandLine.getReference< integer >( viewKeys.suppressPinned );
setPreferPinned((suppressPinned == 0));
PartitionBase & partition = domain.getReference< PartitionBase >( keys::partitionManager );
bool repartition = false;
integer xpar = 1;
integer ypar = 1;
integer zpar = 1;
if( xparCL != 0 )
{
repartition = true;
xpar = xparCL;
}
if( yparCL != 0 )
{
repartition = true;
ypar = yparCL;
}
if( zparCL != 0 )
{
repartition = true;
zpar = zparCL;
}
if( repartition )
{
partition.setPartitions( xpar, ypar, zpar );
int const mpiSize = MpiWrapper::commSize( MPI_COMM_GEOS );
// Case : Using MPI domain decomposition and partition are not defined (mainly for external mesh readers)
if( mpiSize > 1 && xpar == 1 && ypar == 1 && zpar == 1 )
{
//TODO confirm creates no issues with MPI_Cart_Create
partition.setPartitions( 1, 1, mpiSize );
}
}
}
void ProblemManager::initializationOrder( string_array & order )
{
set< string > usedNames;
// first, numerical methods
order.emplace_back( groupKeys.numericalMethodsManager.key() );
usedNames.insert( groupKeys.numericalMethodsManager.key() );
// next, domain
order.emplace_back( groupKeys.domain.key() );
usedNames.insert( groupKeys.domain.key() );
// next, events
order.emplace_back( groupKeys.eventManager.key() );
usedNames.insert( groupKeys.eventManager.key() );
// (keeping outputs for the end)
usedNames.insert( groupKeys.outputManager.key() );
// next, everything...
for( auto const & subGroup : this->getSubGroups() )
{
if( usedNames.count( subGroup.first ) == 0 )
{
order.emplace_back( subGroup.first );
}
}
// end with outputs (in order to define the chunk sizes after any data source)
order.emplace_back( groupKeys.outputManager.key() );
}
void ProblemManager::generateMesh()
{
GEOS_MARK_FUNCTION;
DomainPartition & domain = getDomainPartition();
MeshManager & meshManager = this->getGroup< MeshManager >( groupKeys.meshManager );
meshManager.generateMeshes( domain );
// get all the discretizations from the numerical methods.
// map< pair< mesh body name, pointer to discretization>, array of region names >
map< std::pair< string, Group const * const >, string_array const & >
discretizations = getDiscretizations();
// setup the base discretizations (hard code this for now)
domain.forMeshBodies( [&]( MeshBody & meshBody )
{
MeshLevel & baseMesh = meshBody.getBaseDiscretization();
string_array junk;
if( meshBody.hasParticles() ) // mesh bodies with particles load their data into particle blocks, not cell blocks
{
ParticleBlockManagerABC & particleBlockManager = meshBody.getGroup< ParticleBlockManagerABC >( keys::particleManager );
this->generateMeshLevel( baseMesh,
particleBlockManager,
junk );
}
else
{
CellBlockManagerABC & cellBlockManager = meshBody.getGroup< CellBlockManagerABC >( keys::cellManager );
this->generateMeshLevel( baseMesh,
cellBlockManager,
nullptr,
junk );
ElementRegionManager & elemManager = baseMesh.getElemManager();
elemManager.generateWells( cellBlockManager, baseMesh );
}
} );
Group const & commandLine = this->getGroup< Group >( groupKeys.commandLine );
integer const useNonblockingMPI = commandLine.getReference< integer >( viewKeys.useNonblockingMPI );
domain.setupBaseLevelMeshGlobalInfo();
// setup the MeshLevel associated with the discretizations
for( auto const & discretizationPair: discretizations )
{
string const & meshBodyName = discretizationPair.first.first;
MeshBody & meshBody = domain.getMeshBody( meshBodyName );
if( discretizationPair.first.second!=nullptr && !meshBody.hasParticles() ) // this check shouldn't be required
{ // particle mesh bodies don't have a finite element
// discretization
FiniteElementDiscretization const * const
feDiscretization = dynamic_cast< FiniteElementDiscretization const * >( discretizationPair.first.second );
// if the discretization is a finite element discretization
if( feDiscretization != nullptr )
{
int const order = feDiscretization->getOrder();
string const & discretizationName = feDiscretization->getName();
FiniteElementDiscretization::Formulation const & formulationName = feDiscretization->getFormulation();
string_array const & regionNames = discretizationPair.second;
CellBlockManagerABC const & cellBlockManager = meshBody.getCellBlockManager();
// create a high order MeshLevel
if( order > 1 && formulationName == FiniteElementDiscretization::Formulation::SEM )
{
MeshLevel & mesh = meshBody.createMeshLevel( MeshBody::groupStructKeys::baseDiscretizationString(),
discretizationName, order );
this->generateMeshLevel( mesh,
cellBlockManager,
feDiscretization,
regionNames );
}
// Just create a shallow copy of the base discretization.
else if( order==1 || formulationName == FiniteElementDiscretization::Formulation::DG )
{
// create a shallow copy of the base discretization
meshBody.createShallowMeshLevel( MeshBody::groupStructKeys::baseDiscretizationString(),
discretizationName );
}
}
else // this is a finite volume discretization...i hope
{
Group const * const discretization = discretizationPair.first.second;
if( discretization != nullptr ) // ...it is FV if it isn't nullptr
{
string const & discretizationName = discretization->getName();
meshBody.createShallowMeshLevel( MeshBody::groupStructKeys::baseDiscretizationString(),
discretizationName );
}
}
}
}
domain.setupCommunications( useNonblockingMPI );
domain.outputPartitionInformation();
// Optionally validate the Euler-Poincaré characteristic χ = V − E + F − C.
// This must run AFTER setupCommunications() so that ghost cells and proper
// node ghost ranks are available. The computation reconstructs V, E, F from
// cell-to-node maps (iterating owned + ghost cells) and uses a min-global-
// node ownership rule for MPI de-duplication.
domain.forMeshBodies( [&]( MeshBody & meshBody )
{
MeshGeneratorBase const * const meshGen =
meshManager.getGroupPointer< MeshGeneratorBase >( meshBody.getName() );
if( meshGen != nullptr && meshGen->m_checkEulerCharacteristic )
{
MeshLevel & baseMesh = meshBody.getBaseDiscretization();
integer const chi = computeEulerCharacteristic( baseMesh.getNodeManager(),
baseMesh.getEdgeManager(),
baseMesh.getFaceManager(),
baseMesh.getElemManager() );
GEOS_LOG_RANK_0_IF( chi != 1,
"Mesh \"" << meshBody.getName() << "\": Euler-Poincaré characteristic "
"χ = V − E + F − C = " << chi << " (expected 1 for a single connected "
"solid without interior voids). The mesh may contain multiple disconnected "
"bodies, interior voids, or non-manifold topology. "
"The simulation will proceed." );
GEOS_LOG_RANK_0_IF( chi == 1,
"Mesh \"" << meshBody.getName() << "\": Euler characteristic χ = 1 ✓" );
}
} );
domain.forMeshBodies( [&]( MeshBody & meshBody )
{
if( meshBody.hasGroup( keys::particleManager ) )
{
meshBody.deregisterGroup( keys::particleManager );
}
else if( meshBody.hasGroup( keys::cellManager ) )
{
// meshBody.deregisterGroup( keys::cellManager );
meshBody.deregisterCellBlockManager();
}
meshBody.forMeshLevels( [&]( MeshLevel & meshLevel )
{
FaceManager & faceManager = meshLevel.getFaceManager();
EdgeManager & edgeManager = meshLevel.getEdgeManager();
NodeManager const & nodeManager = meshLevel.getNodeManager();
ElementRegionManager & elementManager = meshLevel.getElemManager();
elementManager.forElementSubRegions< FaceElementSubRegion >( [&]( FaceElementSubRegion & subRegion )
{
/// 1. The computation of geometric quantities which is now possible for `FaceElementSubRegion`,
// because the ghosting ensures that the neighbor cells of the fracture elements are available.
// These neighbor cells are providing the node information to the fracture elements.
subRegion.calculateElementGeometricQuantities( nodeManager, faceManager );
// 2. Reorder the face map based on global numbering of neighboring cells
subRegion.flipFaceMap( faceManager, elementManager );
// 3. We flip the face normals of faces adjacent to the faceElements if they are not pointing in the
// direction of the fracture.
subRegion.fixNeighboringFacesNormals( faceManager, elementManager );
// faceToNodes(kf0, a) and faceToNodes(kf1, a) are geometrically paired (collocated) nodes.
// This is required by the conforming contact kernels which assume this pairing.
subRegion.orderKf1NodesConsistentlyWithKf0( faceManager, nodeManager );
} );
faceManager.setIsExternal();
edgeManager.setIsExternal( faceManager );
} );
} );
}
void ProblemManager::importFields()
{
GEOS_MARK_FUNCTION;
DomainPartition & domain = getDomainPartition();
MeshManager & meshManager = this->getGroup< MeshManager >( groupKeys.meshManager );
meshManager.importFields( domain );
}
void ProblemManager::applyNumericalMethods()
{
DomainPartition & domain = getDomainPartition();
ConstitutiveManager & constitutiveManager = domain.getGroup< ConstitutiveManager >( groupKeys.constitutiveManager );
Group & meshBodies = domain.getMeshBodies();
// this contains a key tuple< mesh body name, mesh level name, region name, subregion name> with a value of the number of quadrature
// points.
map< std::tuple< string, string, string, string >, localIndex > const regionQuadrature = calculateRegionQuadrature( meshBodies );
setRegionQuadrature( meshBodies, constitutiveManager, regionQuadrature );
}
map< std::pair< string, Group const * const >, string_array const & >
ProblemManager::getDiscretizations() const
{
map< std::pair< string, Group const * const >, string_array const & > meshDiscretizations;
NumericalMethodsManager const &
numericalMethodManager = getGroup< NumericalMethodsManager >( groupKeys.numericalMethodsManager.key() );
FiniteElementDiscretizationManager const &
feDiscretizationManager = numericalMethodManager.getFiniteElementDiscretizationManager();
FiniteVolumeManager const &
fvDiscretizationManager = numericalMethodManager.getFiniteVolumeManager();
DomainPartition const & domain = getDomainPartition();
Group const & meshBodies = domain.getMeshBodies();
m_physicsSolverManager->forSubGroups< PhysicsSolverBase >( [&]( PhysicsSolverBase & solver )
{
solver.generateMeshTargetsFromTargetRegions( meshBodies );
string const discretizationName = solver.getDiscretizationName();
Group const *
discretization = feDiscretizationManager.getGroupPointer( discretizationName );
if( discretization==nullptr )
{
discretization = fvDiscretizationManager.getGroupPointer( discretizationName );
}
if( discretization!=nullptr )
{
solver.forDiscretizationOnMeshTargets( meshBodies,
[&]( string const & meshBodyName,
MeshLevel const &,
auto const & regionNames )
{
std::pair< string, Group const * const > key = std::make_pair( meshBodyName, discretization );
meshDiscretizations.insert( { key, regionNames } );
} );
}
} );
return meshDiscretizations;
}
void ProblemManager::generateMeshLevel( MeshLevel & meshLevel,
CellBlockManagerABC const & cellBlockManager,
Group const * const discretization,
string_array const & )
{
if( discretization != nullptr )
{
auto const * const
feDisc = dynamic_cast< FiniteElementDiscretization const * >(discretization);
auto const * const
fvsDisc = dynamic_cast< FluxApproximationBase const * >(discretization);
auto const * const
fvhDisc = dynamic_cast< HybridMimeticDiscretization const * >(discretization);
if( feDisc==nullptr && fvsDisc==nullptr && fvhDisc==nullptr )
{
GEOS_ERROR( "Group expected to cast to a discretization object." );
}
}
NodeManager & nodeManager = meshLevel.getNodeManager();
EdgeManager & edgeManager = meshLevel.getEdgeManager();
FaceManager & faceManager = meshLevel.getFaceManager();
ElementRegionManager & elemRegionManager = meshLevel.getElemManager();
bool const isBaseMeshLevel = meshLevel.getName() == MeshBody::groupStructKeys::baseDiscretizationString();
elemRegionManager.generateMesh( cellBlockManager );
nodeManager.setGeometricalRelations( cellBlockManager, elemRegionManager, isBaseMeshLevel );
edgeManager.setGeometricalRelations( cellBlockManager, isBaseMeshLevel );
faceManager.setGeometricalRelations( cellBlockManager, elemRegionManager, nodeManager, isBaseMeshLevel );
nodeManager.constructGlobalToLocalMap( cellBlockManager );
// Edge, face and element region managers rely on the sets provided by the node manager.
// This is why `nodeManager.buildSets` is called first.
nodeManager.buildSets( cellBlockManager, this->getGroup< GeometricObjectManager >( groupKeys.geometricObjectManager ) );
edgeManager.buildSets( nodeManager );
faceManager.buildSets( nodeManager );
elemRegionManager.buildSets( nodeManager );
// The edge manager do not hold any information related to the regions nor the elements.
// This is why the element region manager is not provided.
nodeManager.setupRelatedObjectsInRelations( edgeManager, faceManager, elemRegionManager );
edgeManager.setupRelatedObjectsInRelations( nodeManager, faceManager );
faceManager.setupRelatedObjectsInRelations( nodeManager, edgeManager, elemRegionManager );
// Node and edge managers rely on the boundary information provided by the face manager.
// This is why `faceManager.setDomainBoundaryObjects` is called first.
faceManager.setDomainBoundaryObjects( elemRegionManager );
edgeManager.setDomainBoundaryObjects( faceManager );
nodeManager.setDomainBoundaryObjects( faceManager, edgeManager );