cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Vector input into solve block

DJF
16-Pearl
16-Pearl

Vector input into solve block

I have a model (compressible flow through o r i f i c e s in series) that utilizes a solve block to find the mass flow and pressures.  It works great for any single point analysis. I then tried to feed it multiple flow areas as a vector and haven't gotten it to work.  It's slightly unique in that I have an IF inside the solve block. I have tried to vectorize everything and rearrange the IF, all to no avail.

PDF and 3.1 file attached.

P.S.  I know that I can rework this to use the solve block as a function and call it that way to repeat calculations.  That's just not what I'm after today.

P.P.S This is a dumbed-down version just to demonstrate the problem.  No need to correct my physics as I know they're off.

Basically, I don't think Mathcad likes this IF inside solve block when trying to solve for a vector of inputs.

picv.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
DJF
16-Pearl
16-Pearl
(To:DJF)

A-ha!  I believe I have it.  By telling mathcad which P_ratio2 to use (through a for loop) it can then figure out the rest.  It can't compare a vector to a scalar, so we have to feed it one value.  This is what solved it.

vec5.jpg

Note: Several variations on this do not work (e.g. storing the results into m_dot_i or using P_2o_i)

Thanks for the assistance.

View solution in original post

8 REPLIES 8
Fred_Kohlhepp
23-Emerald I
(To:DJF)

Does it work if you vectorize the whole constraint?

Make the arrow cover the m_dot too.

While it will solve, it does not solve correctly.  I believe that as soon as I do what you suggest the whole equation is no longer recognized.  I get the same incorrect answers if I just delete the offending equations. I also noted that if I vectorize the entirety of other constraints that the "constraints" bar no longer enveloped them.  They were in no mans land and don't seem to effect the output (or lead to an error).  

vec2.jpg

MJG
18-Opal
18-Opal
(To:DJF)

I can't open your file to play with it.  Can you convert your if statement to Boolean algebra?

Instead of this:

If A <= B

  T

Else

  F

Write this:

(A<=B)*T+(A>B)*F

Possibly even just converting the programming if to an if function would work:

if(A<=B,T,F)

DJF
16-Pearl
16-Pearl
(To:MJG)

Your suggestions, unfortunately, didn't work.  But, they led me to a clue.  I replaced the current IF statement by something that was obviously true (e.g. if D_bore < 1000 in) and it works beautifully.  So, it seems to be balking at the IF.  I'm thinking it's confused because there would be multiple values of P_ratio2 and it doesn't know how to vectorize.  Adding vectorize to the IF doesn't seem to resolve it though.

MJG
18-Opal
18-Opal
(To:DJF)

This might be your best option:

dferry wrote:

P.S.  I know that I can rework this to use the solve block as a function and call it that way to repeat calculations
DJF
16-Pearl
16-Pearl
(To:MJG)

Yes, that's a project for another day.  What you aren't seeing is the rest of the program that would make this a bigger job than it might appear.  However, I think we're on the right track. I found this thread which I think is relevant.  Although I haven't yet gotten Werner's g4(x) program to work.I'm not sure something like that can go inside a solve block.

Vectors and proraming in a fuction

vec4.jpg

DJF
16-Pearl
16-Pearl
(To:DJF)

A-ha!  I believe I have it.  By telling mathcad which P_ratio2 to use (through a for loop) it can then figure out the rest.  It can't compare a vector to a scalar, so we have to feed it one value.  This is what solved it.

vec5.jpg

Note: Several variations on this do not work (e.g. storing the results into m_dot_i or using P_2o_i)

Thanks for the assistance.

RichardJ
19-Tanzanite
(To:DJF)

It's a little unconventional, but you can use the heavyside step function to create an "if" statement:

The solve block understands this.

As an aside, this is also a useful trick for the symbolic processor, which also does not understand if statement, but does understand the heavyside step function.

Top Tags