12 #define _USE_MATH_DEFINES 29 #define _SOLVE_3D (true) 37 const std::pair<int, double>& secondElem) {
38 return firstElem.second < secondElem.second;
45 #define track_flux(p,e) (track_flux[(p)*_num_moc_groups + (e)] 77 CMFD_PRECISION*** _boundary_volumes;
78 CMFD_PRECISION*** _boundary_reaction;
79 CMFD_PRECISION*** _boundary_diffusion;
80 CMFD_PRECISION*** _old_boundary_flux;
81 CMFD_PRECISION*** _boundary_surface_currents;
83 CMFD_PRECISION*** _send_volumes;
84 CMFD_PRECISION*** _send_reaction;
85 CMFD_PRECISION*** _send_diffusion;
86 CMFD_PRECISION*** _send_currents;
88 CMFD_PRECISION* _send_split_current_data;
89 CMFD_PRECISION* _receive_split_current_data;
90 CMFD_PRECISION** _send_split_currents_array;
91 CMFD_PRECISION** _receive_split_currents_array;
92 CMFD_PRECISION*** _off_domain_split_currents;
93 CMFD_PRECISION*** _received_split_currents;
104 Vector* _old_dif_surf_corr;
107 bool _old_dif_surf_valid;
113 double _source_convergence_threshold;
135 int _num_cmfd_groups;
141 int* _group_indices_map;
144 int _num_backup_groups;
147 std::vector< std::vector<int> > _backup_group_structure;
150 int* _cmfd_group_to_backup_group;
153 bool _user_group_indices;
163 bool _balance_sigma_t;
169 FP_PRECISION* _FSR_volumes;
175 FP_PRECISION* _FSR_fluxes;
178 FP_PRECISION* _FSR_sources;
181 FP_PRECISION* _flux_moments;
193 double _cell_width_x;
194 double _cell_width_y;
195 double _cell_width_z;
198 std::vector<double> _cell_widths_x;
199 std::vector<double> _cell_widths_y;
200 std::vector<double> _cell_widths_z;
203 std::vector<double> _accumulate_x;
204 std::vector<double> _accumulate_y;
205 std::vector<double> _accumulate_z;
211 bool _widths_adjusted_for_domains;
217 Vector* _surface_currents;
220 Vector* _starting_currents;
227 Vector* _full_surface_currents;
230 std::map<int, CMFD_PRECISION> _edge_corner_currents;
233 std::vector< std::vector<long> > _cell_fsrs;
239 bool _flux_update_on;
242 bool _centroid_update_on;
245 bool _check_neutron_balance;
248 bool _negative_fluxes_allowed;
254 double _relaxation_factor;
257 std::map<long, std::vector< std::pair<int, double> > >
261 omp_lock_t* _cell_locks;
264 omp_lock_t _edge_corner_lock;
272 double* _azim_spacings;
275 double** _polar_spacings;
278 int _use_axial_interpolation;
281 std::vector<double*> _axial_interpolants;
290 CMFD_PRECISION* _inter_domain_data;
293 CMFD_PRECISION* _send_domain_data;
296 CMFD_PRECISION** _domain_data_by_surface;
299 CMFD_PRECISION** _send_data_by_surface;
302 std::vector<std::map<int, int> > _boundary_index_map;
313 std::vector<int> _accumulate_lmx;
314 std::vector<int> _accumulate_lmy;
315 std::vector<int> _accumulate_lmz;
318 long _total_tally_size;
321 CMFD_PRECISION* _tally_memory;
324 CMFD_PRECISION** _reaction_tally;
327 CMFD_PRECISION** _volume_tally;
330 CMFD_PRECISION** _diffusion_tally;
333 bool _tallies_allocated;
337 bool _domain_communicator_allocated;
346 CMFD_PRECISION computeLarsensEDCFactor(CMFD_PRECISION dif_coef,
347 CMFD_PRECISION delta);
348 void constructMatrices(
int moc_iteration);
350 void updateMOCFlux();
352 void splitVertexCurrents();
353 void splitEdgeCurrents();
354 void getVertexSplitSurfaces(
int cell,
int vertex, std::vector<int>* surfaces);
355 void getEdgeSplitSurfaces(
int cell,
int edge, std::vector<int>* surfaces);
356 void initializeMaterials();
357 void initializeCurrents();
358 void generateKNearestStencils();
359 int convertDirectionToSurface(
int* direction);
360 void convertSurfaceToDirection(
int surface,
int* direction);
361 std::string getSurfaceNameFromDirection(
int* direction);
362 std::string getSurfaceNameFromSurface(
int surface);
366 bool neighbor=
false);
367 int getCellByStencil(
int cell_id,
int stencil_id);
368 CMFD_PRECISION getFluxRatio(
int cell_id,
int group,
long fsr);
369 CMFD_PRECISION getUpdateRatio(
int cell_id,
int moc_group,
long fsr);
370 double getDistanceToCentroid(
Point* centroid,
int cell_id,
int local_cell_id,
372 void getSurfaceDiffusionCoefficient(
int cmfd_cell,
int surface,
373 int group,
int moc_iteration, CMFD_PRECISION& dif_surf,
374 CMFD_PRECISION& dif_surf_corr);
375 CMFD_PRECISION getDiffusionCoefficient(
int cmfd_cell,
int group);
376 CMFD_PRECISION getSurfaceWidth(
int surface,
int global_ind);
377 CMFD_PRECISION getPerpendicularSurfaceWidth(
int surface,
int global_ind);
378 int getSense(
int surface);
379 int getLocalCMFDCell(
int cmfd_cell);
380 int getGlobalCMFDCell(
int cmfd_cell);
381 int getCellColor(
int cmfd_cell);
384 void ghostCellExchange();
385 void communicateSplits(
bool faces);
387 void unpackSplitCurrents(
bool faces);
388 void copyFullSurfaceCurrents();
389 void checkNeutronBalance(
bool pre_split=
true,
bool old_source=
false);
390 void printProlongationFactors(
int iteration);
412 int azim_index,
int polar_index,
bool fwd);
414 double delta_z,
float*
track_flux,
double weight);
463 polar_spacings,
int num_azim,
int num_polar);
468 void setNumDomains(
int num_x,
int num_y,
int num_z);
469 void setDomainIndexes(
int idx_x,
int idx_y,
int idx_z);
484 void setCellFSRs(std::vector< std::vector<long> >* cell_fsrs);
488 void setWidths(std::vector< std::vector<double> > widths);
501 return _group_indices_map[group];
517 int global_cell_id = getGlobalCMFDCell(
cell_id);
527 inline int Cmfd::getGlobalCMFDCell(
int cmfd_cell) {
532 if (_domain_communicator != NULL) {
533 x_start = _accumulate_lmx[_domain_communicator->_domain_idx_x];
534 y_start = _accumulate_lmy[_domain_communicator->_domain_idx_y];
535 z_start = _accumulate_lmz[_domain_communicator->_domain_idx_z];
538 int ix = cmfd_cell % _local_num_x;
539 int iy = (cmfd_cell % (_local_num_x * _local_num_y)) / _local_num_x;
540 int iz = cmfd_cell / (_local_num_x * _local_num_y);
542 return ((iz + z_start) * _num_y + iy + y_start) * _num_x
557 int azim_index,
int polar_index,
bool fwd) {
559 int surf_id,
cell_id, cmfd_group;
560 int ncg = _num_cmfd_groups;
563 bool tally_current =
false;
567 tally_current =
true;
572 tally_current =
true;
578 CMFD_PRECISION currents[_num_cmfd_groups]
579 __attribute__ ((aligned(VEC_ALIGNMENT)));
580 memset(¤ts[0], 0, _num_cmfd_groups *
sizeof(CMFD_PRECISION));
581 int local_cell_id = getLocalCMFDCell(
cell_id);
585 for (
int e=0; e < _num_moc_groups; e++) {
594 #pragma omp simd aligned(currents) 595 for (
int g=0; g < ncg; g++)
601 (local_cell_id, surf_id*ncg, (surf_id+1)*ncg - 1, currents);
606 int first_ind = (local_cell_id * NUM_SURFACES + surf_id) * ncg;
607 omp_set_lock(&_edge_corner_lock);
609 #pragma omp simd aligned(currents) 610 for (
int g=0; g < ncg; g++)
611 _edge_corner_currents[first_ind+g] += currents[g];
613 omp_unset_lock(&_edge_corner_lock);
618 for (
int p=0; p < _num_polar/2; p++) {
619 for (
int e=0; e < _num_moc_groups; e++) {
633 (local_cell_id, surf_id*ncg, (surf_id+1)*ncg - 1, currents);
636 omp_set_lock(&_edge_corner_lock);
638 int first_ind = (local_cell_id * NUM_SURFACES + surf_id) * ncg;
641 #pragma omp simd aligned(currents) 642 for (
int g=0; g < ncg; g++)
643 _edge_corner_currents[first_ind+g] += currents[g];
645 omp_unset_lock(&_edge_corner_lock);
void setFluxMoments(FP_PRECISION *flux_moments)
Set pointer to source region flux moments array.
Definition: Cmfd.cpp:1620
int _cmfd_surface_fwd
Definition: Track.h:42
int surface_id()
Returns an auto-generated unique surface ID.
Definition: Surface.cpp:16
int findCmfdCell(LocalCoords *coords)
Find the CMFD cell that a LocalCoords object is in.
Definition: Cmfd.cpp:1926
void recordNetCurrents()
Records net currents (leakage) on every CMFD cell for every group.
Definition: Cmfd.cpp:5376
bool isSigmaTRebalanceOn()
Returns a flag indicating whether the sigma-t rebalance is on.
Definition: Cmfd.cpp:2731
#define NUM_FACES
Definition: constants.h:116
void setFSRFluxes(FP_PRECISION *scalar_flux)
Set pointer to FSR flux array.
Definition: Cmfd.cpp:1602
The LocalCoords represents a set of local coordinates on some level of nested Universes making up the...
Definition: LocalCoords.h:46
void setQuadrature(Quadrature *quadrature)
Sets the Quadrature object in use by the MOC Solver.
Definition: Cmfd.cpp:2784
int cell_id()
Returns an auto-generated unique Cell ID.
Definition: Cell.cpp:20
int convertGlobalFSRIdToCmfdCell(long global_fsr_id)
Return the CMFD cell ID that a FSR lies in.
Definition: Cmfd.cpp:2558
void setCMFDRelaxationFactor(double relaxation_factor)
Set the CMFD relaxation factor applied to diffusion coefficients.
Definition: Cmfd.cpp:1644
int getNumCells()
Get the number of CMFD cells.
Definition: Cmfd.cpp:1996
void printInputParamsSummary()
A function that prints a summary of the CMFD input parameters.
Definition: Cmfd.cpp:4234
bool isCentroidUpdateOn()
Get flag indicating whether to use FSR centroids to update the MOC flux.
Definition: Cmfd.cpp:2761
void setKeff(double k_eff)
Set the value of the k effective for the CMFD solver. This is meant for research / debugging purposes...
Definition: Cmfd.cpp:4177
void setBackupGroupStructure(std::vector< std::vector< int > > group_indices)
Set the backup CMFD solver's group structure. It is necessarily coarser than and must align with the ...
Definition: Cmfd.cpp:4187
void setNumY(int num_y)
Set the number of Mesh cells in a column.
Definition: Cmfd.cpp:277
void setFSRSources(FP_PRECISION *sources)
Set pointer to FSR source array.
Definition: Cmfd.cpp:1611
void setNumX(int num_x)
Set the number of Mesh cells in a row.
Definition: Cmfd.cpp:258
double getWeightInline(size_t azim, size_t polar) const
Returns the total weight for Tracks with the given azimuthal and polar indexes without error checking...
Definition: Quadrature.h:313
boundaryType
The types of boundary conditions supported by OpenMOC for Surfaces.
Definition: boundary_type.h:15
Math constants and comparision tolerances.
bool isFluxUpdateOn()
Get flag indicating whether to update the MOC flux.
Definition: Cmfd.cpp:2740
void useAxialInterpolation(int interpolate)
Set the flag indicating whether to use quadratic axial interpolation for update ratios.
Definition: Cmfd.cpp:2643
void setKNearest(int k_nearest)
Set a number of k-nearest neighbor cells to use in updating the FSR flux.
Definition: Cmfd.cpp:3326
Verbose iteration information for the CMFD eigenvalue solver.
Definition: linalg.h:31
int getNumMOCGroups()
Get the number of MOC energy groups.
Definition: Cmfd.cpp:1987
virtual ~Cmfd()
Destructor deletes arrays of A and M row insertion arrays.
Definition: Cmfd.cpp:107
void setNumZ(int num_z)
Set the number of Mesh cells in the z-direction.
Definition: Cmfd.cpp:296
void tallyCurrent(segment *curr_segment, float *track_flux, int azim_index, int polar_index, bool fwd)
Tallies the current contribution from this segment across the the appropriate CMFD mesh cell surface...
Definition: Cmfd.h:556
void setGeometry(Geometry *geometry)
Set a pointer to the Geometry.
Definition: Cmfd.cpp:3316
void useFluxLimiting(bool flux_limiting)
Turns on the flux limiting condition.
Definition: Cmfd.cpp:2664
void setAzimSpacings(const std::vector< double > &azim_spacings, int num_azim)
Sets the azimuthal spacings.
Definition: Cmfd.cpp:4132
void printCmfdCellSizes()
Print information about CMFD cell dimensions.
Definition: Cmfd.cpp:5482
Class to represent a 2D/3D point in space.
Definition: Point.h:24
int getNumZ()
Get the number of Mesh cells in the z-direction.
Definition: Cmfd.cpp:333
int _cmfd_surface_bwd
Definition: Track.h:45
Structure for communication of fluxes between neighbor domains.
Definition: linalg.h:74
void setNumFSRs(long num_fsrs)
set the number of FSRs.
Definition: Cmfd.cpp:2005
The arbitrary quadrature parent class.
Definition: Quadrature.h:76
void enforceBalanceOnDiagonal(int cmfd_cell, int group)
Modifies the diagonal element to be consistent with the MOC solve.
Definition: Cmfd.cpp:2681
void setLatticeStructure(int num_x, int num_y, int num_z=1)
The structure of the Lattice to be used as the CMFD mesh.
Definition: Cmfd.cpp:1947
The master class containing references to all geometry-related objects - Surfaces, Cells, Universes and Lattices - and Materials.
Definition: Geometry.h:122
void tallyStartingCurrent(Point *point, double delta_x, double delta_y, double delta_z, float *track_flux, double weight)
This function tallies the current impinging on the domain from starting fluxes.
Definition: Cmfd.cpp:5306
void setWidthY(double width)
Set Mesh width in the y-direction.
Definition: Cmfd.cpp:369
void zeroCurrents()
Zero the surface currents for each mesh cell and energy group.
Definition: Cmfd.cpp:3342
void setWidths(std::vector< std::vector< double > > widths)
Set width of non-uniform meshes in x y z directions.
Definition: Cmfd.cpp:5463
A segment represents a line segment within a single flat source region along a track.
Definition: Track.h:27
void setGroupStructure(std::vector< std::vector< int > > group_indices)
Set a coarse energy group structure for CMFD.
Definition: Cmfd.cpp:1687
double computeKeff(int moc_iteration)
Solve the nonlinear diffusion acceleration problem to accelerate the convergence of the MOC problem...
Definition: Cmfd.cpp:1145
void setSORRelaxationFactor(double SOR_factor)
Set successive over-relaxation relaxation factor.
Definition: Cmfd.cpp:1630
int getNumY()
Get the number of Mesh cells in a column.
Definition: Cmfd.cpp:324
void setFluxUpdateOn(bool flux_update_on)
Set flag indicating whether to update the MOC flux.
Definition: Cmfd.cpp:2620
CMFD_PRECISION *** getBoundarySurfaceCurrents()
Get the array of surface currents on the boundaries.
Definition: Cmfd.cpp:351
void setBoundary(int side, boundaryType boundary)
Set the CMFD boundary type for a given surface.
Definition: Cmfd.cpp:2507
int getNumX()
Get the number of Mesh cells in a row.
Definition: Cmfd.cpp:315
void setConvergenceData(ConvergenceData *convergence_data)
Sets the a ConvergenceData object to record diagnostics.
Definition: Cmfd.cpp:2632
void initialize()
Initialize the Matrix and Vector objects, k-nearest stencils, the CMFD cell currents and MOC material...
Definition: Cmfd.cpp:3388
void setNumMOCGroups(int num_moc_groups)
Set the number of MOC energy groups.
Definition: Cmfd.cpp:1978
#define track_flux(p, e)
Definition: Cmfd.h:45
int getCmfdGroup(int group)
Get the CMFD group given an MOC group.
Definition: Cmfd.h:500
std::vector< std::vector< long > > * getCellFSRs()
Return a pointer to the vector of vectors that contains the FSRs that lie in each cell...
Definition: Cmfd.cpp:2593
void copyCurrentsToBackup()
Copies the current from the regular to the backup CMFD solver.
Definition: Cmfd.cpp:3985
void setFSRVolumes(FP_PRECISION *FSR_volumes)
Set the pointer to the array of FSR_volumes.
Definition: Cmfd.cpp:1593
int getLatticeSurfaceOTF(int cell, double z, int surface_2D)
Finds the Lattice cell surface that a point lies on. If the point is not on a surface, -1 is returned.
Definition: Universe.cpp:2225
A class for Coarse Mesh Finite Difference (CMFD) acceleration.
Definition: Cmfd.h:51
void setFSRMaterials(Material **FSR_materials)
Set the FSR materials array pointer.
Definition: Cmfd.cpp:1584
void setCentroidUpdateOn(bool centroid_update_on)
Set flag indicating whether to use FSR centroids to update the MOC flux.
Definition: Cmfd.cpp:2751
The Material class represents a unique material and its relevant nuclear data (i.e., multigroup cross-sections) for neutron transport.
Definition: Material.h:51
void rebalanceSigmaT(bool balance_sigma_t)
Rebalances the total cross section to be consistent with the MOC solution on every sweep...
Definition: Cmfd.cpp:2722
int getNumCmfdGroups()
Get the number of coarse CMFD energy groups.
Definition: Cmfd.cpp:1667
Cmfd()
Constructor initializes boundaries and variables that describe the CMFD object.
Definition: Cmfd.cpp:10
#define scalar_flux(tid, e)
Definition: GPUSolver.h:38
void setWidthZ(double width)
Set Mesh width in the z-direction.
Definition: Cmfd.cpp:378
void setSolve3D(bool solve_3d)
Sets a flag to indicate whether a 2D or 3D problem is being solved.
Definition: Cmfd.cpp:4120
void initializeCellMap()
Initializes the vector of vectors that links CMFD cells with FSRs.
Definition: Cmfd.cpp:1800
void checkBalance()
Forces CMFD to check neutron balance on every solve.
Definition: Cmfd.cpp:1658
void setWidthX(double width)
Set Mesh width in the x-direction.
Definition: Cmfd.cpp:360
The Quadrature abstract class and subclasses.
bool stencilCompare(const std::pair< int, double > &firstElem, const std::pair< int, double > &secondElem)
Definition: Cmfd.h:36
void setPolarSpacings(const std::vector< std::vector< double > > &polar_spacings, int num_azim, int num_polar)
Sets the polar spacings.
Definition: Cmfd.cpp:4152
void initializeLattice(Point *offset, bool is_2D=false)
Initialize the CMFD lattice and compute mesh dimensions, considering both uniform/non-uniform and 2D/...
Definition: Cmfd.cpp:3766
int getBoundary(int side)
Get the boundaryType for one side of the CMFD mesh.
Definition: Cmfd.cpp:2517
void initializeBackupCmfdSolver()
Initializes a backup CMFD solver.
Definition: Cmfd.cpp:3899
void setSourceConvergenceThreshold(double source_thresh)
Sets the threshold for CMFD source convergence (>0).
Definition: Cmfd.cpp:2770
int findCmfdSurfaceOTF(int cell_id, double z, int surface_2D)
Quickly finds a 3D CMFD surface given a cell, global coordinate, and 2D CMFD surface. Intended for use in axial on-the-fly ray tracing.
Definition: Cmfd.h:516
Represents a repeating 3D Lattice of Universes.
Definition: Universe.h:156
int convertFSRIdToCmfdCell(long fsr_id)
Return the CMFD cell ID that a FSR lies in.
Definition: Cmfd.cpp:2537
The Timer class is for timing and profiling regions of code.
Definition: Timer.h:40
void incrementValues(int cell, int group_start, int group_end, CMFD_PRECISION *vals)
Increment values in the vector.
Definition: Vector.cpp:92
Utility functions for writing log messages to the screen.
Lattice * getLattice()
Returns the Lattice object used as the CMFD mesh.
Definition: Cmfd.cpp:1958
void initializeGroupMap()
Initialize and set array that links the MOC energy groups to the CMFD energy groups.
Definition: Cmfd.cpp:1862
void allocateTallies()
Allocates memory for the CMFD tallies.
Definition: Cmfd.cpp:1818
void printTimerReport()
Report the physical time use by major components of the CMFD solver.
Definition: Cmfd.cpp:4281
void addFSRToCell(int cell_id, long fsr_id)
Add an FSR ID to a vector that contains all the FSR IDs contained within a CMFD mesh cell...
Definition: Cmfd.cpp:1969
int findCmfdSurface(int cell_id, LocalCoords *coords)
Find the CMFD surface that a LocalCoords object lies on.
Definition: Cmfd.cpp:1911
void setCellFSRs(std::vector< std::vector< long > > *cell_fsrs)
Set the vector of vectors that contains the FSRs that lie in each cell.
Definition: Cmfd.cpp:2603
Vector * getLocalCurrents()
Get the Vector of surface currents.
Definition: Cmfd.cpp:342