1+ #include < lsToDiskMesh.hpp>
2+ #include < process/psTranslationField.hpp>
3+ #include < psElementToPointData.hpp>
4+ #include < rayTraceDisk.hpp>
5+ #include < rayTraceTriangle.hpp>
6+
7+ #include " Benchmark.hpp"
8+
9+ int main () {
10+ using NumericType = float ;
11+ constexpr int D = DIM ;
12+
13+ const std::vector<int > numThreadsList = {1 , 2 , 4 , 8 , 16 };
14+ std::string fluxLabel = particleType == 0 ? " flux" : " ionFlux" ;
15+ auto particle = makeCPUParticle<NumericType, D>();
16+
17+ if constexpr (runDisk) { // Disk
18+ std::ofstream file (std::string (" CPU_Scaling_Disk_" ) +
19+ std::to_string (particleType) + " .txt" );
20+ file << " Meshing;Tracing;Postprocessing;RayTraced;NumThreads\n " ;
21+
22+ viennaray::TraceDisk<NumericType, D> tracer;
23+ tracer.setNumberOfRaysPerPoint (raysPerPoint);
24+ if (FIXED_RAYS )
25+ tracer.setNumberOfRaysFixed (numRays);
26+ tracer.setUseRandomSeeds (false );
27+ tracer.setParticleType (particle);
28+
29+ std::cout << " Starting Disk Benchmark\n " ;
30+
31+ for (int i = 0 ; i < numThreadsList.size (); i++) {
32+ std::cout << " T: " << numThreadsList[i] << " \n " ;
33+ omp_set_num_threads (numThreadsList[i]);
34+ auto domain = MAKE_GEO <NumericType>();
35+
36+ auto diskMesh = viennals::Mesh<NumericType>::New ();
37+ auto translator = SmartPointer<TranslatorType>::New ();
38+ viennals::ToDiskMesh<NumericType, D> mesher (domain->getSurface (),
39+ diskMesh);
40+ mesher.setTranslator (translator);
41+
42+ for (int j = 0 ; j < numRuns; j++) {
43+ std::cout << " Process Step: " << j + 1 << " \n " ;
44+
45+ Timer timer;
46+
47+ // MESHING
48+ timer.start ();
49+ mesher.apply ();
50+ const auto &materialIds = *diskMesh->getMaterialIds ();
51+ const auto &normals = *diskMesh->getNormals ();
52+ tracer.setGeometry (diskMesh->nodes , normals, domain->getGridDelta ());
53+ tracer.setMaterialIds (materialIds);
54+ timer.finish ();
55+ file << timer.currentDuration << " ;" ;
56+
57+ // TRACING
58+ timer.start ();
59+ tracer.apply ();
60+ timer.finish ();
61+ file << timer.currentDuration << " ;" ;
62+
63+ // POSTPROCESSING
64+ timer.start ();
65+ auto flux = std::move (*tracer.getLocalData ().getScalarData (fluxLabel));
66+ tracer.normalizeFlux (flux);
67+ int smoothingNeighbors = 1 ;
68+ tracer.smoothFlux (flux, smoothingNeighbors);
69+ timer.finish ();
70+ file << timer.currentDuration << " ;" ;
71+ file << tracer.getRayTraceInfo ().totalRaysTraced << " ;" ;
72+ file << numThreadsList[i] << " \n " ;
73+ }
74+ }
75+
76+ file.close ();
77+ }
78+
79+ if constexpr (runTriangle) { // Triangle
80+ std::ofstream file (std::string (" CPU_Scaling_Triangle_" ) +
81+ std::to_string (particleType) + " .txt" );
82+ file << " Meshing;Tracing;Postprocessing;RayTraced;NumThreads\n " ;
83+
84+ std::cout << " Starting Triangle Benchmark\n " ;
85+
86+ viennaray::TraceTriangle<NumericType, D> tracer;
87+ tracer.setNumberOfRaysPerPoint (raysPerPoint);
88+ if (FIXED_RAYS )
89+ tracer.setNumberOfRaysFixed (numRays);
90+ tracer.setUseRandomSeeds (false );
91+ tracer.setParticleType (particle);
92+
93+ const auto &dataLabels = particle->getLocalDataLabels ();
94+
95+ for (int i = 0 ; i < numThreadsList.size (); i++) {
96+ std::cout << " T: " << numThreadsList[i] << " \n " ;
97+ omp_set_num_threads (numThreadsList[i]);
98+ auto domain = MAKE_GEO <NumericType>();
99+
100+ auto diskMesh = viennals::Mesh<NumericType>::New ();
101+ auto translator = SmartPointer<TranslatorType>::New ();
102+ viennals::ToDiskMesh<NumericType, D> diskMesher (domain->getSurface (),
103+ diskMesh);
104+ diskMesher.setTranslator (translator);
105+
106+ auto elementKdTree =
107+ SmartPointer<KDTree<NumericType, Vec3D<NumericType>>>::New ();
108+ auto surfMesh = viennals::Mesh<NumericType>::New ();
109+
110+ auto velocityField =
111+ SmartPointer<DefaultVelocityField<NumericType, D>>::New ();
112+ auto translationField =
113+ SmartPointer<TranslationField<NumericType, D>>::New (
114+ velocityField, domain->getMaterialMap (), 1 );
115+ translationField->setTranslator (translator);
116+
117+ for (int j = 0 ; j < numRuns; j++) {
118+ std::cout << " Process Step: " << j + 1 << " \n " ;
119+
120+ Timer timer;
121+
122+ // MESHING
123+ timer.start ();
124+ diskMesher.apply ();
125+ translationField->buildKdTree (diskMesh->nodes );
126+ setupTriangleGeometry<NumericType, D, decltype (tracer)>(
127+ domain, surfMesh, elementKdTree, tracer);
128+ timer.finish ();
129+ file << timer.currentDuration << " ;" ;
130+
131+ // TRACING
132+ timer.start ();
133+ tracer.apply ();
134+ timer.finish ();
135+ file << timer.currentDuration << " ;" ;
136+
137+ // POSTPROCESSING
138+ timer.start ();
139+ auto pointData = PointData<NumericType>::New ();
140+ auto fluxResult =
141+ std::move (*tracer.getLocalData ().getScalarData (fluxLabel));
142+ tracer.normalizeFlux (fluxResult);
143+ std::vector<std::vector<NumericType>> fluxResultVec;
144+ fluxResultVec.push_back (std::move (fluxResult));
145+ if constexpr (particleType == 1 ) {
146+ fluxResult = std::move (*tracer.getLocalData ().getScalarData (1 ));
147+ tracer.normalizeFlux (fluxResult);
148+ fluxResultVec.push_back (std::move (fluxResult));
149+ }
150+ ElementToPointData<NumericType, float , float > post (
151+ dataLabels, pointData, elementKdTree, diskMesh, surfMesh,
152+ domain->getGridDelta () * 2 .0f );
153+ post .setElementDataArrays (std::move (fluxResultVec));
154+ post .apply ();
155+ timer.finish ();
156+ file << timer.currentDuration << " ;" ;
157+ file << tracer.getRayTraceInfo ().totalRaysTraced << " ;" ;
158+ file << numThreadsList[i] << " \n " ;
159+ }
160+ }
161+ file.close ();
162+ }
163+ }
0 commit comments