Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writepermas.cpp
3206 views
//1// Write Permas file2// for Intes GmbH, Stuttgart3//45#include <mystdlib.h>67#include <myadt.hpp>8#include <linalg.hpp>9#include <csg.hpp>10#include <meshing.hpp>1112#include <string>1314using namespace std;1516namespace netgen17{18#include "writeuser.hpp"19// Forward declarations (don't know, where to define them, sorry)20int addComponent(string &strComp, string &strSitu, ofstream &out);212223// This should be the new function to export a PERMAS file24void WritePermasFormat (const Mesh &mesh, const string &filename,25string &strComp, string &strSitu)26{27ofstream outfile (filename.c_str());28addComponent(strComp, strSitu, outfile);29WritePermasFormat ( mesh, filename);30}3132void WritePermasFormat (const Mesh &mesh, const string &filename)33{34string strComp, strSitu;35ofstream outfile (filename.c_str());3637outfile.precision(8);3839strSitu = strComp = "";40if (addComponent(strComp, strSitu, outfile) == 1) {41printf("Error while exporting PERMAS dat!\n");42return;43}4445int np = mesh.GetNP();46int ne = mesh.GetNE();47int nse = mesh.GetNSE();48int i, j, k;4950if (ne == 0)51{52// pure surface mesh53cout << "\nWrite Permas Surface Mesh" << endl;5455int elnr = 0;56for (j = 1; j <= 2; j++)57{58int nelp(0);59switch (j)60{61case 1:62nelp = 3;63outfile << "$ELEMENT TYPE = TRIA3 ESET = ALLQUAD" << endl;64break;65case 2:66nelp = 4;67outfile << "$ELEMENT TYPE = QUAD4 ESET = ALLQUAD" << endl;68break;69}7071for (i = 1; i <= nse; i++)72{73const Element2d & el = mesh.SurfaceElement(i);74if (el.GetNP() != nelp)75continue;7677elnr++;78outfile << elnr << " ";79for (k = 1; k <= nelp; k++)80outfile << " " << el.PNum(k);81outfile << endl;8283}84}85}86else87{88cout << "\nWrite Permas Volume Mesh" << endl;8990int secondorder = (mesh.VolumeElement(1).GetNP() == 10);9192if (!secondorder)93{94outfile << "$ELEMENT TYPE = TET4 ESET = ALLTET" << endl;95for (i = 1; i <= ne; i++)96{97const Element & el = mesh.VolumeElement(i);98outfile << i99<< " " << el.PNum(1)100<< " " << el.PNum(2)101<< " " << el.PNum(3)102<< " " << el.PNum(4) << endl;103}104}105else106{107outfile << "$ELEMENT TYPE = TET10 ESET = ALLTET" << endl;108for (i = 1; i <= ne; i++)109{110const Element & el = mesh.VolumeElement(i);111outfile << i112<< " " << el.PNum(1)113<< " " << el.PNum(5)114<< " " << el.PNum(2)115<< " " << el.PNum(8)116<< " " << el.PNum(3)117<< " " << el.PNum(6) << endl << "& "118<< " " << el.PNum(7)119<< " " << el.PNum(9)120<< " " << el.PNum(10)121<< " " << el.PNum(4) << endl;122}123}124125outfile << endl << endl;126127128outfile << "$SURFACE GEO SURFID = 1 SFSET = ALLSUR" << endl;129for (i = 1; i <= nse; i++)130{131const Element2d & el = mesh.SurfaceElement(i);132if (el.GetNP() == 3)133outfile << "STRIA3"134<< " " << el.PNum(1)135<< " " << el.PNum(2)136<< " " << el.PNum(3) << endl;137}138139for (i = 1; i <= nse; i++)140{141const Element2d & el = mesh.SurfaceElement(i);142if (el.GetNP() == 4)143outfile << "SQUAD4"144<< " " << el.PNum(1)145<< " " << el.PNum(2)146<< " " << el.PNum(3)147<< " " << el.PNum(4) << endl;148}149150for (i = 1; i <= nse; i++)151{152const Element2d & el = mesh.SurfaceElement(i);153if (el.GetNP() == 6)154outfile << "STRIA6"155<< " " << el.PNum(1)156<< " " << el.PNum(4)157<< " " << el.PNum(2)158<< " " << el.PNum(5)159<< " " << el.PNum(3)160<< " " << el.PNum(6) << endl;161}162}163164165outfile << endl << endl;166167outfile << "$COOR NSET = ALLNODES" << endl;168169outfile.precision(6);170outfile.setf (ios::fixed, ios::floatfield);171outfile.setf (ios::showpoint);172173for (i = 1; i <= np; i++)174{175outfile << i << " ";176outfile << mesh.Point(i)(0) << " ";177outfile << mesh.Point(i)(1) << " ";178outfile << mesh.Point(i)(2) << "\n";179}180}181//////////////////////////////////////////////////////////////////////////////////182// \brief Writes PERMAS configuration header into export file183// Returns >0 in case of errors184// \par string &strComp : Reference to component description185// \par string &strComp : Reference to situation description186//////////////////////////////////////////////////////////////////////////////////187int addComponent(string &strComp, string &strSitu, ofstream &out)188{189if (strComp.size() > 12 || strSitu > 12)190return 1;191192if (0 == strComp.size())193strComp = "KOMPO1";194195if (0 == strSitu.size())196strSitu = "SIT1";197198// Writing description header of configuration199out << "$ENTER COMPONENT NAME = " << strComp << " DOFTYPE = DISP MATH" << endl << endl;200out << " $SITUATION NAME = " << strSitu << endl;201out << " $END SITUATION" << endl << endl;202out << " $STRUCTURE" << endl;203204return 0;205}206207}208209210