From f86bbbc82792a7d5a246932660c6594886ce11a1 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Mon, 27 May 2013 13:01:58 +0000 Subject: [PATCH] meshes in 1D, visualization --- libsrc/interface/nginterface.cpp | 58 +++++++++++++++++++++------- libsrc/interface/nginterface_v2.cpp | 13 +++++-- libsrc/meshing/meshclass.cpp | 39 ++++++++----------- libsrc/visualization/soldata.hpp | 3 ++ libsrc/visualization/vssolution.cpp | 60 ++++++++++++++++++++++++++++- libsrc/visualization/vssolution.hpp | 3 ++ 6 files changed, 133 insertions(+), 43 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 2f4d3ae1..8c80331b 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -727,10 +727,19 @@ int Ng_FindSurfaceElementOfPoint (double * p, double * lami, int build_searchtre int Ng_IsElementCurved (int ei) { + switch (mesh->GetDimension()) + { + case 1: return mesh->GetCurvedElements().IsSegmentCurved (ei-1); + case 2: return mesh->GetCurvedElements().IsSurfaceElementCurved (ei-1); + case 3: return mesh->GetCurvedElements().IsElementCurved (ei-1); + } + return 0; + /* if (mesh->GetDimension() == 2) return mesh->GetCurvedElements().IsSurfaceElementCurved (ei-1); else return mesh->GetCurvedElements().IsElementCurved (ei-1); + */ } @@ -1604,25 +1613,46 @@ void Ng_GetEdge_Vertices (int ednr, int * vert) int Ng_GetNVertexElements (int vnr) { - if (mesh->GetDimension() == 3) - return mesh->GetTopology().GetVertexElements(vnr).Size(); - else - return mesh->GetTopology().GetVertexSurfaceElements(vnr).Size(); + switch (mesh->GetDimension()) + { + case 3: + return mesh->GetTopology().GetVertexElements(vnr).Size(); + case 2: + return mesh->GetTopology().GetVertexSurfaceElements(vnr).Size(); + case 1: + { + int cnt = 0; + for (SegmentIndex i = 0; i < mesh->GetNSeg(); i++) + if ( ((*mesh)[i][0] == vnr) || ((*mesh)[i][1] == vnr) ) cnt++; + return cnt; + } + } } void Ng_GetVertexElements (int vnr, int * els) { - if (mesh->GetDimension() == 3) + switch (mesh->GetDimension()) { - FlatArray ia = mesh->GetTopology().GetVertexElements(vnr); - for (int i = 0; i < ia.Size(); i++) - els[i] = ia[i]+1; - } - else - { - FlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); - for (int i = 0; i < ia.Size(); i++) - els[i] = ia[i]; + case 3: + { + FlatArray ia = mesh->GetTopology().GetVertexElements(vnr); + for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; + break; + } + case 2: + { + FlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]; + break; + } + case 1: + { + int cnt = 0; + for (SegmentIndex i = 0; i < mesh->GetNSeg(); i++) + if ( ((*mesh)[i][0] == vnr) || ((*mesh)[i][1] == vnr) ) + els[cnt++] = i+1; + break; + } } } diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index 6d4caf3f..e116c548 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -51,7 +51,7 @@ namespace netgen { switch (dim) { - case 0: return mesh -> GetNV(); + case 0: return 0; // mesh -> GetNV(); case 1: return mesh -> GetNSeg(); case 2: return mesh -> GetNSE(); case 3: return mesh -> GetNE(); @@ -421,7 +421,13 @@ namespace netgen double * x, double * dxdxi) const { - cout << "1D not supported" << endl; + Point<3> xg; + Vec<3> dx; + + mesh->GetCurvedElements().CalcSegmentTransformation (xi[0], elnr, xg, dx); + + if (x) x[0] = xg(0); + if (dxdxi) dxdxi[0] = dx(0); } @@ -486,7 +492,8 @@ namespace netgen double * x, size_t sx, double * dxdxi, size_t sdxdxi) const { - cout << "1D not supported" << endl; + for (int i = 0; i < npts; i++) + ElementTransformation<1,1> (elnr, xi + i*sxi, x+i*sx, dxdxi+i*sdxdxi); } diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index ca496265..70e85eee 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -1618,25 +1618,23 @@ namespace netgen } } } - - for (int i = 0; i < segments.Size(); i++) - { - const Segment & seg = segments[i]; - for (int j = 1; j <= 2; j++) - { - PointIndex hi = (j == 1) ? seg[0] : seg[1]; - - if (points[hi].Type() == INNERPOINT || - points[hi].Type() == SURFACEPOINT) - points[hi].SetType(EDGEPOINT); - } - } - - - for (int i = 0; i < lockedpoints.Size(); i++) - points[lockedpoints[i]].SetType(FIXEDPOINT); } + for (int i = 0; i < segments.Size(); i++) + { + const Segment & seg = segments[i]; + for (int j = 1; j <= 2; j++) + { + PointIndex hi = (j == 1) ? seg[0] : seg[1]; + if (points[hi].Type() == INNERPOINT || + points[hi].Type() == SURFACEPOINT) + points[hi].SetType(EDGEPOINT); + } + } + + for (int i = 0; i < lockedpoints.Size(); i++) + points[lockedpoints[i]].SetType(FIXEDPOINT); + /* for (i = 0; i < openelements.Size(); i++) @@ -3214,13 +3212,6 @@ namespace netgen // FindOpenElements(); timestamp = NextTimeStamp(); - - /* - (*testout) << "compress, done" << endl - << "np = " << points.Size() - << "ne = " << volelements.Size() << ", type.size = " << eltyps.Size() - << "volelements = " << volelements << endl; - */ } diff --git a/libsrc/visualization/soldata.hpp b/libsrc/visualization/soldata.hpp index d0e14dcb..75e512a8 100644 --- a/libsrc/visualization/soldata.hpp +++ b/libsrc/visualization/soldata.hpp @@ -92,6 +92,9 @@ namespace netgen return res; } + virtual bool GetSegmentValue (int segnr, double xref, double * values) + { return false; } + virtual int GetNumMultiDimComponents () { diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 604f8573..9a7dd034 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -37,6 +37,7 @@ namespace netgen { surfellist = 0; linelist = 0; + element1dlist = 0; clipplanelist_scal = 0; clipplanelist_vec = 0; isolinelist = 0; @@ -554,10 +555,13 @@ namespace netgen glColor3f (0.0f, 0.0f, 0.0f); glDisable (GL_LINE_SMOOTH); + if (vispar.drawedges) + { + glCallList (element1dlist); + } if (vispar.drawoutline && !numisolines) { - // change for Martin SetClippingPlane (); glDepthMask(GL_FALSE); glCallList (linelist); @@ -763,7 +767,11 @@ namespace netgen surfellinetimestamp = max2 (solutiontimestamp, mesh->GetTimeStamp()); } - + + if (vispar.drawedges) + Draw1DElements(); + + if (mesh->GetTimeStamp() > surface_vector_timestamp || solutiontimestamp > surface_vector_timestamp || @@ -1078,8 +1086,56 @@ namespace netgen clipplanetimestamp = max2 (vispar.clipping.timestamp, solutiontimestamp); } + void VisualSceneSolution :: Draw1DElements () + { + if (element1dlist) + glDeleteLists (element1dlist, 1); + + element1dlist = glGenLists (1); + glNewList (element1dlist, GL_COMPILE); + + int npt = (1 << subdivisions) + 1; + Array pref(npt), values(npt); + Array > points(npt); + + const SolData * sol = NULL; + if (scalfunction != -1) sol = soldata[scalfunction]; + + int ncomp = 0; + if (sol) ncomp = sol->components; + Array mvalues(ncomp); + for (int i = 0; i < npt; i++) + pref[i] = double(i) / (npt-1); + + for (SegmentIndex i = 0; i < mesh -> GetNSeg(); i++) + { + // mesh->GetCurvedElements(). + // CalcMultiPointSegmentTransformation (&pref, i, &points, NULL); + // const Segment & seg = mesh -> LineSegment(i); + for (int j = 0; j < npt; j++) + mesh->GetCurvedElements(). + CalcSegmentTransformation (pref[j], i, points[j]); + if (sol) + { + for (int j = 0; j < npt; j++) + { + sol->solclass->GetSegmentValue (i, pref[j], &mvalues[0]); + values[j] = ExtractValue (sol, scalcomp, &mvalues[0]); + points[j](1) += scaledeform * values[j]; + } + } + + glBegin (GL_LINE_STRIP); + for (int i = 0; i < npt; i++) + glVertex3dv (points[i]); + glEnd(); + } + + glEndList (); + } + void VisualSceneSolution :: DrawSurfaceElements () { static int timer = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements"); diff --git a/libsrc/visualization/vssolution.hpp b/libsrc/visualization/vssolution.hpp index 833612ac..067446ae 100644 --- a/libsrc/visualization/vssolution.hpp +++ b/libsrc/visualization/vssolution.hpp @@ -43,6 +43,7 @@ class VisualSceneSolution : public VisualScene int surfellist; int linelist; + int element1dlist; int clipplanelist_scal; int clipplanelist_vec; int isolinelist; @@ -285,6 +286,8 @@ public: /// draw elements (build lists) void DrawSurfaceElements (); void DrawSurfaceElementLines (); + void Draw1DElements(); + void DrawSurfaceVectors (); void DrawTrigSurfaceVectors(const Array< Point<3> > & lp, const Point<3> & pmin, const Point<3> & pmax, const int sei, const SolData * vsol);