Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writeabaqus.cpp
3206 views
//1// Write Abaqus file2//3//45#include <mystdlib.h>67#include <myadt.hpp>8#include <linalg.hpp>9#include <csg.hpp>10#include <meshing.hpp>1112namespace netgen13{14#include "writeuser.hpp"1516171819void WriteAbaqusFormat (const Mesh & mesh,20const string & filename)2122{2324cout << "\nWrite Abaqus Volume Mesh" << endl;2526ofstream outfile (filename.c_str());2728outfile << "*Heading" << endl;29outfile << " " << filename << endl;3031outfile.precision(8);3233outfile << "*Node" << endl;3435int np = mesh.GetNP();36int ne = mesh.GetNE();37int i, j, k;3839for (i = 1; i <= np; i++)40{41outfile << i << ", ";42outfile << mesh.Point(i)(0) << ", ";43outfile << mesh.Point(i)(1) << ", ";44outfile << mesh.Point(i)(2) << "\n";45}4647int elemcnt = 0; //element counter48int finished = 0;49int indcnt = 1; //index counter5051while (!finished)52{53int actcnt = 0;54const Element & el1 = mesh.VolumeElement(1);55int non = el1.GetNP();56if (non == 4)57{58outfile << "*Element, type=C3D4, ELSET=PART" << indcnt << endl;59}60else if (non == 10)61{62outfile << "*Element, type=C3D10, ELSET=PART" << indcnt << endl;63}64else65{66cout << "unsupported Element type!!!" << endl;67}6869for (i = 1; i <= ne; i++)70{71const Element & el = mesh.VolumeElement(i);7273if (el.GetIndex() == indcnt)74{75actcnt++;76if (el.GetNP() != non)77{78cout << "different element-types in a subdomain are not possible!!!" << endl;79continue;80}8182elemcnt++;83outfile << elemcnt << ", ";84if (non == 4)85{86outfile << el.PNum(1) << ", ";87outfile << el.PNum(2) << ", ";88outfile << el.PNum(4) << ", ";89outfile << el.PNum(3) << "\n";90}91else if (non == 10)92{93outfile << el.PNum(1) << ", ";94outfile << el.PNum(2) << ", ";95outfile << el.PNum(4) << ", ";96outfile << el.PNum(3) << ", ";97outfile << el.PNum(5) << ", ";98outfile << el.PNum(9) << ", ";99outfile << el.PNum(7) << ", " << "\n";100outfile << el.PNum(6) << ", ";101outfile << el.PNum(8) << ", ";102outfile << el.PNum(10) << "\n";103}104else105{106cout << "unsupported Element type!!!" << endl;107for (j = 1; j <= el.GetNP(); j++)108{109outfile << el.PNum(j);110if (j != el.GetNP()) outfile << ", ";111}112outfile << "\n";113}114}115}116indcnt++;117if (elemcnt == ne) {finished = 1; cout << "all elements found by Index!" << endl;}118if (actcnt == 0) {finished = 1;}119}120121if (mesh.GetIdentifications().GetMaxNr())122{123// periodic identification, implementation for124// Helmut J. Boehm, TU Vienna125126char cfilename[255];127strcpy (cfilename, filename.c_str());128129char mpcfilename[255];130strcpy (mpcfilename, cfilename);131size_t len = strlen (cfilename);132if (len >= 4 && (strcmp (mpcfilename+len-4, ".inp") == 0))133strcpy (mpcfilename+len-4, ".mpc");134else135strcat (mpcfilename, ".mpc");136137ofstream mpc (mpcfilename);138139int masternode(0);140141ARRAY<INDEX_2> pairs;142BitArray master(np), help(np);143master.Set();144for (i = 1; i <= 3; i++)145{146mesh.GetIdentifications().GetPairs (i, pairs);147help.Clear();148for (j = 1; j <= pairs.Size(); j++)149{150help.Set (pairs.Get(j).I1());151}152master.And (help);153}154for (i = 1; i <= np; i++)155if (master.Test(i))156masternode = i;157158cout << "masternode = " << masternode << " = "159<< mesh.Point(masternode) << endl;160ARRAY<int> slaves(3);161for (i = 1; i <= 3; i++)162{163mesh.GetIdentifications().GetPairs (i, pairs);164for (j = 1; j <= pairs.Size(); j++)165{166if (pairs.Get(j).I1() == masternode)167slaves.Elem(i) = pairs.Get(j).I2();168}169cout << "slave(" << i << ") = " << slaves.Get(i)170<< " = " << mesh.Point(slaves.Get(i)) << endl;171}172173174outfile << "**\n"175<< "*NSET,NSET=CTENODS\n"176<< slaves.Get(1) << ", "177<< slaves.Get(2) << ", "178<< slaves.Get(3) << endl;179180181outfile << "**\n"182<< "**POINT_fixed\n"183<< "**\n"184<< "*BOUNDARY, OP=NEW\n";185for (j = 1; j <= 3; j++)186outfile << masternode << ", " << j << ",, 0.\n";187188outfile << "**\n"189<< "*BOUNDARY, OP=NEW\n";190for (j = 1; j <= 3; j++)191{192Vec3d v(mesh.Point(masternode), mesh.Point(slaves.Get(j)));193double vlen = v.Length();194int dir = 0;195if (fabs (v.X()) > 0.9 * vlen) dir = 2;196if (fabs (v.Y()) > 0.9 * vlen) dir = 3;197if (fabs (v.Z()) > 0.9 * vlen) dir = 1;198if (!dir)199cout << "ERROR: Problem with rigid body constraints" << endl;200outfile << slaves.Get(j) << ", " << dir << ",, 0.\n";201}202203outfile << "**\n"204<< "*EQUATION, INPUT=" << mpcfilename << endl;205206207BitArray eliminated(np);208eliminated.Clear();209for (i = 1; i <= mesh.GetIdentifications().GetMaxNr(); i++)210{211mesh.GetIdentifications().GetPairs (i, pairs);212if (!pairs.Size())213continue;214215for (j = 1; j <= pairs.Size(); j++)216if (pairs.Get(j).I1() != masternode &&217!eliminated.Test(pairs.Get(j).I2()))218{219eliminated.Set (pairs.Get(j).I2());220for (k = 1; k <= 3; k++)221{222mpc << "4" << "\n";223mpc << pairs.Get(j).I2() << "," << k << ", -1.0, ";224mpc << pairs.Get(j).I1() << "," << k << ", 1.0, ";225mpc << slaves.Get(i) << "," << k << ", 1.0, ";226mpc << masternode << "," << k << ", -1.0 \n";227}228}229}230}231232233cout << "done" << endl;234}235236}237238239