Skip to content

Commit

Permalink
Merge branch 'master' into 7277-safari-spellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
moellep authored Jan 31, 2025
2 parents 22d4e1d + 1133485 commit 61ac364
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
5 changes: 5 additions & 0 deletions sirepo/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pykern.pkcollections import PKDict
from pykern.pkdebug import pkdc, pkdlog, pkdp
import csv
import re

_ENCODINGS = ("cp1252", "utf-8", "utf-8-sig")

Expand All @@ -26,9 +27,13 @@ def read_as_number_list(path):

def read_as_list(path, data_type=str):
for e in _ENCODINGS:
skip_header = data_type != str
try:
res = []
for r in open_csv(path, encoding=e):
if skip_header and len(r) and re.search(r"[A-Za-z]", r[0]):
skip_header = False
continue
res.append([data_type(c) for c in r])
return res
except (TypeError, UnicodeDecodeError, ValueError):
Expand Down
5 changes: 5 additions & 0 deletions sirepo/package_data/static/css/openmc.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
.model-tallyReport-axis .sr-enum-button {
min-width: 4em;
}

tr.sr-inactive td {
opacity: 0.8;
font-style: italic;
}
2 changes: 1 addition & 1 deletion sirepo/package_data/static/html/openmc-visualization.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<th>σ</th>
</thead>
<tbody>
<tr data-ng-repeat="e in visualization.eigenvalue.slice(-visualization.eigenvalueHistory()) track by $index">
<tr data-ng-repeat="e in visualization.eigenvalue.slice(-visualization.eigenvalueHistory()) track by $index" data-ng-class="{'sr-inactive': ! e.val[1] }">
<td>{{ e.batch }}</td>
<td>{{ e.val[0] }}</td>
<td>{{ e.val[1] || 'N/A' }}</td>
Expand Down
4 changes: 2 additions & 2 deletions sirepo/package_data/static/json/openmc-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@
"ProbabilityDistribution": [
["None", "None"],
["discrete", "Discrete"],
["tabularFromFile", "From File"],
["legendre", "Legendre"],
["maxwell", "Maxwell"],
["muir", "Muir"],
["normal", "Normal"],
["powerLaw", "PowerLaw"],
["tabular", "Tabular"],
["tabularFromFile", "From File"],
["uniform", "Uniform"],
["watt", "Watt"]
],
Expand Down Expand Up @@ -518,7 +518,7 @@
},
"tabularFromFile": {
"_super": ["_", "model", "univariate"],
"file": ["File", "InputFile", "", "", false],
"file": ["CSV File", "InputFile", "", "A CSV file with two columns: (value, probability) which will be interpolated in a Linear-Linear manner.", false],
"interpolation": ["Interpolation", "Interpolation", "linear-linear"],
"ignore_negative": ["Ignore negative probabilities", "Boolean", "0"]
},
Expand Down
39 changes: 21 additions & 18 deletions sirepo/template/openmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def prepare_for_save(data, qcall):


def python_source_for_model(data, model, qcall, **kwargs):
return _generate_parameters_file(data)
return _generate_parameters_file(data, qcall=qcall)


def sim_frame(frame_args):
Expand Down Expand Up @@ -546,7 +546,7 @@ def _bin(val, mesh, idx):
)


def _generate_angle(angle):
def _generate_angle(angle, qcall):
if angle._type == "None":
return angle._type
args = []
Expand All @@ -555,7 +555,7 @@ def _generate_angle(angle):
elif angle._type == "monodirectional":
args.append(_generate_array(angle.reference_uvw))
elif angle._type == "polarAzimuthal":
args += [_generate_distribution(angle[v]) for v in ["mu", "phi"]]
args += [_generate_distribution(angle[v], qcall) for v in ["mu", "phi"]]
args.append(_generate_array(angle.reference_uvw))
else:
raise AssertionError("unknown angle type: {}".format(angle._type))
Expand All @@ -570,7 +570,7 @@ def _generate_call(name, args):
return "openmc.stats." + name[0].upper() + name[1:] + "(" + ", ".join(args) + ")"


def _generate_distribution(dist):
def _generate_distribution(dist, qcall):
import sirepo.csv

if dist._type == "None":
Expand All @@ -593,7 +593,8 @@ def _generate_distribution(dist):
_SIM_DATA.lib_file_abspath(
_SIM_DATA.lib_file_name_with_model_field(
dist._type, "file", dist.file
)
),
qcall=qcall,
)
)
).T.tolist():
Expand Down Expand Up @@ -686,7 +687,7 @@ def _generate_mesh(mesh):
"""


def _generate_parameters_file(data, run_dir=None):
def _generate_parameters_file(data, run_dir=None, qcall=None):
report = data.get("report", "")
if report == "tallyReport":
return ""
Expand Down Expand Up @@ -714,7 +715,7 @@ def _generate_parameters_file(data, run_dir=None):
v.runCommand = _generate_run_mode(data, v)
v.incomplete_data_msg = ""
v.materials = _generate_materials(data, v)
v.sources = _generate_sources(data, v)
v.sources = _generate_sources(data, v, qcall)
v.sourceFile = _source_filename(data)
v.maxSampleSourceParticles = SCHEMA.model.openmcAnimation.numSampleSourceParticles[
5
Expand Down Expand Up @@ -782,7 +783,7 @@ def _generate_save_weight_windows(data):
return ""


def _generate_source(source):
def _generate_source(source, qcall):
if source.get("type") == "file" and source.get("file"):
return f"openmc.IndependentSource(filename=\"{_SIM_DATA.lib_file_name_with_model_field('source', 'file', source.file)}\")"
if source.space._type == "box":
Expand All @@ -791,24 +792,26 @@ def _generate_source(source):
else:
c = "None"
return f"""openmc.IndependentSource(
space={_generate_space(source.space)},
angle={_generate_angle(source.angle)},
energy={_generate_distribution(source.energy)},
time={_generate_distribution(source.time)},
space={_generate_space(source.space, qcall)},
angle={_generate_angle(source.angle, qcall)},
energy={_generate_distribution(source.energy, qcall)},
time={_generate_distribution(source.time, qcall)},
strength={source.strength},
particle="{source.particle}",
constraints={c},
)"""


def _generate_sources(data, j2_ctx):
def _generate_sources(data, j2_ctx, qcall):
if not len(data.models.settings.sources):
j2_ctx.incomplete_data_msg += " No Settings Sources defined,"
return
return ",\n".join([_generate_source(s) for s in data.models.settings.sources])
return ",\n".join(
[_generate_source(s, qcall) for s in data.models.settings.sources]
)


def _generate_space(space):
def _generate_space(space, qcall):
if space._type == "None":
return space._type
args = []
Expand All @@ -818,14 +821,14 @@ def _generate_space(space):
_generate_array(space.upper_right),
]
elif space._type == "cartesianIndependent":
args += [_generate_distribution(space[v]) for v in ["x", "y", "z"]]
args += [_generate_distribution(space[v], qcall) for v in ["x", "y", "z"]]
elif space._type == "cylindricalIndependent":
args += [_generate_distribution(space[v]) for v in ["r", "phi", "z"]]
args += [_generate_distribution(space[v], qcall) for v in ["r", "phi", "z"]]
args.append(f"origin={_generate_array(space.origin)}")
elif space._type == "point":
args.append(_generate_array(space.xyz))
elif space._type == "sphericalIndependent":
args += [_generate_distribution(space[v]) for v in ["r", "theta", "phi"]]
args += [_generate_distribution(space[v], qcall) for v in ["r", "theta", "phi"]]
args.append(f"origin={_generate_array(space.origin)}")
else:
raise AssertionError("unknown space type: {}".format(space._type))
Expand Down
1 change: 1 addition & 0 deletions tests/csv_import_data/conformance.in/valid.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
header1, header2
50,200
60,166.6666667
70,142.8571429
Expand Down

0 comments on commit 61ac364

Please sign in to comment.