Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RunPython #468

Merged
merged 3 commits into from
Dec 18, 2023
Merged

RunPython #468

merged 3 commits into from
Dec 18, 2023

Conversation

llaniewski
Copy link
Member

This PR extends the RunR capabilities with Python execution through the reticulate. You can now execute Python code with <RunPython/> element, where Solver is exposed in the same way as in R.

Example

<?xml version="1.0"?>
<CLBConfig version="2.0" output="output/">
	<Geometry nx="1024" ny="100">
		<MRT><Box/></MRT>
		<WVelocity><Box nx="1"/></WVelocity>
		<EPressure><Box dx="-1"/></EPressure>
	</Geometry>
	<Model>
		<Param name="VelocityX" value="0.05"/>
		<Param name="Viscosity" value="0.01"/>
	</Model>
	<RunR Iterations="100">
		print(sum(Solver$Quantities$Rho))
	</RunR>
	<RunPython Iterations="100">
print(Solver.Quantities.Rho.sum())
	</RunPython>
	<Solve Iterations="1000"/>
</CLBConfig>

FYI: @TravisMitchell @shkodm @mdzik
I think with this present in the code we can get rid of the native Python support.

@TravisMitchell
Copy link
Member

I was already okay with removing native Python support but this also looks nice :).

@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4e28d4e) 44.30% compared to head (e096d7d) 44.30%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #468   +/-   ##
=======================================
  Coverage   44.30%   44.30%           
=======================================
  Files         169      169           
  Lines        7896     7896           
=======================================
  Hits         3498     3498           
  Misses       4398     4398           
Flag Coverage Δ
d2q9 30.39% <100.00%> (ø)
d2q9_bc 26.68% <100.00%> (ø)
d2q9_kuper 27.46% <100.00%> (ø)
d3q27_PSM_NEBB 36.00% <100.00%> (ø)
d3q27_pf_velocity 30.46% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shkodm
Copy link
Member

shkodm commented Dec 13, 2023

Very exciting, thanks @llaniewski ! Do you want me to test it using the two-phase fracture setup I was working on?

@TravisMitchell
Copy link
Member

@shkodm I think I would like you to test on the fracture setup, and maybe add to the multiphase tools repo as a demo for using it ;)

@llaniewski
Copy link
Member Author

llaniewski commented Dec 13, 2023

@shkodm That would be great. Hope this will simplify your setup a bit. edit: Of course, after you come back to the office.

@TravisMitchell @shkodm Some notes:

  1. Seems that the read-only part works quite well, but setting stuff back in the Solver object doesn't really work well (eg. Solver.Geometry.BOUNDARY[0,0] = "None"). I think this would mean much more effort.
  2. R objects are auto converted to python. Matrices become numpy arrays, so that's good. But the factor arrays seem to be converted to vectors of strings.

@shkodm
Copy link
Member

shkodm commented Dec 18, 2023

@llaniewski I tested, and it seems to work for my purposes now (plotting phase field on the aperture plot). We can probably merge this one directly now and then create follow up PRs if I find some issues.

Regarding notes:

  1. I don't think I need it right now, but setting stuff back would be cool. Maybe it is possible to do it in the follow up PR?
  2. Factor array converted to strings is actually good, because of Inconsistency between RunR export and VTK #470

@llaniewski llaniewski merged commit fea68c2 into CFD-GO:master Dec 18, 2023
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants