TexGen
FibreDistribution1DQuad.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#include "PrecompiledHeaders.h"
22
23using namespace TexGen;
24
25CFibreDistribution1DQuad::CFibreDistribution1DQuad(double dDropOff)
26: m_dDropOff(dDropOff)
27{
28}
29
31: CFibreDistribution(Element)
32{
33 Element.Attribute("DropOff", &m_dDropOff);
34}
35
36void CFibreDistribution1DQuad::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
37{
39 Element.SetDoubleAttribute("DropOff", m_dDropOff);
40}
41
42double CFibreDistribution1DQuad::ComputeMaxX(const vector<XY> &Section) const
43{
44 double dMaxX = 0;
45 for(unsigned int i=0;i<Section.size();++i)
46 {
47 dMaxX = max(Section[i].x, dMaxX);
48 }
49 return dMaxX;
50}
51
52double CFibreDistribution1DQuad::IntegrateDistribution(const vector<XY> &Section, double dMaxX) const
53{
54 double Integral = 0;
55 for(unsigned int i=0;i<Section.size();++i)
56 {
57 double x_0 = Section[i].x, x_1 = Section[(i+1)%Section.size()].x;
58 double dx = abs(x_1 - x_0); // TODO: Probably shouldn't be taking the absoulte value here
59 double avy = (abs(Section[(i+1)%Section.size()].y) + abs(Section[i].y))*0.5;
60 double dA = dx*avy;
61 double avf = (Distribution(1, m_dDropOff, x_1, dMaxX) + Distribution(1, m_dDropOff, x_0, dMaxX)) * 0.5;
62 Integral += dA*avf;
63 }
64 // TODO: Take the absolute value at the end
65 return Integral;
66}
67
68double CFibreDistribution1DQuad::GetVolumeFraction(const vector<XY> &Section, double dFibreArea, XY Location, int YarnIndex) const
69{
70 // compute the max x direction
71 double dMaxX = ComputeMaxX(Section);
72 double dScale = IntegrateDistribution(Section, dMaxX);
73 dScale = dFibreArea/dScale;
74 if(dScale>0.86||dScale<0)
75 {
76 if ( YarnIndex == -1 )
77 {
78 TGERROR("Warning: Volume fraction is not realistic " << dScale);
79 }
80 else
81 {
82 TGERROR("Warning: Volume fraction is not realistic: " << dScale << ", Yarn: " << YarnIndex);
83 }
84 }
85
86 return Distribution(dScale, m_dDropOff*dScale, Location.x, dMaxX);
87}
88
89double CFibreDistribution1DQuad::Distribution(double max, double min, double x, double dMaxX) const
90{
91 double xScaled = x / dMaxX;
92 return min + (max - min)*(1-xScaled*xScaled);
93}
94
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Definition: Logger.h:29
double Distribution(double max, double min, double x, double dMaxX) const
double ComputeMaxX(const vector< XY > &Section) const
double GetVolumeFraction(const vector< XY > &Section, double dFibreArea, XY Location, int YarnIndex=-1) const
Get the volume fraction for a given location.
double IntegrateDistribution(const vector< XY > &Section, double dMaxX) const
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
Abstract base class that defines how the fibres are distributed within a yarn.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
Struct for representing points in 2D space.
Definition: mymath.h:103
double x
Definition: mymath.h:104