Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
I have a problem using a solve block with equations that change at a specific point in the solution. I've attached an example file (Mathcad Prime 3.1) showing the problem and how I've solved it. The scenario is two vessels connected in series. The first vessel is initially full of water while the second vessel is empty. At time = 0, a flow of a second fluid starts into vessel 1. The overflow from vessel 1 goes into vessel 2. When vessel 2 is filled, then the overflow from vessel 2 goes to a drain. I want to calculate the volume fraction of the second fluid in each vessel with time. The equation for the volume fraction in the second vessel changes once the vessel is filled (because it starts to drain.) The way I came up with to handle this is using the step function, but it does some strange things. I've included two solutions, the first showing the problem with the step function, the second showing my messy-looking way of handling the problem with the step function. I'm wondering if there is a better way to handle this.
thx
Mike
Solved! Go to Solution.
You can solve it in steps, three problems sequentially.
Many of us can't read a Prime 3.1 file. Could you also post it as a pdf.
Thanks for pointing out a better way to handle the tt calculation - I like that.
As far as the solution method, I assume the problem with the step function in the first case is the value of the argument [H-h2(t)] is fluctuating around 0 so the step function result is erratic. Forcing the step function argument to be reliably < 0 once vessel 2 is > 99% full [0.99H-h2(t)] in the second solution eliminates this problem. This introduces a slight error in the calculated result for F2, but this only exists for the time during which 0.99H < h2(t) < H.
Is there a better way to solve this system than using the step function?
The changes I see you made are to tighten the tolerances, and in the first solve block to vectorize the arguments of h2 = min(V2/A2, Q0*t/A2). I'm not sure what effect vectorization has, but it looks like the step function is well behaved - I think due to the tighter tolerances.
The problem is that the way the step function is defined in Mathcad, phi(0) = 0.5 rather than phi(0) = 0. My intent with using the step function is to turn the last term of the equation for F2 on or off, and phi(0) = 0.5 doesn't do that. Therefore, the result is still nonsensical. This is clear by looking at F1/V1. It can't be > 1; and by looking at h2 - it instantly --> 1, e.g. vessel 2 is instantly filled.
If the argument of the step function is modified as I did in the second block so that x < 0, and phi(x) = 0, then the result in the first solve block becomes meaningful.
I'm interpreting no suggestions on replacing the step function with some other approach to mean that there may not be a better way to handle this type of problem.
I do appreciate learning more of the fine points of MathCad - I'm a fairly new user and still on the learning curve with Mathcad's capabilities.
You can solve it in steps, three problems sequentially.
OK - that clearly is a good way to handle this. I was hoping for a single solve block, but this is much cleaner, and your result looks like what I expected. My solution from the 2nd solve block looks a bit odd at the early times which makes me concerned there is still something strange going on in my worksheet that I haven't figured out.
Of course, this is a simplified version of the problem I'm working on, but I think I can calculate the corresponding start and end times in my full problem, so I may be able to reliably break it up this way.
Thx for the feedback.