2009-01-13 04:40:13 +05:00
|
|
|
//
|
|
|
|
// Read user dependent output file
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include <mystdlib.h>
|
|
|
|
#include <myadt.hpp>
|
|
|
|
#include <linalg.hpp>
|
|
|
|
#include <csg.hpp>
|
2019-09-20 14:31:52 +05:00
|
|
|
#include <stlgeom.hpp>
|
2009-01-13 04:40:13 +05:00
|
|
|
#include <meshing.hpp>
|
|
|
|
|
|
|
|
#include "writeuser.hpp"
|
|
|
|
|
2016-07-10 21:07:36 +05:00
|
|
|
namespace netgen
|
|
|
|
{
|
2009-01-13 04:40:13 +05:00
|
|
|
void ReadFile (Mesh & mesh,
|
2022-02-17 20:52:07 +05:00
|
|
|
const filesystem::path & filename)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
2019-05-21 13:51:39 +05:00
|
|
|
PrintMessage(3, "Read User File");
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
auto ext = filename.extension();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
char reco[100];
|
|
|
|
int np, nbe;
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".surf" )
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
cout << "Surface file" << endl;
|
|
|
|
|
|
|
|
ifstream in (filename);
|
|
|
|
|
|
|
|
in >> reco;
|
|
|
|
in >> np;
|
2009-04-20 03:15:26 +06:00
|
|
|
for (int i = 1; i <= np; i++)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
Point3d p;
|
|
|
|
in >> p.X() >> p.Y() >> p.Z();
|
|
|
|
mesh.AddPoint (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh.ClearFaceDescriptors();
|
2020-11-27 19:28:48 +05:00
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(1,1,0,0));
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
in >> nbe;
|
|
|
|
// int invert = globflags.GetDefineFlag ("invertsurfacemesh");
|
2009-04-20 03:15:26 +06:00
|
|
|
for (int i = 1; i <= nbe; i++)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
Element2d el;
|
|
|
|
el.SetIndex(1);
|
2009-04-20 03:15:26 +06:00
|
|
|
|
|
|
|
for (int j = 1; j <= 3; j++)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
in >> el.PNum(j);
|
|
|
|
// el.PNum(j)++;
|
|
|
|
if (el.PNum(j) < PointIndex(1) ||
|
|
|
|
el.PNum(j) > PointIndex(np))
|
|
|
|
{
|
|
|
|
cerr << "Point Number " << el.PNum(j) << " out of range 1..."
|
|
|
|
<< np << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (invert)
|
|
|
|
swap (el.PNum(2), el.PNum(3));
|
|
|
|
*/
|
|
|
|
|
|
|
|
mesh.AddSurfaceElement (el);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cout << "points: " << np << " faces: " << nbe << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".unv" )
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
char reco[100];
|
2014-08-20 01:58:36 +06:00
|
|
|
// int invert;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
ifstream in(filename);
|
|
|
|
|
|
|
|
mesh.ClearFaceDescriptors();
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
|
2019-03-29 18:38:38 +05:00
|
|
|
mesh.GetFaceDescriptor(1).SetBCProperty (1);
|
|
|
|
// map from unv element nr to our element number + an index if it is vol (0), bnd(1), ...
|
|
|
|
std::map<size_t, std::tuple<size_t, int>> element_map;
|
2019-07-15 19:07:32 +05:00
|
|
|
int dim = 3;
|
2019-08-01 01:55:43 +05:00
|
|
|
int bccounter = 0;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<Segment> tmp_segments;
|
2009-01-13 04:40:13 +05:00
|
|
|
while (in.good())
|
|
|
|
{
|
|
|
|
in >> reco;
|
2019-03-29 18:38:38 +05:00
|
|
|
if (strcmp(reco, "-1") == 0)
|
|
|
|
continue;
|
2011-07-20 21:08:39 +06:00
|
|
|
|
2019-03-29 18:38:38 +05:00
|
|
|
else if (strcmp (reco, "2411") == 0)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
cout << "nodes found" << endl;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int pi, hi;
|
2011-07-20 21:08:39 +06:00
|
|
|
Point<3> p;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
in >> pi;
|
|
|
|
if (pi == -1)
|
|
|
|
break;
|
2011-07-20 21:08:39 +06:00
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
in >> hi >> hi >> hi;
|
2011-07-20 21:08:39 +06:00
|
|
|
in >> p(0) >> p(1) >> p(2);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
mesh.AddPoint (p);
|
|
|
|
}
|
2011-07-20 21:08:39 +06:00
|
|
|
cout << "read " << mesh.GetNP() << " points" << endl;
|
2019-07-15 19:07:32 +05:00
|
|
|
Point3d pmin, pmax;
|
|
|
|
mesh.GetBox (pmin, pmax);
|
2019-07-16 13:42:27 +05:00
|
|
|
if(fabs(pmin.Z() - pmax.Z()) < 1e-10 * Dist(pmin, pmax))
|
2019-07-15 19:07:32 +05:00
|
|
|
{
|
|
|
|
cout << "Set Dimension to 2." << endl;
|
|
|
|
mesh.SetDimension(2);
|
|
|
|
dim = 2 ;
|
|
|
|
}
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
2019-03-29 18:38:38 +05:00
|
|
|
else if (strcmp (reco, "2412") == 0)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
cout << "elements found" << endl;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2011-07-20 21:08:39 +06:00
|
|
|
int label, fe_id, phys_prop, mat_prop, color, nnodes;
|
|
|
|
int nodes[100];
|
|
|
|
int hi;
|
|
|
|
|
|
|
|
in >> label;
|
|
|
|
if (label == -1) break;
|
|
|
|
in >> fe_id >> phys_prop >> mat_prop >> color >> nnodes;
|
|
|
|
|
|
|
|
if (fe_id >= 11 && fe_id <= 32)
|
|
|
|
in >> hi >> hi >> hi;
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < nnodes; j++)
|
|
|
|
in >> nodes[j];
|
|
|
|
|
|
|
|
switch (fe_id)
|
|
|
|
{
|
2019-07-15 19:07:32 +05:00
|
|
|
case 11: // (Rod) SEGM
|
|
|
|
{
|
|
|
|
Segment el;
|
|
|
|
el[0] = nodes[0];
|
|
|
|
el[1] = nodes[1];
|
|
|
|
el[2] = -1;
|
|
|
|
|
|
|
|
if(dim == 3){
|
2019-07-16 13:42:27 +05:00
|
|
|
auto nr = tmp_segments.Size();
|
|
|
|
tmp_segments.Append(el);
|
|
|
|
element_map[label] = std::make_tuple(nr+1, 2);
|
2019-07-15 19:07:32 +05:00
|
|
|
}
|
|
|
|
else if(dim == 2){
|
2019-07-16 13:42:27 +05:00
|
|
|
el.si = -1; // add label to segment, will be changed later when BC's are assigned
|
|
|
|
auto nr = mesh.AddSegment(el);
|
|
|
|
element_map[label] = std::make_tuple(nr+1, 2);
|
2019-07-15 19:07:32 +05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-02 20:00:37 +05:00
|
|
|
case 22: // (Tapered beam) SEGM
|
|
|
|
{
|
|
|
|
Segment el;
|
|
|
|
el[0] = nodes[0];
|
|
|
|
el[1] = nodes[2];
|
|
|
|
el[2] = nodes[1];
|
2019-05-06 13:30:19 +05:00
|
|
|
|
2019-07-16 13:42:27 +05:00
|
|
|
if(dim == 3){
|
|
|
|
auto nr = tmp_segments.Size();
|
|
|
|
tmp_segments.Append(el);
|
|
|
|
element_map[label] = std::make_tuple(nr+1, 2);
|
|
|
|
}
|
|
|
|
else if(dim == 2){
|
|
|
|
el.si = -1; // add label to segment, will be changed later when BC's are assigned
|
|
|
|
auto nr = mesh.AddSegment(el);
|
|
|
|
element_map[label] = std::make_tuple(nr+1, 2);
|
|
|
|
}
|
|
|
|
|
2019-05-02 20:00:37 +05:00
|
|
|
break;
|
|
|
|
}
|
2019-03-29 18:38:38 +05:00
|
|
|
case 41: // TRIG
|
2011-07-20 21:08:39 +06:00
|
|
|
{
|
|
|
|
Element2d el (TRIG);
|
2019-07-16 13:42:27 +05:00
|
|
|
el.SetIndex (1);
|
2011-07-20 21:08:39 +06:00
|
|
|
for (int j = 0; j < nnodes; j++)
|
|
|
|
el[j] = nodes[j];
|
2019-07-16 13:42:27 +05:00
|
|
|
auto nr = mesh.AddSurfaceElement (el);
|
2019-03-29 18:38:38 +05:00
|
|
|
element_map[label] = std::make_tuple(nr+1, 1);
|
2011-07-20 21:08:39 +06:00
|
|
|
break;
|
|
|
|
}
|
2019-03-29 18:38:38 +05:00
|
|
|
case 42: // TRIG6
|
|
|
|
{
|
|
|
|
Element2d el(TRIG6);
|
|
|
|
el.SetIndex(1);
|
|
|
|
int jj = 0;
|
|
|
|
for(auto j : {0,2,4,3,5,1})
|
|
|
|
el[jj++] = nodes[j];
|
|
|
|
auto nr = mesh.AddSurfaceElement(el);
|
|
|
|
element_map[label] = std::make_tuple(nr+1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 111: // TET
|
2011-07-20 21:08:39 +06:00
|
|
|
{
|
|
|
|
Element el (TET);
|
|
|
|
el.SetIndex (1);
|
|
|
|
for (int j = 0; j < nnodes; j++)
|
|
|
|
el[j] = nodes[j];
|
2019-03-29 18:38:38 +05:00
|
|
|
auto nr = mesh.AddVolumeElement (el);
|
|
|
|
element_map[label] = std::make_tuple(nr+1, 0);
|
2011-07-20 21:08:39 +06:00
|
|
|
break;
|
|
|
|
}
|
2019-03-29 18:38:38 +05:00
|
|
|
case 118: // TET10
|
|
|
|
{
|
|
|
|
Element el(TET10);
|
|
|
|
el.SetIndex(1);
|
|
|
|
int jj = 0;
|
|
|
|
for(auto j : {0,2,4,9,1,5,6,3,7,8})
|
|
|
|
el[jj++] = nodes[j];
|
|
|
|
auto nr = mesh.AddVolumeElement(el);
|
|
|
|
element_map[label] = std::make_tuple(nr+1, 0);
|
|
|
|
break;
|
|
|
|
}
|
2019-05-02 20:00:37 +05:00
|
|
|
default:
|
|
|
|
cout << "Do not know fe_id = " << fe_id << ", skipping it." << endl;
|
|
|
|
break;
|
2011-07-20 21:08:39 +06:00
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
2019-03-29 18:38:38 +05:00
|
|
|
cout << mesh.GetNE() << " elements found" << endl;
|
|
|
|
cout << mesh.GetNSE() << " surface elements found" << endl;
|
2019-07-15 19:42:13 +05:00
|
|
|
|
2019-03-29 18:38:38 +05:00
|
|
|
}
|
|
|
|
else if(strcmp (reco, "2467") == 0)
|
|
|
|
{
|
|
|
|
int matnr = 1;
|
|
|
|
cout << "Groups found" << endl;
|
|
|
|
while(in.good())
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
string name;
|
|
|
|
in >> len;
|
|
|
|
if(len == -1)
|
|
|
|
break;
|
|
|
|
for(int i=0; i < 7; i++)
|
|
|
|
in >> len;
|
|
|
|
in >> name;
|
|
|
|
cout << len << " element are in group " << name << endl;
|
|
|
|
int hi, index;
|
2019-05-02 20:00:37 +05:00
|
|
|
int fdnr, ednr;
|
|
|
|
|
|
|
|
in >> hi >> index >> hi >> hi;
|
|
|
|
int codim = get<1>(element_map[index]);
|
2019-03-29 18:38:38 +05:00
|
|
|
// use first element to determine if boundary or volume
|
2019-05-02 20:00:37 +05:00
|
|
|
|
|
|
|
switch (codim)
|
2019-03-29 18:38:38 +05:00
|
|
|
{
|
2019-05-02 20:00:37 +05:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
mesh.SetMaterial(++matnr, name);
|
|
|
|
mesh.VolumeElement(get<0>(element_map[index])).SetIndex(matnr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2019-07-15 19:07:32 +05:00
|
|
|
if(dim == 3)
|
|
|
|
{
|
2019-08-01 01:55:43 +05:00
|
|
|
int bcpr = mesh.GetNFD();
|
2019-07-15 19:07:32 +05:00
|
|
|
fdnr = mesh.AddFaceDescriptor(FaceDescriptor(bcpr, 0,0,0));
|
|
|
|
mesh.GetFaceDescriptor(fdnr).SetBCProperty(bcpr+1);
|
|
|
|
mesh.SetBCName(bcpr, name);
|
|
|
|
mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(fdnr);
|
2019-08-01 01:55:43 +05:00
|
|
|
bccounter++;
|
2019-07-15 19:07:32 +05:00
|
|
|
}
|
|
|
|
else if(dim == 2)
|
|
|
|
{
|
|
|
|
mesh.SetMaterial(matnr, name);
|
|
|
|
fdnr = mesh.AddFaceDescriptor(FaceDescriptor(matnr, 0,0,0));
|
|
|
|
mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(matnr);
|
|
|
|
mesh.GetFaceDescriptor(fdnr).SetBCProperty(matnr);
|
|
|
|
matnr++;
|
|
|
|
}
|
2019-05-02 20:00:37 +05:00
|
|
|
break;
|
2019-07-15 19:07:32 +05:00
|
|
|
|
2019-05-02 20:00:37 +05:00
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2019-07-15 19:07:32 +05:00
|
|
|
if(dim == 3)
|
|
|
|
{
|
|
|
|
int bcpr = mesh.GetNCD2Names()+1;
|
|
|
|
auto ed = EdgeDescriptor();
|
|
|
|
ed.SetSurfNr(0,bcpr);//?
|
|
|
|
ednr = mesh.AddEdgeDescriptor(ed);
|
|
|
|
mesh.SetCD2Name(bcpr, name);
|
|
|
|
auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]);
|
|
|
|
mesh[nr].edgenr = ednr+1;
|
|
|
|
}
|
|
|
|
else if(dim == 2)
|
|
|
|
{
|
|
|
|
Segment & seg = mesh.LineSegment(get<0>(element_map[index]));
|
|
|
|
seg.si = bccounter + 1;
|
|
|
|
mesh.SetBCName(bccounter, name);
|
|
|
|
bccounter++;
|
|
|
|
}
|
2019-05-02 20:00:37 +05:00
|
|
|
break;
|
2019-07-15 19:07:32 +05:00
|
|
|
|
2019-05-02 20:00:37 +05:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
cout << "Codim " << codim << " not implemented yet!" << endl;
|
|
|
|
}
|
2019-03-29 18:38:38 +05:00
|
|
|
}
|
2019-05-02 20:00:37 +05:00
|
|
|
|
2019-03-29 18:38:38 +05:00
|
|
|
for(int i=0; i<len-1; i++)
|
|
|
|
{
|
|
|
|
in >> hi >> index >> hi >> hi;
|
2019-05-02 20:00:37 +05:00
|
|
|
switch (codim)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
mesh.VolumeElement(get<0>(element_map[index])).SetIndex(matnr);
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-07-15 19:07:32 +05:00
|
|
|
if(dim == 3) mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(fdnr);
|
|
|
|
else if (dim == 2){
|
|
|
|
mesh.SurfaceElement(get<0>(element_map[index])).SetIndex(matnr-1);
|
|
|
|
mesh.GetFaceDescriptor(fdnr).SetBCProperty(matnr);
|
|
|
|
}
|
2019-05-02 20:00:37 +05:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-07-15 19:07:32 +05:00
|
|
|
if(dim == 3)
|
2019-05-06 13:30:19 +05:00
|
|
|
{
|
|
|
|
auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]);
|
2019-05-06 17:59:18 +05:00
|
|
|
mesh[nr].edgenr = ednr+1;
|
2019-05-06 13:30:19 +05:00
|
|
|
}
|
2019-07-15 19:07:32 +05:00
|
|
|
else if(dim == 2)
|
|
|
|
{
|
|
|
|
Segment & seg = mesh.LineSegment(get<0>(element_map[index]));
|
|
|
|
seg.si = bccounter;
|
|
|
|
}
|
2019-05-02 20:00:37 +05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-03-29 18:38:38 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "Do not know data field type " << reco << ", skipping it" << endl;
|
|
|
|
while(in.good())
|
|
|
|
{
|
|
|
|
in >> reco;
|
|
|
|
if(strcmp(reco, "-1") == 0)
|
|
|
|
break;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
}
|
2019-07-15 19:07:32 +05:00
|
|
|
|
|
|
|
if(dim == 2){
|
|
|
|
// loop through segments to assign default BC to unmarked edges
|
|
|
|
int bccounter_tmp = bccounter;
|
2019-07-15 19:42:13 +05:00
|
|
|
for(int index=1; index <= mesh.GetNSeg(); index++){
|
2019-07-24 02:23:10 +05:00
|
|
|
Segment & seg = mesh.LineSegment(index);
|
2019-07-15 19:07:32 +05:00
|
|
|
if(seg.si == -1){
|
2019-07-15 19:42:13 +05:00
|
|
|
seg.si = bccounter + 1;
|
|
|
|
if(bccounter_tmp == bccounter) mesh.SetBCName(bccounter, "default"); // could be more efficient
|
2019-07-15 19:07:32 +05:00
|
|
|
bccounter_tmp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(bccounter_tmp > bccounter) bccounter++;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
|
|
|
Point3d pmin, pmax;
|
2019-03-29 18:38:38 +05:00
|
|
|
mesh.ComputeNVertices();
|
2019-04-11 17:45:57 +05:00
|
|
|
mesh.RebuildSurfaceElementLists();
|
2009-01-13 04:40:13 +05:00
|
|
|
mesh.GetBox (pmin, pmax);
|
2019-05-02 20:00:37 +05:00
|
|
|
mesh.UpdateTopology();
|
2019-08-01 01:55:43 +05:00
|
|
|
if(dim == 3) bccounter++;
|
2009-01-13 04:40:13 +05:00
|
|
|
cout << "bounding-box = " << pmin << "-" << pmax << endl;
|
2019-07-15 19:07:32 +05:00
|
|
|
cout << "Created " << bccounter << " boundaries." << endl;
|
|
|
|
for(int i=0; i<bccounter; i++){
|
|
|
|
cout << mesh.GetBCName(i) << endl;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fepp format2d:
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".mesh2d" )
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
cout << "Reading FEPP2D Mesh" << endl;
|
|
|
|
|
|
|
|
char buf[100];
|
|
|
|
int np, ne, nseg, i, j;
|
|
|
|
|
|
|
|
ifstream in (filename);
|
|
|
|
|
|
|
|
in >> buf;
|
|
|
|
|
|
|
|
in >> nseg;
|
|
|
|
for (i = 1; i <= nseg; i++)
|
|
|
|
{
|
|
|
|
int bound, p1, p2;
|
|
|
|
in >> bound >> p1 >> p2;
|
|
|
|
// forget them
|
|
|
|
}
|
|
|
|
|
|
|
|
in >> ne;
|
|
|
|
for (i = 1; i <= ne; i++)
|
|
|
|
{
|
|
|
|
int mat, nelp;
|
|
|
|
in >> mat >> nelp;
|
|
|
|
Element2d el (nelp == 3 ? TRIG : QUAD);
|
|
|
|
el.SetIndex (mat);
|
|
|
|
for (j = 1; j <= nelp; j++)
|
|
|
|
in >> el.PNum(j);
|
|
|
|
mesh.AddSurfaceElement (el);
|
|
|
|
}
|
|
|
|
|
|
|
|
in >> np;
|
|
|
|
for (i = 1; i <= np; i++)
|
|
|
|
{
|
|
|
|
Point3d p(0,0,0);
|
|
|
|
in >> p.X() >> p.Y();
|
|
|
|
mesh.AddPoint (p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
else if ( ext == ".mesh" )
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
cout << "Reading Neutral Format" << endl;
|
|
|
|
|
|
|
|
int np, ne, nse, i, j;
|
|
|
|
|
|
|
|
ifstream in (filename);
|
|
|
|
|
|
|
|
in >> np;
|
|
|
|
|
|
|
|
if (in.good())
|
|
|
|
{
|
|
|
|
// file starts with an integer
|
|
|
|
|
|
|
|
for (i = 1; i <= np; i++)
|
|
|
|
{
|
|
|
|
Point3d p(0,0,0);
|
|
|
|
in >> p.X() >> p.Y() >> p.Z();
|
|
|
|
mesh.AddPoint (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
in >> ne;
|
|
|
|
for (i = 1; i <= ne; i++)
|
|
|
|
{
|
|
|
|
int mat;
|
|
|
|
in >> mat;
|
|
|
|
Element el (4);
|
|
|
|
el.SetIndex (mat);
|
|
|
|
for (j = 1; j <= 4; j++)
|
|
|
|
in >> el.PNum(j);
|
|
|
|
mesh.AddVolumeElement (el);
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor (1, 1, 0, 0));
|
2017-08-01 13:15:07 +05:00
|
|
|
int nfd = 1;
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
in >> nse;
|
|
|
|
for (i = 1; i <= nse; i++)
|
|
|
|
{
|
2009-04-20 03:15:26 +06:00
|
|
|
int mat; // , nelp;
|
2009-01-13 04:40:13 +05:00
|
|
|
in >> mat;
|
|
|
|
Element2d el (TRIG);
|
|
|
|
el.SetIndex (mat);
|
2017-08-01 13:15:07 +05:00
|
|
|
while(nfd<mat)
|
|
|
|
{
|
|
|
|
++nfd;
|
|
|
|
mesh.AddFaceDescriptor(FaceDescriptor(nfd,nfd,0,0));
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
for (j = 1; j <= 3; j++)
|
|
|
|
in >> el.PNum(j);
|
|
|
|
mesh.AddSurfaceElement (el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
in.clear();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
in >> buf;
|
|
|
|
cout << "buf = " << buf << endl;
|
|
|
|
if (strcmp (buf, "points") == 0)
|
|
|
|
{
|
|
|
|
in >> np;
|
|
|
|
cout << "np = " << np << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (in.good());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".emt" )
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
|
|
|
ifstream inemt (filename);
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
auto pktfile = filename;
|
|
|
|
pktfile.replace_extension("pkt");
|
2009-01-13 04:40:13 +05:00
|
|
|
cout << "pktfile = " << pktfile << endl;
|
|
|
|
|
|
|
|
int np, nse, i;
|
2009-04-20 03:15:26 +06:00
|
|
|
int bcprop;
|
2022-02-17 20:52:07 +05:00
|
|
|
ifstream inpkt (pktfile);
|
2009-01-13 04:40:13 +05:00
|
|
|
inpkt >> np;
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<double> values(np);
|
2009-01-13 04:40:13 +05:00
|
|
|
for (i = 1; i <= np; i++)
|
|
|
|
{
|
|
|
|
Point3d p(0,0,0);
|
|
|
|
inpkt >> p.X() >> p.Y() >> p.Z()
|
|
|
|
>> bcprop >> values.Elem(i);
|
|
|
|
mesh.AddPoint (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh.ClearFaceDescriptors();
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
|
|
|
|
mesh.GetFaceDescriptor(1).SetBCProperty (1);
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
|
|
|
|
mesh.GetFaceDescriptor(2).SetBCProperty (2);
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
|
|
|
|
mesh.GetFaceDescriptor(3).SetBCProperty (3);
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
|
|
|
|
mesh.GetFaceDescriptor(4).SetBCProperty (4);
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
|
|
|
|
mesh.GetFaceDescriptor(5).SetBCProperty (5);
|
|
|
|
|
|
|
|
int p1, p2, p3;
|
|
|
|
double value;
|
|
|
|
inemt >> nse;
|
|
|
|
for (i = 1; i <= nse; i++)
|
|
|
|
{
|
|
|
|
inemt >> p1 >> p2 >> p3 >> bcprop >> value;
|
|
|
|
|
|
|
|
if (bcprop < 1 || bcprop > 4)
|
|
|
|
cerr << "bcprop out of range, bcprop = " << bcprop << endl;
|
|
|
|
p1++;
|
|
|
|
p2++;
|
|
|
|
p3++;
|
|
|
|
if (p1 < 1 || p1 > np || p2 < 1 || p2 > np || p3 < 1 || p3 > np)
|
|
|
|
{
|
|
|
|
cout << "p1 = " << p1 << " p2 = " << p2 << " p3 = " << p3 << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > 110354) Swap (p2, p3);
|
|
|
|
if (mesh.Point(p1)(0) < 0.25)
|
|
|
|
Swap (p2,p3);
|
|
|
|
|
|
|
|
Element2d el(TRIG);
|
|
|
|
|
|
|
|
if (bcprop == 1)
|
|
|
|
{
|
|
|
|
if (values.Get(p1) < -69999)
|
|
|
|
el.SetIndex(1);
|
|
|
|
else
|
|
|
|
el.SetIndex(2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
el.SetIndex(3);
|
|
|
|
|
|
|
|
|
|
|
|
el.PNum(1) = p1;
|
|
|
|
el.PNum(2) = p2;
|
|
|
|
el.PNum(3) = p3;
|
|
|
|
mesh.AddSurfaceElement (el);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ifstream incyl ("ngusers/guenter/cylinder.surf");
|
|
|
|
int npcyl, nsecyl;
|
|
|
|
incyl >> npcyl;
|
|
|
|
cout << "npcyl = " << npcyl << endl;
|
|
|
|
for (i = 1; i <= npcyl; i++)
|
|
|
|
{
|
|
|
|
Point3d p(0,0,0);
|
|
|
|
incyl >> p.X() >> p.Y() >> p.Z();
|
|
|
|
mesh.AddPoint (p);
|
|
|
|
}
|
|
|
|
incyl >> nsecyl;
|
|
|
|
cout << "nsecyl = " << nsecyl << endl;
|
|
|
|
for (i = 1; i <= nsecyl; i++)
|
|
|
|
{
|
|
|
|
incyl >> p1 >> p2 >> p3;
|
|
|
|
p1 += np;
|
|
|
|
p2 += np;
|
|
|
|
p3 += np;
|
|
|
|
Element2d el(TRIG);
|
|
|
|
el.SetIndex(5);
|
|
|
|
el.PNum(1) = p1;
|
|
|
|
el.PNum(2) = p2;
|
|
|
|
el.PNum(3) = p3;
|
|
|
|
mesh.AddSurfaceElement (el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// .tet mesh
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".tet" )
|
2009-01-13 04:40:13 +05:00
|
|
|
ReadTETFormat (mesh, filename);
|
|
|
|
|
|
|
|
// .fnf mesh (FNF - PE neutral format)
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".fnf" )
|
2009-01-13 04:40:13 +05:00
|
|
|
ReadFNFFormat (mesh, filename);
|
|
|
|
|
2020-03-11 15:48:05 +05:00
|
|
|
// .cgns file - CFD General Notation System
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".cgns" )
|
2020-03-11 15:48:05 +05:00
|
|
|
ReadCGNSMesh (mesh, filename);
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
if ( ext == ".stl" || ext == ".stlb" )
|
2019-09-20 14:31:52 +05:00
|
|
|
{
|
2022-02-17 20:52:07 +05:00
|
|
|
ifstream ist{filename};
|
2019-09-20 14:31:52 +05:00
|
|
|
auto geom = shared_ptr<STLGeometry>(STLGeometry::Load(ist));
|
|
|
|
|
|
|
|
mesh.SetDimension (3);
|
|
|
|
|
|
|
|
auto & points = geom->GetPoints();
|
|
|
|
|
|
|
|
for (auto & p : points)
|
|
|
|
mesh.AddPoint(MeshPoint(p));
|
|
|
|
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor (1, 1, 0, 1));
|
|
|
|
|
|
|
|
for (auto ti : IntRange(geom->GetNT()))
|
|
|
|
{
|
|
|
|
Element2d el(TRIG);
|
|
|
|
for (auto i : IntRange(3))
|
2019-09-21 05:22:20 +05:00
|
|
|
el[i] = int((*geom)[STLTrigId(ti+IndexBASE<netgen::STLTrigId>())][i]);
|
2019-09-20 14:31:52 +05:00
|
|
|
|
|
|
|
el.SetIndex(1);
|
|
|
|
|
|
|
|
mesh.AddSurfaceElement(el);
|
|
|
|
}
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|