- """
- This function sorts the list of neighbouring objects on each side, according to their intersection
- with the object being created. From South to North and from East to West
- """
- Output = List
- # First find the directions where no neighbour exists
- # Important : Here we assume that exactly two directions have no neighbours !!!
- # Should we change this to allow a more general case ????
- dummy = IndexMultiOcc(List,(-1,))
-
- # dummy[0] is either 0, meaning there is no neighbour on X- (West)
- # or 1, meaning there is no neighbour on X+ (East)
- # Similarly dummy[1] can be either 2 or 3 (South and North respectively)
- # In order to get back to the formalism of groups (SNWE)
- # => we do the following to define Sense of no neighbours and then the Direction list
- # is calculated as to include uniquely the directions where we DO have neighbours
- if len(dummy) == 1 :
- # This adds a second direction where neighbours are not regarded, it is either 0 or 2
- dummy.append(2*(dummy[0]+2<4))
- print("Careful, you have neighbours on 3 or more sides of the box, we will not check if on two parallel sides the boxes are compatible !!!")
- if len(dummy) == 2 or len(dummy) == 1 :
- # Sense contains : Vertical then Horizontal
- Sense = [dummy[1]%2,dummy[0]]
- DirList = [[1,0][dummy[0]],[3,2][dummy[1]%2]]
- for index,Direction in enumerate(DirList) :
- ObjList = List[Direction]
- RankMin = []
- ToLook0 = [2,2,0,0][Direction]
- ToLook1 = [3,2,1,0][Direction]
- for index1,ObjID in enumerate(ObjList) :
- RankMin.append([-1.,1.][Sense[index]] * FindCommonSide(Config.ListObj[ObjID].DirBoundaries(ToLook1),[X0-DX/2.,X0+DX/2.,Y0-DY/2.,Y0+DY/2.][ToLook0:ToLook0+2])[Sense[index]])
- Output[Direction] = SortList(ObjList,RankMin)
-
- elif len(dummy) == 3 :
- # We find the direction where we do have neighbours and then we sort the object list along it
- Sense = dummy[0]%2
- Direction = [ i not in dummy for i in range(4) ].index(True)
- ObjList = List[Direction]
- RankMin = []
- ToLook0 = [2,2,0,0][Direction]
- ToLook1 = [3,2,1,0][Direction]
- for index1,ObjID in enumerate(ObjList) :
- RankMin.append([-1.,1.][Sense] * FindCommonSide(Config.ListObj[ObjID].DirBoundaries(ToLook1),[X0-DX/2.,X0+DX/2.,Y0-DY/2.,Y0+DY/2.][ToLook0:ToLook0+2])[Sense])
- Output[Direction] = SortList(ObjList,RankMin)
- else :
- print ("Error : the composite box being created has no neighbours, how on earth do you want us to inherit its mesh parameters!!!")
-
-
- return Output
-
-def IndexMultiOcc (Array,Element) :
- """
- This functions returns the occurrences indices of Element in Array.
- As opposed to Array.index(Element) method, this allows determining
- multiple entries rather than just the first one!
- """
- Output = []
- try : Array.index(Element)
- except ValueError : print "No more occurrences"
- else : Output.append(Array.index(Element))
-
- if not(Output == []) and len(Array) > 1 :
- for index, ArrElem in enumerate(Array[Output[0]+1:]) :
- if ArrElem == Element : Output.append(index+Output[0]+1)
-
- return Output
-
-def SortList (ValList, CritList):
- Output = []
- SortedCritList = copy.copy(CritList)
- SortedCritList.sort()
- for i in range(0,len(ValList)):
- index = CritList.index(SortedCritList[i])
- Output.append(ValList[index])
- return Output
+ """
+ This function sorts the list of neighbouring objects on each side, according to their intersection
+ with the object being created. From South to North and from East to West
+ """
+ Output = List
+ # First find the directions where no neighbour exists
+ # Important : Here we assume that exactly two directions have no neighbours !!!
+ # Should we change this to allow a more general case ????
+ dummy = IndexMultiOcc(List,(-1,))
+
+ # dummy[0] is either 0, meaning there is no neighbour on X- (West)
+ # or 1, meaning there is no neighbour on X+ (East)
+ # Similarly dummy[1] can be either 2 or 3 (South and North respectively)
+ # In order to get back to the formalism of groups (SNWE)
+ # => we do the following to define Sense of no neighbours and then the Direction list
+ # is calculated as to include uniquely the directions where we DO have neighbours
+ if len(dummy) == 1 :
+ # This adds a second direction where neighbours are not regarded, it is either 0 or 2
+ dummy.append(2*(dummy[0]+2<4))
+ print("Careful, you have neighbours on 3 or more sides of the box, we will not check if on two parallel sides the boxes are compatible !!!")
+ if len(dummy) == 2 or len(dummy) == 1 :
+ # Sense contains : Vertical then Horizontal
+ Sense = [dummy[1]%2,dummy[0]]
+ DirList = [[1,0][dummy[0]],[3,2][dummy[1]%2]]
+ for index,Direction in enumerate(DirList) :
+ ObjList = List[Direction]
+ RankMin = []
+ ToLook0 = [2,2,0,0][Direction]
+ ToLook1 = [3,2,1,0][Direction]
+ for index1,ObjID in enumerate(ObjList) :
+ RankMin.append([-1.,1.][Sense[index]] * FindCommonSide(Config.ListObj[ObjID].DirBoundaries(ToLook1),[X0-DX/2.,X0+DX/2.,Y0-DY/2.,Y0+DY/2.][ToLook0:ToLook0+2])[Sense[index]])
+ Output[Direction] = SortList(ObjList,RankMin)
+
+ elif len(dummy) == 3 :
+ # We find the direction where we do have neighbours and then we sort the object list along it
+ Sense = dummy[0]%2
+ Direction = [ i not in dummy for i in range(4) ].index(True)
+ ObjList = List[Direction]
+ RankMin = []
+ ToLook0 = [2,2,0,0][Direction]
+ ToLook1 = [3,2,1,0][Direction]
+ for index1,ObjID in enumerate(ObjList) :
+ RankMin.append([-1.,1.][Sense] * FindCommonSide(Config.ListObj[ObjID].DirBoundaries(ToLook1),[X0-DX/2.,X0+DX/2.,Y0-DY/2.,Y0+DY/2.][ToLook0:ToLook0+2])[Sense])
+ Output[Direction] = SortList(ObjList,RankMin)
+ else :
+ print ("Error : the composite box being created has no neighbours, how on earth do you want us to inherit its mesh parameters!!!")
+
+
+ return Output