pyopensn.solver.LBSProblem
- class pyopensn.solver.LBSProblem
Base class for all linear Boltzmann problems.
Wrapper of
opensn::LBSProblem.- ComputeFissionProduction(self: pyopensn.solver.LBSProblem, scalar_flux_iterate: str) float
Computes the total fission production (nu*fission).
- Parameters:
scalar_flux_iterate ({'old', 'new'}) –
- Specifies which scalar flux vector to use in the calculation.
’old’: Use the previous scalar flux iterate.
’new’: Use the current scalar flux iterate.
- Returns:
The total fission production.
- Return type:
float
- Raises:
ValueError – If scalar_flux_iterate is not ‘old’ or ‘new’.
- ComputeFissionRate(self: pyopensn.solver.LBSProblem, scalar_flux_iterate: str) float
Computes the total fission rate.
- Parameters:
scalar_flux_iterate ({'old', 'new'}) –
- Specifies which scalar flux vector to use in the calculation.
’old’: Use the previous scalar flux iterate.
’new’: Use the current scalar flux iterate.
- Returns:
The total fission rate.
- Return type:
float
- Raises:
ValueError – If scalar_flux_iterate is not ‘old’ or ‘new’.
- CreateAndWriteSourceMoments(self: pyopensn.solver.LBSProblem, file_base: str) None
Write source moments from latest flux iterate to file.
- Parameters:
file_base (str) – File basename.
- CreateFieldFunction(self: pyopensn.solver.LBSProblem, name: str, xs_name: str, power_normalization_target: float = -1.0) pyopensn.fieldfunc.FieldFunctionGridBased
Create a named scalar field function derived from a 1D XS or
power.- Parameters:
name (str) – Name to assign to the returned field function.
xs_name (str) – Built-in 1D XS name, custom XS name, or the special value
power.power_normalization_target (float, default=-1.0) – If positive, scale the derived field function so that the raw power field would integrate to this total power.
Notes
The returned field function is created on demand from the current scalar-flux iterate. For ordinary XS names this computes
sum_g xs[g] * phi_gat each node.The returned field function is a snapshot of the solver state at creation time; it is not refreshed automatically if the solver state changes. It supports
CanUpdate()andUpdate()while its owning problem is still alive. CallingUpdate()explicitly recomputes the same field function from the solver’s latest state.If
xs_name == "power", the same power-generation formula used elsewhere by the solver is applied on demand.If
power_normalization_target > 0, the returned field function is scaled using the power implied by the current scalar flux. This scaling affects only the returned field function; it does not mutate the solver’s internalphivectors.The returned field function is a fresh object created for this call. It is not automatically updated by later solves or timesteps.
- GetPhiNewLocal(self: pyopensn.solver.LBSProblem) memoryview
Get the current scalar flux iterate (local vector).
- Returns:
Memory view of the local new scalar flux vector.
- Return type:
memoryview
- GetPhiOldLocal(self: pyopensn.solver.LBSProblem) memoryview
Get the previous scalar flux iterate (local vector).
- Returns:
Memory view of the local old scalar flux vector.
- Return type:
memoryview
- GetScalarFluxFieldFunction(self: pyopensn.solver.LBSProblem, only_scalar_flux: bool = True) list
Return scalar-flux or flux-moment field functions grouped by energy group.
- Parameters:
only_scalar_flux (bool, default=True) – If True, returns only the zeroth moment (scalar flux) field function for each group. If False, returns all moment field functions for each group.
- Returns:
If
only_scalar_flux=True:result[g]is the scalar-flux field function for groupg.If
only_scalar_flux=False:result[g][m]is the field function for groupgand momentm.- Return type:
Union[List[pyopensn.fieldfunc.FieldFunctionGridBased], List[List[pyopensn.fieldfunc.FieldFunctionGridBased]]]
Notes
Field functions are created on demand from the current solver state.
The returned field functions are snapshots of the solver state at creation time; they are not refreshed automatically if the solver state changes.
They support
CanUpdate()andUpdate()while their owning problem is still alive. CallingUpdate()explicitly refreshes the same field-function object from the solver’s latest state.Calling
GetScalarFluxFieldFunction(only_scalar_flux=False)creates all requested moments from the currentphiiterate at the time of the call.In the nested form (
only_scalar_flux=False), the moment index varies fastest within each group (inner index = moment, outer index = group).
- GetTime(self: pyopensn.solver.LBSProblem) float
Get the current simulation time in seconds.
- GetTimeStep(self: pyopensn.solver.LBSProblem) float
Get the current timestep size.
- IsAdjoint(self: pyopensn.solver.LBSProblem) bool
Return
Trueif the problem is in adjoint mode, otherwiseFalse.
- IsTimeDependent(self: pyopensn.solver.LBSProblem) bool
Return
Trueif the problem is in time-dependent mode, otherwiseFalse.
- ReadAngularFluxes(self: opensn::DiscreteOrdinatesProblem, file_base: str) None
Read angular fluxes from file.
- Parameters:
file_base (str) – File basename.
- ReadFluxMoments(self: pyopensn.solver.LBSProblem, file_base: str, single_file_flag: bool) None
Read flux moment data.
- Parameters:
file_base (str) – File basename.
single_file_flag (bool) – True if all flux moments are in a single file.
- ReadFluxMomentsAndMakeSourceMoments(self: pyopensn.solver.LBSProblem, file_base: str, single_file_flag: bool) None
Read flux moments and compute corresponding source moments.
- Parameters:
file_base (str) – File basename.
single_file_flag (bool) – True if all flux moments are in a single file.
- ReadSourceMoments(self: pyopensn.solver.LBSProblem, file_base: str, single_file_flag: bool) None
Read source moments from file.
- Parameters:
file_base (str) – File basename.
single_file_flag (bool) – True if all source moments are in a single file.
- SetAdjoint(self: pyopensn.solver.LBSProblem, adjoint: bool = True) None
Set forward/adjoint transport mode.
- Parameters:
adjoint (bool, default=True) –
Trueenables adjoint mode andFalseenables forward mode.
Notes
- This is one of two supported mode-setting paths in Python:
options={'adjoint': ...}in the problem constructor.SetAdjoint(...)(this method).
- If this changes mode, OpenSn performs a full mode-transition reset:
Materials are reinitialized in the selected mode.
Point and volumetric sources are cleared.
Boundary conditions are cleared.
Scalar and angular flux vectors are zeroed.
If this is called with the same mode as the current setting, no reset is performed.
The block-id to cross-section map is preserved across the transition. However, the mode change is applied to the mapped
MultiGroupXSobjects themselves. If those objects are shared with other problems, they observe the same mode toggle.- After a mode change, reapply the desired driving terms before solving, typically:
This routine is intentionally destructive with respect to source/boundary/flux state to avoid hidden coupling between forward and adjoint setups.
- SetForward(self: pyopensn.solver.LBSProblem) None
Set forward transport mode.
Equivalent to
SetAdjoint(False).
- SetPointSources(self: pyopensn.solver.LBSProblem, **kwargs) None
Set or clear point sources.
- Parameters:
clear_point_sources (bool, default=False) – If true, all current the point sources of the problem are deleted.
point_sources (List[pyopensn.source.PointSource]) – List of new point sources to be added to the problem.
- SetVolumetricSources(self: pyopensn.solver.LBSProblem, **kwargs) None
Set or clear volumetric sources.
- Parameters:
clear_volumetric_sources (bool, default=False) – If true, all current the volumetric sources of the problem are deleted.
volumetric_sources (List[pyopensn.source.VolumetricSource]) – List of new volumetric sources to be added to the problem.
- SetXSMap(self: pyopensn.solver.LBSProblem, **kwargs) None
Replace the block-id to cross-section map.
- Parameters:
xs_map (List[Dict]) –
- A list of block-id to cross-section mapping dictionaries. Each dictionary supports:
- block_ids: List[int] (required)
Mesh block ids to associate with the cross section.
- xs: pyopensn.xs.MultiGroupXS (required)
Cross section object.
Notes
The problem is refreshed immediately after replacing the map. Material metadata, precursor storage, GPU carriers, and derived solver state owned by the concrete problem are rebuilt for the new cross sections.
If
options.use_precursors=True, this flag remains active across XS-map changes even when the current map has no precursor-bearing material. In that case delayed-neutron source terms are simply inactive until a later map provides precursor data again.Existing precursor concentrations are remapped by local cell and precursor-family index. When the new material for a cell has fewer precursor families, extra old families are dropped. When it has more families, newly introduced families are initialized to zero. If a cell changes through a material with zero precursors, the precursor history for that cell is discarded and any later reintroduced precursor families start from zero.
If any fissionable material in the new map contains delayed-neutron precursor data and
options.use_precursors=True, all fissionable materials in the map must contain precursor data. Non-fissionable materials may have zero precursors.Forward/adjoint mode toggles via
LBSProblem.SetAdjoint()do not change this map. TheMultiGroupXSobjects themselves are mutable and shared by pointer. If the sameMultiGroupXShandle is shared across multiple problems, toggling adjoint mode in one problem also changes the transport mode seen by the others.
- WriteAngularFluxes(self: opensn::DiscreteOrdinatesProblem, file_base: str) None
Write angular flux data to file.
- Parameters:
file_base (str) – File basename.
- WriteFluxMoments(self: pyopensn.solver.LBSProblem, file_base: str) None
Write flux moments to file.
- Parameters:
file_base (str) – File basename.
- ZeroPhi(self: pyopensn.solver.LBSProblem) None
Zero the scalar-flux vectors (
phi_oldandphi_new) in-place.