-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathdpg_vms.h
More file actions
1590 lines (1472 loc) · 66.9 KB
/
dpg_vms.h
File metadata and controls
1590 lines (1472 loc) · 66.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
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Kazem Kamran
//
#if !defined(KRATOS_TWO_FLUID_DPGVMS_H_INCLUDED )
#define KRATOS_TWO_FLUID_DPGVMS_H_INCLUDED
// System includes
#include <string>
#include <iostream>
// External includes
// Project includes
#include "containers/array_1d.h"
#include "includes/define.h"
#include "custom_elements/vms.h"
#include "includes/serializer.h"
#include "utilities/geometry_utilities.h"
#include "utilities/split_tetrahedra.h"
#include "utilities/enrichment_utilities.h"
// Application includes
#include "fluid_dynamics_application_variables.h"
#include "vms.h"
namespace Kratos
{
///@addtogroup FluidDynamicsApplication
///@{
///@name Kratos Globals
///@{
///@}
///@name Type Definitions
///@{
///@}
///@name Enum's
///@{
///@}
///@name Functions
///@{
///@}
///@name Kratos Classes
///@{
template< unsigned int TDim,
unsigned int TNumNodes = TDim + 1 >
class DPGVMS : public VMS<TDim, TNumNodes>
{
public:
///@name Type Definitions
///@{
/// Pointer definition of DPGVMS
KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(DPGVMS);
///base type: an IndexedObject that automatically has a unique number
typedef IndexedObject BaseType;
///Element from which it is derived
typedef VMS<TDim, TNumNodes> ElementBaseType;
///definition of node type (default is: Node)
typedef Node NodeType;
/**
* Properties are used to store any parameters
* related to the constitutive law
*/
typedef Properties PropertiesType;
///definition of the geometry type with given NodeType
typedef Geometry<NodeType> GeometryType;
///definition of nodes container type, redefined from GeometryType
typedef Geometry<NodeType>::PointsArrayType NodesArrayType;
typedef Vector VectorType;
typedef typename ElementBaseType::MatrixType MatrixType;
typedef std::size_t IndexType;
typedef std::size_t SizeType;
typedef std::vector<std::size_t> EquationIdVectorType;
typedef std::vector< Dof<double>::Pointer > DofsVectorType;
typedef PointerVectorSet<Dof<double>, IndexedObject> DofsArrayType;
///@}
///@name Life Cycle
///@{
//Constructors.
/// Default constructor.
/**
* @param NewId Index number of the new element (optional)
*/
DPGVMS(IndexType NewId = 0) :
ElementBaseType(NewId)
{
}
///Constructor using an array of nodes.
/**
* @param NewId Index of the new element
* @param ThisNodes An array containing the nodes of the new element
*/
DPGVMS(IndexType NewId, const NodesArrayType& ThisNodes) :
ElementBaseType(NewId, ThisNodes)
{
}
/// Constructor using a geometry object.
/**
* @param NewId Index of the new element
* @param pGeometry Pointer to a geometry object
*/
DPGVMS(IndexType NewId, GeometryType::Pointer pGeometry) :
ElementBaseType(NewId, pGeometry)
{
}
/// Constructor using geometry and properties.
/**
* @param NewId Index of the new element
* @param pGeometry Pointer to a geometry object
* @param pProperties Pointer to the element's properties
*/
DPGVMS(IndexType NewId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties) :
ElementBaseType(NewId, pGeometry, pProperties)
{
}
/// Destructor.
~DPGVMS() override
{
}
///@}
///@name Operators
///@{
///@}
///@name Operations
///@{
/// Create a new element of this type
/**
* Returns a pointer to a new DPGVMS element, created using given input
* @param NewId the ID of the new element
* @param ThisNodes the nodes of the new element
* @param pProperties the properties assigned to the new element
* @return a Pointer to the new element
*/
Element::Pointer Create(IndexType NewId, NodesArrayType const& ThisNodes,
PropertiesType::Pointer pProperties) const override
{
return Kratos::make_intrusive<DPGVMS>(NewId, (this->GetGeometry()).Create(ThisNodes), pProperties);
}
/// Create a new element of this type.
/**
@param NewId Index of the new element
@param pGeom A pointer to the geometry of the new element
@param pProperties Pointer to the element's properties
*/
Element::Pointer Create(
IndexType NewId,
GeometryType::Pointer pGeom,
PropertiesType::Pointer pProperties) const override
{
return Kratos::make_intrusive< DPGVMS >(NewId,pGeom,pProperties);
}
/// Call at the beginning of each step, it decides if element is cut or not!
/**
*/
void InitializeSolutionStep(const ProcessInfo &rCurrentProcessInfo) override
{
// for (unsigned int jj = 0; jj < 4; jj++){
// this->GetGeometry()[jj].FastGetSolutionStepValue(WET_VOLUME ) = 0.0;
// this->GetGeometry()[jj].FastGetSolutionStepValue(CUTTED_AREA ) = 0.0;
// }
}
/// Call at the beginning of each iteration, it decides if element is cut or not!
/**
*/
void InitializeNonLinearIteration(const ProcessInfo& rCurrentProcessInfo) override
{
// Calculate this element's geometric parameters
double Area;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Area);
//get position of the cut surface
Vector distances(TNumNodes);
Matrix Nenriched(6, 1);
Vector volumes(6);
Matrix coords(TNumNodes, TDim);
Matrix Ngauss(6, TNumNodes);
Vector signs(6);
std::vector< Matrix > gauss_gradients(6);
//fill coordinates
for (unsigned int i = 0; i < TNumNodes; i++)
{
const array_1d<double, 3 > & xyz = this->GetGeometry()[i].Coordinates();
volumes[i] = 0.0;
distances[i] = this->GetGeometry()[i].FastGetSolutionStepValue(DISTANCE);
for (unsigned int j = 0; j < TDim; j++)
coords(i, j) = xyz[j];
}
this->GetValue(AUX_INDEX) = 0.0;
for (unsigned int i = 0; i < 6; i++)
gauss_gradients[i].resize(1, TDim, false);
array_1d<double,6> edge_areas;
unsigned int ndivisions = EnrichmentUtilities::CalculateTetrahedraEnrichedShapeFuncions(coords, DN_DX, distances, volumes, Ngauss, signs, gauss_gradients, Nenriched,edge_areas);
if(ndivisions == 1)
this->is_cutted = 0;
else{
this->is_cutted = 1;
this->GetValue(AUX_INDEX) = 1.0;
}
}
/// Provides local contributions from body forces and OSS projection terms
/**
* This is called during the assembly process and provides the terms of the
* system that are either constant or computed explicitly (from the 'old'
* iteration variables). In this case this means the body force terms and the
* OSS projections, that are treated explicitly.
* @param rLeftHandSideMatrix the elemental left hand side matrix. Not used here, required for compatibility purposes only.
* @param rRightHandSideVector the elemental right hand side
* @param rCurrentProcessInfo the current process info
*/
void CalculateLocalSystem(MatrixType& rLeftHandSideMatrix,
VectorType& rRightHandSideVector,
const ProcessInfo& rCurrentProcessInfo) override
{
// this->IsCutted();
unsigned int LocalSize = (TDim + 1) * TNumNodes;
if( this->is_cutted == 1)
{
LocalSize += 1;
// Check sizes and initialize matrix
if (rLeftHandSideMatrix.size1() != LocalSize)
rLeftHandSideMatrix.resize(LocalSize, LocalSize, false);
noalias(rLeftHandSideMatrix) = ZeroMatrix(LocalSize, LocalSize);
this->CalculateRightHandSide(rRightHandSideVector, rCurrentProcessInfo);
}
else
{
// Check sizes and initialize matrix
if (rLeftHandSideMatrix.size1() != LocalSize)
rLeftHandSideMatrix.resize(LocalSize, LocalSize, false);
noalias(rLeftHandSideMatrix) = ZeroMatrix(LocalSize, LocalSize);
ElementBaseType::CalculateRightHandSide(rRightHandSideVector, rCurrentProcessInfo);
}
}
/// Provides local contributions from body forces and projections to the RHS
/**
* This is called during the assembly process and provides the RHS terms of the
* system that are either constant or computed explicitly (from the 'old'
* iteration variables). In this case this means the body force terms and the
* OSS projections, that are treated explicitly.
* @param rRightHandSideVector Will be filled with the elemental right hand side
* @param rCurrentProcessInfo ProcessInfo instance from the ModelPart. It is
* expected to contain values for OSS_SWITCH, DYNAMIC_TAU and DELTA_TIME
*/
void CalculateRightHandSide(VectorType& rRightHandSideVector,
const ProcessInfo& rCurrentProcessInfo) override
{
if( this->is_cutted == 1)
{
unsigned int LocalSize = (TDim + 1) * TNumNodes + 1;
// Check sizes and initialize
if (rRightHandSideVector.size() != LocalSize)
rRightHandSideVector.resize(LocalSize, false);
noalias(rRightHandSideVector) = ZeroVector(LocalSize);
// Calculate this element's geometric parameters
double Area;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Area);
//get position of the cut surface
Vector distances(TNumNodes);
Matrix Nenriched(6, 1);
Vector volumes(6);
Matrix coords(TNumNodes, TDim);
Matrix Ngauss(6, TNumNodes);
Vector signs(6);
std::vector< Matrix > gauss_gradients(6);
//fill coordinates
for (unsigned int i = 0; i < TNumNodes; i++)
{
const array_1d<double, 3 > & xyz = this->GetGeometry()[i].Coordinates();
volumes[i] = 0.0;
distances[i] = this->GetGeometry()[i].FastGetSolutionStepValue(DISTANCE);
for (unsigned int j = 0; j < TDim; j++)
coords(i, j) = xyz[j];
}
for (unsigned int i = 0; i < 6; i++)
gauss_gradients[i].resize(1, TDim, false);
array_1d<double,6> edge_areas;
unsigned int ndivisions = EnrichmentUtilities::CalculateTetrahedraEnrichedShapeFuncions(coords, DN_DX, distances, volumes, Ngauss, signs, gauss_gradients, Nenriched,edge_areas);
//do integration
for (unsigned int igauss = 0; igauss < ndivisions; igauss++)
{
//assigning the gauss data
for (unsigned int k = 0; k < TNumNodes; k++)
N[k] = Ngauss(igauss, k);
double wGauss = volumes[igauss];
// Calculate this element's fluid properties
double Density;
this->EvaluateInPoint(Density, DENSITY, N);
// Calculate Momentum RHS contribution
this->AddMomentumRHS(rRightHandSideVector, Density, N, wGauss);
// For OSS: Add projection of residuals to RHS
// if (rCurrentProcessInfo[OSS_SWITCH] == 1)
// {
// array_1d<double, 3 > AdvVel;
// this->GetAdvectiveVel(AdvVel, N);
// double KinViscosity;
// this->EvaluateInPoint(KinViscosity, VISCOSITY, N);
// double Viscosity;
// this->GetEffectiveViscosity(Density, KinViscosity, N, DN_DX, Viscosity, rCurrentProcessInfo);
// // Calculate stabilization parameters
// double TauOne, TauTwo;
// // if (ndivisions == 1)
// this->CalculateTau(TauOne, TauTwo, AdvVel, Area, Density, Viscosity, rCurrentProcessInfo);
// // else
// // {
// // TauOne = 0.0;
// // TauTwo = 0.0;
// // }
// // this->CalculateTau(TauOne, TauTwo, AdvVel, Area, Viscosity, rCurrentProcessInfo);
// this->AddProjectionToRHS(rRightHandSideVector, AdvVel, Density, TauOne, TauTwo, N, DN_DX, wGauss, rCurrentProcessInfo[DELTA_TIME]);
// }
}
}
else
ElementBaseType::CalculateRightHandSide(rRightHandSideVector, rCurrentProcessInfo);
}
/// Computes local contributions to the mass matrix
/**
* Provides the local contributions to the mass matrix, which is defined here
* as the matrix associated to velocity derivatives. Note that the mass
* matrix implemented here is lumped.
* @param rMassMatrix Will be filled with the elemental mass matrix
* @param rCurrentProcessInfo the current process info instance
*/
void CalculateMassMatrix(MatrixType& rMassMatrix, const ProcessInfo& rCurrentProcessInfo) override
{
// this->IsCutted();
if( this->is_cutted == 0)
ElementBaseType::CalculateMassMatrix(rMassMatrix, rCurrentProcessInfo);
else
{
const unsigned int LocalSize = (TDim + 1) * TNumNodes + 1;
// Resize and set to zero
if (rMassMatrix.size1() != LocalSize)
rMassMatrix.resize(LocalSize, LocalSize, false);
rMassMatrix = ZeroMatrix(LocalSize, LocalSize);
// Get the element's geometric parameters
double Area;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Area);
//get position of the cut surface
Vector distances(TNumNodes);
Matrix Nenriched(6, 1);
Vector volumes(6);
Matrix coords(TNumNodes, TDim);
Matrix Ngauss(6, TNumNodes);
Vector signs(6);
std::vector< Matrix > gauss_gradients(6);
//fill coordinates
for (unsigned int i = 0; i < TNumNodes; i++)
{
const array_1d<double, 3 > & xyz = this->GetGeometry()[i].Coordinates();
volumes[i] = 0.0;
distances[i] = this->GetGeometry()[i].FastGetSolutionStepValue(DISTANCE);
for (unsigned int j = 0; j < TDim; j++)
coords(i, j) = xyz[j];
}
for (unsigned int i = 0; i < 6; i++)
gauss_gradients[i] = ZeroMatrix(1,TDim);//.resize(1, TDim, false);
array_1d<double,6> edge_areas;
unsigned int ndivisions = EnrichmentUtilities::CalculateTetrahedraEnrichedShapeFuncions(coords, DN_DX, distances, volumes, Ngauss, signs, gauss_gradients, Nenriched,edge_areas);
//mass matrix
for (unsigned int igauss = 0; igauss < ndivisions; igauss++)
{
//assigning the gauss data
for (unsigned int k = 0; k < TNumNodes; k++)
N[k] = Ngauss(igauss, k);
double wGauss = volumes[igauss];
// Calculate this element's fluid properties
double Density;
this->EvaluateInPoint(Density, DENSITY, N);
// Consistent Mass Matrix
this->AddConsistentMassMatrixContribution(rMassMatrix, N, Density, wGauss);
}
this->LumpMassMatrix(rMassMatrix);
//stabilization terms
for (unsigned int igauss = 0; igauss < ndivisions; igauss++)
{
//assigning the gauss data
for (unsigned int k = 0; k < TNumNodes; k++)
N[k] = Ngauss(igauss, k);
double wGauss = volumes[igauss];
// Calculate this element's fluid properties
double Density;
this->EvaluateInPoint(Density, DENSITY, N);
/* For ASGS: add dynamic stabilization terms.
* These terms are not used in OSS, as they belong to the finite element
* space and cancel out with their projections.
*/
if (rCurrentProcessInfo[OSS_SWITCH] != 1)
{
double ElemSize = this->ElementSize(Area);
double Viscosity = this->EffectiveViscosity(Density,N,DN_DX,ElemSize, rCurrentProcessInfo);
// Get Advective velocity
array_1d<double, 3 > AdvVel;
this->GetAdvectiveVel(AdvVel, N);
// Calculate stabilization parameters
double TauOne, TauTwo;
this->CalculateTau(TauOne, TauTwo, AdvVel, ElemSize, Density, Viscosity, rCurrentProcessInfo);
// Add dynamic stabilization terms ( all terms involving a delta(u) )
this->AddMassStabTerms(rMassMatrix, Density, AdvVel, TauOne, N, DN_DX, wGauss,gauss_gradients[igauss]);
}
}
}
}
/// Computes the local contribution associated to 'new' velocity and pressure values
/**
* Provides local contributions to the system associated to the velocity and
* pressure terms (convection, diffusion, pressure gradient/velocity divergence
* and stabilization).
* @param rDampingMatrix Will be filled with the velocity-proportional "damping" matrix
* @param rRightHandSideVector the elemental right hand side vector
* @param rCurrentProcessInfo the current process info instance
*/
void CalculateLocalVelocityContribution(MatrixType& rDampingMatrix,
VectorType& rRightHandSideVector,
const ProcessInfo& rCurrentProcessInfo) override
{
// this->IsCutted();
if( this->is_cutted == 0){
ElementBaseType::CalculateLocalVelocityContribution(rDampingMatrix, rRightHandSideVector, rCurrentProcessInfo);
//compute boundary term
// int boundary_nodes = 0;
//unsigned int inside_index = -1;
// for (unsigned int i = 0; i < TNumNodes; i++)
// {
// double nd_flag = this->GetGeometry()[i].FastGetSolutionStepValue(FLAG_VARIABLE);
// if (nd_flag == 5.0)
// boundary_nodes++;
// //else
// //inside_index = i;
// }
/* if(boundary_nodes == TDim)
{
// Get this element's geometric properties
double Volume;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Volume);
BoundedMatrix<double, 16, 16 > boundary_damp_matrix;
noalias(boundary_damp_matrix) = ZeroMatrix(16,16);
array_1d<double,3> face_normal;
face_normal[0] = -DN_DX(inside_index,0);
face_normal[1] = -DN_DX(inside_index,1);
face_normal[2] = -DN_DX(inside_index,2);
const double fn = norm_2(face_normal);
face_normal/= fn;
double face_area = 3.0*Volume*fn;
// int LocalIndex = 0;
// for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
// {
// const double& pnode = this->GetGeometry()[iNode].FastGetSolutionStepValue(PRESSURE); // Pressure Dof
// for (unsigned int d = 0; d < TDim; ++d) // Velocity Dofs
// {
// if(iNode != inside_index)
// rRightHandSideVector[LocalIndex] -= pnode*face_normal[d]*face_area/3.0 ;
// ++LocalIndex;
// }
// ++LocalIndex;
// }
// int LocalIndex = 0;
// double pface = 0.0;
// for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
// {
// const double& pnode = this->GetGeometry()[iNode].FastGetSolutionStepValue(PRESSURE); // Pressure Dof
// if(iNode != inside_index) pface += pnode;
// }
// pface/=3.0;
//
// for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
// {
// for (unsigned int d = 0; d < TDim; ++d) // Velocity Dofs
// {
// if(iNode != inside_index)
// rRightHandSideVector[LocalIndex] -= pface*face_normal[d]*face_area/3.0 ;
// ++LocalIndex;
// }
// ++LocalIndex;
// }
AddBoundaryTerm(boundary_damp_matrix, DN_DX, N, face_normal, face_area, Volume, rCurrentProcessInfo);
VectorType U = ZeroVector(16);
int LocalIndex = 0;
for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
{
array_1d< double, 3 > & rVel = this->GetGeometry()[iNode].FastGetSolutionStepValue(VELOCITY);
for (unsigned int d = 0; d < TDim; ++d) // Velocity Dofs
{
U[LocalIndex] = rVel[d];
++LocalIndex;
}
U[LocalIndex] = this->GetGeometry()[iNode].FastGetSolutionStepValue(PRESSURE); // Pressure Dof
++LocalIndex;
}
noalias(rRightHandSideVector) -= prod(boundary_damp_matrix, U);
noalias(rDampingMatrix) += boundary_damp_matrix;
} */
}
else
{
const unsigned int LocalSize = (TDim + 1) * TNumNodes + 1;
// Resize and set to zero the matrix
// Note that we don't clean the RHS because it will already contain body force (and stabilization) contributions
if (rDampingMatrix.size1() != LocalSize)
rDampingMatrix.resize(LocalSize, LocalSize, false);
noalias(rDampingMatrix) = ZeroMatrix(LocalSize, LocalSize);
// Get this element's geometric properties
double Area;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Area);
//get position of the cut surface
Vector distances(TNumNodes);
Matrix Nenriched(6, 1);
Vector volumes(6);
Matrix coords(TNumNodes, TDim);
Matrix Ngauss(6, TNumNodes);
Vector signs(6);
std::vector< Matrix > gauss_gradients(6);
//fill coordinates
for (unsigned int i = 0; i < TNumNodes; i++)
{
const array_1d<double, 3 > & xyz = this->GetGeometry()[i].Coordinates();
volumes[i] = 0.0;
distances[i] = this->GetGeometry()[i].FastGetSolutionStepValue(DISTANCE);
for (unsigned int j = 0; j < TDim; j++)
coords(i, j) = xyz[j];
}
for (unsigned int i = 0; i < 6; i++)
gauss_gradients[i] = ZeroMatrix(1,TDim);
array_1d<double,6> edge_areas;
unsigned int ndivisions = EnrichmentUtilities::CalculateTetrahedraEnrichedShapeFuncions(coords, DN_DX, distances, volumes, Ngauss, signs, gauss_gradients, Nenriched,edge_areas);
// Vector enrichment_terms_vertical = ZeroVector(LocalSize);
// Vector enrichment_terms_horizontal = ZeroVector(LocalSize);
// double enrichment_diagonal = 0.0;
// double enriched_rhs = 0.0;
array_1d<double,3> bf = ZeroVector(3);
//double positive_volume = 0.0;
//double negative_volume = 0.0;
//do integration
for (unsigned int igauss = 0; igauss < ndivisions; igauss++)
{
//assigning the gauss data
for (unsigned int k = 0; k < TNumNodes; k++)
N[k] = Ngauss(igauss, k);
const double wGauss = volumes[igauss];
// if(signs[igauss] > 0)
// positive_volume += wGauss;
// else
// negative_volume += wGauss;
// Calculate this element's fluid properties
double Density;
this->EvaluateInPoint(Density, DENSITY, N);
double ElemSize = this->ElementSize(Area);
double Viscosity = this->EffectiveViscosity(Density,N,DN_DX,ElemSize, rCurrentProcessInfo);
// Get Advective velocity
array_1d<double, 3 > AdvVel;
this->GetAdvectiveVel(AdvVel, N);
// Calculate stabilization parameters
double TauOne, TauTwo;
this->CalculateTau(TauOne, TauTwo, AdvVel, ElemSize, Density, Viscosity, rCurrentProcessInfo);
this->AddIntegrationPointVelocityContribution(rDampingMatrix, rRightHandSideVector, Density, Viscosity, AdvVel, TauOne, TauTwo, N, DN_DX, wGauss,Nenriched(igauss, 0),gauss_gradients[igauss]);
// if (ndivisions > 1)
// {
// //compute enrichment terms contribution
// for (unsigned int inode = 0; inode < TNumNodes; inode++)
// {
// int base_index = (TDim + 1) * inode;
// array_1d<double,TNumNodes> AGradN = ZeroVector(TNumNodes);
// this->GetConvectionOperator(AGradN,AdvVel,DN_DX);
// //momentum term
// for (unsigned int k = 0; k < TDim; k++)
// {
// double ConvTerm = wGauss * TauOne * gauss_gradients[igauss](0,k)* Density * AGradN[inode];
// enrichment_terms_vertical[base_index + k] += ConvTerm - wGauss * DN_DX(inode, k) * Nenriched(igauss, 0);
// enrichment_terms_horizontal[base_index + k] += ConvTerm + wGauss * DN_DX(inode, k) * Nenriched(igauss, 0);
// // enrichment_terms_vertical[base_index + k] +=wGauss*N[inode]*gauss_gradients[igauss](0, k); //-= wGauss * DN_DX(inode, k) * Nenriched(igauss, 0);
// // enrichment_terms_horizontal[base_index + k] -=Density*wGauss*N[inode]*gauss_gradients[igauss](0, k); // += Density*wGauss * DN_DX(inode, k) * Nenriched(igauss, 0);
// }
// //pressure term
// for (unsigned int k = 0; k < TDim; k++)
// {
// double temp = wGauss * TauOne* DN_DX(inode, k) * gauss_gradients[igauss](0, k);
// enrichment_terms_vertical[base_index + TDim] += temp;
// enrichment_terms_horizontal[base_index + TDim] += temp;
// }
// //add acceleration enrichment term
// //const array_1d<double,3>& vnode = this->GetGeometry()[inode].FastGetSolutionStepValue(VELOCITY);
// const array_1d<double,3>& old_vnode = this->GetGeometry()[inode].FastGetSolutionStepValue(VELOCITY,1);
// for (unsigned int k = 0; k < TDim; k++)
// {
// double coeff = wGauss * TauOne *Density * gauss_gradients[igauss](0,k)*N[inode] * 2.0/ Dt;
// enrichment_terms_horizontal[base_index + k] += coeff;
// enriched_rhs += coeff * (old_vnode[k]);
// // enrichment_terms_vertical[base_index + k] +=wGauss*N[inode]*gauss_gradients[igauss](0, k); //-= wGauss * DN_DX(inode, k) * Nenriched(igauss, 0);
// // enrichment_terms_horizontal[base_index + k] -=Density*wGauss*N[inode]*gauss_gradients[igauss](0, k); // += Density*wGauss * DN_DX(inode, k) * Nenriched(igauss, 0);
// }
// }
// //compute diagonal enrichment term
// array_1d<double,3> OldAcceleration = N[0]*this->GetGeometry()[0].FastGetSolutionStepValue(ACCELERATION,1);
// for(unsigned int jjj=0; jjj<(this->GetGeometry()).size(); jjj++)
// OldAcceleration += N[jjj]*(this->GetGeometry())[jjj].FastGetSolutionStepValue(ACCELERATION,1);
//
// for (unsigned int k = 0; k < TDim; k++)
// {
// const Matrix& enriched_grad = gauss_gradients[igauss];
// enrichment_diagonal += wGauss * TauOne * pow(enriched_grad(0, k), 2);
// enriched_rhs += wGauss * TauOne *Density * enriched_grad(0,k)*(bf[k]+OldAcceleration[k]);
// }
// }
}
// if (ndivisions > 1)
// {
// //add to LHS enrichment contributions
// double inverse_diag_term = 1.0 / ( enrichment_diagonal);
//
//
//
// for (unsigned int i = 0; i < LocalSize; i++)
// for (unsigned int j = 0; j < LocalSize; j++)
// rDampingMatrix(i, j) -= inverse_diag_term * enrichment_terms_vertical[i] * enrichment_terms_horizontal[j];
// rRightHandSideVector -= (inverse_diag_term*enriched_rhs )*enrichment_terms_vertical;
//
// }
// Now calculate an additional contribution to the residual: r -= rDampingMatrix * (u,p)
VectorType U = ZeroVector(LocalSize);
int LocalIndex = 0;
for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
{
array_1d< double, 3 > & rVel = this->GetGeometry()[iNode].FastGetSolutionStepValue(VELOCITY);
for (unsigned int d = 0; d < TDim; ++d) // Velocity Dofs
{
U[LocalIndex] = rVel[d];
++LocalIndex;
}
U[LocalIndex] = this->GetGeometry()[iNode].FastGetSolutionStepValue(PRESSURE); // Pressure Dof
++LocalIndex;
}
const double enriched_pr = this->GetValue(PRESSUREAUX);
U[LocalIndex] = enriched_pr;
noalias(rRightHandSideVector) -= prod(rDampingMatrix, U);
// KRATOS_WATCH(enriched_pr);
}
}
/// Implementation of FinalizeNonLinearIteration to compute enriched pressure.
void FinalizeNonLinearIteration(const ProcessInfo& rCurrentProcessInfo) override
{
// this->IsCutted();
if( this->is_cutted == 0)
ElementBaseType::FinalizeNonLinearIteration(rCurrentProcessInfo);
else
{
//fill vector of solution
const unsigned int LocalSize = (TDim + 1) * TNumNodes;
VectorType DU = ZeroVector(LocalSize);
int LocalIndex = 0;
for (unsigned int iNode = 0; iNode < TNumNodes; ++iNode)
{
const array_1d< double, 3 > rVel = this->GetGeometry()[iNode].FastGetSolutionStepValue(VELOCITY);
const array_1d< double, 3 > old_rVel = this->GetGeometry()[iNode].FastGetSolutionStepValue(VELOCITY,1);
for (unsigned int d = 0; d < TDim; ++d) // Velocity Dofs
{
DU[LocalIndex] = rVel[d]-old_rVel[d];
++LocalIndex;
}
DU[LocalIndex] = this->GetGeometry()[iNode].FastGetSolutionStepValue(PRESSURE) - this->GetGeometry()[iNode].FastGetSolutionStepValue(PRESSURE,1); // Pressure Dof
++LocalIndex;
}
/*call Residual vector for condensation, it is filled in the
scheme and consists of last row of LHS plus last member of RHS*/
VectorType residual_enr_vector = ZeroVector(LocalSize + 2);
residual_enr_vector = this->GetValue(GAPS);
//compute dp_enr = D^-1 * ( f - C U)
double C_Dup(0.0);
for (unsigned int ii = 0; ii < LocalSize; ++ii)
C_Dup += residual_enr_vector[ii]*DU[ii];
//take the value of enriched pressure from the last step and add the increment
double enr_p = this->GetValue(AUX_INDEX);
if( residual_enr_vector[LocalSize] == 0.0 )
KRATOS_THROW_ERROR(std::invalid_argument,"Diagonla member of enriched RES is zero !!!!!","")
else
enr_p += (residual_enr_vector[LocalSize + 1] - C_Dup)/residual_enr_vector[LocalSize] ;
//current iteration value of the enriched pressure
// enr_p = 0.0;
this->SetValue(PRESSUREAUX,enr_p);
}
}
/// Returns VELOCITY_X, VELOCITY_Y, (VELOCITY_Z,) PRESSURE for each node
/**
* @param Values Vector of nodal unknowns
* @param Step Get result from 'Step' steps back, 0 is current step. (Must be smaller than buffer size)
*/
void GetFirstDerivativesVector(Vector& values, int Step) const override
{
// this->IsCutted();
if( this->is_cutted == 0)
ElementBaseType::GetFirstDerivativesVector(values, Step);
else
{
unsigned int MatSize = (TDim + 1) * TNumNodes + 1;
if (values.size() != MatSize) values.resize(MatSize, false);
for (unsigned int i = 0; i < TNumNodes; i++)
{
unsigned int index = i * (TDim + 1);
values[index] = this->GetGeometry()[i].GetSolutionStepValue(VELOCITY_X, Step);
values[index + 1] = this->GetGeometry()[i].GetSolutionStepValue(VELOCITY_Y, Step);
values[index + 2] = this->GetGeometry()[i].GetSolutionStepValue(VELOCITY_Z, Step);
values[index + 3] = this->GetGeometry()[i].GetSolutionStepValue(PRESSURE, Step);
}
//add the enriched component
int last_index = (TDim + 1) * TNumNodes;
values[last_index] = this->GetValue(PRESSUREAUX);
}
}
/// Returns ACCELERATION_X, ACCELERATION_Y, (ACCELERATION_Z,) 0 for each node
/**
* @param Values Vector of nodal second derivatives
* @param Step Get result from 'Step' steps back, 0 is current step. (Must be smaller than buffer size)
*/
void GetSecondDerivativesVector(Vector& values, int Step) const override
{
// this->IsCutted();
if( this->is_cutted == 0)
ElementBaseType::GetSecondDerivativesVector(values, Step);
else
{
unsigned int MatSize = (TDim + 1) * TNumNodes + 1;
if (values.size() != MatSize) values.resize(MatSize, false);
for (unsigned int i = 0; i < TNumNodes; i++)
{
unsigned int index = i * (TDim + 1);
values[index] = this->GetGeometry()[i].GetSolutionStepValue(ACCELERATION_X, Step);
values[index + 1] = this->GetGeometry()[i].GetSolutionStepValue(ACCELERATION_Y, Step);
values[index + 2] = this->GetGeometry()[i].GetSolutionStepValue(ACCELERATION_Z, Step);
values[index + 3] = 0.0;
}
//add the enriched component
int last_index = (TDim + 1) * TNumNodes;
values[last_index] = 0.0;
}
}
/// Implementation of Calculate to compute the local OSS projections.
/**
* If rVariable == ADVPROJ, This function computes the OSS projection
* terms using pressure and velocity values from the previous iteration. The
* projections are then added to the nodal variables ADVPROJ (Momentum residual)
* and DIVPROJ (Mass continuity residual). It is assumed that the scheme will
* divide the result by the assembled NODAL_AREA, which is equivalent to a
* nodal interpolation using a lumped mass matrix.
* @param rVariable Use ADVPROJ
* @param Output Will be overwritten with the elemental momentum error
* @param rCurrentProcessInfo Process info instance (unused)
*/
void Calculate(const Variable<array_1d<double, 3 > >& rVariable,
array_1d<double, 3 > & rOutput,
const ProcessInfo& rCurrentProcessInfo) override
{
if (rVariable == ADVPROJ) // Compute residual projections for OSS
{
// Get the element's geometric parameters
double Area;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Area);
array_1d< double, 3 > ElementalMomRes = ZeroVector(3);
double ElementalMassRes(0);
//get position of the cut surface
Vector distances(TNumNodes);
Matrix Nenriched(6, 1);
Vector volumes(6);
Matrix coords(TNumNodes, TDim);
Matrix Ngauss(6, TNumNodes);
Vector signs(6);
std::vector< Matrix > gauss_gradients(6);
//fill coordinates
for (unsigned int i = 0; i < TNumNodes; i++)
{
const array_1d<double, 3 > & xyz = this->GetGeometry()[i].Coordinates();
volumes[i] = 0.0;
distances[i] = this->GetGeometry()[i].FastGetSolutionStepValue(DISTANCE);
for (unsigned int j = 0; j < TDim; j++)
coords(i, j) = xyz[j];
}
for (unsigned int i = 0; i < 6; i++)
gauss_gradients[i].resize(1, TDim, false);
array_1d<double,6> edge_areas;
unsigned int ndivisions = EnrichmentUtilities::CalculateTetrahedraEnrichedShapeFuncions(coords, DN_DX, distances, volumes, Ngauss, signs, gauss_gradients, Nenriched,edge_areas);
//do integration
for (unsigned int igauss = 0; igauss < ndivisions; igauss++)
{
//assigning the gauss data
for (unsigned int k = 0; k < TNumNodes; k++)
N[k] = Ngauss(igauss, k);
double wGauss = volumes[igauss];
// Calculate this element's fluid properties
double Density;;
this->EvaluateInPoint(Density, DENSITY, N);
// Get Advective velocity
array_1d<double, 3 > AdvVel;
this->GetAdvectiveVel(AdvVel, N);
// Output containers
ElementalMomRes = ZeroVector(3);
ElementalMassRes = 0.0;
this->AddProjectionResidualContribution(AdvVel, Density, ElementalMomRes, ElementalMassRes, N, DN_DX, wGauss);
if (rCurrentProcessInfo[OSS_SWITCH] == 1)
{
// Carefully write results to nodal variables, to avoid parallelism problems
for (unsigned int i = 0; i < TNumNodes; ++i)
{
this->GetGeometry()[i].SetLock(); // So it is safe to write in the node in OpenMP
array_1d< double, 3 > & rAdvProj = this->GetGeometry()[i].FastGetSolutionStepValue(ADVPROJ);
for (unsigned int d = 0; d < TDim; ++d)
rAdvProj[d] += N[i] * ElementalMomRes[d];
this->GetGeometry()[i].FastGetSolutionStepValue(DIVPROJ) += N[i] * ElementalMassRes;
this->GetGeometry()[i].FastGetSolutionStepValue(NODAL_AREA) += wGauss * N[i];
this->GetGeometry()[i].UnSetLock(); // Free the node for other threads
}
}
}
/// Return output
rOutput = ElementalMomRes;
}
else if (rVariable == SUBSCALE_VELOCITY)
{
// Get the element's geometric parameters
double Area;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Area);
array_1d< double, 3 > ElementalMomRes = ZeroVector(3);
double ElementalMassRes(0);
//get position of the cut surface
Vector distances(TNumNodes);
Matrix Nenriched(6, 1);
Vector volumes(6);
Matrix coords(TNumNodes, TDim);
Matrix Ngauss(6, TNumNodes);
Vector signs(6);
std::vector< Matrix > gauss_gradients(6);
//fill coordinates
for (unsigned int i = 0; i < TNumNodes; i++)
{
const array_1d<double, 3 > & xyz = this->GetGeometry()[i].Coordinates();
volumes[i] = 0.0;
distances[i] = this->GetGeometry()[i].FastGetSolutionStepValue(DISTANCE);
for (unsigned int j = 0; j < TDim; j++)
coords(i, j) = xyz[j];
}
for (unsigned int i = 0; i < 6; i++)
gauss_gradients[i].resize(1, TDim, false);
array_1d<double,6> edge_areas;
unsigned int ndivisions = EnrichmentUtilities::CalculateTetrahedraEnrichedShapeFuncions(coords, DN_DX, distances, volumes, Ngauss, signs, gauss_gradients, Nenriched,edge_areas);
//do integration
for (unsigned int igauss = 0; igauss < ndivisions; igauss++)
{
//assigning the gauss data
for (unsigned int k = 0; k < TNumNodes; k++)
N[k] = Ngauss(igauss, k);
double wGauss = volumes[igauss];
// Calculate this element's fluid properties
double Density;
this->EvaluateInPoint(Density, DENSITY, N);
// Get Advective velocity
array_1d<double, 3 > AdvVel;
this->GetAdvectiveVel(AdvVel, N);
// Output containers
ElementalMomRes = ZeroVector(3);
ElementalMassRes = 0.0;
this->AddProjectionResidualContribution(AdvVel, Density, ElementalMomRes, ElementalMassRes, N, DN_DX, wGauss);
if (rCurrentProcessInfo[OSS_SWITCH] == 1)
{
/* Projections of the elemental residual are computed with
* Newton-Raphson iterations of type M(lumped) dx = ElemRes - M(consistent) * x
*/
const double Weight = ElementBaseType::ConsistentMassCoef(wGauss); // Consistent mass matrix is Weigth * ( Ones(TNumNodes,TNumNodes) + Identity(TNumNodes,TNumNodes) )
// Carefully write results to nodal variables, to avoid parallelism problems
for (unsigned int i = 0; i < TNumNodes; ++i)
{
this->GetGeometry()[i].SetLock(); // So it is safe to write in the node in OpenMP
// Add elemental residual to RHS
array_1d< double, 3 > & rMomRHS = this->GetGeometry()[i].GetValue(ADVPROJ);
double& rMassRHS = this->GetGeometry()[i].GetValue(DIVPROJ);
for (unsigned int d = 0; d < TDim; ++d)
rMomRHS[d] += N[i] * ElementalMomRes[d];
rMassRHS += N[i] * ElementalMassRes;
// Write nodal area
this->GetGeometry()[i].FastGetSolutionStepValue(NODAL_AREA) += wGauss * N[i];
// Substract M(consistent)*x(i-1) from RHS
for (unsigned int j = 0; j < TNumNodes; ++j) // RHS -= Weigth * Ones(TNumNodes,TNumNodes) * x(i-1)
{
for (unsigned int d = 0; d < TDim; ++d)
rMomRHS[d] -= Weight * this->GetGeometry()[j].FastGetSolutionStepValue(ADVPROJ)[d];
rMassRHS -= Weight * this->GetGeometry()[j].FastGetSolutionStepValue(DIVPROJ);
}
for (unsigned int d = 0; d < TDim; ++d) // RHS -= Weigth * Identity(TNumNodes,TNumNodes) * x(i-1)
rMomRHS[d] -= Weight * this->GetGeometry()[i].FastGetSolutionStepValue(ADVPROJ)[d];
rMassRHS -= Weight * this->GetGeometry()[i].FastGetSolutionStepValue(DIVPROJ);
this->GetGeometry()[i].UnSetLock(); // Free the node for other threads
}
}
}
/// Return output
rOutput = ElementalMomRes;
}
}
/**
* @see DPGVMS::CalculateOnIntegrationPoints
*/
void CalculateOnIntegrationPoints(
const Variable<double>& rVariable,
std::vector<double>& rValues,
const ProcessInfo& rCurrentProcessInfo) override
{
if (rVariable == PRESSUREAUX)
{
for (unsigned int PointNumber = 0;
PointNumber < 1; PointNumber++)
{
// KRATOS_WATCH(this->GetValue(IS_WATER));
// KRATOS_WATCH(this->Info());
rValues[PointNumber] = this->GetValue(PRESSUREAUX);;
}
}
else if(rVariable == AUX_INDEX)
{
double Area;
array_1d<double, TNumNodes> N;
BoundedMatrix<double, TNumNodes, TDim> DN_DX;
GeometryUtils::CalculateGeometryData(this->GetGeometry(), DN_DX, N, Area);
array_1d<double, 3 > AdvVel;
this->GetAdvectiveVel(AdvVel, N);
double Density;