netgen/ng/nginterface_v2.cpp

262 lines
6.2 KiB
C++
Raw Normal View History

2009-04-03 20:39:52 +06:00
#include <mystdlib.h>
#include <meshing.hpp>
#include <csg.hpp>
#include <geometry2d.hpp>
#include <stlgeom.hpp>
#ifdef OCCGEOMETRY
#include <occgeom.hpp>
#endif
#ifdef ACIS
#include <acisgeom.hpp>
#endif
#ifdef SOCKETS
#include "../sockets/sockets.hpp"
#endif
#ifndef NOTCL
#include <visual.hpp>
#endif
#include "nginterface.h"
#include "nginterface_v2.hpp"
// #include <FlexLexer.h>
// #include <mystdlib.h>
namespace netgen
{
#include "writeuser.hpp"
2009-07-20 14:36:36 +06:00
extern AutoPtr<Mesh> mesh;
2009-04-03 20:39:52 +06:00
#ifndef NOTCL
extern VisualSceneMesh vsmesh;
extern Tcl_Interp * tcl_interp;
#endif
extern AutoPtr<SplineGeometry2d> geometry2d;
extern AutoPtr<CSGeometry> geometry;
extern STLGeometry * stlgeometry;
#ifdef OCCGEOMETRY
extern OCCGeometry * occgeometry;
#endif
#ifdef ACIS
extern ACISGeometry * acisgeometry;
#endif
#ifdef OPENGL
extern VisualSceneSolution vssolution;
#endif
extern CSGeometry * ParseCSG (istream & istr);
#ifdef SOCKETS
extern AutoPtr<ClientSocket> clientsocket;
//extern Array< AutoPtr < ServerInfo > > servers;
extern Array< ServerInfo* > servers;
#endif
}
2009-07-20 14:36:36 +06:00
namespace netgen
{
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
template <> int DLL_HEADER Ng_GetNElements<1> ()
{
return mesh->GetNSeg();
}
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER int Ng_GetNElements<2> ()
{
return mesh->GetNSE();
}
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER int Ng_GetNElements<3> ()
{
return mesh->GetNE();
}
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER Ng_Element Ng_GetElement<1> (int nr)
{
const Segment & el = mesh->LineSegment (SegmentIndex(nr));
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType());
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.points.num = el.GetNP();
ret.points.ptr = (int*)&(el[0]);
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.vertices.num = 2;
ret.vertices.ptr = (int*)&(el[0]);
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.edges.num = 1;
ret.edges.ptr = mesh->GetTopology().GetSegmentElementEdgesPtr (nr);
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.faces.num = 0;
ret.faces.ptr = NULL;
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
return ret;
}
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER Ng_Element Ng_GetElement<2> (int nr)
{
const Element2d & el = mesh->SurfaceElement (SurfaceElementIndex (nr));
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType());
ret.points.num = el.GetNP();
ret.points.ptr = (int*)&el[0];
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.vertices.num = el.GetNV();
ret.vertices.ptr = (int*)&(el[0]);
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.edges.num = MeshTopology::GetNEdges (el.GetType());
ret.edges.ptr = mesh->GetTopology().GetSurfaceElementEdgesPtr (nr);
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.faces.num = MeshTopology::GetNFaces (el.GetType());
ret.faces.ptr = mesh->GetTopology().GetSurfaceElementFacesPtr (nr);
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
return ret;
}
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER Ng_Element Ng_GetElement<3> (int nr)
{
const Element & el = mesh->VolumeElement (ElementIndex (nr));
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType());
ret.points.num = el.GetNP();
ret.points.ptr = (int*)&el[0];
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.vertices.num = el.GetNV();
ret.vertices.ptr = (int*)&(el[0]);
2009-07-13 19:03:01 +06:00
2009-07-20 14:36:36 +06:00
ret.edges.num = MeshTopology::GetNEdges (el.GetType());
ret.edges.ptr = mesh->GetTopology().GetElementEdgesPtr (nr);
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
ret.faces.num = MeshTopology::GetNFaces (el.GetType());
ret.faces.ptr = mesh->GetTopology().GetElementFacesPtr (nr);
2009-04-03 20:39:52 +06:00
2009-07-20 14:36:36 +06:00
return ret;
}
2009-07-19 23:33:25 +06:00
2009-07-20 14:36:36 +06:00
template <>
DLL_HEADER int Ng_GetElementIndex<1> (int nr)
{
return (*mesh)[SegmentIndex(nr)].si;
}
template <>
DLL_HEADER int Ng_GetElementIndex<2> (int nr)
{
int ind = (*mesh)[SurfaceElementIndex(nr)].GetIndex();
return mesh->GetFaceDescriptor(ind).BCProperty();
}
template <>
DLL_HEADER int Ng_GetElementIndex<3> (int nr)
{
return (*mesh)[ElementIndex(nr)].GetIndex();
}
template <>
DLL_HEADER void Ng_MultiElementTransformation<3,3> (int elnr, int npts,
const double * xi, int sxi,
double * x, int sx,
double * dxdxi, int sdxdxi)
{
mesh->GetCurvedElements().CalcMultiPointElementTransformation (elnr, npts, xi, sxi, x, sx, dxdxi, sdxdxi);
}
template <>
DLL_HEADER void Ng_MultiElementTransformation<2,2> (int elnr, int npts,
const double * xi, int sxi,
double * x, int sx,
double * dxdxi, int sdxdxi)
{
mesh->GetCurvedElements().CalcMultiPointSurfaceTransformation<2> (elnr, npts, xi, sxi, x, sx, dxdxi, sdxdxi);
}
template <>
DLL_HEADER void Ng_MultiElementTransformation<2,3> (int elnr, int npts,
const double * xi, int sxi,
double * x, int sx,
double * dxdxi, int sdxdxi)
{
mesh->GetCurvedElements().CalcMultiPointSurfaceTransformation<3> (elnr, npts, xi, sxi, x, sx, dxdxi, sdxdxi);
}
template <>
DLL_HEADER void Ng_MultiElementTransformation<1,2> (int elnr, int npts,
const double * xi, int sxi,
double * x, int sx,
double * dxdxi, int sdxdxi)
{
for (int ip = 0; ip < npts; ip++)
{
Point<3> xg;
Vec<3> dx;
mesh->GetCurvedElements().CalcSegmentTransformation (xi[ip*sxi], elnr, xg, dx);
if (x)
for (int i = 0; i < 2; i++)
x[ip*sx+i] = xg(i);
if (dxdxi)
for (int i=0; i<2; i++)
dxdxi[ip*sdxdxi+i] = dx(i);
}
}
2009-07-19 23:33:25 +06:00
2009-07-20 14:36:36 +06:00
template <>
DLL_HEADER void Ng_MultiElementTransformation<1,1> (int elnr, int npts,
const double * xi, int sxi,
double * x, int sx,
double * dxdxi, int sdxdxi)
{
cout << "1D not supported" << endl;
}
2009-07-19 23:33:25 +06:00
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER int Ng_GetNNodes<1> ()
{
return mesh->GetTopology().GetNEdges();
}
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER int Ng_GetNNodes<2> ()
{
return mesh->GetTopology().GetNFaces();
}
2009-07-20 14:36:36 +06:00
template <> DLL_HEADER Ng_Node<1> Ng_GetNode<1> (int nr)
{
Ng_Node<1> node;
node.vertices.ptr = mesh->GetTopology().GetEdgeVerticesPtr(nr);
return node;
}
}