-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
622 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
python/examples/.ipynb_checkpoints/NDItk-getting-started-example-1-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "f53a715b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"# a recursive function to find all files with a given extension in a directory\n", | ||
"def getFilesInFolder( directory, extension ) :\n", | ||
"\n", | ||
" files = os.listdir( directory )\n", | ||
" everything = list()\n", | ||
"\n", | ||
" for entry in files :\n", | ||
"\n", | ||
" file = os.path.join( directory, entry )\n", | ||
"\n", | ||
" if os.path.isdir( file ) :\n", | ||
"\n", | ||
" everything += getFilesInFolder( file, extension )\n", | ||
"\n", | ||
" else :\n", | ||
"\n", | ||
" everything.append( file )\n", | ||
"\n", | ||
" return [ file for file in everything if file.endswith( extension ) ]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "74836354", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"FAILED /Users/wim/Projects/libraries/ndi/mt80_30/t20/50118.851nm\n", | ||
"-------------------------\n", | ||
" 1 files\n", | ||
" 1 failed\n", | ||
"elapsed time = 0.000673 s\n", | ||
"-------------------------\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import NDItk\n", | ||
"import time\n", | ||
"\n", | ||
"path = '/Users/wim/Projects/libraries/ndi/mt80_30'\n", | ||
"files = getFilesInFolder( path, '1001.851nm' )\n", | ||
"failed = []\n", | ||
"\n", | ||
"start = time.perf_counter()\n", | ||
"for file in files :\n", | ||
"\n", | ||
" try :\n", | ||
"\n", | ||
" table = NDItk.MultigroupTable.from_file( file )\n", | ||
"\n", | ||
" except :\n", | ||
"\n", | ||
" print( 'FAILED', file )\n", | ||
" failed.append( file )\n", | ||
"\n", | ||
"end = time.perf_counter()\n", | ||
"\n", | ||
"print( '-------------------------' )\n", | ||
"print( '{:4} files'.format( len( files ) ) )\n", | ||
"print( '{:4} failed'.format( len( failed ) ) )\n", | ||
"print( 'elapsed time = {:.3} s'.format( end - start ) )\n", | ||
"print( '-------------------------' )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9d108125", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "f53a715b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"# a recursive function to find all files with a given extension in a directory\n", | ||
"def getFilesInFolder( directory, extension ) :\n", | ||
"\n", | ||
" files = os.listdir( directory )\n", | ||
" everything = list()\n", | ||
"\n", | ||
" for entry in files :\n", | ||
"\n", | ||
" file = os.path.join( directory, entry )\n", | ||
"\n", | ||
" if os.path.isdir( file ) :\n", | ||
"\n", | ||
" everything += getFilesInFolder( file, extension )\n", | ||
"\n", | ||
" else :\n", | ||
"\n", | ||
" everything.append( file )\n", | ||
"\n", | ||
" return [ file for file in everything if file.endswith( extension ) ]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "74836354", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"-------------------------\n", | ||
"13455 files\n", | ||
" 0 failed\n", | ||
"elapsed time = 5.79e+02 s\n", | ||
"-------------------------\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import NDItk\n", | ||
"import time\n", | ||
"\n", | ||
"path = '/Users/wim/Projects/libraries/ndi/mt80'\n", | ||
"files = getFilesInFolder( path, 'nm' )\n", | ||
"failed = []\n", | ||
"\n", | ||
"start = time.perf_counter()\n", | ||
"for file in files :\n", | ||
"\n", | ||
" try :\n", | ||
"\n", | ||
" table = NDItk.MultigroupTable.from_file( file )\n", | ||
"\n", | ||
" except :\n", | ||
"\n", | ||
" print( 'FAILED', file )\n", | ||
" failed.append( file )\n", | ||
"\n", | ||
"end = time.perf_counter()\n", | ||
"\n", | ||
"print( '-------------------------' )\n", | ||
"print( '{:4} files'.format( len( files ) ) )\n", | ||
"print( '{:4} failed'.format( len( failed ) ) )\n", | ||
"print( 'elapsed time = {:.3} s'.format( end - start ) )\n", | ||
"print( '-------------------------' )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9d108125", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import NDItk\n", | ||
"table = NDItk.MultigroupTable.from_file( '/Users/wim/Projects/libraries/ndi/mt80_30/t22/38086.853nm' )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3ed6d2e8", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
python/src/multigroup/FissionNeutronSpectrumMatrix.python.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// system includes | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
// local includes | ||
#include "NDItk/multigroup/FissionNeutronSpectrumMatrix.hpp" | ||
#include "tools/views/views-python.hpp" | ||
#include "definitions.hpp" | ||
#include "read.hpp" | ||
|
||
// namespace aliases | ||
namespace python = pybind11; | ||
|
||
namespace multigroup { | ||
|
||
void wrapFissionNeutronSpectrumMatrix( python::module& module, python::module& ) { | ||
|
||
// type aliases | ||
using Record = njoy::NDItk::multigroup::FissionNeutronSpectrumMatrix; | ||
using FissionType = njoy::NDItk::multigroup::FissionType; | ||
|
||
// wrap views created by this record | ||
|
||
// create the record | ||
python::class_< Record > record( | ||
|
||
module, | ||
"FissionNeutronSpectrumMatrix", | ||
"A fission neutron spectrum matrix record for multigroup neutron and photon data" | ||
); | ||
|
||
// wrap the record | ||
record | ||
.def( | ||
|
||
python::init< FissionType, std::vector< double > >(), | ||
python::arg( "type" ), python::arg( "values" ), | ||
"Initialise the record\n\n" | ||
"Arguments:\n" | ||
" self the record\n" | ||
" values the fission neutron spectrum matrix values" | ||
) | ||
.def_property_readonly( | ||
|
||
"type", | ||
&Record::type, | ||
"The fission type defined by this record" | ||
) | ||
.def_property_readonly( | ||
|
||
"number_groups", | ||
&Record::numberGroups, | ||
"The number of groups defined by this record" | ||
) | ||
.def_property_readonly( | ||
|
||
"matrix", | ||
[] ( const Record& self ) -> DoubleRange2D | ||
{ return self.matrix(); }, | ||
"The matrix defined by this record" | ||
) | ||
.def_static( | ||
|
||
"from_string", | ||
[] ( const std::string& string, unsigned int number ) -> Record | ||
{ return readWithFissionSubtype< Record >( string, number ); }, | ||
python::arg( "string" ), python::arg( "number" ), | ||
"Read the record from a string\n\n" | ||
"An exception is raised if something goes wrong while reading the\n" | ||
"record\n\n" | ||
"Arguments:\n" | ||
" string the string representing the record\n" | ||
" number the number of groups" | ||
); | ||
|
||
// add standard record definitions | ||
addStandardRecordDefinitions< Record, DoubleRange >( record ); | ||
} | ||
|
||
} // multigroup namespace |
Oops, something went wrong.