-
Notifications
You must be signed in to change notification settings - Fork 11
/
pzinterpolationspace.cpp
1793 lines (1571 loc) · 57.5 KB
/
pzinterpolationspace.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file
* @brief Contains the implementation of the TPZInterpolationSpace methods.
*/
#include "pzinterpolationspace.h"
#include "TPZMaterial.h"
#include "TPZMatSingleSpace.h"
#include "TPZMatErrorSingleSpace.h"
#include "TPZMatLoadCases.h"
#include "TPZMaterialDataT.h"
#include "TPZBndCond.h"
#include "TPZElementMatrixT.h"
#include "pzquad.h"
#include "TPZCompElDisc.h"
#include "TPZInterfaceEl.h"
#include "pztransfer.h"
#include "tpzchangeel.h"
#include "pzlog.h"
#ifdef PZ_LOG
static TPZLogger logger("pz.mesh.TPZInterpolationSpace");
#endif
TPZInterpolationSpace::TPZInterpolationSpace()
: TPZCompEl()
{
fPreferredOrder = -1;
}
TPZInterpolationSpace::TPZInterpolationSpace(TPZCompMesh &mesh, const TPZInterpolationSpace ©)
: TPZCompEl(mesh, copy)
{
fPreferredOrder = copy.fPreferredOrder;
}
TPZInterpolationSpace::TPZInterpolationSpace(TPZCompMesh &mesh, const TPZInterpolationSpace ©, std::map<int64_t,int64_t> &gl2lcElMap)
: TPZCompEl(mesh, copy, gl2lcElMap)
{
fPreferredOrder = copy.fPreferredOrder;
}
TPZInterpolationSpace::TPZInterpolationSpace(TPZCompMesh &mesh, const TPZInterpolationSpace ©, int64_t &index)
: TPZCompEl(mesh, copy, index)
{
fPreferredOrder = copy.fPreferredOrder;
}
TPZInterpolationSpace::TPZInterpolationSpace(TPZCompMesh &mesh, TPZGeoEl *gel, int64_t &index)
: TPZCompEl(mesh,gel,index)
{
fPreferredOrder = mesh.GetDefaultOrder();
}
TPZInterpolationSpace::~TPZInterpolationSpace(){
}
int TPZInterpolationSpace::MaxOrder(){
const int n = this->NConnects();
int result = -1;
int side;
for(int i = 0; i < n; i++){
// skip unidentified connects
if (ConnectIndex(i) < 0) {
continue;
}
side = this->Connect(i).Order();
if (side > result) result = side;
}//i
return result;
}
/** @brief Adjust the integration rule according to the polynomial order of shape functions. */
void TPZInterpolationSpace::AdjustIntegrationRule()
{
int order = MaxOrder();
int integrationruleorder = 0;
auto *mat =
dynamic_cast<TPZMatSingleSpace*>(this->Material());
if (mat) {
integrationruleorder = mat->IntegrationRuleOrder(order);
}else
{
integrationruleorder = order + order;
}
SetIntegrationRule(integrationruleorder);
}
int TPZInterpolationSpace::ComputeIntegrationOrder() const {
DebugStop();
return 0;
}
void TPZInterpolationSpace::Print(std::ostream &out) const {
out << __PRETTY_FUNCTION__ << std::endl;
TPZCompEl::Print(out);
out << "PreferredSideOrder " << fPreferredOrder << std::endl;
}
void TPZInterpolationSpace::ShortPrint(std::ostream &out) const {
out << __PRETTY_FUNCTION__ << std::endl;
out << "PreferredSideOrder " << fPreferredOrder << std::endl;
}
void TPZInterpolationSpace::ComputeSolution(TPZVec<REAL> &qsi,
TPZMaterialDataT<STATE> &data,
bool hasPhi){
if(hasPhi){
this->ReallyComputeSolution(data);
}else{
this->InitMaterialData(data);
data.fNeedsSol=true;
this->ComputeRequiredData(data,qsi);
}
}
void TPZInterpolationSpace::ReallyComputeSolution(TPZMaterialDataT<STATE> &data){
this->ReallyComputeSolutionT(data);
}
void TPZInterpolationSpace::ComputeSolution(TPZVec<REAL> &qsi,
TPZMaterialDataT<CSTATE> &data,
bool hasPhi){
if(hasPhi){
this->ReallyComputeSolution(data);
}else{
this->InitMaterialData(data);
data.fNeedsSol=true;
this->ComputeRequiredData(data,qsi);
}
}
void TPZInterpolationSpace::ReallyComputeSolution(TPZMaterialDataT<CSTATE> &data){
this->ReallyComputeSolutionT(data);
}
template<class TVar>
void TPZInterpolationSpace::ReallyComputeSolutionT(TPZMaterialDataT<TVar>& data){
const TPZFMatrix<REAL> &phi = data.phi;
const TPZFMatrix<REAL> &dphix = data.dphix;
const TPZFMatrix<REAL> &axes = data.axes;
TPZSolVec<TVar> &sol = data.sol;
TPZGradSolVec<TVar> &dsol = data.dsol;
const int nstate = this->Material()->NStateVariables();
const int ncon = this->NConnects();
TPZBlock &block = Mesh()->Block();
TPZFMatrix<TVar> &MeshSol = Mesh()->Solution();
const int64_t numbersol = MeshSol.Cols();
const int solVecSize = ncon? nstate : 0;
sol.resize(numbersol);
dsol.resize(numbersol);
for (int is = 0; is<numbersol; is++) {
sol[is].Resize(solVecSize);
sol[is].Fill(0.);
dsol[is].Redim(dphix.Rows(), solVecSize);
dsol[is].Zero();
}
int64_t iv = 0;
for(int in=0; in<ncon; in++) {
TPZConnect *df = &Connect(in);
const int64_t dfseq = df->SequenceNumber();
const int dfvar = block.Size(dfseq);
const int64_t pos = block.Position(dfseq);
for(int jn=0; jn<dfvar; jn++) {
for (int64_t is=0; is<numbersol; is++) {
sol[is][iv%nstate] +=
(TVar)phi.Get(iv/nstate,0)*MeshSol(pos+jn,is);
for(auto d=0; d<dphix.Rows(); d++){
dsol[is](d,iv%nstate) +=
(TVar)dphix.Get(d,iv/nstate)*MeshSol(pos+jn,is);
}
}
iv++;
}
}
}//method
void TPZInterpolationSpace::ComputeShape(TPZVec<REAL> &intpoint, TPZVec<REAL> &X,
TPZFMatrix<REAL> &jacobian, TPZFMatrix<REAL> &axes,
REAL &detjac, TPZFMatrix<REAL> &jacinv,
TPZFMatrix<REAL> &phi, TPZFMatrix<REAL> &dphi, TPZFMatrix<REAL> &dphidx){
TPZGeoEl * ref = this->Reference();
if (!ref){
PZError << "\nERROR AT " << __PRETTY_FUNCTION__ << " - this->Reference() == NULL\n";
return;
}//if
ref->Jacobian( intpoint, jacobian, axes, detjac , jacinv);
this->Shape(intpoint,phi,dphi);
this->Convert2Axes(dphi, jacinv, dphidx);
}
void TPZInterpolationSpace::ComputeShape(TPZVec<REAL> &intpoint, TPZMaterialData &data){
this->ComputeShape(intpoint,data.x,data.jacobian,data.axes,data.detjac,data.jacinv,data.phi,data.dphi,data.dphix);
}
REAL TPZInterpolationSpace::InnerRadius(){
if (!this->Reference()){
PZError << "Error at " << __PRETTY_FUNCTION__ << " this->Reference() == NULL\n";
return 0.;
}
return this->Reference()->ElementRadius();
}
void TPZInterpolationSpace::InitMaterialData(TPZMaterialData &data){
data.gelElId = this->Reference()->Id();
auto *mat =
dynamic_cast<TPZMatSingleSpace*>(this->Material());
#ifdef PZDEBUG
if(!mat)
{
DebugStop();
}
#endif
mat->FillDataRequirements(data);
const int dim = this->Dimension();
const int nshape = this->NShapeF();
const int nstate = this->Material()->NStateVariables();
data.fShapeType = TPZMaterialData::EScalarShape;
data.phi.Redim(nshape,1);
data.dphi.Redim(dim,nshape);
data.dphix.Redim(dim,nshape);
data.axes.Redim(dim,3);
data.jacobian.Redim(dim,dim);
data.jacinv.Redim(dim,dim);
data.x.Resize(3);
if (data.fNeedsSol){
uint64_t ulen,durow,ducol;
mat->GetSolDimensions(ulen,durow,ducol);
data.SetSolSizes(nstate, ulen, durow, ducol);
}
//Completing for three dimensional elements
TPZManVector<REAL,3> x_center(3,0.0);
TPZVec<REAL> center_qsi(dim,0.0);
if (dim == 2) {
if (Reference()->Type() == ETriangle) {
center_qsi[0] = 0.25;
center_qsi[1] = 0.25;
}
}
else if (dim == 3) {
if (Reference()->Type() == EPrisma) {
center_qsi[0] = 1./3.;
center_qsi[1] = 1./3.;
center_qsi[2] = 0.0;
}
else if (Reference()->Type() == ETetraedro) {
center_qsi[0] = 0.25;
center_qsi[1] = 0.25;
center_qsi[2] = 0.25;
}
else if (Reference()->Type() == EPiramide) {
center_qsi[0] = 0.0;
center_qsi[1] = 0.0;
center_qsi[2] = 1./5.;
}
}
Reference()->X(center_qsi, x_center);
data.XCenter = x_center;
}//void
template<class TVar>
void TPZInterpolationSpace::ComputeRequiredDataT(TPZMaterialDataT<TVar> &data,
TPZVec<REAL> &qsi){
// data.intGlobPtIndex = -1;
this->ComputeShape(qsi, data);
if (data.fNeedsSol){
this->ReallyComputeSolution(data);
}//fNeedsSol
data.x.Resize(3, 0.0);
Reference()->X(qsi, data.x);
data.xParametric = qsi;
if (data.fNeedsHSize){
data.HSize = 2.*this->InnerRadius();
}//fNeedHSize
if (data.fNeedsNormal){
this->ComputeNormal(data);
}//fNeedsNormal
}//void
void TPZInterpolationSpace::ComputeNormal(TPZMaterialData & data)
{
data.normal.Resize(3,0.);
int thisFace, neighbourFace, i, dim;
TPZGeoEl * thisGeoEl, * neighbourGeoEl;
thisGeoEl = this->Reference();
int thiseldim = thisGeoEl->Dimension();
TPZManVector<REAL,3> thisCenter(thiseldim,0.), thisXVol(3,0.), neighbourXVol(3,0.), vec(3), axes1(3), axes2(3);
thisFace = thisGeoEl->NSides() - 1;
TPZGeoElSide thisside(thisGeoEl,thisFace);
TPZCompMesh *cmesh = this->Mesh();
TPZGeoElSide neighbourGeoElSide = thisGeoEl->Neighbour(thisFace);
int matid = neighbourGeoElSide.Element()->MaterialId();
while (neighbourGeoElSide != thisside) {
matid = neighbourGeoElSide.Element()->MaterialId();
if(cmesh->FindMaterial(matid) && neighbourGeoElSide.Element()->Dimension() > thiseldim)
{
break;
}
neighbourGeoElSide = neighbourGeoElSide.Neighbour();
}
neighbourGeoEl = neighbourGeoElSide.Element();
neighbourFace = neighbourGeoEl->NSides() - 1;
if(neighbourGeoEl == thisGeoEl)
{
// normal evaluation makes no sense since the internal element side doesn't have a neighbour.
return; // place a breakpoint here if this is an issue
}
int neightdim = neighbourGeoEl->Dimension();
TPZManVector<REAL,3> neighbourCenter(neightdim,0.);
thisGeoEl->CenterPoint(thisFace, thisCenter);
neighbourGeoEl->CenterPoint(neighbourFace, neighbourCenter);
thisGeoEl->X(thisCenter,thisXVol);
neighbourGeoEl->X(neighbourCenter,neighbourXVol);
for(i = 0; i < 3; i++)
vec[i] = -neighbourXVol[i] + thisXVol[i];// vector towards the center of the neighbour element
dim = thisGeoEl->Dimension();
switch(dim)
{
case(0): // normal points towards the x-direction
data.normal[0] = 1.;
data.normal[1] = 0.;
data.normal[2] = 0.;
break;
case(1):
for(i = 0 ; i < 3; i ++) axes1[i] = data.axes(0,i); // rib direction
this->VectorialProd(axes1, vec, axes2);
this->VectorialProd(axes2, axes1, data.normal, true);
break;
case(2):
for(i = 0; i < 3; i++)
{
axes1[i] = data.axes(0,i);
axes2[i] = data.axes(1,i);
}
this->VectorialProd(axes1, axes2, data.normal, true);
break;
case(3):// in this case the normal becomes senseless. A null vector is passed instead
break;
default:
PZError << "TPZInterpolationSpace::ComputeNormal - unhandled element dimension\n";
}
// ensuring the normal vector points towards the neighbour element
REAL dot = 0.;
for(i = 0; i < 3; i++) dot += data.normal[i] * vec[i];
if(dot < 0.)
for(i = 0; i < 3; i++) data.normal[i] *= -1.;
}
void TPZInterpolationSpace::VectorialProd(TPZVec<REAL> & ivec, TPZVec<REAL> & jvec, TPZVec<REAL> & kvec, bool unitary)
{
kvec.Resize(3);
kvec[0] = ivec[1]*jvec[2] - ivec[2]*jvec[1];
kvec[1] = -ivec[0]*jvec[2] + ivec[2]*jvec[0];
kvec[2] = ivec[0]*jvec[1] - ivec[1]*jvec[0];
if(unitary)
{
REAL size = 0.;
int i;
for(i = 0; i < 3; i++)size += kvec[i] * kvec[i];
size = sqrt(size);
//if(size <= 1.e-9)PZError << "\nTPZInterpolationSpace::VectorialProd - null result\n";
for(i = 0; i < 3; i++)kvec[i] /= size;
}
}
template<class TVar>
void TPZInterpolationSpace::CalcStiffInternal(TPZElementMatrixT<TVar> &ek, TPZElementMatrixT<TVar> &ef){
auto* material =
dynamic_cast<TPZMatSingleSpaceT<TVar> *>(this->Material());
if(!material){
PZError << "Error at " << __PRETTY_FUNCTION__ << " this->Material() == NULL\n";
int matid = Reference()->MaterialId();
PZError << "Material Id which is missing = " << matid << std::endl;
ek.Reset();
ef.Reset();
return;
}
#ifdef PZ_LOG
if (logger.isDebugEnabled())
{
std::stringstream sout;
sout << __PRETTY_FUNCTION__ << " material id " << this->Material()->Id();
LOGPZ_DEBUG(logger,sout.str());
}
#endif
this->InitializeElementMatrix(ek,ef);
if (this->NConnects() == 0) return;//boundary discontinuous elements have this characteristic
TPZMaterialDataT<TVar> data;
this->InitMaterialData(data);
data.p = this->MaxOrder();
int dim = Dimension();
TPZManVector<REAL,3> intpoint(dim,0.);
REAL weight = 0.;
TPZAutoPointer<TPZIntPoints> intrule = GetIntegrationRule().Clone();
//#ifdef PZDEBUG
// {
// TPZManVector<int,3> intorder(dim,this->MaxOrder()*2);
// TPZAutoPointer<TPZIntPoints> intrule_clone = intrule->Clone();
// intrule_clone->SetOrder(intorder);
//
// if(intrule_clone->NPoints() > intrule->NPoints()){
// std::cout << "Element " << fIndex << " Bad integration rule points needed = " << intrule_clone->NPoints() << "; points obtained = " << intrule->NPoints() << std::endl;
// intrule = intrule_clone;
// }
// }
//#endif
// if(material->HasForcingFunction())
// {
// int maxorder = intrule->GetMaxOrder();
// if (maxorder > order) {
// order = maxorder;
// }
// }
// TPZManVector<int,3> intorder(dim,order);
// intrule->SetOrder(intorder);
int intrulepoints = intrule->NPoints();
for(int int_ind = 0; int_ind < intrulepoints; ++int_ind){
intrule->Point(int_ind,intpoint,weight);
data.intLocPtIndex = int_ind;
this->ComputeRequiredData(data, intpoint);
weight *= fabs(data.detjac);
material->Contribute(data, weight, ek.fMat, ef.fMat);
}//loop over integratin points
}//CalcStiff
template<class TVar>
void TPZInterpolationSpace::CalcResidualInternal(TPZElementMatrixT<TVar> &ef){
auto* material =
dynamic_cast<TPZMatSingleSpaceT<TVar> *>(this->Material());
if(!material){
PZError << "Error at " << __PRETTY_FUNCTION__ << " this->Material() == NULL\n";
ef.Reset();
return;
}
this->InitializeElementMatrix(ef);
if (this->NConnects() == 0) return; //boundary discontinuous elements have this characteristic
TPZMaterialDataT<TVar> data;
this->InitMaterialData(data);
data.p = this->MaxOrder();
int dim = Dimension();
TPZManVector<REAL,3> intpoint(dim,0.);
REAL weight = 0.;
TPZAutoPointer<TPZIntPoints> intrule = GetIntegrationRule().Clone();
// if(material->HasForcingFunction())
// {
// int maxorder = intrule->GetMaxOrder();
// if (maxorder > order) {
// order = maxorder;
// }
// }
// TPZManVector<int,3> intorder(dim,order);
// intrule->SetOrder(intorder);
// material->SetIntegrationRule(intrule, data.p, dim);
int intrulepoints = intrule->NPoints();
for(int int_ind = 0; int_ind < intrulepoints; ++int_ind){
intrule->Point(int_ind,intpoint,weight);
//this->ComputeShape(intpoint, data.x, data.jacobian, data.axes, data.detjac, data.jacinv, data.phi, data.dphix);
//weight *= fabs(data.detjac);
data.intLocPtIndex = int_ind;
this->ComputeRequiredData(data, intpoint);
weight *= fabs(data.detjac);
material->Contribute(data,weight,ef.fMat);
}//loop over integratin points
}//CalcResidual
void TPZInterpolationSpace::Solution(TPZVec<REAL> &qsi,int var,TPZVec<STATE> &sol) {
//TODOCOMPLEX
if(var >= 100) {
TPZCompEl::Solution(qsi,var,sol);
return;
}
if(var == 99) {
sol[0] = GetPreferredOrder();
// if (sol[0] != 2) {
// std::cout << __PRETTY_FUNCTION__ << " preferred order " << sol[0] << std::endl;
// }
return;
}
auto* material =
dynamic_cast<TPZMatSingleSpaceT<STATE> *>(this->Material());
if(!material) {
sol.Resize(0);
return;
}
//TODOCOMPLEX
TPZMaterialDataT<STATE> data;
this->InitMaterialData(data);
data.p = this->MaxOrder();
this->ComputeShape(qsi, data);
constexpr bool hasPhi{true};
this->ComputeSolution(qsi,data,hasPhi);
data.x.Resize(3);
this->Reference()->X(qsi, data.x);
int solSize = this->Material()->NSolutionVariables(var);
sol.Resize(solSize);
sol.Fill(0.);
material->Solution(data, var, sol);
}
void TPZInterpolationSpace::InterpolateSolution(TPZInterpolationSpace &coarsel){
// accumulates the transfer coefficients between the current element and the
// coarse element into the transfer matrix, using the transformation t
TPZMaterial * material = Material();
if(!material) {
PZError << __PRETTY_FUNCTION__ << " this->Material() == NULL " << std::endl;
return;
}
TPZTransform<> t(Dimension());
TPZGeoEl *ref = Reference();
//Cedric 16/03/99
// Reference()->BuildTransform(NConnects(),coarsel.Reference(),t);
t = Reference()->BuildTransform2(ref->NSides()-1,coarsel.Reference(),t);
int locnod = NConnects();
// int cornod = coarsel.NConnects();
int locmatsize = NShapeF();
int cormatsize = coarsel.NShapeF();
int nvar = material->NStateVariables();
int dimension = Dimension();
if (!dimension) {
PZError << "\nExiting " << __PRETTY_FUNCTION__ << " - trying to interpolate a node solution.\n";
return ;
}
//TPZFMatrix<REAL> loclocmat(locmatsize,locmatsize,0.);
TPZFMatrix<STATE> loclocmat(locmatsize,locmatsize,0.);
//TPZFMatrix<REAL> projectmat(locmatsize,nvar,0.);
TPZFMatrix<STATE> projectmat(locmatsize,nvar,0.);
TPZManVector<int,3> prevorder(dimension);
TPZAutoPointer<TPZIntPoints> intrule = GetIntegrationRule().Clone();
intrule->GetOrder(prevorder);
int thismaxorder = this->MaxOrder();
int coarsemaxorder = coarsel.MaxOrder();
int maxorder = (thismaxorder > coarsemaxorder) ? thismaxorder : coarsemaxorder;
// Cesar 2003-11-25 -->> To avoid integration warnings...
maxorder = (2*maxorder > intrule->GetMaxOrder() ) ? intrule->GetMaxOrder() : 2*maxorder;
TPZManVector<int,3> order(dimension,maxorder);
for(int dim = 0; dim < dimension; dim++) {
order[dim] = maxorder*2;
}
intrule->SetOrder(order);
TPZFNMatrix<220> locphi(locmatsize,1);
TPZFNMatrix<660> locdphi(dimension,locmatsize);//derivative of the shape function in the master domain
TPZFNMatrix<660> locdphidx(dimension,locmatsize);//derivative of the shape function in the deformed domain
TPZFNMatrix<220> corphi(cormatsize,1);
TPZFNMatrix<660> cordphi(dimension,cormatsize);//derivative of the shape function in the master domain
TPZManVector<REAL,3> int_point(dimension),coarse_int_point(dimension);
TPZFNMatrix<9> jacobian(dimension,dimension),jacinv(dimension,dimension);
TPZFNMatrix<9> axes(3,3,0.), coarseaxes(3,3,0.);
REAL zero = 0.;
TPZManVector<REAL,3> x(3,zero);
//TPZManVector<TPZManVector<REAL,10>, 10> u(1);
//TODOCOMPLEX
TPZSolVec<STATE> u(1);
u[0].resize(nvar);
//TPZManVector<TPZFNMatrix<30>, 10> du(1);
TPZGradSolVec<STATE> du(1);
du[0].Redim(dimension,nvar);
int numintpoints = intrule->NPoints();
REAL weight;
int lin,ljn,cjn;
TPZConnect *df;
// TPZBlock &coarseblock = coarsel.Mesh()->Block();
for(int int_ind = 0; int_ind < numintpoints; ++int_ind) {
intrule->Point(int_ind,int_point,weight);
t.Apply(int_point,coarse_int_point);
TPZMaterialDataT<STATE> coarsedata;
coarsedata.fNeedsSol=true;
constexpr bool hasPhi{false};
coarsel.ComputeSolution(coarse_int_point,coarsedata,hasPhi);
REAL jac_det = 1.;
this->ComputeShape(int_point, x, jacobian, axes, jac_det, jacinv, locphi, locdphi, locdphidx);
weight *= jac_det;
for(lin=0; lin<locmatsize; lin++) {
for(ljn=0; ljn<locmatsize; ljn++) {
loclocmat(lin,ljn) += weight*locphi(lin,0)*locphi(ljn,0);
}
for(cjn=0; cjn<nvar; cjn++) {
projectmat(lin,cjn) += (STATE)weight*(STATE)locphi(lin,0)*u[0][cjn];
}
}
jacobian.Zero();
}
REAL large = 0.;
for (lin = 0; lin < locmatsize; lin++) {
for (cjn = 0; cjn < locmatsize; cjn++) {
REAL val = fabs(loclocmat(lin,cjn));
large = large<val ? val : large;
}
}
loclocmat *= 1./large;
projectmat *= 1./large;
loclocmat.SolveDirect(projectmat,ELU);
// identify the non-zero blocks for each row
TPZBlock &fineblock = Mesh()->Block();
TPZFMatrix<STATE> &finesol = Mesh()->Solution();
int iv=0,in;
for(in=0; in<locnod; in++) {
df = &Connect(in);
int64_t dfseq = df->SequenceNumber();
int dfvar = fineblock.Size(dfseq);
for(ljn=0; ljn<dfvar; ljn++) {
finesol.at(fineblock.at(dfseq,0,ljn,0)) = projectmat(iv/nvar,iv%nvar);
iv++;
}
}
intrule->SetOrder(prevorder);
}//InterpolateSolution
void TPZInterpolationSpace::CreateInterfaces(bool BetweenContinuous) {
//nao verifica-se caso o elemento de contorno
//eh maior em tamanho que o interface associado
//caso AdjustBoundaryElement nao for aplicado
//a malha eh criada consistentemente
TPZGeoEl *ref = Reference();
int nsides = ref->NSides();
int InterfaceDimension = this->Material()->Dimension() - 1;
int side;
nsides--;//last face
for(side=nsides;side>=0;side--) {
if(ref->SideDimension(side) != InterfaceDimension) continue;
TPZCompElSide thisside(this,side);
if(this->ExistsInterface(thisside.Reference())) {
// cout << "TPZCompElDisc::CreateInterface inconsistent: interface already exists\n";
continue;
}
TPZStack<TPZCompElSide> highlist;
thisside.HigherLevelElementList(highlist,0,1);
//a interface se cria uma vez so quando existem ambos
//elementos esquerdo e direito (compu tacionais)
if(!highlist.NElements()) {
this->CreateInterface(side, BetweenContinuous);//s�tem iguais ou grande => pode criar a interface
} else {
int64_t ns = highlist.NElements();
int64_t is;
for(is=0; is<ns; is++) {//existem pequenos ligados ao lado atual
const int higheldim = highlist[is].Reference().Dimension();
if(higheldim != InterfaceDimension) continue;
// TPZCompElDisc *del = dynamic_cast<TPZCompElDisc *> (highlist[is].Element());
// if(!del) continue;
TPZCompEl *del = highlist[is].Element();
if(!del) continue;
TPZCompElSide delside( del, highlist[is].Side() );
TPZInterpolationSpace * delSp = dynamic_cast<TPZInterpolationSpace*>(del);
if (!delSp) {
PZError << "\nERROR AT " << __PRETTY_FUNCTION__ << " - CASE NOT AVAILABLE\n";
return;
}
if ( delSp->ExistsInterface(delside.Reference()) ) {
// cout << "TPZCompElDisc::CreateInterface inconsistent: interface already exists\n";
}
else {
delSp->CreateInterface(highlist[is].Side(), BetweenContinuous);
}
}
}
}
}
TPZInterfaceElement * TPZInterpolationSpace::CreateInterface(int side, bool BetweenContinuous)
{
// LOGPZ_INFO(logger, "Entering CreateInterface");
TPZGeoEl *ref = Reference();
if(!ref) {
LOGPZ_WARN(logger, "Exiting CreateInterface Null reference reached - NULL interface returned");
return NULL;
}
TPZCompElSide thisside(this,side);
TPZStack<TPZCompElSide> list;
list.Resize(0);
thisside.EqualLevelElementList(list,0,1);//retorna distinto ao atual ou nulo
const int64_t size = list.NElements();
if (size > 1) {
DebugStop();
}
//espera-se ter os elementos computacionais esquerdo e direito
//ja criados antes de criar o elemento interface
if(size){
//Interface has the same material of the neighbour with lesser dimension.
//It makes the interface have the same material of boundary conditions (TPZCompElDisc with interface dimension)
int64_t index;
TPZCompEl *list0 = list[0].Element();
int list0side = list[0].Side();
TPZCompElDisc * thisdisc = dynamic_cast<TPZCompElDisc*>(this);
TPZCompElDisc * neighdisc = dynamic_cast<TPZCompElDisc*>(list0);
int thisside = side;
int neighside = list0side;
if (BetweenContinuous == false){
//It means at least one element must be discontinuous
if (!thisdisc && !neighdisc){
return NULL;
}
}
TPZInterfaceElement * newcreatedinterface = NULL;
if (Dimension() == list0->Dimension())
{
const int matid = this->Mesh()->Reference()->InterfaceMaterial(this->Material()->Id(), list0->Material()->Id() );
TPZGeoEl *gel = ref->CreateBCGeoEl(side,matid); //isto acertou as vizinhanas da interface geometrica com o atual
if(!gel)
{
#ifdef PZ_LOG
if (logger.isDebugEnabled())
{
std::stringstream sout;
sout << "CreateBCGeoEl devolveu zero!@@@@";
LOGPZ_DEBUG(logger,sout.str());
}
#endif
DebugStop();
}
TPZCompElSide thiscompelside(this, thisside);
TPZCompElSide neighcompelside(list0, neighside);
int64_t index;
newcreatedinterface = new TPZInterfaceElement(*fMesh,gel,index,thiscompelside,neighcompelside);
} else
{
if(Dimension() > list0->Dimension())
{
const int matid = list0->Material()->Id();
TPZGeoEl *gel = ref->CreateBCGeoEl(side,matid); //isto acertou as vizinhanas da interface geometrica com o atual
if (!gel) {
DebugStop();
}
//o de volume eh o direito caso um deles seja BC
//a normal aponta para fora do contorno
TPZCompElSide thiscompelside(this, thisside);
TPZCompElSide neighcompelside(list0, neighside);
newcreatedinterface = new TPZInterfaceElement(*fMesh,gel,index,thiscompelside,neighcompelside);
} else {
const int matid = this->Material()->Id();
TPZGeoEl *gel = ref->CreateBCGeoEl(side,matid); //isto acertou as vizinhanas da interface geometrica com o atual
if(!gel) DebugStop();
//caso contrario ou caso ambos sejam de volume
TPZCompElSide thiscompelside(this, thisside);
TPZCompElSide neighcompelside(list0, neighside);
newcreatedinterface = new TPZInterfaceElement(*fMesh,gel,index,neighcompelside,thiscompelside);
}
}
/** GeoBlend verifications ***/
#ifdef PZDEBUG
{
TPZGeoEl * faceGel = newcreatedinterface->Reference();
TPZGeoEl * leftGel = newcreatedinterface->LeftElement()->Reference();
TPZGeoEl * rightGel = newcreatedinterface->RightElement()->Reference();
bool leftIsLinear = leftGel->IsLinearMapping();
bool rightIsLinear = rightGel->IsLinearMapping();
if(!leftIsLinear && !rightIsLinear){
if(faceGel->IsGeoBlendEl() == false){
std::cout << "\nError at " << __PRETTY_FUNCTION__ << "\n";
#ifdef PZ_LOG
{
std::stringstream sout;
sout << "\nError at " << __PRETTY_FUNCTION__ << "\n";
sout << "left gel:\n";
leftGel->Print(sout);
sout << "right gel:";
rightGel->Print(sout);
sout << "face gel:";
faceGel->Print(sout);
LOGPZ_ERROR(logger,sout.str());
}
#endif
}
}
}
#endif
/** ***/
return newcreatedinterface;
}
//If there is no equal level element, we try the lower elements.
//Higher elements will not be considered by this method. In that case the interface must be created by the neighbour.
TPZCompElSide lower = thisside.LowerLevelElementList(0);
if(lower.Exists()){
//Interface has the same material of the neighbour with lesser dimension.
//It makes the interface has the same material of boundary conditions (TPZCompElDisc with interface dimension)
int matid;
int thisdim = this->Dimension();
int neighbourdim = lower.Element()->Dimension();
if (thisdim == neighbourdim){
// matid = this->Material()->Id();
matid = this->Mesh()->Reference()->InterfaceMaterial(this->Material()->Id(), lower.Element()->Material()->Id() );
}
else { //one element is a boundary condition
if (thisdim < neighbourdim) matid = this->Material()->Id();
else
{
TPZCompEl *cel = lower.Element();
if (!cel) {
DebugStop();
}
TPZMaterial *mat = cel->Material();
if (!mat ) {
DebugStop();
}
matid = lower.Element()->Material()->Id();
}
}
TPZCompEl *lowcel = lower.Element();
int lowside = lower.Side();
TPZCompElDisc * thisdisc = dynamic_cast<TPZCompElDisc*>(this);
TPZCompElDisc * neighdisc = dynamic_cast<TPZCompElDisc*>(lowcel);
int thisside = side;
int neighside = lowside;
if (BetweenContinuous == false){
//It means at least one element must be discontinuous
if (!thisdisc && !neighdisc){
return NULL;
}
}
TPZInterfaceElement * newcreatedinterface = NULL;
int64_t index;
if(Dimension() == lowcel->Dimension()){///faces internas
const int matid = this->Mesh()->Reference()->InterfaceMaterial(lowcel->Material()->Id(), this->Material()->Id() );
TPZGeoEl *gel = ref->CreateBCGeoEl(side,matid); //isto acertou as vizinhanas da interface geometrica com o atual
if(!gel) DebugStop();
TPZCompElSide lowcelcompelside(lowcel, neighside);
TPZCompElSide thiscompelside(this, thisside);
int64_t index;
newcreatedinterface = new TPZInterfaceElement(*fMesh,gel,index,lowcelcompelside,thiscompelside);
}
else{
if(Dimension() > lowcel->Dimension()){
const int matid = lowcel->Material()->Id();
TPZGeoEl *gel = ref->CreateBCGeoEl(side,matid);
if (!gel) {
DebugStop();
}
//para que o elemento esquerdo seja de volume
TPZCompElSide thiscompelside(this, thisside);
TPZCompElSide lowcelcompelside(lowcel, neighside);
newcreatedinterface = new TPZInterfaceElement(*fMesh,gel,index,thiscompelside,lowcelcompelside);
} else {
const int matid = this->Material()->Id();
TPZGeoEl *gel = ref->CreateBCGeoEl(side,matid);
if (!gel) {
DebugStop();
}
TPZCompElSide thiscompelside(this, thisside);
TPZCompElSide lowcelcompelside(lowcel, neighside);
#ifdef PZ_LOG_KEEP
if (logger.isDebugEnabled())
{
std::stringstream sout;
sout << __PRETTY_FUNCTION__ << " left element";
sout << lowcelcompelside << thiscompelside;
sout << "Left Element ";
lowcelcompelside.Element()->Print(sout);
sout << "Right Element ";
thiscompelside.Element()->Print(sout);
LOGPZ_DEBUG(logger,sout.str())
}
#endif
newcreatedinterface = new TPZInterfaceElement(*fMesh,gel,index,lowcelcompelside,thiscompelside);
}
}
/** GeoBlend verifications ***/
#ifdef PZDEBUG
{
TPZGeoEl * faceGel = newcreatedinterface->Reference();
TPZGeoEl * leftGel = newcreatedinterface->LeftElement()->Reference();
TPZGeoEl * rightGel = newcreatedinterface->RightElement()->Reference();
bool leftIsLinear = leftGel->IsLinearMapping();
bool rightIsLinear = rightGel->IsLinearMapping();
if(!leftIsLinear && !rightIsLinear){
if(faceGel->IsGeoBlendEl() == false){
std::cout << "\nError at " << __PRETTY_FUNCTION__ << "\n";
#ifdef PZ_LOG
{
std::stringstream sout;
sout << "\nError at " << __PRETTY_FUNCTION__ << "\n";
sout << "left gel:\n";
leftGel->Print(sout);
sout << "right gel:";
rightGel->Print(sout);
sout << "face gel:";
faceGel->Print(sout);
LOGPZ_ERROR(logger,sout.str());
}
#endif
}
}
}
#endif
/** ***/
return newcreatedinterface;
}
return NULL;
}
int TPZInterpolationSpace::ExistsInterface(TPZGeoElSide geosd){
TPZGeoElSide neighside = geosd.Neighbour();
while(neighside.Element() && neighside.Element() != geosd.Element()){
TPZCompElSide neighcompside = neighside.Reference();
neighside = neighside.Neighbour();
if(!neighcompside.Element()) continue;
if(neighcompside.Element()->Type() == EInterface)
return 1;