0
$\begingroup$

I want to convert the local connectivity matrix to the global one as follows. Consider two quad elements with connectivity

{{1,2,3,4},{2,5,6,3}}

Now let's say each node has 5 degrees of freedom. Then I want to write my connectivity including 5 degrees of freedom at each node as follows: For Element 2

{2,5,6,3} -> {6,7,8,9,10,21,22,23,24,25,26,27,28,29,30,11,12,13,14,15}

Is there a simple way to convert into this form?

$\endgroup$
5
  • 1
    $\begingroup$ How did you get to the second part in the rule list? $\endgroup$
    – user21
    Jan 6, 2020 at 12:58
  • $\begingroup$ I mean at each node if there are 5 degrees of freedom, then at 2nd node the degrees of freedom consisting are 6,7,8,9,10. Similarly at 5th node 21,22,23,24,25. Like wise... $\endgroup$ Jan 6, 2020 at 13:26
  • 1
    $\begingroup$ @S.B.MD I still don’t understand the pattern that generated that second version you seek. How did you calculate that “at 5th node 21, 22, 23, 24, 25”? It is not immediately apparent to me. $\endgroup$
    – MarcoB
    Jan 6, 2020 at 13:52
  • $\begingroup$ Node 1:{1,2,3,4,5} Node 2: {6,7,8,9,10} Node 3:{11,12,13,14,15} Node 4:{16,17,18,19,20} Node 5: {21,22,23,24,25} Node 6: {26,27,28,29,30}. Therefore, total degrees of freedom for two quad elements with nodal connectivity {{1,2,3,4},{2,5,6,3}} is 30 i.e., (6nodes * 5 dof at each node) $\endgroup$ Jan 6, 2020 at 13:58
  • $\begingroup$ list = {2, 5, 6, 3}; Flatten[ list /. n_?NumericQ :> 5 (n - 1) + {1, 2, 3, 4, 5} ] $\endgroup$
    – LouisB
    Jan 8, 2020 at 4:08

3 Answers 3

1
$\begingroup$

The question is not very clear. If all you want is to map the elements to the corresponding list then here is one way to do it.

map = Table[5 i + j, {i, 0, 5}, {j, 1, 5}] // AssociationThread[Range[6], #] &;
map[#] & /@ {2, 5, 6, 3} // Flatten
(* {6, 7, 8, 9, 10, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 11, 12, 13, 14, 15} *)

or using replacement rules

rules = Table[5 i + j, {i, 0, 5}, {j, 1, 5}] // Thread[Range[6] -> #] &;
{2, 5, 6, 3} /. rules // Flatten
$\endgroup$
0
$\begingroup$
f = {a, m} \[Function] Module[{n, k},
    {n, k} = Dimensions[a];
    ArrayReshape[
     Outer[Plus, Flatten[(a - 1) m], Range[1, m]],
     {n, m k}
     ]
    ];

Test:

f[{{1,2,3,4},{2,5,6,3}} , 5]

{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, {6, 7, 8, 9, 10, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 11, 12, 13, 14, 15}}

This is fairly efficient:

a = Partition[RandomChoice[1 ;; 1000000, 1000000], 4];
f[a, 5]; // RepeatedTiming // First

0.03

$\endgroup$
0
$\begingroup$

This may work:

   list1 = {{1, 2, 3, 4}, {2, 5, 6, 3}}
   Flatten[{5*# - 4, 5*# - 3, 5*# - 2, 5*# - 1, 5*#}\[Transpose]] & /@ list1

{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, {6, 7, 8, 9, 10, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 11, 12, 13, 14, 15}}

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.