## Fem constraint contact

About the development of the FEM module/workbench.

Moderator: bernd

bernd
Posts: 11091
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### Re: Fem constraint contact

would it be possible to reduce your problematic code to just one constraint contact without a loop?
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

### 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

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

[col,row]=np.array(array.shape)
for i in range(array.size):
#print(i)
idxc=0
idxr=0
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)")
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)
else:
print("No object found to apply contact ",objName)
except Exception:
print("Not Shape")
except Exception:
print("Not object")
``````
bernd
Posts: 11091
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### 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
bernd
Posts: 11091
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### Re: Fem constraint contact

makkemal wrote:
Wed Oct 10, 2018 10:31 am
This is going to be a very useful feature
I do not get the point of this. What is this feature useful for?
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

### Re: Fem constraint contact

Civil engineers .....
I do not get the point of this. What is this feature useful for?
https://www.ansys.com/products/structur ... assemblies
bernd
Posts: 11091
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### Re: Fem constraint contact

wow ...
makkemal wrote:
Wed Oct 10, 2018 11:00 am
Civil engineers .....
structural engineer, but anyway, we do not need such stuff either ...
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

### Re: Fem constraint contact

I have updated the script and it seems to be working now
contact_apply_01.py
Two test problem that work well
contact_test.FCStd
contact_test2.FCStd
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 ?
bernd
Posts: 11091
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### 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
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

### Re: Fem constraint contact

What do I need to do to test all this? May be than I have a even better idea
The only input the script need is :

Code: Select all

``````Slope = 1000000.000000  # Contact stiffness
Friction = 0.300000     # Friction
``````
These values are applied to all contact objects generated
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
bernd
Posts: 11091
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

### 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.