C#: 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 C#:

C# - decode nodes KFIX value#
static void Main(string[] args)
{
   float x = 0;
   int result = 112;
   string value = "PXPYPZMXMYMZ";

   x = (64 & result);
   if (x > 0)
         value = "PXPYPZMXMYMZ";

   x = (32 & result);
   if (x > 0)
         value = value.Replace("MZ", null);

   x = (16 & result);
   if (x > 0)
         value = value.Replace("MY", null);

   x = (8 & result);
   if (x > 0)
         value = value.Replace("MX", null);

   x = (4 & result);
   if (x > 0)
         value = value.Replace("PZ", null);

   x = (2 & result);
   if (x > 0)
         value = value.Replace("PY", null);

   x = (1 & result);
   if (x > 0)
         value = value.Replace("PX", null);

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

   Console.WriteLine("Value:" + value);
   Console.ReadKey();
}