-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathCompositionalMultiphaseBase.cpp
More file actions
3030 lines (2647 loc) · 151 KB
/
CompositionalMultiphaseBase.cpp
File metadata and controls
3030 lines (2647 loc) · 151 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.
* ------------------------------------------------------------------------------------------------------------
*/
/**
* @file CompositionalMultiphaseBase.cpp
*/
#include "CompositionalMultiphaseBase.hpp"
#include "constitutive/ConstitutiveManager.hpp"
#include "constitutive/capillaryPressure/CapillaryPressureFields.hpp"
#include "constitutive/capillaryPressure/CapillaryPressureSelector.hpp"
#include "constitutive/ConstitutivePassThru.hpp"
#include "constitutive/diffusion/DiffusionSelector.hpp"
#include "constitutive/dispersion/DispersionSelector.hpp"
#include "constitutive/fluid/multifluid/MultiFluidFields.hpp"
#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp"
#include "constitutive/relativePermeability/RelativePermeabilitySelector.hpp"
#include "constitutive/solid/SolidInternalEnergy.hpp"
#include "constitutive/thermalConductivity/MultiPhaseThermalConductivitySelector.hpp"
#include "fieldSpecification/AquiferBoundaryCondition.hpp"
#include "fieldSpecification/EquilibriumInitialCondition.hpp"
#include "fieldSpecification/SourceFluxBoundaryCondition.hpp"
#include "finiteVolume/FluxApproximationBase.hpp"
#include "mesh/DomainPartition.hpp"
#include "mesh/mpiCommunications/CommunicationTools.hpp"
#include "physicsSolvers/LogLevelsInfo.hpp"
#include "physicsSolvers/fluidFlow/CompositionalMultiphaseBaseFields.hpp"
#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp"
#include "physicsSolvers/fluidFlow/SourceFluxStatistics.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/GlobalComponentFractionKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/PhaseVolumeFractionKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/ThermalPhaseVolumeFractionKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/FluidUpdateKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/RelativePermeabilityUpdateKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureInversionKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/CapillaryPressureUpdateKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/SolidInternalEnergyUpdateKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/HydrostaticPressureKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/StatisticsKernel.hpp"
#include "physicsSolvers/fluidFlow/kernels/compositional/zFormulation/PhaseVolumeFractionZFormulationKernel.hpp"
#if defined( __INTEL_COMPILER )
#pragma GCC optimize "O0"
#endif
namespace geos
{
using namespace dataRepository;
using namespace constitutive;
using namespace fields;
CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name,
Group * const parent )
:
FlowSolverBase( name, parent ),
m_numPhases( 0 ),
m_numComponents( 0 ),
m_hasCapPressure( false ),
m_hasDiffusion( false ),
m_hasDispersion( false ),
m_minScalingFactor( 0.01 ),
m_allowCompDensChopping( 1 ),
m_useTotalMassEquation( 1 ),
m_useSimpleAccumulation( 1 ),
m_minCompDens( isothermalCompositionalMultiphaseBaseKernels::minDensForDivision ),
m_minCompFrac( isothermalCompositionalMultiphaseBaseKernels::minCompFracForDivision )
{
//START_SPHINX_INCLUDE_00
this->registerWrapper( viewKeyStruct::inputTemperatureString(), &m_inputTemperature ).
setInputFlag( InputFlags::REQUIRED ).
setDescription( "Temperature" );
//END_SPHINX_INCLUDE_00
// TODO: add more description on how useMass can alter the simulation (convergence issues?). How does it interact with wells useMass?
this->registerWrapper( viewKeyStruct::useMassFlagString(), &m_useMass ).
setApplyDefaultValue( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( GEOS_FMT( "Use mass formulation instead of molar. Warning : Affects {} rates units.",
SourceFluxBoundaryCondition::catalogName() ) );
this->registerWrapper( viewKeyStruct::formulationTypeString(), &m_formulationType ).
setApplyDefaultValue( CompositionalMultiphaseFormulationType::ComponentDensities ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Type of formulation used." );
this->registerWrapper( viewKeyStruct::solutionChangeScalingFactorString(), &m_solutionChangeScalingFactor ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.5 ).
setDescription( "Damping factor for solution change targets" );
this->registerWrapper( viewKeyStruct::targetRelativePresChangeString(), &m_targetRelativePresChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.2 ).
setDescription( "Target (relative) change in pressure in a time step (expected value between 0 and 1)" );
this->registerWrapper( viewKeyStruct::targetRelativeTempChangeString(), &m_targetRelativeTempChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.2 ).
setDescription( "Target (relative) change in temperature in a time step (expected value between 0 and 1)" );
this->registerWrapper( viewKeyStruct::targetPhaseVolFracChangeString(), &m_targetPhaseVolFracChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.2 ).
setDescription( "Target (absolute) change in the phase volume fraction within a single time step." );
this->registerWrapper( viewKeyStruct::targetRelativeCompDensChangeString(), &m_targetRelativeCompDensChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( LvArray::NumericLimits< real64 >::max ). // disabled by default
setDescription( "Target (relative) change in component density in a time step" );
this->registerWrapper( viewKeyStruct::targetCompFracChangeString(), &m_targetCompFracChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( LvArray::NumericLimits< real64 >::max ). // disabled by default
setDescription( "Target change in component fraction in a time step" );
this->registerWrapper( viewKeyStruct::maxCompFracChangeString(), &m_maxCompFracChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.5 ).
setDescription( "Maximum (absolute) allowed change in the composition fraction of any component within a single time step, in a Newton iteration" );
this->registerWrapper( viewKeyStruct::maxRelativePresChangeString(), &m_maxRelativePresChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.5 ).
setDescription( "Maximum (relative) change in pressure in a Newton iteration" );
this->registerWrapper( viewKeyStruct::maxRelativeTempChangeString(), &m_maxRelativeTempChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.5 ).
setDescription( "Maximum (relative) change in temperature in a Newton iteration" );
this->registerWrapper( viewKeyStruct::maxRelativeCompDensChangeString(), &m_maxRelativeCompDensChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( LvArray::NumericLimits< real64 >::max/1.0e100 ). // disabled by default
setDescription( "Maximum (relative) change in a component density in a Newton iteration" );
this->registerWrapper( viewKeyStruct::allowLocalCompDensChoppingString(), &m_allowCompDensChopping ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 1 ).
setDescription( "Flag indicating whether local (cell-wise) chopping of negative compositions is allowed" );
this->registerWrapper( viewKeyStruct::useTotalMassEquationString(), &m_useTotalMassEquation ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 1 ).
setDescription( "Flag indicating whether total mass equation is used" );
this->registerWrapper( viewKeyStruct::useSimpleAccumulationString(), &m_useSimpleAccumulation ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 1 ).
setDescription( "Flag indicating whether simple accumulation form is used" );
this->registerWrapper( viewKeyStruct::minCompDensString(), &m_minCompDens ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( isothermalCompositionalMultiphaseBaseKernels::minDensForDivision ).
setDescription( "Minimum allowed global component density" );
this->registerWrapper( viewKeyStruct::minCompFracString(), &m_minCompFrac ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( isothermalCompositionalMultiphaseBaseKernels::minCompFracForDivision ).
setDescription( "Minimum allowed global component fraction" );
this->registerWrapper( viewKeyStruct::maxSequentialCompDensChangeString(), &m_maxSequentialCompDensChange ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 1.0 ).
setDescription( "Maximum (absolute) component density change in a sequential iteration, used for outer loop convergence check" );
this->registerWrapper( viewKeyStruct::minScalingFactorString(), &m_minScalingFactor ).
setSizedFromParent( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setApplyDefaultValue( 0.01 ).
setDescription( "Minimum value for solution scaling factor" );
addLogLevel< logInfo::BoundaryConditions >();
}
void CompositionalMultiphaseBase::postInputInitialization()
{
FlowSolverBase::postInputInitialization();
GEOS_ERROR_IF_GT_MSG( m_maxCompFracChange, 1.0,
getWrapperDataContext( viewKeyStruct::maxCompFracChangeString() ) <<
": The maximum absolute change in component fraction in a Newton iteration must be smaller or equal to 1.0" );
GEOS_ERROR_IF_LE_MSG( m_maxCompFracChange, 0.0,
getWrapperDataContext( viewKeyStruct::maxCompFracChangeString() ) <<
": The maximum absolute change in component fraction in a Newton iteration must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_maxRelativePresChange, 0.0,
getWrapperDataContext( viewKeyStruct::maxRelativePresChangeString() ) <<
": The maximum relative change in pressure in a Newton iteration must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_maxRelativeTempChange, 0.0,
getWrapperDataContext( viewKeyStruct::maxRelativeTempChangeString() ) <<
": The maximum relative change in temperature in a Newton iteration must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_maxRelativeCompDensChange, 0.0,
getWrapperDataContext( viewKeyStruct::maxRelativeCompDensChangeString() ) <<
": The maximum relative change in component density in a Newton iteration must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_targetRelativePresChange, 0.0,
getWrapperDataContext( viewKeyStruct::targetRelativePresChangeString() ) <<
": The target relative change in pressure in a time step must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_targetRelativeTempChange, 0.0,
getWrapperDataContext( viewKeyStruct::targetRelativeTempChangeString() ) <<
": The target relative change in temperature in a time step must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_targetPhaseVolFracChange, 0.0,
getWrapperDataContext( viewKeyStruct::targetPhaseVolFracChangeString() ) <<
": The target change in phase volume fraction in a time step must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_targetRelativeCompDensChange, 0.0,
getWrapperDataContext( viewKeyStruct::targetRelativeCompDensChangeString() ) <<
": The target change in component density in a time step must be larger than 0.0" );
GEOS_ERROR_IF_LE_MSG( m_targetCompFracChange, 0.0,
getWrapperDataContext( viewKeyStruct::targetCompFracChangeString() ) <<
": The target change in component fraction in a time step must be larger than 0.0" );
GEOS_ERROR_IF_LT_MSG( m_solutionChangeScalingFactor, 0.0,
getWrapperDataContext( viewKeyStruct::solutionChangeScalingFactorString() ) <<
": The solution change scaling factor must be larger or equal to 0.0" );
GEOS_ERROR_IF_GT_MSG( m_solutionChangeScalingFactor, 1.0,
getWrapperDataContext( viewKeyStruct::solutionChangeScalingFactorString() ) <<
": The solution change scaling factor must be smaller or equal to 1.0" );
GEOS_ERROR_IF_LE_MSG( m_minScalingFactor, 0.0,
getWrapperDataContext( viewKeyStruct::minScalingFactorString() ) <<
": The minumum scaling factor must be larger than 0.0" );
GEOS_ERROR_IF_GT_MSG( m_minScalingFactor, 1.0,
getWrapperDataContext( viewKeyStruct::minScalingFactorString() ) <<
": The minumum scaling factor must be smaller or equal to 1.0" );
if( m_isThermal && m_useSimpleAccumulation ) // useSimpleAccumulation is not yet compatible with thermal
{
GEOS_LOG_RANK_0( GEOS_FMT( "{}: '{}' is not yet implemented for thermal simulation. Switched to phase sum accumulation.",
getDataContext(), viewKeyStruct::useSimpleAccumulationString() ) );
m_useSimpleAccumulation = 0;
}
if( m_formulationType == CompositionalMultiphaseFormulationType::OverallComposition )
{
string const formulationName = EnumStrings< CompositionalMultiphaseFormulationType >::toString( CompositionalMultiphaseFormulationType::OverallComposition );
if( m_isThermal ) // z_c formulation is not yet compatible with thermal
{
GEOS_ERROR( GEOS_FMT( "{}: '{}' is currently not available for thermal simulations",
getDataContext(), formulationName ) );
}
if( m_hasDiffusion || m_hasDispersion ) // z_c formulation is not yet compatible with diffusion or dispersion
{
GEOS_ERROR( GEOS_FMT( "{}: {} is currently not available for diffusion or dispersion",
getDataContext(), formulationName ) );
}
if( m_isJumpStabilized ) // z_c formulation is not yet compatible with pressure stabilization
{
GEOS_ERROR( GEOS_FMT( "{}: pressure stabilization is not yet supported by {}",
getDataContext(), formulationName ) );
}
}
}
void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies )
{
FlowSolverBase::registerDataOnMesh( meshBodies );
DomainPartition const & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" );
ConstitutiveManager const & cm = domain.getConstitutiveManager();
// 0. Find a "reference" fluid model name (at this point, models are already attached to subregions)
forDiscretizationOnMeshTargets( meshBodies, [&]( string const &,
MeshLevel & mesh,
string_array const & regionNames )
{
mesh.getElemManager().forElementSubRegions( regionNames,
[&]( localIndex const,
ElementSubRegionBase & subRegion )
{
if( m_referenceFluidModelName.empty() )
{
m_referenceFluidModelName = getConstitutiveName< MultiFluidBase >( subRegion );
}
// If at least one region has a capillary pressure model, consider it enabled for all
m_hasCapPressure |= !getConstitutiveName< CapillaryPressureBase >( subRegion ).empty();
// If at least one region has a diffusion model, consider it enabled for all
m_hasDiffusion |= !getConstitutiveName< DiffusionBase >( subRegion ).empty();
// If at least one region has a dispersion model, consider it enabled for all
m_hasDispersion |= !getConstitutiveName< DispersionBase >( subRegion ).empty();
GEOS_ERROR_IF( m_hasDispersion, "Dispersion is not supported yet, please remove it from this XML file" );
} );
} );
// check consistency between subregions
forDiscretizationOnMeshTargets( meshBodies, [&]( string const &,
MeshLevel & mesh,
string_array const & regionNames )
{
mesh.getElemManager().forElementSubRegions( regionNames,
[&]( localIndex const,
ElementSubRegionBase & subRegion )
{
if( m_hasCapPressure )
{
GEOS_THROW_IF( getConstitutiveName< CapillaryPressureBase >( subRegion ).empty(),
GEOS_FMT( "{}: Capillary pressure model not found on subregion {}",
getDataContext(), subRegion.getDataContext() ),
InputError );
}
if( m_hasDiffusion )
{
GEOS_THROW_IF( getConstitutiveName< DiffusionBase >( subRegion ).empty(),
GEOS_FMT( "{}: Diffusion model not found on subregion {}",
getDataContext(), subRegion.getDataContext() ),
InputError );
}
if( m_hasDispersion )
{
GEOS_THROW_IF( getConstitutiveName< DispersionBase >( subRegion ).empty(),
GEOS_FMT( "{}: Dispersion model not found on subregion {}",
getDataContext(), subRegion.getDataContext() ),
InputError );
}
} );
} );
// 1. Set key dimensions of the problem
// Check needed to avoid errors when running in schema generation mode.
if( !m_referenceFluidModelName.empty() )
{
MultiFluidBase const & referenceFluid = cm.getConstitutiveRelation< MultiFluidBase >( m_referenceFluidModelName );
m_numPhases = referenceFluid.numFluidPhases();
m_numComponents = referenceFluid.numFluidComponents();
m_isThermal = referenceFluid.isThermal();
}
if( m_formulationType == CompositionalMultiphaseFormulationType::ComponentDensities )
{
// default formulation - component densities and pressure are primary unknowns
// n_c components + one pressure ( + one temperature if needed )
m_numDofPerCell = m_isThermal ? m_numComponents + 2 : m_numComponents + 1;
}
else if( m_formulationType == CompositionalMultiphaseFormulationType::OverallComposition )
{
// z_c formulation - component densities and pressure are primary unknowns
// (n_c-1) overall compositions + one pressure
// Testing: let's have sum_c z_c = 1 as explicit equation for now
m_numDofPerCell = m_numComponents + 1;
}
else
{
GEOS_ERROR( GEOS_FMT( "{}: unknown formulation type", getDataContext() ) );
}
// 2. Register and resize all fields as necessary
forDiscretizationOnMeshTargets( meshBodies, [&]( string const &,
MeshLevel & mesh,
string_array const & regionNames )
{
mesh.getElemManager().forElementSubRegions( regionNames,
[&]( localIndex const,
ElementSubRegionBase & subRegion )
{
string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() );
MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName );
subRegion.registerField< flow::pressureScalingFactor >( getName() );
subRegion.registerField< flow::temperatureScalingFactor >( getName() );
// The resizing of the arrays needs to happen here, before the call to initializePreSubGroups,
// to make sure that the dimensions are properly set before the timeHistoryOutput starts its initialization.
subRegion.registerField< flow::globalCompFraction >( getName() ).
setDimLabels( 1, fluid.componentNames() ).
reference().resizeDimension< 1 >( m_numComponents );
if( m_formulationType == CompositionalMultiphaseFormulationType::OverallComposition )
{
subRegion.registerField< flow::globalCompFraction_n >( getName() ).
setDimLabels( 1, fluid.componentNames() ).
reference().resizeDimension< 1 >( m_numComponents );
// may be needed later for sequential poromechanics implementation
//if( m_isFixedStressPoromechanicsUpdate )
//{
// subRegion.registerField< flow::globalCompFraction_k >( getName() ).
// setDimLabels( 1, fluid.componentNames() ).
// reference().resizeDimension< 1 >( m_numComponents );
//}
subRegion.registerField< flow::globalCompFractionScalingFactor >( getName() );
}
else
{
subRegion.registerField< flow::globalCompDensity >( getName() ).
setDimLabels( 1, fluid.componentNames() ).
reference().resizeDimension< 1 >( m_numComponents );
subRegion.registerField< flow::globalCompDensity_n >( getName() ).
reference().resizeDimension< 1 >( m_numComponents );
if( m_isFixedStressPoromechanicsUpdate )
{
subRegion.registerField< flow::globalCompDensity_k >( getName() ).
setDimLabels( 1, fluid.componentNames() ).
reference().resizeDimension< 1 >( m_numComponents );
}
subRegion.registerField< flow::globalCompDensityScalingFactor >( getName() );
subRegion.registerField< flow::dGlobalCompFraction_dGlobalCompDensity >( getName() ).
reference().resizeDimension< 1, 2 >( m_numComponents, m_numComponents );
}
subRegion.registerField< flow::phaseVolumeFraction >( getName() ).
setDimLabels( 1, fluid.phaseNames() ).
reference().resizeDimension< 1 >( m_numPhases );
subRegion.registerField< flow::dPhaseVolumeFraction >( getName() ).
reference().resizeDimension< 1, 2 >( m_numPhases, m_numComponents + 2 ); // dP, dT, dC
subRegion.registerField< flow::phaseMobility >( getName() ).
setDimLabels( 1, fluid.phaseNames() ).
reference().resizeDimension< 1 >( m_numPhases );
subRegion.registerField< flow::dPhaseMobility >( getName() ).
reference().resizeDimension< 1, 2 >( m_numPhases, m_numComponents + 2 ); // dP, dT, dC
// needed for time step selector
subRegion.registerField< flow::phaseVolumeFraction_n >( getName() ).
reference().resizeDimension< 1 >( m_numPhases );
subRegion.registerField< flow::compAmount >( getName() ).
setDimLabels( 1, fluid.componentNames() ).
reference().resizeDimension< 1 >( m_numComponents );
subRegion.registerField< flow::compAmount_n >( getName() ).
setDimLabels( 1, fluid.componentNames() ).
reference().resizeDimension< 1 >( m_numComponents );
} );
FaceManager & faceManager = mesh.getFaceManager();
{
// We make the assumption that component names are uniform across the fluid models used in the simulation
MultiFluidBase const & fluid0 = cm.getConstitutiveRelation< MultiFluidBase >( m_referenceFluidModelName );
// TODO: add conditional registration later, this is only needed when there is a face-based Dirichlet BC
faceManager.registerField< flow::faceTemperature >( getName() );
faceManager.registerField< flow::faceGlobalCompFraction >( getName() ).
setDimLabels( 1, fluid0.componentNames() ).
reference().resizeDimension< 1 >( m_numComponents );
}
} );
}
void CompositionalMultiphaseBase::setConstitutiveNames( ElementSubRegionBase & subRegion ) const
{
setConstitutiveName< MultiFluidBase >( subRegion, viewKeyStruct::fluidNamesString(), "multiphase fluid" );
setConstitutiveName< RelativePermeabilityBase >( subRegion, viewKeyStruct::relPermNamesString(), "relative permeability" );
if( !getConstitutiveName< CapillaryPressureBase >( subRegion ).empty() )
{
setConstitutiveName< CapillaryPressureBase >( subRegion, viewKeyStruct::capPressureNamesString(), "capillary pressure" );
}
if( !getConstitutiveName< DiffusionBase >( subRegion ).empty() )
{
setConstitutiveName< DiffusionBase >( subRegion, viewKeyStruct::diffusionNamesString(), "diffusion" );
}
if( !getConstitutiveName< DispersionBase >( subRegion ).empty() )
{
setConstitutiveName< DispersionBase >( subRegion, viewKeyStruct::dispersionNamesString(), "dispersion" );
}
if( m_isThermal )
{
setConstitutiveName< MultiPhaseThermalConductivityBase >( subRegion, viewKeyStruct::thermalConductivityNamesString(), "multiphase thermal conductivity" );
}
}
namespace
{
template< typename MODEL1_TYPE, typename MODEL2_TYPE >
void compareMultiphaseModels( MODEL1_TYPE const & lhs, MODEL2_TYPE const & rhs )
{
GEOS_THROW_IF_NE_MSG( lhs.numFluidPhases(), rhs.numFluidPhases(),
GEOS_FMT( "Mismatch in number of phases between constitutive models {} and {}",
lhs.getDataContext(), rhs.getDataContext() ),
InputError );
for( integer ip = 0; ip < lhs.numFluidPhases(); ++ip )
{
GEOS_THROW_IF_NE_MSG( lhs.phaseNames()[ip], rhs.phaseNames()[ip],
GEOS_FMT( "Mismatch in phase names between constitutive models {} and {}",
lhs.getDataContext(), rhs.getDataContext() ),
InputError );
}
}
template< typename MODEL1_TYPE, typename MODEL2_TYPE >
void compareMulticomponentModels( MODEL1_TYPE const & lhs, MODEL2_TYPE const & rhs )
{
GEOS_THROW_IF_NE_MSG( lhs.numFluidComponents(), rhs.numFluidComponents(),
GEOS_FMT( "Mismatch in number of components between constitutive models {} and {}",
lhs.getDataContext(), rhs.getDataContext() ),
InputError );
for( integer ic = 0; ic < lhs.numFluidComponents(); ++ic )
{
GEOS_THROW_IF_NE_MSG( lhs.componentNames()[ic], rhs.componentNames()[ic],
GEOS_FMT( "Mismatch in component names between constitutive models {} and {}",
lhs.getDataContext(), rhs.getDataContext() ),
InputError );
}
}
}
void CompositionalMultiphaseBase::initializeAquiferBC( ConstitutiveManager const & cm ) const
{
FieldSpecificationManager & fsManager = FieldSpecificationManager::getInstance();
fsManager.forSubGroups< AquiferBoundaryCondition >( [&] ( AquiferBoundaryCondition & bc )
{
MultiFluidBase const & fluid0 = cm.getConstitutiveRelation< MultiFluidBase >( m_referenceFluidModelName );
// set the gravity vector (needed later for the potential diff calculations)
bc.setGravityVector( gravityVector() );
// set the water phase index in the Aquifer boundary condition
// note: if the water phase is not found, the fluid model is going to throw an error
integer const waterPhaseIndex = fluid0.getWaterPhaseIndex();
bc.setWaterPhaseIndex( waterPhaseIndex );
arrayView1d< real64 const > const & aquiferWaterPhaseCompFrac = bc.getWaterPhaseComponentFraction();
string_array const & aquiferWaterPhaseCompNames = bc.getWaterPhaseComponentNames();
GEOS_ERROR_IF_NE_MSG( fluid0.numFluidComponents(), aquiferWaterPhaseCompFrac.size(),
getDataContext() << ": Mismatch in number of components between constitutive model "
<< fluid0.getName() << " and the water phase composition in aquifer " << bc.getName() );
for( integer ic = 0; ic < fluid0.numFluidComponents(); ++ic )
{
GEOS_ERROR_IF_NE_MSG( fluid0.componentNames()[ic], aquiferWaterPhaseCompNames[ic],
getDataContext() << ": Mismatch in component names between constitutive model "
<< fluid0.getName() << " and the water phase components in aquifer " << bc.getName() );
}
} );
}
void CompositionalMultiphaseBase::initializePreSubGroups()
{
FlowSolverBase::initializePreSubGroups();
DomainPartition & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" );
ConstitutiveManager const & cm = domain.getConstitutiveManager();
// 1. Validate various models against each other (must have same phases and components)
validateConstitutiveModels( domain );
// 2. Set the value of temperature
forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &,
MeshLevel & mesh,
string_array const & regionNames )
{
mesh.getElemManager().forElementSubRegions( regionNames,
[&]( localIndex const,
ElementSubRegionBase & subRegion )
{
arrayView1d< real64 > const temp = subRegion.getField< flow::temperature >();
temp.setValues< parallelHostPolicy >( m_inputTemperature );
} );
} );
// 3. Initialize and validate the aquifer boundary condition
initializeAquiferBC( cm );
}
void CompositionalMultiphaseBase::validateConstitutiveModels( DomainPartition const & domain ) const
{
GEOS_MARK_FUNCTION;
ConstitutiveManager const & cm = domain.getConstitutiveManager();
MultiFluidBase const & referenceFluid = cm.getConstitutiveRelation< MultiFluidBase >( m_referenceFluidModelName );
forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &,
MeshLevel const & mesh,
string_array const & regionNames )
{
mesh.getElemManager().forElementSubRegions( regionNames,
[&]( localIndex const,
ElementSubRegionBase const & subRegion )
{
string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() );
MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName );
compareMultiphaseModels( fluid, referenceFluid );
compareMulticomponentModels( fluid, referenceFluid );
bool const isFluidModelThermal = fluid.isThermal();
GEOS_THROW_IF( m_isThermal && !isFluidModelThermal,
GEOS_FMT( "CompositionalMultiphaseBase {}: the thermal option is enabled in the solver, but the fluid model {} is incompatible with the thermal option",
getDataContext(), fluid.getDataContext() ),
InputError, getDataContext(), fluid.getDataContext() );
GEOS_THROW_IF( !m_isThermal && isFluidModelThermal,
GEOS_FMT( "CompositionalMultiphaseBase {}: the thermal option is enabled in fluid model {}, but the solver options are incompatible with the thermal option",
getDataContext(), fluid.getDataContext() ),
InputError, getDataContext(), fluid.getDataContext() );
string const & relpermName = subRegion.getReference< string >( viewKeyStruct::relPermNamesString() );
RelativePermeabilityBase const & relPerm = getConstitutiveModel< RelativePermeabilityBase >( subRegion, relpermName );
compareMultiphaseModels( relPerm, referenceFluid );
if( m_hasCapPressure )
{
string const & capPressureName = subRegion.getReference< string >( viewKeyStruct::capPressureNamesString() );
CapillaryPressureBase const & capPressure = getConstitutiveModel< CapillaryPressureBase >( subRegion, capPressureName );
compareMultiphaseModels( capPressure, referenceFluid );
}
if( m_hasDiffusion )
{
string const & diffusionName = subRegion.getReference< string >( viewKeyStruct::diffusionNamesString() );
DiffusionBase const & diffusion = getConstitutiveModel< DiffusionBase >( subRegion, diffusionName );
compareMultiphaseModels( diffusion, referenceFluid );
}
if( m_isThermal )
{
string const & thermalConductivityName = subRegion.getReference< string >( viewKeyStruct::thermalConductivityNamesString() );
MultiPhaseThermalConductivityBase const & conductivity = getConstitutiveModel< MultiPhaseThermalConductivityBase >( subRegion, thermalConductivityName );
compareMultiphaseModels( conductivity, referenceFluid );
}
} );
} );
}
void CompositionalMultiphaseBase::updateGlobalComponentFraction( ObjectManagerBase & dataGroup ) const
{
GEOS_MARK_FUNCTION;
isothermalCompositionalMultiphaseBaseKernels::
GlobalComponentFractionKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
dataGroup );
}
real64 CompositionalMultiphaseBase::updatePhaseVolumeFraction( ObjectManagerBase & dataGroup ) const
{
GEOS_MARK_FUNCTION;
string const & fluidName = dataGroup.getReference< string >( viewKeyStruct::fluidNamesString() );
MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( dataGroup, fluidName );
if( m_formulationType == CompositionalMultiphaseFormulationType::OverallComposition )
{
// isothermal for now
return isothermalCompositionalMultiphaseBaseKernels::
PhaseVolumeFractionZFormulationKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dataGroup,
fluid );
}
else
{
if( m_isThermal )
{
return thermalCompositionalMultiphaseBaseKernels::
PhaseVolumeFractionKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dataGroup,
fluid );
}
else
{
return isothermalCompositionalMultiphaseBaseKernels::
PhaseVolumeFractionKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dataGroup,
fluid );
}
}
}
void CompositionalMultiphaseBase::updateFluidModel( ObjectManagerBase & dataGroup ) const
{
GEOS_MARK_FUNCTION;
arrayView1d< real64 const > const pres = dataGroup.getField< flow::pressure >();
arrayView1d< real64 const > const temp = dataGroup.getField< flow::temperature >();
arrayView2d< real64 const, compflow::USD_COMP > const compFrac =
dataGroup.getField< flow::globalCompFraction >();
string const & fluidName = dataGroup.getReference< string >( viewKeyStruct::fluidNamesString() );
MultiFluidBase & fluid = getConstitutiveModel< MultiFluidBase >( dataGroup, fluidName );
constitutiveUpdatePassThru( fluid, [&] ( auto & castedFluid )
{
using FluidType = TYPEOFREF( castedFluid );
using ExecPolicy = typename FluidType::exec_policy;
typename FluidType::KernelWrapper fluidWrapper = castedFluid.createKernelWrapper();
thermalCompositionalMultiphaseBaseKernels::
FluidUpdateKernel::
launch< ExecPolicy >( dataGroup.size(),
fluidWrapper,
pres,
temp,
compFrac );
} );
}
void CompositionalMultiphaseBase::updateRelPermModel( ObjectManagerBase & dataGroup ) const
{
GEOS_MARK_FUNCTION;
arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac =
dataGroup.getField< flow::phaseVolumeFraction >();
string const & relPermName = dataGroup.getReference< string >( viewKeyStruct::relPermNamesString() );
RelativePermeabilityBase & relPerm = getConstitutiveModel< RelativePermeabilityBase >( dataGroup, relPermName );
constitutive::constitutiveUpdatePassThru( relPerm, [&] ( auto & castedRelPerm )
{
typename TYPEOFREF( castedRelPerm ) ::KernelWrapper relPermWrapper = castedRelPerm.createKernelWrapper();
isothermalCompositionalMultiphaseBaseKernels::
RelativePermeabilityUpdateKernel::
launch< parallelDevicePolicy<> >( dataGroup.size(),
relPermWrapper,
phaseVolFrac );
} );
}
void CompositionalMultiphaseBase::updateCapPressureModel( ObjectManagerBase & dataGroup ) const
{
GEOS_MARK_FUNCTION;
if( m_hasCapPressure )
{
arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac =
dataGroup.getField< flow::phaseVolumeFraction >();
string const & cappresName = dataGroup.getReference< string >( viewKeyStruct::capPressureNamesString() );
CapillaryPressureBase & capPressure = getConstitutiveModel< CapillaryPressureBase >( dataGroup, cappresName );
constitutive::constitutiveUpdatePassThru( capPressure, [&] ( auto & castedCapPres )
{
typename TYPEOFREF( castedCapPres ) ::KernelWrapper capPresWrapper = castedCapPres.createKernelWrapper();
isothermalCompositionalMultiphaseBaseKernels::
CapillaryPressureUpdateKernel::
launch< parallelDevicePolicy<> >( dataGroup.size(),
capPresWrapper,
phaseVolFrac );
} );
}
}
void CompositionalMultiphaseBase::updateCompAmount( ElementSubRegionBase & subRegion ) const
{
GEOS_MARK_FUNCTION;
arrayView2d< real64, compflow::USD_COMP > const compAmount = subRegion.getField< flow::compAmount >();
arrayView1d< real64 const > const volume = subRegion.getElementVolume();
arrayView1d< real64 const > const deltaVolume = subRegion.getField< fields::flow::deltaVolume >();
string const & solidName = subRegion.template getReference< string >( viewKeyStruct::solidNamesString() );
CoupledSolidBase const & porousMaterial = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName );
arrayView2d< real64 const > const porosity = porousMaterial.getPorosity();
integer const numComp = m_numComponents;
if( m_formulationType == CompositionalMultiphaseFormulationType::OverallComposition )
{
arrayView2d< real64 const, compflow::USD_COMP > const compFrac = subRegion.getField< flow::globalCompFraction >();
// access total density stored in the fluid
string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() );
MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName );
arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const totalDens = fluid.totalDensity();
forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei )
{
for( integer ic = 0; ic < numComp; ++ic )
{
// m = phi*V*z_c*rho_T
compAmount[ei][ic] = porosity[ei][0] * (volume[ei]+deltaVolume[ei]) * compFrac[ei][ic] * totalDens[ei][0];
}
} );
}
else
{
arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.getField< flow::globalCompDensity >();
forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei )
{
for( integer ic = 0; ic < numComp; ++ic )
{
compAmount[ei][ic] = porosity[ei][0] * (volume[ei]+deltaVolume[ei]) * compDens[ei][ic];
GEOS_LOG_RANK(GEOS_FMT("Attempted Correction @{}/{} : {} -> {} ", ei, ic,
porosity[ei][0]*volume[ei]* compDens[ei][ic],
porosity[ei][0]*deltaVolume[ei]* compDens[ei][ic]
));
}
} );
}
}
void CompositionalMultiphaseBase::updateEnergy( ElementSubRegionBase & subRegion ) const
{
GEOS_MARK_FUNCTION;
string const & solidName = subRegion.template getReference< string >( viewKeyStruct::solidNamesString() );
CoupledSolidBase const & porousMaterial = getConstitutiveModel< CoupledSolidBase >( subRegion, solidName );
arrayView2d< real64 const > const porosity = porousMaterial.getPorosity();
arrayView2d< real64 const > rockInternalEnergy = porousMaterial.getInternalEnergy();
arrayView1d< real64 const > const volume = subRegion.getElementVolume();
arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = subRegion.getField< flow::phaseVolumeFraction >();
string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() );
MultiFluidBase & fluid = subRegion.getConstitutiveModel< MultiFluidBase >( fluidName );
arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const phaseDens = fluid.phaseDensity();
arrayView3d< real64 const, constitutive::multifluid::USD_PHASE > const phaseInternalEnergy = fluid.phaseInternalEnergy();
arrayView1d< real64 > const energy = subRegion.getField< flow::energy >();
integer const numPhases = m_numPhases;
forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei )
{
energy[ei] = volume[ei] * (1.0 - porosity[ei][0]) * rockInternalEnergy[ei][0];
for( integer ip = 0; ip < numPhases; ++ip )
{
energy[ei] += volume[ei] * porosity[ei][0] * phaseVolFrac[ei][ip] * phaseDens[ei][0][ip] * phaseInternalEnergy[ei][0][ip];
}
} );
}
void CompositionalMultiphaseBase::updateSolidInternalEnergyModel( ObjectManagerBase & dataGroup ) const
{
arrayView1d< real64 const > const temp = dataGroup.getField< flow::temperature >();
string const & solidInternalEnergyName = dataGroup.getReference< string >( viewKeyStruct::solidInternalEnergyNamesString() );
SolidInternalEnergy & solidInternalEnergy = getConstitutiveModel< SolidInternalEnergy >( dataGroup, solidInternalEnergyName );
SolidInternalEnergy::KernelWrapper solidInternalEnergyWrapper = solidInternalEnergy.createKernelUpdates();
// TODO: this should go somewhere, handle the case of flow in fracture, etc
thermalCompositionalMultiphaseBaseKernels::
SolidInternalEnergyUpdateKernel::
launch< parallelDevicePolicy<> >( dataGroup.size(),
solidInternalEnergyWrapper,
temp );
}
real64 CompositionalMultiphaseBase::updateFluidState( ElementSubRegionBase & subRegion ) const
{
GEOS_MARK_FUNCTION;
if( m_formulationType == CompositionalMultiphaseFormulationType::ComponentDensities )
{
// For p, rho_c as the primary unknowns
updateGlobalComponentFraction( subRegion );
}
updateFluidModel( subRegion );
updateCompAmount( subRegion );
real64 const maxDeltaPhaseVolFrac = updatePhaseVolumeFraction( subRegion );
updateRelPermModel( subRegion );
updatePhaseMobility( subRegion );
updateCapPressureModel( subRegion );
// note1: for now, thermal conductivity is treated explicitly, so no update here
// note2: for now, diffusion and dispersion are also treated explicitly
return maxDeltaPhaseVolFrac;
}
void CompositionalMultiphaseBase::initializeFluidState( MeshLevel & mesh,
string_array const & regionNames )
{
GEOS_MARK_FUNCTION;
integer const numComp = m_numComponents;
mesh.getElemManager().forElementSubRegions( regionNames,
[&]( localIndex const,
ElementSubRegionBase & subRegion )
{
// check the global component fractions values
arrayView2d< real64 const, compflow::USD_COMP > const compFrac =
subRegion.getField< flow::globalCompFraction >();
{
RAJA::ReduceSum< parallelDeviceReduce, localIndex > localNegativeValues( 0 );
RAJA::ReduceSum< parallelDeviceReduce, localIndex > localTooHighFracCount( 0 );
RAJA::ReduceSum< parallelDeviceReduce, localIndex > localTooLowFracCount( 0 );
RAJA::ReduceMin< parallelDeviceReduce, localIndex > localMinFrac( LvArray::NumericLimits< localIndex >::max );
RAJA::ReduceMax< parallelDeviceReduce, localIndex > localMaxFrac( LvArray::NumericLimits< localIndex >::min );
forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei )
{
real64 sumCompFrac = 0.0;
for( integer ic = 0; ic < numComp; ++ic )
{
sumCompFrac += compFrac[ei][ic];
if( compFrac[ei][ic] < 0.0 )
localNegativeValues += 1;
}
localMinFrac.min( sumCompFrac );
localMaxFrac.max( sumCompFrac );
if( sumCompFrac > 1 + 1e-6 )
localTooHighFracCount += 1;
if( sumCompFrac < 1 - 1e-6 )
localTooLowFracCount += 1;
} );
localIndex const negativeValues = MpiWrapper::sum( localNegativeValues.get() );
GEOS_ERROR_IF( negativeValues > 0,
GEOS_FMT( "{}: negative global component fraction values found in subregion '{}' for {} elements",
getName(), subRegion.getName(), negativeValues ) );
localIndex const totalSupFrac = MpiWrapper::sum( localTooHighFracCount.get() );
localIndex const totalInfFrac = MpiWrapper::sum( localTooLowFracCount.get() );
localIndex const totalWrongCompFrac = totalSupFrac + totalInfFrac;
localIndex const minFrac = MpiWrapper::min( localMinFrac.get() );
localIndex const maxFrac = MpiWrapper::sum( localMaxFrac.get() );
GEOS_ERROR_IF( totalWrongCompFrac > 0,
GEOS_FMT( "{} component fractions do not sum to 1.0 in subregion '{}'!\n"
"{} are too low ; {} are too high ; component fractions sum range is from {} to {}.\n"
"Consider adding field specification to initialize the '{}' field.",
totalWrongCompFrac, subRegion.getName(),
localTooLowFracCount.get(), localTooHighFracCount.get(), minFrac, maxFrac,
fields::flow::globalCompFraction::key() ),
getDataContext());
}
// Assume global component fractions have been prescribed.
// Initialize constitutive state to get fluid density.
updateFluidModel( subRegion );
// Back-calculate global component densities from fractions and total fluid density
// in order to initialize the primary solution variables
string const & fluidName = subRegion.template getReference< string >( viewKeyStruct::fluidNamesString() );
MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName );
arrayView2d< real64 const, constitutive::multifluid::USD_FLUID > const totalDens = fluid.totalDensity();
if( m_formulationType == CompositionalMultiphaseFormulationType::ComponentDensities )
{
arrayView2d< real64, compflow::USD_COMP > const compDens =
subRegion.getField< flow::globalCompDensity >();
forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei )
{
for( integer ic = 0; ic < numComp; ++ic )
{
compDens[ei][ic] = totalDens[ei][0] * compFrac[ei][ic];
}
} );
// with initial component densities defined - check if they need to be corrected to avoid zero diags etc
if( m_allowCompDensChopping )
{
chopNegativeDensities( subRegion );
}
}
} );
// check if comp fractions need to be corrected to avoid zero diags etc
if( m_formulationType == CompositionalMultiphaseFormulationType::OverallComposition && m_allowCompDensChopping )
{
DomainPartition & domain = this->getGroupByPath< DomainPartition >( "/Problem/domain" );
chopNegativeCompFractions( domain );
}
// for some reason CUDA does not want the host_device lambda to be defined inside the generic lambda
// I need the exact type of the subRegion for updateSolidflowProperties to work well.
mesh.getElemManager().forElementSubRegions< CellElementSubRegion,
SurfaceElementSubRegion >( regionNames, [&]( localIndex const,
auto & subRegion )
{
// Initialize/update dependent state quantities
updateCompAmount( subRegion );
updatePhaseVolumeFraction( subRegion );
// Update the constitutive models that only depend on