smash.Model.set_serr_sigma_parameters#
- Model.set_serr_sigma_parameters(key, value)[source]#
Set the values of a Model structural error sigma parameter.
This method performs an in-place operation on the Model object.
- Parameters:
- keystr
The name of the structural error sigma parameter.
- valuefloat or
numpy.ndarray
The value(s) to set to the structural error sigma parameter. If the value is a
numpy.ndarray
, its shape must be broadcastable into the structural error sigma parameter shape.
See also
Model.get_serr_sigma_parameters
Get the values of a Model structural error sigma parameter.
Model.serr_sigma_parameters
Model structural error sigma parameters.
Examples
>>> from smash.factory import load_dataset >>> setup, mesh = load_dataset("cance") >>> model = smash.Model(setup, mesh)
Set a specific value to a structural error sigma parameter vector
>>> model.set_serr_sigma_parameters("sg0", 2)
Access its value
>>> model.get_serr_sigma_parameters("sg0") array([2., 2., 2.], dtype=float32)
Set a vector with a shape equivalent to the structural error sigma parameter
Get the structural error sigma parameter size (equivalent to the number of gauge
model.mesh.ng
)>>> size = model.get_serr_sigma_parameters("sg0").size >>> size 3
Generate the vector
>>> vec = np.arange(1, size + 1) >>> vec array([1, 2, 3])
Set to the structural error sigma parameter the vector
>>> model.set_serr_sigma_parameters("sg0", vec) >>> model.get_serr_sigma_parameters("sg0") array([1., 2., 3.], dtype=float32)
Note
This method is equivalent to directly slicing the
serr_sigma_parameters.values
array (as shown below) and change the values but is simpler andsafer
to use.Access the structual error sigma parameter keys
>>> model.serr_sigma_parameters.keys array(['sg0', 'sg1'], dtype='<U3')
Get the index of the structural error sigma parameter
'sg0'
>>> ind = np.argwhere(model.serr_sigma_parameters.keys == "sg0").item() >>> ind 0
Slice the
serr_sigma_parameters.values
array on the last axis and change its values>>> model.serr_sigma_parameters.values[..., ind] = 0.5 >>> model.serr_sigma_parameters.values[..., ind] array([[0.5, 0.5, 0.5]], dtype=float32)
Warning
In that case, there’s no problem to set the value
0.5
to the structural error sigma parameter'sg0'
, but each structural error sigma parameter has a feasibility domain, and that outside this domain, the model cannot run. For example, the feasibility domain of'sg0'
is \(]0, +\inf[\).Trying to set a negative value to the strutural error sigma parameter
'sg0'
without the setter>>> model.serr_sigma_parameters.values[..., ind] = -1 >>> model.serr_sigma_parameters.values[..., ind] array([[-1., -1., -1.]], dtype=float32)
No particular problem doing this but trying with the setter
>>> model.set_serr_sigma_parameters("sg0", -1) ValueError: Invalid value for model serr_sigma_parameter 'sg0'. serr_sigma_parameter domain [-1, -1] is not included in the feasible domain ]0, inf[
Finally, trying to run the Model with a negative value set to the structural error sigma parameter
'sg0'
leads to the same error>>> model.forward_run() ValueError: Invalid value for model serr_sigma_parameter 'sg0'. serr_sigma_parameter domain [-1, -1] is not included in the feasible domain ]0, inf[