Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GIDI_settings_particle.cc
Go to the documentation of this file.
1 /*
2 # <<BEGIN-copyright>>
3 # <<END-copyright>>
4 */
5 
6 #include <iostream>
7 #include <cmath>
8 
9 #include "GIDI_settings.hh"
10 
11 using namespace GIDI;
12 
13 /*
14 =========================================================
15 */
16 GIDI_settings_particle::GIDI_settings_particle( int PoPId, bool transporting, int energyMode ) : mGroup( ) {
17 
18  initialize( PoPId, transporting, energyMode );
19 }
20 /*
21 =========================================================
22 */
24 
25  initialize( particle.mPoPId, particle.mTransporting, particle.mEnergyMode );
26  setGroup( particle.mGroup );
27  for( std::vector<GIDI_settings_processedFlux>::const_iterator iter = particle.mProcessedFluxes.begin( ); iter != particle.mProcessedFluxes.end( ); ++iter ) {
28  mProcessedFluxes.push_back( *iter );
29  }
30 }
31 /*
32 =========================================================
33 */
34 int GIDI_settings_particle::initialize( int PoPId, bool transporting, int energyMode ) {
35 
36  mPoPId = PoPId;
37  mTransporting = transporting;
38  int energyMode_ = ( energyMode & GIDI_settings_projectileEnergyMode_continuousEnergy )
40 // + ( energyMode & GIDI_settings_projectileEnergyMode_fixedGrid ) // Currently not supported.
41  ;
42 
43  if( energyMode_ != energyMode ) throw 1;
44  mEnergyMode = energyMode;
45 
46  mGroupX = NULL;
47  setGroup( mGroup );
48  return( 0 );
49 }
50 /*
51 =========================================================
52 */
54 
55  nfu_status status_nf;
56 
57  mGroup = group;
58 
59  if( mGroupX != NULL ) ptwX_free( mGroupX );
60  mGroupX = NULL;
61  if( mGroup.size( ) > 0 ) {
62  if( ( mGroupX = ptwX_create( (int) mGroup.size( ), (int) mGroup.size( ), mGroup.pointer( ), &status_nf ) ) == NULL ) throw 1;
63  }
64 }
65 /*
66 =========================================================
67 */
69 
70  if( mGroupX != NULL ) ptwX_free( mGroupX );
71 }
72 /*
73 =========================================================
74 */
76 
77  double temperature = flux.getTemperature( );
78  std::vector<GIDI_settings_processedFlux>::iterator iter;
79 
80  for( iter = mProcessedFluxes.begin( ); iter != mProcessedFluxes.end( ); ++iter ) {
81  if( temperature <= iter->getTemperature( ) ) break;
82  }
83 // BRB need to check if temperature is the same.
84  mProcessedFluxes.insert( iter, GIDI_settings_processedFlux( flux, mGroupX ) );
85  return( 0 );
86 }
87 /*
88 =========================================================
89 */
91 
92  double priorTemperature, lastTemperature;
93  std::vector<GIDI_settings_processedFlux>::const_iterator iter;
94 
95  if( mProcessedFluxes.size( ) == 0 ) return( NULL );
96 
97  priorTemperature = mProcessedFluxes[0].getTemperature( );
98  //TK adds next line
99  lastTemperature = mProcessedFluxes[0].getTemperature( );
100  for( iter = mProcessedFluxes.begin( ); iter != mProcessedFluxes.end( ); ++iter ) {
101  lastTemperature = iter->getTemperature( );
102  if( lastTemperature > temperature ) break;
103  //TK add next line
104  priorTemperature = iter->getTemperature( );
105  }
106  if( iter == mProcessedFluxes.end( ) ) {
107  --iter; }
108  else {
109  //if( fabs( lastTemperature - temperature ) < fabs( temperature - priorTemperature ) ) --iter;
110  //TK modified above line
111  if( std::fabs( lastTemperature - temperature ) > std::fabs( temperature - priorTemperature ) ) --iter;
112  }
113  return( &(*iter) );
114 }
115 /*
116 =========================================================
117 */
118 ptwXPoints *GIDI_settings_particle::groupFunction( statusMessageReporting *smr, ptwXYPoints *ptwXY1, double temperature, int order ) const {
119 
120  if( mGroupX == NULL ) return( NULL );
121  GIDI_settings_processedFlux const *processedFlux = nearestFluxToTemperature( temperature );
122  if( processedFlux == NULL ) return( NULL );
123  return( processedFlux->groupFunction( smr, mGroupX, ptwXY1, order ) );
124 }
125 
126 /* ---- GIDI_settings_processedFlux ---- */
127 /*
128 =========================================================
129 */
131 
132  nfu_status status_nf;
133  ptwXYPoints *fluxXY = NULL;
134  ptwXPoints *groupedFluxX;
135  GIDI_settings_flux_order const *fluxOrder;
136  double const *energies, *fluxes;
137 
138  for( int order = 0; order < (int) flux.size( ); ++order ) {
139  fluxOrder = flux[order];
140  energies = fluxOrder->getEnergies( );
141  fluxes = fluxOrder->getFluxes( );
142  if( ( fluxXY = ptwXY_createFrom_Xs_Ys( ptwXY_interpolationLinLin, NULL, 12, 1e-3, fluxOrder->size( ), 10,
143  fluxOrder->size( ), energies, fluxes, &status_nf, 0 ) ) == NULL ) goto err;
144  mFluxXY.push_back( fluxXY );
145  if( ( groupedFluxX = ptwXY_groupOneFunction( fluxXY, groupX, ptwXY_group_normType_none, NULL, &status_nf ) ) == NULL ) goto err;
146  mGroupedFlux.push_back( groupedFluxX );
147  }
148  return;
149 
150 err:
151  throw 1;
152 }
153 /*
154 =========================================================
155 */
157 
158  nfu_status status_nf;
159  ptwXYPoints *fluxXY;
160  ptwXPoints *fluxX;
161 
162  for( int order = 0; order < (int) mFlux.size( ); ++order ) {
163  if( ( fluxXY = ptwXY_clone( flux.mFluxXY[order], &status_nf ) ) == NULL ) goto err;
164  mFluxXY.push_back( fluxXY );
165  if( ( fluxX = ptwX_clone( flux.mGroupedFlux[order], &status_nf ) ) == NULL ) goto err;
166  mGroupedFlux.push_back( fluxX );
167  }
168  return;
169 
170 err:
171  for( std::vector<ptwXYPoints *>::iterator iter = mFluxXY.begin( ); iter != mFluxXY.end( ); ++iter ) ptwXY_free( *iter );
172  for( std::vector<ptwXPoints *>::iterator iter = mGroupedFlux.begin( ); iter != mGroupedFlux.end( ); ++iter ) ptwX_free( *iter );
173  throw 1;
174 }
175 /*
176 =========================================================
177 */
179 
180  for( std::vector<ptwXYPoints *>::iterator iter = mFluxXY.begin( ); iter != mFluxXY.end( ); ++iter ) ptwXY_free( *iter );
181  for( std::vector<ptwXPoints *>::iterator iter = mGroupedFlux.begin( ); iter != mGroupedFlux.end( ); ++iter ) ptwX_free( *iter );
182 }
183 /*
184 =========================================================
185 */
187 
188  nfu_status status_nf;
189  ptwXYPoints *fluxXY;
190  ptwXPoints *groupedX;
191 
192  if( groupX == NULL ) return( NULL );
193  if( order < 0 ) order = 0;
194  if( order >= (int) mFluxXY.size( ) ) order = (int) mFluxXY.size( ) - 1;
195 
196  fluxXY = ptwXY_xSlice( mFluxXY[order], ptwXY_getXMin( ptwXY1 ), ptwXY_getXMax( ptwXY1 ), 10, 1, &status_nf );
197 // if( fluxXY == NULL ) smr_setReportError2( smr, smr_unknownID, 1, "ptwXY_xSlice error %d: %s", status_nf, nfu_statusMessage( status_nf ) );
198 
199  groupedX = ptwXY_groupTwoFunctions( ptwXY1, fluxXY, groupX, ptwXY_group_normType_norm, mGroupedFlux[order], &status_nf );
200  ptwXY_free( fluxXY );
201 // if( groupedX == NULL ) smr_setReportError2( smr, smr_unknownID, 1, "ptwXY_groupTwoFunctions error %d: %s", status_nf, nfu_statusMessage( status_nf ) );
202  return( groupedX );
203 }
GIDI::ptwXPoints * groupFunction(GIDI::statusMessageReporting *smr, GIDI::ptwXPoints *groupX, GIDI::ptwXYPoints *ptwXY1, int order) const
GIDI::ptwXPoints * groupFunction(GIDI::statusMessageReporting *smr, GIDI::ptwXYPoints *ptwXY1, double temperature, int order) const
double const * getEnergies(void) const
ptwXYPoints * ptwXY_createFrom_Xs_Ys(ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo, double biSectionMax, double accuracy, int64_t primarySize, int64_t secondarySize, int64_t length, double const *Xs, double const *Ys, nfu_status *status, int userFlag)
Definition: ptwXY_core.cc:126
int addFlux(GIDI::statusMessageReporting *smr, GIDI_settings_flux const &flux)
GIDI_settings_particle(int PoPId, bool transporting, int energyMode)
ptwXYPoints * ptwXY_clone(ptwXYPoints *ptwXY, nfu_status *status)
Definition: ptwXY_core.cc:208
void setGroup(GIDI_settings_group const &group)
ptwXYPoints * ptwXY_free(ptwXYPoints *ptwXY)
Definition: ptwXY_core.cc:574
int size(void) const
double getTemperature() const
GIDI_settings_processedFlux(GIDI_settings_flux const &flux, GIDI::ptwXPoints *groupX)
double const * getFluxes(void) const
ptwXPoints * ptwX_create(int64_t size, int64_t length, double const *xs, nfu_status *status)
Definition: ptwX_core.cc:50
ptwXPoints * ptwX_free(ptwXPoints *ptwX)
Definition: ptwX_core.cc:158
enum nfu_status_e nfu_status
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
double ptwXY_getXMin(ptwXYPoints *ptwXY)
Definition: ptwXY_core.cc:1206
GIDI_settings_processedFlux const * nearestFluxToTemperature(double temperature) const
ptwXPoints * ptwX_clone(ptwXPoints *ptwX, nfu_status *status)
Definition: ptwX_core.cc:88
double const * pointer(void) const
ptwXPoints * ptwXY_groupOneFunction(ptwXYPoints *ptwXY, ptwXPoints *groupBoundaries, ptwXY_group_normType normType, ptwXPoints *ptwX_norm, nfu_status *status)
int size(void) const
ptwXYPoints * ptwXY_xSlice(ptwXYPoints *ptwXY, double xMin, double xMax, int64_t secondarySize, int fill, nfu_status *status)
Definition: ptwXY_core.cc:274
ptwXPoints * ptwXY_groupTwoFunctions(ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, ptwXPoints *groupBoundaries, ptwXY_group_normType normType, ptwXPoints *ptwX_norm, nfu_status *status)
#define GIDI_settings_projectileEnergyMode_grouped
int initialize(int PoPId, bool transporting, int energyMode)
double ptwXY_getXMax(ptwXYPoints *ptwXY)
Definition: ptwXY_core.cc:1239
#define GIDI_settings_projectileEnergyMode_continuousEnergy