~ubuntu-branches/ubuntu/trusty/yade/trusty

« back to all changes in this revision

Viewing changes to pkg/dem/VTKRecorder.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky, cf3f8d9
  • Date: 2013-10-30 20:56:33 UTC
  • mfrom: (20.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20131030205633-1f01r7hjce17d723
Tags: 1.05.0-2
[cf3f8d9] Pass -ftrack-macro-expansion=0 only if gcc>=4.8. (Closes: #726009)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include<vtkTriangle.h>
17
17
#include<vtkLine.h>
18
18
#include<vtkQuad.h>
 
19
#include<vtkHexahedron.h>
19
20
#ifdef YADE_VTK_MULTIBLOCK
20
21
  #include<vtkXMLMultiBlockDataWriter.h>
21
22
  #include<vtkMultiBlockDataSet.h>
26
27
#include<yade/pkg/common/Facet.hpp>
27
28
#include<yade/pkg/common/Box.hpp>
28
29
#include<yade/pkg/dem/ConcretePM.hpp>
29
 
#include<yade/pkg/dem/RockPM.hpp>
30
30
#include<yade/pkg/dem/WirePM.hpp>
 
31
#include<yade/pkg/dem/JointedCohesiveFrictionalPM.hpp>
31
32
#include<yade/pkg/dem/Shop.hpp>
32
33
 
33
34
 
50
51
                        recActive[REC_CLUMPID]=true;
51
52
                        recActive[REC_MATERIALID]=true;
52
53
                        recActive[REC_STRESS]=true;
 
54
                        if (scene->isPeriodic) { recActive[REC_PERICELL]=true; }
53
55
                }
54
56
                else if(rec=="spheres") recActive[REC_SPHERES]=true;
55
57
                else if(rec=="velocity") recActive[REC_VELOCITY]=true;
58
60
                else if(rec=="mass") recActive[REC_MASS]=true;
59
61
                else if((rec=="colors") || (rec=="color"))recActive[REC_COLORS]=true;
60
62
                else if(rec=="cpm") recActive[REC_CPM]=true;
61
 
                else if(rec=="rpm") recActive[REC_RPM]=true;
62
63
                else if(rec=="wpm") recActive[REC_WPM]=true;
63
64
                else if(rec=="intr") recActive[REC_INTR]=true;
64
65
                else if((rec=="ids") || (rec=="id")) recActive[REC_ID]=true;
66
67
                else if((rec=="clumpids") || (rec=="clumpId")) recActive[REC_CLUMPID]=true;
67
68
                else if(rec=="materialId") recActive[REC_MATERIALID]=true;
68
69
                else if(rec=="stress") recActive[REC_STRESS]=true;
69
 
                else LOG_ERROR("Unknown recorder named `"<<rec<<"' (supported are: all, spheres, velocity, facets, boxes, color, stress, cpm, rpm, wpm, intr, id, clumpId, materialId). Ignored.");
 
70
                else if(rec=="jcfpm") recActive[REC_JCFPM]=true;
 
71
                else if(rec=="cracks") recActive[REC_CRACKS]=true;
 
72
                else if(rec=="pericell" && scene->isPeriodic) recActive[REC_PERICELL]=true;
 
73
                else LOG_ERROR("Unknown recorder named `"<<rec<<"' (supported are: all, spheres, velocity, facets, boxes, color, stress, cpm, wpm, intr, id, clumpId, materialId, jcfpm, cracks, pericell). Ignored.");
70
74
        }
71
75
        // cpm needs interactions
72
76
        if(recActive[REC_CPM]) recActive[REC_INTR]=true;
73
77
        
 
78
        // jcfpm needs interactions
 
79
        if(recActive[REC_JCFPM]) recActive[REC_INTR]=true;
 
80
 
74
81
        // wpm needs interactions
75
82
        if(recActive[REC_WPM]) recActive[REC_INTR]=true;
76
83
        
191
198
        intrAbsForceT->SetNumberOfComponents(3);
192
199
        intrAbsForceT->SetName("absForceT");
193
200
 
 
201
        // pericell
 
202
        vtkSmartPointer<vtkPoints> pericellPoints = vtkSmartPointer<vtkPoints>::New();
 
203
        vtkSmartPointer<vtkCellArray> pericellHexa = vtkSmartPointer<vtkCellArray>::New();
 
204
 
194
205
        // extras for CPM
195
206
        if(recActive[REC_CPM]){ CpmStateUpdater csu; csu.update(scene); }
196
207
        vtkSmartPointer<vtkFloatArray> cpmDamage = vtkSmartPointer<vtkFloatArray>::New();
200
211
        cpmStress->SetNumberOfComponents(9);
201
212
        cpmStress->SetName("cpmStress");
202
213
 
203
 
        // extras for RPM
204
 
        vtkSmartPointer<vtkFloatArray> rpmSpecNum = vtkSmartPointer<vtkFloatArray>::New();
205
 
        rpmSpecNum->SetNumberOfComponents(1);
206
 
        rpmSpecNum->SetName("rpmSpecNum");
207
 
        vtkSmartPointer<vtkFloatArray> rpmSpecMass = vtkSmartPointer<vtkFloatArray>::New();
208
 
        rpmSpecMass->SetNumberOfComponents(1);
209
 
        rpmSpecMass->SetName("rpmSpecMass");
210
 
        vtkSmartPointer<vtkFloatArray> rpmSpecDiam = vtkSmartPointer<vtkFloatArray>::New();
211
 
        rpmSpecDiam->SetNumberOfComponents(1);
212
 
        rpmSpecDiam->SetName("rpmSpecDiam");
 
214
        // extras for JCFpm
 
215
        vtkSmartPointer<vtkFloatArray> damage = vtkSmartPointer<vtkFloatArray>::New();
 
216
        damage->SetNumberOfComponents(1);;
 
217
        damage->SetName("damage");
 
218
        vtkSmartPointer<vtkFloatArray> damageRel = vtkSmartPointer<vtkFloatArray>::New();
 
219
        damageRel->SetNumberOfComponents(1);;
 
220
        damageRel->SetName("damageRel");
 
221
        vtkSmartPointer<vtkFloatArray> intrIsCohesive = vtkSmartPointer<vtkFloatArray>::New();
 
222
        intrIsCohesive->SetNumberOfComponents(1);
 
223
        intrIsCohesive->SetName("isCohesive");
 
224
        vtkSmartPointer<vtkFloatArray> intrIsOnJoint = vtkSmartPointer<vtkFloatArray>::New();
 
225
        intrIsOnJoint->SetNumberOfComponents(1);
 
226
        intrIsOnJoint->SetName("isOnJoint");
 
227
        
 
228
        // extras for cracks
 
229
        vtkSmartPointer<vtkPoints> crackPos = vtkSmartPointer<vtkPoints>::New();
 
230
        vtkSmartPointer<vtkCellArray> crackCells = vtkSmartPointer<vtkCellArray>::New();
 
231
        vtkSmartPointer<vtkFloatArray> iter = vtkSmartPointer<vtkFloatArray>::New();
 
232
        iter->SetNumberOfComponents(1);
 
233
        iter->SetName("iter");
 
234
        vtkSmartPointer<vtkFloatArray> crackType = vtkSmartPointer<vtkFloatArray>::New();
 
235
        crackType->SetNumberOfComponents(1);
 
236
        crackType->SetName("crackType");
 
237
        vtkSmartPointer<vtkFloatArray> crackSize = vtkSmartPointer<vtkFloatArray>::New();
 
238
        crackSize->SetNumberOfComponents(1);
 
239
        crackSize->SetName("crackSize");
 
240
        vtkSmartPointer<vtkFloatArray> crackNorm = vtkSmartPointer<vtkFloatArray>::New();
 
241
        crackNorm->SetNumberOfComponents(3);
 
242
        crackNorm->SetName("crackNorm");
213
243
 
 
244
//      // the same for newly created cracks
 
245
//      vtkSmartPointer<vtkPoints> crackPosNew = vtkSmartPointer<vtkPoints>::New();
 
246
//      vtkSmartPointer<vtkCellArray> crackCellsNew = vtkSmartPointer<vtkCellArray>::New();
 
247
//      vtkSmartPointer<vtkFloatArray> iterNew = vtkSmartPointer<vtkFloatArray>::New();
 
248
//      iterNew->SetNumberOfComponents(1);
 
249
//      iterNew->SetName("iter");
 
250
//      vtkSmartPointer<vtkFloatArray> crackTypeNew = vtkSmartPointer<vtkFloatArray>::New();
 
251
//      crackTypeNew->SetNumberOfComponents(1);
 
252
//      crackTypeNew->SetName("crackType");
 
253
//      vtkSmartPointer<vtkFloatArray> crackSizeNew = vtkSmartPointer<vtkFloatArray>::New();
 
254
//      crackSizeNew->SetNumberOfComponents(1);
 
255
//      crackSizeNew->SetName("crackSize");
 
256
//      vtkSmartPointer<vtkFloatArray> crackNormNew = vtkSmartPointer<vtkFloatArray>::New();
 
257
//      crackNormNew->SetNumberOfComponents(3);
 
258
//      crackNormNew->SetName("crackNorm");
 
259
        
214
260
        // extras for WireMatPM
215
261
        vtkSmartPointer<vtkFloatArray> wpmNormalForce = vtkSmartPointer<vtkFloatArray>::New();
216
262
        wpmNormalForce->SetNumberOfComponents(1);
296
342
                                                wpmLimitFactor->InsertNextValue(NaN);
297
343
                                        }
298
344
                                }
 
345
                                else if (recActive[REC_JCFPM]){
 
346
                                        const JCFpmPhys* jcfpmphys = YADE_CAST<JCFpmPhys*>(I->phys.get());
 
347
                                        intrIsCohesive->InsertNextValue(jcfpmphys->isCohesive);
 
348
                                        intrIsOnJoint->InsertNextValue(jcfpmphys->isOnJoint);
 
349
                                        intrForceN->InsertNextValue(fn);
 
350
                                }
 
351
 
299
352
                                else {
300
353
                                        intrForceN->InsertNextValue(fn);
301
354
                                }
356
409
                                        float s[9]={ (float) ss(0,0), (float) ss(0,1), (float) ss(0,2), (float) ss(1,0), (float) ss(1,1), (float) ss(1,2), (float) ss(2,0), (float) ss(2,1), (float) ss(2,2)};
357
410
                                        cpmStress->InsertNextTupleValue(s);
358
411
                                }
359
 
                                if (recActive[REC_RPM]){
360
 
                                        rpmSpecNum->InsertNextValue(YADE_PTR_CAST<RpmState>(b->state)->specimenNumber);
361
 
                                        rpmSpecMass->InsertNextValue(YADE_PTR_CAST<RpmState>(b->state)->specimenMass);
362
 
                                        rpmSpecDiam->InsertNextValue(YADE_PTR_CAST<RpmState>(b->state)->specimenMaxDiam);
363
 
                                }
364
412
                                
 
413
                                if (recActive[REC_JCFPM]){
 
414
                                        damage->InsertNextValue(YADE_PTR_CAST<JCFpmState>(b->state)->tensBreak + YADE_PTR_CAST<JCFpmState>(b->state)->shearBreak);
 
415
//                                      damageRel->InsertNextValue(YADE_PTR_CAST<JCFpmState>(b->state)->tensBreakRel + YADE_PTR_CAST<JCFpmState>(b->state)->shearBreakRel);
 
416
                                }
 
417
 
365
418
                                if (recActive[REC_MATERIALID]) spheresMaterialId->InsertNextValue(b->material->id);
366
419
                                continue;
367
420
                        }
451
504
                }
452
505
        }
453
506
 
 
507
        if (recActive[REC_PERICELL]) {
 
508
                const Matrix3r& hSize = scene->cell->hSize;
 
509
                Vector3r v0 = hSize*Vector3r(0,0,1);
 
510
                Vector3r v1 = hSize*Vector3r(0,1,1);
 
511
                Vector3r v2 = hSize*Vector3r(1,1,1);
 
512
                Vector3r v3 = hSize*Vector3r(1,0,1);
 
513
                Vector3r v4 = hSize*Vector3r(0,0,0);
 
514
                Vector3r v5 = hSize*Vector3r(0,1,0);
 
515
                Vector3r v6 = hSize*Vector3r(1,1,0);
 
516
                Vector3r v7 = hSize*Vector3r(1,0,0);
 
517
                pericellPoints->InsertNextPoint(v0[0],v0[1],v0[2]);
 
518
                pericellPoints->InsertNextPoint(v1[0],v1[1],v1[2]);
 
519
                pericellPoints->InsertNextPoint(v2[0],v2[1],v2[2]);
 
520
                pericellPoints->InsertNextPoint(v3[0],v3[1],v3[2]);
 
521
                pericellPoints->InsertNextPoint(v4[0],v4[1],v4[2]);
 
522
                pericellPoints->InsertNextPoint(v5[0],v5[1],v5[2]);
 
523
                pericellPoints->InsertNextPoint(v6[0],v6[1],v6[2]);
 
524
                pericellPoints->InsertNextPoint(v7[0],v7[1],v7[2]);
 
525
                vtkSmartPointer<vtkHexahedron> h = vtkSmartPointer<vtkHexahedron>::New();
 
526
                vtkIdList* l = h->GetPointIds();
 
527
                for (int i=0; i<8; i++) {
 
528
                        l->SetId(i,i);
 
529
                }
 
530
                pericellHexa->InsertNextCell(h);
 
531
        }
 
532
 
454
533
        
455
534
        vtkSmartPointer<vtkDataCompressor> compressor;
456
535
        if(compress) compressor=vtkSmartPointer<vtkZLibDataCompressor>::New();
480
559
                        spheresUg->GetPointData()->AddArray(cpmDamage);
481
560
                        spheresUg->GetPointData()->AddArray(cpmStress);
482
561
                }
483
 
                if (recActive[REC_RPM]){
484
 
                        spheresUg->GetPointData()->AddArray(rpmSpecNum);
485
 
                        spheresUg->GetPointData()->AddArray(rpmSpecMass);
486
 
                        spheresUg->GetPointData()->AddArray(rpmSpecDiam);
487
 
                }
488
562
 
 
563
                if (recActive[REC_JCFPM]) {
 
564
                        spheresUg->GetPointData()->AddArray(damage);
 
565
                }
489
566
                if (recActive[REC_MATERIALID]) spheresUg->GetPointData()->AddArray(spheresMaterialId);
490
 
                
 
567
 
491
568
                #ifdef YADE_VTK_MULTIBLOCK
492
569
                if(!multiblock)
493
570
                #endif
555
632
                intrPd->SetLines(intrCells);
556
633
                intrPd->GetCellData()->AddArray(intrForceN);
557
634
                intrPd->GetCellData()->AddArray(intrAbsForceT);
 
635
                if (recActive[REC_JCFPM]) { 
 
636
                        intrPd->GetCellData()->AddArray(intrIsCohesive);
 
637
                        intrPd->GetCellData()->AddArray(intrIsOnJoint);
 
638
                }
558
639
                if (recActive[REC_WPM]){
559
640
                        intrPd->GetCellData()->AddArray(wpmNormalForce);
560
641
                        intrPd->GetCellData()->AddArray(wpmLimitFactor);
572
653
                        writer->Write();
573
654
                }
574
655
        }
 
656
        vtkSmartPointer<vtkUnstructuredGrid> pericellUg = vtkSmartPointer<vtkUnstructuredGrid>::New();
 
657
        if (recActive[REC_PERICELL]){
 
658
                pericellUg->SetPoints(pericellPoints);
 
659
                pericellUg->SetCells(12,pericellHexa);
 
660
                #ifdef YADE_VTK_MULTIBLOCK
 
661
                        if(!multiblock)
 
662
                #endif
 
663
                        {
 
664
                        vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
 
665
                        if(compress) writer->SetCompressor(compressor);
 
666
                        if(ascii) writer->SetDataModeToAscii();
 
667
                        string fn=fileName+"pericell."+lexical_cast<string>(scene->iter)+".vtu";
 
668
                        writer->SetFileName(fn.c_str());
 
669
                        writer->SetInput(pericellUg);
 
670
                        writer->Write();
 
671
                }
 
672
        }
 
673
 
 
674
        if (recActive[REC_CRACKS]) {
 
675
                std::ifstream file ("cracks.txt",std::ios::in);
 
676
                vtkSmartPointer<vtkUnstructuredGrid> crackUg = vtkSmartPointer<vtkUnstructuredGrid>::New();
 
677
                vtkSmartPointer<vtkUnstructuredGrid> crackUgNew = vtkSmartPointer<vtkUnstructuredGrid>::New();
 
678
                
 
679
                 if(file){
 
680
                         while ( !file.eof() ){
 
681
                                std::string line;
 
682
                                Real i,p0,p1,p2,t,s,n0,n1,n2;
 
683
                                while ( std::getline(file, line)/* writes into string "line", a line of file "file". To go along diff. lines*/ ) 
 
684
                                {
 
685
                                        file >> i >> p0 >> p1 >> p2 >> t >> s >> n0 >> n1 >> n2;
 
686
                                        vtkIdType pid[1];
 
687
                                        pid[0] = crackPos->InsertNextPoint(p0, p1, p2);
 
688
                                        crackCells->InsertNextCell(1,pid);
 
689
                                        crackType->InsertNextValue(t);
 
690
                                        crackSize->InsertNextValue(s);
 
691
                                        iter->InsertNextValue(i);
 
692
                                        float n[3] = { n0, n1, n2 };
 
693
                                        crackNorm->InsertNextTupleValue(n);
 
694
//                                      if (i > scene->iter - iterPeriod)
 
695
//                                      {
 
696
//                                        pid[0] = crackPosNew->InsertNextPoint(p0, p1, p2);
 
697
//                                        crackCellsNew->InsertNextCell(1,pid);
 
698
//                                        crackTypeNew->InsertNextValue(t);
 
699
//                                        crackSizeNew->InsertNextValue(s);
 
700
//                                        iterNew->InsertNextValue(i);
 
701
//                                        crackNormNew->InsertNextTupleValue(n);
 
702
//                                      }
 
703
                                          
 
704
                                }
 
705
                         }
 
706
                         file.close();
 
707
                } 
 
708
 
 
709
                crackUg->SetPoints(crackPos);
 
710
                crackUg->SetCells(VTK_VERTEX, crackCells);
 
711
                crackUg->GetPointData()->AddArray(iter);
 
712
                crackUg->GetPointData()->AddArray(crackType);
 
713
                crackUg->GetPointData()->AddArray(crackSize);
 
714
                crackUg->GetPointData()->AddArray(crackNorm); //orientation of 2D glyphs does not match this direction (some work to do in order to have the good orientation) 
 
715
                
 
716
                /*crackUgNew->SetPoints(crackPosNew);
 
717
                crackUgNew->SetCells(VTK_VERTEX, crackCellsNew);
 
718
                crackUgNew->GetPointData()->AddArray(iterNew);
 
719
                crackUgNew->GetPointData()->AddArray(crackTypeNew);
 
720
                crackUgNew->GetPointData()->AddArray(crackSizeNew);
 
721
                crackUgNew->GetPointData()->AddArray(crackNormNew); //same remark...*/
 
722
        
 
723
                vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
 
724
                if(compress) writer->SetCompressor(compressor);
 
725
                if(ascii) writer->SetDataModeToAscii();
 
726
                string fn=fileName+"cracks."+lexical_cast<string>(scene->iter)+".vtu";
 
727
                writer->SetFileName(fn.c_str());
 
728
                writer->SetInput(crackUg);
 
729
                writer->Write();
 
730
                
 
731
//              fn=fileName+"newcracks."+lexical_cast<string>(scene->iter)+".vtu";
 
732
//              writer->SetFileName(fn.c_str());
 
733
//              writer->SetInput(crackUgNew);
 
734
//              writer->Write();
 
735
        }
 
736
 
575
737
        #ifdef YADE_VTK_MULTIBLOCK
576
738
                if(multiblock){
577
739
                        vtkSmartPointer<vtkMultiBlockDataSet> multiblockDataset = vtkSmartPointer<vtkMultiBlockDataSet>::New();
579
741
                        if(recActive[REC_SPHERES]) multiblockDataset->SetBlock(i++,spheresUg);
580
742
                        if(recActive[REC_FACETS]) multiblockDataset->SetBlock(i++,facetsUg);
581
743
                        if(recActive[REC_INTR]) multiblockDataset->SetBlock(i++,intrPd);
 
744
                        if(recActive[REC_PERICELL]) multiblockDataset->SetBlock(i++,pericellUg);
582
745
                        vtkSmartPointer<vtkXMLMultiBlockDataWriter> writer = vtkSmartPointer<vtkXMLMultiBlockDataWriter>::New();
583
746
                        if(ascii) writer->SetDataModeToAscii();
584
747
                        string fn=fileName+lexical_cast<string>(scene->iter)+".vtm";