File: writepermas.cpp

package info (click to toggle)
netgen 6.2.2601%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 13,076 kB
  • sloc: cpp: 166,627; tcl: 6,310; python: 2,868; sh: 522; makefile: 90
file content (210 lines) | stat: -rw-r--r-- 7,190 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//
// Write Permas file
// for Intes GmbH, Stuttgart
//

#include <mystdlib.h>

#include <myadt.hpp>
#include <linalg.hpp>
#include <csg.hpp>
#include <meshing.hpp>

#include <string>

#include "writeuser.hpp"
using namespace std;

namespace netgen
{
    // Forward declarations (don't know, where to define them, sorry)
    int addComponent(string &strComp, string &strSitu, ofstream &out);

    void WritePermasFormat (const Mesh &mesh, const filesystem::path &filename);

    // This should be the new function to export a PERMAS file
    void WritePermasFormat (const Mesh &mesh, const filesystem::path &filename, 
                            string &strComp, string &strSitu) 
    {
        ofstream outfile (filename);
        addComponent(strComp, strSitu, outfile);
        WritePermasFormat ( mesh, filename);
    }

    void WritePermasFormat (const Mesh &mesh, const filesystem::path &filename)
    {
        string strComp, strSitu;
        ofstream outfile (filename);
        
        outfile.precision(8);

        strSitu = strComp = "";
        if (addComponent(strComp, strSitu, outfile) == 1) {
            printf("Error while exporting PERMAS dat!\n");
            return;
        }
    
        int np = mesh.GetNP();
        int ne = mesh.GetNE();
        int nse = mesh.GetNSE();
        int i, j, k;
    
        if (ne == 0)
        {
            // pure surface mesh
            cout << "\nWrite Permas Surface Mesh" << endl;
            
            int elnr = 0;
            for (j = 1; j <= 2; j++)
            {
                int nelp(0);
                switch (j)
                {
                case 1:
                    nelp = 3;
                    outfile << "$ELEMENT TYPE = TRIA3  ESET = ALLQUAD" << endl;		  
                    break;
                case 2:
                    nelp = 4;
                    outfile << "$ELEMENT TYPE = QUAD4  ESET = ALLQUAD" << endl;		  
                    break;
                }
                
                for (i = 1; i <= nse; i++)
                {
                    const Element2d & el = mesh.SurfaceElement(i);
                    if (el.GetNP() != nelp)
                        continue;
                    
                    elnr++;
                    outfile << elnr << "  ";
                    for (k = 1; k <= nelp; k++)
                        outfile << " " << el.PNum(k);
                    outfile << endl;
                    
                }
            }
        }
        else
        {
            cout << "\nWrite Permas Volume Mesh" << endl;
            
            int secondorder = (mesh.VolumeElement(1).GetNP() == 10);
            
            if (!secondorder)
            {
                outfile << "$ELEMENT TYPE = TET4  ESET = ALLTET" << endl;
                for (i = 1; i <= ne; i++)
                {
                    const Element & el = mesh.VolumeElement(i);
                    outfile << i 
                            << " " << el.PNum(1) 
                            << " " << el.PNum(2) 
                            << " " << el.PNum(4) 
                            << " " << el.PNum(3) << endl;
                }
            }
            else
            {
                outfile << "$ELEMENT TYPE = TET10  ESET = ALLTET" << endl;
                for (i = 1; i <= ne; i++)
                {
                    const Element & el = mesh.VolumeElement(i);
                    outfile << i 
                            << " " << el.PNum(1) 
                            << " " << el.PNum(5) 
                            << " " << el.PNum(2) 
                            << " " << el.PNum(8) 
                            << " " << el.PNum(3) 
                            << " " << el.PNum(6) << endl << "& "
                            << " " << el.PNum(7) 
                            << " " << el.PNum(9) 
                            << " " << el.PNum(10) 
                            << " " << el.PNum(4) << endl;
                }
            }
            
            outfile << endl << endl;
            
            
            outfile << "$SURFACE GEO  SURFID = 1  SFSET = ALLSUR" << endl;
            for (i = 1; i <= nse; i++)
            {
                const Element2d & el = mesh.SurfaceElement(i);
                if (el.GetNP() == 3)
                    outfile << "STRIA3"
                            << " " << el.PNum(1) 
                            << " " << el.PNum(2) 
                            << " " << el.PNum(3) << endl;
            }    
            
            for (i = 1; i <= nse; i++)
            {
                const Element2d & el = mesh.SurfaceElement(i);
                if (el.GetNP() == 4)
                    outfile << "SQUAD4"
                            << " " << el.PNum(1) 
                            << " " << el.PNum(2) 
                            << " " << el.PNum(3) 
                            << " " << el.PNum(4) << endl;
            }      
            
            for (i = 1; i <= nse; i++)
            {
                const Element2d & el = mesh.SurfaceElement(i);
                if (el.GetNP() == 6)
                    outfile << "STRIA6"
                            << " " << el.PNum(1) 
                            << " " << el.PNum(4) 
                            << " " << el.PNum(2) 
                            << " " << el.PNum(5) 
                            << " " << el.PNum(3) 
                            << " " << el.PNum(6) << endl;
            }      
        }
        
        
        outfile << endl << endl;
        
        outfile << "$COOR  NSET = ALLNODES" << endl;
        
        outfile.precision(6);
        outfile.setf (ios::fixed, ios::floatfield);
        outfile.setf (ios::showpoint);
        
        for (i = 1; i <= np; i++)
        {
            outfile << i << " ";
            outfile << mesh.Point(i)(0) << " ";
            outfile << mesh.Point(i)(1) << " ";
            outfile << mesh.Point(i)(2) << "\n";
        }
    }
    ////////////////////////////////////////////////////////////////////////////////// 
    // \brief Writes PERMAS configuration header into export file
    //        Returns >0 in case of errors
    // \par string &strComp  : Reference to component description
    // \par string &strComp  : Reference to situation description
    ////////////////////////////////////////////////////////////////////////////////// 
    int addComponent(string &strComp, string &strSitu, ofstream &out)
    {
        if (strComp.size() > 12 || strSitu > 12) 
            return 1;

        if (0 == strComp.size()) 
            strComp = "KOMPO1";
        
        if (0 == strSitu.size())
            strSitu = "SIT1";

        // Writing description header of configuration
        out << "$ENTER COMPONENT  NAME = " << strComp << "  DOFTYPE = DISP MATH" << endl << endl;
        out << "   $SITUATION  NAME = " << strSitu << endl;
        out << "   $END SITUATION" << endl << endl;
        out << "   $STRUCTURE" << endl;
        
        return 0;
    }
    
static RegisterUserFormat reg_permas ("Permas Format", {".mesh"}, nullopt, static_cast<void(*)(const Mesh &, const filesystem::path&)>(&WritePermasFormat));
}