An open source method of characteristics neutron transport code.
CPUSolver.h
Go to the documentation of this file.
1 
9 #ifndef CPUSOLVER_H_
10 #define CPUSOLVER_H_
11 
12 #ifdef __cplusplus
13 #define _USE_MATH_DEFINES
14 #include "Solver.h"
16 #include <math.h>
17 #include <omp.h>
18 #include <stdlib.h>
19 #include <unordered_map>
20 #endif
21 
22 #undef track_flux
23 
24 #ifdef NGROUPS
25 #define _num_groups (NGROUPS)
26 #endif
27 
30 #define track_flux(pe) (track_flux[(pe)])
31 
34 #define track_out_flux(pe) (track_out_flux[(pe)])
35 
38 #define track_leakage(pe) (track_leakage[(pe)])
39 
40 
41 /* Structure containing the info to send about a track (used in printCycle) */
42 struct sendInfo {
43  long track_id;
44  int domain;
45  bool fwd;
46 };
47 
48 
54 class CPUSolver : public Solver {
55 
56 protected:
57 
60 
62  omp_lock_t* _FSR_locks;
63 
64 #ifdef MPIx
65  /* Message size when communicating track angular fluxes at interfaces */
66  int _track_message_size;
67 
68  /* Buffer to send track angular fluxes and associated information */
69  std::vector<std::vector<float> > _send_buffers;
70 
71  /* Index into send_buffers for pre-filling (ONLYVACUUMBC mode) */
72  std::vector<int> _send_buffers_index;
73 
74  /* Buffer to receive track angular fluxes and associated information */
75  std::vector<std::vector<float> > _receive_buffers;
76 
77  /* Vector of vectors containing boundary track ids and direction */
78  std::vector<std::vector<long> > _boundary_tracks;
79 
80  /* Vector to know how big of a send buffer to send to another domain */
81  std::vector<int> _send_size;
82 
83  /* Vector to save the size of the receive buffers */
84  std::vector<int> _receive_size;
85 
86  /* Vector of vectors containing the connecting track id and direction */
87  std::vector<std::vector<long> > _track_connections;
88 
89  /* Vector of vectors containing the connecting domains */
90  std::vector<std::vector<int> > _domain_connections;
91 
92  /* Rank of domains neighboring local domain */
93  std::vector<int> _neighbor_domains;
94 
95  /* Index of neighboring domains in _neighbor_domains */
96  std::unordered_map<int, int> _neighbor_connections;
97 
98  /* Array to check whether MPI communications are finished */
99  MPI_Request* _MPI_requests;
100 
101  /* Arrays of booleans to know whether a send/receive call was made */
102  bool* _MPI_sends;
103  bool* _MPI_receives;
104 #endif
105 
106 #ifdef ONLYVACUUMBC
107  /* Vector of the vacuum boundary track ids and direction */
108  std::vector<long> _tracks_from_vacuum;
109 
110  /* Vector of vectors containing if a track flux has been sent by pre-fill */
111  std::vector<std::vector<bool> > _track_flux_sent;
112 #endif
113 
114  virtual void initializeFluxArrays();
115  virtual void initializeSourceArrays();
116  virtual void initializeFSRs();
117 
118 
119  void zeroTrackFluxes();
120  void copyBoundaryFluxes();
121  void tallyStartingCurrents();
122 #ifdef MPIx
123  void setupMPIBuffers();
124  void deleteMPIBuffers();
125  void packBuffers(std::vector<long> &packing_indexes);
126  void transferAllInterfaceFluxes();
127  void printCycle(long track_start, int domain_start, int length);
128  void boundaryFluxChecker();
129 #endif
130 #ifdef ONLYVACUUMBC
131  void resetBoundaryFluxes();
132 #endif
133  virtual void flattenFSRFluxes(FP_PRECISION value);
135  void storeFSRFluxes();
136  virtual double normalizeFluxes();
139  virtual void computeFSRSources(int iteration);
140  void transportSweep();
141  virtual void computeStabilizingFlux();
142  virtual void stabilizeFlux();
143  virtual void addSourceToScalarFlux();
144  void computeKeff();
145  double computeResidual(residualType res_type);
146 
147 public:
148  CPUSolver(TrackGenerator* track_generator=NULL);
149  virtual ~CPUSolver();
150 
151  int getNumThreads();
152  void setNumThreads(int num_threads);
153  void setFluxes(FP_PRECISION* in_fluxes, int num_fluxes);
154  void setFixedSourceByFSR(long fsr_id, int group, FP_PRECISION source);
155  void computeFSRFissionRates(double* fission_rates, long num_FSRs,
156  bool nu = false);
158 
159  void tallyScalarFlux(segment* curr_segment, int azim_index, int polar_index,
160  FP_PRECISION* fsr_flux, float* track_flux);
161 
162  void accumulateScalarFluxContribution(long fsr_id, FP_PRECISION weight,
163  FP_PRECISION* fsr_flux);
164 
165  void tallyCurrent(segment* curr_segment, int azim_index, int polar_index,
166  float* track_flux, bool fwd);
167 
168  void transferBoundaryFlux(Track* track, int azim_index, int polar_index,
169  bool direction, float* track_flux);
170 
171  void getFluxes(FP_PRECISION* out_fluxes, int num_fluxes);
172  void initializeFixedSources();
173 
174  void printFSRFluxes(std::vector<double> dim1,
175  std::vector<double> dim2, double offset,
176  const char* plane);
177  void printFluxesTemp();
178  void printNegativeSources(int iteration, int num_x, int num_y, int num_z);
179 };
180 
181 
182 #endif /* CPUSOLVER_H_ */
void transferBoundaryFlux(Track *track, int azim_index, int polar_index, bool direction, float *track_flux)
Updates the boundary flux for a Track given boundary conditions.
Definition: CPUSolver.cpp:2385
This a subclass of the Solver class for multi-core CPUs using OpenMP multi-threading.
Definition: CPUSolver.h:54
void tallyCurrent(segment *curr_segment, int azim_index, int polar_index, float *track_flux, bool fwd)
Tallies the current contribution from this segment across the the appropriate CMFD mesh cell surface...
Definition: CPUSolver.cpp:2364
virtual void computeFSRSources(int iteration)
Computes the total source (fission, scattering, fixed) in each FSR.
Definition: CPUSolver.cpp:1771
virtual void initializeFSRs()
Initializes the FSR volumes and Materials array.
Definition: CPUSolver.cpp:231
void copyBoundaryFluxes()
Copies values from the start flux into the boundary flux array for both the "forward" and "reverse" d...
Definition: CPUSolver.cpp:453
virtual ~CPUSolver()
Destructor deletes array for OpenMP mutual exclusion locks for FSR scalar flux updates, and calls Solver parent class destructor to deletes arrays for fluxes and sources.
Definition: CPUSolver.cpp:34
virtual void initializeFluxArrays()
Allocates memory for Track boundary angular flux and leakage and FSR scalar flux arrays.
Definition: CPUSolver.cpp:252
omp_lock_t * _FSR_locks
Definition: CPUSolver.h:62
double computeResidual(residualType res_type)
Computes the residual between source/flux iterations.
Definition: CPUSolver.cpp:1940
The TrackGenerator is dedicated to generating and storing Tracks which cyclically wrap across the Geo...
Definition: TrackGenerator.h:36
void tallyScalarFlux(segment *curr_segment, int azim_index, int polar_index, FP_PRECISION *fsr_flux, float *track_flux)
Computes the contribution to the FSR scalar flux from a Track segment.
Definition: CPUSolver.cpp:2230
virtual void initializeSourceArrays()
Allocates memory for FSR source arrays.
Definition: CPUSolver.cpp:361
void initializeFixedSources()
Populates array of fixed sources assigned by FSR.
Definition: CPUSolver.cpp:398
void computeFSRFissionSources()
Computes the total fission source in each FSR.
Definition: CPUSolver.cpp:1857
Definition: CPUSolver.h:42
void computeKeff()
Compute from successive fission sources.
Definition: CPUSolver.cpp:2085
virtual void addSourceToScalarFlux()
Add the source term contribution in the transport equation to the FSR scalar flux.
Definition: CPUSolver.cpp:2433
void printNegativeSources(int iteration, int num_x, int num_y, int num_z)
A function that prints the number of FSRs with negative sources in the whole geometry subdivided by a...
Definition: CPUSolver.cpp:2849
virtual double normalizeFluxes()
Normalizes all FSR scalar fluxes and Track boundary angular fluxes to the total fission source (times...
Definition: CPUSolver.cpp:1692
Contains classes which extend the TraverseSegments class to apply algorithms to Tracks and possibly t...
void setFixedSourceByFSR(long fsr_id, int group, FP_PRECISION source)
Assign a fixed source for a flat source region and energy group.
Definition: CPUSolver.cpp:204
int getNumThreads()
Returns the number of shared memory OpenMP threads in use.
Definition: CPUSolver.cpp:45
A segment represents a line segment within a single flat source region along a track.
Definition: Track.h:27
void computeFSRFissionRates(double *fission_rates, long num_FSRs, bool nu=false)
Computes the volume-averaged, energy-integrated fission or nu-fission rate in each FSR and stores the...
Definition: CPUSolver.cpp:2650
virtual void stabilizeFlux()
Adjusts the scalar flux for transport stabilization.
Definition: CPUSolver.cpp:2561
The Solver class.
int _num_threads
Definition: CPUSolver.h:59
void accumulateScalarFluxContribution(long fsr_id, FP_PRECISION weight, FP_PRECISION *fsr_flux)
Move the segment(s)&#39; contributions to the scalar flux from the buffer to the global scalar flux array...
Definition: CPUSolver.cpp:2335
virtual void computeStabilizingFlux()
Computes the stabilizing flux for transport stabilization.
Definition: CPUSolver.cpp:2490
CPUSolver(TrackGenerator *track_generator=NULL)
Constructor initializes array pointers for Tracks and Materials.
Definition: CPUSolver.cpp:13
This is an abstract base class which different Solver subclasses implement for different architecture...
Definition: Solver.h:121
void getFluxes(FP_PRECISION *out_fluxes, int num_fluxes)
Fills an array with the scalar fluxes.
Definition: CPUSolver.cpp:66
void computeFSRScatterSources()
Computes the total scattering source in each FSR.
Definition: CPUSolver.cpp:1899
void storeFSRFluxes()
Stores the FSR scalar fluxes in the old scalar flux array.
Definition: CPUSolver.cpp:1678
void setNumThreads(int num_threads)
Sets the number of shared memory OpenMP threads to use (>0).
Definition: CPUSolver.cpp:132
void transportSweep()
This method performs one transport sweep of all azimuthal angles, Tracks, Track segments, polar angles and energy groups.
Definition: CPUSolver.cpp:2165
void printInputParamsSummary()
A function that prints a summary of the input parameters.
Definition: CPUSolver.cpp:2717
void tallyStartingCurrents()
Computes the total current impingent on boundary CMFD cells from starting angular fluxes...
Definition: CPUSolver.cpp:468
void printFluxesTemp()
A function that prints fsr fluxes in xy plane at z=middle.
Definition: CPUSolver.cpp:2812
A Track represents a characteristic line across the geometry.
Definition: Track.h:67
void printFSRFluxes(std::vector< double > dim1, std::vector< double > dim2, double offset, const char *plane)
A function that prints the source region fluxes on a 2D mesh grid.
Definition: CPUSolver.cpp:2734
virtual void flattenFSRFluxes(FP_PRECISION value)
Set the scalar flux for each FSR and energy group to some value.
Definition: CPUSolver.cpp:1648
#define track_flux(pe)
Definition: CPUSolver.h:30
residualType
The type of residual used for the convergence criterion.
Definition: Solver.h:86
void zeroTrackFluxes()
Zero each Track&#39;s boundary fluxes for each energy group (and polar angle in 2D) in the "forward" and ...
Definition: CPUSolver.cpp:433
void setFluxes(FP_PRECISION *in_fluxes, int num_fluxes)
Set the flux array for use in transport sweep source calculations.
Definition: CPUSolver.cpp:180
void flattenFSRFluxesChiSpectrum()
Set the scalar flux for each FSR to a chi spectrum.
Definition: CPUSolver.cpp:1661