Skip to main content
10-Marble
March 21, 2014
Solved

ODE Solve Blocks with conditional statements used to switch equations

  • March 21, 2014
  • 1 reply
  • 10895 views

Werner;

The attached worksheet outlines my ultimate goal. This structure of the equations or requiems are called upon when particular conditions are met as shown on the diagrams and accompanying mass balance equations. This stormwater control structure is called a high early discharge tank. As you can see the tank has two chambers which become active when the water rises to particular levels in the first and second tanks. These different flow requiems which you have help me solve previously but this time all this knowledge needs to be stitched together. Unfortunately as you can see by the diagrams these must be switched on at certain times. Can you do this using a complex solve block? I thought one may be able to use an if statement in the solve block but this seems like it is not allowed. Is there another way to accomplish this for example can solve blocks become part of a programming block? What do you suggest? See the later parts of the worksheet for explanation.

You have been so helpful to me thus but once we solve this problem then my goal is achieved.

Kind regards, Mark

Best answer by Werner_E

Your still QSCout still looks very suspicous. Not sure what you have in mind with the interpolation you suggest, but it sounds like a big botch. So why not just use Qpipe for the whole range - I guess it won't effect the maximum flowrate you obviously are after. At least unless you succeed in putting those equatoons right. Flowrate shouldn't change apruptly in my opinion and so the values at the end of the different ranges should match. Maybe there is some kind of correction factor you can apply?

In yor new QSCout there is a new discrepancy as of your habit of using the same name for differnt things - you are using h_LC in the routine which is not available here (and also Ithink should not be used here). But h_LC is not only the function for the water height in the main chamber, its also a variable you have defined somewhere, a very small lenght of 1um.

I think the large chamber does empty itself see the revised worksheet.

??? No, it obviously doesn't do so now. there remains a height of about 10cm at then end.

The length of that pipe is only the thickness of the barrier wall but the way the functions are being called it is the same length as the outlet pipe. It would be silly to rewrite these functions but I don't know how to pass a revised length back to the velocity function. As you see

No I don't and I won't bother looking at those lengthy calculations in detail. But gererally speaking - if you want a calculation being doen for different values of a variable, you will have to turn the whole calculation in one function/program. You have to know which argumetns that function must have.

The last and final problem is a way to auto place a horizontal marker to show the peak discharge. As you can see from the final graph I am doing the placement manually because for some reason if I use Qscout(hsc(t) in the place holder I get an error.

Huh!?? What value of t you would have provided when you tried this?? Its silly, but those markers are not allowed to contain any units. So you may place QSCout(58min)/(L/s)in that marker placeholder. But first you would have to solve for the max time. One way is a differential appraoch like the following

SB1.png

What really bothers me is why the solve block fails if I slightly increase IN_SC(t). If I use the sheet use posted in your last reply I am not able to increase that inflow for more than 1.5% like so:

SB2.png

If I enlarge the length of the main chamber (L_t=20m, L_LC=19m) I am able to increase the inflow INSC up to 45%, then the solve block fails again. I am not sure why it is sfailing, but as changing the main chamber size affects it, I suppose it has soemthing to do with QLCout.

1 reply

25-Diamond I
March 21, 2014

Guess I have to give up, things are going to confusing for me.

Just some last remarks concerning your last solve block:

h is parameter of the solveblock function, so it must be either a constant value or a known function when it is passed as argument later. You pass 15mm, so its a constant. But in the block h is first treated as function and even worse as a function which is subject to change - you gave an ODE for h(t) and even an initial condition, but you don't solve for it. And to top it you use a line later h again as a constant scalar as parameter for Qwinflow. So what did you have in mind for h: known constant, known function, function to be solved for, constant argument for Qwinflow,...???

Also problem with hw. First you use it as a constant (if hw<Spilllevel) and then as a function to solve for.

It seems to me you are searching for two functions at the same time and your solve block needs no argument. You also have to define the derivatives of those functions for the whole range of time.

I see vaguely from the pictures and textbook snippets you provide what you may be after, but I don't recognize it in your solve block. I also guees the meaning of h has again changed, its not the water height above exterm weir anymore, But then I may be missing the point.

10-Marble
March 22, 2014

Werner;

I think I now know how to solve this problem at least conceptually. I don't think I need to couple ODEs in the solve block or try to incorporate tricky if statements to swap which equations the solve block needs to calculate at a given point in time. This is strategy is probably not even possible with Mathcad? So as you suggested I went through the worksheet and harmonized the variables. You were correct I was using different names for the same variable and I also had many redundant equations. It is surprising to me that the sheet worked at all. Lesson 1 be more meticulous.

Another surprise is that the cleanup didn't seem to alter the answer so I think I was simply using slightly differnt but redundant versions of the same equation. So here is what I think the solution is:

What I have to do is calculate the time at which the water spills over the internal weir. We already know how fast the water is rising in the first chamber (smallest tank). Next thing we know is the height of the spill level from the base of the tank i.e. the spill level creates a weir connection to the second tank chamber. The trick is that the water continues to rise over the barrier between the 2 chambers and thus creates the weir. The increasing depth above the weir then creates higher inflow to the large chamber (second tank). As you will see I have an array called X which is the depth of water at the weir location i.e. the height above the spill level.

The problem is one has a depth array but we need accompanying times at which these depths occur i.e. a time array. Once you calculate the time and knowing the depth then you can calculate the flow at each depth. Flow rate vs time array is a hydrograph (albeit a much smaller one than the main inflow hydrograph) which can then be routed to the second chamber i.e. water spills to the large chamber taking volume from the smaller chamber.

The problem is I do not know how to input multiple depth levels into solve block so that it can calculate the times at each depth level over the weir. I have an array of depths at the barrier location called X which I need to feed to the solve block so it can spit out the time array. However, my many attempts at this have failed. Is their a way to do this? See my X array and hw(t) function I have assigned hw(t)=X so that t can be calculated but for some reason this fails. Can you fix this and/or explain how this can be done?

Kind regards, Mark

25-Diamond I
March 22, 2014

Haven't looked at the sheet but from your description it sounds like you are trying to mix a continious, functional approach (beginning with the interpolation of inflow values to turn it into a function, up to solving the ODE for the height in the first chamber) with a discrete approach, using kind of a lookup table, vector. This may be a discrepancy hard to follow. I can image that either a discrete or a continuos appraoch might work from the very beginning, but I doubt about the mixture. I have not the time to play around with the sheet at the moment but for the functional appraoch you sure have a pair of coupled functions and you will have to solve fo both at the same time (two compartnent problems) - being it Outflow_of_chamber1 & Inflow_to_Chamber2 or the heights in both chambers. Both function will be coupled by the height Hw and the valve betwen the two chambers. Not sure if you can look at the two chambers as one bigger chamber when the hydrograph is falling and both chambers are emptying.

So working with if-statements seems inevitable, but they do not belong in the solve block but in the definition of the functions in play. So one way could be to setup Hm(t) as a Hm(t, Hf) and use it in the solve block as Hm(t,Hf(t)). Not sure if that will work as expected, though.