Page 1 of 1

Eliminating Subscript Dependency in Subsequent Equations

Posted: Sat Jan 11, 2025 7:34 pm
by geo_curious
Hi,

Relating to viewtopic.php?p=33432, I would like to take an output from an auxiliary variable that has a subscript dependency, placing it into a subsequent function without requiring the subsequent function to also be dependent on the subscript.

For example,
Where:

gfunction output[borehole array size] = gfunct subscript[borehole array size]

I would like to avoid subsequent dependency, using only the value of the output from the previous function, such as:

wall temperature = initial temp+temp change+((q/(2*pi*k)*gfunction output))

This does not appear to be possible without inheriting a subscript error. Is there a work around? I have so many dependencies, that I do not want to introduce an erroneous subscript requirement for each of many auxiliary variables such as the one shown here.

Re: Eliminating Subscript Dependency in Subsequent Equations

Posted: Mon Jan 13, 2025 11:42 pm
by tomfid
You can use VECTOR SELECT or SUM for this, combined with an indicator variable that shows which of the RHS elements to select.

Re: Eliminating Subscript Dependency in Subsequent Equations

Posted: Mon Jan 13, 2025 11:46 pm
by tomfid
k : k1-k10
y[k] = x[k]
y active[k] = IF THEN ELSE( k=3, 1, 0)
y out = SUM( y[k!]*y active[k!] )

Another option for picking a single value would be,

y out = VECTOR ELM MAP( y[k1], offset )

where offset is the index of the value you want as a 0-based offset from k1.

Re: Eliminating Subscript Dependency in Subsequent Equations

Posted: Sun Mar 02, 2025 8:47 pm
by geo_curious
So far as I can tell, it is not true that SUM() prevents the propagation of subscripts in subsequent equations. I cannot get anything to run, whatever the case, but here is one example where SUM() is doing nothing to prevent propagation of subscripts:

Gives "incorrect number of subscripts for gfunct subscript" error:
gfunct selected[borehole array size, Interval,Instance]= INITIAL(
sum(
IF THEN ELSE ( array size selected = array size[borehole array size!]
,gfunct subscript[borehole array size!, Interval!, Instance!]
,0)
))
~ Dmnl
~ |

Still requires (depends on) subscripts from gfunct selected and will not run:
borehole wall temp Tb[borehole array size,Interval,Instance]=
initial production temperature
+sum(gfunct selected*diff dQ[Interval!,Instance!])
*c0
~ Celsius
~ |

Also, it is a bit excruciating to have to come back to the forum every time there is an error with subscripts. The error handling message should read what the problem is specifically - like the number of subscripts expected or why else something is wrong, etc. That is a suggestion!

Re: Eliminating Subscript Dependency in Subsequent Equations

Posted: Sun Mar 02, 2025 9:08 pm
by Administrator
Try removing the @"[borehole array size, Interval,Instance]" from the left hand side of the equation for "gfunct selected".

gfunct selected= INITIAL(
sum(
IF THEN ELSE ( array size selected = array size[borehole array size!]
,gfunct subscript[borehole array size!, Interval!, Instance!]
,0)
))

Re: Eliminating Subscript Dependency in Subsequent Equations

Posted: Sun Mar 02, 2025 9:33 pm
by geo_curious
Removing the subscripts from the left hand side did not prevent the error. The equation still returns "Incorrect number of subscripts for -gfunct subscript-."

I am posting a smaller version of this model to troubleshoot here. A change from some posts that Tom had previously helped me work through is that this model is trying to select a borehole array size from table data, instead of using a fixed lookup. With that change I have the addition of one more subscript (array size), and now another error to figure out. Thank you for any assistance you might offer here.
subscript hand holding.mdl
(3.55 KiB) Downloaded 437 times
ground_response_functions.xlsx
(17.52 KiB) Downloaded 435 times

Re: Eliminating Subscript Dependency in Subsequent Equations

Posted: Sun Mar 02, 2025 10:39 pm
by geo_curious
Ok, I solved my own problem. The starting point of the subscript use needed to be added to the Excel data variable. I also omitted a few subequations in the first posting of the mdl. Here is the corrected .mdl, that will run.
subscript hand holding.mdl
(4.15 KiB) Downloaded 570 times