Question

we are some engineer students, who have to use finite element to compute a simulation - our project is to find all the nodes on the edge of the object, and compare them to a defined line We have no python experience and have been reading about a week, but with no luck, so now we are trying to write this post. our raw date looks like this

$#   eid     pid      n1      n2      n3      n4      n5      n6      n7      n8
      1       1       1      76      77       2
      2       1       2      77      78       3
      3       1       3      78      79       4
      4       1       4      79      80       5
      5       1       5      80      81       6
      6       1       6      81      82       7
      7       1       7      82      83       8
      8       1       8      83      84       9
      9       1       9      84      85      10
     10       1      10      85      86      11
     11       1      11      86      87      12
     12       1      12      87      88      13
     13       1      13      88      89      14
     14       1      14      89      90      15
     15       1      15      90      91      16
     16       1      16      91      92      17

what we need to do is search for numbers that occur 2 or 3 times in the 3rd to 6th column and print them to a separate text document. Afterwards we need to find the coordinates for these nodes in the same text document, they look like this

   4441       1    4381    4400    4529    4530
   4442       1    4394    4393    4536    4536
   4443       1    4393    4407    4535    4536
*NODE (this is the end of the columns with nodes)
$#   nid               x               y               z      tc      rc
      1           0.000           0.000     -35.0448952
      2       1.0216124  -1.0579003e-12     -35.0447197
      3       2.0431936           0.000     -35.0445557
      4       3.0647054  -3.6848050e-13     -35.0442314
      5       4.0861325           0.000     -35.0437469
      6       5.1074324           0.000     -35.0432587
      7       6.1286263           0.000     -35.0426292
      8       7.1495924           0.000     -35.0419121
      9       8.1704435  -4.7529106e-14     -35.0411606
     10       9.1909819           0.000     -35.0402603
     11      10.2113619           0.000     -35.0393677

now with all the edge coordinates, we can compare our simulation's edge with the required edge.

We don't want a final solution, since we want to learn to program in python, and we have to be able to explain this at our exam, we are hoping someone can guide us toward the right literature or a basic script we can play around with, since we haven't found anything on this forum, that matches our needs

thank you in advance

No correct solution

OTHER TIPS

I recommend starting with the python tutorial - it won't take that long.

Anyway, hopefully, this should give you some ideas how to proceed.

By no means is this a working solution, nor does it do any error checking, but it should guide you to the parts of python to learn.

I'm using a dictionary to count the numbers of each column (I've done only column3 here).

# open the file
col3_counts = {}
txtfile = open('txtfile', 'r')

# reading 2 types of data from the file: the 'nodes' and the 'coordinates'
end_of_nodes = False

# read each line from the file
for line in txtfile:
    if line.startswith('*NODE'):
        end_of_nodes = True

    if not end_of_nodes:
        # read the node column
        cols = line.split()  #  cols[0] = eid, cols[1] = pid, .... 

        # get the value of column3 
        col3 = cols[4]

        if col3 not in col3_counts:
            col3_counts[col3] = 0
        else:
            col3_counts[col3] += 1

    else:
        # now read the coordinates using .split()
        # ... 

        # determine those in column 3 with a count > 2
        for num, count in col3_counts.items():
            if count > 2:
                # do something here

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top