TexGen
Materials.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2017 Louise Brown
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"
21#include "Materials.h"
22#include "TexGen.h"
23
24#define DEFAULT_E 1e+9
25#define DEFAULT_v 0.1
26#define DEFAULT_G 1e+9
27#define DEFAULT_A 3e-6
28
29using namespace TexGen;
30
31void CTextileMaterials::SetupMaterials( CTextile &Textile )
32{
33 int iNumYarns = Textile.GetNumYarns();
34 int i;
35 int j = 0;
36
37 map<string, pair<CObjectContainer<CMaterial>, CObjectContainer<CMaterial> > >::iterator itMaterial;
38
39 m_Materials.clear();
40
41 for( i = -1; i < iNumYarns; ++i )
42 {
43 pair< vector<double>,vector<double> > YarnConstants;
44 if ( i == -1 )
45 {
46 YarnConstants.first.push_back( Textile.GetMatrixYoungsModulus("Pa") );
47 YarnConstants.first.push_back( Textile.GetMatrixPoissonsRatio() );
48 YarnConstants.second.push_back( Textile.GetMatrixAlpha() );
49 }
50 else
51 {
52 CYarn* Yarn = Textile.GetYarn(i);
53 YarnConstants.first.push_back( Yarn->GetYoungsModulusX("Pa") );
54 YarnConstants.first.push_back( Yarn->GetYoungsModulusY("Pa") );
55 YarnConstants.first.push_back( Yarn->GetYoungsModulusZ("Pa") );
56 YarnConstants.first.push_back( Yarn->GetPoissonsRatioX() );
57 YarnConstants.first.push_back( Yarn->GetPoissonsRatioY() );
58 YarnConstants.first.push_back( Yarn->GetPoissonsRatioZ() );
59 YarnConstants.first.push_back( Yarn->GetShearModulusXY("Pa") );
60 YarnConstants.first.push_back( Yarn->GetShearModulusXZ("Pa") );
61 YarnConstants.first.push_back( Yarn->GetShearModulusYZ("Pa") );
62 YarnConstants.second.push_back( Yarn->GetAlphaX("/K") );
63 YarnConstants.second.push_back( Yarn->GetAlphaY("/K") );
64 YarnConstants.second.push_back( Yarn->GetAlphaZ("/K") );
65 }
66
67 if ( CheckYarnConstants( YarnConstants ) )
68 {
69 if ( i == -1 )
70 {
71 TGERROR("One or more material constant not set for matrix, assigning defaults" );
72 }
73 else
74 {
75 TGERROR("One or more material constant not set for yarn " << i << ", assigning defaults" );
76 }
77 }
78
79 for (itMaterial = m_Materials.begin(); itMaterial != m_Materials.end(); ++itMaterial)
80 {
81 // Find corresponding material if already created and assign to yarn
82 pair< CObjectContainer<CMaterial>, CObjectContainer<CMaterial> > Material = itMaterial->second;
83 vector<double> &MatConstants = Material.first->GetConstants();
84 vector<double> &ThermConstants = Material.second->GetConstants();
85
86 if ( MatConstants.size() == YarnConstants.first.size() && ThermConstants.size() == YarnConstants.second.size() )
87 {
88 if ( CompareMaterialConstants( MatConstants, ThermConstants, YarnConstants ) )
89 {
90 AssignMaterial( itMaterial->first, i );
91 break;
92 }
93 }
94 }
95 if ( itMaterial == m_Materials.end() ) // Yarn properties not from existing material so create new one & assign to yarn
96 {
97 string Name = "Mat" + stringify(j);
98 AddMaterial( Name, YarnConstants );
99 AssignMaterial( Name, i );
100 ++j;
101 }
102 }
103
104
105}
106
107void CTextileMaterials::AssignMaterial(string Material, int iYarn)
108{
109 m_MaterialAssignements[iYarn] = Material;
110}
111
112void CTextileMaterials::AssignMaterial(string Material, const vector<int> &Yarns)
113{
114 vector<int>::const_iterator itYarn;
115 for (itYarn = Yarns.begin(); itYarn != Yarns.end(); ++itYarn)
116 {
117 m_MaterialAssignements[*itYarn] = Material;
118 }
119}
120
121bool CTextileMaterials::CompareMaterialConstants( const vector<double> &MatConstants, const vector<double> &ThermConstants, const pair< vector<double>, vector<double> > &Constants )
122{
123 vector<double>::const_iterator itMatConstants, itThermConstants, itConstants;
124
125 for( itMatConstants = MatConstants.begin(), itConstants = Constants.first.begin(); itMatConstants != MatConstants.end(); ++itMatConstants, ++itConstants )
126 {
127 if ( *itMatConstants != *itConstants )
128 return false;
129 }
130 for( itThermConstants = ThermConstants.begin(), itConstants = Constants.second.begin(); itThermConstants != ThermConstants.end(); ++itThermConstants, ++itConstants )
131 {
132 if ( *itThermConstants != *itConstants )
133 return false;
134 }
135 return true;
136}
137
138void CTextileMaterials::AddMaterial(string Name, const pair< vector<double>, vector<double> > &Constants)
139{
140 pair< CObjectContainer<CMaterial>, CObjectContainer<CMaterial> > materials;
141 materials.first = CUMAT(Constants.first);
142 materials.second = CUMAT(Constants.second);
143 //m_Materials[Name] = CUMAT(Constants);
144 m_Materials[Name] = materials;
145}
146
147bool CTextileMaterials::CheckYarnConstants( pair< vector<double>, vector<double> > &Constants )
148{
149 vector<double>::iterator itConstants;
150 bool bSetDefault = false;
151
152 int i;
153 int iNumConstants = Constants.first.size();
154
155 for( itConstants = Constants.first.begin(), i = 0; itConstants != Constants.first.end(); ++itConstants, ++i )
156 {
157
158 if ( *itConstants == 0.0 )
159 {
160 if ( iNumConstants == 2 )
161 {
162 *itConstants = i == 0 ? DEFAULT_E : DEFAULT_v;
163 }
164 else
165 {
166 if ( i < 3 )
167 *itConstants = DEFAULT_E;
168 else if ( i > 5 )
169 *itConstants = DEFAULT_G;
170 else
171 *itConstants = DEFAULT_v;
172 }
173 bSetDefault = true;
174 }
175 }
176 for( itConstants = Constants.second.begin(), i = 0; itConstants != Constants.second.end(); ++itConstants, ++i )
177 {
178 if ( *itConstants == 0.0 )
179 {
180 *itConstants = DEFAULT_A;
181 bSetDefault = true;
182 }
183 }
184 return bSetDefault;
185}
186
187void CTextileMaterials::OutputMaterials(ostream &Output, int iNumYarns, bool bMatrixOnly )
188{
189 Output << "*****************" << endl;
190 Output << "*** MATERIALS ***" << endl;
191 Output << "*****************" << endl;
192
193 map<string, pair<CObjectContainer<CMaterial>, CObjectContainer<CMaterial> > >::iterator itMaterial;
194 for (itMaterial = m_Materials.begin(); itMaterial != m_Materials.end(); ++itMaterial)
195 {
196 Output << "*Material, Name=" << itMaterial->first << endl;
197 if ( itMaterial->second.first->GetConstants().size() == 2 )
198 Output << itMaterial->second.first->GetAbaqusCommands();
199 else
200 Output << itMaterial->second.first->GetAbaqusCommands( "ENGINEERING CONSTANTS" );
201
202 if ( itMaterial->second.second->GetConstants().size() == 1 )
203 Output << itMaterial->second.second->GetThermAbaqusCommands("");
204 else
205 Output << itMaterial->second.second->GetThermAbaqusCommands( "ORTHO" );
206 }
207 int i;
208 string MatName;
209 for (i = -1; i < iNumYarns; ++i)
210 {
211 if (m_MaterialAssignements.count(i))
212 MatName = m_MaterialAssignements[i];
213 else
214 MatName = m_Materials.begin()->first;
215 if ( i == -1 )
216 {
217 Output << "*Solid Section, ElSet=Matrix, Material=" << MatName << endl;
218 Output << "1.0," << endl;
219 }
220 else if (!bMatrixOnly)
221 {
222 Output << "*Solid Section, ElSet=Yarn" << i << ", Material=" << MatName << ", Orientation=TexGenOrientations" << endl;
223 Output << "1.0," << endl;
224 }
225 }
226}
227
228string CUMAT::GetAbaqusCommands( string Type )
229{
230 ostringstream Output;
231 if ( Type == "" )
232 Output << "*Elastic" << endl;
233 else
234 Output << "*Elastic, type=" << Type << endl;
235
236 WriteValues(Output, m_Constants, 8);
237 return Output.str();
238}
239
240string CUMAT::GetThermAbaqusCommands( string Type )
241{
242 ostringstream Output;
243 if ( Type == "" )
244 Output << "*Expansion" << endl;
245 else
246 Output << "*Expansion, type=" << Type << endl;
247 WriteValues(Output, m_Constants, 8);
248 return Output.str();
249}
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Definition: Logger.h:29
#define DEFAULT_v
Definition: Materials.cpp:25
#define DEFAULT_E
Definition: Materials.cpp:24
#define DEFAULT_G
Definition: Materials.cpp:26
#define DEFAULT_A
Definition: Materials.cpp:27
Object container to help handle memory management issues.
double GetShearModulusYZ(string Units="MPa") const
Definition: Properties.cpp:314
double GetAlphaZ(string Units="/K") const
Definition: Properties.cpp:329
double GetAlphaY(string Units="/K") const
Definition: Properties.cpp:324
double GetYoungsModulusY(string Units="MPa") const
Definition: Properties.cpp:294
double GetPoissonsRatioY() const
Definition: Properties.cpp:339
double GetPoissonsRatioZ() const
Definition: Properties.cpp:344
double GetYoungsModulusX(string Units="MPa") const
Definition: Properties.cpp:289
double GetPoissonsRatioX() const
Definition: Properties.cpp:334
double GetAlphaX(string Units="/K") const
Definition: Properties.cpp:319
double GetShearModulusXZ(string Units="MPa") const
Definition: Properties.cpp:309
double GetYoungsModulusZ(string Units="MPa") const
Definition: Properties.cpp:299
double GetShearModulusXY(string Units="MPa") const
Definition: Properties.cpp:304
double GetMatrixYoungsModulus(string Units="MPa") const
Represents a textile cell containing yarns.
Definition: Textile.h:39
int GetNumYarns() const
Definition: Textile.cpp:704
const CYarn * GetYarn(int iIndex) const
Definition: Textile.cpp:693
void OutputMaterials(ostream &Output, int iNumYarns, bool bMatrixOnly)
Output materials and assign to yarn element sets.
Definition: Materials.cpp:187
map< string, pair< CObjectContainer< CMaterial >, CObjectContainer< CMaterial > > > m_Materials
Definition: Materials.h:81
bool CheckYarnConstants(pair< vector< double >, vector< double > > &Constants)
Check if material constants have been assigned (ie != 0). Return false if all 0.0.
Definition: Materials.cpp:147
map< int, string > m_MaterialAssignements
Output materials and assign to yarn element sets.
Definition: Materials.h:80
bool CompareMaterialConstants(const vector< double > &MatConstants, const vector< double > &ThermConstants, const pair< vector< double >, vector< double > > &Constants)
Compare two sets of material constants. Return true if identical.
Definition: Materials.cpp:121
void AssignMaterial(string Material, int iYarn)
Assign the material to a given yarn.
Definition: Materials.cpp:107
void AddMaterial(string Name, const pair< vector< double >, vector< double > > &Constants)
Add a material with associated name, this should then be assigned to yarns individually.
Definition: Materials.cpp:138
Represents a UMAT material definition.
Definition: Materials.h:39
string GetThermAbaqusCommands(string Type="")
Definition: Materials.cpp:240
vector< double > m_Constants
Definition: Materials.h:50
string GetAbaqusCommands(string Type="")
Definition: Materials.cpp:228
Represents a yarn consisting of master nodes, section and interpolation function.
Definition: Yarn.h:49
Namespace containing a series of customised math operations not found in the standard c++ library.
void WriteValues(std::ostream &Output, T &Values, int iMaxPerLine)
Definition: Misc.h:274
std::string stringify(const T &x, int iPrecision=12, bool bScientific=true)
Function to convert a value (e.g. int, double, etc...) to a string.
Definition: Misc.h:50