FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
IntegralHeart.hpp
1#define ENABLE_MEMCORE_GETTIME
2#include <memcore/Timer.hpp>
3
4#include "IntegralFace.hpp"
5
6#include <BaseSpace/FieldInterpolator.hpp>
7#include <eagle/PhysicalSpace.hpp>
8#include <eagle/STA.hpp>
9#include <ocean/shrimp/VEnum.hpp>
10#include <ocean/shrimp/PhysicalSpace.hpp>
11
12#include <fish/fiber/vector/Interpolate.hpp>
13#include <fish/fiber/vector/LinearIpol.hpp>
14#include <bone/FishField.hpp>
15#include <bone/FishSlice.hpp>
16#include <ocean/shrimp/VObjectStatus.hpp>
17#include <fish/fiber/baseop/LocalFromWorldPoint.hpp>
18#include <fish/fiber/baseop/ExpandBBox.hpp>
19#include <fish/fiber/baseop/CopySkeletons.hpp>
20//#include <fish/fiber/baseop/AMRFieldFinder.hpp>
21
22#include <ode/dop853def.hpp>
23#include <baseop/TangentialVectors.hpp>
24
25//#include <ocean/plankton/VTimer.hpp>
26#include <memcore/Timer.hpp>
27
28#include <grid/types/LineSet.hpp>
29#include <fish/fiber/baseop/RefineSurface.hpp>
30
31#ifdef USE_OPENMP
32#include <omp.h>
33#endif
34
35//#define VERBOSE
36#define PRT_TIME_ONLY
37#define TIMEIT
38
39
40namespace Fiber
41{
42 // convinience function, to be placed somewhere else
43 template<int N, typename T>
44 RefPtr<MemArray<N, T> > getMemArrayViaMBase( RefPtr<Field>& myField, RefPtr<FragmentID> FragID = MemCore::NullPtr() )
45 {
46 RefPtr<CreativeArrayBase> cBase = myField->getCreator();
47 if(!cBase)
48 {
49 puts("getMemArrayViaMBase() No cBase for FIELD found in field");fflush(stdout);
50 return MemCore::NullPtr();
51 }
52
53 RefPtr<MemBase> mBase = cBase->create();
54 if(!mBase)
55 {
56 puts("getMemArrayViaMBase() No mBase for FIELD found in field");fflush(stdout);
57 return MemCore::NullPtr();
58 }
59
61 ret = myField->getCreator(FragID)->create();
62 if(!ret)
63 {
64 mBase.speak("MBase Inforation ------>");
65 puts("getMemArrayViaMBase() ERROR retrieving matching field.");
66
67 return MemCore::NullPtr();
68 }
69
70 return ret;
71 }
72
73 template<typename T>
75 {
78
79 return DataArr->myChunk();
80 }
81}
82
83namespace FieldLines
84{
85typedef std::string FragmentID_t;
86
87// This class iterates over the input grid object and
88// maps Field with time value for time dependent fields.
89//template<typename FieldType, typename LineType>
90class GridIterator : public EvolutionIterator<Grid>
91 , public MemCore::ReferenceBase<GridIterator>
92{
94 std::string theFieldName;
95public:
96 MapFieldObject_t fieldObjectCollection;
97 std::map<double, double> timeDifferenceMap;
98 double t0, t1;
99
100 // Constructor
101 GridIterator(const string fieldName)
103 , theFieldName(fieldName)
104 , t0(0.0)
105 , t1(0.0)
106 {}
107
108 // Define the apply function here.
109 bool apply(double t, GridID&id, Grid&g)
110 {
111 t1 = t;
112 if(t1 != t0)
113 {
114 double stepTime = t1-t0;
115 timeDifferenceMap[t1] = timeDifferenceMap[t0] = stepTime;
116 }
117 else
118 timeDifferenceMap[t0] = 0.0;
119
120 t0 = t;
121
122 // Get the Field object with corresponding fieldName
123 RefPtr<Field> fieldObj = g(theFieldName);
124
125 if(!fieldObj)
126 {
127 printf("GridIterator::apply() Null to field retrieved. Abording at t=%f!", t);
128 return true;
129 }
130
131// assert(fieldObj);
132
133 fieldObjectCollection[t] = fieldObj;
134
135#ifdef VERBOSE
136 printf("GridIterator::apply() inserted %s st %.18f --> map size:%d\n", theFieldName.c_str(), t, int(fieldObjectCollection.size() ) );
137 fflush(stdout);
138#endif
139 return true;
140 }
141};
142
143
145{
146protected:
147 RefPtr<Grid> myGrid;
149
150 unsigned size;
151
152// RefPtr<MemArray<1, Eagle::point3> > LocalPositions;
153// RefPtr<MemArray<1, std::string> > FragmentNames;
154public:
156 : myGrid(myGridP)
157 , size(0)
158 {
159 RefPtr<Field> PosField = myGrid->getCartesianPositions();
160
161 if( !PosField )
162 puts("FieldCollectionDataBase1D::FieldCollectionDataBase1D() ERROR No Field in Grid");
163 else
164 {
166
167 if( Positions )
168 size = Positions->Size()[0];
169 }
170 }
171
172};
173
174template <class FieldType, typename LineType>
175struct FieldCollection : public MemCore::ReferenceBase<FieldCollection<FieldType,LineType> >
176{
179 {}
180
181 unsigned getVertexSize()
182 {
183 puts("FieldCollection::getVertexSize() not implemented, returning ZERO");
184 return 0;
185 }
186
187 unsigned getDataSize()
188 {
189 puts("FieldCollection::getDataSize() not implemented, returning ZERO");
190 return 0;
191 }
192};
193
195{
196 RefPtr<LocalFromWorldPoint> LocalPointFinder;
200 double step_size;
201 double nextTime;
202 unsigned long stepNr;
203
206 const double step_sizeP)
207 : LocalPointFinder(LocalPointFinderP)
209 , BB(BBP)
210 , GI(GridIteratorP)
211 , step_size(step_sizeP)
212 , nextTime(0.0)
213 , stepNr(0)
214 {}
215
217 {
218#ifdef VERBOSE
219 puts("~AtomicDataBase()");fflush(stdout);
220 LocalPointFinder.speak("--------------------------------------------------------------~AtomicDataBase() LocalPointFinder"); fflush(stdout);
221 BB.speak("--------------------------------------------------------------~AtomicDataBase() BB"); fflush(stdout);
222 GI.speak("--------------------------------------------------------------~AtomicDataBase() GI"); fflush(stdout);
223#endif
224 }
225};
226
227// type trait for atomic integration requires Euler and Dop853 functions
228// the interpolation type is defined at compile time via the last template paramter.
229template<typename FieldType, typename LineType, int InterpolType>
231{
233public:
234
235 virtual ~AtomicIntegrator()
236 {
237#ifdef VERBOSE
238 puts("~AtomicIntegrator() base");fflush(stdout);
239#endif
240 }
241
242 unsigned long nextStartIndexPerCoarseCall( unsigned long start, unsigned long size )
243 {
244 puts("FieldLines::AtomicIntegrator<FieldType>.nextStartIndexPerCoarseCall() ERROR: Unsupported type Field/Line Type doing nothing!");fflush(stdout);
245 return 0;
246 }
247
248 // does the local data extraction from using the positions field of the front to comput local coords, fragmentIds
249 // and interpolated field data.
251 const unsigned index, const double time )
252 {
253 puts("FieldLines::AtomicIntegrator<FieldType>.extractLocalData() ERROR: Unsupported type Field/Line Type doing nothing!");fflush(stdout);
254 return true;
255 }
256
260 unsigned index,
262 double time,
263 unsigned integration_width)
264 {
265 puts("FieldLines::AtomicIntegrator<FieldType>.doEuler (Fronts) () ERROR: Unsupported type Field/Line Type doing nothing!");fflush(stdout);
266 return false;
267 }
268
270 unsigned index,
272 double time,
273 unsigned integration_width )
274 {
275 puts("FieldLines::AtomicIntegrator<FieldType>.doDop853() ERROR: Unsupported type FieldType doing nothing!");fflush(stdout);
276 return false;
277 }
278
279 bool initDop853( const int number_of_lines )
280 {
281 puts("FieldLines::AtomicIntegrator<FieldType>.initDop853() ERROR: Unsupported type FieldType doing nothing!");fflush(stdout);
282 return false;
283 }
284
285 double getNextTime()
286 {
287 return 0.0;
288 }
289};
290
291
292template<class FieldType, typename LineType>
293struct GridOperatorData : public MemCore::ReferenceBase<GridOperatorData<FieldType,LineType> >
294{
297 {}
298
299};
300
301template <class FieldType, typename LineType>
303{
304 RefPtr<Bundle>& myBundle;
306
307public:
308// GridOperator( RefPtr<Bundle> myBundleP = MemCore::NullPtr() )
309// :myBundle( myBundleP )
310// {}
311
313 :myBundle( myBundleP )
314 ,myData( myDataP )
315 {}
316
317 RefPtr<Grid> getPreparedGrid( const RefPtr<Grid>& EmitterGrid, unsigned long steps_estimate = 500 )
318 {
319 puts("GridOperator::getpreparedGrid() WARNING: Using default base implementation, returning new Grid");
320 return myBundle->newGrid();
321 }
322
323 RefPtr<Grid> advanceGrid(const RefPtr<Grid>& gridP )
324 {
325 puts("GridOperator::advanceGrid() WARNING: Using default implementation, returning new Grid");
326 return myBundle->newGrid();
327 }
328
329 RefPtr<Grid> refineGrid(const RefPtr<Grid>& gridP )
330 {
331 puts("GridOperator::advanceGrid() WARNING: Using default implementation, returning new Grid");
332 return gridP;
333 }
334
335 void storeGrid( const std::string& grid_name, const RefPtr<Grid>& gridP, double time )
336 {
337 puts("GridOperator::storeGrid() WARNING: Using default implementation, doing Nothing");
338 }
339
340 void finalizeGrid( const std::string& grid_name, const RefPtr<Grid>& gridP, double slice )
341 {
342 puts("GridOperator::finalizeGrid() WARNING: Using default implementation, doing Nothing");
343 }
344
345 unsigned getIntegrationSize( const RefPtr<Grid>& gridP )
346 {
347 puts("GridOperator::getIntegrationSize() WARNING: Using default implementation, returning ZERO");
348 return 0;
349 }
350
351 RefPtr<Bundle> getBundle()
352 {
353 return myBundle;
354 }
355};
356
357
358
359template <class FieldType, typename LineType, int InterpolType>
361{
363
365
366 bool dop;
367 size_t nPoints;
368 double line_length;
369 double start_time;
370 double time;
371 int number_lines;
372
373public:
376 const double step_sizeP, const bool dopP, const size_t nPointsP,
377 const double line_lengthP, const double start_timeP )
379 , dop(dopP)
380 , nPoints(nPointsP)
381 , line_length(line_lengthP)
382 , start_time(start_timeP)
383 , time(start_timeP)
384 {}
385
386 virtual ~CoarseIntegrator()
387 {
388#ifdef VERBOSE
389 puts("~FronAdvancer()");fflush(stdout);
390#endif
391 }
392
393// LineIntegrator::LineIntegrator(){}
394
395
396 size_t getNPoints() { return nPoints;}
397
399 double&time, unsigned long&start, unsigned long&size)
400 {
401// puts("CoarseIntegrator::advance() enter" );fflush(stdout);
403// puts("CoarseIntegrator::advance() 1" );fflush(stdout);
405// puts("CoarseIntegrator::advance() 2" );fflush(stdout);
406
407 unsigned end_counter = 0;
408
409 if(dop)
410 AI.initDop853( size );
411
412 //printf("CoarseIntegrator::Time at the start of advnace = %.18f\n", time);
413 //printf("About to get into Euler...start = %d, size = %d\n", int(start), int(size) );
414
415 // add a omp pragma here maybe
416// #ifdef USE_OPENMP
417
418// #ifdef VERBOSE
419
420// const int max_threads_possible = omp_get_max_threads();
421// cout << "advance() using threads per front: " << max_threads_possible << endl;
422
423// exit(0);
424
425// #endif
426
427// #pragma omp parallel
428// {
429
430// #pragma omp for schedule(dynamic, 10)
431// #endif
432 for(unsigned p = start; p < start + size; p++)
433 {
434#ifdef VERBOSE
435 //printf("\n WORKING ON LINE %d out of %d\n", p, Lines.size() );
436// VActionNotifier::ProgressInfo("Working on line " + String(int(p)) + " out of " + String(int(size)) );
437 printf("Working on point %d, about to get into Euler...start = %d, size = %d\n", p, int(start), int(size));
438#endif
439
440 bool test;
441
442 // could this condition also be pulled out to one condition in the update, like the integration type?
443 if( !dop )
444 test = AI.doEuler( CurrentFields, p, NewFields, time, size );
445 else
446 // test = AI.doDop853( CurrentFields, p, NewFields, time, size );
447
448
449 if( test == false )
450 end_counter++;
451 else
452 nPoints++;
453 }
454
455// #ifdef USE_OPENMP
456// } // omp parallel
457// #endif
458
459 // change the time value here ...MAY BE!!!
460 time = AI.getNextTime();
461
462#ifdef VERBOSE
463 printf("CoarseIntegrator::Time at the end of advance = %.18f\n", time);
464#endif
465 // change the start index in the needs of the Atomic Integrator
466 start = AI.nextStartIndexPerCoarseCall( start, size );
467
468// VActionNotifier::ProgressInfo("Integration of " + String(int(size)) + " lines done." );
469
470// printf("end_counter %d, Lines.size() %d\n", end_counter, Lines.size() );
471
472// bool check = ( end_counter == size ) ? true : false;
473
474// printf("CoarseIntegrator::advance() exit, check: %d\n", check);fflush(stdout);
475
476 return true;
477 }
478
479 // should be implementable by filling the data arrays up to the size of the vertices
480 bool extractLocalGridData( RefPtr<Grid > & CurrentGrid, double time )
481 {
482#ifdef VERBOSE
483 puts("CoarseIntegrator::extractLocalGridData() enter");fflush(stdout);
484#endif
486
487#ifdef VERBOSE
488 puts("CoarseIntegrator::extractLocalGridData() 1");fflush(stdout);
489#endif
490
491 bool check = true;
492
493 for( unsigned p = CurrentFields.getDataSize(); p < CurrentFields.getVertexSize(); p++ )
494 {
495 check = check && AI.extractLocalData( CurrentFields, p, time );
496 }
497
498#ifdef VERBOSE
499 printf("CoarseIntegrator::extractLocalGridData() exit, check: %d\n", check);fflush(stdout);
500#endif
501
502 return check;
503 }
504
505};
506
507
508// type trait to convert the integration line type to a string used for naming in the fiber bundle
509// must be provided in the specializations
510template<typename FieldType, typename LineType>
512{
513 string name() { return "Unknown"; }
514};
515
516
517
518template <typename FieldType, typename LineType>
520{
521public:
522enum { NumberOfInputFields = 1 };
525
532
533 struct FieldState : State
534 {
535 WeakPtr<GridIterator> flowIterator;
536 double time;
537
538 FieldState()
539 : time(0.0)
540 {}
541 };
542
543 RefPtr<State> newState() const override
544 {
545 return new FieldState();
546 }
547
548
549 IntegralHeart(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
550 : VObject(name, p, VP)
551 , Fish<Field>("inputfield")
552 , IntegralFace(name, p, VP)
553 {}
554
555 typedef typename FieldType::Chart_t Chart_t;
556 typedef typename Coordinates<Chart_t>::point point;
557 typedef typename Coordinates<Chart_t>::vector tvector4;
558
559 bool update(VRequest&R, double precision) override;
560
561// experimental AMR code disabled for now, WB 19.JUL.2010
562#if 0
568 struct AMRLevelExtractor : public LevelIterator
569 {
570 double currenttime;
572
573 // store available refinement levels of Field in map (at current time)
574// std::map<unsigned, MemCore::RefPtr<Fiber::Field> > collect;
576
577 AMRLevelExtractor(std::string& fieldnameP, double currenttimeP, std::map<double, std::map<unsigned, RefPtr<Fiber::Field> > >& collectP)
580 , collect(collectP)
581 {}
582
583 // collect time, levelnr and field in map
585 double time, int Level,
587 const RefPtr<ValuePool>&Context) override
588 {
589 RefPtr<Field> Coords = CartesianLevelRep->Positions();
590 RefPtr<Field> DataField = (*CartesianLevelRep)(AMRfieldname);
591
592 collect.insert( pair<unsigned, RefPtr<Fiber::Field> >( Level, DataField ) );
593
594 return true;
595 }
596
597 };
598
599
600 class AMRFieldFinder
601 {
604 std::string fieldname;
605
606 // iterate over grids in time
607 struct AMRGridEvolution : EvolutionIterator<Fiber::Grid>
608 {
609 std::string fieldname;
610// std::map<double, std::map<unsigned, RefPtr<Fiber::Field> > > myAMRField;
611
612 AMRGridEvolution( std::string& fieldnameP) //, std::map<double, std::map<unsigned, RefPtr<Fiber::Field> > >&myAMRFieldP )
613 : fieldname(fieldnameP)
614// , myAMRField(myAMRFieldP)
615 {};
616
617 // first collect level data in map by using the level iterator. then store available field ptr and level nr
618 // in time-map of Field finder
619 bool apply (double t, GridID&id, Grid&g) override
620 {
622
623 AMRLevelExtractor refIt(fieldname, t, collect);
624
625 g.iterate( refIt );
626
627 AMRField.insert( pair<double, RefPtr<Field> >(t, collect) );
628
629 return true;
630 }
631 };
632
633
634
635 public:
636
637 AMRFieldFinder(const string& fieldnameP)
638 : fieldname(fieldnameP)
639 {}
640
641 // collect all time and field data into a the map structure
642 void precompute()
643 {
644 }
645
646 /* also provide a function to find field on demand without pre-iterations
647 pre evaluation might be not too efficient in huge time dependent data sets
648 RefPtr<Fiber::Field> getFinestField(double time)
649 {
650 return MemCore::NullPtr();
651 }
652 */
653
654 };
655#endif
656
657
658 static string createChildname(const string&inputfield)
659 {
661 return tmp.name() +"(" + inputfield + ")";
662 }
663
664 // print progress of iteration as status and stdout
665 void printProgress( unsigned long&old_nPoints, const unsigned long nPoints, const unsigned long nPointsEst, VRequest&Context)
666 {
667 if( old_nPoints + 100 < nPoints )
668 {
669 old_nPoints = nPoints;
670 char buf[64];
671 float percent = double(nPoints / nPointsEst * 100);
672 sprintf(buf, "Integrating %.1f %% #%d", percent, int(nPoints));
673// VActionNotifier::ProgressInfo (string(buf));
674 printf("IntegralHeart::printProgress(): %s\n", buf);fflush(stdout);
676 }
677
678 }
679
680
681 // Function to simplify main iteration loop in update.
682 template<class IntegratorType>
683 int doMainLoop(IntegratorType&IntT,
684 RefPtr<Grid>& StartGrid,
686 const string& grid_name,
688 double time,
689 unsigned long max_steps, int nPointsEst, size_t nPoints, VRequest&Context)
690 {
691// puts("IntegralHeart::doMainLoop() enter");fflush(stdout);
692
693 unsigned long step_counter = 0;
694 unsigned long integration_width = GridOperator.getIntegrationSize( StartGrid );
695 unsigned long start_count = 0;
696 bool hasfinished = false;
697 unsigned long old_nPoints = 0;
698
699 RefPtr<Grid> CurrentGrid = StartGrid;
701
702 VActionNotifier::Progress viP( "Integrating...", max_steps );
703 while( hasfinished == false && step_counter < max_steps && viP.proceed( step_counter ) )
704 {
705 printProgress(old_nPoints, nPoints, nPointsEst, Context );
706#ifdef VERBOSE
707 puts("fill local data and store grid in case of being the initial front");
708#endif
709 if( step_counter == 0)
710 {
711 printf("Emitter Grid:: Time at which emitter grid is stored %.18f\n", time);
713 !IntT.extractLocalGridData( CurrentGrid, time );
714#ifdef VERBOSE
715// DebugGridContent(CurrentGrid, "<<<..Initial Iteration...>>>");
716#endif
717 GridOperator.storeGrid( grid_name, CurrentGrid, time );
718 }
719#ifdef VERBOSE
720 puts("maybe create a copy for the new grid");
721#endif
722 NewGrid = GridOperator.advanceGrid( CurrentGrid );
723
724#ifdef VERBOSE
725 printf("<<<... After NewGrid=GridOperator.advanceGrid(CurrentGrid)...>>>\n");fflush(stdout);
726// DebugGridContent(CurrentGrid, " --- CurrentGrid");
727// DebugGridContent(NewGrid, " --- NewGrid");
728 puts("do one integration step of the whole front");
729#endif
730 integration_width = GridOperator.getIntegrationSize(CurrentGrid);
732 !IntT.advance( CurrentGrid, NewGrid, time, start_count, integration_width );
733#ifdef VERBOSE
734// DebugGridContent(NewGrid, "<<<...IntT.advance(CurrentGrid, NewGrid, time, start_count, integration_width)...>>>");
735 puts("refine the grid");
736#endif
737#ifdef PRT_TIME_ONLY
738 printf("<<<<<<<<<<<< timestep = %.8f >>>>>>>>>>>>\n", time); fflush(stdout);
739#endif
740 NewGrid = GridOperator.refineGrid( NewGrid );
741
742#ifdef VERBOSE
743 puts("fill local data in front");
744#endif
746 !IntT.extractLocalGridData( NewGrid, time );
747#ifdef VERBOSE
748// DebugGridContent(NewGrid, "<<<...After new positions/velocities interpolations...>>>");
749 puts("store grid");
750#endif
751 GridOperator.storeGrid( grid_name, NewGrid, time );
752
754
755 step_counter++;
756#ifdef VERBOSE
757 printf("hasfinished: %d, step_counter: %ld, max_steps: %ld \n\n", hasfinished, step_counter, max_steps); fflush(stdout);
758#endif
759 }
760
761#ifdef VERBOSE
762 puts("do a final operation on the grid");
763#endif
764 GridOperator.finalizeGrid( grid_name, NewGrid, time );
765
766#ifdef VERBOSE
767 puts("exit main loop");
768#endif
769 return IntT.getNPoints();
770 }
771
773 {
774 return NullPtr();
775 }
776
777};
778
779template<typename FieldType, typename LineType>
780bool IntegralHeart<FieldType,LineType>::update(VRequest&Context, double precision)
781{
782double sec = 0.0;
784
785 printf("IntegralLines::update() -->%s<--: enter\n", Name().c_str() );fflush(stdout);
786
787// 1. Get input field information
788//
789 puts("IntegralLines::update() 1. Get input field information");fflush(stdout);
790FieldSelector FieldSelection = getFieldSelector(Context);
791RefPtr<Field> InputToIntegrateField = FieldSelection.getField();
792
793 if(!FieldSelection.theSourceBundle) { return errorMsg(Context, "No bundle found in integrate field"); }
794 if(!InputToIntegrateField) { return errorMsg(Context, "No integratable field in input bundle"); }
795
796double time = FieldSelection.getTime();
797string fieldName = FieldSelection.getFieldName();
798
799// Get the State Variable
800RefPtr<FieldState> state = newState();
801
802
803// 2. Get emitter info
804//
805GridSelector EmitterGS;
806FieldSelector EmitterFS;
807 StartGrid << Context >> EmitterGS;
808 StartField << Context >> EmitterFS;
809
810// extract the emitter grid from field or gridselector, getEmitterGrid is a function defined in IntegralFace.cpp
811EmitterFieldData EFD( EmitterGS, EmitterFS, time );
812RefPtr<Grid> EmitterGrid = getEmitterGrid( Context, EFD );
813
814//
815// 3. Construct name for the output grid (the integral lines) and check if it already exists. And if so, if not the
816// input is newer, such that it would require re-creation.
817//
818// create a gridname dependent on the grid of the data field and the own module name
819string grid_name = FieldSelection.Gridname() + "_" + Name();
820
821GridSelector GS;
823
824// check if a recomputation is necessary, needUpdate is a function defined in IntegralFace.cpp
825UpdateCheckData UCD( EmitterGrid, FieldSelection, GS, InputToIntegrateField, time, grid_name);
826 if( !needUpdate( Context, UCD ) )
827 {
828 puts("IntegralLines::update() 3.5 no update needed");
829 return true;
830 }
831//
832// 4. Make sure we have some seed points
833//
834// puts("IntegralLines::update() 4. Make sure we have seeding points");fflush(stdout);
835
836// in case no emitter field or grid is connected, create initial seed points along the diagonal
837// of the bounding box of the data fiel
838RefPtr<BoundingBox> ToIntegratefieldBBox = getBoundingBox( *FieldSelection.getGrid() );
839 if (!ToIntegratefieldBBox) return setStatusError(Context, "No bounding box available.\n");
840
841AutoEmitterData AED( EmitterGrid, ToIntegratefieldBBox, 23, FieldSelection.theSourceBundle);
842 setDefaultEmissionPoints(Context, AED); // defined in IntegralFace.cpp
843
844//
845// 5. Prepare data structs for integration
846//
847//
848 puts("IntegralLines::update() 5. Prepare data");fflush(stdout);
849BundlePtr bundlePtr = FieldSelection.BundleSource(); // Was named as outBPtr. Modified by Bidur
851
852 assert( FieldSelection.getGrid() );
853
854 setStatusInfo(Context, "Setting up index search");
855
856double UnimapperScale = 1.0;
858
859Eagle::point3 tree_query_scale;
861
863 LocalPointFinder = new LocalFromWorldPoint(*currentSlice.getSlice(), FieldSelection.getGrid(),
864 FieldSelection.getGridname(),
865 //FieldSelection.getGrid()->getCartesianPositions(),
866 UnimapperScale, 0.1, tvector( tree_query_scale ) );
867
868double step_size;
869double min_line_length = 0.0;
870double max_steps = 0.0;
871
872 MinLineLength << Context >> min_line_length;
874 StepSize << Context >> step_size;
875
876 step_size *= ToIntegratefieldBBox->radius();
877 step_size /= 33.0;
878
879 if( max_steps < 2) max_steps = 2;
880 if( min_line_length < 0.0) min_line_length = 0.0;
881
882unsigned long max_steps_l = static_cast<unsigned long>(std::floor(max_steps));
883
884//Enum AddData, AddMagnitude;
885// IncludeData << Context >> AddData;
886// IncludeMagnitude << Context >> AddMagnitude;
887
888 cout << "size: " << EFD.Size << ", seeds: " << AED.nSeeds << endl;
889
890unsigned nEmPoints = (EFD.Size==0) ? AED.nSeeds:EFD.Size; // if efd.size is 0 used autocreated seeds instead
891unsigned nPointsEst = nEmPoints * int(max_steps);
892
893 printf("IntegralHeart::update() nEmPoints: %d, nPointsEst: %d\n",nEmPoints, nPointsEst);
894
898
899size_t nPoints = 0;
900
902
903 if(!myGridSetupData)
904 {
905 puts("IntegralHeart::update(): no grid operator data created!");
906// return setStatusError(Context, "no grid operator data created");
907 // in case of Frontstreamlines this is yet null and should be ok
908 }
909
912
913// TODO make sure emitter grid is there. overrides current version of emitter-grid-point-creation!
914RefPtr<Grid> IntegrationGeometry = integrationGridOperator.getPreparedGrid( AED.EmitterGrid,
915 static_cast<unsigned long>(max_steps) );
916
917//
918// 6. Do the actual integration
919//
920 puts("IntegralLines::update() 6. Do the actual Integration");fflush(stdout);
921 setStatusInfo(Context, "Integrating ...");
922
923// Define new GridIterator and assign it the Iterator from State variable
924RefPtr<GridIterator> flowIterator = state->flowIterator;
925
926int totalSteps;
927double gridTime;
928
929 // Declare and initialize Grid Iterator
930 flowIterator = new GridIterator( fieldName );
931 gridTime = time;
932
933 // This iterates over Grid objects of input Bundle.
934 // FlowIterator then maps the time of Grid with the Field(vector field) object of Grid.
935 totalSteps = bundlePtr->iterateForward(gridTime, FieldSelection.Gridname(), *flowIterator, false);
936 printf("\nTotal time slices = %d and Time value = %f %f\n", totalSteps, time, gridTime);
937
938
941//Enum Dop;
942// UseDop853 << Context >> Dop;
943
944Options options;
946
947 puts("2");
948
950
951 if( Interpol("linear") )
952 {
953
954 AdvancerLinear MyAdvancerLinear( FieldSelection, LocalPointFinder, ToIntegratefieldBBox, flowIterator,
955 step_size, options("dop853"), nPoints, min_line_length, time );
956
958 FieldSelection, time, max_steps_l, nPointsEst, nPoints, Context);
959
960 nPoints = MyAdvancerLinear.getNPoints();
961 }
962 else if( Interpol("cubic") )
963 {
964 AdvancerCubic MyAdvancerCubic( FieldSelection, LocalPointFinder, ToIntegratefieldBBox, flowIterator,
965 step_size, options("dop853"), nPoints, min_line_length, time );
966
968 FieldSelection, time, max_steps_l, nPointsEst, nPoints, Context);
969 nPoints = MyAdvancerCubic.getNPoints();
970 }
971 else
972 {
973 AdvancerAnalytic MyAdvancerAnalytic( FieldSelection, LocalPointFinder, ToIntegratefieldBBox, flowIterator,
974 step_size, options("dop853"), nPoints, min_line_length, time );
975
977 FieldSelection, time, max_steps_l, nPointsEst, nPoints, Context );
978 nPoints = MyAdvancerAnalytic.getNPoints();
979 }
980
981#ifdef VERBOSE
982 puts("3");fflush(stdout);
983#endif
984
985 double overall_int_time = Tim_update.secs() - sec;
986
987// ________________________________________________printTime("IntegralLines::update(): Compute Time:", Tim_update.secs() - sec);
988
989 printf("IntegralLines::update(): ComputeTime: %f\n",overall_int_time );
990 printf("IntegralLines::update(): Time per integration %d points: %f\n", int(nPointsEst), overall_int_time / nPointsEst );
991
992 CurviCellsPerUniCell << Context << LocalPointFinder->MaxListSize;
993
994#ifdef VERBOSE
995 puts("4");fflush(stdout);
996#endif
997
998 {
999 GridSelector GS( grid_name, integrationGridOperator.getBundle() );
1000 myIntegralLines << Context << GS;
1001
1002 printf("time: %f\n", time);
1003
1004/*
1005 Grid& myGrid = *GS(time);
1006
1007 puts("5");fflush(stdout);
1008
1009 RefPtr<Field> myField = myGrid.CartesianPositions();
1010
1011 if(!myField)
1012 {
1013 puts("No FIELD!"); return true;
1014 }
1015
1016 RefPtr<MemArray<1, Eagle::point3> > myArr = getMemArrayViaMBase<1, Eagle::point3>( myField );
1017 if(!myArr)
1018 {
1019 puts("No ARR!"); return true;
1020 }
1021
1022 MultiArray<1, Eagle::point3>&multArr = *myArr;
1023
1024
1025
1026 MultiIndex<1> mx = multArr.Size();
1027 printf("MultiArray: Size(): %ld\n", mx[0] );
1028
1029 MultiIndex<1> mi;
1030
1031 unsigned long hyperlen = multArr.getLength();
1032 printf("MultiArray: hyper size: %ld\n", hyperlen );
1033
1034 unsigned long hypercount = multArr.maxcount();
1035 printf("MultiArray: hyper size: %ld\n", hyperlen );
1036 printf("MultiArray: hyper count: %ld\n", hypercount );
1037
1038 printf("MultiArray: multidim size: %ld\n", mx[0]);
1039
1040 for(unsigned i = 0; i < mx[0]; i++)
1041 {
1042 mi[0] = i;
1043 std::cout << multArr[mi] << endl;
1044 }
1045 printf("ArraySize: %ld\n", mx[0]);
1046
1047 RefPtr<Chunk<Eagle::point3> >PositionsChunk = getChunkOfField<Eagle::point3>( myField );
1048 if(!PositionsChunk)
1049 {
1050 puts("No CHUNK!"); return true;
1051 }
1052
1053 for(unsigned i = 0; i < PositionsChunk->size(); i++)
1054 std::cout << (*PositionsChunk)[i] << endl;
1055*/
1056 }
1057
1058 infoMsg(Context, "Done, output at: " + grid_name);fflush(stdout);
1059
1060// printf("ComputMultipleStreamLines::update() Written into Bundle, setPersitentData and touched Spacetimeslot()\n");
1061 VActionNotifier::StatusInfo( "Integration computation complete");
1062
1063
1064 return true;
1065}
1066
1067}
valarray< size_t > size() const
_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply(_Tp __func(_Tp)) const
basic_string< char > string
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
ostream cout
void insert(_InputIterator __first, _InputIterator __last)
size_type size() const noexcept
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
An abstract selection of fields, that is given by names of fields and possible types for each field.
Definition FieldSelection.hpp:23
string getFieldName() const
Retrieve the name of a unique field, if only one is stored here.
Definition FieldSelection.cpp:68
An internal class that stores a couple of textual names.
Definition FieldSelector.hpp:18
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
A grid identifier.
Definition GridID.hpp:29
Iterator callback object for iteration within time slices.
Definition Slice.hpp:16
Context information to select a grid from within a bundle.
Definition GridSelector.hpp:26
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
Use this class to compute a local cell index and fragment ID (if neccessary) of any coordinate field ...
Definition LocalFromWorldPoint.hpp:71
Definition IntegralHeart.hpp:231
bool doEuler(FieldCollection< FieldType, LineType > &lastFront, unsigned index, FieldCollection< FieldType, LineType > &newFront, double time, unsigned integration_width)
Do a one step integration.
Definition IntegralHeart.hpp:259
Definition IntegralHeart.hpp:361
Definition IntegralHeart.hpp:145
Definition IntegralHeart.hpp:92
Definition IntegralHeart.hpp:303
Definition IntegralHeart.hpp:520
Definition IntegralFace.hpp:37
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
std::nullptr_t NullPtr
Definition IndexListViaSelectionString.hpp:30
Definition IntegralHeart.hpp:195
Definition IntegralHeart.hpp:176
Definition IntegralHeart.hpp:294
Definition IntegralHeart.hpp:534
Definition IntegralHeart.hpp:512
bool setStatusInfo(const RefPtr< ValuePool > &Context, const string &what) const