1 //
2 // Write Permas file
3 // for Intes GmbH, Stuttgart
4 //
5 
6 #include <mystdlib.h>
7 
8 #include <myadt.hpp>
9 #include <linalg.hpp>
10 #include <csg.hpp>
11 #include <meshing.hpp>
12 
13 #include <string>
14 
15 using namespace std;
16 
17 namespace netgen
18 {
19 #include "writeuser.hpp"
20     // Forward declarations (don't know, where to define them, sorry)
21     int addComponent(string &strComp, string &strSitu, ofstream &out);
22 
23 
24     // This should be the new function to export a PERMAS file
WritePermasFormat(const Mesh & mesh,const string & filename,string & strComp,string & strSitu)25     void WritePermasFormat (const Mesh &mesh, const string &filename,
26                             string &strComp, string &strSitu)
27     {
28         ofstream outfile (filename.c_str());
29         addComponent(strComp, strSitu, outfile);
30         WritePermasFormat ( mesh, filename);
31     }
32 
WritePermasFormat(const Mesh & mesh,const string & filename)33     void WritePermasFormat (const Mesh &mesh, const string &filename)
34     {
35         string strComp, strSitu;
36         ofstream outfile (filename.c_str());
37 
38         outfile.precision(8);
39 
40         strSitu = strComp = "";
41         if (addComponent(strComp, strSitu, outfile) == 1) {
42             printf("Error while exporting PERMAS dat!\n");
43             return;
44         }
45 
46         int np = mesh.GetNP();
47         int ne = mesh.GetNE();
48         int nse = mesh.GetNSE();
49         int i, j, k;
50 
51         if (ne == 0)
52         {
53             // pure surface mesh
54             cout << "\nWrite Permas Surface Mesh" << endl;
55 
56             int elnr = 0;
57             for (j = 1; j <= 2; j++)
58             {
59                 int nelp(0);
60                 switch (j)
61                 {
62                 case 1:
63                     nelp = 3;
64                     outfile << "$ELEMENT TYPE = TRIA3  ESET = ALLQUAD" << endl;
65                     break;
66                 case 2:
67                     nelp = 4;
68                     outfile << "$ELEMENT TYPE = QUAD4  ESET = ALLQUAD" << endl;
69                     break;
70                 }
71 
72                 for (i = 1; i <= nse; i++)
73                 {
74                     const Element2d & el = mesh.SurfaceElement(i);
75                     if (el.GetNP() != nelp)
76                         continue;
77 
78                     elnr++;
79                     outfile << elnr << "  ";
80                     for (k = 1; k <= nelp; k++)
81                         outfile << " " << el.PNum(k);
82                     outfile << endl;
83 
84                 }
85             }
86         }
87         else
88         {
89             cout << "\nWrite Permas Volume Mesh" << endl;
90 
91             int secondorder = (mesh.VolumeElement(1).GetNP() == 10);
92 
93             if (!secondorder)
94             {
95                 outfile << "$ELEMENT TYPE = TET4  ESET = ALLTET" << endl;
96                 for (i = 1; i <= ne; i++)
97                 {
98                     const Element & el = mesh.VolumeElement(i);
99                     outfile << i
100                             << " " << el.PNum(1)
101                             << " " << el.PNum(2)
102                             << " " << el.PNum(3)
103                             << " " << el.PNum(4) << endl;
104                 }
105             }
106             else
107             {
108                 outfile << "$ELEMENT TYPE = TET10  ESET = ALLTET" << endl;
109                 for (i = 1; i <= ne; i++)
110                 {
111                     const Element & el = mesh.VolumeElement(i);
112                     outfile << i
113                             << " " << el.PNum(1)
114                             << " " << el.PNum(5)
115                             << " " << el.PNum(2)
116                             << " " << el.PNum(8)
117                             << " " << el.PNum(3)
118                             << " " << el.PNum(6) << endl << "& "
119                             << " " << el.PNum(7)
120                             << " " << el.PNum(9)
121                             << " " << el.PNum(10)
122                             << " " << el.PNum(4) << endl;
123                 }
124             }
125 
126             outfile << endl << endl;
127 
128 
129             outfile << "$SURFACE GEO  SURFID = 1  SFSET = ALLSUR" << endl;
130             for (i = 1; i <= nse; i++)
131             {
132                 const Element2d & el = mesh.SurfaceElement(i);
133                 if (el.GetNP() == 3)
134                     outfile << "STRIA3"
135                             << " " << el.PNum(1)
136                             << " " << el.PNum(2)
137                             << " " << el.PNum(3) << endl;
138             }
139 
140             for (i = 1; i <= nse; i++)
141             {
142                 const Element2d & el = mesh.SurfaceElement(i);
143                 if (el.GetNP() == 4)
144                     outfile << "SQUAD4"
145                             << " " << el.PNum(1)
146                             << " " << el.PNum(2)
147                             << " " << el.PNum(3)
148                             << " " << el.PNum(4) << endl;
149             }
150 
151             for (i = 1; i <= nse; i++)
152             {
153                 const Element2d & el = mesh.SurfaceElement(i);
154                 if (el.GetNP() == 6)
155                     outfile << "STRIA6"
156                             << " " << el.PNum(1)
157                             << " " << el.PNum(4)
158                             << " " << el.PNum(2)
159                             << " " << el.PNum(5)
160                             << " " << el.PNum(3)
161                             << " " << el.PNum(6) << endl;
162             }
163         }
164 
165 
166         outfile << endl << endl;
167 
168         outfile << "$COOR  NSET = ALLNODES" << endl;
169 
170         outfile.precision(6);
171         outfile.setf (ios::fixed, ios::floatfield);
172         outfile.setf (ios::showpoint);
173 
174         for (i = 1; i <= np; i++)
175         {
176             outfile << i << " ";
177             outfile << mesh.Point(i)(0) << " ";
178             outfile << mesh.Point(i)(1) << " ";
179             outfile << mesh.Point(i)(2) << "\n";
180         }
181     }
182     //////////////////////////////////////////////////////////////////////////////////
183     // \brief Writes PERMAS configuration header into export file
184     //        Returns >0 in case of errors
185     // \par string &strComp  : Reference to component description
186     // \par string &strComp  : Reference to situation description
187     //////////////////////////////////////////////////////////////////////////////////
addComponent(string & strComp,string & strSitu,ofstream & out)188     int addComponent(string &strComp, string &strSitu, ofstream &out)
189     {
190         if (strComp.size() > 12 || strSitu > 12)
191             return 1;
192 
193         if (0 == strComp.size())
194             strComp = "KOMPO1";
195 
196         if (0 == strSitu.size())
197             strSitu = "SIT1";
198 
199         // Writing description header of configuration
200         out << "$ENTER COMPONENT  NAME = " << strComp << "  DOFTYPE = DISP MATH" << endl << endl;
201         out << "   $SITUATION  NAME = " << strSitu << endl;
202         out << "   $END SITUATION" << endl << endl;
203         out << "   $STRUCTURE" << endl;
204 
205         return 0;
206     }
207 
208 }
209