Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
getLoops.py
Go to the documentation of this file.
1import os,glob,sys
2import numpy as np
3
4
5class node:
6 def __init__(self,p):
7 self.p = np.array([s for s in p])
8
9class loop:
10 def __init__(self,b,n):
11 self.b = np.array([s for s in b])
12 self.n = np.array([s for s in n])
13 self._c = np.array([0., 0., 0.])
14 self._r = 0.0
15 self._links = []
16
17 def addLinks(self,source,sink):
18 self._links.append( [source,sink] )
19
20 def updateCenter(self,nodelist):
21 for link in self._links:
22 for n in link:
23 self._c += nodelist[n].p/len(self._links)/len(link)
24
25 def getRadius(self,nodelist):
26 for link in self._links:
27 for n in link:
28 self._r += np.sqrt(np.sum(np.square(nodelist[n].p-self._c)))/len(self._links)/len(link)
29
30
31def getLoops(filename):
32#----------------------------------------------------------------------------#
33# Get input file
34#----------------------------------------------------------------------------#
35 ff = filename+'.txt'
36#----------------------------------------------------------------------------#
37# Get three lists
38#----------------------------------------------------------------------------#
39
40 nlist = {} # Point list
41 llist = {} # Loop list
42
43 fcon = open(ff)
44 ntotal = int(fcon.readline().strip())
45 ltotal = int(fcon.readline().strip())
46 stotal = int(fcon.readline().strip())
47
48
49 for line_number in range(ntotal):
50 line = fcon.readline().strip().split()
51 nlist.update({ int(line[0]): node(np.array([float(s) for s in line[1:4]])) })
52
53 for line_number in range(ltotal):
54 line = fcon.readline().strip().split()
55 llist.update({int(line[0]): loop(np.array([float(s) for s in line[1:4]]),np.array([float(s) for s in line[4:7]]))})
56
57 for line_number in range(stotal):
58 line = fcon.readline().strip().split()
59 llist[int(line[0])].addLinks(int(line[1]),int(line[2]))
60
61#----------------------------------------------------------------------------#
62# Update loop center and get radius
63#----------------------------------------------------------------------------#
64 for l in llist:
65 llist[l].updateCenter(nlist)
66 llist[l].getRadius(nlist)
67
68 return llist
addLinks(self, source, sink)
Definition getLoops.py:17
getRadius(self, nodelist)
Definition getLoops.py:25
__init__(self, b, n)
Definition getLoops.py:10
updateCenter(self, nodelist)
Definition getLoops.py:20
__init__(self, p)
Definition getLoops.py:6
REAL split