Struct WeightWindow

pub struct WeightWindow {
Show 30 fields pub f: u8, pub iv: u8, pub ni: u8, pub ne: usize, pub nt: usize, pub nr: u8, pub nwg: u8, pub probid: String, pub nfx: usize, pub nfy: usize, pub nfz: usize, pub ncx: usize, pub ncy: usize, pub ncz: usize, pub x0: f64, pub y0: f64, pub z0: f64, pub x1: f64, pub y1: f64, pub z1: f64, pub x2: f64, pub y2: f64, pub z2: f64, pub e: Vec<f64>, pub t: Vec<f64>, pub qps_x: Vec<[f64; 3]>, pub qps_y: Vec<[f64; 3]>, pub qps_z: Vec<[f64; 3]>, pub weights: Vec<f64>, pub particle: u8,
}
Expand description

Mesh-based global weight window data for WWINP/WWOUT/WWONE

The WeightWindow data structure represents a set of weight windows for a single mesh and particle type.

Writers are implemented to generate the standardised UTF-8 file format for WWINP/WWOUT/WWONE files for direct use in MCNP simulations.

§Memory use

Large weight window meshes are approximately ~8 bytes per unique voxel

§Field naming

While unreadable, the WeightWindow fields correspond closely to the internal FORTRAN MCNP variables outlined in the Appendicies of the MCNPv6.2 and MCNPv6.3 user manuals.

This really helps to maintain consistency with the underlying data.

§Formatting

All formats will match fortran formats in the table below, explicitly using the scientific number representation for any genral ‘g’ format.

BlockFormatVariable List
14i10, 20x, a19if iv ni nr probid
17i10nt(1) … nt(ni) [if iv=2]
17i10ne(1) … ne(ni)
16g13.5nfx nfy nfz x0 y0 z0
16g13.5ncx ncy ncz nwg [if nr=10]
16g13.5ncx ncy ncz x1 y1 z1 [if nr=16]
16g13.5x2 y2 z2 nwg [if nr=16]
26g13.5x0 (qx(i), px(i), sx(i), i=1,ncx)
26g13.5y0 (qy(i), py(i), sy(i), i=1,ncy)
26g13.5z0 (qz(i), pz(i), sz(i), i=1,ncz)
36g13.5t(i,1) … t(i,nt(i)) [if nt(i)>1]
36g13.5e(i,1) … e(i,ne(i))
36g13.5(((w(i,j,k,l,1) j=1,nft), k=1,ne(i)), l=1,nt(i))

Formatting is done in blocks for consistency with the specifications provided in the user manual appendices.

Fields§

§f: u8

File type, manual states unused, so always 1.

§iv: u8

Time-dependent windows flag, 1=no 2=yes.

§ni: u8

Number of particle types

§ne: usize

Number of energy bins for each particle type

§nt: usize

Number of time bins for each particle type

§nr: u8

Number of ‘words’ to describe mesh. rec=10, cyl/sph=16

§nwg: u8

Mesh type 1=rec, 2=cyl, 3=sph

§probid: String

Problem description, 19-char string, can be blank.

§nfx: usize

Total number of fine mesh points in i

§nfy: usize

Total number of fine mesh points in j

§nfz: usize

Total number of fine mesh points in k

§ncx: usize

Total number of coarse mesh points in i

§ncy: usize

Total number of coarse mesh points in j

§ncz: usize

Total number of coarse mesh points in k

§x0: f64

Origin i coordinate

§y0: f64

Origin j coordinate

§z0: f64

Origin k coordinate

§x1: f64

Axis i coordinate

§y1: f64

Axis j coordinate

§z1: f64

Axis k coordinate

§x2: f64

Vec i coordinate

§y2: f64

Vec j coordinate

§z2: f64

Vec k coordinate

§e: Vec<f64>

Upper energy bounds for each particle type

§t: Vec<f64>

Upper time bounds for each particle type if nt(i)>1

§qps_x: Vec<[f64; 3]>

List of (qx(i), px(i), sx(i)) tuples for i=1,ncx

§qps_y: Vec<[f64; 3]>

List of (qy(i), py(i), sy(i)) tuples for i=1,ncy

§qps_z: Vec<[f64; 3]>

List of (qz(i), pz(i), sz(i)) tuples for i=1,ncz

§weights: Vec<f64>

Flattened vector of lower weights for each voxel, for each energy bin, for each time bin

§particle: u8

Retain particle type for use in multi-particle sets

Implementations§

§

impl WeightWindow

pub fn write(&self, path: &str)

Write the weight window to the standard fromatted UTF-8 file

Generates the WWINP/WWOUT/WWONE formatted files for direct input to MCNP simulations.

Tools to combine weight window sets for multiple particles are provided see write_multi_particle().

pub fn scale(&mut self, factor: f64)

Multiply all weights by a constant factor

This is just a blanket multiplication that applies to every weight across all energy/time groups and particle types.

let mut wwout = WeightWindow {
    weights: vec![0.2, 0.15, 0.4],
    ..Default::default()
};

// Double every weight
wwout.scale(2.0);

assert_eq!(wwout.weights, vec![0.4, 0.3, 0.8])

pub fn non_analogue_percentage(&self) -> f64

Calculate number of non-zero weights

Useful common sense value for checking the conversion to weights and that successive weight windows are imporving. Do not expect it to reach 100% if the mesh geometry covers any areas of zero importance for a given particle type.

let wwout = WeightWindow {
    weights: vec![0.2, 0.15, 0.0, 0.0],
    ..Default::default()
};

assert_eq!(wwout.non_analogue_percentage(), 50.0)

pub fn file_content(&self) -> String

Generate file content as a string (not for large files)

Build a string for the full wwout file. Can be useful for small files and quick checks. However, this can end up duplicating a lot of data and the memory usage could be large for a significant number of weights.

pub fn etijk_from_cell_index( &self, idx: usize, ) -> (usize, usize, usize, usize, usize)

Find the (e,t,i,j,k) indicies for a given cell index

pub fn voxel_index_from_etijk( &self, e_idx: usize, t_idx: usize, i_idx: usize, j_idx: usize, k_idx: usize, ) -> usize

Convert indexed bins to a voxel index

pub fn voxel_index_from_cell_index(&self, idx: usize) -> usize

Convert from a cell index to a voxel index

Generally useful for weight windows to vtk plotting orders.

§

impl WeightWindow

pub fn block_1_header(&self) -> String

Only the formatted header String

pub fn block_1(&self) -> String

Block 1 formatted String of common data for all combined window sets

pub fn block_2(&self) -> String

Block 2 formatted String containing all the coarse mesh bounds

pub fn block_3(&self) -> String

Block 3 formatted String of weight windows for each voxel group

Trait Implementations§

§

impl Clone for WeightWindow

§

fn clone(&self) -> WeightWindow

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for WeightWindow

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for WeightWindow

§

fn default() -> WeightWindow

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.