Fem constraint contact
Moderator: bernd
Forum rules
and Helpful information for the FEM forum
and Helpful information for the FEM forum
Re: Fem constraint contact
would it be possible to reduce your problematic code to just one constraint contact without a loop?
Re: Fem constraint contact
So I found the problem although Face index start at 0 the Face numbers on start at 1
Fixed now
So currently I step through compound and find closest faces for the whole compound
Now the question is if I have a face how do I check that the closest face is not part of the same sub solid ?
The compound solid is made of a number of solids I need to identify the faces that are part of the same sub solid but have the number as it is in the compound solid ?
This is going to be a very useful feature
Thanks
Fixed now
So currently I step through compound and find closest faces for the whole compound
Now the question is if I have a face how do I check that the closest face is not part of the same sub solid ?
The compound solid is made of a number of solids I need to identify the faces that are part of the same sub solid but have the number as it is in the compound solid ?
This is going to be a very useful feature
Thanks
Code: Select all
import FreeCADGui, FreeCAD
import numpy as np
locations = []
#Variables
num=3 # Number of nearest neigbours to found
Slope = 1000000.000000 # Contact stiffness
Friction = 0.300000 # Friction
Scale = 1 # Scale
def find_index_of_nearest(array, idx,num ):
xpoint=array[idx,0]
ypoint=array[idx,1]
zpoint=array[idx,2]
distance = []
for i in range(array.shape[0]):
distance.append((array[i,0]-xpoint)**2 + (array[i,1]-ypoint)**2+ (array[i,2]-zpoint)**2)
idxmin = np.argpartition(np.array(distance), num)
idxmin=np.array(idxmin[0:num])
idxmin=np.delete(idxmin,np.where(idxmin==idx))
return idxmin
def get_all_close_surfaces(array, num):
store = []
for i in range(array.shape[0]):
store.append(find_index_of_nearest(array,i,num))
return store
def addcontactobjects(array,geom):
[col,row]=np.array(array.shape)
for i in range(array.size):
#print(i)
FreeCAD.activeDocument().addObject("Fem::ConstraintContact","FemConstraintContact")
idxc=0
idxr=0
for obj in FreeCAD.ActiveDocument.Objects:
if (obj.isDerivedFrom('Fem::ConstraintContact')):
objName = obj.Name
#print(objName)
obj.Slope = Slope
obj.Friction = Friction
obj.Scale = Scale
face1='Face'+str(idxc+1)
# print(face1)
face2='Face'+str(array[idxc,idxr]+1)
# print(face2)
obj.References = [(geom,face1), (geom,face2)]
# print(idxc+1,array[idxc,idxr]+)
idxr+=1
if idxr > row-1:
idxr = 0
idxc+=1
try:
for obj in FreeCAD.ActiveDocument.Objects: # seach all objects in document
objName = obj.Name
objLabel = obj.Label
try:
if obj.Shape.Faces: # is a face then
print( objLabel, objName, len(obj.Shape.Faces), " face(s)")
FreeCADGui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj.Name)) # select the object with face
if 'Compound' in objName:
print('Getting vector list for nearest neighbours contact \n ', objName)
for face in range(len(obj.Shape.Faces)): # list the face(s) of object
# print(face)
surfaceloc=np.array(obj.Shape.Faces[face].CenterOfMass) # center point
locations.append(surfaceloc)
# print(surfaceloc)
locations = np.array(locations)
#print(locations.shape)
results = np.array(get_all_close_surfaces(locations,num))
# print(results)
addcontactobjects(results,obj)
else:
print("No object found to apply contact ",objName)
except Exception:
print("Not Shape")
except Exception:
print("Not object")
Re: Fem constraint contact
could you post a simple FreeCAD file with boxes and describe the problem with exact names from the example file?
The not smart way would be to compare the goemetry of the faces for each face of corresponding solids. Than you know if it is part of the subsolid or not. You can try this def https://github.com/FreeCAD/FreeCAD/blob ... 1415-L1447
The not smart way would be to compare the goemetry of the faces for each face of corresponding solids. Than you know if it is part of the subsolid or not. You can try this def https://github.com/FreeCAD/FreeCAD/blob ... 1415-L1447
Re: Fem constraint contact
Civil engineers .....
https://www.ansys.com/products/structur ... assembliesI do not get the point of this. What is this feature useful for?
Re: Fem constraint contact
I have updated the script and it seems to be working now
But since the constraint contact was done in CPP and this is python I don't know how t link it ?
Two test problem that work well
Now I'm stuck I was thing of just adding a bottom to the ConstraintContact ui that runs this script.But since the constraint contact was done in CPP and this is python I don't know how t link it ?
Re: Fem constraint contact
we could add the methods too utilities, and only add a button to the contact ui. At button click the def from utilities will be run. Or and total independent tool?
What input parameter does your code needs? What is the output or outcome?
What do I need to do to test all this? May be than I have a even better idea.
bernd
What input parameter does your code needs? What is the output or outcome?
What do I need to do to test all this? May be than I have a even better idea.
bernd
Re: Fem constraint contact
The only input the script need is :What do I need to do to test all this? May be than I have a even better idea
Code: Select all
Slope = 1000000.000000 # Contact stiffness
Friction = 0.300000 # Friction
The default ui have these value but I guess a new ui with just these can be made ?
The solids need to be in a "compound" but adding any contact needs that
The rest is automatic
Re: Fem constraint contact
OK, what does it actually do.
- select a compound, run the code
- for all solids in the compound contakt constraints are generated
- with this it is not needed to make a boolean fragment mesh
If this is true I would wote for a totally independent tool in utilities with it's own icon.
- select a compound, run the code
- for all solids in the compound contakt constraints are generated
- with this it is not needed to make a boolean fragment mesh
If this is true I would wote for a totally independent tool in utilities with it's own icon.