-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathSolidFSISPHEvaluateDerivatives.cc
More file actions
957 lines (829 loc) · 43.5 KB
/
SolidFSISPHEvaluateDerivatives.cc
File metadata and controls
957 lines (829 loc) · 43.5 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
#include <variant>
namespace Spheral {
//------------------------------------------------------------------------------
// Dispatch evaluateDerivatives based on type of Q
//------------------------------------------------------------------------------
template<typename Dimension>
void
SolidFSISPH<Dimension>::
evaluateDerivatives(const typename Dimension::Scalar time,
const typename Dimension::Scalar dt,
const DataBase<Dimension>& dataBase,
const State<Dimension>& state,
StateDerivatives<Dimension>& derivatives) const {
this->firstDerivativesLoop(time,dt,dataBase,state,derivatives);
// Depending on the type of the ArtificialViscosity, dispatch the call to
// the secondDerivativesLoop
auto& Qhandle = this->artificialViscosity();
if (Qhandle.QPiTypeIndex() == std::type_index(typeid(Scalar))) {
const auto& Q = dynamic_cast<const ArtificialViscosity<Dimension, Scalar>&>(Qhandle);
this->secondDerivativesLoop(time,dt,dataBase,state,derivatives,Q);
} else {
CHECK(Qhandle.QPiTypeIndex() == std::type_index(typeid(Tensor)));
const auto& Q = dynamic_cast<const ArtificialViscosity<Dimension, Tensor>&>(Qhandle);
this->secondDerivativesLoop(time,dt,dataBase,state,derivatives,Q);
}
//this->setH(time,dt,dataBase,state,derivatves)
}
//------------------------------------------------------------------------------
// Determine the principle derivatives.
//------------------------------------------------------------------------------
template<typename Dimension>
template<typename QType>
void
SolidFSISPH<Dimension>::
secondDerivativesLoop(const typename Dimension::Scalar time,
const typename Dimension::Scalar dt,
const DataBase<Dimension>& dataBase,
const State<Dimension>& state,
StateDerivatives<Dimension>& derivs,
const QType& Q) const {
using QPiType = typename QType::ReturnType;
// Get the SlideSurfaces.
auto& slides = this->slideSurface();
// The kernels and such.
const auto& W = this->kernel();
// huge amount of tinies
const auto tiny = std::numeric_limits<double>::epsilon();
const auto tinyScalarDamage = 1.0e-2;
const auto tinyNonDimensional = 1.0e-9;
// map to get the new interface flag from the neighbor details
std::vector<std::vector<int>> interfaceFlagMap(2, vector<int>(6,0));
interfaceFlagMap[0][2] = 1;
interfaceFlagMap[0][4] = 1;
interfaceFlagMap[1][0] = 3;
interfaceFlagMap[1][1] = 3;
interfaceFlagMap[1][2] = 3;
interfaceFlagMap[1][3] = 3;
interfaceFlagMap[1][4] = 3;
// constants
const auto W0 = W(0.0, 1.0);
const auto interfaceNeighborAngleThreshold = this->interfaceNeighborAngleThreshold();
const auto interfacePmin = this->interfacePmin();
const auto decoupleDamagedMaterial = this->decoupleDamagedMaterial();
const auto epsTensile = this->epsilonTensile();
const auto compatibleEnergy = this->compatibleEnergyEvolution();
const auto totalEnergy = this->evolveTotalEnergy();
const auto epsDiffusionCoeff = this->specificThermalEnergyDiffusionCoefficient();
const auto rhoStabilizeCoeff = this->densityStabilizationCoefficient();
const auto surfaceForceCoeff = this->surfaceForceCoefficient();
const auto xsphCoeff = this->xsphCoefficient();
const auto XSPH = xsphCoeff > tiny;
const auto diffuseEnergy = epsDiffusionCoeff>tiny and compatibleEnergy;
const auto stabilizeDensity = rhoStabilizeCoeff>tiny;
const auto alwaysAverageKernels = (mKernelAveragingMethod==KernelAveragingMethod::AlwaysAverageKernels);
const auto averageInterfaceKernels = (mKernelAveragingMethod==KernelAveragingMethod::AverageInterfaceKernels);
const auto constructHLLC = (mInterfaceMethod == InterfaceMethod::HLLCInterface);
const auto activateConstruction = !(mInterfaceMethod == InterfaceMethod::NoInterface);
// The connectivity.
const auto& connectivityMap = dataBase.connectivityMap();
const auto& pairs = connectivityMap.nodePairList();
const auto& nodeLists = connectivityMap.nodeLists();
const auto numNodeLists = nodeLists.size();
const auto numPairs = pairs.size();
const auto nPerh = nodeLists[0]->nodesPerSmoothingScale();
const auto WnPerh = W(1.0/nPerh, 1.0);
// Get the state and derivative FieldLists.
const auto interfaceNormals = state.fields(FSIFieldNames::interfaceNormals, Vector::zero);
const auto interfaceFlags = state.fields(FSIFieldNames::interfaceFlags, int(0));
const auto interfaceAreaVectors = state.fields(FSIFieldNames::interfaceAreaVectors, Vector::zero);
const auto interfaceSmoothness = state.fields(FSIFieldNames::interfaceSmoothness, 0.0);
const auto mass = state.fields(HydroFieldNames::mass, 0.0);
const auto position = state.fields(HydroFieldNames::position, Vector::zero);
const auto velocity = state.fields(HydroFieldNames::velocity, Vector::zero);
const auto massDensity = state.fields(HydroFieldNames::massDensity, 0.0);
const auto specificThermalEnergy = state.fields(HydroFieldNames::specificThermalEnergy, 0.0);
const auto H = state.fields(HydroFieldNames::H, SymTensor::zero);
const auto damagedPressure = state.fields(SolidFieldNames::damagedPressure, 0.0);
const auto pressure = state.fields(HydroFieldNames::pressure, 0.0);
const auto soundSpeed = state.fields(HydroFieldNames::soundSpeed, 0.0);
const auto S = state.fields(SolidFieldNames::deviatoricStress, SymTensor::zero);
const auto K = state.fields(SolidFieldNames::bulkModulus, 0.0);
const auto mu = state.fields(SolidFieldNames::shearModulus, 0.0);
const auto damage = state.fields(SolidFieldNames::tensorDamage, SymTensor::zero);
const auto fragIDs = state.fields(SolidFieldNames::fragmentIDs, int(1));
const auto pTypes = state.fields(SolidFieldNames::particleTypes, int(0));
const auto fClQ = state.fields(HydroFieldNames::ArtificialViscousClMultiplier, 0.0);
const auto fCqQ = state.fields(HydroFieldNames::ArtificialViscousCqMultiplier, 0.0);
const auto DvDxQ = state.fields(HydroFieldNames::ArtificialViscosityVelocityGradient, Tensor::zero);
//const auto yield = state.fields(SolidFieldNames::yieldStrength, 0.0);
//const auto invJ2 = state.fields(FSIFieldNames::inverseEquivalentDeviatoricStress, 0.0);
CHECK(interfaceFlags.size() == numNodeLists);
CHECK(interfaceAreaVectors.size() == numNodeLists);
CHECK(interfaceNormals.size() == numNodeLists);
CHECK(interfaceSmoothness.size() == numNodeLists);
CHECK(mass.size() == numNodeLists);
CHECK(position.size() == numNodeLists);
CHECK(velocity.size() == numNodeLists);
CHECK(massDensity.size() == numNodeLists);
CHECK(specificThermalEnergy.size() == numNodeLists);
CHECK(H.size() == numNodeLists);
CHECK(pressure.size() == numNodeLists);
CHECK(damagedPressure.size() == numNodeLists);
CHECK(soundSpeed.size() == numNodeLists);
CHECK(S.size() == numNodeLists);
CHECK(K.size() == numNodeLists);
CHECK(mu.size() == numNodeLists);
CHECK(damage.size() == numNodeLists);
CHECK(fragIDs.size() == numNodeLists);
CHECK(pTypes.size() == numNodeLists);
CHECK(fClQ.size() == 0 or fClQ.size() == numNodeLists);
CHECK(fCqQ.size() == 0 or fCqQ.size() == numNodeLists);
CHECK(DvDxQ.size() == 0 or DvDxQ.size() == numNodeLists);
//CHECK(yield.size() == numNodeLists);
//CHECK(invJ2.size() == numNodeLists);
// Derivative FieldLists.
const auto M = derivs.fields(HydroFieldNames::M_SPHCorrection, Tensor::zero);
const auto localM = derivs.fields("local " + HydroFieldNames::M_SPHCorrection, Tensor::zero);
const auto DepsDx = derivs.fields(FSIFieldNames::specificThermalEnergyGradient, Vector::zero);
const auto DPDx = derivs.fields(FSIFieldNames::pressureGradient, Vector::zero);
auto newInterfaceNormals = derivs.fields(PureReplaceState<Dimension, Vector>::prefix() + FSIFieldNames::interfaceNormals, Vector::zero);
auto newInterfaceFlags = derivs.fields(PureReplaceState<Dimension, int>::prefix() + FSIFieldNames::interfaceFlags, int(0));
auto newInterfaceAreaVectors = derivs.fields(PureReplaceState<Dimension, Vector>::prefix() + FSIFieldNames::interfaceAreaVectors, Vector::zero);
auto interfaceSmoothnessNormalization = derivs.fields(FSIFieldNames::interfaceSmoothnessNormalization, 0.0);
auto interfaceFraction = derivs.fields(FSIFieldNames::interfaceFraction, 0.0);
auto newInterfaceSmoothness = derivs.fields(PureReplaceState<Dimension, Scalar>::prefix() + FSIFieldNames::interfaceSmoothness, 0.0);
auto interfaceAngles = derivs.fields(FSIFieldNames::interfaceAngles, 0.0);
auto normalization = derivs.fields(HydroFieldNames::normalization, 0.0);
auto DxDt = derivs.fields(IncrementState<Dimension, Vector>::prefix() + HydroFieldNames::position, Vector::zero);
auto DrhoDt = derivs.fields(IncrementState<Dimension, Scalar>::prefix() + HydroFieldNames::massDensity, 0.0);
auto DvDt = derivs.fields(HydroFieldNames::hydroAcceleration, Vector::zero);
auto DepsDt = derivs.fields(IncrementState<Dimension, Scalar>::prefix() + HydroFieldNames::specificThermalEnergy, 0.0);
auto DvDx = derivs.fields(HydroFieldNames::velocityGradient, Tensor::zero);
auto localDvDx = derivs.fields(HydroFieldNames::internalVelocityGradient, Tensor::zero);
auto maxViscousPressure = derivs.fields(HydroFieldNames::maxViscousPressure, 0.0);
auto effViscousPressure = derivs.fields(HydroFieldNames::effectiveViscousPressure, 0.0);
auto XSPHWeightSum = derivs.fields(HydroFieldNames::XSPHWeightSum, 0.0);
auto XSPHDeltaV = derivs.fields(HydroFieldNames::XSPHDeltaV, Vector::zero);
auto DSDt = derivs.fields(IncrementState<Dimension, SymTensor>::prefix() + SolidFieldNames::deviatoricStress, SymTensor::zero);
auto* pairAccelerationsPtr = (compatibleEnergy ?
&derivs.template get<PairAccelerationsType>(HydroFieldNames::pairAccelerations) :
nullptr);
auto* pairDepsDtPtr = (compatibleEnergy ?
&derivs.template get<PairWorkType>(HydroFieldNames::pairWork) :
nullptr);
CHECK(M.size() == numNodeLists);
CHECK(localM.size() == numNodeLists);
CHECK(DepsDx.size() == numNodeLists);
CHECK(DPDx.size() == numNodeLists);
CHECK(newInterfaceFlags.size() == numNodeLists);
CHECK(newInterfaceAreaVectors.size() == numNodeLists);
CHECK(newInterfaceNormals.size() == numNodeLists);
CHECK(interfaceSmoothnessNormalization.size() == numNodeLists);
CHECK(interfaceFraction.size() == numNodeLists);
CHECK(newInterfaceSmoothness.size() == numNodeLists);
CHECK(interfaceAngles.size() == numNodeLists);
CHECK(normalization.size() == numNodeLists);
CHECK(DxDt.size() == numNodeLists);
CHECK(DrhoDt.size() == numNodeLists);
CHECK(DvDt.size() == numNodeLists);
CHECK(DepsDt.size() == numNodeLists);
CHECK(DvDx.size() == numNodeLists);
CHECK(localDvDx.size() == numNodeLists);
CHECK(M.size() == numNodeLists);
CHECK(localM.size() == numNodeLists);
CHECK(maxViscousPressure.size() == numNodeLists);
CHECK(effViscousPressure.size() == numNodeLists);
CHECK(XSPHWeightSum.size() == numNodeLists);
CHECK(XSPHDeltaV.size() == numNodeLists);
CHECK(DSDt.size() == numNodeLists);
CHECK(not compatibleEnergy or pairAccelerationsPtr->size() == numPairs);
CHECK(not compatibleEnergy or pairDepsDtPtr->size() == numPairs);
//this->computeMCorrection(time,dt,dataBase,state,derivs);
// Now we calculate the hydro deriviatives
// Walk all the interacting pairs.
#pragma omp parallel
{
// Thread private scratch variables.
unsigned i, j, nodeListi, nodeListj;
Scalar Wi, gWi, Wj, gWj, PLineari, PLinearj, epsLineari, epsLinearj, Qi, Qj;
QPiType QPiij, QPiji;
SymTensor sigmai, sigmaj;
Vector sigmarhoi, sigmarhoj;
typename SpheralThreads<Dimension>::FieldListStack threadStack;
auto newInterfaceFlags_thread = newInterfaceFlags.threadCopy(threadStack, ThreadReduction::MAX);
auto newInterfaceAreaVectors_thread = newInterfaceAreaVectors.threadCopy(threadStack);
auto newInterfaceNormals_thread = newInterfaceNormals.threadCopy(threadStack);
auto newInterfaceSmoothness_thread = newInterfaceSmoothness.threadCopy(threadStack);
auto interfaceSmoothnessNormalization_thread = interfaceSmoothnessNormalization.threadCopy(threadStack);
auto interfaceFraction_thread = interfaceFraction.threadCopy(threadStack);
auto interfaceAngles_thread = interfaceAngles.threadCopy(threadStack, ThreadReduction::MAX);
auto normalization_thread = normalization.threadCopy(threadStack);
auto DvDt_thread = DvDt.threadCopy(threadStack);
auto DepsDt_thread = DepsDt.threadCopy(threadStack);
auto DrhoDt_thread = DrhoDt.threadCopy(threadStack);
auto DSDt_thread = DSDt.threadCopy(threadStack);
auto DvDx_thread = DvDx.threadCopy(threadStack);
auto localDvDx_thread = localDvDx.threadCopy(threadStack);
auto XSPHWeightSum_thread = XSPHWeightSum.threadCopy(threadStack);
auto XSPHDeltaV_thread = XSPHDeltaV.threadCopy(threadStack);
auto maxViscousPressure_thread = maxViscousPressure.threadCopy(threadStack, ThreadReduction::MAX);
auto effViscousPressure_thread = effViscousPressure.threadCopy(threadStack);
#pragma omp for
for (auto kk = 0u; kk < numPairs; ++kk) {
i = pairs[kk].i_node;
j = pairs[kk].j_node;
nodeListi = pairs[kk].i_list;
nodeListj = pairs[kk].j_list;
// Get the state for node i.
const auto& interfaceFlagsi = interfaceFlags(nodeListi,i);
const auto& interfaceAreaVectorsi = interfaceAreaVectors(nodeListi,i);
const auto& interfaceNormalsi = interfaceNormals(nodeListi,i);
const auto& interfaceSmoothnessi = interfaceSmoothness(nodeListi,i);
const auto& ri = position(nodeListi, i);
const auto& vi = velocity(nodeListi, i);
const auto& mi = mass(nodeListi, i);
const auto& Hi = H(nodeListi, i);
const auto& rhoi = massDensity(nodeListi, i);
const auto& epsi = specificThermalEnergy(nodeListi,i);
const auto& Pi = pressure(nodeListi, i);
const auto& Pdi = damagedPressure(nodeListi, i);
const auto& ci = soundSpeed(nodeListi, i);
const auto& Si = S(nodeListi, i);
const auto& pTypei = pTypes(nodeListi, i);
const auto fragIDi = fragIDs(nodeListi, i);
//const auto Yi = yield(nodeListi, i);
//const auto invJ2i = invJ2(nodeListi, i);
const auto voli = mi/rhoi;
const auto mui = max(mu(nodeListi,i),tiny);
const auto Ki = max(tiny,K(nodeListi,i))+4.0/3.0*mui;
const auto Hdeti = Hi.Determinant();
epsLineari = epsi;
PLineari = Pdi;
CHECK(mi > 0.0);
CHECK(rhoi > 0.0);
CHECK(Hdeti > 0.0);
const auto& DepsDxi = DepsDx(nodeListi, i);
const auto& DPDxi = DPDx(nodeListi, i);
const auto& Mi = M(nodeListi, i);
auto& normi = normalization_thread(nodeListi,i);
auto& DvDti = DvDt_thread(nodeListi, i);
auto& DepsDti = DepsDt_thread(nodeListi, i);
auto& DvDxi = DvDx_thread(nodeListi, i);
auto& localDvDxi = localDvDx_thread(nodeListi, i);
auto& XSPHWeightSumi = XSPHWeightSum_thread(nodeListi, i);
auto& XSPHDeltaVi = XSPHDeltaV_thread(nodeListi, i);
auto& maxViscousPressurei = maxViscousPressure_thread(nodeListi, i);
auto& effViscousPressurei = effViscousPressure_thread(nodeListi, i);
auto& newInterfaceFlagsi = newInterfaceFlags_thread(nodeListi,i);
auto& newInterfaceAreaVectorsi = newInterfaceAreaVectors_thread(nodeListi,i);
auto& newInterfaceNormalsi = newInterfaceNormals_thread(nodeListi,i);
auto& newInterfaceSmoothnessi = newInterfaceSmoothness_thread(nodeListi,i);
auto& interfaceFractioni = interfaceFraction_thread(nodeListi,i);
auto& interfaceSmoothnessNormalizationi = interfaceSmoothnessNormalization_thread(nodeListi,i);
auto& minNeighborAnglei = interfaceAngles_thread(nodeListi,i);
// Get the state for node j
const auto& interfaceFlagsj = interfaceFlags(nodeListj,j);
const auto& interfaceAreaVectorsj = interfaceAreaVectors(nodeListj,j);
const auto& interfaceNormalsj = interfaceNormals(nodeListj,j);
const auto& interfaceSmoothnessj = interfaceSmoothness(nodeListj,j);
const auto& rj = position(nodeListj, j);
const auto& vj = velocity(nodeListj, j);
const auto& mj = mass(nodeListj, j);
const auto& Hj = H(nodeListj, j);
const auto& rhoj = massDensity(nodeListj, j);
const auto& epsj = specificThermalEnergy(nodeListj,j);
const auto& Pj = pressure(nodeListj, j);
const auto& Pdj = damagedPressure(nodeListj, j);
const auto& cj = soundSpeed(nodeListj, j);
const auto& Sj = S(nodeListj, j);
const auto& pTypej = pTypes(nodeListj, j);
const auto fragIDj = fragIDs(nodeListj, j);
//const auto Yj = yield(nodeListj, j);
//const auto invJ2j = invJ2(nodeListj, j);
const auto volj = mj/rhoj;
const auto muj = max(mu(nodeListj,j),tiny);
const auto Kj = max(tiny,K(nodeListj,j))+4.0/3.0*muj;
const auto Hdetj = Hj.Determinant();
epsLinearj = epsj;
PLinearj = Pdj;
CHECK(mj > 0.0);
CHECK(rhoj > 0.0);
CHECK(Hdetj > 0.0);
const auto& DepsDxj = DepsDx(nodeListj, j);
const auto& DPDxj = DPDx(nodeListj, j);
const auto& Mj = M(nodeListj,j);
auto& normj = normalization_thread(nodeListj,j);
auto& DvDtj = DvDt_thread(nodeListj, j);
auto& DepsDtj = DepsDt_thread(nodeListj, j);
auto& DvDxj = DvDx_thread(nodeListj, j);
auto& localDvDxj = localDvDx_thread(nodeListj, j);
auto& XSPHWeightSumj = XSPHWeightSum_thread(nodeListj, j);
auto& XSPHDeltaVj = XSPHDeltaV_thread(nodeListj, j);
auto& maxViscousPressurej = maxViscousPressure_thread(nodeListj, j);
auto& effViscousPressurej = effViscousPressure_thread(nodeListj, j);
auto& newInterfaceFlagsj = newInterfaceFlags_thread(nodeListj,j);
auto& newInterfaceAreaVectorsj = newInterfaceAreaVectors_thread(nodeListj,j);
auto& newInterfaceNormalsj = newInterfaceNormals_thread(nodeListj,j);
auto& newInterfaceSmoothnessj = newInterfaceSmoothness_thread(nodeListj,j);
auto& interfaceFractionj = interfaceFraction_thread(nodeListj,j);
auto& interfaceSmoothnessNormalizationj = interfaceSmoothnessNormalization_thread(nodeListj,j);
auto& minNeighborAnglej = interfaceAngles_thread(nodeListj,j);
// line of action
const auto rij = ri - rj;
const auto rhatij = rij.unitVector();
// decoupling and boolean switches
//-------------------------------------------------------
// Flag if this is a contiguous material pair or not.
const auto sameMatij = (nodeListi == nodeListj and fragIDi==fragIDj);
const auto differentMatij = !sameMatij;
const auto averageKernelij = ( (differentMatij and averageInterfaceKernels) or alwaysAverageKernels);
// Flag if at least one particle is free (0).
const auto freeParticle = (pTypei == 0 or pTypej == 0);
// pairwise damage and nodal damage
const auto Di = max(0.0, min(1.0, damage(nodeListi, i).dot(rhatij).magnitude()));
const auto Dj = max(0.0, min(1.0, damage(nodeListj, j).dot(rhatij).magnitude()));
const auto fDi = (sameMatij ? (1.0-Di)*(1.0-Di) : 0.0 );
const auto fDj = (sameMatij ? (1.0-Dj)*(1.0-Dj) : 0.0 );
const auto fDij = (sameMatij ? pow(1.0-std::abs(Di-Dj),2.0) : 0.0 );
// is Pmin being activated? (Pmin -> interface Pmin)
const auto pLimiti = (sameMatij ? (Pdi-rhoi*ci*ci*tinyNonDimensional) : interfacePmin);
const auto pLimitj = (sameMatij ? (Pdj-rhoj*cj*cj*tinyNonDimensional) : interfacePmin);
const auto pminActivei = (Pi < pLimiti);
const auto pminActivej = (Pj < pLimitj);
// decoupling criteria, we want material interface to be able to separate and if
// decoupleDamagedMaterial is active we want damaged material to behave like gravel
const auto isExpanding = (ri-rj).dot(vi-vj) > 0.0;
const auto isFullyDamaged = (fDi<tinyScalarDamage) or (fDj<tinyScalarDamage);
const auto isPastAdhesionThreshold = pminActivei or pminActivej;
const auto canDecouple = (isFullyDamaged and decoupleDamagedMaterial) or differentMatij;
const auto decouple = isExpanding and isPastAdhesionThreshold and canDecouple;
// do we need to construct our interface velocity?
const auto constructInterface = (fDij < 1.0-tinyScalarDamage) and activateConstruction;
const auto negligableShearWave = max(mui,muj) < tinyNonDimensional*min(Ki,Kj);
// do we reduce our deviatoric stress
const auto isTensile = (((Si+Sj)-(Pdi+Pdj)*SymTensor::one).dot(rhatij)).dot(rhatij) > 0;
const auto damageReduceStress = isTensile or differentMatij;
// Kernels
//--------------------------------------
const auto Hij = 0.5*(Hi+Hj);
const auto etaij = Hij*rij;
const auto etai = Hi*rij;
const auto etaj = Hj*rij;
const auto etaMagij = etaij.magnitude();
const auto etaMagi = etai.magnitude();
const auto etaMagj = etaj.magnitude();
CHECK(etaMagij >= 0.0);
CHECK(etaMagi >= 0.0);
CHECK(etaMagj >= 0.0);
// Symmetrized kernel weight and gradient.
W.kernelAndGradValue(etaMagi, Hdeti, Wi, gWi);
W.kernelAndGradValue(etaMagj, Hdetj, Wj, gWj);
const auto Hetai = Hi*etai.unitVector();
const auto Hetaj = Hj*etaj.unitVector();
auto gradWi = gWi*Hetai;
auto gradWj = gWj*Hetaj;
auto gradWiMi = gradWi;
auto gradWjMj = gradWj;
// average our kernels
const auto gradWij = 0.5*(gradWi+gradWj);
const auto Wij = 0.5*(Wi+Wj);
if(averageKernelij){
const auto gWij = 0.5*(gWi+gWj);
Wi = Wij;
Wj = Wij;
gWi = gWij;
gWj = gWij;
gradWi = gradWij;
gradWj = gradWij;
}
gradWiMi = Mi.Transpose()*gradWi;
gradWjMj = Mj.Transpose()*gradWj;
// interface fields
//----------------------------------------------------------------------------------
const auto fSij = ( sameMatij ? 1.0 : -1.0);
const auto interfaceSwitch = std::min(std::min(interfaceFlagsj,interfaceFlagsi),1);
const int sameMatMask = (sameMatij ? 1 : 0);
const int diffMatMask = 1-sameMatMask;
const int controlNodeMaski = interfaceFlagMap[0][interfaceFlagsi];
const int controlNodeMaskj = interfaceFlagMap[0][interfaceFlagsj];
const auto AijMij = fSij*(voli*volj)*(gradWjMj+gradWiMi); // surface area vector
const auto alignment = (interfaceFlagsi == 5 or interfaceFlagsj == 5 ?
0.0:
std::max(fSij*interfaceNormalsi.dot(interfaceNormalsj),0.0));
newInterfaceAreaVectorsi -= AijMij;
newInterfaceAreaVectorsj += AijMij;
interfaceFractioni += sameMatMask * volj * Wi;
interfaceFractionj += sameMatMask * voli * Wj;
// we use the angle between normal and neighbors to check for interface control particles (type 2 or 4)
const auto minNeighborMaski = (interfaceFlagsj != 5 and sameMatij ? 1.0 : -1.0); // turns following into no-op
const auto minNeighborMaskj = (interfaceFlagsi != 5 and sameMatij ? 1.0 : -1.0);
minNeighborAnglei = std::max(std::min(minNeighborMaski,-interfaceAreaVectorsi.unitVector().dot(rhatij)),minNeighborAnglei);
minNeighborAnglej = std::max(std::min(minNeighborMaskj, interfaceAreaVectorsj.unitVector().dot(rhatij)),minNeighborAnglej);
// if the node neighbors a control node, set its value to 1 if initially 0
newInterfaceFlagsi = std::max(newInterfaceFlagsi, interfaceFlagMap[diffMatMask][interfaceFlagsj]);
newInterfaceFlagsj = std::max(newInterfaceFlagsj, interfaceFlagMap[diffMatMask][interfaceFlagsi]);
// only flagged nodes get normals and they're based on their control node neighbors
newInterfaceNormalsi += interfaceSwitch*controlNodeMaskj*fSij*volj*interfaceAreaVectorsj*Wij;
newInterfaceNormalsj += interfaceSwitch*controlNodeMaski*fSij*voli*interfaceAreaVectorsi*Wij;
// smoothness is calculated for all flagged interface/surface nodes
interfaceSmoothnessNormalizationi += interfaceSwitch*volj*Wij;
interfaceSmoothnessNormalizationj += interfaceSwitch*voli*Wij;
newInterfaceSmoothnessi += interfaceSwitch*alignment*volj*Wij;
newInterfaceSmoothnessj += interfaceSwitch*alignment*voli*Wij;
if (!decouple){
// Stress state
//---------------------------------------------------------------
const auto rhoij = 0.5*(rhoi+rhoj);
const auto cij = 0.5*(ci+cj);
const auto vij = vi - vj;
// raw AV
Q.QPiij(QPiij, QPiji, Qi, Qj,
nodeListi, i, nodeListj, j,
ri, Hij, etaij, vi, rhoij, cij,
rj, Hij, etaij, vj, rhoij, cij,
fClQ, fCqQ, DvDxQ);
// slide correction
if (slides.isSlideSurface(nodeListi,nodeListj)){
const auto slideCorr = slides.slideCorrection(interfaceSmoothnessi,
interfaceSmoothnessj,
interfaceNormalsi,
interfaceNormalsj,
vi,
vj);
QPiij *= slideCorr;
QPiji *= slideCorr;
}
// save our max pressure from the AV for each node
const auto conversionFactorQ = rhoi*rhoj/(max(rhoij,tiny)*max(rhoij,tiny));
Qi *= conversionFactorQ;
Qj *= conversionFactorQ;
maxViscousPressurei = max(maxViscousPressurei, Qi);
maxViscousPressurej = max(maxViscousPressurej, Qj);
effViscousPressurei += volj * Qi * Wi;
effViscousPressurej += voli * Qj * Wj;
// stress tensor
//{
// apply yield pairwise
//const auto Yij = std::max(0.0,std::min(Yi,Yj));
//const auto fYieldi = std::min(Yij*invJ2i,1.0);
//const auto fYieldj = std::min(Yij*invJ2j,1.0);
//const auto Seffi = (sameMatij ? 1.0 : 0.0 ) * Si;
//const auto Seffj = (sameMatij ? 1.0 : 0.0 ) * Sj;
//const auto Seffi = (min(Pi,Pj) < 0.0 or differentMatij ? maxfDij : 1.0) * Si;
//const auto Seffj = (min(Pi,Pj) < 0.0 or differentMatij ? maxfDij : 1.0) * Sj;
//const auto Peffi = maxfDij*min(Pi,0.0) + max(Pi,0.0);
//const auto Peffj = maxfDij*min(Pj,0.0) + max(Pj,0.0);
//const auto Seffi = maxfDij * Si; //(damageReduceStress ? fDij : 1.0) * Si;
//const auto Seffj = maxfDij * Sj; //(damageReduceStress ? fDij : 1.0) * Sj;
const auto Peffi = (differentMatij ? max(Pdi,interfacePmin) : Pdi);
const auto Peffj = (differentMatij ? max(Pdj,interfacePmin) : Pdj);
const auto Seffi = (damageReduceStress ? fDij : 1.0) * Si;
const auto Seffj = (damageReduceStress ? fDij : 1.0) * Sj;
sigmai = Seffi - Peffi * SymTensor::one;
sigmaj = Seffj - Peffj * SymTensor::one;
//}
// Compute the tensile correction to add to the stress as described in
// Gray, Monaghan, & Swift (Comput. Methods Appl. Mech. Eng., 190, 2001)
{
const auto fi = epsTensile*FastMath::pow4(Wi/(Hdeti*WnPerh));
const auto fj = epsTensile*FastMath::pow4(Wj/(Hdetj*WnPerh));
const auto Ri = fi*tensileStressCorrection(sigmai);
const auto Rj = fj*tensileStressCorrection(sigmaj);
sigmai += Ri;
sigmaj += Rj;
}
// accelerations
//---------------------------------------------------------------
const auto rhoirhoj = 1.0/(rhoi*rhoj);
const auto sf = (sameMatij ? 1.0 : 1.0 + surfaceForceCoeff*abs((rhoi-rhoj)/(rhoi+rhoj+tiny)));
sigmarhoi = sf*(rhoirhoj*sigmai*gradWiMi - 0.5*QPiij*gradWiMi);
sigmarhoj = sf*(rhoirhoj*sigmaj*gradWjMj - 0.5*QPiji*gradWjMj);
if (averageKernelij){
const auto sigmarhoij = 0.5*(sigmarhoi+sigmarhoj);
sigmarhoi = sigmarhoij;
sigmarhoj = sigmarhoij;
}
const auto deltaDvDt = sigmarhoi + sigmarhoj;
if (freeParticle) {
DvDti += mj*deltaDvDt;
DvDtj -= mi*deltaDvDt;
}
// Velocity Gradient
//-----------------------------------------------------------
// construct our interface velocity
auto vstar = 0.5*(vi+vj);
linearReconstruction(ri,rj,Pdi,Pdj,DPDxi,DPDxj,PLineari,PLinearj);
if (constructInterface){
// components
const auto ui = vi.dot(rhatij);
const auto uj = vj.dot(rhatij);
const auto wi = vi - ui*rhatij;
const auto wj = vj - uj*rhatij;
// weights weights
const auto Ci = (constructHLLC ? std::sqrt(rhoi*Ki) : Ki ) + tiny;
const auto Cj = (constructHLLC ? std::sqrt(rhoj*Kj) : Kj ) + tiny;
const auto Csi = (constructHLLC ? std::sqrt(rhoi*mui) : mui ) + tiny;
const auto Csj = (constructHLLC ? std::sqrt(rhoj*muj) : muj ) + tiny;
const auto CiCjInv = safeInv(Ci+Cj,tiny);
const auto CsiCsjInv = safeInv(Csi+Csj,tiny);
// weights
const auto weightUi = max(0.0, min(1.0, Ci*CiCjInv));
const auto weightUj = 1.0 - weightUi;
const auto weightWi = (negligableShearWave ? weightUi : max(0.0, min(1.0, Csi*CsiCsjInv )) );
const auto weightWj = 1.0 - weightWi;
// interface velocity
const auto ustar = weightUi*ui + weightUj*uj + (constructHLLC ? (PLinearj - PLineari)*CiCjInv : 0.0);
const auto wstar = weightWi*wi + weightWj*wj;// - (constructHLLC ? (Seffj - Seffi).dot(rhatij)*CsiCsjInv : Vector::zero);
vstar = fDij * vstar + (1.0-fDij)*(ustar*rhatij + wstar);
}
// TODO:
//------------------------------------------------------------
// fix pressure/rawPressure convert to damagePressure/pressure
// get wave speeds in there in a good manner
//------------------------------------------------------------
// local velocity gradient for DSDt
if (sameMatij) {
localDvDxi -= 2.0*volj*((vi-vstar).dyad(gradWi));
localDvDxj -= 2.0*voli*((vstar-vj).dyad(gradWj));
}
// diffuse to stabilize things
if (stabilizeDensity and (ci>tiny and cj>tiny)){
const auto cFactor = 1.0 + max(min( (vi-vj).dot(rhatij)/max(cij,tiny), 0.0), -1.0);
const auto effCoeff = (differentMatij ? 1.0 : rhoStabilizeCoeff*cFactor);
vstar += (constructHLLC ? fDij : 1.0) * effCoeff * rhatij * cij * min(max((PLinearj-PLineari)/(Ki + Kj),-0.25),0.25);
}
// global velocity gradient
DvDxi -= 2.0*volj*(vi-vstar).dyad(gradWiMi);
DvDxj -= 2.0*voli*(vstar-vj).dyad(gradWjMj);
// energy conservation
// ----------------------------------------------------------
const auto deltaDepsDti = 2.0*sigmarhoi.dot(vi-vstar);
const auto deltaDepsDtj = 2.0*sigmarhoj.dot(vstar-vj);
DepsDti -= mj*deltaDepsDti;
DepsDtj -= mi*deltaDepsDtj;
if(compatibleEnergy){
(*pairAccelerationsPtr)[kk] = - deltaDvDt;
(*pairDepsDtPtr)[kk][0] = - deltaDepsDti;
(*pairDepsDtPtr)[kk][1] = - deltaDepsDtj;
}
// thermal diffusion
//-----------------------------------------------------------
if (sameMatij and diffuseEnergy){
linearReconstruction(ri,rj,epsi,epsj,DepsDxi,DepsDxj,epsLineari,epsLinearj);
const auto cijEff = max(min(cij + (vi-vj).dot(rhatij), cij),0.0);
const auto diffusion = epsDiffusionCoeff*cijEff*(epsLineari-epsLinearj)*etaij.dot(gradWij)/(rhoij*etaMagij*etaMagij+tiny);
if (compatibleEnergy) {
(*pairDepsDtPtr)[kk][0] += diffusion;
(*pairDepsDtPtr)[kk][1] -= diffusion;
}
}
// normalization
//-----------------------------------------------------------
normi += volj*Wi;
normj += voli*Wj;
// XSPH -- we use this to handle tensile instability here
//-----------------------------------------------------------
if (sameMatij and XSPH) {
const auto fxsph = (std::min(Pdi,Pdj) < 0 ? 1 : 0);
XSPHWeightSumi += fxsph * volj*Wi;
XSPHWeightSumj += fxsph * voli*Wj;
XSPHDeltaVi -= fDij*volj*Wi*(vi-vj);
XSPHDeltaVj -= fDij*voli*Wj*(vj-vi);
}
} // if damageDecouple
} // loop over pairs
threadReduceFieldLists<Dimension>(threadStack);
} // OpenMP parallel region
// Finish up the derivatives for each point.
for (auto nodeListi = 0u; nodeListi < numNodeLists; ++nodeListi) {
const auto& nodeList = mass[nodeListi]->nodeList();
const auto ni = nodeList.numInternalNodes();
#pragma omp parallel for
for (auto i = 0u; i < ni; ++i) {
// Get the state for node i.
const auto& mi = mass(nodeListi, i);
const auto& vi = velocity(nodeListi, i);
const auto& rhoi = massDensity(nodeListi, i);
const auto& Hi = H(nodeListi, i);
const auto& Si = S(nodeListi, i);
const auto& mui = mu(nodeListi, i);
const auto& interfaceFlagsi = interfaceFlags(nodeListi,i);
const auto& interfaceAreaVectorsi = interfaceAreaVectors(nodeListi,i);
const auto Hdeti = Hi.Determinant();
const auto psi = Hdeti*mi/rhoi*W0;
CHECK(mi > 0.0);
CHECK(rhoi > 0.0);
CHECK(Hdeti > 0.0);
const auto& DvDti = DvDt(nodeListi,i);
const auto& localMi = localM(nodeListi, i);
auto& normi = normalization(nodeListi,i);
auto& DepsDti = DepsDt(nodeListi,i);
auto& DxDti = DxDt(nodeListi, i);
auto& DrhoDti = DrhoDt(nodeListi, i);
auto& DvDxi = DvDx(nodeListi, i);
auto& localDvDxi = localDvDx(nodeListi, i);
auto& XSPHWeightSumi = XSPHWeightSum(nodeListi, i);
auto& XSPHDeltaVi = XSPHDeltaV(nodeListi, i);
auto& DSDti = DSDt(nodeListi, i);
auto& newInterfaceNormalsi = newInterfaceNormals(nodeListi,i);
auto& newInterfaceSmoothnessi = newInterfaceSmoothness(nodeListi,i);
auto& interfaceSmoothnessNormalizationi = interfaceSmoothnessNormalization(nodeListi,i);
auto& interfaceFractioni = interfaceFraction(nodeListi,i);
auto& newInterfaceFlagsi = newInterfaceFlags(nodeListi,i);
auto& minNeighborAnglei = interfaceAngles(nodeListi,i);
// finish our normalization
normi += psi;
// finish our interface fields.
if(minNeighborAnglei < interfaceNeighborAngleThreshold) newInterfaceFlagsi = std::max(2,newInterfaceFlagsi+1);
if(interfaceFractioni/(1.0-psi)<0.1) newInterfaceFlagsi = 5.0;
interfaceFractioni += psi;
if ( interfaceFlagsi > 0 ){
const double proxWeighti = 100*(1.0 - interfaceFlagsi % 2);
newInterfaceNormalsi = (newInterfaceNormalsi + proxWeighti * psi * interfaceAreaVectorsi).unitVector();
newInterfaceSmoothnessi = newInterfaceSmoothnessi/max(interfaceSmoothnessNormalizationi,tiny);
} else {
newInterfaceNormalsi = Vector::zero;
}
DrhoDti -= rhoi*DvDxi.Trace();
if (totalEnergy) DepsDti = mi*(vi.dot(DvDti) + DepsDti);
DxDti = vi;
if (XSPH) {
CHECK(normi >= 0.0);
const auto invNormi = 1.0/max(normi,tiny);
XSPHWeightSumi = (interfaceFlagsi == 0 ? XSPHWeightSumi*invNormi : 0);
DxDti += xsphCoeff*XSPHWeightSumi*XSPHDeltaVi*invNormi;
}
localDvDxi = localDvDxi*localMi;
// Determine the deviatoric stress evolution.
const auto deformation = localDvDxi.Symmetric();
const auto spin = localDvDxi.SkewSymmetric();
const auto deviatoricDeformation = deformation - deformation.Trace()/3.0*SymTensor::one;
const auto spinCorrection = (spin*Si + Si*spin).Symmetric();
DSDti += spinCorrection + 2.0*mui*deviatoricDeformation;
} //loop-nodes
} //loop-nodeLists
} // evaluateDerivatives method
//------------------------------------------------------------------------------
// EvalDerivs subroutine for spatial derivs
//------------------------------------------------------------------------------
template<typename Dimension>
void
SolidFSISPH<Dimension>::
firstDerivativesLoop(const typename Dimension::Scalar /*time*/,
const typename Dimension::Scalar /*dt*/,
const DataBase<Dimension>& dataBase,
const State<Dimension>& state,
StateDerivatives<Dimension>& derivs) const {
// The kernels and such.
const auto& W = this->kernel();
// A few useful constants we'll use in the following loop.
const auto alwaysAverageKernels = (mKernelAveragingMethod==KernelAveragingMethod::AlwaysAverageKernels);
const auto averageInterfaceKernels = (mKernelAveragingMethod==KernelAveragingMethod::AverageInterfaceKernels);
// The connectivity.
const auto& connectivityMap = dataBase.connectivityMap();
const auto& pairs = connectivityMap.nodePairList();
const auto& nodeLists = connectivityMap.nodeLists();
const auto numNodeLists = nodeLists.size();
const auto numPairs = pairs.size();
// Get the state and derivative FieldLists.
const auto mass = state.fields(HydroFieldNames::mass, 0.0);
const auto position = state.fields(HydroFieldNames::position, Vector::zero);
const auto massDensity = state.fields(HydroFieldNames::massDensity, 0.0);
const auto specificThermalEnergy = state.fields(HydroFieldNames::specificThermalEnergy, 0.0);
const auto H = state.fields(HydroFieldNames::H, SymTensor::zero);
const auto damagedPressure = state.fields(SolidFieldNames::damagedPressure, 0.0);
const auto fragIDs = state.fields(SolidFieldNames::fragmentIDs, int(1));
CHECK(mass.size() == numNodeLists);
CHECK(position.size() == numNodeLists);
CHECK(massDensity.size() == numNodeLists);
CHECK(specificThermalEnergy.size() == numNodeLists);
CHECK(H.size() == numNodeLists);
CHECK(damagedPressure.size() == numNodeLists);
// Derivative FieldLists.
auto DepsDx = derivs.fields(FSIFieldNames::specificThermalEnergyGradient, Vector::zero);
auto DPDx = derivs.fields(FSIFieldNames::pressureGradient, Vector::zero);
auto M = derivs.fields(HydroFieldNames::M_SPHCorrection, Tensor::zero);
auto localM = derivs.fields("local " + HydroFieldNames::M_SPHCorrection, Tensor::zero);
CHECK(DepsDx.size() == numNodeLists);
CHECK(DPDx.size() == numNodeLists);
CHECK(M.size() == numNodeLists);
CHECK(localM.size() == numNodeLists);
#pragma omp parallel
{
// Thread private scratch variables.
int i, j, nodeListi, nodeListj;
typename SpheralThreads<Dimension>::FieldListStack threadStack;
auto M_thread = M.threadCopy(threadStack);
auto localM_thread = localM.threadCopy(threadStack);
auto DPDx_thread = DPDx.threadCopy(threadStack);
auto DepsDx_thread = DepsDx.threadCopy(threadStack);
#pragma omp for
for (auto kk = 0u; kk < numPairs; ++kk) {
i = pairs[kk].i_node;
j = pairs[kk].j_node;
nodeListi = pairs[kk].i_list;
nodeListj = pairs[kk].j_list;
// Get the state for node i.
const auto& fragIDi = fragIDs(nodeListi,i);
const auto& ri = position(nodeListi, i);
const auto& mi = mass(nodeListi, i);
const auto& epsi = specificThermalEnergy(nodeListi, i);
const auto& Pi = damagedPressure(nodeListi, i);
const auto& rhoi = massDensity(nodeListi, i);
const auto& Hi = H(nodeListi, i);
const auto Hdeti = Hi.Determinant();
CHECK(mi > 0.0);
CHECK(rhoi > 0.0);
CHECK(Hdeti > 0.0);
// Get the state for node j
const auto& fragIDj = fragIDs(nodeListj,j);
const auto& rj = position(nodeListj, j);
const auto& mj = mass(nodeListj, j);
const auto& epsj = specificThermalEnergy(nodeListj, j);
const auto& Pj = damagedPressure(nodeListj, j);
const auto& rhoj = massDensity(nodeListj, j);
const auto& Hj = H(nodeListj, j);
const auto Hdetj = Hj.Determinant();
CHECK(mj > 0.0);
CHECK(rhoj > 0.0);
CHECK(Hdetj > 0.0);
auto& DPDxi = DPDx_thread(nodeListi, i);
auto& DPDxj = DPDx_thread(nodeListj, j);
auto& DepsDxi = DepsDx_thread(nodeListi, i);
auto& DepsDxj = DepsDx_thread(nodeListj, j);
auto& localMi = localM_thread(nodeListi,i);
auto& localMj = localM_thread(nodeListj,j);
auto& Mi = M_thread(nodeListi,i);
auto& Mj = M_thread(nodeListj,j);
const auto rij = ri - rj;
const auto Pij = Pi - Pj;
const auto epsij = epsi - epsj;
// logic
//---------------------------------------
const auto sameMatij = (nodeListi == nodeListj and fragIDi == fragIDj);
const auto differentMatij = (nodeListi!=nodeListj);
const auto averageKernelij = ( (differentMatij and averageInterfaceKernels) or alwaysAverageKernels);
// Kernels
//--------------------------------------
const auto etai = Hi*rij;
const auto etaj = Hj*rij;
const auto etaMagi = etai.magnitude();
const auto etaMagj = etaj.magnitude();
CHECK(etaMagi >= 0.0);
CHECK(etaMagj >= 0.0);
// Symmetrized kernel weight and gradient.
const auto gWi = W.gradValue(etaMagi, Hdeti);
const auto gWj = W.gradValue(etaMagj, Hdetj);
const auto Hetai = Hi*etai.unitVector();
const auto Hetaj = Hj*etaj.unitVector();
auto gradWi = gWi*Hetai;
auto gradWj = gWj*Hetaj;
//Wi & Wj --> Wij for interface better agreement DrhoDt and DepsDt
if(averageKernelij){
const auto gradWij = 0.5*(gradWi+gradWj);
gradWi = gradWij;
gradWj = gradWij;
}
gradWi *= mj/rhoj;
gradWj *= mi/rhoi;
// spatial gradients and correction
//---------------------------------------------------------------
const auto deltaRi = rij.dyad(gradWi);
const auto deltaRj = rij.dyad(gradWj);
Mi -= deltaRi;
Mj -= deltaRj;
DPDxi -= Pij*gradWi;
DPDxj -= Pij*gradWj;
if(sameMatij){
localMi -= deltaRi;
localMj -= deltaRj;
DepsDxi -= epsij*gradWi;
DepsDxj -= epsij*gradWj;
}
} // loop over pairs
// Reduce the thread values to the master.
threadReduceFieldLists<Dimension>(threadStack);
} // OpenMP parallel region
for (auto nodeListi = 0u; nodeListi < numNodeLists; ++nodeListi) {
const auto& nodeList = mass[nodeListi]->nodeList();
const auto ni = nodeList.numInternalNodes();
#pragma omp parallel for
for (auto i = 0u; i < ni; ++i) {
const auto numNeighborsi = connectivityMap.numNeighborsForNode(nodeListi, i);
auto& Mi = M(nodeListi, i);
auto& localMi = localM(nodeListi, i);
auto& DepsDxi = DepsDx(nodeListi, i);
auto& DPDxi = DPDx(nodeListi, i);
const auto Mdeti = Mi.Determinant();
const auto goodM = ( Mdeti > 1.0e-2 and numNeighborsi > Dimension::pownu(2));
Mi = (goodM and this->linearCorrectGradients() ? Mi.Inverse() : Tensor::one);
const auto localMdeti = localMi.Determinant();
const auto goodLocalM = ( localMdeti > 1.0e-2 and numNeighborsi > Dimension::pownu(2));
localMi = (goodLocalM and this->linearCorrectGradients() ? localMi.Inverse() : Tensor::one);
DPDxi = Mi.Transpose()*DPDxi;
DepsDxi = localMi.Transpose()*DepsDxi;
} // for each node
} // for each nodelist
for (ConstBoundaryIterator boundaryItr = this->boundaryBegin();
boundaryItr != this->boundaryEnd();
++boundaryItr) {
(*boundaryItr)->applyFieldListGhostBoundary(M);
(*boundaryItr)->applyFieldListGhostBoundary(DPDx);
(*boundaryItr)->applyFieldListGhostBoundary(DepsDx);
}
for (ConstBoundaryIterator boundaryItr = this->boundaryBegin();
boundaryItr != this->boundaryEnd();
++boundaryItr) (*boundaryItr)->finalizeGhostBoundary();
} // method
} // spheral namespace