How to code convergence...without looping?

Hi all!

I am building a closed polysurface in GH using an input surface and a numeric parameter. The final volume depends on this input parameter.

I would like to adjust the input parameter until my object reaches a target volume. I can do this manually with a slider but I would like to toggle a button and have it adjust automatically. Better yet, when I change the target volume it adjusts the parameter automatically.

I tried writing a python component, but I am having trouble as it won’t let me feed the volume of the object back to the script: it complains that the object depends on itself.

I feel I am missing a “grasshopper way” of approaching this problem. In “traditional, non-grasshopper” python I would do a for loop, and break out once I am within a chosen tolerance.

Thoughts? Ideas? Thansk!

Hello
use a range component for the surface (lets name X), calculate the volumes (let name Z)
Make points with X and Z, Make a polyline or better a curve. Make a plane XY with a height equal to the volume you want, search intersection with your curves, the X coordinate of the intersections will be good approximation of what you want.

1 Like

Hi Laurent - yes, I thought of something like that: create a list of input values, and corresponding volumes, and then find the input value that matches the volume I want. The problem is, I still need to manually input the value back into my script to create the final object, which defeats the purpose. I want this to be done automatically, so every time I adjust something I don’t have to go in and adjust my input parameter again.

I have no magical solution,
or you do n times the simulation and pick one of the best solution. Or you make a function, a cluster. One cluster for the resolution and one for the final results.
So lots of calculation and more simple
Or less calculations and more components
or more pure maths and analytical calculus!

Isn’t the Galapagos plugin for this sort of thing?

Interesting thought, but WAY overkill for what I need right now. (Although this may come in handy down the road when I add parameters).

My problem is a very smoothly behaved volume curve: increase the parameter, the volume increases, decrease the parameter, volume decreases. This is the perfect behavior for a Newton-Raphson type solver (which is very easy to code in Python) and should converge within 10-15 iterations. The problem is I can’t seem to figure out how to code it since to create the object I need an initial parameter, which isn’t available yet since the code hasn’t run yet. I get this error: 1. Recursive data stream found, this component depends on itself

I totally like Laurent first comment method, in fact i use that often…
By what you say, it seems you need a 3D version of what Laurent said.
You might end up “mapping” every possible solutions beforehand and then only pick the combination of parameters you need, so building the geometry only once.

Anyway, whould you mind share your definition?

Seems an interesting problem, but it is hard to help with purely abstract concepts…

Thanks, Laurent, Martyn, and Riccardo for your feedback - it is much appreciated.

Here is a screenshot of the script. As simple as it gets! If I change the sinkage value, the height of the water changes. I then create a boolean intersection and get a new volume that represents the immersed volume.

What I want to do is hit a button, and have the sinkage automatically change so that the volume difference between the actual volume, and the target volume, is zero. I know I can just slide the slider now, but in the future, I will have at least two sliders, and things will get more complicated. If I can solve this simple problem, then the rest should be easy.

I haven’t found a simple way of doing this…!

gh_sink_solver_v1.gh (13.4 KB) Screenshot 2021-04-28 14.33.21|690x344