mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
refactor MCPL file read part of FileSource
A new constructor is added to FileSource that reads from a given MCPL-file.
This commit is contained in:
parent
76e726b527
commit
bdc76d95fc
1 changed files with 73 additions and 0 deletions
|
|
@ -437,6 +437,79 @@ CustomSourceWrapper::~CustomSourceWrapper()
|
|||
}
|
||||
|
||||
|
||||
MCPLFileSource::~MCPLFileSource(){
|
||||
mcpl_close_file(mcpl_file);
|
||||
}
|
||||
|
||||
SourceSite MCPLFileSource::sample(uint64_t* seed) const
|
||||
{
|
||||
size_t i_site = sites_.size() * prn(seed);
|
||||
return sites_[i_site];
|
||||
}
|
||||
|
||||
void MCPLFileSource::read_source_bank(vector<SourceSite> &sites_)
|
||||
{
|
||||
sites_.resize(n_sites);
|
||||
for (int i=0;i<n_sites;i++){
|
||||
sites_[i]=read_single_particle();
|
||||
}
|
||||
}
|
||||
|
||||
SourceSite MCPLFileSource::read_single_particle() const
|
||||
{
|
||||
SourceSite omc_particle_;
|
||||
const mcpl_particle_t *mcpl_particle;
|
||||
// extract particle from mcpl-file
|
||||
mcpl_particle=mcpl_read(mcpl_file);
|
||||
// check if it is a neutron, photon, electron, or positron. Otherwise skip.
|
||||
int pdg=mcpl_particle->pdgcode;
|
||||
while ( pdg!=2112 && pdg!=22 && pdg!=11 && pdg!=-11) {
|
||||
mcpl_particle=mcpl_read(mcpl_file);
|
||||
pdg=mcpl_particle->pdgcode;
|
||||
//should check for file exhaustion. This could happen if particles are other than
|
||||
//neutrons, photons, electrons, or positrons.
|
||||
}
|
||||
|
||||
switch(pdg){
|
||||
case 2112:
|
||||
omc_particle_.particle=ParticleType::neutron;
|
||||
break;
|
||||
case 22:
|
||||
omc_particle_.particle=ParticleType::photon;
|
||||
break;
|
||||
case 11:
|
||||
omc_particle_.particle=ParticleType::electron;
|
||||
break;
|
||||
case -11:
|
||||
omc_particle_.particle=ParticleType::positron;
|
||||
break;
|
||||
}
|
||||
|
||||
//particle is good, convert to openmc-formalism
|
||||
omc_particle_.r.x=mcpl_particle->position[0];
|
||||
omc_particle_.r.y=mcpl_particle->position[1];
|
||||
omc_particle_.r.z=mcpl_particle->position[2];
|
||||
|
||||
omc_particle_.u.x=mcpl_particle->direction[0];
|
||||
omc_particle_.u.y=mcpl_particle->direction[1];
|
||||
omc_particle_.u.z=mcpl_particle->direction[2];
|
||||
|
||||
//mcpl stores kinetic energy in MeV
|
||||
omc_particle_.E=mcpl_particle->ekin*1e6;
|
||||
//mcpl stores time in ms
|
||||
omc_particle_.time=mcpl_particle->time*1e-3;
|
||||
omc_particle_.wgt=mcpl_particle->weight;
|
||||
omc_particle_.delayed_group=0;
|
||||
return omc_particle_;
|
||||
}
|
||||
#endif //OPENMC_MCPL
|
||||
=======
|
||||
>>>>>>> 380cfc150b449ef56debb5261caa010a52c42bdd
|
||||
=======
|
||||
#endif
|
||||
>>>>>>> 71568d4f4 (refactor MCPL file read part of FileSource)
|
||||
>>>>>>> 55f2be19e (refactor MCPL file read part of FileSource)
|
||||
|
||||
//==============================================================================
|
||||
// Non-member functions
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue