netgen/libsrc/interface/read_fnf_mesh.cpp

475 lines
16 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
//
// Read Pro/ENGINEER neutral format
//
#include <mystdlib.h>
#include <myadt.hpp>
#include <linalg.hpp>
#include <csg.hpp>
#include <meshing.hpp>
#include <sys/stat.h>
namespace netgen
{
#include "writeuser.hpp"
bool ReadLine (istream & in, string & buf)
{
do
{
buf = "";
while (in.good())
{
char ch = in.get();
if (ch == '\n') break;
if (ch == '\r') break;
if (ch == '\\')
{
// while (iswhite (ch = in.get() )
ch = in.get(); // '\n' CR
ch = in.get(); // '\n' LF
}
else
buf += ch;
}
}
while (in.good() && (buf == "" || buf[0] == '#'));
return in.good();
}
class LoadType
{
public:
int id;
string name;
string placement;
string valuetype;
2019-07-09 13:39:16 +05:00
NgArray<double> places;
2009-01-13 04:40:13 +05:00
};
void ReadFNFFormat (Mesh & mesh,
const string & filename)
{
ifstream fin (filename.c_str());
string buf;
mesh.SetDimension (3);
while (ReadLine (fin, buf))
{
stringstream sbuf(buf);
string start_sect, token; char ch;
sbuf >> start_sect;
if (start_sect == "%START_SECT")
{
sbuf >> ch >> token;
if (token == "HEADER")
{
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token;
sbuf >> token;
if (token == "%TITLE")
{
char ch;
string name;
sbuf >> ch >> name;
2019-05-13 21:17:53 +05:00
PrintMessage(3, "Title: ", name);
2009-01-13 04:40:13 +05:00
}
else if (token == "%STATISTICS")
{
;
}
else if (token == "%END_SECT")
{
break;
}
else
{
2019-05-13 21:17:53 +05:00
PrintMessage(1, "SECTION HEADER, unknown field: ",buf);
2009-01-13 04:40:13 +05:00
}
}
}
else if (token == "ELEM_TYPES")
{
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token;
sbuf >> token;
if (token == "%ELEM_TYPE")
{
int nr;
string def;
char ch;
sbuf >> nr >> def >> ch;
if (def == "DEF")
{
string classname, type;
sbuf >> classname >> type;
if (classname != "SOLID" || type != "TETRA")
cerr << "Element not supported: " << buf << endl;
}
}
else if (token == "%END_SECT")
{
break;
}
else
{
2019-05-13 21:17:53 +05:00
PrintMessage(1, "SECTION ELEM_TYPE, unknown field: ", buf);
2009-01-13 04:40:13 +05:00
}
}
}
else if (token == "COORD_SYSTEMS")
{
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token;
sbuf >> token;
if (token == "%END_SECT")
{
break;
}
else
{
// cout << "COORD_SYSTEMS, unknown field: " << buf << endl;
}
}
}
else if (token == "ANALYSIS")
{
// ignore this section
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token;
sbuf >> token;
if (token == "%END_SECT")
{
break;
}
}
}
2009-01-13 04:40:13 +05:00
else if (token == "MATERIALS")
{
2011-01-11 01:18:01 +05:00
*testout << "parse materials" << endl;
2019-07-09 13:39:16 +05:00
NgArray<double> young_modulus, poisson_ratio, mass_density;
2009-01-13 04:40:13 +05:00
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token;
sbuf >> token;
if (token == "%MATERIAL")
{
int nr;
string prop;
char ch;
double val;
sbuf >> nr >> prop >> ch;
if (prop == "DEF")
{
2020-08-06 21:06:26 +05:00
string name;
sbuf >> name;
mesh.SetMaterial(nr, name);
2009-01-13 04:40:13 +05:00
}
else
{
sbuf >> val;
2011-01-11 01:18:01 +05:00
*testout << "prop = " << prop << ", val = " << val << endl;
2009-01-13 04:40:13 +05:00
if (prop == "YOUNG_MODULUS")
young_modulus.Append (val);
else if (prop == "POISSON_RATIO")
poisson_ratio.Append (val);
else if (prop == "MASS_DENSITY")
mass_density.Append (val);
}
}
else if (token == "%END_SECT")
{
mesh.SetUserData ("YOUNG_MODULUS", young_modulus);
mesh.SetUserData ("POISSON_RATIO", poisson_ratio);
mesh.SetUserData ("MASS_DENSITY", mass_density);
2011-01-11 01:18:01 +05:00
*testout << "young = " << young_modulus << endl;
*testout << "poisson = " << poisson_ratio << endl;
2009-01-13 04:40:13 +05:00
break;
}
else
{
2019-05-13 21:17:53 +05:00
PrintMessage(1, "SECTION MATERIALS, unknown field: ", buf);
2009-01-13 04:40:13 +05:00
}
}
}
else if (token == "MESH")
{
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token;
sbuf >> token;
if (token == "%NODE")
{
string st;
char ch;
int nr, ks_id;
double x,y,z;
sbuf >> nr >> st >> ch >> x >> y >> z >> ks_id;
mesh.AddPoint (Point3d (x,y,z) );
}
else if (token == "%ELEM")
{
string elemid, def;
char ch;
int elnr, typid, matid;
string propid;
sbuf >> elnr >> def >> ch;
sbuf >> typid >> matid >> propid;
2019-07-09 13:39:16 +05:00
NgArray<int> pnums;
2009-01-13 04:40:13 +05:00
while (1)
{
int pn;
sbuf >> pn;
if (!sbuf.good()) break;
pnums.Append (pn);
}
int pe2ng [] = { 0, 1, 2, 3, 4, 7, 5, 6, 8, 9 };
Element el(pnums.Size());
for (int j = 0; j < pnums.Size(); j++)
el[pe2ng[j]] = pnums[j];
el.SetIndex (matid);
mesh.AddVolumeElement (el);
}
else if (token == "%END_SECT")
{
break;
}
else
{
2019-05-13 21:17:53 +05:00
PrintMessage(1, "SECTION MESH, unknown: ", buf);
2009-01-13 04:40:13 +05:00
}
}
}
else if (token == "MESH_TOPOLOGY")
{
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token, kw;
int nr;
char ch;
sbuf >> token;
if (token == "%EDGE")
{
sbuf >> nr >> kw >> ch;
if (kw == "NODES")
{
2019-07-09 13:39:16 +05:00
NgArray<int> enums;
2009-01-13 04:40:13 +05:00
while (1)
{
int en;
sbuf >> en;
if (!sbuf.good()) break;
enums.Append (en);
}
for (int j = 0; j+2 < enums.Size(); j+=2)
{
Segment seg;
2009-04-03 20:39:52 +06:00
seg[0] = enums[j];
seg[1] = enums[j+2];
seg[2] = enums[j+1];
2009-01-13 04:40:13 +05:00
seg.edgenr = nr;
mesh.AddSegment (seg);
}
}
}
else if (token == "%SURFACE")
{
sbuf >> nr >> kw >> ch;
if (kw == "FACES")
{
2019-07-09 13:39:16 +05:00
NgArray<int> fnums;
2009-01-13 04:40:13 +05:00
while (1)
{
int fn;
sbuf >> fn;
if (!sbuf.good()) break;
fnums.Append (fn);
}
FaceDescriptor fd(-1, -1, -1, -1);
fd.SetBCProperty (nr);
2011-01-11 01:18:01 +05:00
*testout << "add fd " << mesh.GetNFD() << ", nr = " << nr << endl;
2009-01-13 04:40:13 +05:00
mesh.AddFaceDescriptor (fd);
for (int j = 0; j < fnums.Size(); j += 2)
{
int elnr = fnums[j];
int fnr = fnums[j+1];
const Element & el = mesh.VolumeElement (elnr);
if(j == 0)
mesh.GetFaceDescriptor(nr).SetDomainIn(el.GetIndex());
2009-01-13 04:40:13 +05:00
Element2d el2d;
el.GetFace (fnr, el2d);
el2d.SetIndex (nr);
mesh.AddSurfaceElement (el2d);
}
}
}
else if (token == "%END_SECT")
{
break;
}
else
{
2019-05-13 21:17:53 +05:00
PrintMessage(1, "SECTION MESH, unknown: ", buf);
2009-01-13 04:40:13 +05:00
}
}
}
else if (token == "LOADS")
{
2019-07-09 13:39:16 +05:00
NgArray<LoadType*> loadtypes;
2009-01-13 04:40:13 +05:00
while (1)
{
ReadLine (fin, buf);
stringstream sbuf(buf);
string token;
sbuf >> token;
if (token == "%LOAD_TYPE")
{
string def;
char ch;
LoadType * lt = new LoadType;
sbuf >> lt->id >> def >> ch >> lt->name >> lt->placement >> lt->valuetype;
if (lt->name == "DISPLACEMENT")
2019-05-13 21:17:53 +05:00
PrintMessage(3, "loadtype DISPLACEMENT found");
2009-01-13 04:40:13 +05:00
if (lt->placement != "FACE" && lt->placement != "EDGE" && lt->placement != "NODE")
2019-05-13 21:17:53 +05:00
PrintMessage(1, "unsupported placement ", lt->placement);
2009-01-13 04:40:13 +05:00
loadtypes.Append (lt);
}
else if (token == "%LOAD")
{
int id;
string def;
char ch;
int placement;
int load_type_id, con_case_id;
sbuf >> id >> def >> ch;
if (def == "DEF")
{
sbuf >> load_type_id >> con_case_id;
}
if (def == "VAL")
{
sbuf >> placement;
for (int i = 0; i < loadtypes.Size(); i++)
if (load_type_id == loadtypes[i]->id)
loadtypes[i]->places.Append (placement);
}
}
else if (token == "%CON_CASE")
{ ; }
2009-01-13 04:40:13 +05:00
else if (token == "%END_SECT")
{
for (int i = 0; i < loadtypes.Size(); i++)
{
2019-05-13 21:17:53 +05:00
stringstream str;
str << loadtypes[i]->places;
2009-01-13 04:40:13 +05:00
if (loadtypes[i]->placement == "FACE" && loadtypes[i]->name == "DISPLACEMENT")
{
mesh.SetUserData ("CONSTRAINT_DISP_FACE", loadtypes[i]->places);
2019-05-13 21:17:53 +05:00
PrintMessage(3, "constrained faces: ", str.str());
2009-01-13 04:40:13 +05:00
}
if (loadtypes[i]->placement == "EDGE" && loadtypes[i]->name == "DISPLACEMENT")
{
mesh.SetUserData ("CONSTRAINT_DISP_EDGE", loadtypes[i]->places);
2019-05-13 21:17:53 +05:00
PrintMessage(3,"constrained edges: ", str.str());
2009-01-13 04:40:13 +05:00
}
if (loadtypes[i]->placement == "NODE" && loadtypes[i]->name == "DISPLACEMENT")
{
mesh.SetUserData ("CONSTRAINT_DISP_NODE", loadtypes[i]->places);
2019-05-13 21:17:53 +05:00
PrintMessage(3, "constrained nodes: ", str.str());
2009-01-13 04:40:13 +05:00
}
}
break;
}
else
{
2019-05-13 21:17:53 +05:00
PrintMessage(1, "SECTION LOADS, unknown field: ", buf);
2009-01-13 04:40:13 +05:00
}
}
}
else
{
2019-05-13 21:17:53 +05:00
PrintMessage(1, "unknown section ", token);
2009-01-13 04:40:13 +05:00
}
}
else
2019-05-13 21:17:53 +05:00
PrintMessage(3, "parse line: (", buf, ")");
2009-01-13 04:40:13 +05:00
}
mesh.ComputeNVertices();
2009-01-13 04:40:13 +05:00
}
}