GetArea of a section

General discussion about TexGen.

Moderators: Martin, Developers

Post Reply
fstig
Regular
Posts: 14
Joined: Thu Apr 24, 2008 7:09 am
Location: Gothenburg, Sweden
Contact:

GetArea of a section

Post by fstig »

Hi
I have created a texgen model using a deformed FE-mesh as input data. The TexGen model looks like this

Code: Select all

###############################
Yarn = CYarn()
upVW = XYZ(1,0,0)
Yarn.AssignInterpolation(CInterpolationBezier())
yarnsection = CYarnSectionInterpNode(1, 0,1)

Yarn.AddNode(CNode(XYZ( 1.432, 2.321 ,0.132),XYZ() ,upVW))
Points = [XY(0.435029525407,0.199547127674), XY(.... 
yarnsection.AddSection(CSectionPolygon(Points)) 

#Add more points and sections ...

Yarn.AssignSection(yarnsection)
Yarn.SetResolution(res)
DefTextile.AddYarn(Yarn) 

AddTextile("xxx" ,yyy)
##########################################
I use this texgen python script in another post processing script where I need to get the cross section area at the master nodes. There is a function for that that operates on the yarnsection. The problem is I can't seem to get to yarnsection object. I have tried (among other things)

Code: Select all

tmpYarn = Textile.GetYarn(0) # first yarn
sec         = tmpYarn.GetYarnSection()
#then I think the info I'm looking for is in 
sec = tmpYarn.GetYarnSection(XXXXX)
I don't know how to write XXXXX. In the user guide it says
const YARN_POSITION_INFORMATION PositionInfo,
int iNumPoints,
bool bEquiSpaced = false
but I don't know on which format YARN_POSITION_INFORMATION is?
Can anybody help me?

Regards
Fredrik
Researcher RISE
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: GetArea of a section

Post by louisepb »

Hi Fredrik,

This could probably do with documenting a bit better!

When you do the sec = yarn.GetYarnSection() call it returns the pointer to the class that contains the information about all the sections in the yarn - ie the CYarnSectionInterpNode.

Once you have got this then you get the sections from there, using the YARN_POSITION_INFORMATION structure. The reference is here http://texgen.sourceforge.net/api/struc ... 2820135bc2
(but could do with some improvement!)

You create the structure using

Code: Select all

pos = YARN_POSITION_INFORMATION()
which will create it with defaults of 0 for the dSectionPosition and iSection variables. iSection is the node number of the first node in the section that you're interested in. dSectionPosition gives the normalised distance between that and the next node. So - if you want to get the section at node 1, iSection = 1 and dSectionPosition = 0. For the section at the midpoint between nodes 1 and 2 change dSectionPosition to be 0.5.
You also need to set up the SectionLengths vector which can be done with:

Code: Select all

pos.SectionLengths = yarn.GetSectionLengths()
You can then do a call to get the section coordinates using

Code: Select all

Points = sec.GetSection(pos, x)
where x is the number of points that you want around the section perimeter.

Hope that makes sense! Let me know if you need anything clarifying.
Louise
fstig
Regular
Posts: 14
Joined: Thu Apr 24, 2008 7:09 am
Location: Gothenburg, Sweden
Contact:

Re: GetArea of a section

Post by fstig »

Hi and thank you for the swift reply.

I'm have learnt something today, thank you. However, I'm not "there" yet with my coding. After creating the model and running it, I have now the following bit of code:

Code: Select all

sections = tmpYarn.GetYarnSection()
pos = YARN_POSITION_INFORMATION()
pos.SectionLengths = tmpYarn.GetSectionLengths()
pos.dSectionPosition = 0
pos.iSection = 1
Points = sections.GetSection(pos, 40)
sec.GetArea(Points)
line 3 pos.SectionLengths = tmpYarn.GetSectionLengths() gives me the following error:
TypeError: in method 'YARN_POSITION_INFORMATION_SectionLengths_set', argument 2 of type 'std::vector< double > *'
When I print tmpYarn.GetSectionLengths() then I get a tuple with data so that is good. I have also tried to assign pos with dSectionPosition and iSection but failed. I'm also unsure about the last getArea command as well.

Regards
Fredrik
Researcher RISE
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: GetArea of a section

Post by louisepb »

Hi Fredrik,

Apologies, I left a step out. The C++ vectors are all wrapped so that they can be used in the Python functions (the list of the templates is here http://texgen.sourceforge.net/api/index.html ) so the vector returned from the GetSectionLengths has to be assigned as a DoubleVector so that it has the correct data type.
The GetArea function is a static member of the CSection class so you can just call it directly with your vector of points. I think the following works!

Code: Select all

textile = GetTextile()
yarn = textile.GetYarn(0)
sections = yarn.GetYarnSection()
pos = YARN_POSITION_INFORMATION()
pos.SectionLengths = DoubleVector( yarn.GetSectionLengths() )
pos.iSection = 1

Points = sections.GetSection(pos, 40)
area = CSection.GetArea(Points)
Hope that helps,
Louise
fstig
Regular
Posts: 14
Joined: Thu Apr 24, 2008 7:09 am
Location: Gothenburg, Sweden
Contact:

Re: GetArea of a section

Post by fstig »

Thank you, it is all clear now :)
Researcher RISE
Post Reply