An open source method of characteristics neutron transport code.
GPUSolver.h
Go to the documentation of this file.
1 
8 #ifndef GPUSOLVER_H_
9 #define GPUSOLVER_H_
10 
11 #ifdef __cplusplus
12 #ifdef SWIG
13 #include "Python.h"
14 #endif
15 #include "../../Solver.h"
16 #endif
17 
18 #define PySys_WriteStdout printf
19 
20 #include <thrust/copy.h>
21 #include <iostream>
22 
23 #include <thrust/device_vector.h>
24 #include <thrust/copy.h>
25 #include <thrust/fill.h>
26 #include <thrust/reduce.h>
27 #include <thrust/replace.h>
28 #include <thrust/functional.h>
29 #include <thrust/iterator/constant_iterator.h>
30 #include <thrust/iterator/counting_iterator.h>
31 #include <thrust/iterator/transform_iterator.h>
32 #include <thrust/iterator/permutation_iterator.h>
33 #include <sm_20_atomic_functions.h>
34 #include "clone.h"
35 #include "GPUExpEvaluator.h"
36 
38 #define scalar_flux(tid,e) (scalar_flux[(tid)*(*num_groups) + (e)])
39 
41 #define old_scalar_flux(tid,e) (old_scalar_flux[(tid)*(*num_groups) + (e)])
42 
45 #define reduced_sources(tid,e) (reduced_sources[(tid)*(*num_groups) + (e)])
46 
48 #define fixed_sources(r,e) (fixed_sources[(r)*(*num_groups) + (e)])
49 
51 #define weights(i,p) (weights[(i)*(*num_polar_2) + (p)])
52 
55 #define boundary_flux(t,pe2) (boundary_flux[2*(t)*(*polar_times_groups)+(pe2)])
56 
60 #define start_flux(t,pe2) (start_flux[2*(t)*(*polar_times_groups)+(pe2)])
61 
69 class GPUSolver : public Solver {
70 
71 private:
72 
74  int _B;
75 
77  int _T;
78 
80  int* _FSR_materials;
81 
83  dev_material* _materials;
84 
86  dev_track* _dev_tracks;
87 
89  thrust::device_vector<FP_PRECISION> _boundary_flux;
90 
92  thrust::device_vector<FP_PRECISION> _start_flux;
93 
95  thrust::device_vector<FP_PRECISION> _scalar_flux;
96 
98  thrust::device_vector<FP_PRECISION> _old_scalar_flux;
99 
101  thrust::device_vector<FP_PRECISION> _fixed_sources;
102 
104  thrust::device_vector<FP_PRECISION> _reduced_sources;
105 
107  std::map<int, int> _material_IDs_to_indices;
108 
109  void copyQuadrature();
110 
111 public:
112 
113  GPUSolver(TrackGenerator* track_generator=NULL);
114  virtual ~GPUSolver();
115 
116  int getNumThreadBlocks();
117 
122  int getNumThreadsPerBlock();
123  FP_PRECISION getFSRSource(int fsr_id, int group);
124  FP_PRECISION getFlux(int fsr_id, int group);
125  void getFluxes(FP_PRECISION* out_fluxes, int num_fluxes);
126 
127  void setNumThreadBlocks(int num_blocks);
128  void setNumThreadsPerBlock(int num_threads);
129  void setGeometry(Geometry* geometry);
130  void setTrackGenerator(TrackGenerator* track_generator);
131  void setFluxes(FP_PRECISION* in_fluxes, int num_fluxes);
132 
133  void initializeExpEvaluator();
134  void initializeMaterials(solverMode mode=ADJOINT);
135  void initializeFSRs();
136  void initializeTracks();
137  void initializeFluxArrays();
138  void initializeSourceArrays();
139  void initializeFixedSources();
140 
141  void zeroTrackFluxes();
142  void flattenFSRFluxes(FP_PRECISION value);
143  void storeFSRFluxes();
144  void normalizeFluxes();
145  void computeFSRSources();
148  void transportSweep();
149  void addSourceToScalarFlux();
150  void computeKeff();
151  double computeResidual(residualType res_type);
152 
153  void computeFSRFissionRates(double* fission_rates, int num_FSRs);
154 };
155 
156 
157 #endif /* GPUSOLVER_H_ */
This a subclass of the Solver class for NVIDIA Graphics Processing Units (GPUs).
Definition: GPUSolver.h:69
void zeroTrackFluxes()
Zero each Track&#39;s boundary fluxes for each energy group and polar angle in the "forward" and "reverse...
void flattenFSRFluxes(FP_PRECISION value)
Set the scalar flux for each FSR and energy group to some value.
A dev_track represents a characteristic line across the geometry.
Definition: DeviceTrack.h:43
Routines to copy Material and Track objects to the GPU from CPU.
void initializeFixedSources()
Assigns fixed sources assigned by Cell, Material to FSRs.
void initializeSourceArrays()
Allocates memory for FSR source arrays.
The TrackGenerator is dedicated to generating and storing Tracks which cyclically wrap across the Geo...
Definition: TrackGenerator.h:36
void storeFSRFluxes()
Stores the current scalar fluxes in the old scalar flux array.
void computeKeff()
Compute from total fission and absorption rates in each FSR and energy group.
void computeFSRScatterSources()
Computes the total scattering source for each FSR and energy group.
The master class containing references to all geometry-related objects - Surfaces, Cells, Universes and Lattices - and Materials.
Definition: Geometry.h:122
double computeResidual(residualType res_type)
Computes the residual between successive flux/source iterations.
void addSourceToScalarFlux()
Add the source term contribution in the transport equation to the FSR scalar flux.
void initializeFSRs()
Initializes the FSR volumes and Materials array.
void transportSweep()
This method performs one transport sweep of all azimuthal angles, Tracks, segments, polar angles and energy groups.
Definition: Solver.h:78
void normalizeFluxes()
Normalizes all FSR scalar fluxes and Track boundary angular fluxes to the total fission source (times...
void computeFSRFissionSources()
Computes the total fission source for each FSR and energy group.
A Material&#39;s nuclear data to be stored on a GPU.
Definition: DeviceMaterial.h:22
This is an abstract base class which different Solver subclasses implement for different architecture...
Definition: Solver.h:121
int getNumThreadsPerBlock()
Returns the number of threads per block to execute on the GPU.
void initializeFluxArrays()
Initializes Track boundary angular flux and leakage and FSR scalar flux arrays.
residualType
The type of residual used for the convergence criterion.
Definition: Solver.h:86
solverMode
The solution mode used by the MOC solver.
Definition: Solver.h:72
The GPUExpEvaluator class.