Decode and encode the data#

Problem Description#

In this example the decoding of the CDB data (KFIX value from @20/0 Nodes) is examined. E.g. KFIX value for node 1 (KFIX=112) and for node 11 (KFIX=113). What does it mean?

In CDBASE.CHM you can find the description on how to encode/decode the KFIX value (degree of freedoms for nodes). A value 112 doesn’t mean nothing to us when we do not know what it means.

Example: CDBASE.CHM description#
@2# KFIX [int] degree of freedoms old definition:

#0     all fixed
&1     displacement uX
&2     displacement uY
&4     displacement uZ
&8     rotation PHIX
&16    rotation PHIY
&32    rotation PHIZ
&64    twisting dPHIx/dx
&128   split continuous beams flag
&256   ux-uy-uz may be suppressed
&512   phix-phiz may be suppressed
&1024  warping may be suppressed

For KFIX=112

112 - 1024 = -912 < 0

warping my be suppressed

FALSE

112-512 = -400 < 0

phix-phiz may be suppressed

FALSE

112-256 = -144 < 0

ux-uy-uz may be suppressed

FALSE

112-128 = -16 < 0

split continuous beams flag

FALSE

112-64 = 48 > 0

twisting dPHIx/dx

TRUE

48-32 = 16 > 0

rotation PHIZ

TRUE

16-16 = 0 = 0

rotation PHIY

TRUE


twisting dPHIx/dx

= PX + PY + PZ + MX + MY + MZ

rotation PHIZ

= -MZ

rotation PHIY

= -MY

Result

= PX + PY + PZ + MX = PPMX

For KFIX=113

113 - 1024 = -912 < 0

warping my be suppressed

FALSE

113-512 = -399 < 0

phix-phiz may be suppressed

FALSE

113-256 = -143 < 0

ux-uy-uz may be suppressed

FALSE

113-128 = -15 < 0

split continuous beams flag

FALSE

113-64 = 49 > 0

twisting dPHIx/dx

TRUE

49-32 = 17

rotation PHIZ

TRUE

17-16 = 1 > 0

rotation PHIY

TRUE

1-8 = -7 < 0

rotation PHIX

FALSE

1-4 = -7 < 0

displacement uZ

FALSE

1-2 = -7 < 0

displacement uY

FALSE

1-1 = 0 = 0

displacement uX

TRUE


twisting dPHIx/dx

= PX + PY + PZ + MX + MY + MZ

rotation PHIZ

= -MZ

rotation PHIY

= -MY

displacement uX

= -PX

Result

= PY + PZ + MX = XPMX

Problem Solution#

A code example for Python:

Python - decode data#
import string

x = 1
result = 113 #input te KFIX value here
value = "PXPYPZMXMYMZ"

x = 64 & result
if x > 0:
   value = "PXPYPZMXMYMZ"

x = 32 & result
if x > 0:
   value = string.replace(value, "MZ", "")

x = 16 & result
if x > 0:
   value = string.replace(value, "MY", "")

x = 8 & result
if x > 0:
   value = string.replace(value, "MX", "")

x = 4 & result
if x > 0:
   value = string.replace(value, "PZ", "")

x = 2 & result
if x > 0:
   value = string.replace(value, "PY", "")

x = 1 & result
if x > 0:
   value = string.replace(value, "PX", "")

# Replace the text
value = string.replace(value, "PXPYPZ", "PP")
value = string.replace(value, "MXMYMZ", "MM")
value = string.replace(value, "PYPZ", "XP")
value = string.replace(value, "PXPZ", "YP")
value = string.replace(value, "PXPY", "ZP")
value = string.replace(value, "MYMZ", "XM")
value = string.replace(value, "MXMZ", "YM")
value = string.replace(value, "MXMY", "ZM")
value = string.replace(value, "PPMM", "F")

print value