优化仿真求解性能并修复流量闭合问题(初版)
This commit is contained in:
1 parent
57b459bc72
commit
5332a788f3
55 files changed
+8973
-549
No files matched your search
@@ -166,6 +166,77 @@ class SimulationPerformancePipelineTests(unittest.TestCase):
|
||||
self.assertGreater(len(snapshot["properties"]), 0)
|
||||
self.assertGreater(snapshot["propertyOutermostNs"], 0)
|
||||
|
||||
def test_audit_property_totals_match_run_local_cache(self) -> None:
|
||||
script = textwrap.dedent(
|
||||
"""
|
||||
import json
|
||||
|
||||
from app.simulation.components.amesim.media.mediums import (
|
||||
AmesimHeliumPengRobinsonMedium,
|
||||
)
|
||||
from app.simulation.performance import profile_run
|
||||
from app.simulation.property_cache import property_cache_run
|
||||
|
||||
medium = AmesimHeliumPengRobinsonMedium()
|
||||
pressure = 15.3e6
|
||||
temperature = 293.15
|
||||
volume = 0.057
|
||||
with property_cache_run() as cache:
|
||||
assert cache is not None
|
||||
with profile_run() as trace:
|
||||
density = medium.density(pressure, temperature)
|
||||
medium.density(pressure, temperature)
|
||||
medium.isentropic_density_pressure_factor(
|
||||
pressure, temperature, 1.0e6
|
||||
)
|
||||
medium.isentropic_density_pressure_factor(
|
||||
pressure, temperature, 1.0e6
|
||||
)
|
||||
enthalpy = medium.specific_enthalpy_at_pressure(
|
||||
pressure, temperature
|
||||
)
|
||||
medium.temperature_from_pressure_enthalpy(pressure, enthalpy)
|
||||
medium.temperature_from_pressure_enthalpy(pressure, enthalpy)
|
||||
mass = density * volume
|
||||
energy = mass * medium.specific_internal_energy_at_pressure(
|
||||
pressure, temperature
|
||||
)
|
||||
medium.properties_from_mU(mass, energy, volume)
|
||||
medium.properties_from_mU(mass, energy, volume)
|
||||
cache_info = cache.info()
|
||||
snapshot = trace.snapshot()
|
||||
cached_properties = [
|
||||
metrics
|
||||
for metrics in snapshot["properties"].values()
|
||||
if metrics["cacheLookups"] > 0
|
||||
]
|
||||
print(json.dumps({
|
||||
"cacheHits": cache_info.hits,
|
||||
"cacheMisses": cache_info.misses,
|
||||
"propertyHits": sum(item["cacheHits"] for item in cached_properties),
|
||||
"propertyMisses": sum(item["cacheMisses"] for item in cached_properties),
|
||||
}))
|
||||
"""
|
||||
)
|
||||
environment = os.environ.copy()
|
||||
environment["SIMULATIONAPP_PROFILE"] = "audit"
|
||||
environment["SIMULATIONAPP_PROPERTY_CACHE"] = "on"
|
||||
completed = subprocess.run(
|
||||
[sys.executable, "-c", script],
|
||||
cwd=PROJECT_ROOT,
|
||||
env=environment,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
)
|
||||
totals = json.loads(completed.stdout)
|
||||
|
||||
self.assertGreater(totals["cacheHits"], 0)
|
||||
self.assertGreater(totals["cacheMisses"], 0)
|
||||
self.assertEqual(totals["cacheHits"], totals["propertyHits"])
|
||||
self.assertEqual(totals["cacheMisses"], totals["propertyMisses"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user