try on a linux machine ...
Code: Select all
find src/Mod/Fem/ -name "*\.py" | grep -v convert2TetGen.py | grep -v InitGui.py | grep -v TestFem.py | xargs -I [] flake8 --ignore=E266,E402,E722,W503 --max-line-length=200 []
Moderator: bernd
Code: Select all
find src/Mod/Fem/ -name "*\.py" | grep -v convert2TetGen.py | grep -v InitGui.py | grep -v TestFem.py | xargs -I [] flake8 --ignore=E266,E402,E722,W503 --max-line-length=200 []
Code: Select all
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 56, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
TypeError: Partition index must be integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femguiobjects/_ViewProviderFemConstraintAutoContact.py", line 136, in add_contact
femutils.AddAutoContact(self.slope,self.friction,self.facenum)
File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtools/femutils.py", line 308, in AddAutoContact
results = np.array(get_all_close_surfaces(locations,num))
File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtools/femutils.py", line 197, in get_all_close_surfaces
store.append(find_index_of_nearest(array, i, num))
File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtools/femutils.py", line 188, in find_index_of_nearest
idxmin = np.argpartition(np.array(distance), num)
File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 808, in argpartition
return _wrapfunc(a, 'argpartition', kth, axis=axis, kind=kind, order=order)
File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 66, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 46, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: Partition index must be integer
Code: Select all
Freecad/FreeCAD$ find src/Mod/Fem/ -name "*\.py" | grep -v convert2TetGen.py | grep -v InitGui.py | grep -v TestFem.py | xargs -I [] flake8 --ignore=E266,E402,E722,W503 --max-line-length=200 []
src/Mod/Fem/femguiobjects/_ViewProviderFemConstraintAutoContact.py:36:1: F401 '_FemConstraintAutoContact' imported but unused
Code: Select all
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15652 +2 (Git)
Build type: Release
Branch: femautocontact
Hash: cd70f86543101b6440f65ce82fc14e88daca778e
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: English/SouthAfrica (en_ZA)
Code: Select all
from PySide import QtCore, QtGui
import FreeCAD
import Fem
minDist=0.5 # minimum distance between faces for which they are considered in contact
Slope = 1000000.000000 # Contact stiffness
Friction = 0.300000 # Friction
Scale = 1 # Scale
def findContacts(bodiesGroup): # find the contacts between each surface of first body and surfaces of the rest of bodies
contacts=[]
if len(bodiesGroup) <= 1:
return contacts
firstMember=bodiesGroup[0]
restOfMembers=bodiesGroup[1:len(bodiesGroup)]
contacts=findContacts(restOfMembers) # recursively find contacts
c=len(contacts)
i=0
for face in firstMember.Shape.Faces: # browse the list of shapes of the first body
j=0
for neighbourBody in restOfMembers: # browse the list of neighbour body
for neighbourFace in neighbourBody.Shape.Faces: # browse the list of shapes for each body
dist=face.distToShape(neighbourFace)[0]
# print("Distance from face ", face, " of ", firstMember.Name, " to the face ", neighbourFace, " of ", neighbourBody.Name, " is ", dist)
if dist <= minDist:
contacts.append([i,j]) # Appending indexes of faces in contact - indexes are according to number of faces checked in current instance of function
j=j+1
i=i+1
for k in range(0,c): # Correcting the indexes returned from the previous instance according to number of faces founded in the current instance
contacts[k][0]=contacts[k][0]+i
contacts[k][1]=contacts[k][1]+i
for k in range(c,len(contacts)): # Correcting the index of faces belonging to the rest of bodies according to number of faces belonging to the first body
contacts[k][1]=contacts[k][1]+i
return contacts
def addContacts(facePairs, group): # Adding contacts according to the faces pairs given in first argument
active = FemGui.getActiveAnalysis()
for pair in facePairs:
obj = FreeCAD.activeDocument().addObject("Fem::ConstraintContact","FemConstraintContact")
obj.Slope = Slope
obj.Friction = Friction
obj.Scale = Scale
obj.References = [(group,"Face"+str(pair[0]+1)),(group,"Face"+str(pair[1]+1))]
active.addObject(obj)
def errorDialog(msg):
# Create a simple dialog QMessageBox
# The first argument indicates the icon used: one of QtGui.QMessageBox.{NoIcon, Information, Warning, Critical, Question}
diag = QtGui.QMessageBox(QtGui.QMessageBox.Warning, 'Error in AutoContacts', msg)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()
class Error(Exception):
"""Base class for other exceptions"""
pass
class ActiveAnalysis(Error):
"""Raised when something go wrong with analyse"""
pass
try:
if not FemGui.getActiveAnalysis():
raise ActiveAnalysis
for obj in FreeCAD.ActiveDocument.Objects: # seach all objects in document
contacts=[]
objName = obj.Name
objLabel = obj.Label
if 'Compound' in objName or 'Fusion' in objName: # detect if an oject is compound or fussion
bodiesGroup=[]
group=App.ActiveDocument.getObject(objName).OutList # get the list of member objects
for member in group:
if member.Shape.Faces: # is a face then
bodiesGroup.append(member)
else:
print("Not a Shape")
contacts=findContacts(bodiesGroup)
addContacts(contacts, obj)
except ActiveAnalysis:
errorDialog("There is not an active analysis.\nPlease create a FEM analyse first!")
except Exception:
print("Not object")