Bitmasking in VSPScript?

28 views
Skip to first unread message

Tim Cuatt

unread,
Dec 27, 2025, 10:57:14 AM (2 days ago) Dec 27
to OpenVSP
Hello all,

I'm working on evaluating an aircraft design that may or may not have twin vertical tails- so my adv-link based tail sizer parses the sym flag.

I realize that under the hood VSP will be performing a bitmask on a single int to determine the combination of symmetry operations requested, however I am not sure how to do the conditional in the VSPScript.

int sflag = vtail_symm;
int sym_mod = 1;
if (sflag == 2)
{
  sym_mod = 2;
}
sv = vv*s*b/(xv-xw)/sym_mod;

The intent here is to check if the XZ flag is set, and reduce the per-surface sizing appropriately. However as it's a bitmask, I need to check if bit number 2 is set, and it seems the C++ syntax isn't working there. The "if (sflag == 2)" should be checking for 2nd bit but "(var) & (1<<(pos))" does not compile. As long as no other sym flags are set the ==2 method works, but it would be nicer to make it robust in case of other symmetry cases layered on top.

Best,
-Tim C

Rob McDonald

unread,
Dec 28, 2025, 1:14:43 AM (yesterday) Dec 28
to OpenVSP
Try:

if ( sflag & vsp::SYM_XZ )
{
   sym_mod = 2;
}

Note, the single vertical bar & does bitwise and -- which is different from logical and &&.

So, this will result in the value of vsp::SYM_XZ if that bit is set in sflag.  Since this value is non-zero, it will be true.

All the SYM_XX enums only have a single bit set, but if any had multiple bits set, the above code would be true if any of them matched.

If you need a more strict test -- for only exact matches in the multiple bit case, then you would want 

if ( ( sflag & vsp::SYM_XZ ) == vsp::SYM_XZ )

To make sure all the bits in SYM_XZ were set in sflag.

Rob

Tim Cuatt

unread,
Dec 28, 2025, 12:55:11 PM (17 hours ago) Dec 28
to OpenVSP
Thanks Rob,

I had issues without the strict test to convert to a bool for the conditional. I think VSPScript didn't like the implicit conditional.

I also had to change the namespace call on my machine for some reason, but the script that ended up working was this:

int sflag = vtail_symm;

int sym_mod = 1;

if ( ( sflag & SYM_XZ ) == SYM_XZ )
{
  sym_mod = 2;
}

sv = vv*s*b/(xv-xw)/sym_mod;

The only change needed was removing the vsp:: namespace call for the SYM_XZ enum.

Best,
-Tim C

Rob McDonald

unread,
12:52 AM (5 hours ago) 12:52 AM
to OpenVSP
OK, thanks for the clarification.

I guess AngelScript doesn't automatically interpret ints as bool.  You could probably do it with a cast or 

if ( ( sflag & SYM_XZ ) != 0 )

If you wanted a more general test.

I also wasn't sure about the namespace.  I'm pretty sure that in the Python API, you have to vsp.SYM_XZ everything, but I guess not in vspscript.

Rob
Reply all
Reply to author
Forward
0 new messages