Get amount of interference in Python interface

General discussion about TexGen.

Moderators: Martin, Developers

Post Reply
Beun
Posts: 5
Joined: Thu Feb 07, 2013 9:31 am

Get amount of interference in Python interface

Post by Beun »

Hi there,

I am building a 3D textile with Python, and I would like to know what is the maximum yarn volume fraction I can achieve without significant interference. It would be quite complicated to do it analytically, so I thought I would make a script that tries various sizes of gaps and checks if there is interference or not. The trick is that I would like to know how much interference there is, because sometimes there is some interference, but it's quite negligible in my view.

I've tried looking through this forum and haven't found much talk about interference. I am afraid the documentation is of little help for me, since I have no clue how to translate all those C++ commands into the suitable Python API command. Maybe the following command would help:

int DetectInterference (vector< float > &DistanceToSurface, vector< int > &YarnIndex, bool bTrimToDomain, CMesh *pInterferingPoints=NULL)

I understand what those arguments mean and if I look at the code I think to myself 'ok, makes sense'... but I don't know how to use it in Python (maybe that's the real subject of this topic. If I get some insight about this, I'll be able to understand the documentation better for other things too).

Any tip is welcome !

Ben
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Get amount of interference in Python interface

Post by louisepb »

Hi Ben,

Welcome to the forum.

The C++ functions documented in the API reference have all been wrapped as Python functions using SWIG. You can therefore make the same function calls from your Python program. There is a slight difference in the way that some of the parameters are addressed in Python. (In looking into your question I've realised that this isn't documented in the API reference so I'll do something about that!). There is a list of templates defined in the Core.i file which enable you to use the various STL constructs used in the C++ files.

%template(StringVector) vector<string>;
%template(PlaneVector) vector<TexGen::PLANE>;
%template(XYZPair) pair<TexGen::XYZ, TexGen::XYZ>;
%template(YarnList) list<TexGen::CYarn>;
%template(YarnVector) vector<TexGen::CYarn>;
%template(YarnVectorPtr) vector<TexGen::CYarn*>;
%template(TextileVector) vector<TexGen::CTextile*>;
%template(TextileMap) map<string, TexGen::CTextile*>;
%template(NodeVector) vector<TexGen::CNode>;
%template(SlaveNodeVector) vector<TexGen::CSlaveNode>;
%template(XYZVector) vector<TexGen::XYZ>;
%template(XYVector) vector<TexGen::XY>;
%template(DoubleVector) vector<double>;
%template(IntPair) pair<int, int>;
%template(IntPairVector) vector<pair<int, int> >;
%template(PointInfoVector) vector<TexGen::POINT_INFO>;
%template(DoubleXYZPair) pair<double, TexGen::XYZ>;
%template(DoubleXYZPairVector) vector< pair<double, TexGen::XYZ> >;
%template(BoolPair) pair<bool, bool>;
%template(IntList) list<int>;
%template(IntVector) vector<int>;
%template(BoolVector) vector<bool>;
%template(ElementDataList) list<TexGen::MESHER_ELEMENT_DATA>;
%template(MeshDataVector) vector<TexGen::CMeshDataBase*>;
%template(LinearTransformationVector) vector<CLinearTransformation>;
%template(FloatVector) vector<float>;

Unfortunately the bottom one for vector<float> had been omitted from the list which means that in the current TexGen release the DetectInterference function can't be called from the Python interface. (Apparently you are the first person to try this!) I will incorporate this change into the next TexGen release. Once this is working you would then need a piece of code something like that below:

Code: Select all

textile = GetTextile()

DistanceToSurface = FloatVector()
YarnIndices = IntVector()
InterferingPoints = CMesh()

textile.DetectInterference( DistanceToSurface, YarnIndices, True, InterferingPoints )
You would then have a vector containing the list of distances to the yarn surface (ie the interference depth) with a corresponding mesh giving the points on the mesh at which those interferences occur.

In the meantime you can use the Render Textile Interference Depth option in the GUI which uses the same function and outputs the number of interference points and the maximum interference depth. The rendering gives an indication of where the maximum intersections occur.

I hope that helps. Let me know if there's anything else I can help with.

Best regards,
Louise
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Get amount of interference in Python interface

Post by louisepb »

Hi Ben,

I also forgot to say that there is a scripting guide on the TexGen website here: http://texgen.sourceforge.net/index.php/Scripting_Guide

Best regards,
Louise
Beun
Posts: 5
Joined: Thu Feb 07, 2013 9:31 am

Re: Get amount of interference in Python interface

Post by Beun »

Thank you very much Louise.
I think that the template list is what I've been missing to understand all this by myself. Just to have an idea, when do you think the next release will be available ?
Cheers
Ben
stephinity
Posts: 2
Joined: Thu Nov 13, 2014 2:14 pm

Re: Get amount of interference in Python interface

Post by stephinity »

Hi Louise,

First of all thank you for all the work on TexGen - it really is outstanding software! The more I use it the more I'm continually impressed!

Similar to Ben, I've also been looking at Detecting Interference via TexGen's Python wrapper functions. I'm working with Layered Textiles, that have been nested (via NestLayers() ), and have a few interference points that I'm trying to remove - all from within Python scripts.

From here:
http://texgen.sourceforge.net/phpBB3/vi ... ence#p5872

I came to the CAdjustMeshInterference Class, from which I would like to call AdjustMesh(Textile,YarnMeshes,Tolerance), but when I call the constructor of this class - CAdjustMeshInterference(), I get the error that this constructor method is not defined.

NameError: name 'CAdjustMeshInterference' is not defined

Can I call CAdjustMeshInterference() from Python, just as I would CTextile() or CYarn()? Or am I not understanding properly from which kind of object I should call AdjustMesh()?

Or - is there another way to call AdjustMesh(...)?

Thanks for your help!

Best regards,
Stephan
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Get amount of interference in Python interface

Post by louisepb »

Hi Stephan,

Glad you are finding TexGen useful.

The CAdjustMeshInterference class is currently not wrapped to give Python functions available via the API.

I will take a look at it and see if I can sort that out. I am planning to do a new release shortly so I'll do my best to get it included in that.

In the meantime you can perform the correction by using the Export Abaqus Dry Fibre option in the GUI and select Adjust Intersections and Regenerate Mesh.

Hope that helps,
Louise
stephinity
Posts: 2
Joined: Thu Nov 13, 2014 2:14 pm

Re: Get amount of interference in Python interface

Post by stephinity »

Hi Louise,

Thanks for answering my question! I had suspected that that class hadn't been wrapped. I needed the matrix mesh as well, so the dry fiber export wasn't applicable for me.

Also, I wanted to correct the interference from within my script, so I wrote this little workaround to correct the interference, and perhaps someone else will find it useful :)

The code checks for interference, and if found adds a (user defined) offset to each layer in the layered textile (yarn by yarn).

weave is an instance of CTextileWeave2D
layeredTextile is an instance of CTextileLayered (made up of n layers of the weave)
interferenceCorrection = 0.010 (mm in my case)

Code: Select all

# After calling NestLayers(), check for interference of nodes and correct it

# Check for interference (using CTextile.DetectInterference(...))
distanceToSurface = FloatVector()
yarnIndices = IntVector()
interferingPoints = CMesh()
numInterferingPoints = layeredTextile.DetectInterference(distanceToSurface, yarnIndices, True, interferingPoints)

if numInterferingPoints == 0:
    print("No interference detected")
else:
    print(str(numInterferingPoints) + " inteference points detected: adjusting layer heights by: "+str(interferenceCorrection)+"...")

    layerOffset = XYZ(0,0,0)
    for i in range(layeredTextile.GetNumYarns()):

        # Increment offset after looping through all yarns of one weave (layer)
        if (i != 0) and (i % weave.GetNumYarns() == 0):
            layerOffset.z += interferenceCorrection

        layeredTextile.GetYarn(i).Translate(layerOffset)

    numInterferingPoints = layeredTextile.DetectInterference(distanceToSurface, yarnIndices, True, interferingPoints)
    print("After interference correction, " + str(numInterferingPoints) + " interference points remain")

All the best - and thanks again for the great work!
Stephan
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Get amount of interference in Python interface

Post by louisepb »

Hi Stephan,

Glad you managed to find a way around it and thanks for sharing your solution.

I have now got the interference correction wrapped, so that will go out in the next release which will hopefully be soon.

Best wishes,
Louise
Post Reply