Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writediffpack.cpp
3206 views
//1// Write diffpack file2//3// by4// Bartosz Sawicki <[email protected]>5// extended by6// Jacques Lechelle <[email protected]>7//8#include <mystdlib.h>910#include <myadt.hpp>11#include <linalg.hpp>12#include <csg.hpp>13#include <meshing.hpp>141516namespace netgen17{18#include "writeuser.hpp"192021void WriteDiffPackFormat (const Mesh & mesh,22const CSGeometry & geom,23const string & filename)24{25// double scale = globflags.GetNumFlag ("scale", 1);26double scale = 1;2728ofstream outfile(filename.c_str());2930if (mesh.GetDimension() == 3)3132{33// Output compatible to Diffpack grid format34// Bartosz Sawicki <[email protected]>3536int np = mesh.GetNP();37int ne = mesh.GetNE();38int nse = mesh.GetNSE();39ARRAY <int> BIname;40ARRAY <int> BCsinpoint;41int i, j, k, l;424344outfile.precision(6);45outfile.setf (ios::fixed, ios::floatfield);46outfile.setf (ios::showpoint);4748const Element & eldummy = mesh.VolumeElement((int)1);49outfile << "\n\n"50"Finite element mesh (GridFE):\n\n"51" Number of space dim. = 3\n"52" Number of elements = " << ne << "\n"53" Number of nodes = " << np << "\n\n"54" All elements are of the same type : dpTRUE\n"55" Max number of nodes in an element: "<< eldummy.GetNP() << "\n"56" Only one subdomain : dpFALSE\n"57" Lattice data ? 0\n\n\n\n";5859for (i = 1; i <= nse; i++)60{61int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty();62int nbi=BIname.Size();63int found=0;64for (j = 1; j <= nbi; j++)65if(BI == BIname.Get(j)) found = 1;66if( ! found ) BIname.Append(BI);67}6869outfile << " " << BIname.Size() << " Boundary indicators: ";70for (i =1 ; i <= BIname.Size(); i++)71outfile << BIname.Get(i) << " ";72outfile << "\n\n\n";7374outfile << " Nodal coordinates and nodal boundary indicators,\n"75" the columns contain:\n"76" - node number\n"77" - coordinates\n"78" - no of boundary indicators that are set (ON)\n"79" - the boundary indicators that are set (ON) if any.\n"80"#\n";8182for (i = 1; i <= np; i++)83{84const Point3d & p = mesh.Point(i);8586outfile.width(4);87outfile << i << " (";88outfile.width(10);89outfile << p.X()/scale << ", ";90outfile.width(9);91outfile << p.Y()/scale << ", ";92outfile.width(9);93outfile << p.Z()/scale << ") ";9495if(mesh[PointIndex(i)].Type() != INNERPOINT)96{97BCsinpoint.DeleteAll();98for (j = 1; j <= nse; j++)99{100for (k = 1; k <= mesh.SurfaceElement(j).GetNP(); k++)101{102if(mesh.SurfaceElement(j).PNum(k)==i)103{104int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty();105int nbcsp=BCsinpoint.Size();106int found = 0;107for (l = 1; l <= nbcsp; l++)108if(BC == BCsinpoint.Get(l)) found = 1;109if( ! found ) BCsinpoint.Append(BC);110}111}112}113int nbcsp = BCsinpoint.Size();114outfile << "[" << nbcsp << "] ";115for (j = 1; j <= nbcsp; j++)116outfile << BCsinpoint.Get(j) << " ";117outfile << "\n";118}119else outfile << "[0]\n";120121}122123outfile << "\n"124" Element types and connectivity\n"125" the columns contain:\n"126" - element number\n"127" - element type\n"128" - subdomain number\n"129" - the global node numbers of the nodes in the element.\n"130"#\n";131132for (i = 1; i <= ne; i++)133{134const Element & el = mesh.VolumeElement(i);135outfile.width(5);136if(el.GetNP()==4)137outfile << i << " ElmT4n3D ";138else139outfile << i << " ElmT10n3D ";140outfile.width(4);141outfile << el.GetIndex() << " ";142if(el.GetNP()==10)143{144outfile.width(8);145outfile << el.PNum(1);146outfile.width(8);147outfile << el.PNum(3);148outfile.width(8);149outfile << el.PNum(2);150outfile.width(8);151outfile << el.PNum(4);152outfile.width(8);153outfile << el.PNum(6);154outfile.width(8);155outfile << el.PNum(8);156outfile.width(8);157outfile << el.PNum(5);158outfile.width(8);159outfile << el.PNum(7);160outfile.width(8);161outfile << el.PNum(10);162outfile.width(8);163outfile << el.PNum(9);164}165else166{167outfile.width(8);168outfile << el.PNum(1);169outfile.width(8);170outfile << el.PNum(3);171outfile.width(8);172outfile << el.PNum(2);173outfile.width(8);174outfile << el.PNum(4);175}176outfile << "\n";177}178} /* Diffpack */179180else181182{183// Output compatible to Diffpack grid format 2D184185int np = mesh.GetNP();186//int ne = mesh.GetNE();187int nse = mesh.GetNSE();188ARRAY <int> BIname;189ARRAY <int> BCsinpoint;190int i, j, k, l;191192193outfile.precision(6);194outfile.setf (ios::fixed, ios::floatfield);195outfile.setf (ios::showpoint);196197outfile << "\n\n"198"Finite element mesh (GridFE):\n\n"199" Number of space dim. = 2\n"200" Number of elements = " << nse << "\n"201" Number of nodes = " << np << "\n\n"202" All elements are of the same type : dpTRUE\n"203" Max number of nodes in an element: 3\n"204" Only one subdomain : dpFALSE\n"205" Lattice data ? 0\n\n\n\n";206207for (i = 1; i <= nse; i++)208{209int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty();210int nbi=BIname.Size();211int found=0;212for (j = 1; j <= nbi; j++)213if(BI == BIname.Get(j)) found = 1;214if( ! found ) BIname.Append(BI);215}216217outfile << " " << BIname.Size() << " Boundary indicators: ";218for (i =1 ; i <= BIname.Size(); i++)219outfile << BIname.Get(i) << " ";220outfile << "\n\n\n";221222outfile << " Nodal coordinates and nodal boundary indicators,\n"223" the columns contain:\n"224" - node number\n"225" - coordinates\n"226" - no of boundary indicators that are set (ON)\n"227" - the boundary indicators that are set (ON) if any.\n"228"#\n";229230for (i = 1; i <= np; i++)231{232const Point3d & p = mesh.Point(i);233234outfile.width(4);235outfile << i << " (";236outfile.width(10);237outfile << p.X()/scale << ", ";238outfile.width(9);239outfile << p.Y()/scale << ", ";240241if(mesh[PointIndex(i)].Type() != INNERPOINT)242{243BCsinpoint.DeleteAll();244for (j = 1; j <= nse; j++)245{246for (k = 1; k <= 2; k++)247{248if(mesh.SurfaceElement(j).PNum(k)==i)249{250int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty();251int nbcsp=BCsinpoint.Size();252int found = 0;253for (l = 1; l <= nbcsp; l++)254if(BC == BCsinpoint.Get(l)) found = 1;255if( ! found ) BCsinpoint.Append(BC);256}257}258}259int nbcsp = BCsinpoint.Size();260outfile << "[" << nbcsp << "] ";261for (j = 1; j <= nbcsp; j++)262outfile << BCsinpoint.Get(j) << " ";263outfile << "\n";264}265else outfile << "[0]\n";266267}268269outfile << "\n"270" Element types and connectivity\n"271" the columns contain:\n"272" - element number\n"273" - element type\n"274" - subdomain number\n"275" - the global node numbers of the nodes in the element.\n"276"#\n";277278for (i = 1; i <= nse; i++)279{280const Element2d & el = mesh.SurfaceElement(i);281outfile.width(5);282outfile << i << " ElmT3n2D ";283outfile.width(4);284outfile << el.GetIndex() << " ";285outfile.width(8);286outfile << el.PNum(1);287outfile.width(8);288outfile << el.PNum(3);289outfile.width(8);290outfile << el.PNum(2);291outfile << "\n";292}293}294}295}296297298