Skip to content

Commit

Permalink
config-generator: added checkpoints and NLM filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Horn committed Aug 13, 2024
1 parent ce36ec5 commit c42c63e
Show file tree
Hide file tree
Showing 8 changed files with 43,938 additions and 14 deletions.
1 change: 1 addition & 0 deletions examples/config-generator/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/__pycache__
.venv
!requirements.txt
!assets/*
21,954 changes: 21,954 additions & 0 deletions examples/config-generator/assets/CheckpointSimpleMD_10000_periodic_0.checkpoint

Large diffs are not rendered by default.

21,954 changes: 21,954 additions & 0 deletions examples/config-generator/assets/CheckpointSimpleMD_10000_reflecting_0.checkpoint

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/config-generator/assets/configuration_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@
"selected": true,
"value": false
},
{
"value": "nlm",
"label": "non-local means"
},
{
"value": "gauss",
"label": "2D gaussian"
},
{
"value": "nlm",
"label": "non-local means"
}
]
},
Expand Down
5 changes: 1 addition & 4 deletions examples/config-generator/assets/couette.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@
</molecular-dynamics>

<filter-pipeline>
<per-instance output = "md" >
{filtering}
</per-instance>

{per-instance-filtering}
<post-multi-instance output="md"></post-multi-instance>
</filter-pipeline>
</scenario-configuration>
23 changes: 19 additions & 4 deletions examples/config-generator/src/generators/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@ def apply(partial_xml, get_config_value) -> None:
filtering = get_config_value(key)

xml_2d_gaussian = """
<per-instance output = "gaussXY" >
<per-instance output="md">
<gaussXY filtered-values="macro-mass macro-momentum">
<gauss dim="0" sigma="1" extrapolation="mirror" />
<gauss dim="1" sigma="1" extrapolation="mirror" />
</gaussXY>
</per-instance>
""".strip()

xml_nlm = """
<per-instance output="nlm-junction">
<prefilter filtered-values="macro-mass macro-momentum">
<gauss dim="0" sigma="1" extrapolation="mirror" />
<gauss dim="1" sigma="1" extrapolation="mirror" />
<gauss dim="2" sigma="1" extrapolation="mirror" />
</prefilter>
<nlm-junction filtered-values="macro-mass macro-momentum" input="md prefilter">
<NLM time-window-size="5" sigsq="10" hsq="20" sigsq_rel="0.05" hsq_rel="0.1" />
</nlm-junction>
</per-instance>
""".strip()

if filtering == False:
filter_xml = ""
per_instance_filtering_xml = "<per-instance output=\"md\"></per-instance>"
elif filtering == "gauss":
filter_xml = xml_2d_gaussian
per_instance_filtering_xml = xml_2d_gaussian
elif filtering == "nlm":
per_instance_filtering_xml = xml_nlm
else:
raise NotImplementedError(key + " = " + filtering)

partial_xml.substitute("filtering", filter_xml)
partial_xml.substitute("per-instance-filtering", per_instance_filtering_xml)
print("Substituted filtering pipeline")
5 changes: 4 additions & 1 deletion examples/config-generator/src/generators/solver_cfd.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
def validate(get_config_value) -> str:
"""MaMiCo config validation:
The analytical CFD solver does not support two-way coupling.
Only the OpenFOAM solver should be used with two-way coupling.
"""
key = __name__.split(".")[-1]
solver = get_config_value(key)
use_2way_coupling = get_config_value("coupling_2way")
if solver == "analytical" and use_2way_coupling:
return f"Cannot use 2-way coupling with analytical CFD solver."
return f"Cannot use two-way coupling with analytical CFD solver."
if solver != "foam" and use_2way_coupling:
return f"OpenFOAM solver should be used for two-way coupling."
return None


Expand Down
2 changes: 1 addition & 1 deletion examples/config-generator/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def validate(configs: list) -> str:
)
except AttributeError:
print(
f"FIXME: Could not invoke validation for generator \"{config['key']}\""
f"Could not invoke validation for generator \"{config['key']}\"", file=sys.stderr,
)
continue
if validation_error is not None:
Expand Down

0 comments on commit c42c63e

Please sign in to comment.