netgen/libsrc/include/nginterface_v2_impl.hpp

377 lines
9.4 KiB
C++
Raw Normal View History

2014-01-07 16:42:39 +06:00
NGX_INLINE DLL_HEADER Ng_Point Ngx_Mesh :: GetPoint (int nr) const
{
2016-12-11 16:12:05 +05:00
return Ng_Point (&mesh->Point(PointIndex(nr+PointIndex::BASE))(0));
2014-01-07 16:42:39 +06:00
}
2015-01-10 19:48:49 +05:00
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<0> (size_t nr) const
2015-01-10 19:48:49 +05:00
{
2015-11-11 22:46:18 +05:00
return (*mesh).pointelements[nr].index;
2015-01-10 19:48:49 +05:00
}
2014-01-07 16:42:39 +06:00
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<1> (size_t nr) const
2014-01-07 16:42:39 +06:00
{
2017-10-29 15:31:23 +05:00
/*
2016-10-05 22:48:18 +05:00
if(mesh->GetDimension()==3)
2016-10-11 17:10:36 +05:00
return (*mesh)[SegmentIndex(nr)].edgenr;
2016-10-05 22:48:18 +05:00
else
return (*mesh)[SegmentIndex(nr)].si;
2017-10-29 15:31:23 +05:00
*/
if(mesh->GetDimension()==3)
return mesh->LineSegments()[nr].edgenr;
else
return mesh->LineSegments()[nr].si;
2014-01-07 16:42:39 +06:00
}
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<2> (size_t nr) const
2014-01-07 16:42:39 +06:00
{
// int ind = (*mesh)[SurfaceElementIndex(nr)].GetIndex();
// return mesh->GetFaceDescriptor(ind).BCProperty();
const Element2d & el = (*mesh)[SurfaceElementIndex(nr)];
return mesh->GetFaceDescriptor(el).BCProperty();
2014-01-07 16:42:39 +06:00
}
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<3> (size_t nr) const
2014-01-07 16:42:39 +06:00
{
return (*mesh)[ElementIndex(nr)].GetIndex();
}
2015-11-11 22:46:18 +05:00
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (size_t nr) const
2015-11-11 22:46:18 +05:00
{
const Element0d & el = mesh->pointelements[nr];
Ng_Element ret;
ret.type = NG_PNT;
ret.index = el.index;
2023-08-05 23:14:32 +05:00
ret.mat = el.name;
2015-11-11 22:46:18 +05:00
ret.points.num = 1;
ret.points.ptr = (int*)&el.pnum;
ret.vertices.num = 1;
ret.vertices.ptr = (int*)&el.pnum;
/*
2015-11-11 22:46:18 +05:00
ret.edges.num = 0;
ret.edges.ptr = NULL;
*/
ret.edges.Assign ( FlatArray<T_EDGE2> (0, nullptr) );
/*
2015-11-11 22:46:18 +05:00
ret.faces.num = 0;
ret.faces.ptr = NULL;
*/
ret.faces.Assign ( { 0, nullptr } );
2017-06-24 01:09:50 +05:00
ret.facets.num = 1;
ret.facets.base = POINTINDEX_BASE;
2017-06-24 01:09:50 +05:00
ret.facets.ptr = (int*)&el.pnum;
2018-12-07 17:47:35 +05:00
if (mesh->GetDimension() == 1)
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh->GetBCNamePtr(el.index-1));
2018-12-07 17:47:35 +05:00
else if (mesh->GetDimension() == 2)
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh->GetCD2NamePtr(el.index-1));
2018-12-07 17:47:35 +05:00
else
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh->GetCD3NamePtr(el.index-1));
2015-11-11 22:46:18 +05:00
return ret;
}
2014-01-07 16:42:39 +06:00
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const
2014-01-07 16:42:39 +06:00
{
2017-10-29 15:31:23 +05:00
// const Segment & el = mesh->LineSegment (SegmentIndex(nr));
const Segment & el = mesh->LineSegments()[nr];
2014-01-07 16:42:39 +06:00
Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType());
2016-11-17 21:03:58 +05:00
if(mesh->GetDimension()==3)
2016-10-05 22:48:18 +05:00
ret.index = el.edgenr;
2016-11-17 21:03:58 +05:00
else
ret.index = el.si;
2016-10-10 22:58:14 +05:00
if (mesh->GetDimension() == 2)
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh->GetBCNamePtr(el.si-1));
2016-10-10 22:58:14 +05:00
else
2017-03-30 18:22:19 +05:00
{
2017-04-03 21:15:34 +05:00
if (mesh->GetDimension() == 3)
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh->GetCD2NamePtr(el.edgenr-1));
2017-03-30 18:22:19 +05:00
else
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh->GetMaterialPtr(el.si));
2017-03-30 18:22:19 +05:00
}
2014-01-07 16:42:39 +06:00
ret.points.num = el.GetNP();
ret.points.ptr = (int*)&(el[0]);
ret.vertices.num = 2;
ret.vertices.ptr = (int*)&(el[0]);
/*
2014-01-07 16:42:39 +06:00
ret.edges.num = 1;
ret.edges.ptr = mesh->GetTopology().GetSegmentElementEdgesPtr (nr);
*/
ret.edges.Assign ( FlatArray<T_EDGE2> (1, const_cast<T_EDGE2*>( mesh->GetTopology().GetSegmentElementEdgesPtr (nr))));
2014-01-07 16:42:39 +06:00
/*
2014-01-07 16:42:39 +06:00
ret.faces.num = 0;
ret.faces.ptr = NULL;
*/
ret.faces.Assign ( { 0, nullptr });
2020-06-25 21:39:29 +05:00
if (mesh->GetDimension() == 3)
{
ret.facets.num = 0;
ret.facets.base = 0;
ret.facets.ptr = nullptr;
}
else if (mesh->GetDimension() == 2)
{
ret.facets.num = 1;
ret.facets.base = 0;
ret.facets.ptr = ret.edges.Data();
}
else
{
ret.facets.num = 2;
ret.facets.base = 1;
ret.facets.ptr = (int*)&(el[0]);
}
// ret.is_curved = mesh->GetCurvedElements().IsSegmentCurved(nr);
ret.is_curved = el.IsCurved();
2015-04-27 14:18:22 +05:00
2014-01-07 16:42:39 +06:00
return ret;
}
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const
2014-01-07 16:42:39 +06:00
{
const Element2d & el = mesh->SurfaceElements()[nr];
2014-01-07 16:42:39 +06:00
Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType());
const FaceDescriptor & fd = mesh->GetFaceDescriptor(el); // .GetIndex());
2016-02-27 00:30:40 +05:00
ret.index = fd.BCProperty();
if (mesh->GetDimension() == 3)
2023-08-05 23:14:32 +05:00
ret.mat = fd.GetBCName();
2016-02-27 00:30:40 +05:00
else
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh -> GetMaterialPtr(ret.index));
2014-01-07 16:42:39 +06:00
ret.points.num = el.GetNP();
ret.points.ptr = (int*)&el[0];
ret.vertices.num = el.GetNV();
ret.vertices.ptr = (int*)&(el[0]);
/*
2014-01-07 16:42:39 +06:00
ret.edges.num = MeshTopology::GetNEdges (el.GetType());
ret.edges.ptr = mesh->GetTopology().GetSurfaceElementEdgesPtr (nr);
*/
ret.edges.Assign (mesh->GetTopology().GetEdges (SurfaceElementIndex(nr)));
/*
2014-01-07 16:42:39 +06:00
ret.faces.num = MeshTopology::GetNFaces (el.GetType());
ret.faces.ptr = mesh->GetTopology().GetSurfaceElementFacesPtr (nr);
*/
ret.faces.Assign ( { 1, const_cast<int*>(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) });
if (mesh->GetDimension() == 3)
{
ret.facets.num = ret.faces.Size();
ret.facets.base = 0;
ret.facets.ptr = ret.faces.Data();
}
else
{
ret.facets.num = ret.edges.Size();
ret.facets.base = 0;
ret.facets.ptr = ret.edges.Data();
}
2015-04-27 14:18:22 +05:00
ret.is_curved = el.IsCurved();
2014-01-07 16:42:39 +06:00
return ret;
}
template <>
2017-02-25 21:11:30 +05:00
NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const
2014-01-07 16:42:39 +06:00
{
const Element & el = mesh->VolumeElements()[nr];
2014-01-07 16:42:39 +06:00
Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType());
2014-12-04 17:39:12 +05:00
ret.index = el.GetIndex();
2023-08-05 23:14:32 +05:00
ret.mat = *(mesh -> GetMaterialPtr(ret.index));
2014-01-07 16:42:39 +06:00
ret.points.num = el.GetNP();
ret.points.ptr = (int*)&el[0];
ret.vertices.num = el.GetNV();
ret.vertices.ptr = (int*)&(el[0]);
/*
2014-01-07 16:42:39 +06:00
ret.edges.num = MeshTopology::GetNEdges (el.GetType());
ret.edges.ptr = mesh->GetTopology().GetElementEdgesPtr (nr);
*/
ret.edges.Assign (mesh->GetTopology().GetEdges (ElementIndex(nr)));
2014-01-07 16:42:39 +06:00
/*
2014-01-07 16:42:39 +06:00
ret.faces.num = MeshTopology::GetNFaces (el.GetType());
ret.faces.ptr = mesh->GetTopology().GetElementFacesPtr (nr);
*/
ret.faces.Assign (mesh->GetTopology().GetFaces (ElementIndex(nr)));
ret.facets.num = ret.faces.Size();
ret.facets.base = 0;
ret.facets.ptr = ret.faces.Data();
ret.is_curved = el.IsCurved();
2014-01-07 16:42:39 +06:00
return ret;
}
2016-03-23 12:17:45 +05:00
template <> NGX_INLINE DLL_HEADER
2023-08-05 23:14:32 +05:00
string_view Ngx_Mesh :: GetMaterialCD<0> (int region_nr) const
{
return mesh->GetMaterial(region_nr+1);
}
2016-03-23 12:17:45 +05:00
template <> NGX_INLINE DLL_HEADER
2023-08-05 23:14:32 +05:00
string_view Ngx_Mesh :: GetMaterialCD<1> (int region_nr) const
{
return mesh->GetBCName(region_nr);
}
2016-03-23 12:17:45 +05:00
template <> NGX_INLINE DLL_HEADER
2023-08-05 23:14:32 +05:00
string_view Ngx_Mesh :: GetMaterialCD<2> (int region_nr) const
{
return mesh->GetCD2Name(region_nr);
}
2016-03-23 12:17:45 +05:00
2017-09-22 19:55:10 +05:00
template <> NGX_INLINE DLL_HEADER
2023-08-05 23:14:32 +05:00
string_view Ngx_Mesh :: GetMaterialCD<3> (int region_nr) const
2017-09-22 19:55:10 +05:00
{
2018-08-06 20:09:03 +05:00
return mesh->GetCD3Name(region_nr);
2017-09-22 19:55:10 +05:00
}
2016-03-23 12:17:45 +05:00
template <> NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetNNodes<1> ()
{
return mesh->GetTopology().GetNEdges();
}
template <> NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetNNodes<2> ()
{
return mesh->GetTopology().GetNFaces();
}
template <> NGX_INLINE DLL_HEADER const Ng_Node<0> Ngx_Mesh :: GetNode<0> (int vnr) const
{
Ng_Node<0> node;
vnr++;
switch (mesh->GetDimension())
{
case 3:
{
auto ia = mesh->GetTopology().GetVertexElements(vnr);
2016-03-23 12:17:45 +05:00
node.elements.ne = ia.Size();
2021-05-17 18:35:12 +05:00
node.elements.ptr = (int*)ia.Data();
2016-03-23 12:17:45 +05:00
auto bia = mesh->GetTopology().GetVertexSurfaceElements(vnr);
2016-03-23 12:17:45 +05:00
node.bnd_elements.ne = bia.Size();
2021-05-17 18:35:12 +05:00
node.bnd_elements.ptr = (int*)bia.Data();
2016-03-23 12:17:45 +05:00
break;
}
case 2:
{
auto ia = mesh->GetTopology().GetVertexSurfaceElements(vnr);
2016-03-23 12:17:45 +05:00
node.elements.ne = ia.Size();
2021-05-17 18:35:12 +05:00
node.elements.ptr = (int*)ia.Data();
2016-03-23 12:17:45 +05:00
2021-05-11 21:21:40 +05:00
auto bia = mesh->GetTopology().GetVertexSegments(vnr);
2016-03-23 12:17:45 +05:00
node.bnd_elements.ne = bia.Size();
2021-05-17 18:35:12 +05:00
node.bnd_elements.ptr = (int*)bia.Data();
2016-03-23 12:17:45 +05:00
break;
}
case 1:
{
2021-05-11 21:21:40 +05:00
auto ia = mesh->GetTopology().GetVertexSegments(vnr);
2016-03-23 12:17:45 +05:00
node.elements.ne = ia.Size();
2021-05-17 18:35:12 +05:00
node.elements.ptr = (int*)ia.Data();
2016-03-23 12:17:45 +05:00
2021-05-11 21:21:40 +05:00
auto bia = mesh->GetTopology().GetVertexPointElements(vnr);
node.bnd_elements.ne = bia.Size();
2021-05-17 18:35:12 +05:00
node.bnd_elements.ptr = (int*)bia.Data();
2016-03-23 12:17:45 +05:00
break;
}
default:
;
}
return node;
}
template <> NGX_INLINE DLL_HEADER const Ng_Node<1> Ngx_Mesh :: GetNode<1> (int nr) const
{
Ng_Node<1> node;
2022-04-21 14:37:30 +05:00
node.vertices.ptr = (const int*)mesh->GetTopology().GetEdgeVerticesPtr(nr);
2016-03-23 12:17:45 +05:00
return node;
}
template <> NGX_INLINE DLL_HEADER const Ng_Node<2> Ngx_Mesh :: GetNode<2> (int nr) const
{
Ng_Node<2> node;
2022-04-21 14:37:30 +05:00
node.vertices.ptr = (const int*)mesh->GetTopology().GetFaceVerticesPtr(nr);
2016-03-23 12:17:45 +05:00
node.vertices.nv = (node.vertices.ptr[3] == 0) ? 3 : 4;
2017-05-10 20:41:44 +05:00
node.surface_el = mesh->GetTopology().GetFace2SurfaceElement (nr+1)-1;
2016-03-23 12:17:45 +05:00
return node;
}
2018-05-19 00:13:09 +05:00
2018-06-08 19:28:51 +05:00
NGX_INLINE DLL_HEADER Ng_Buffer<int[2]> Ngx_Mesh :: GetPeriodicVertices(int idnr) const
{
2019-07-09 13:39:16 +05:00
NgArray<INDEX_2> apairs;
mesh->GetIdentifications().GetPairs (idnr+1, apairs);
for(auto& ind : apairs)
{
ind.I1()--;
ind.I2()--;
}
2018-06-08 19:28:51 +05:00
typedef int ti2[2];
return { apairs.Size(), (ti2*)(void*)apairs.Release() };
}
2018-07-21 11:08:20 +05:00
NGX_INLINE void Ngx_Mesh :: GetParentNodes (int ni, int * parents) const
{
ni++;
if (ni <= mesh->mlbetweennodes.Size())
{
parents[0] = mesh->mlbetweennodes.Get(ni).I1()-1;
parents[1] = mesh->mlbetweennodes.Get(ni).I2()-1;
}
else
parents[0] = parents[1] = -1;
}
inline bool Ngx_Mesh :: HasParentEdges() const
{
return mesh->GetTopology().HasParentEdges();
}
inline tuple<int, std::array<int,3>> Ngx_Mesh :: GetParentEdges (int enr) const
{
return mesh->GetTopology().GetParentEdges(enr);
}
inline tuple<int, std::array<int,4>> Ngx_Mesh :: GetParentFaces (int fnr) const
{
return mesh->GetTopology().GetParentFaces(fnr);
}
2018-07-21 11:08:20 +05:00
2018-05-19 00:13:09 +05:00
inline auto Ngx_Mesh :: GetTimeStamp() const { return mesh->GetTimeStamp(); }