Skip to content

Commit

Permalink
merge from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Aug 25, 2016
1 parent 97bfb43 commit e9b07fa
Show file tree
Hide file tree
Showing 14 changed files with 555 additions and 161 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ if (BUILD_EXAMPLES)
target_link_libraries(mcplexample_read mcpl)
add_executable(mcplexample_write "${SRCEX}/rawexample_writemcpl.c")
target_link_libraries(mcplexample_write mcpl)
install(TARGETS mcplexample_read mcplexample_write ${INSTDEST})
add_executable(mcplexample_filter "${SRCEX}/rawexample_filtermcpl.c")
target_link_libraries(mcplexample_filter mcpl)
install(TARGETS mcplexample_read mcplexample_write mcplexample_filter ${INSTDEST})
endif()

if (BUILD_FAT)
Expand Down
2 changes: 2 additions & 0 deletions FILES
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ src/mcnpssw/ : MCPL hooks for MCNP in C, in the form of a few .h/.c file
by MCNP.
src/mcstas/ : No actual code is here, just a small reminder of how the
MCPL plugin shipped with McStas can be used.
src/mcxtrace/ : No actual code is here, just a small reminder of how the
MCPL plugin shipped with McXtrace can be used.
src_fat/ : Various "fat" versions of files from the above directories
under src/, for convenience. These files are automatically
generated and might also contain code under the zlib
Expand Down
9 changes: 6 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ programmes might require additional permissions and licenses, as mandated by the
third-party programme in question. This is outside the scope of the MCPL
project, and the authors of MCPL can not be held responsible for any such usage.

If you use MCPL in your scientific work, we would appreciate if you would
remember to cite the following reference in your writings:
A substantial effort went into developing MCPL. If you use it for your work, we
would appreciate it if you would use the following reference in your work:


[ Paper not yet published, please find draft and instructions ]
[ for how to cite on https://mctools.github.io/mcpl/ ]

(submission in progress - please contact [email protected] for details).

=====================
=== The CC0 license ===
Expand Down
36 changes: 19 additions & 17 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@ format with lists of particle state information, for interchanging and
reshooting events between various Monte Carlo simulation applications.

Hooks for Geant4 (geant4.cern.ch) and MCNP (SSW files) are included in this
distribution as well. Hooks for McStas (mcstas.org) are already included
directly upstream in McStas. A few examples of how to use the Geant4 hooks, or
how to interact with MCPL files from standalone C code, are also provided. Refer
to the FILES file for more information about included files, and refer to the
comment at the top of the CMakeLists.txt file for how to build and install with
CMake.
distribution as well. Hooks for McStas (mcstas.org) and McXtrace (mcxtrace.org)
are already included directly upstream in those applications. A few examples of
how to use the Geant4 hooks, or how to interact with MCPL files from standalone
C code, are also provided. Refer to the FILES file for more information about
included files, and refer to the comment at the top of the CMakeLists.txt file
for how to build and install with CMake.

MCPL and most code distributed here was written 2015-2016 by Thomas Kittelmann
([email protected]). The MCNP-SSW converters were written in close
collaboration with Esben Klinkby ([email protected]), and the McStas converters were
written by Erik Knudsen ([email protected]) and Peter Willendrup
collaboration with Esben Klinkby ([email protected]), and the McStas and McXtrace
converters were written by Erik Knudsen ([email protected]) and Peter Willendrup
([email protected]).

See the file LICENSE for usage conditions.

A substantial effort went into developing MCPL. If you use it for your work, we
would appreciate it if you would use the following reference in your work:


[ Paper not yet published, please find draft and instructions ]
[ for how to cite on https://mctools.github.io/mcpl/ ]


The latest version of MCPL and further instructions and documentation can be
found at the websites: http://cern.ch/mcpl and http://mcpl.mccode.org/.
found at https://mctools.github.io/mcpl/.

Note that instructions for installation and setup of third-party products like
Geant4, McStas and MCNP are beyond the scope of this file. But for Geant4, a few
extra tips are given here, to avoid typical issues encountered by new users
(this was tested with Geant4 10.0.p03):

1) Refer to the instructions at http://geant4.cern.ch/
2) Provide the -DGEANT4_INSTALL_DATA=ON flag to CMake during installation.
3) After installation, source <geant4installdir>/bin/geant4.sh to set up
a proper runtime environment.
Geant4, McStas and MCNP are beyond the scope of this file. Please refer to the
products own instructions for more information.
31 changes: 22 additions & 9 deletions examples/rawexample_writemcpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include <stdlib.h>
#include <memory.h>


double randuniform(double a, double b)
{
return a + rand() * (b-a) / RAND_MAX;
}

int main(int argc,char**argv) {

if (argc!=2) {
Expand All @@ -32,7 +38,6 @@ int main(int argc,char**argv) {

mcpl_outfile_t f = mcpl_create_outfile(filename);
mcpl_hdr_set_srcname(f,"my_cool_program_name");
mcpl_enable_universal_pdgcode(f,2112);//all particles are neutrons

// By default, floating point numbers will be stored in single precision and
// neither polarisation nor user-flags will be stored in the file. These
Expand All @@ -43,6 +48,10 @@ int main(int argc,char**argv) {
// mcpl_enable_polarisation(f);
// mcpl_enable_doubleprec(f);

// If all particles will be of the same type, optimise the file a bit by:
//
// mcpl_enable_universal_pdgcode(f,2112);//all particles are neutrons

//We can add comments (strings) to the header. It is always a good idea to add
//comments explaining things like coordinate system, contents of user-flags
//(if any), and what the values in the "weight" field means exactly.:
Expand All @@ -56,26 +65,31 @@ int main(int argc,char**argv) {

//Allocate the particle structure we will use during the simulation loop
//to register particle data in the output file:
mcpl_particle_t * particle = (mcpl_particle_t*)calloc(sizeof(mcpl_particle_t),1);
mcpl_particle_t * particle = mcpl_get_empty_particle(f);

//Simulation loop, modify the particle struct and add to the file as many
//times as needed (here everything will simply be filled with some stupid
//random numbers):
for (int i = 0; i < 1000; ++i) {
//particle type:
if (rand()%2)
particle->pdgcode = 2112;//50% neutrons
else
particle->pdgcode = 22;//50% gammas
//position in centimeters:
particle->position[0] = rand();
particle->position[1] = rand();
particle->position[2] = rand();
particle->position[0] = randuniform(-100,100);
particle->position[1] = randuniform(-100,100);
particle->position[2] = randuniform(-100,100);
//kinetic energy in MeV:
particle->ekin = rand();
particle->ekin = randuniform(0.001,10);
//momentum direction (unit vector):
particle->direction[0] = 0.0;
particle->direction[1] = 0;
particle->direction[2] = 1.0;
//time in milliseconds:
particle->time = rand();
particle->time = randuniform(0,100);
//weight in unspecified units:
particle->weight = rand();
particle->weight = randuniform(0.01,10);
//modify userflags and polarisation (what units?) as well, if enabled.

//Finally, add the particle to the file:
Expand All @@ -84,7 +98,6 @@ int main(int argc,char**argv) {

//At the end, remember to properly close the output file (and cleanup mem if desired):
mcpl_closeandgzip_outfile(f);
free(particle);

//Note: By calling mcpl_closeandgzip_outfile rather than mcpl_close_outfile,
//the output file will (in most cases) end up being gzipped, resulting in a
Expand Down
58 changes: 31 additions & 27 deletions src/mcnpssw/sswmcpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int ssw2mcpl2(const char * sswfile, const char * mcplfile,
printf("Error: specified configuration file %s does not contain title found in ssw file: \"%s\".\n",inputdeckfile,ssw_title(f));
return 0;
}
mcpl_hdr_add_data(mcplfh, "mcnp_config_file", (uint32_t)cfgfile_lbuf,(const char *)cfgfile_buf);
mcpl_hdr_add_data(mcplfh, "mcnp_input_deck", (uint32_t)cfgfile_lbuf,(const char *)cfgfile_buf);
free(cfgfile_buf);
}

Expand Down Expand Up @@ -199,13 +199,14 @@ int ssw2mcpl2(const char * sswfile, const char * mcplfile,
actual_filename[0]='\0';
strcat(actual_filename,tmp);

int did_gzip = 0;
if (opt_gzip)
mcpl_closeandgzip_outfile(mcplfh);
did_gzip = mcpl_closeandgzip_outfile_rc(mcplfh);
else
mcpl_close_outfile(mcplfh);
ssw_close_file(f);

printf("Created %s%s\n",actual_filename,(opt_gzip?".gz":""));
printf("Created %s%s\n",actual_filename,(did_gzip?".gz":""));
free(actual_filename);
return 1;
}
Expand All @@ -227,18 +228,18 @@ void ssw2mcpl_parse_args(int argc,char **argv, const char** infile,
progname = progname ? progname + 1 : argv[0];
printf("Usage:\n\n");
printf(" %s [options] input.ssw [output.mcpl]\n\n",progname);
printf("Converts the Monte Carlo particles in the input.ssw file (MCNP Surface \n"
printf("Converts the Monte Carlo particles in the input.ssw file (MCNP Surface\n"
"Source Write format) to MCPL format and stores in the designated output\n"
"file (defaults to \"output.mcpl\").\n"
"\n"
"Options:\n"
"\n"
" -h, --help : Show this usage information.\n"
" -d, --double : Enable double-precision storage of floating point values.\n"
" -s, --surf : Store SSW surface id information in the MCPL userflags.\n"
" -s, --surf : Store SSW surface IDs in the MCPL userflags.\n"
" -n, --nogzip : Do not attempt to gzip output file.\n"
" -c FILE : Embed entire configuration FILE used to produce input.sww\n"
" in the MCPL header.\n"
" -c FILE : Embed entire configuration FILE (the input deck)\n"
" used to produce input.ssw in the MCPL header.\n"
);
exit(0);
}
Expand Down Expand Up @@ -475,8 +476,6 @@ int mcpl2ssw(const char * inmcplfile, const char * outsswfile, const char * refs
rawtype = conv_mcnp6_pdg2ssw(mcpl_p->pdgcode);
else
rawtype = conv_mcnpx_pdg2ssw(mcpl_p->pdgcode);
if (rawtype==2)
rawtype=0;
if (!rawtype) {
++skipped_nosswtype;
if (skipped_nosswtype<=100) {
Expand Down Expand Up @@ -555,30 +554,31 @@ int mcpl2ssw_app_usage( const char** argv, const char * errmsg ) {
progname = progname ? progname + 1 : argv[0];
printf("Usage:\n\n");
printf(" %s [options] <input.mcpl> <reference.ssw> [output.ssw]\n\n",progname);
printf("Converts the Monte Carlo particles in the input MCPL file to SSW format (MCNP\n"
"Surface Source Write) and stores the result in the designated output file (defaults\n"
"to \"output.ssw\").\n"
printf("Converts the Monte Carlo particles in the input MCPL file to SSW format\n"
"(MCNP Surface Source Write) and stores the result in the designated output\n"
"file (defaults to \"output.ssw\").\n"
"\n"
"In order to do so and get the details of the SSW format correct, the user must also\n"
"provide a reference SSW file from the same approximate setup (MCNP version, input\n"
"deck...) where the new SSW file is to be used. The reference SSW file can of course\n"
"be very small, as only the file header is important (the new file essentially gets\n"
"a copy of the header found in the reference file, except for certain fields related\n"
"to number of particles whose values are changed).\n"
"In order to do so and get the details of the SSW format correct, the user\n"
"must also provide a reference SSW file from the same approximate setup\n"
"(MCNP version, input deck...) where the new SSW file is to be used. The\n"
"reference SSW file can of course be very small, as only the file header is\n"
"important (the new file essentially gets a copy of the header found in the\n"
"reference file, except for certain fields related to number of particles\n"
"whose values are changed).\n"
"\n"
"Finally, one must pay attention to the Surface ID assigned to the particles in the\n"
"resulting SSW file: Either the user specifies a global one with -s<ID>, or it is assumed\n"
"that the MCPL userflags field in the input file is actually intended to become the\n"
"Surface ID. Note that not all MCPL files have userflag fields and that valid Surface\n"
"IDs are integers in the range 1-999999.\n"
"Finally, one must pay attention to the Surface ID assigned to the\n"
"particles in the resulting SSW file: Either the user specifies a global\n"
"one with -s<ID>, or it is assumed that the MCPL userflags field in the\n"
"input file is actually intended to become the Surface ID. Note that not\n"
"all MCPL files have userflag fields and that valid Surface IDs are\n"
"integers in the range 1-999999.\n"
"\n"
"Options:\n"
"\n"
" -h, --help : Show this usage information.\n"
" -d, --double : Enable double-precision storage of floating point values.\n"
" -s<ID> : All particles in the resulting SSW file will have this surface ID.\n"
" -l<LIMIT> : Limit the maximum number of particles to put in the SSW file (note\n"
" that SSW files only supports up to 2147483647 particles).\n"
" -s<ID> : All particles in the SSW file will get this surface ID.\n"
" -l<LIMIT> : Limit the number of particles transferred to the SSW file\n"
" (defaults to 2147483647, the maximal SSW capacity).\n"
);
return 0;
}
Expand Down Expand Up @@ -624,6 +624,10 @@ int mcpl2ssw_parse_args(int argc,const char **argv, const char** inmcplfile,
return mcpl2ssw_app_usage(argv,"Bad option: missing number");
}
}

} else if (n==6 && strcmp(a,"--help")==0) {
mcpl2ssw_app_usage(argv,0);
return -1;
} else if (n>=1&&a[0]!='-') {
if (*outsswfile)
return mcpl2ssw_app_usage(argv,"Too many arguments.");
Expand Down
12 changes: 8 additions & 4 deletions src/mcnpssw/sswread.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ ssw_file_t ssw_open_file(const char * filename)
/* printf("ssw_open_file: Found aids = '%s'\n",f->aids); */

if ( f->is_mcnp6 ) {
if ( strcmp(f->vers,"6")!=0 ) {
printf("ssw_open_file error: Unsupported MCNP6 source version :\"%s\" (must be \"6\")\n",f->vers);
if ( strcmp(f->vers,"6")!=0 && strcmp(f->vers,"6.mpi")!=0 ) {
printf("ssw_open_file error: Unsupported MCNP6 source version :\"%s\" (must be \"6\" or \"6.mpi\")\n",f->vers);
return ssw_openerror(f,"ssw_open_file error: Unsupported MCNP6 source version");
}
} else {
Expand Down Expand Up @@ -536,7 +536,7 @@ int32_t conv_mcnpx_ssw2pdg(int32_t c)
if (c<=34)
return conv_mcnpx_to_pdg_0to34[c];
if (c>=401&&c<=434)
return - conv_mcnpx_to_pdg_0to34[c%100];
return c==402 ? 22 : - conv_mcnpx_to_pdg_0to34[c%100];
int32_t sign = 1;
if (c%1000==435) {
sign = -1;
Expand All @@ -554,6 +554,10 @@ int32_t conv_mcnpx_ssw2pdg(int32_t c)
long ZM1 = c%1000;
return sign * (1000000000 + (ZM1+1)*10000 + A*10);
}
//Retry without non-type related parts:
int j = (c%1000)/100;
if (j==2||j==6)
return conv_mcnpx_ssw2pdg(c-200);
return 0;
}

Expand All @@ -568,7 +572,7 @@ int32_t conv_mcnp6_ssw2pdg(int32_t c)
//Note that A (see below) has been observed in SSW files to have non-zero
//values for ptype<37 as well, so don't require A, Z or S to be 0 here.
int32_t p = conv_mcnp6_to_pdg_0to36[ptype];
return antibit ? -p : p;
return (antibit&&p!=22) ? -p : p;
}
if (ptype==37) {
int A = c%512; c /= 512;
Expand Down
Loading

0 comments on commit e9b07fa

Please sign in to comment.