Suggestions for Temporal Superposition

Use this forum to post Vensim related questions.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

Obviously id depends on how big the FEA is, but if there's a good reason to use the above form, then it makes sense to do so.

The code in the Excel file still seems underspecified to me, because a bunch of the columns are numbers rather than expressions. However, if "invert" means that you just need:
i : (i1-i5)
y[i1] = x[i1]*z[i5]
y[i2] = x[i2]*z[i4]
...
y[i5] = x[i5]*z[i1]
that's easy. You can create a second subscript with the elements in reverse order, or use VECTOR ELM MAP for arbitrary access to elements. I'd probably prefer the latter. The offsets for the elements are as in your xfn, list1->vals[n_values - i - 1] * list2->vals.
Thank you Tom. I did mention to JJ that since these values you are see (in lieu of expressions) will be changing in Vensim, it is not possible to put them in as a subscript or a reverse subscript. This is why I am suggesting that the output of Vensim I am looking for, to run in an external expression, is the a list output from an auxiliary variable. I hope that makes sense. I have made that one simplification to provide constants instead of expressions in the Excel file as a demonstration, but the only thing that I need to achieve is demonstrated by the yellow highlighted columns.

I hope that makes sense.

As for the compiling, I will see what I can do. I think it is working, so far, as a cpp --. .dll, but the calculations themselves are suspect. If I do them by hand, the outputs from Vensim do not match. This is actually simple multiplication. The only difficult part is taking the g-function outputs (including all previous values), at each timestep, and feeding them to the function as a list, to be reversed, then multiplied by the difference in heat to the heat exchange (represented by "qi-qi-1").
data from the first 3 timesteps for "qi-qi-1":
0 = 0; 1 = 0; 2 = -5.79858; 3 = 1.55211

data from the first 3 timesteps for gfunction output:
0 = 2.49682; 1 = 2.49682; 2 = 2.49682; 3 = 2.49682

data from the output of REVERSE AND MULTIPLY SUM():
0 = 0; 1 = 0; 2 = -14.478; 3 = 15.278
You can see the values above from each time step appear as expected, but the product then sum of those values do not match. So, there is either something wrong with the function itself, or there is something going on with the integration that is not working well with my expectations.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

I may be dense, but I'm still not getting it. If you can pass two vectors into a function to muliply x[k]*z[k inverted] you can do the same with VECTOR ELM MAP. I can create an example if helpful.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

Hi Tom,

I guess it sounds like I am assuming that a vector cannot be read in during the simulation from a variable, but maybe you know how to do this. I am also a little skeptical that this can be done at each time step. If you have the time, I would like to see an example, maybe even one that will run for 10 timesteps or something of that nature.
LAUJJL
Senior Member
Posts: 1470
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by LAUJJL »

Hi

you must represent the vector as a stock, and at each time step, see which element of the vector must be made equal to some values of the variable and keep the other values of the vector not changing. i do not see the difficulty.

JJ
LAUJJL
Senior Member
Posts: 1470
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by LAUJJL »

Hi

you must represent the vector as a stock, and at each time step, see which element of the vector must be made equal to some values of the variable and keep the other values of the vector unchanged. I do not see the difficulty. I think that your problem has reached a level of complexity that is ahead of your capacity to understand it and especially to explain it to anybody. The solution is to simplify it until it becomes understandable.

JJ
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

Copy. I'm too stupid for Vensim. Good feedback.

Recalling again, the task is:

1. Take in two auxiliary variables as lists of outputs up to the present timestep, gives 2 lists
2. Reverse one of the 2 lists
3. Multiply the two lists by one another at the new index value of each list
4. Sum the new output (a third list)
5. Repeat for each timestep

While it is clear that this is too complex of an explanation for some, I am still seeking assistance.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

I have debugged this function more by handling null of NaN inputs as zeros. Now the function will run without crashing but the outputs are chaos and incorrect. I have not found a method of printing to the Vensim console. I only know how to print the error messages for checks. This function will run in Vensim, but again the outputs are wrong:

Code: Select all

double REVERSE_AND_MULTIPLY_SUM(VECTOR_ARG *list1, VECTOR_ARG *list2, int n_values) {
    // Validate
    if (!list1 || !list2 || n_values <= 0) {
        return 0.0; // Return 0 for invalid inputs
    }

    double cumulative_sum = 0.0; // Initiate

    // Reverse and multiply operation
    for (int i = 0; i < n_values; ++i) {
        double val1 = list1->vals[i];
        double val2 = list2->vals[n_values - 1 - i];

        // Multiply and add to cumulative sum
        cumulative_sum += val1 * val2;
    }

    return cumulative_sum; 
}
The outputs appear in the bottom row, with the inputs on the top two rows:
Time (Hour) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
"qi-qi-1" : current 0 0 -5.79858 1.55211 -1.51414 -1.71988 -0.409142 -0.978838 -2.77491 0.844003 0.764655 -0.285943 -1.21656 0.642707 2.1135 1.20256 0.480693 0.0732347 -0.207201 -0.476975 -0.744547
gfunction output : current 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682 2.49682
multiply sum : current 0 0 -14.478 15.278 3.21637 41.7655 -899986 1498.29 8.80024 M 2.20132 M 88.0003 M 2.23537 M 2.18458 M 9.89995 M 8770.88 72.7979 M 52555.1 28235.5 270512 42664.8 1.13001 M
So, yeah, I still need help on this function.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

A variant on representing the vector as a stock is using SAMPLE IF TRUE.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

I think it's possible to attach the debugger to the xfn dll when the model runs, but I don't remember the details. Then you could peek inside to observe execution.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

This submodel may do what is required.

There are two arbitrary input vectors that are sampled at at 10hr intervals, starting at time 10. The expected product[hN] is therefore approximately N plus some small random noise.

There are a couple unit errors in the inputs from my abuse of the PINK NOISE function, but I think the rest is OK, so those will disappear in use.
sum inv mult.mdl
(4.49 KiB) Downloaded 19 times
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

This turned out to be some pretty tricky subscripting, but I haven't thought of a nicer way to do it.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

Hi Tom,

Wow, that was a complex bit of subscript work. I am not sure if I would have ever been able to develop that in Vensim. Thank you for putting that model together. I have applied my data to the framework and am still reviewing it. I do have a question right away. Regarding the "vec sample interval" variable - I presume that I want to keep that with the model timestep, correct? I also assume that this variable defines when to sample and if the data is changing continuously, putting "vec sample interval" at a value greater than model time will degrade resolution. Am I on the right track?
data_vector_sampling.png
data_vector_sampling.png (139.02 KiB) Viewed 1121 times
When I leave the variable at 10, then the grey line in the plot results. When I change the variable to 1, then the green line results - for stuff*stuff. Although this is not temperature it is related and it does seem to make sense that the green line is accurate while the grey line is way off base. The blue line is the difference in energy input from the previous timestep (unimportant, other than to know it is the data). I wonder how the 10-hour time interval sample is so perfectly wrong that it becomes positive instead of negative, a trend opposite of the green line.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

Having reviewed this a little bit more, and taken the functions to the next step, it does indeed appear to be working correctly. I do have to debug some other things in my model that are failing for separate reasons before I can run the simulations to final time for confirmation, but this is very good sign.
temperature.png
temperature.png (56.1 KiB) Viewed 1119 times
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

It does look like this works by preserving history of the temperature accumulation in the heat exchangers over time, but I have had to add many more subscripts, since the intermittent sampling intervals are not providing accurate values. So, from Tom's example with 100 subscripts, I have increased it to 87600 (10 years). This is making Vensim run super slow, but also I cannot add more subscripts without crashing Vensim. For example, if I want to run 100 years (876,000 subscripts), Vensim simply crashes when I increase the subscript range. Does anyone have any advice on this, preferably to do with how to prevent Vensim from crashing before I even run a simulation? I am wondering if the inefficiency of adding this to the GUI means that I should go back to an external function.
I am running 6 cores for this.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

Added cores only help on parallel tasks like sensitivity analysis or MCMC.

Seems like it must be possible to do this with some kind of moving window. It just can't be the case that the system needs memory on all time scales from an hour to a year.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

I would support operating this on a moving window, but I am uncertain on how that would work. I have not been able to run the simulation beyond 4 years (35040 subscripts) without Vensim failing to save at the end. At 4 years, 95% of my memory is allocated at the end of the simulation.

I am attaching a version with artificial data to test. You can also see how slowly the simulation runs. I have kept it to one year for this example, with 2 years of subscripts. These can be manipulated to see the challenge for yourself.
Attachments
sum inv mult.mdl
(165 KiB) Downloaded 6 times
example.xlsx
(903.74 KiB) Downloaded 7 times
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

I think the data in the previous post should indicate an increasing trend, year over year, if someone were able to get it to run for an extended period of time.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

The model runs have also grown in size to about 4.5 GB for 3 - 4 years.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

You could use a savelist to exclude the large vector. However, I still believe that there's a conceptual flaw in the approach. Old terms need to be dropped.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

Here's a rolling version of my previous example of term storage with SAMPLE IF TRUE.
rolling sum inv mult.mdl
(2.87 KiB) Downloaded 22 times
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

Just for kicks, this is a guess at a FE version, abstracting away some of the details of length of loop and flow rate.
ground loop 1.mdl
(5.6 KiB) Downloaded 15 times
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

I understand the urge to assign a simplification of the seasonal sinusoidal pattern of heat transfer, but the ambient temperature of the earth eventually has very little overall impact on the borehole as heat injection and abstraction equilibrates the thermal plumes. The ambient temperature usually has the most impact on how quickly the system temperatures will saturate/degrade on decadal scales. These history terms are important to track for the long-term influence on the affected rock volumes. I have previously tried a simplistic assignment for production temperatures and it is highly influenced by the thermal diffusivity and idealized rock volume. The rock volume would need to change as a function of the diffusivity and the discretization would need to change with each variation of inputs for accuracy. Eventually the problem becomes so convoluted, and lacking in validity, that it is better to return to the temporal superposition quantification of q in versus q out, which leaves us with a remaining computational limit problem. T0, or the ambient ground temperature could be dumped for each 8760-hour period and restarted, therefore all subscripts less than 8760 might be reset, but I have not figured out how to do that yet. I will work on it a bit now, but we are on month X of this thread and my progress/contributions are very similar to day 1.
tomfid
Administrator
Posts: 3936
Joined: Wed May 24, 2006 4:54 am

Re: Suggestions for Temporal Superposition

Post by tomfid »

Not really knowing the system I can't say a lot, but it seems like the temporal resolution needed must decay with time and distance from the borohole. For example, yesterday's temperature at noon might have some influence within 1 meter, but the daily pattern a month or a year ago wouldn't make the slightest difference at 100m.

I'm not sure a hard reset, or the rolling reset in my version above, at 8761 hours is a good idea if saturation is a multiyear phenomenon.

Did you try the savelist?
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

Yea, saturation is a multi-year phenomenon, which is why most engineers are scared of geothermal heating and cooling. I will try the savelist next. First, I need to figure out what that means for this context. I will explore the docs.
geo_curious
Senior Member
Posts: 119
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Suggestions for Temporal Superposition

Post by geo_curious »

.
Post Reply