netgen/libsrc/visualization/vssolution.cpp

4866 lines
141 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#include <mystdlib.h>
#include <myadt.hpp>
#include <meshing.hpp>
#include <csg.hpp>
#include <stlgeom.hpp>
2012-06-11 20:24:35 +06:00
2009-01-25 17:20:07 +05:00
// #include <parallel.hpp>
2009-01-13 04:40:13 +05:00
#include <visual.hpp>
2013-07-10 13:07:29 +06:00
#include <limits>
2009-01-13 04:40:13 +05:00
namespace netgen
{
2014-10-06 15:57:44 +06:00
DLL_HEADER VisualSceneSolution & GetVSSolution()
{
static VisualSceneSolution vssolution;
return vssolution;
}
2014-10-06 15:57:44 +06:00
// extern shared_ptr<Mesh> mesh;
2009-01-13 04:40:13 +05:00
extern VisualSceneMesh vsmesh;
2015-05-03 20:56:29 +05:00
void AddUserVisualizationObject (UserVisualizationObject * vis)
{
// vssolution.AddUserVisualizationObject (vis);
GetVSSolution().AddUserVisualizationObject (vis);
2015-05-03 20:56:29 +05:00
}
2009-01-13 04:40:13 +05:00
VisualSceneSolution :: SolData :: SolData ()
2017-06-25 21:22:46 +05:00
: data (0), solclass(0)
2009-01-13 04:40:13 +05:00
{ ; }
VisualSceneSolution :: SolData :: ~SolData ()
{
2017-06-25 21:22:46 +05:00
// delete [] name;
2009-01-13 04:40:13 +05:00
delete data;
delete solclass;
}
VisualSceneSolution :: VisualSceneSolution ()
: VisualScene()
{
// cout << "init VisualSceneSolution" << endl;
2009-01-13 04:40:13 +05:00
surfellist = 0;
linelist = 0;
2013-05-27 19:01:58 +06:00
element1dlist = 0;
2011-02-15 21:22:05 +05:00
clipplanelist_scal = 0;
clipplanelist_vec = 0;
2009-01-13 04:40:13 +05:00
isolinelist = 0;
clipplane_isolinelist = 0;
surface_vector_list = 0;
isosurface_list = 0;
fieldlineslist = 0;
pointcurvelist = 0;
num_fieldlineslists = 0;
surfeltimestamp = GetTimeStamp();
surfellinetimestamp = GetTimeStamp();
clipplanetimestamp = GetTimeStamp();
solutiontimestamp = GetTimeStamp();
fieldlinestimestamp = GetTimeStamp();
pointcurve_timestamp = GetTimeStamp();
surface_vector_timestamp = GetTimeStamp();
isosurface_timestamp = GetTimeStamp();
timetimestamp = GetTimeStamp();
2014-10-06 15:57:44 +06:00
// AddVisualizationScene ("solution", &vssolution);
2009-01-13 04:40:13 +05:00
}
VisualSceneSolution :: ~VisualSceneSolution ()
{
// cout << "exit VisualSceneSolution" << endl;
2009-01-13 04:40:13 +05:00
ClearSolutionData();
}
2015-01-09 02:18:33 +05:00
/*
2014-10-09 15:00:50 +06:00
void VisualSceneSolution :: SetMesh (shared_ptr<Mesh> amesh)
{
wp_mesh = amesh;
}
2015-01-09 02:18:33 +05:00
*/
2014-10-09 15:00:50 +06:00
2009-01-13 04:40:13 +05:00
void VisualSceneSolution :: AddSolutionData (SolData * sd)
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
NgLock meshlock1 (mesh->MajorMutex(), 1);
int funcnr = -1;
for (int i = 0; i < soldata.Size(); i++)
{
2017-06-25 21:22:46 +05:00
// if (strcmp (soldata[i]->name, sd->name) == 0)
if (soldata[i]->name == sd->name)
2009-01-13 04:40:13 +05:00
{
delete soldata[i];
soldata[i] = sd;
funcnr = i;
break;
}
}
if (funcnr == -1)
{
soldata.Append (sd);
funcnr = soldata.Size()-1;
}
2013-03-14 05:34:30 +06:00
SolData * nsd = soldata[funcnr];
2009-01-13 04:40:13 +05:00
nsd->size = 0;
if (mesh)
{
switch (nsd->soltype)
{
case SOL_NODAL: nsd->size = mesh->GetNV(); break;
case SOL_ELEMENT: nsd->size = mesh->GetNE(); break;
case SOL_SURFACE_ELEMENT: nsd->size = mesh->GetNSE(); break;
case SOL_NONCONTINUOUS:
{
switch (nsd->order)
{
case 0: nsd->size = mesh->GetNE(); break;
case 1: nsd->size = 6 * mesh->GetNE(); break;
case 2: nsd->size = 18 * mesh->GetNE(); break;
}
break;
}
case SOL_SURFACE_NONCONTINUOUS:
{
switch (nsd->order)
{
case 0: nsd->size = mesh->GetNSE(); break;
case 1: nsd->size = 4 * mesh->GetNSE(); break;
case 2: nsd->size = 9 * mesh->GetNSE(); break;
}
break;
}
2009-07-20 14:36:36 +06:00
default:
nsd->size = 0;
2009-01-13 04:40:13 +05:00
}
solutiontimestamp = NextTimeStamp();
}
}
void VisualSceneSolution :: ClearSolutionData ()
{
for (int i = 0; i < soldata.Size(); i++)
delete soldata[i];
soldata.SetSize (0);
}
void VisualSceneSolution :: UpdateSolutionTimeStamp ()
{
solutiontimestamp = NextTimeStamp();
}
VisualSceneSolution::SolData * VisualSceneSolution :: GetSolData (int i)
{
if (i >= 0 && i < soldata.Size())
return soldata[i];
else
return NULL;
}
void VisualSceneSolution :: SaveSolutionData (const char * filename)
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
PrintMessage (1, "Write solution data to file ", filename);
if (strcmp (&filename[strlen(filename)-3], "sol") == 0)
{
ofstream ost(filename);
for (int i = 0; i < soldata.Size(); i++)
{
const SolData & sol = *soldata[i];
ost << "solution "
<< sol.name
<< " -size=" << sol.size
<< " -components=" << sol.components
<< " -order=" << sol.order;
if (sol.iscomplex)
ost << " -complex";
switch (sol.soltype)
{
case SOL_NODAL:
ost << " -type=nodal"; break;
case SOL_ELEMENT:
ost << " -type=element"; break;
case SOL_SURFACE_ELEMENT:
ost << " -type=surfaceelement"; break;
case SOL_NONCONTINUOUS:
ost << " -type=noncontinuous"; break;
case SOL_SURFACE_NONCONTINUOUS:
ost << " -type=surfacenoncontinuous"; break;
2009-07-20 14:36:36 +06:00
default:
cerr << "save solution data, case not handeld" << endl;
2009-01-13 04:40:13 +05:00
}
ost << endl;
for (int j = 0; j < sol.size; j++)
{
for (int k = 0; k < sol.components; k++)
ost << sol.data[j*sol.dist+k] << " ";
ost << "\n";
}
}
}
if (strcmp (&filename[strlen(filename)-3], "vtk") == 0)
{
string surf_fn = filename;
surf_fn.erase (strlen(filename)-4);
surf_fn += "_surf.vtk";
cout << "surface mesh = " << surf_fn << endl;
ofstream surf_ost(surf_fn.c_str());
surf_ost << "# vtk DataFile Version 1.0\n"
2011-01-11 01:18:01 +05:00
<< "NGSolve surface mesh\n"
<< "ASCII\n"
<< "DATASET UNSTRUCTURED_GRID\n\n";
2009-01-13 04:40:13 +05:00
surf_ost << "POINTS " << mesh->GetNP() << " float\n";
for (PointIndex pi = PointIndex::BASE; pi < mesh->GetNP()+PointIndex::BASE; pi++)
{
const MeshPoint & mp = (*mesh)[pi];
surf_ost << mp(0) << " " << mp(1) << " " << mp(2) << "\n";
}
int cntverts = 0;
for (SurfaceElementIndex sei = 0; sei < mesh->GetNSE(); sei++)
cntverts += 1 + (*mesh)[sei].GetNP();
surf_ost << "\nCELLS " << mesh->GetNSE() << " " << cntverts << "\n";
for (SurfaceElementIndex sei = 0; sei < mesh->GetNSE(); sei++)
{
const Element2d & el = (*mesh)[sei];
surf_ost << el.GetNP();
for (int j = 0; j < el.GetNP(); j++)
surf_ost << " " << el[j] - PointIndex::BASE;
surf_ost << "\n";
}
surf_ost << "\nCELL_TYPES " << mesh->GetNSE() << "\n";
for (SurfaceElementIndex sei = 0; sei < mesh->GetNSE(); sei++)
{
const Element2d & el = (*mesh)[sei];
switch (el.GetType())
{
case QUAD: surf_ost << 9; break;
case TRIG: surf_ost << 5; break;
2009-07-20 14:36:36 +06:00
default:
cerr << "not implemented 2378" << endl;
2009-01-13 04:40:13 +05:00
}
surf_ost << "\n";
}
ofstream ost(filename);
ost << "# vtk DataFile Version 1.0\n"
<< "NGSolve solution\n"
<< "ASCII\n"
<< "DATASET UNSTRUCTURED_GRID\n\n";
ost << "POINTS " << mesh->GetNP() << " float\n";
for (PointIndex pi = PointIndex::BASE; pi < mesh->GetNP()+PointIndex::BASE; pi++)
{
const MeshPoint & mp = (*mesh)[pi];
ost << mp(0) << " " << mp(1) << " " << mp(2) << "\n";
}
cntverts = 0;
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
cntverts += 1 + (*mesh)[ei].GetNP();
ost << "\nCELLS " << mesh->GetNE() << " " << cntverts << "\n";
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
{
const Element & el = (*mesh)[ei];
ost << el.GetNP();
for (int j = 0; j < el.GetNP(); j++)
ost << " " << el[j] - PointIndex::BASE;
ost << "\n";
}
ost << "\nCELL_TYPES " << mesh->GetNE() << "\n";
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
{
const Element & el = (*mesh)[ei];
switch (el.GetType())
{
case TET: ost << 10; break;
2009-07-20 14:36:36 +06:00
default:
cerr << "not implemented 67324" << endl;
2009-01-13 04:40:13 +05:00
}
ost << "\n";
}
ost << "CELL_DATA " << mesh->GetNE() << "\n";
for (int i = 0; i < soldata.Size(); i++)
{
ost << "VECTORS bfield float\n";
SolutionData & sol = *(soldata[i] -> solclass);
double values[3];
for (int elnr = 0; elnr < mesh->GetNE(); elnr++)
{
sol.GetValue (elnr, 0.25, 0.25, 0.25, values);
ost << values[0] << " " << values[1] << " " << values[2] << "\n";
}
}
/*
2011-01-11 01:18:01 +05:00
ost << "POINT_DATA " << mesh->GetNP() << "\n";
for (int i = 0; i < soldata.Size(); i++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
ost << "VECTORS bfield float\n";
SolutionData & sol = *(soldata[i] -> solclass);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (PointIndex pi = PointIndex::BASE;
pi < mesh->GetNP()+PointIndex::BASE; pi++)
{
double values[3], sumvalues[3] = { 0, 0, 0 };
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
FlatArray<int> els = mesh->GetTopology().GetVertexElements(pi);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int j = 0; j < els.Size(); j++)
{
sol.GetValue (els[j]-1, 0.25, 0.25, 0.25, values);
for (int k = 0; k < 3; k++)
sumvalues[k] += values[k];
}
for (int k = 0; k < 3; k++)
sumvalues[k] /= els.Size();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
ost << sumvalues[0] << " " << sumvalues[1] << " " << sumvalues[2] << "\n";
}
2009-01-13 04:40:13 +05:00
}
*/
}
}
void VisualSceneSolution :: DrawScene ()
{
2014-10-06 15:57:44 +06:00
try
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
if (!mesh)
{
VisualScene::DrawScene();
return;
}
2009-08-24 06:03:40 +06:00
// static NgLock mem_lock(mem_mutex);
// mem_lock.Lock();
2009-01-13 04:40:13 +05:00
NgLock meshlock1 (mesh->MajorMutex(), true);
NgLock meshlock (mesh->Mutex(), true);
BuildScene();
CreateTexture (numtexturecols, lineartexture, 0.5, GL_MODULATE);
2009-01-13 04:40:13 +05:00
glClearColor(backcolor, backcolor, backcolor, 1);
// glClearColor(backcolor, backcolor, backcolor, 0);
2009-01-13 04:40:13 +05:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SetLight();
glPushMatrix();
glMultMatrixd (transformationmat);
2009-01-13 04:40:13 +05:00
glMatrixMode (GL_MODELVIEW);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glPolygonOffset (1, 1);
glEnable (GL_POLYGON_OFFSET_FILL);
glEnable (GL_COLOR_MATERIAL);
if (usetexture)
{
2009-08-05 20:20:30 +06:00
SetTextureMode (usetexture);
2009-01-13 04:40:13 +05:00
glMatrixMode (GL_TEXTURE);
glLoadIdentity();
if (usetexture == 1)
{
double hmax = maxval;
double hmin = minval;
if (invcolor) Swap (hmax, hmin);
if (fabs (hmax - hmin) > 1e-30)
glScaled (1.0 / (hmin - hmax), 0, 0);
else
glScaled (1e30, 0, 0);
glTranslatef (-hmax, 0, 0);
}
else
{
glTranslatef (0.5, 0, 0);
glRotatef(360 * netgen::GetVSSolution().time, 0, 0, -1);
2009-01-13 04:40:13 +05:00
if (fabs (maxval) > 1e-10)
glScalef(0.5/maxval, 0.5/maxval, 0.5/maxval);
else
glScalef (1e10, 1e10, 1e10);
}
glMatrixMode (GL_MODELVIEW);
}
2009-01-13 04:40:13 +05:00
if (vispar.drawfilledtrigs || vispar.drawtetsdomain > 0 || vispar.drawdomainsurf > 0)
{
// Change for Martin:
// orig:
SetClippingPlane ();
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// glEnable(GL_BLEND);
glDisable(GL_BLEND);
glCallList (surfellist);
#ifdef USE_BUFFERS
2016-11-01 15:47:49 +05:00
static int timer = NgProfiler::CreateTimer ("Solution::drawing - DrawSurfaceElements VBO");
NgProfiler::StartTimer(timer);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2016-11-01 15:47:49 +05:00
glDrawElements(GL_TRIANGLES, surfel_vbo_size, GL_UNSIGNED_INT, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2016-11-01 15:47:49 +05:00
NgProfiler::StopTimer(timer);
#endif
glDisable(GL_BLEND);
/*
// transparent test ...
glColor4f (1, 0, 0, 0.1);
glEnable (GL_COLOR_MATERIAL);
glDepthFunc(GL_GREATER);
glDepthMask(GL_FALSE);
// glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA);
glCallList (surfellist);
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glCallList (surfellist);
// end test ...
*/
2009-01-13 04:40:13 +05:00
glCallList (surface_vector_list);
glDisable(GL_CLIP_PLANE0);
}
2009-01-13 04:40:13 +05:00
if (showclipsolution)
2011-02-15 21:22:05 +05:00
{
if (clipsolution == 1)
{
// Martin
// orig:
2013-06-06 20:47:05 +06:00
glCallList (clipplanelist_scal);
// transparent experiments
// see http://wiki.delphigl.com/index.php/Blenden
/*
glColor4f (1, 1, 1, 0.5);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_COLOR);
glDepthFunc(GL_GREATER);
glDepthMask(GL_FALSE);
glCallList (clipplanelist_scal);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glCallList (clipplanelist_scal);
glDisable(GL_BLEND);
*/
2013-06-06 20:47:05 +06:00
/*
// latest transparent version ...
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
// CreateTexture (numtexturecols, lineartexture, 0.25, GL_MODULATE);
// glCallList (clipplanelist_scal);
glEnable(GL_BLEND);
// glDisable(GL_DEPTH_TEST);
// CreateTexture (numtexturecols, lineartexture, 0.25, GL_MODULATE);
glCallList (clipplanelist_scal);
// glDepthFunc(GL_LEQUAL);
// glDepthMask(GL_TRUE);
// glCallList (clipplanelist_scal);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
2013-06-06 20:47:05 +06:00
*/
// end test
}
2011-02-15 21:22:05 +05:00
if (clipsolution == 2)
{
// glDisable(GL_DEPTH_TEST);
glCallList (clipplanelist_vec);
// glEnable(GL_DEPTH_TEST);
}
2011-02-15 21:22:05 +05:00
}
2009-01-13 04:40:13 +05:00
2009-01-13 04:40:13 +05:00
if (draw_fieldlines)
{
SetClippingPlane();
if (num_fieldlineslists <= 1)
glCallList (fieldlineslist);
else
{ // animated
int start = int (time / 10 * num_fieldlineslists);
for (int ln = 0; ln < 10; ln++)
{
int nr = fieldlineslist + (start + ln) % num_fieldlineslists;
glCallList (nr);
}
}
glDisable(GL_CLIP_PLANE0);
}
if(drawpointcurves)
{
glCallList(pointcurvelist);
}
2009-08-05 20:20:30 +06:00
2009-01-13 04:40:13 +05:00
glMatrixMode (GL_TEXTURE);
glLoadIdentity();
glMatrixMode (GL_MODELVIEW);
2009-08-05 20:20:30 +06:00
glDisable (GL_TEXTURE_1D);
glDisable (GL_TEXTURE_2D);
2009-01-13 04:40:13 +05:00
glDisable (GL_POLYGON_OFFSET_FILL);
glDisable (GL_COLOR_MATERIAL);
if (draw_isosurface)
glCallList (isosurface_list);
GLfloat matcol0[] = { 0, 0, 0, 1 };
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matcol0);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, matcol0);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matcol0);
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
glLineWidth (1.0f);
glColor3f (0.0f, 0.0f, 0.0f);
glDisable (GL_LINE_SMOOTH);
2013-05-27 19:01:58 +06:00
if (vispar.drawedges)
{
glCallList (element1dlist);
}
2009-01-13 04:40:13 +05:00
if (vispar.drawoutline && !numisolines)
{
SetClippingPlane ();
glDepthMask(GL_FALSE);
2009-01-13 04:40:13 +05:00
glCallList (linelist);
glDepthMask(GL_TRUE);
2009-01-13 04:40:13 +05:00
glDisable(GL_CLIP_PLANE0);
}
if (numisolines)
{
SetClippingPlane ();
glCallList (isolinelist);
glDisable(GL_CLIP_PLANE0);
glCallList (clipplane_isolinelist);
}
2014-02-24 01:31:40 +06:00
// user visualization
for (int i = 0; i < user_vis.Size(); i++)
user_vis[i] -> Draw();
2009-01-13 04:40:13 +05:00
glPopMatrix();
glDisable(GL_CLIP_PLANE0);
DrawColorBar (minval, maxval, logscale, lineartexture);
if (vispar.drawcoordinatecross)
DrawCoordinateCross ();
DrawNetgenLogo ();
glFinish();
// delete lock;
2009-08-24 06:03:40 +06:00
// mem_lock.UnLock();
2014-10-06 15:57:44 +06:00
}
catch (bad_weak_ptr e)
{
2017-01-01 19:34:38 +05:00
// cout << "don't have a mesh to visualize" << endl;
2014-10-06 15:57:44 +06:00
VisualScene::DrawScene();
}
2009-01-13 04:40:13 +05:00
}
2013-02-27 23:30:38 +06:00
/*
2009-01-13 04:40:13 +05:00
void VisualSceneSolution :: RealVec3d (const double * values, Vec3d & v,
bool iscomplex, bool imag)
{
if (!iscomplex)
{
v.X() = values[0];
v.Y() = values[1];
v.Z() = values[2];
}
else
{
if (!imag)
{
v.X() = values[0];
v.Y() = values[2];
v.Z() = values[4];
}
else
{
v.X() = values[1];
v.Y() = values[3];
v.Z() = values[5];
}
}
}
2013-02-27 23:30:38 +06:00
*/
Vec<3> VisualSceneSolution :: RealVec3d (const double * values,
bool iscomplex, bool imag)
{
Vec<3> v;
if (!iscomplex)
{
for (int j = 0; j < 3; j++)
v(j) = values[j];
}
else
{
if (!imag)
{
for (int j = 0; j < 3; j++)
v(j) = values[2*j];
}
else
{
for (int j = 0; j < 3; j++)
v(j) = values[2*j+1];
}
}
return v;
}
2009-01-13 04:40:13 +05:00
void VisualSceneSolution :: RealVec3d (const double * values, Vec3d & v,
bool iscomplex, double phaser, double phasei)
{
if (!iscomplex)
{
v.X() = values[0];
v.Y() = values[1];
v.Z() = values[2];
}
else
{
for (int i = 0; i < 3; i++)
v.X(i+1) = phaser * values[2*i] + phasei * values[2*i+1];
}
}
void VisualSceneSolution :: BuildScene (int zoomall)
{
2014-10-06 15:57:44 +06:00
try
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
if (!mesh)
{
VisualScene::BuildScene (zoomall);
return;
}
2009-08-05 20:20:30 +06:00
/*
2011-01-11 01:18:01 +05:00
if (!cone_list)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
cone_list = glGenLists (1);
glNewList (cone_list, GL_COMPILE);
DrawCone (Point<3> (0,0,0), Point<3> (0,0,1), 0.4);
glEndList();
2009-01-13 04:40:13 +05:00
}
2009-08-05 20:20:30 +06:00
*/
2009-01-13 04:40:13 +05:00
// vispar.colormeshsize = 1;
2009-01-13 04:40:13 +05:00
// recalc clipping plane
SetClippingPlane ();
glDisable(GL_CLIP_PLANE0);
SolData * sol = NULL;
SolData * vsol = NULL;
if (scalfunction != -1)
sol = soldata[scalfunction];
if (vecfunction != -1)
vsol = soldata[vecfunction];
if (mesh->GetTimeStamp () > solutiontimestamp)
{
sol = NULL;
vsol = NULL;
}
if (sol && sol->solclass) sol->solclass->SetMultiDimComponent (multidimcomponent);
if (vsol && vsol->solclass) vsol->solclass->SetMultiDimComponent (multidimcomponent);
2009-08-05 20:20:30 +06:00
if (!autoscale || (!sol && !vsol) )
2009-01-13 04:40:13 +05:00
{
minval = mminval;
maxval = mmaxval;
}
else
{
if (mesh->GetTimeStamp () > surfeltimestamp ||
2012-11-05 17:28:36 +06:00
vispar.clipping.timestamp > clipplanetimestamp ||
2009-01-13 04:40:13 +05:00
solutiontimestamp > surfeltimestamp)
{
GetMinMax (scalfunction, scalcomp, minval, maxval);
}
}
2012-11-05 17:28:36 +06:00
2009-01-13 04:40:13 +05:00
if (mesh->GetTimeStamp() > surfeltimestamp ||
solutiontimestamp > surfeltimestamp ||
zoomall)
{
if (mesh->GetTimeStamp() > surfeltimestamp || zoomall)
{
// mesh has changed
Point3d pmin, pmax;
static double oldrad = 0;
mesh->GetBox (pmin, pmax, -1);
center = Center (pmin, pmax);
rad = 0.5 * Dist (pmin, pmax);
glEnable (GL_NORMALIZE);
if (rad > 1.5 * oldrad ||
mesh->GetMajorTimeStamp() > surfeltimestamp ||
zoomall)
{
CalcTransformationMatrices();
oldrad = rad;
}
}
DrawSurfaceElements();
surfeltimestamp = max2 (solutiontimestamp, mesh->GetTimeStamp());
}
if (mesh->GetTimeStamp() > surfellinetimestamp ||
subdivision_timestamp > surfellinetimestamp ||
(deform && solutiontimestamp > surfellinetimestamp) ||
zoomall)
2012-08-20 20:10:23 +06:00
{
DrawSurfaceElementLines();
2009-01-13 04:40:13 +05:00
surfellinetimestamp = max2 (solutiontimestamp, mesh->GetTimeStamp());
}
2013-05-27 19:01:58 +06:00
if (vispar.drawedges)
Draw1DElements();
2009-01-13 04:40:13 +05:00
if (mesh->GetTimeStamp() > surface_vector_timestamp ||
solutiontimestamp > surface_vector_timestamp ||
zoomall)
{
if (surface_vector_list)
glDeleteLists (surface_vector_list, 1);
surface_vector_list = glGenLists (1);
glNewList (surface_vector_list, GL_COMPILE);
glEnable (GL_NORMALIZE);
DrawSurfaceVectors();
glEndList ();
surface_vector_timestamp =
max2 (mesh->GetTimeStamp(), solutiontimestamp);
}
2012-11-05 17:28:36 +06:00
if (clipplanetimestamp < vispar.clipping.timestamp ||
2009-01-13 04:40:13 +05:00
clipplanetimestamp < solutiontimestamp)
{
// cout << "clipsolution = " << clipsolution << endl;
2012-11-05 17:28:36 +06:00
if (vispar.clipping.enable && clipsolution == 2)
2009-01-13 04:40:13 +05:00
{
mesh->Mutex().unlock();
2009-01-13 04:40:13 +05:00
mesh->BuildElementSearchTree();
mesh->Mutex().lock();
2009-01-13 04:40:13 +05:00
}
2012-11-05 17:28:36 +06:00
if (vispar.clipping.enable && clipsolution == 1 && sol)
2011-11-03 17:02:05 +06:00
DrawClipPlaneTrigs ();
2009-01-13 04:40:13 +05:00
2011-02-15 21:22:05 +05:00
if (clipplanelist_vec)
glDeleteLists (clipplanelist_vec, 1);
2009-01-13 04:40:13 +05:00
2011-02-15 21:22:05 +05:00
clipplanelist_vec = glGenLists (1);
glNewList (clipplanelist_vec, GL_COMPILE);
2012-11-05 17:28:36 +06:00
if (vispar.clipping.enable && clipsolution == 2 && vsol)
2009-01-13 04:40:13 +05:00
{
2009-08-05 20:20:30 +06:00
SetTextureMode (usetexture);
2009-01-13 04:40:13 +05:00
if (autoscale)
GetMinMax (vecfunction, 0, minval, maxval);
2009-01-25 17:35:25 +05:00
Array<ClipPlanePoint> cpp;
2009-01-13 04:40:13 +05:00
GetClippingPlaneGrid (cpp);
for (int i = 0; i < cpp.Size(); i++)
{
const ClipPlanePoint & p = cpp[i];
double values[6];
Vec3d v;
2009-08-05 20:20:30 +06:00
bool drawelem =
GetValues (vsol, p.elnr, p.lami(0), p.lami(1), p.lami(2), values);
2013-02-27 23:30:38 +06:00
// RealVec3d (values, v, vsol->iscomplex, imag_part);
v = RealVec3d (values, vsol->iscomplex, imag_part);
2009-01-13 04:40:13 +05:00
double val = v.Length();
if (drawelem && val > 1e-10 * maxval)
{
v *= (rad / val / gridsize * 0.5);
2009-08-05 20:20:30 +06:00
SetOpenGlColor (val);
2009-01-13 04:40:13 +05:00
DrawCone (p.p, p.p+v, rad / gridsize * 0.2);
}
}
}
glEndList ();
}
if (mesh->GetTimeStamp() > isosurface_timestamp ||
solutiontimestamp > isosurface_timestamp ||
zoomall)
{
if (isosurface_list)
glDeleteLists (isosurface_list, 1);
isosurface_list = glGenLists (1);
glNewList (isosurface_list, GL_COMPILE);
glEnable (GL_NORMALIZE);
DrawIsoSurface(sol, vsol, scalcomp);
glEndList ();
isosurface_timestamp =
max2 (mesh->GetTimeStamp(), solutiontimestamp);
}
if(mesh->GetTimeStamp() > pointcurve_timestamp ||
solutiontimestamp > pointcurve_timestamp)
{
if(pointcurvelist)
glDeleteLists(pointcurvelist,1);
if(mesh->GetNumPointCurves() > 0)
{
pointcurvelist = glGenLists(1);
glNewList(pointcurvelist,GL_COMPILE);
//glColor3f (1.0f, 0.f, 0.f);
for(int i=0; i<mesh->GetNumPointCurves(); i++)
{
Box3d box;
box.SetPoint(mesh->GetPointCurvePoint(i,0));
for(int j=1; j<mesh->GetNumPointsOfPointCurve(i); j++)
box.AddPoint(mesh->GetPointCurvePoint(i,j));
double diam = box.CalcDiam();
double thick = min2(0.1*diam, 0.001*rad);
double red,green,blue;
mesh->GetPointCurveColor(i,red,green,blue);
glColor3f (red, green, blue);
for(int j=0; j<mesh->GetNumPointsOfPointCurve(i)-1; j++)
{
DrawCylinder(mesh->GetPointCurvePoint(i,j),
mesh->GetPointCurvePoint(i,j+1),
thick);
}
}
glEndList();
}
}
if (
numisolines &&
2012-11-05 17:28:36 +06:00
(clipplanetimestamp < vispar.clipping.timestamp ||
2009-01-13 04:40:13 +05:00
clipplanetimestamp < solutiontimestamp)
)
{
if (isolinelist) glDeleteLists (isolinelist, 1);
isolinelist = glGenLists (1);
glNewList (isolinelist, GL_COMPILE);
Point<3> points[1100];
double values[1100];
int nse = mesh->GetNSE();
CurvedElements & curv = mesh->GetCurvedElements();
if (sol)
{
glBegin (GL_LINES);
for (SurfaceElementIndex sei = 0; sei < nse; sei++)
{
const Element2d & el = (*mesh)[sei];
bool curved = curv.IsHighOrder(); // && curv.IsSurfaceElementCurved(sei);
if (el.GetType() == TRIG || el.GetType() == TRIG6)
{
Point<3> lp1, lp2, lp3;
if (!curved)
{
GetPointDeformation (el[0]-1, lp1);
GetPointDeformation (el[1]-1, lp2);
GetPointDeformation (el[2]-1, lp3);
}
int n = 1 << subdivisions;
int ii = 0;
int ix, iy;
for (iy = 0; iy <= n; iy++)
for (ix = 0; ix <= n-iy; ix++)
{
double x = double(ix) / n;
double y = double(iy) / n;
// TODO: consider return value (bool: draw/don't draw element)
2012-04-27 00:22:49 +06:00
GetSurfValue (sol, sei, -1, x, y, scalcomp, values[ii]);
2009-01-13 04:40:13 +05:00
Point<2> xref(x,y);
if (curved)
mesh->GetCurvedElements().
CalcSurfaceTransformation (xref, sei, points[ii]);
else
points[ii] = lp3 + x * (lp1-lp3) + y * (lp2-lp3);
if (deform)
{
2012-04-27 00:22:49 +06:00
points[ii] += GetSurfDeformation (sei, -1, x, y);
2009-01-13 04:40:13 +05:00
}
ii++;
}
ii = 0;
for (iy = 0; iy < n; iy++, ii++)
for (ix = 0; ix < n-iy; ix++, ii++)
{
int index[] = { ii, ii+1, ii+n-iy+1,
ii+1, ii+n-iy+2, ii+n-iy+1 };
DrawIsoLines (points[index[0]], points[index[1]], points[index[2]],
values[index[0]], values[index[1]], values[index[2]]);
2011-01-11 01:18:01 +05:00
2009-01-13 04:40:13 +05:00
if (ix < n-iy-1)
DrawIsoLines (points[index[3]], points[index[4]], points[index[5]],
values[index[3]], values[index[4]], values[index[5]]);
}
}
if (el.GetType() == QUAD || el.GetType() == QUAD6 || el.GetType() == QUAD8 )
{
Point<3> lpi[4];
2012-04-27 00:22:49 +06:00
Vec<3> vx = 0.0, vy = 0.0, vtwist = 0.0, def;
2009-01-13 04:40:13 +05:00
if (!curved)
{
for (int j = 0; j < 4; j++)
GetPointDeformation (el[j]-1, lpi[j]);
vx = lpi[1]-lpi[0];
vy = lpi[3]-lpi[0];
vtwist = (lpi[0]-lpi[1]) + (lpi[2]-lpi[3]);
}
int n = 1 << subdivisions;
int ix, iy, ii = 0;
for (iy = 0; iy <= n; iy++)
for (ix = 0; ix <= n; ix++, ii++)
{
double x = double(ix) / n;
double y = double(iy) / n;
// TODO: consider return value (bool: draw/don't draw element)
2012-04-27 00:22:49 +06:00
GetSurfValue (sol, sei, -1, x, y, scalcomp, values[ii]);
2009-01-13 04:40:13 +05:00
Point<2> xref(x,y);
if (curved)
mesh->GetCurvedElements().
CalcSurfaceTransformation (xref, sei, points[ii]);
else
points[ii] = lpi[0] + x * vx + y * vy + x*y * vtwist;
if (deform)
2012-04-27 00:22:49 +06:00
points[ii] += GetSurfDeformation (sei, -1, x, y);
2009-01-13 04:40:13 +05:00
}
ii = 0;
for (iy = 0; iy < n; iy++, ii++)
for (ix = 0; ix < n; ix++, ii++)
{
DrawIsoLines (points[ii], points[ii+1], points[ii+n+1],
values[ii], values[ii+1], values[ii+n+1]);
DrawIsoLines (points[ii+1], points[ii+n+2], points[ii+n+1],
values[ii+1], values[ii+n+2], values[ii+n+1]);
}
}
}
glEnd();
}
glEndList ();
if (clipplane_isolinelist) glDeleteLists (clipplane_isolinelist, 1);
2012-11-05 17:28:36 +06:00
if (vispar.clipping.enable && clipsolution == 1 && sol)
2009-01-13 04:40:13 +05:00
{
clipplane_isolinelist = glGenLists (1);
glNewList (clipplane_isolinelist, GL_COMPILE);
2009-01-25 17:35:25 +05:00
Array<ClipPlaneTrig> cpt;
Array<ClipPlanePoint> pts;
2009-01-13 04:40:13 +05:00
GetClippingPlaneTrigs (cpt, pts);
bool drawelem;
glNormal3d (-clipplane[0], -clipplane[1], -clipplane[2]);
if (numisolines)
for (int i = 0; i < cpt.Size(); i++)
{
const ClipPlaneTrig & trig = cpt[i];
double vali[3];
for (int j = 0; j < 3; j++)
{
Point<3> lami = pts[trig.points[j].pnr].lami;
drawelem = GetValue (sol, trig.elnr, lami(0), lami(1), lami(2),
scalcomp, vali[j]);
}
if ( drawelem )
DrawIsoLines (pts[trig.points[0].pnr].p,
pts[trig.points[1].pnr].p,
pts[trig.points[2].pnr].p,
// trig.points[1].p,
// trig.points[2].p,
2011-01-11 01:18:01 +05:00
vali[0], vali[1], vali[2]);
2009-01-13 04:40:13 +05:00
}
glEndList ();
}
glEnd();
}
2012-11-05 17:28:36 +06:00
clipplanetimestamp = max2 (vispar.clipping.timestamp, solutiontimestamp);
2014-10-06 15:57:44 +06:00
}
catch (bad_weak_ptr e)
{
2017-01-01 19:34:38 +05:00
PrintMessage (3, "vssolution::buildscene: don't have a mesh to visualize");
2014-10-06 15:57:44 +06:00
VisualScene::BuildScene (zoomall);
}
2009-01-13 04:40:13 +05:00
}
2013-05-27 19:01:58 +06:00
void VisualSceneSolution :: Draw1DElements ()
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2013-05-27 19:01:58 +06:00
if (element1dlist)
glDeleteLists (element1dlist, 1);
element1dlist = glGenLists (1);
glNewList (element1dlist, GL_COMPILE);
int npt = (1 << subdivisions) + 1;
Array<double> pref(npt), values(npt);
Array<Point<3> > points(npt);
const SolData * sol = NULL;
if (scalfunction != -1) sol = soldata[scalfunction];
int ncomp = 0;
if (sol) ncomp = sol->components;
Array<double> mvalues(ncomp);
2009-01-13 04:40:13 +05:00
2013-05-27 19:01:58 +06:00
for (int i = 0; i < npt; i++)
pref[i] = double(i) / (npt-1);
2009-01-13 04:40:13 +05:00
2013-05-27 19:01:58 +06:00
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 ();
}
2009-01-13 04:40:13 +05:00
void VisualSceneSolution :: DrawSurfaceElements ()
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
static int timer = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements");
2016-11-01 15:47:49 +05:00
static int timerstart = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements start");
static int timerloops = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements loops");
static int timerlist = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements list");
static int timerbuffer = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements buffer");
static int timer1 = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements 1");
static int timer1a = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements 1a");
static int timer1b = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements 1b");
static int timer1c = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements 1c");
static int timer2 = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements 2");
static int timer2a = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements 2a");
static int timer2b = NgProfiler::CreateTimer ("Solution::DrawSurfaceElements 2b");
2009-01-13 04:40:13 +05:00
NgProfiler::RegionTimer reg (timer);
#ifdef PARALLELGL
if (id == 0 && ntasks > 1)
{
InitParallelGL();
par_surfellists.SetSize (ntasks);
2011-07-15 03:36:19 +06:00
MyMPI_SendCmd ("redraw");
MyMPI_SendCmd ("solsurfellist");
2009-01-13 04:40:13 +05:00
for ( int dest = 1; dest < ntasks; dest++ )
2011-07-07 03:08:58 +06:00
MyMPI_Recv (par_surfellists[dest], dest, MPI_TAG_VIS);
2009-01-13 04:40:13 +05:00
if (surfellist)
glDeleteLists (surfellist, 1);
surfellist = glGenLists (1);
glNewList (surfellist, GL_COMPILE);
for ( int dest = 1; dest < ntasks; dest++ )
glCallList (par_surfellists[dest]);
glEndList();
return;
}
#endif
2016-11-01 15:47:49 +05:00
NgProfiler::StartTimer(timerstart);
2009-01-13 04:40:13 +05:00
if (surfellist)
glDeleteLists (surfellist, 1);
surfellist = glGenLists (1);
glNewList (surfellist, GL_COMPILE);
const SolData * sol = NULL;
if (scalfunction != -1)
sol = soldata[scalfunction];
if (mesh->GetTimeStamp () > solutiontimestamp)
2011-05-13 17:36:50 +06:00
sol = NULL;
2009-01-13 04:40:13 +05:00
2011-11-03 17:02:05 +06:00
if (sol && sol->solclass) sol->solclass->SetMultiDimComponent (multidimcomponent);
2009-01-13 04:40:13 +05:00
glLineWidth (1.0f);
GLfloat col_grey[] = { 0.6f, 0.6f, 0.6f, 1.0f };
2009-08-05 20:20:30 +06:00
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, col_grey);
2009-01-13 04:40:13 +05:00
int nse = mesh->GetNSE();
2009-08-05 20:20:30 +06:00
SetTextureMode (usetexture);
2009-01-13 04:40:13 +05:00
CurvedElements & curv = mesh->GetCurvedElements();
int n = 1 << subdivisions;
int npt = sqr(n+1);
2010-03-02 01:23:55 +05:00
Array<Point<2> > pref (npt);
Array<Point<3> > points (npt);
Array<Mat<3,2> > dxdxis (npt);
Array<Vec<3> > nvs(npt);
Array<double> values(npt);
Array<double> mvalues(npt);
2016-11-01 15:47:49 +05:00
int sol_comp = (sol && sol->draw_surface) ? sol->components : 0;
2016-10-30 19:01:52 +05:00
Array<Point<2,SIMD<double>> > simd_pref ( (npt+SIMD<double>::Size()-1)/SIMD<double>::Size() );
Array<Point<3,SIMD<double>> > simd_points ( (npt+SIMD<double>::Size()-1)/SIMD<double>::Size() );
Array<Mat<3,2,SIMD<double>> > simd_dxdxis ( (npt+SIMD<double>::Size()-1)/SIMD<double>::Size() );
Array<Vec<3,SIMD<double>> > simd_nvs( (npt+SIMD<double>::Size()-1)/SIMD<double>::Size() );
2016-11-01 15:47:49 +05:00
Array<SIMD<double>> simd_values( (npt+SIMD<double>::Size()-1)/SIMD<double>::Size() * sol_comp);
2016-10-30 19:01:52 +05:00
2016-11-01 15:47:49 +05:00
// Array<Point<3,float>> glob_pnts;
// Array<Vec<3,float>> glob_nvs;
// Array<double> glob_values;
2010-03-02 01:23:55 +05:00
if (sol && sol->draw_surface) mvalues.SetSize (npt * sol->components);
2016-10-30 19:01:52 +05:00
2010-03-02 01:23:55 +05:00
Array<complex<double> > valuesc(npt);
#ifdef USE_BUFFERS
2016-11-01 15:47:49 +05:00
if (has_surfel_vbo)
glDeleteBuffers (4, &surfel_vbo[0]);
glGenBuffers (4, &surfel_vbo[0]);
2016-11-01 15:47:49 +05:00
has_surfel_vbo = true;
glBindBuffer (GL_ARRAY_BUFFER, surfel_vbo[0]);
glBufferData (GL_ARRAY_BUFFER,
nse*npt*sizeof(Point<3,double>),
NULL, GL_STATIC_DRAW);
glVertexPointer(3, GL_DOUBLE, 0, 0);
// glEnableClientState(GL_VERTEX_ARRAY);
2016-11-01 15:47:49 +05:00
glBindBuffer (GL_ARRAY_BUFFER, surfel_vbo[1]);
glBufferData (GL_ARRAY_BUFFER,
nse*npt*sizeof(Vec<3,double>),
NULL, GL_STATIC_DRAW);
// glEnableClientState(GL_NORMAL_ARRAY);
2016-11-01 15:47:49 +05:00
glNormalPointer(GL_DOUBLE, 0, 0);
// glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2016-11-01 15:47:49 +05:00
glBindBuffer (GL_ARRAY_BUFFER, surfel_vbo[2]);
glBufferData (GL_ARRAY_BUFFER, nse*npt*sizeof(double), NULL, GL_STATIC_DRAW);
glTexCoordPointer(1, GL_DOUBLE, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surfel_vbo[3]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, nse*npt*6*sizeof(int), NULL, GL_STATIC_DRAW);
surfel_vbo_size = 0;
#endif
2016-11-01 15:47:49 +05:00
NgProfiler::StopTimer(timerstart);
2009-01-13 04:40:13 +05:00
for (SurfaceElementIndex sei = 0; sei < nse; sei++)
{
const Element2d & el = (*mesh)[sei];
2009-08-05 20:20:30 +06:00
if (vispar.drawdomainsurf > 0)
{
if (mesh->GetDimension() == 3)
{
if (vispar.drawdomainsurf != mesh->GetFaceDescriptor(el.GetIndex()).DomainIn() &&
vispar.drawdomainsurf != mesh->GetFaceDescriptor(el.GetIndex()).DomainOut())
continue;
}
else
{
if (el.GetIndex() != vispar.drawdomainsurf) continue;
}
}
2009-01-13 04:40:13 +05:00
if ( el.GetType() == QUAD || el.GetType() == QUAD6 )
{
2009-08-24 06:03:40 +06:00
bool curved = curv.IsSurfaceElementCurved (sei);
2009-01-13 04:40:13 +05:00
for (int iy = 0, ii = 0; iy <= n; iy++)
for (int ix = 0; ix <= n; ix++, ii++)
2009-02-25 21:06:34 +05:00
pref[ii] = Point<2> (double(ix)/n, double(iy)/n);
2009-01-13 04:40:13 +05:00
int npt = (n+1)*(n+1);
if (curved)
{
for (int ii = 0; ii < npt; ii++)
{
Point<2> xref = pref[ii];
mesh->GetCurvedElements().
CalcSurfaceTransformation (xref, sei, points[ii], dxdxis[ii]);
nvs[ii] = Cross (dxdxis[ii].Col(0), dxdxis[ii].Col(1));
nvs[ii].Normalize();
}
}
2009-01-13 04:40:13 +05:00
else
{
2011-01-11 01:18:01 +05:00
Point<3> lpi[4];
Vec<3> vx, vy, vtwist;
for (int k = 0; k < 4; k++)
GetPointDeformation (el[k]-1, lpi[k]);
vx = lpi[1]-lpi[0];
vy = lpi[3]-lpi[0];
vtwist = (lpi[0]-lpi[1]) + (lpi[2]-lpi[3]);
2009-01-13 04:40:13 +05:00
for (int ii = 0; ii < npt; ii++)
{
double x = pref[ii](0);
double y = pref[ii](1);
points[ii] = lpi[0] + x * vx + y * vy + x*y * vtwist;
for (int j = 0; j < 3; j++)
{
dxdxis[ii](j,0) = vx(j) + y*vtwist(j);
dxdxis[ii](j,1) = vy(j) + x*vtwist(j);
}
2009-01-13 04:40:13 +05:00
}
Vec<3> nv = Cross (vx, vy);
nv.Normalize();
for (int ii = 0; ii < npt; ii++)
nvs[ii] = nv;
}
2009-02-25 21:06:34 +05:00
2009-08-05 20:20:30 +06:00
bool drawelem = false;
2012-11-05 17:28:36 +06:00
/*
2009-01-13 04:40:13 +05:00
if (sol && sol->draw_surface)
{
if (usetexture == 2)
for (int ii = 0; ii < npt; ii++)
2012-04-27 00:22:49 +06:00
drawelem = GetSurfValueComplex (sol, sei, -1, pref[ii](0), pref[ii](1), scalcomp, valuesc[ii]);
2009-01-13 04:40:13 +05:00
else
for (int ii = 0; ii < npt; ii++)
2012-04-27 00:22:49 +06:00
drawelem = GetSurfValue (sol, sei, -1, pref[ii](0), pref[ii](1), scalcomp, values[ii]);
2009-01-13 04:40:13 +05:00
}
2012-11-05 17:28:36 +06:00
*/
if (sol && sol->draw_surface)
{
drawelem = GetMultiSurfValues (sol, sei, -1, npt,
&pref[0](0), &pref[1](0)-&pref[0](0),
&points[0](0), &points[1](0)-&points[0](0),
&dxdxis[0](0), &dxdxis[1](0)-&dxdxis[0](0),
&mvalues[0], sol->components);
if (usetexture == 2)
for (int ii = 0; ii < npt; ii++)
valuesc[ii] = ExtractValueComplex(sol, scalcomp, &mvalues[ii*sol->components]);
else
for (int ii = 0; ii < npt; ii++)
values[ii] = ExtractValue(sol, scalcomp, &mvalues[ii*sol->components]);
}
2009-01-13 04:40:13 +05:00
if (deform)
for (int ii = 0; ii < npt; ii++)
2012-04-27 00:22:49 +06:00
points[ii] += GetSurfDeformation (sei, -1, pref[ii](0), pref[ii](1));
2009-01-13 04:40:13 +05:00
2009-08-05 20:20:30 +06:00
int save_usetexture = usetexture;
if (!drawelem)
{
usetexture = 0;
SetTextureMode (0);
}
2009-01-13 04:40:13 +05:00
int ii = 0;
2009-08-05 20:20:30 +06:00
glBegin (GL_QUADS);
2009-01-13 04:40:13 +05:00
for (int iy = 0; iy < n; iy++, ii++)
for (int ix = 0; ix < n; ix++, ii++)
{
int index[] = { ii, ii+1, ii+n+2, ii+n+1 };
for (int j = 0; j < 4; j++)
{
2009-08-05 20:20:30 +06:00
if (drawelem)
2009-01-13 04:40:13 +05:00
{
2009-08-05 20:20:30 +06:00
if (usetexture != 2)
SetOpenGlColor (values[index[j]]);
2009-01-13 04:40:13 +05:00
else
2009-08-24 06:03:40 +06:00
glTexCoord2f ( valuesc[index[j]].real(),
valuesc[index[j]].imag() );
2009-01-13 04:40:13 +05:00
}
2009-08-05 20:20:30 +06:00
else
glColor4fv (col_grey);
2009-01-13 04:40:13 +05:00
glNormal3dv (nvs[index[j]]);
glVertex3dv (points[index[j]]);
}
}
2009-08-05 20:20:30 +06:00
glEnd();
if (!drawelem && (usetexture != save_usetexture))
{
usetexture = save_usetexture;
SetTextureMode (usetexture);
}
2009-01-13 04:40:13 +05:00
}
}
n = 1 << subdivisions;
double invn = 1.0 / n;
npt = (n+1)*(n+2)/2;
2016-11-01 15:47:49 +05:00
NgProfiler::StartTimer(timerloops);
size_t base_pi = 0;
2009-01-13 04:40:13 +05:00
2016-11-01 15:47:49 +05:00
for (int iy = 0, ii = 0; iy <= n; iy++)
for (int ix = 0; ix <= n-iy; ix++, ii++)
pref[ii] = Point<2> (ix*invn, iy*invn);
constexpr size_t simd_size = SIMD<double>::Size();
size_t simd_npt = (npt+simd_size-1)/simd_size;
for (size_t i = 0; i < simd_npt; i++)
{
simd_pref[i](0) = [&] (size_t j) { size_t ii = i*simd_size+j; return (ii < npt) ? pref[ii](0) : 0; };
simd_pref[i](1) = [&] (size_t j) { size_t ii = i*simd_size+j; return (ii < npt) ? pref[ii](1) : 0; };
2016-11-01 15:47:49 +05:00
}
Array<int> ind_reftrig;
for (int iy = 0, ii = 0; iy < n; iy++,ii++)
for (int ix = 0; ix < n-iy; ix++, ii++)
{
int nv = (ix+iy+1 < n) ? 6 : 3;
int ind[] = { ii, ii+1, ii+n-iy+1,
ii+n-iy+1, ii+1, ii+n-iy+2 };
for (int j = 0; j < nv; j++)
ind_reftrig.Append (ind[j]);
}
Array<int> glob_ind;
glob_ind.SetSize(ind_reftrig.Size());
2009-01-13 04:40:13 +05:00
for(SurfaceElementIndex sei = 0; sei < nse; sei++)
{
const Element2d & el = (*mesh)[sei];
// if (el.GetIndex() <= 1) continue;
2009-01-13 04:40:13 +05:00
2009-08-24 06:03:40 +06:00
if(vispar.drawdomainsurf > 0)
{
if (mesh->GetDimension() == 3)
{
if (vispar.drawdomainsurf != mesh->GetFaceDescriptor(el.GetIndex()).DomainIn() &&
vispar.drawdomainsurf != mesh->GetFaceDescriptor(el.GetIndex()).DomainOut())
continue;
}
else
{
if (el.GetIndex() != vispar.drawdomainsurf)
continue;
}
}
2009-01-13 04:40:13 +05:00
if ( el.GetType() == TRIG || el.GetType() == TRIG6 )
{
2016-11-01 15:47:49 +05:00
NgProfiler::StartTimer(timer1);
2016-10-30 19:01:52 +05:00
#ifdef __AVX_try_it_out__
2016-11-01 15:47:49 +05:00
// NgProfiler::StartTimer(timer1a);
2016-10-30 19:01:52 +05:00
bool curved = curv.IsSurfaceElementCurved(sei);
if (curved)
{
mesh->GetCurvedElements().
CalcMultiPointSurfaceTransformation<3> (sei, simd_npt,
&simd_pref[0](0), 2,
&simd_points[0](0), 3,
&simd_dxdxis[0](0,0), 6);
for (size_t ii = 0; ii < simd_npt; ii++)
simd_nvs[ii] = Cross (simd_dxdxis[ii].Col(0), simd_dxdxis[ii].Col(1)).Normalize();
}
else
{
Point<3,SIMD<double>> p1 = mesh->Point (el[0]);
Point<3,SIMD<double>> p2 = mesh->Point (el[1]);
Point<3,SIMD<double>> p3 = mesh->Point (el[2]);
Vec<3,SIMD<double>> vx = p1-p3;
Vec<3,SIMD<double>> vy = p2-p3;
for (size_t ii = 0; ii < simd_npt; ii++)
{
simd_points[ii] = p3 + simd_pref[ii](0) * vx + simd_pref[ii](1) * vy;
for (size_t j = 0; j < 3; j++)
{
simd_dxdxis[ii](j,0) = vx(j);
simd_dxdxis[ii](j,1) = vy(j);
}
}
Vec<3,SIMD<double>> nv = Cross (vx, vy).Normalize();
for (size_t ii = 0; ii < simd_npt; ii++)
simd_nvs[ii] = nv;
}
2016-11-01 15:47:49 +05:00
2016-10-30 19:01:52 +05:00
bool drawelem = false;
if (sol && sol->draw_surface)
{
2016-11-01 15:47:49 +05:00
// NgProfiler::StopTimer(timer1a);
// NgProfiler::StartTimer(timer1b);
2016-10-30 19:01:52 +05:00
drawelem = sol->solclass->GetMultiSurfValue (sei, -1, simd_npt,
&simd_pref[0](0).Data(),
&simd_points[0](0).Data(),
&simd_dxdxis[0](0).Data(),
&simd_values[0].Data());
2016-11-01 15:47:49 +05:00
// NgProfiler::StopTimer(timer1b);
// NgProfiler::StartTimer(timer1c);
2016-10-30 19:01:52 +05:00
for (size_t j = 0; j < sol->components; j++)
for (size_t i = 0; i < npt; i++)
mvalues[i*sol->components+j] = ((double*)&simd_values[j*simd_npt])[i];
if (usetexture == 2)
for (int ii = 0; ii < npt; ii++)
valuesc[ii] = ExtractValueComplex(sol, scalcomp, &mvalues[ii*sol->components]);
else
for (int ii = 0; ii < npt; ii++)
values[ii] = ExtractValue(sol, scalcomp, &mvalues[ii*sol->components]);
}
for (size_t i = 0; i < npt; i++)
{
size_t ii = i/4;
size_t r = i%4;
for (int j = 0; j < 2; j++)
pref[i](j) = simd_pref[ii](j)[r];
for (int j = 0; j < 3; j++)
points[i](j) = simd_points[ii](j)[r];
for (int j = 0; j < 3; j++)
nvs[i](j) = simd_nvs[ii](j)[r];
}
if (deform)
for (int ii = 0; ii < npt; ii++)
points[ii] += GetSurfDeformation (sei, -1, pref[ii](0), pref[ii](1));
2016-11-01 15:47:49 +05:00
// NgProfiler::StopTimer(timer1c);
2016-10-30 19:01:52 +05:00
#else
2009-08-24 06:03:40 +06:00
bool curved = curv.IsSurfaceElementCurved(sei);
2009-01-13 04:40:13 +05:00
for (int iy = 0, ii = 0; iy <= n; iy++)
for (int ix = 0; ix <= n-iy; ix++, ii++)
pref[ii] = Point<2> (ix*invn, iy*invn);
if (curved)
{
mesh->GetCurvedElements().
CalcMultiPointSurfaceTransformation (&pref, sei, &points, &dxdxis);
for (int ii = 0; ii < npt; ii++)
nvs[ii] = Cross (dxdxis[ii].Col(0), dxdxis[ii].Col(1)).Normalize();
}
else
{
2009-08-24 06:03:40 +06:00
Point<3> p1 = mesh->Point (el[0]);
Point<3> p2 = mesh->Point (el[1]);
Point<3> p3 = mesh->Point (el[2]);
Vec<3> vx = p1-p3;
Vec<3> vy = p2-p3;
2009-01-13 04:40:13 +05:00
for (int ii = 0; ii < npt; ii++)
{
2009-08-24 06:03:40 +06:00
points[ii] = p3 + pref[ii](0) * vx + pref[ii](1) * vy;
2009-01-13 04:40:13 +05:00
for (int j = 0; j < 3; j++)
{
dxdxis[ii](j,0) = vx(j);
dxdxis[ii](j,1) = vy(j);
}
}
Vec<3> nv = Cross (vx, vy).Normalize();
for (int ii = 0; ii < npt; ii++)
nvs[ii] = nv;
}
2009-08-05 20:20:30 +06:00
bool drawelem = false;
2009-01-13 04:40:13 +05:00
if (sol && sol->draw_surface)
{
2012-04-27 00:22:49 +06:00
drawelem = GetMultiSurfValues (sol, sei, -1, npt,
2009-08-24 06:03:40 +06:00
&pref[0](0), &pref[1](0)-&pref[0](0),
&points[0](0), &points[1](0)-&points[0](0),
&dxdxis[0](0), &dxdxis[1](0)-&dxdxis[0](0),
&mvalues[0], sol->components);
2009-01-13 04:40:13 +05:00
if (usetexture == 2)
2009-08-24 06:03:40 +06:00
for (int ii = 0; ii < npt; ii++)
2010-03-02 01:23:55 +05:00
valuesc[ii] = ExtractValueComplex(sol, scalcomp, &mvalues[ii*sol->components]);
2009-01-13 04:40:13 +05:00
else
2009-08-24 06:03:40 +06:00
for (int ii = 0; ii < npt; ii++)
2010-03-02 01:23:55 +05:00
values[ii] = ExtractValue(sol, scalcomp, &mvalues[ii*sol->components]);
2009-01-13 04:40:13 +05:00
}
if (deform)
for (int ii = 0; ii < npt; ii++)
2012-04-27 00:22:49 +06:00
points[ii] += GetSurfDeformation (sei, -1, pref[ii](0), pref[ii](1));
2016-10-30 19:01:52 +05:00
#endif
2016-11-01 15:47:49 +05:00
NgProfiler::StopTimer(timer1);
2009-08-05 20:20:30 +06:00
int save_usetexture = usetexture;
if (!drawelem)
{
usetexture = 0;
SetTextureMode (usetexture);
}
2012-06-11 20:24:35 +06:00
2016-11-01 15:47:49 +05:00
NgProfiler::StartTimer(timer2);
2012-06-11 20:24:35 +06:00
#ifdef USE_BUFFERS
2016-11-01 15:47:49 +05:00
if (drawelem && usetexture == 1 && !logscale)
2012-06-11 20:24:35 +06:00
{
2016-11-01 15:47:49 +05:00
glBindBuffer (GL_ARRAY_BUFFER, surfel_vbo[0]);
glBufferSubData (GL_ARRAY_BUFFER, base_pi*sizeof(Point<3,double>),
npt*sizeof(Point<3,double>), &points[0][0]);
glBindBuffer (GL_ARRAY_BUFFER, surfel_vbo[1]);
glBufferSubData (GL_ARRAY_BUFFER, base_pi*sizeof(Vec<3,double>),
npt*sizeof(Vec<3,double>), &nvs[0][0]);
glBindBuffer (GL_ARRAY_BUFFER, surfel_vbo[2]);
glBufferSubData (GL_ARRAY_BUFFER, base_pi*sizeof(double),
npt*sizeof(double), &values[0]);
for (size_t i = 0; i < ind_reftrig.Size(); i++)
glob_ind[i] = base_pi+ind_reftrig[i];
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, surfel_vbo[3]);
glBufferSubData (GL_ELEMENT_ARRAY_BUFFER, surfel_vbo_size*sizeof(int),
ind_reftrig.Size()*sizeof(int), &glob_ind[0]);
surfel_vbo_size += ind_reftrig.Size();
base_pi += npt;
2012-06-11 20:24:35 +06:00
}
2016-11-01 15:47:49 +05:00
else
#endif
2016-11-01 15:47:49 +05:00
for (int iy = 0, ii = 0; iy < n; iy++)
{
glBegin (GL_TRIANGLE_STRIP);
for (int ix = 0; ix <= n-iy; ix++, ii++)
for (int k = 0; k < 2; k++)
{
if (ix+iy+k > n) continue;
int hi = (k == 0) ? ii : ii+n-iy+1;
if (drawelem)
{
if (usetexture != 2)
SetOpenGlColor (values[hi]);
else
glTexCoord2f ( valuesc[hi].real(), valuesc[hi].imag() );
}
else
glColor4fv (col_grey);
glNormal3dv (nvs[hi]);
glVertex3dv (points[hi]);
}
glEnd();
}
NgProfiler::StopTimer(timer2);
2012-06-11 20:24:35 +06:00
2016-11-01 15:47:49 +05:00
2009-08-05 20:20:30 +06:00
if (!drawelem && (usetexture != save_usetexture))
{
usetexture = save_usetexture;
SetTextureMode (usetexture);
}
2009-01-13 04:40:13 +05:00
}
}
2016-11-01 15:47:49 +05:00
NgProfiler::StopTimer(timerloops);
NgProfiler::StartTimer(timerbuffer);
2009-01-13 04:40:13 +05:00
2016-11-01 15:47:49 +05:00
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surfel_vbo[3]);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, glob_ind.Size()*sizeof(int), &glob_ind[0], GL_STATIC_DRAW);
// surfel_vbo_size = glob_ind.Size();
NgProfiler::StopTimer(timerbuffer);
// glDrawElements(GL_TRIANGLES, surfel_vbo_size, GL_UNSIGNED_INT, 0);
2009-01-13 04:40:13 +05:00
2016-11-01 15:47:49 +05:00
// glDrawElements(GL_TRIANGLES, glob_ind.Size(), GL_UNSIGNED_INT, &glob_ind[0]);
// glDisableClientState(GL_VERTEX_ARRAY);
// glDisableClientState(GL_NORMAL_ARRAY);
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// glDeleteBuffers (1, &IndexVBOID);
// glDeleteBuffers (4, &vboId[0]);
NgProfiler::StartTimer(timerlist);
glEndList ();
NgProfiler::StopTimer(timerlist);
2009-01-13 04:40:13 +05:00
#ifdef PARALLELGL
glFinish();
if (id > 0)
2011-07-07 03:08:58 +06:00
MyMPI_Send (surfellist, 0, MPI_TAG_VIS);
2009-01-13 04:40:13 +05:00
#endif
}
void VisualSceneSolution :: DrawSurfaceElementLines ()
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2012-08-20 20:10:23 +06:00
#ifdef PARALLELGL
if (id == 0 && ntasks > 1)
{
InitParallelGL();
par_surfellists.SetSize (ntasks);
MyMPI_SendCmd ("redraw");
MyMPI_SendCmd ("solsurfellinelist");
for ( int dest = 1; dest < ntasks; dest++ )
MyMPI_Recv (par_surfellists[dest], dest, MPI_TAG_VIS);
if (linelist)
glDeleteLists (linelist, 1);
linelist = glGenLists (1);
glNewList (linelist, GL_COMPILE);
for ( int dest = 1; dest < ntasks; dest++ )
glCallList (par_surfellists[dest]);
glEndList();
return;
}
#endif
if (linelist)
glDeleteLists (linelist, 1);
linelist = glGenLists (1);
glNewList (linelist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
glLineWidth (1.0f);
int nse = mesh->GetNSE();
CurvedElements & curv = mesh->GetCurvedElements();
2009-08-24 06:03:40 +06:00
int n = 1 << subdivisions;
ArrayMem<Point<2>, 65> ptsloc(n+1);
ArrayMem<Point<3>, 65> ptsglob(n+1);
2012-04-27 01:20:47 +06:00
double trigpts[3][2] = { { 0, 0 }, { 0, 1 }, { 1, 0} };
2012-04-27 00:22:49 +06:00
double trigvecs[3][2] = { { 1, 0 }, { 0, -1 }, { -1, 1} };
2012-08-20 20:10:23 +06:00
2012-04-27 01:20:47 +06:00
double quadpts[4][2] = { { 0, 0 }, { 1, 1 }, { 0, 1}, { 1, 0 } };
double quadvecs[4][2] = { { 1, 0 }, { -1, 0}, { 0, -1}, { 0, 1 } };
2009-08-24 06:03:40 +06:00
2009-01-13 04:40:13 +05:00
for (SurfaceElementIndex sei = 0; sei < nse; sei++)
{
Element2d & el = (*mesh)[sei];
2009-08-05 20:20:30 +06:00
int nv = (el.GetType() == TRIG || el.GetType() == TRIG6) ? 3 : 4;
2009-01-13 04:40:13 +05:00
for (int k = 0; k < nv; k++)
{
2009-08-24 06:03:40 +06:00
Point<2> p0;
Vec<2> vtau;
2009-01-13 04:40:13 +05:00
if (nv == 3)
2009-08-24 06:03:40 +06:00
{
p0 = Point<2>(trigpts[k][0], trigpts[k][1]);
vtau = Vec<2>(trigvecs[k][0], trigvecs[k][1]);
}
2009-01-13 04:40:13 +05:00
else
2009-08-24 06:03:40 +06:00
{
p0 = Point<2>(quadpts[k][0], quadpts[k][1]);
vtau = Vec<2>(quadvecs[k][0], quadvecs[k][1]);
}
2009-01-13 04:40:13 +05:00
glBegin (GL_LINE_STRIP);
2012-08-20 20:10:23 +06:00
for (int ix = 0; ix <= n; ix++)
ptsloc[ix] = p0 + (double(ix) / n) * vtau;
curv.CalcMultiPointSurfaceTransformation (&ptsloc, sei, &ptsglob, 0);
for (int ix = 0; ix <= n; ix++)
{
if (deform)
ptsglob[ix] += GetSurfDeformation (sei, k, ptsloc[ix](0), ptsloc[ix](1));
glVertex3dv (ptsglob[ix]);
}
2009-01-13 04:40:13 +05:00
glEnd ();
}
}
2012-08-20 20:10:23 +06:00
glEndList ();
#ifdef PARALLELGL
glFinish();
if (id > 0)
MyMPI_Send (linelist, 0, MPI_TAG_VIS);
#endif
2009-01-13 04:40:13 +05:00
}
void VisualSceneSolution :: DrawIsoSurface(const SolData * sol,
const SolData * vsol,
int comp)
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
if (!draw_isosurface) return;
if (!sol) return;
2009-08-05 20:20:30 +06:00
SetTextureMode (0);
2009-01-13 04:40:13 +05:00
glColor3d (1.0, 0, 0);
glEnable (GL_COLOR_MATERIAL);
glBegin (GL_TRIANGLES);
int ne = mesh->GetNE();
const int edgei[6][2] =
{ { 0, 1 }, { 0, 2 }, { 0, 3 },
{ 1, 2 }, { 1, 3 }, { 2, 3 } };
double edgelam[6];
Point<3> edgep[6];
Vec<3> normp[6];
double nodevali[4];
int cntce;
int cpe1 = 0, cpe2 = 0, cpe3 = 0;
int n = 1 << subdivisions;
int n3 = (n+1)*(n+1)*(n+1);
2009-01-25 17:35:25 +05:00
Array<Point<3> > grid(n3);
Array<Point<3> > locgrid(n3);
Array<Mat<3,3> > trans(n3);
Array<double> val1(n3*sol->components);
Array<Vec<3> > grads1(n3);
2009-01-25 17:35:25 +05:00
Array<int> compress(n3);
2009-01-13 04:40:13 +05:00
MatrixFixWidth<3> pointmat(8);
grads1 = Vec<3> (0.0);
2009-01-13 04:40:13 +05:00
for (ElementIndex ei = 0; ei < ne; ei++)
{
// if(vispar.clipdomain > 0 && vispar.clipdomain != (*mesh)[ei].GetIndex()) continue;
// if(vispar.donotclipdomain > 0 && vispar.donotclipdomain == (*mesh)[ei].GetIndex()) continue;
ELEMENT_TYPE type = (*mesh)[ei].GetType();
if (type == HEX || type == PRISM || type == TET || type == PYRAMID)
{
const Element & el = (*mesh)[ei];
int ii = 0;
int cnt_valid = 0;
for (int ix = 0; ix <= n; ix++)
for (int iy = 0; iy <= n; iy++)
for (int iz = 0; iz <= n; iz++, ii++)
{
Point<3> ploc;
compress[ii] = ii;
switch (type)
{
case PRISM:
if (ix+iy <= n)
{
ploc = Point<3> (double(ix) / n, double(iy) / n, double(iz) / n);
compress[ii] = cnt_valid;
cnt_valid++;
}
else
compress[ii] = -1;
break;
case TET:
if (ix+iy+iz <= n)
{
ploc = Point<3> (double(ix) / n, double(iy) / n, double(iz) / n);
compress[ii] = cnt_valid;
cnt_valid++;
}
else
compress[ii] = -1;
break;
case HEX:
ploc = Point<3> (double(ix) / n, double(iy) / n, double(iz) / n);
break;
case PYRAMID:
ploc = Point<3> (double(ix) / n * (1-double(iz)/n),
double(iy) / n * (1-double(iz)/n),
double(iz)/n);
break;
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implementd 878234" << endl;
ploc = 0.0;
2009-01-13 04:40:13 +05:00
}
if (compress[ii] != -1)
locgrid[compress[ii]] = ploc;
}
if (type != TET && type != PRISM) cnt_valid = n3;
if (mesh->GetCurvedElements().IsHighOrder() || 1)
{
mesh->GetCurvedElements().
CalcMultiPointElementTransformation (&locgrid, ei, &grid, &trans);
}
else
{
Vector shape(el.GetNP());
for (int k = 0; k < el.GetNP(); k++)
for (int j = 0; j < 3; j++)
pointmat(k,j) = (*mesh)[el[k]](j);
for (int i = 0; i < cnt_valid; i++)
{
2016-07-07 21:31:09 +05:00
el.GetShapeNew<double> (locgrid[i], shape);
2009-01-13 04:40:13 +05:00
Point<3> pglob;
for (int j = 0; j < 3; j++)
{
pglob(j) = 0;
for (int k = 0; k < el.GetNP(); k++)
pglob(j) += shape(k) * pointmat(k,j);
}
grid[i] = pglob;
}
}
bool has_pos = 0, has_neg = 0;
GetMultiValues( sol, ei, -1, n3,
&locgrid[0](0), &locgrid[1](0)-&locgrid[0](0),
&grid[0](0), &grid[1](0)-&grid[0](0),
&trans[0](0), &trans[1](0)-&trans[0](0),
&val1[0], sol->components);
2009-01-13 04:40:13 +05:00
for (int i = 0; i < cnt_valid; i++)
{
// GetValue (sol, ei, &locgrid[i](0), &grid[i](0), &trans[i](0), comp, val[i]);
2009-01-13 04:40:13 +05:00
// val[i] -= minval;
val1[sol->components*i+comp-1] -= minval;
2009-01-13 04:40:13 +05:00
// if (vsol)
// GetValues (vsol, ei, &locgrid[i](0), &grid[i](0), &trans[i](0), &grads[i](0));
// grads[i] *= -1;
if (val1[i*sol->components+comp-1] > 0)
2009-01-13 04:40:13 +05:00
has_pos = 1;
else
has_neg = 1;
// if (val[i] > 0)
// has_pos = 1;
// else
// has_neg = 1;
2009-01-13 04:40:13 +05:00
}
if (!has_pos || !has_neg) continue;
if (vsol)
{
GetMultiValues(vsol, ei, -1, n3,
&locgrid[0](0), &locgrid[1](0)-&locgrid[0](0),
&grid[0](0), &grid[1](0)-&grid[0](0),
&trans[0](0), &trans[1](0)-&trans[0](0),
&grads1[0](0), vsol->components);
// for (int i = 0; i < cnt_valid; i++)
// grads1[i*sol->components+comp-1] *= -1;
for (int i = 0; i < cnt_valid; i++)
grads1[i] *= -1;
}
2009-01-13 04:40:13 +05:00
for (int ix = 0; ix < n; ix++)
for (int iy = 0; iy < n; iy++)
for (int iz = 0; iz < n; iz++)
{
int base = iz + (n+1)*iy + (n+1)*(n+1)*ix;
int pi[8] =
{ base, base+(n+1)*(n+1), base+(n+1)*(n+1)+(n+1), base+(n+1),
base+1, base+(n+1)*(n+1)+1, base+(n+1)*(n+1)+(n+1)+1, base+(n+1)+1 };
for (int j = 0; j < 8; j++)
pi[j] = compress[pi[j]];
int tets[6][4] =
{ { 1, 2, 4, 5 },
{ 4, 5, 2, 8 },
{ 2, 8, 5, 6 },
{ 2, 3, 4, 8 },
{ 2, 3, 8, 6 },
{ 3, 8, 6, 7 } };
for (int ii = 0; ii < 6; ii++)
{
int teti[4];
for (int k = 0; k < 4; k++)
teti[k] = pi[tets[ii][k]-1];
bool is_valid = 1;
for (int j = 0; j < 4; j++)
if (teti[j] == -1) is_valid = 0;
if (!is_valid) continue;
// for (int j = 0; j < 4; j++)
// nodevali[j] = val[teti[j]];
2009-01-13 04:40:13 +05:00
for (int j = 0; j < 4; j++)
nodevali[j] = val1[sol->components*teti[j]+comp-1];
2009-01-13 04:40:13 +05:00
cntce = 0;
for (int j = 0; j < 6; j++)
{
int lpi1 = edgei[j][0];
int lpi2 = edgei[j][1];
if ( (nodevali[lpi1] > 0) !=
(nodevali[lpi2] > 0) )
{
Point<3> p1 = grid[teti[lpi1]];
Point<3> p2 = grid[teti[lpi2]];
edgelam[j] = nodevali[lpi2] / (nodevali[lpi2] - nodevali[lpi1]);
edgep[j] = grid[teti[lpi1]] + (1-edgelam[j]) * (grid[teti[lpi2]]-grid[teti[lpi1]]);
// normp[j] = grads[teti[lpi1]] + (1-edgelam[j]) * (grads[teti[lpi2]]-grads[teti[lpi1]]);
normp[j] = grads1[teti[lpi1]] + (1-edgelam[j]) * (grads1[teti[lpi2]]-grads1[teti[lpi1]]);
// normp[j] = grads1[sol->components*teti[lpi1]+comp-1] + (1-edgelam[j]) * (grads1[sol->components*teti[lpi2]+comp-1]-grads1[sol->components*teti[lpi1]+comp-1]);
2009-01-13 04:40:13 +05:00
cntce++;
cpe3 = cpe2;
cpe2 = cpe1;
cpe1 = j;
if (cntce >= 3)
{
if (!vsol)
{
Point<3> points[3];
points[0] = edgep[cpe1];
points[1] = edgep[cpe2];
points[2] = edgep[cpe3];
Vec<3> normal = Cross (points[2]-points[0], points[1]-points[0]);
2009-07-20 14:36:36 +06:00
if ( ( (normal * (p2-p1)) > 0 ) == ( nodevali[lpi1] < 0) )
2009-01-13 04:40:13 +05:00
normal *= -1;
glNormal3dv (normal);
glVertex3dv (points[0]);
glVertex3dv (points[1]);
glVertex3dv (points[2]);
}
else
{
glNormal3dv (normp[cpe1]);
glVertex3dv (edgep[cpe1]);
glNormal3dv (normp[cpe2]);
glVertex3dv (edgep[cpe2]);
glNormal3dv (normp[cpe3]);
glVertex3dv (edgep[cpe3]);
}
}
}
}
}
}
}
}
glEnd();
}
2009-08-05 20:20:30 +06:00
void VisualSceneSolution :: DrawTrigSurfaceVectors(const Array< Point<3> > & lp,
const Point<3> & pmin, const Point<3> & pmax,
2009-01-13 04:40:13 +05:00
const int sei, const SolData * vsol)
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
int dir,dir1,dir2;
double s,t;
Vec<3> n = Cross (lp[1]-lp[0], lp[2]-lp[0]);
Vec<3> na (fabs (n(0)), fabs(n(1)), fabs(n(2)));
if (na(0) > na(1) && na(0) > na(2))
dir = 1;
else if (na(1) > na(2))
dir = 2;
else
dir = 3;
dir1 = (dir % 3) + 1;
dir2 = (dir1 % 3) + 1;
Point<2> p2d[3];
int k;
for (k = 0; k < 3; k++)
{
p2d[k] = Point<2> ((lp[k](dir1-1) - pmin(dir1-1)) / (2*rad),
(lp[k](dir2-1) - pmin(dir2-1)) / (2*rad));
}
double minx2d, maxx2d, miny2d, maxy2d;
minx2d = maxx2d = p2d[0](0);
miny2d = maxy2d = p2d[0](1);
for (k = 1; k < 3; k++)
{
minx2d = min2 (minx2d, p2d[k](0));
maxx2d = max2 (maxx2d, p2d[k](0));
miny2d = min2 (miny2d, p2d[k](1));
maxy2d = max2 (maxy2d, p2d[k](1));
}
double mat11 = p2d[1](0) - p2d[0](0);
double mat21 = p2d[1](1) - p2d[0](1);
double mat12 = p2d[2](0) - p2d[0](0);
double mat22 = p2d[2](1) - p2d[0](1);
double det = mat11*mat22-mat21*mat12;
double inv11 = mat22/det;
double inv21 = -mat21/det;
double inv12 = -mat12/det;
double inv22 = mat11/det;
// cout << "drawsurfacevectors. xoffset = " << xoffset << ", yoffset = ";
// cout << yoffset << endl;
for (s = xoffset/gridsize; s <= 1+xoffset/gridsize; s += 1.0 / gridsize)
if (s >= minx2d && s <= maxx2d)
for (t = yoffset/gridsize; t <= 1+yoffset/gridsize; t += 1.0 / gridsize)
if (t >= miny2d && t <= maxy2d)
{
double lam1 = inv11 * (s - p2d[0](0)) + inv12 * (t-p2d[0](1));
double lam2 = inv21 * (s - p2d[0](0)) + inv22 * (t-p2d[0](1));
if (lam1 >= 0 && lam2 >= 0 && lam1+lam2 <= 1)
{
Point<3> cp;
for (k = 0; k < 3; k++)
cp(k) = lp[0](k) +
lam1 * (lp[1](k)-lp[0](k)) +
lam2 * (lp[2](k)-lp[0](k));
2015-11-23 17:12:38 +05:00
Point<2> xref(lam1, lam2);
if (mesh->GetCurvedElements().IsHighOrder())
mesh->GetCurvedElements().
CalcSurfaceTransformation (xref, sei, cp);
2009-01-13 04:40:13 +05:00
Vec<3> v;
double values[6];
2009-08-05 20:20:30 +06:00
bool drawelem =
2012-04-27 00:22:49 +06:00
GetSurfValues (vsol, sei, -1, lam1, lam2, values);
2009-01-13 04:40:13 +05:00
if (!vsol->iscomplex)
for (k = 0; k < 3; k++)
v(k) = values[k];
else
{
if (!imag_part)
for (k = 0; k < 3; k++)
v(k) = values[2*k];
else
for (k = 0; k < 3; k++)
v(k) = values[2*k+1];
}
if (mesh->GetDimension() == 2)
if ( (!vsol->iscomplex && vsol->components != 3) ||
(vsol->iscomplex && vsol->components != 6) )
v(2) = 0;
double val = v.Length();
2009-08-05 20:20:30 +06:00
SetOpenGlColor (val); // (val, minval, maxval, logscale); // change JS
2009-01-13 04:40:13 +05:00
if (val > 1e-10 * maxval)
v *= (rad / val / gridsize * 0.5);
else
drawelem = 0;
if ( drawelem )
DrawCone (cp, cp+4*v, 0.8*rad / gridsize);
}
}
}
void VisualSceneSolution :: DrawSurfaceVectors ()
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
SurfaceElementIndex sei;
const SolData * vsol = NULL;
// bool drawelem;
if (vecfunction != -1)
vsol = soldata[vecfunction];
if (mesh->GetTimeStamp () > solutiontimestamp)
vsol = NULL;
if (!vsol) return;
Point<3> pmin = center - Vec3d (rad, rad, rad);
Point<3> pmax = center - Vec3d (rad, rad, rad);
2009-08-05 20:20:30 +06:00
// glColor3d (1.0, 1.0, 1.0);
2009-01-13 04:40:13 +05:00
// glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
if (vsol->draw_surface && showsurfacesolution)
{
int nse = mesh->GetNSE();
for (sei = 0; sei < nse; sei++)
{
const Element2d & el = (*mesh)[sei];
if (el.GetType() == TRIG || el.GetType() == TRIG6)
{
2009-01-25 17:35:25 +05:00
Array< Point<3> > lp(3);
2009-08-05 20:20:30 +06:00
2009-01-13 04:40:13 +05:00
lp[0] = mesh->Point(el[2]);
lp[1] = mesh->Point(el[0]);
lp[2] = mesh->Point(el[1]);
DrawTrigSurfaceVectors(lp,pmin,pmax,sei,vsol);
/*
Vec<3> n = Cross (lp[1]-lp[0], lp[2]-lp[0]);
Vec<3> na (fabs (n(0)), fabs(n(1)), fabs(n(2)));
if (na(0) > na(1) && na(0) > na(2))
dir = 1;
else if (na(1) > na(2))
dir = 2;
else
dir = 3;
dir1 = (dir % 3) + 1;
dir2 = (dir1 % 3) + 1;
for (k = 0; k < 3; k++)
{
p2d[k] = Point<2> ((lp[k](dir1-1) - pmin(dir1-1)) / (2*rad),
(lp[k](dir2-1) - pmin(dir2-1)) / (2*rad));
}
double minx2d, maxx2d, miny2d, maxy2d;
minx2d = maxx2d = p2d[0](0);
miny2d = maxy2d = p2d[0](1);
for (k = 1; k < 3; k++)
{
minx2d = min2 (minx2d, p2d[k](0));
maxx2d = max2 (maxx2d, p2d[k](0));
miny2d = min2 (miny2d, p2d[k](1));
maxy2d = max2 (maxy2d, p2d[k](1));
}
double mat11 = p2d[1](0) - p2d[0](0);
double mat21 = p2d[1](1) - p2d[0](1);
double mat12 = p2d[2](0) - p2d[0](0);
double mat22 = p2d[2](1) - p2d[0](1);
double det = mat11*mat22-mat21*mat12;
double inv11 = mat22/det;
double inv21 = -mat21/det;
double inv12 = -mat12/det;
double inv22 = mat11/det;
// cout << "drawsurfacevectors. xoffset = " << xoffset << ", yoffset = ";
// cout << yoffset << endl;
for (s = xoffset/gridsize; s <= 1+xoffset/gridsize; s += 1.0 / gridsize)
if (s >= minx2d && s <= maxx2d)
for (t = yoffset/gridsize; t <= 1+yoffset/gridsize; t += 1.0 / gridsize)
if (t >= miny2d && t <= maxy2d)
{
double lam1 = inv11 * (s - p2d[0](0)) + inv12 * (t-p2d[0](1));
double lam2 = inv21 * (s - p2d[0](0)) + inv22 * (t-p2d[0](1));
if (lam1 >= 0 && lam2 >= 0 && lam1+lam2 <= 1)
{
Point<3> cp;
for (k = 0; k < 3; k++)
cp(k) = lp[0](k) +
lam1 * (lp[1](k)-lp[0](k)) +
lam2 * (lp[2](k)-lp[0](k));
Vec<3> v;
double values[6];
drawelem = GetSurfValues (vsol, sei, lam1, lam2, values);
if (!vsol->iscomplex)
for (k = 0; k < 3; k++)
v(k) = values[k];
else
{
if (!imag_part)
for (k = 0; k < 3; k++)
v(k) = values[2*k];
else
for (k = 0; k < 3; k++)
v(k) = values[2*k+1];
}
if (mesh->GetDimension() == 2)
if ( (!vsol->iscomplex && vsol->components != 3) ||
(vsol->iscomplex && vsol->components != 6) )
v(2) = 0;
double val = v.Length();
SetOpenGlColor (val, minval, maxval, logscale);
if (val > 1e-10 * maxval)
v *= (rad / val / gridsize * 0.5);
else drawelem = 0;
// "drawelem": added 07.04.2004 (FB)
if ( drawelem ) DrawCone (cp, cp+4*v, 0.8*rad / gridsize);
}
}
*/
}
else if (el.GetType() == QUAD)
{
2009-04-20 03:15:26 +06:00
/*
2011-01-11 01:18:01 +05:00
Array < Point<3> > lp(3);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
lp[0] = mesh->Point(el[0]);
lp[1] = mesh->Point(el[1]);
lp[2] = mesh->Point(el[2]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
DrawTrigSurfaceVectors(lp,pmin,pmax,sei,vsol);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
lp[0] = mesh->Point(el[0]);
lp[1] = mesh->Point(el[2]);
lp[2] = mesh->Point(el[3]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
DrawTrigSurfaceVectors(lp,pmin,pmax,sei,vsol);
2009-04-20 03:15:26 +06:00
*/
Point<3> lp[4];
Point<2> p2d[4];
for (int k = 0; k < 4; k++)
2009-01-13 04:40:13 +05:00
lp[k] = mesh->Point (el[k]);
2009-04-20 03:15:26 +06:00
Vec<3> n = Cross (lp[1]-lp[0], lp[2]-lp[0]);
Vec<3> na (fabs (n(0)), fabs(n(1)), fabs(n(2)));
int dir, dir1, dir2;
if (na(0) > na(1) && na(0) > na(2))
2009-01-13 04:40:13 +05:00
dir = 1;
2009-04-20 03:15:26 +06:00
else if (na(1) > na(2))
2009-01-13 04:40:13 +05:00
dir = 2;
2009-04-20 03:15:26 +06:00
else
2009-01-13 04:40:13 +05:00
dir = 3;
2009-04-20 03:15:26 +06:00
dir1 = (dir % 3) + 1;
dir2 = (dir1 % 3) + 1;
for (int k = 0; k < 4; k++)
2009-01-13 04:40:13 +05:00
{
2009-04-20 03:15:26 +06:00
p2d[k] = Point<2> ((lp[k](dir1-1) - pmin(dir1-1)) / (2*rad),
(lp[k](dir2-1) - pmin(dir2-1)) / (2*rad));
2009-01-13 04:40:13 +05:00
}
2009-04-20 03:15:26 +06:00
double minx2d, maxx2d, miny2d, maxy2d;
minx2d = maxx2d = p2d[0](0);
miny2d = maxy2d = p2d[0](1);
for (int k = 1; k < 4; k++)
2009-01-13 04:40:13 +05:00
{
2009-04-20 03:15:26 +06:00
minx2d = min2 (minx2d, p2d[k](0));
maxx2d = max2 (maxx2d, p2d[k](0));
miny2d = min2 (miny2d, p2d[k](1));
maxy2d = max2 (maxy2d, p2d[k](1));
2009-01-13 04:40:13 +05:00
}
2009-04-20 03:15:26 +06:00
for (double s = xoffset/gridsize; s <= 1+xoffset/gridsize; s += 1.0 / gridsize)
2009-01-13 04:40:13 +05:00
if (s >= minx2d && s <= maxx2d)
2009-04-20 03:15:26 +06:00
for (double t = yoffset/gridsize; t <= 1+yoffset/gridsize; t += 1.0 / gridsize)
if (t >= miny2d && t <= maxy2d)
{
double lami[3];
Point3d p3d(2*rad*s+pmin(0), 2*rad*t+pmin(1),0);
if (mesh->PointContainedIn2DElement (p3d, lami, sei+1))
{
Point<3> cp = p3d;
double lam1 = lami[0];
double lam2 = lami[1];
2009-01-13 04:40:13 +05:00
2009-04-20 03:15:26 +06:00
//for (k = 0; k < 3; k++)
//cp(k) = lp[0](k) +
//lam1 * (lp[1](k)-lp[0](k)) +
//lam2 * (lp[2](k)-lp[0](k));
Vec<3> v;
double values[6];
2012-04-27 00:22:49 +06:00
bool drawelem = GetSurfValues (vsol, sei, -1, lam1, lam2, values);
2009-04-20 03:15:26 +06:00
(*testout) << "sei " << sei << " lam1 " << lam1 << " lam2 " << lam2 << " drawelem " << drawelem << endl;
if (!vsol->iscomplex)
for (int k = 0; k < 3; k++)
v(k) = values[k];
else
{
if (!imag_part)
for (int k = 0; k < 3; k++)
v(k) = values[2*k];
else
for (int k = 0; k < 3; k++)
v(k) = values[2*k+1];
}
if (mesh->GetDimension() == 2)
if ( (!vsol->iscomplex && vsol->components != 3) ||
(vsol->iscomplex && vsol->components != 6) )
v(2) = 0;
double val = v.Length();
2009-08-05 20:20:30 +06:00
SetOpenGlColor (val); // , minval, maxval, logscale); july 09
2009-04-20 03:15:26 +06:00
(*testout) << "v " << v << endl;
if (val > 1e-10 * maxval)
v *= (rad / val / gridsize * 0.5);
(*testout) << "v " << v << endl;
if ( drawelem )
{
DrawCone (cp, cp+4*v, 0.8*rad / gridsize);
(*testout) << "cp " << cp << " rad " << rad << " gridsize " << gridsize << endl;
}
}
}
2009-01-13 04:40:13 +05:00
}
}
}
}
void VisualSceneSolution ::
DrawIsoLines (const Point<3> & p1,
const Point<3> & p2,
const Point<3> & p3,
double val1, double val2, double val3)
{
DrawIsoLines2 (p1, p2, p1, p3, val1, val2, val1, val3); // , minval, maxval, n);
DrawIsoLines2 (p2, p1, p2, p3, val2, val1, val2, val3); // , minval, maxval, n);
DrawIsoLines2 (p3, p1, p3, p2, val3, val1, val3, val2); // , minval, maxval, n);
}
void VisualSceneSolution ::
DrawIsoLines2 (const Point<3> & hp1,
const Point<3> & hp2,
const Point<3> & hp3,
const Point<3> & hp4,
double val1, double val2, double val3, double val4)
{
int n = numisolines;
Point<3> p1, p2, p3, p4;
if (val1 < val2)
{
p1 = hp1; p2 = hp2;
}
else
{
p1 = hp2; p2 = hp1;
swap (val1, val2);
}
if (val3 < val4)
{
p3 = hp3; p4 = hp4;
}
else
{
p3 = hp4; p4 = hp3;
swap (val3, val4);
}
val2 += 1e-10;
val4 += 1e-10;
double fac = (maxval-minval) / n;
double idelta1 = 1.0 / (val2 - val1);
double idelta2 = 1.0 / (val4 - val3);
int mini = int ((max2 (val1, val3) - minval) / fac);
int maxi = int ((min2 (val2, val4) - minval) / fac);
if (mini < 0) mini = 0;
if (maxi > n-1) maxi = n-1;
for (int i = mini; i <= maxi; i++)
{
double val = minval + i * fac;
double lam1 = (val - val1) * idelta1;
double lam2 = (val - val3) * idelta2;
if (lam1 >= 0 && lam1 <= 1 && lam2 >= 0 && lam2 <= 1)
{
Point<3> lp1 = p1 + lam1 * (p2-p1);
Point<3> lp2 = p3 + lam2 * (p4-p3);
glVertex3dv (lp1 );
glVertex3dv (lp2 );
// glVertex3dv (lp2 ); // better ?
// glVertex3dv (lp1 );
}
}
}
void VisualSceneSolution ::
GetMinMax (int funcnr, int comp, double & minv, double & maxv) const
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2013-07-10 02:52:59 +06:00
static int timer1 = NgProfiler::CreateTimer ("getminmax, vol");
static int timer2 = NgProfiler::CreateTimer ("getminmax, surf");
2011-07-15 22:26:32 +06:00
#ifdef PARALLEL
if (id == 0)
{
MyMPI_SendCmd ("redraw");
MyMPI_SendCmd ("getminmax");
}
MyMPI_Bcast (funcnr);
MyMPI_Bcast (comp);
#endif
2014-01-07 16:42:30 +06:00
// double val;
2012-06-13 15:07:11 +06:00
// bool considerElem;
2009-01-13 04:40:13 +05:00
bool hasit = false;
#ifdef max
#undef max
#endif
2013-07-10 20:51:25 +06:00
minv = numeric_limits<double>::max();
maxv = -numeric_limits<double>::max();
2012-06-13 15:07:11 +06:00
if ((ntasks == 1) || (id > 0))
if (funcnr != -1)
2014-01-07 16:42:30 +06:00
{
const SolData * sol = soldata[funcnr];
2013-07-10 02:52:59 +06:00
2014-01-07 16:42:30 +06:00
if (sol->draw_volume)
{
NgProfiler::RegionTimer reg1 (timer1);
int ne = mesh->GetNE();
2016-02-22 22:43:51 +05:00
mutex min_mutex;
mutex max_mutex;
ParallelFor(0, ne, [&] (int first, int next)
2014-01-07 16:42:30 +06:00
{
2016-02-22 22:43:51 +05:00
double minv_local = numeric_limits<double>::max();
double maxv_local = -numeric_limits<double>::max();
for (int i=first; i<next; i++)
{
double val;
bool considerElem = GetValue (sol, i, 0.333, 0.333, 0.333, comp, val);
if (considerElem)
{
if (val > maxv_local) maxv_local = val;
if (val < minv_local) minv_local = val;
hasit = true;
}
}
if(minv_local < minv)
2014-01-07 16:42:30 +06:00
{
2016-02-22 22:43:51 +05:00
lock_guard<mutex> guard(min_mutex);
2016-11-01 15:47:49 +05:00
if(minv_local < minv)
minv = minv_local;
2014-01-07 16:42:30 +06:00
}
2016-02-22 22:43:51 +05:00
if(maxv_local > maxv)
{
lock_guard<mutex> guard(max_mutex);
2016-11-01 15:47:49 +05:00
if(maxv_local > maxv)
maxv = maxv_local;
2016-02-22 22:43:51 +05:00
}
});
2014-01-07 16:42:30 +06:00
}
if (sol->draw_surface)
{
NgProfiler::RegionTimer reg2 (timer2);
int nse = mesh->GetNSE();
for (int i = 0; i < nse; i++)
{
ELEMENT_TYPE type = mesh->SurfaceElement(i+1).GetType();
double val;
bool considerElem = (type == QUAD)
? GetSurfValue (sol, i, -1, 0.5, 0.5, comp, val)
: GetSurfValue (sol, i, -1, 0.3333333, 0.3333333, comp, val);
if (considerElem)
2013-07-10 13:07:29 +06:00
{
2014-01-07 16:42:30 +06:00
if (val > maxv) maxv = val;
if (val < minv) minv = val;
2013-07-10 13:07:29 +06:00
hasit = true;
}
2014-01-07 16:42:30 +06:00
}
}
}
2009-01-13 04:40:13 +05:00
if (minv == maxv) maxv = minv+1e-6;
2014-01-07 16:42:30 +06:00
if (!hasit) { minv = 0; maxv = 1; }
2011-07-15 22:26:32 +06:00
#ifdef PARALLEL
2011-07-17 05:13:26 +06:00
if ((ntasks > 1) && (id == 0))
2011-07-15 22:26:32 +06:00
{
minv = 1e99;
maxv = -1e99;
}
double hmin, hmax;
MPI_Reduce (&minv, &hmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
MPI_Reduce (&maxv, &hmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
minv = hmin;
maxv = hmax;
#endif
2009-01-13 04:40:13 +05:00
}
bool VisualSceneSolution ::
GetValues (const SolData * data, ElementIndex elnr,
double lam1, double lam2, double lam3,
double * values) const
{
2009-07-20 14:36:36 +06:00
bool ok = false;
2009-01-13 04:40:13 +05:00
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
ok = data->solclass->GetValue (elnr, lam1, lam2, lam3, values);
break;
}
default:
{
for (int i = 0; i < data->components; i++)
ok = GetValue (data, elnr, lam1, lam2, lam3, i+1, values[i]);
}
}
return ok;
}
bool VisualSceneSolution ::
GetValues (const SolData * data, ElementIndex elnr,
const double xref[], const double x[], const double dxdxref[],
double * values) const
{
2009-07-20 14:36:36 +06:00
bool ok = false;
2009-01-13 04:40:13 +05:00
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
ok = data->solclass->GetValue (elnr, xref, x, dxdxref, values);
break;
}
default:
{
for (int i = 0; i < data->components; i++)
ok = GetValue (data, elnr, xref[0], xref[1], xref[2], i+1, values[i]);
}
}
return ok;
}
bool VisualSceneSolution ::
GetValue (const SolData * data, ElementIndex elnr,
const double xref[], const double x[], const double dxdxref[],
int comp, double & val) const
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2009-01-13 04:40:13 +05:00
double lam1 = xref[0];
double lam2 = xref[1];
double lam3 = xref[2];
val = 0;
bool ok = 0;
if (comp == 0)
{
ArrayMem<double,20> values(data->components);
ok = GetValues (data, elnr, xref, x, dxdxref, &values[0]);
2011-01-11 01:18:01 +05:00
val = ExtractValue (data, 0, &values[0]);
return ok;
2009-01-13 04:40:13 +05:00
}
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
double values[20];
ok = data->solclass->GetValue (elnr, xref, x, dxdxref, values);
val = values[comp-1];
return ok;
}
case SOL_NODAL:
{
const Element & el = (*mesh)[elnr];
2009-07-20 14:36:36 +06:00
double lami[8] = { 0.0 };
int np = 0;
2009-01-13 04:40:13 +05:00
switch (el.GetType())
{
case TET:
case TET10:
{
lami[1] = lam1;
lami[2] = lam2;
lami[3] = lam3;
lami[0] = 1-lam1-lam2-lam3;
np = 4;
break;
}
case PRISM:
case PRISM12:
{
lami[0] = (1-lam3) * (1-lam1-lam2);
lami[1] = (1-lam3) * lam1;
lami[2] = (1-lam3) * lam2;
lami[3] = (lam3) * (1-lam1-lam2);
lami[4] = (lam3) * lam1;
lami[5] = (lam3) * lam2;
np = 6;
break;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implementd 23523" << endl;
2009-01-13 04:40:13 +05:00
}
2009-07-20 14:36:36 +06:00
for (int i = 0; i < np; i++)
2009-01-13 04:40:13 +05:00
val += lami[i] * data->data[(el[i]-1) * data->dist + comp-1];
return 1;
}
case SOL_ELEMENT:
{
val = data->data[elnr * data->dist + comp-1];
return 1;
}
case SOL_SURFACE_ELEMENT:
return 0;
case SOL_NONCONTINUOUS:
{
const Element & el = (*mesh)[elnr];
2009-07-20 14:36:36 +06:00
double lami[8] = { 0.0 };
int np = 0;
2009-01-13 04:40:13 +05:00
switch (el.GetType())
{
case TET:
case TET10:
{
lami[1] = lam1;
lami[2] = lam2;
lami[3] = lam3;
lami[0] = 1-lam1-lam2-lam3;
np = 4;
break;
}
case PRISM:
case PRISM12:
{
lami[0] = (1-lam3) * (1-lam1-lam2);
lami[1] = (1-lam3) * lam1;
lami[2] = (1-lam3) * lam2;
lami[3] = (lam3) * (1-lam1-lam2);
lami[4] = (lam3) * lam1;
lami[5] = (lam3) * lam2;
np = 6;
break;
}
case PYRAMID:
{
if (lam3 > 1-1e-5)
{
lami[0] = lami[1] = lami[2] = lami[3] = 0;
lami[4] = 1;
}
else
{
double x0 = lam1 / (1-lam3);
double y0 = lam2 / (1-lam3);
lami[0] = (1-x0) * (1-y0) * (1-lam3);
lami[1] = ( x0) * (1-y0) * (1-lam3);
lami[2] = ( x0) * ( y0) * (1-lam3);
lami[3] = (1-x0) * ( y0) * (1-lam3);
lami[4] = lam3;
np = 5;
}
break;
}
default:
np = 0;
}
int base;
if (data->order == 1)
base = 6 * elnr;
else
base = 10 * elnr;
2009-07-20 14:36:36 +06:00
for (int i = 0; i < np; i++)
2009-01-13 04:40:13 +05:00
val += lami[i] * data->data[(base+i) * data->dist + comp-1];
return 1;
}
case SOL_MARKED_ELEMENTS:
{
val = (*mesh)[elnr].TestRefinementFlag();
return 1;
}
case SOL_ELEMENT_ORDER:
{
val = (*mesh)[elnr].GetOrder();
return 1;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not handled 7234" << endl;
2009-01-13 04:40:13 +05:00
}
return 0;
}
bool VisualSceneSolution ::
GetValue (const SolData * data, ElementIndex elnr,
double lam1, double lam2, double lam3,
int comp, double & val) const
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2009-01-13 04:40:13 +05:00
val = 0;
bool ok = 0;
if (comp == 0)
{
ArrayMem<double,20> values(data->components);
ok = GetValues (data, elnr, lam1, lam2, lam3, &values[0]);
2011-01-11 01:18:01 +05:00
val = ExtractValue (data, 0, &values[0]);
return ok;
2009-01-13 04:40:13 +05:00
}
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
2014-04-28 13:09:39 +06:00
val = 0.0;
2009-01-13 04:40:13 +05:00
double values[20];
2014-04-28 13:09:39 +06:00
ok = data->solclass->GetValue (elnr, lam1, lam2, lam3, values);
2009-01-13 04:40:13 +05:00
val = values[comp-1];
return ok;
}
case SOL_NODAL:
{
const Element & el = (*mesh)[elnr];
2009-07-20 14:36:36 +06:00
double lami[8] = { 0.0 };
int np = 0;
2009-01-13 04:40:13 +05:00
switch (el.GetType())
{
case TET:
case TET10:
{
lami[1] = lam1;
lami[2] = lam2;
lami[3] = lam3;
lami[0] = 1-lam1-lam2-lam3;
np = 4;
break;
}
case PRISM:
case PRISM12:
{
lami[0] = (1-lam3) * (1-lam1-lam2);
lami[1] = (1-lam3) * lam1;
lami[2] = (1-lam3) * lam2;
lami[3] = (lam3) * (1-lam1-lam2);
lami[4] = (lam3) * lam1;
lami[5] = (lam3) * lam2;
np = 6;
break;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implemented 234324" << endl;
2009-01-13 04:40:13 +05:00
}
2009-07-20 14:36:36 +06:00
for (int i = 0; i < np; i++)
2009-01-13 04:40:13 +05:00
val += lami[i] * data->data[(el[i]-1) * data->dist + comp-1];
return 1;
}
case SOL_ELEMENT:
{
val = data->data[elnr * data->dist + comp-1];
return 1;
}
case SOL_SURFACE_ELEMENT:
return 0;
case SOL_NONCONTINUOUS:
{
const Element & el = (*mesh)[elnr];
2009-07-20 14:36:36 +06:00
double lami[8] = { 0.0 };
int np = 0;
2009-01-13 04:40:13 +05:00
switch (el.GetType())
{
case TET:
case TET10:
{
lami[1] = lam1;
lami[2] = lam2;
lami[3] = lam3;
lami[0] = 1-lam1-lam2-lam3;
np = 4;
break;
}
case PRISM:
case PRISM12:
{
lami[0] = (1-lam3) * (1-lam1-lam2);
lami[1] = (1-lam3) * lam1;
lami[2] = (1-lam3) * lam2;
lami[3] = (lam3) * (1-lam1-lam2);
lami[4] = (lam3) * lam1;
lami[5] = (lam3) * lam2;
np = 6;
break;
}
case PYRAMID:
{
if (lam3 > 1-1e-5)
{
lami[0] = lami[1] = lami[2] = lami[3] = 0;
lami[4] = 1;
}
else
{
double x0 = lam1 / (1-lam3);
double y0 = lam2 / (1-lam3);
lami[0] = (1-x0) * (1-y0) * (1-lam3);
lami[1] = ( x0) * (1-y0) * (1-lam3);
lami[2] = ( x0) * ( y0) * (1-lam3);
lami[3] = (1-x0) * ( y0) * (1-lam3);
lami[4] = lam3;
np = 5;
}
break;
}
default:
np = 0;
}
int base;
if (data->order == 1)
base = 6 * elnr;
else
base = 10 * elnr;
2009-07-20 14:36:36 +06:00
for (int i = 0; i < np; i++)
2009-01-13 04:40:13 +05:00
val += lami[i] * data->data[(base+i) * data->dist + comp-1];
return 1;
}
case SOL_MARKED_ELEMENTS:
{
val = (*mesh)[elnr].TestRefinementFlag();
return 1;
}
case SOL_ELEMENT_ORDER:
{
val = (*mesh)[elnr].GetOrder();
return 1;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implemented 234234" << endl;
2009-01-13 04:40:13 +05:00
}
return 0;
}
bool VisualSceneSolution ::
GetValueComplex (const SolData * data, ElementIndex elnr,
double lam1, double lam2, double lam3,
2009-08-29 15:29:09 +06:00
int comp, complex<double> & val) const
2009-01-13 04:40:13 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-08-29 15:29:09 +06:00
val = 0.0;
2009-01-13 04:40:13 +05:00
bool ok = 0;
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
double values[20];
ok = data->solclass->GetValue (elnr, lam1, lam2, lam3, values);
2009-08-29 15:29:09 +06:00
val = complex<double> (values[comp-1], values[comp]);
2009-01-13 04:40:13 +05:00
return ok;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not handled 234234" << endl;
2009-01-13 04:40:13 +05:00
}
return 0;
}
bool VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetMultiValues (const SolData * data, ElementIndex elnr, int facetnr, int npt,
const double * xref, int sxref,
const double * x, int sx,
const double * dxdxref, int sdxdxref,
double * val, int sval) const
{
bool drawelem = false;
if (data->soltype == SOL_VIRTUALFUNCTION)
2012-04-27 00:22:49 +06:00
drawelem = data->solclass->GetMultiValue(elnr, facetnr, npt, xref, sxref, x, sx, dxdxref, sdxdxref, val, sval);
else
for (int i = 0; i < npt; i++)
drawelem = GetValues (data, elnr, xref+i*sxref, x+i*sx, dxdxref+i*sdxdxref, val+i*sval);
return drawelem;
}
2009-01-13 04:40:13 +05:00
bool VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetSurfValues (const SolData * data, SurfaceElementIndex selnr, int facetnr,
2009-01-13 04:40:13 +05:00
double lam1, double lam2,
double * values) const
{
2009-07-20 14:36:36 +06:00
bool ok = false;
2009-01-13 04:40:13 +05:00
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
2012-04-27 00:22:49 +06:00
ok = data->solclass->GetSurfValue (selnr, facetnr, lam1, lam2, values);
2009-01-13 04:40:13 +05:00
// ok = 1;
// values[0] = 1.0;
break;
}
default:
{
for (int i = 0; i < data->components; i++)
2012-04-27 00:22:49 +06:00
ok = GetSurfValue (data, selnr, facetnr, lam1, lam2, i+1, values[i]);
2009-01-13 04:40:13 +05:00
}
}
return ok;
}
bool VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetSurfValues (const SolData * data, SurfaceElementIndex selnr, int facetnr,
2009-01-13 04:40:13 +05:00
const double xref[], const double x[], const double dxdxref[],
double * values) const
{
2009-07-20 14:36:36 +06:00
bool ok = false;
2009-01-13 04:40:13 +05:00
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
2012-04-27 00:22:49 +06:00
ok = data->solclass->GetSurfValue (selnr, facetnr, xref, x, dxdxref, values);
2009-01-13 04:40:13 +05:00
break;
}
default:
{
for (int i = 0; i < data->components; i++)
2012-04-27 00:22:49 +06:00
ok = GetSurfValue (data, selnr, facetnr, xref[0], xref[1], i+1, values[i]);
2009-01-13 04:40:13 +05:00
}
}
return ok;
}
2009-07-20 14:36:36 +06:00
bool VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetMultiSurfValues (const SolData * data, SurfaceElementIndex elnr, int facetnr, int npt,
2009-07-20 14:36:36 +06:00
const double * xref, int sxref,
const double * x, int sx,
const double * dxdxref, int sdxdxref,
double * val, int sval) const
{
bool drawelem = false;
if (data->soltype == SOL_VIRTUALFUNCTION)
2012-04-27 00:22:49 +06:00
drawelem = data->solclass->GetMultiSurfValue(elnr, facetnr, npt, xref, sxref, x, sx, dxdxref, sdxdxref, val, sval);
2009-07-20 14:36:36 +06:00
else
for (int i = 0; i < npt; i++)
2012-04-27 00:22:49 +06:00
drawelem = GetSurfValues (data, elnr, facetnr, xref+i*sxref, x+i*sx, dxdxref+i*sdxdxref, val+i*sval);
2009-07-20 14:36:36 +06:00
return drawelem;
}
double VisualSceneSolution :: ExtractValue (const SolData * data, int comp, double * values) const
{
double val = 0;
if (comp == 0)
{
switch (evalfunc)
{
case FUNC_ABS:
{
for (int ci = 0; ci < data->components; ci++)
val += sqr (values[ci]);
val = sqrt (val);
break;
}
case FUNC_ABS_TENSOR:
{
int d = 0;
switch (data->components)
{
case 1: d = 1; break;
case 3: d = 2; break;
case 6: d = 3; break;
}
for (int ci = 0; ci < d; ci++)
val += sqr (values[ci]);
for (int ci = d; ci < data->components; ci++)
val += 2*sqr (values[ci]);
val = sqrt (val);
break;
}
case FUNC_MISES:
{
int d = 0;
switch(data->components)
{
case 1: d = 1; break;
case 3: d = 2; break;
case 6: d = 3; break;
}
int ci;
double trace = 0.;
for (ci = 0; ci < d; ci++)
trace += 1./3.*(values[ci]);
for (ci = 0; ci < d; ci++)
val += sqr (values[ci]-trace);
for (ci = d; ci < data->components; ci++)
val += 2.*sqr (values[ci]);
val = sqrt (val);
break;
}
case FUNC_MAIN:
{
int d = 0;
switch(data->components)
{
case 1: d = 1; break;
case 3: d = 2; break;
case 6: d = 3; break;
}
Mat<3,3> m ;
Vec<3> ev;
int ci;
for (ci = 0; ci < d; ci++)
m(ci,ci) = (values[ci]);
m(0,1) = m(1,0) = values[3];
m(0,2) = m(2,0) = values[4];
m(1,2) = m(2,1) = values[5];
EigenValues (m, ev);
double help;
for (int i=0; i<d; i++)
{
for (int j=d-1; i<j; j--)
{
if ( abs(ev(j)) > abs(ev(j-1)) )
{
help = ev(j);
ev(j) = ev(j-1);
ev(j-1) = help;
}
}
}
val = (ev(0));
break;
}
}
return val;
}
return values[comp-1];
}
2009-08-24 06:03:40 +06:00
complex<double> VisualSceneSolution :: ExtractValueComplex (const SolData * data, int comp, double * values) const
{
if (!data->iscomplex)
2009-08-29 15:29:09 +06:00
return values[comp-1];
2009-08-24 06:03:40 +06:00
else
2009-08-29 15:29:09 +06:00
return complex<double> (values[comp-1], values[comp]);
2009-08-24 06:03:40 +06:00
}
2009-07-20 14:36:36 +06:00
2009-01-13 04:40:13 +05:00
bool VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetSurfValueComplex (const SolData * data, SurfaceElementIndex selnr, int facetnr,
2009-01-13 04:40:13 +05:00
double lam1, double lam2,
2009-08-29 15:29:09 +06:00
int comp, complex<double> & val) const
2009-01-13 04:40:13 +05:00
{
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
ArrayMem<double,20> values(data->components);
bool ok;
2012-04-27 00:22:49 +06:00
ok = data->solclass->GetSurfValue (selnr, facetnr, lam1, lam2, &values[0]);
2009-01-13 04:40:13 +05:00
if (ok)
{
if (!data->iscomplex)
2009-08-29 15:29:09 +06:00
val = values[comp-1];
2009-01-13 04:40:13 +05:00
else
2009-08-29 15:29:09 +06:00
val = complex<double> (values[comp-1], values[comp]);
2009-01-13 04:40:13 +05:00
}
return ok;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implementd 6565" << endl;
2009-01-13 04:40:13 +05:00
}
return 0;
}
bool VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetSurfValue (const SolData * data, SurfaceElementIndex selnr, int facetnr,
2009-01-13 04:40:13 +05:00
double lam1, double lam2,
int comp, double & val) const
{
bool ok;
if (comp == 0)
{
val = 0;
ArrayMem<double,20> values(data->components);
2012-04-27 00:22:49 +06:00
ok = GetSurfValues (data, selnr, facetnr, lam1, lam2, &values[0]);
2011-01-11 01:18:01 +05:00
val = ExtractValue (data, 0, &values[0]);
return ok;
2009-01-13 04:40:13 +05:00
}
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
ArrayMem<double,20> values(data->components);
bool ok;
2012-04-27 00:22:49 +06:00
ok = data->solclass->GetSurfValue (selnr, facetnr, lam1, lam2, &values[0]);
2009-01-13 04:40:13 +05:00
if (ok)
{
if (!data->iscomplex)
val = values[comp-1];
else
{
// cout << "time = " << time << ", cos = " << cos(time) << endl;
// old version: val = values[comp-1]*cos(3*time) + values[comp]*sin(3*time);
// SZ: Sept 06
if(comp%2==0)
val = values[comp-1]*cos(3*time) - values[comp-2]*sin(3*time);
else
val = values[comp-1]*cos(3*time) + values[comp]*sin(3*time);
}
}
return ok;
}
case SOL_NODAL:
{
2017-04-04 14:34:24 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2009-01-13 04:40:13 +05:00
const Element2d & el = (*mesh)[selnr];
double lami[8];
int np, i;
val = 0;
double lam3 = 1-lam1-lam2;
switch (el.GetType())
{
case TRIG:
/*
lami[0] = lam3;
lami[1] = lam1;
lami[2] = lam2;
*/
lami[0] = lam1;
lami[1] = lam2;
lami[2] = lam3;
np = 3;
break;
case TRIG6:
/*
lami[0] = lam3*(2*lam3-1);
lami[1] = lam1*(2*lam1-1);
lami[2] = lam2*(2*lam2-1);
*/
// hierarchical basis:
lami[0] = lam3;
lami[1] = lam1;
lami[2] = lam2;
lami[3] = 4*lam1*lam2;
lami[4] = 4*lam2*lam3;
lami[5] = 4*lam1*lam3;
np = 6;
break;
case QUAD:
case QUAD6:
lami[0] = (1-lam1)*(1-lam2);
lami[1] = lam1 * (1-lam2);
lami[2] = lam1 * lam2;
lami[3] = (1-lam1) * lam2;
np = 4;
break;
default:
np = 0;
}
for (i = 0; i < np; i++)
val += lami[i] * data->data[(el[i]-1) * data->dist + comp-1];
return 1;
}
case SOL_ELEMENT:
{
2017-04-04 14:34:24 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2009-01-13 04:40:13 +05:00
int el1, el2;
mesh->GetTopology().GetSurface2VolumeElement (selnr+1, el1, el2);
el1--;
val = data->data[el1 * data->dist+comp-1];
return 1;
}
case SOL_NONCONTINUOUS:
{
val = 0;
// ?????
return 0;
}
case SOL_SURFACE_ELEMENT:
{
val = data->data[selnr * data->dist + comp-1];
return 1;
}
case SOL_SURFACE_NONCONTINUOUS:
{
2017-04-04 14:34:24 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2009-01-13 04:40:13 +05:00
const Element2d & el = (*mesh)[selnr];
double lami[8];
2009-07-20 14:36:36 +06:00
int np = 0;
2009-01-13 04:40:13 +05:00
val = 0;
int order = data->order;
switch (order)
{
case 0:
return data->data[selnr * data->dist + comp-1];
case 1:
{
switch (el.GetType())
{
case TRIG:
case TRIG6:
{
lami[1] = lam1;
lami[2] = lam2;
lami[0] = 1-lam1-lam2;
np = 3;
break;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implementd 2342" << endl;
2009-01-13 04:40:13 +05:00
}
break;
}
case 2:
{
switch (el.GetType())
{
case TRIG:
{
lami[1] = lam1;
lami[2] = lam2;
lami[0] = 1-lam1-lam2;
np = 3;
break;
}
case TRIG6:
{
double lam3 = 1-lam1-lam2;
lami[1] = 2*lam1 * (lam1-0.5);
lami[2] = 2*lam2 * (lam2-0.5);
lami[0] = 2*lam3 * (lam3-0.5);
lami[3] = 4*lam1*lam2;
lami[4] = 4*lam2*lam3;
lami[5] = 4*lam1*lam3;
np = 6;
break;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implemented 8712" << endl;
2009-01-13 04:40:13 +05:00
}
break;
}
}
int base;
if (order == 1)
base = 4 * selnr;
else
base = 9 * selnr;
2009-07-20 14:36:36 +06:00
for (int i = 0; i < np; i++)
val += lami[i] * data->data[(base+i) * data->dist + comp-1];
2009-01-13 04:40:13 +05:00
return 1;
}
case SOL_MARKED_ELEMENTS:
{
2017-04-04 14:34:24 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2009-01-13 04:40:13 +05:00
val = (*mesh)[selnr].TestRefinementFlag();
return 1;
}
case SOL_ELEMENT_ORDER:
2017-04-04 14:34:24 +05:00
{
shared_ptr<Mesh> mesh = GetMesh();
2009-01-13 04:40:13 +05:00
val = (*mesh)[selnr].GetOrder();
return 1;
}
}
return 0;
}
bool VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetSurfValue (const SolData * data, SurfaceElementIndex selnr, int facetnr,
2009-01-13 04:40:13 +05:00
const double xref[], const double x[], const double dxdxref[],
int comp, double & val) const
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
double lam1 = xref[0], lam2 = xref[1];
bool ok;
if (comp == 0)
{
val = 0;
ArrayMem<double,20> values(data->components);
2012-04-27 00:22:49 +06:00
ok = GetSurfValues (data, selnr, facetnr, xref, x, dxdxref, &values[0]);
2011-01-11 01:18:01 +05:00
val = ExtractValue (data, 0, &values[0]);
return ok;
2009-01-13 04:40:13 +05:00
}
switch (data->soltype)
{
case SOL_VIRTUALFUNCTION:
{
ArrayMem<double,20> values(data->components);
bool ok;
// ok = data->solclass->GetSurfValue (selnr, lam1, lam2, &values[0]);
// cout << "data->solclass = " << flush << data->solclass << endl;
2012-04-27 00:22:49 +06:00
ok = data->solclass->GetSurfValue (selnr, facetnr, xref, x, dxdxref, &values[0]);
2009-01-13 04:40:13 +05:00
// ok = 1;
// values[0] = 1.0;
if (ok)
{
if (!data->iscomplex)
val = values[comp-1];
else
{
// cout << "time = " << time << ", cos = " << cos(time) << endl;
// old version: val = values[comp-1]*cos(3*time) + values[comp]*sin(3*time);
// SZ: Sept 06
if(comp%2==0)
val = values[comp-1]*cos(3*time) - values[comp-2]*sin(3*time);
else
val = values[comp-1]*cos(3*time) + values[comp]*sin(3*time);
}
}
return ok;
}
case SOL_NODAL:
{
const Element2d & el = (*mesh)[selnr];
double lami[8];
int np, i;
val = 0;
double lam3 = 1-lam1-lam2;
switch (el.GetType())
{
case TRIG:
/*
lami[0] = lam3;
lami[1] = lam1;
lami[2] = lam2;
*/
lami[0] = lam1;
lami[1] = lam2;
lami[2] = lam3;
np = 3;
break;
case TRIG6:
/*
lami[0] = lam3*(2*lam3-1);
lami[1] = lam1*(2*lam1-1);
lami[2] = lam2*(2*lam2-1);
*/
// hierarchical basis:
lami[0] = lam3;
lami[1] = lam1;
lami[2] = lam2;
lami[3] = 4*lam1*lam2;
lami[4] = 4*lam2*lam3;
lami[5] = 4*lam1*lam3;
np = 6;
break;
case QUAD:
case QUAD6:
lami[0] = (1-lam1)*(1-lam2);
lami[1] = lam1 * (1-lam2);
lami[2] = lam1 * lam2;
lami[3] = (1-lam1) * lam2;
np = 4;
break;
default:
np = 0;
}
for (i = 0; i < np; i++)
val += lami[i] * data->data[(el[i]-1) * data->dist + comp-1];
return 1;
}
case SOL_ELEMENT:
{
int el1, el2;
mesh->GetTopology().GetSurface2VolumeElement (selnr+1, el1, el2);
el1--;
val = data->data[el1 * data->dist+comp-1];
return 1;
}
case SOL_NONCONTINUOUS:
{
val = 0;
// ?????
return 0;
}
case SOL_SURFACE_ELEMENT:
{
val = data->data[selnr * data->dist + comp-1];
return 1;
}
case SOL_SURFACE_NONCONTINUOUS:
{
const Element2d & el = (*mesh)[selnr];
2009-07-20 14:36:36 +06:00
double lami[8] = { 0.0 };
int np = 0;
2009-01-13 04:40:13 +05:00
val = 0;
int order = data->order;
switch (order)
{
case 0:
return data->data[selnr * data->dist + comp-1];
case 1:
{
switch (el.GetType())
{
case TRIG:
case TRIG6:
{
lami[1] = lam1;
lami[2] = lam2;
lami[0] = 1-lam1-lam2;
np = 3;
break;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not impl 234234" << endl;
2009-01-13 04:40:13 +05:00
}
break;
}
case 2:
{
switch (el.GetType())
{
case TRIG:
{
lami[1] = lam1;
lami[2] = lam2;
lami[0] = 1-lam1-lam2;
np = 3;
break;
}
case TRIG6:
{
double lam3 = 1-lam1-lam2;
lami[1] = 2*lam1 * (lam1-0.5);
lami[2] = 2*lam2 * (lam2-0.5);
lami[0] = 2*lam3 * (lam3-0.5);
lami[3] = 4*lam1*lam2;
lami[4] = 4*lam2*lam3;
lami[5] = 4*lam1*lam3;
np = 6;
break;
}
2009-07-20 14:36:36 +06:00
default:
cerr << "case not implented 3234" << endl;
2009-01-13 04:40:13 +05:00
}
break;
}
}
int base;
if (order == 1)
base = 4 * selnr;
else
base = 9 * selnr;
2009-07-20 14:36:36 +06:00
for (int i = 0; i < np; i++)
val += lami[i] * data->data[(base+i) * data->dist + comp-1];
2009-01-13 04:40:13 +05:00
return 1;
}
case SOL_MARKED_ELEMENTS:
{
val = (*mesh)[selnr].TestRefinementFlag();
return 1;
}
case SOL_ELEMENT_ORDER:
{
val = (*mesh)[selnr].GetOrder();
return 1;
}
}
return 0;
}
Vec<3> VisualSceneSolution ::
GetDeformation (ElementIndex elnr, const Point<3> & p) const
{
Vec<3> def;
if (deform && vecfunction != -1)
{
GetValues (soldata[vecfunction], elnr, p(0), p(1), p(2), &def(0));
def *= scaledeform;
2009-07-20 14:36:36 +06:00
if (soldata[vecfunction]->components == 2) def(2) = 0;
2009-01-13 04:40:13 +05:00
}
else
def = 0;
return def;
}
Vec<3> VisualSceneSolution ::
2012-04-27 00:22:49 +06:00
GetSurfDeformation (SurfaceElementIndex elnr, int facetnr, double lam1, double lam2) const
2009-01-13 04:40:13 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
Vec<3> def;
if (deform && vecfunction != -1)
{
2013-02-27 23:30:38 +06:00
// GetSurfValues (soldata[vecfunction], elnr, facetnr, lam1, lam2, &def(0));
double values[6];
GetSurfValues (soldata[vecfunction], elnr, facetnr, lam1, lam2, values);
def = RealVec3d (values, soldata[vecfunction]->iscomplex, imag_part);
2009-01-13 04:40:13 +05:00
def *= scaledeform;
2009-07-20 14:36:36 +06:00
if (soldata[vecfunction]->components == 2) def(2) = 0;
2009-01-13 04:40:13 +05:00
}
else if (deform && scalfunction != -1 && mesh->GetDimension()==2)
{ // he: allow for 3d plots of 2d surfaces: usage: turn deformation on
def = 0;
2012-04-27 00:22:49 +06:00
GetSurfValue (soldata[scalfunction], elnr, facetnr, lam1, lam2, scalcomp, def(2));
2009-01-13 04:40:13 +05:00
def *= scaledeform;
}
else
def = 0;
return def;
}
void VisualSceneSolution :: GetPointDeformation (int pnum, Point<3> & p,
SurfaceElementIndex elnr) const
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
p = mesh->Point (pnum+1);
if (deform && vecfunction != -1)
{
const SolData * vsol = soldata[vecfunction];
Vec<3> v(0,0,0);
if (vsol->soltype == SOL_NODAL)
{
v = Vec3d(vsol->data[pnum * vsol->dist],
vsol->data[pnum * vsol->dist+1],
vsol->data[pnum * vsol->dist+2]);
}
else if (vsol->soltype == SOL_SURFACE_NONCONTINUOUS)
{
const Element2d & el = (*mesh)[elnr];
for (int j = 0; j < el.GetNP(); j++)
if (el[j] == pnum+1)
{
int base = (4*elnr+j-1) * vsol->dist;
v = Vec3d(vsol->data[base],
vsol->data[base+1],
vsol->data[base+2]);
}
}
if (vsol->dist == 2) v(2) = 0;
v *= scaledeform;
p += v;
}
}
2009-01-25 17:35:25 +05:00
void VisualSceneSolution :: GetClippingPlaneTrigs (Array<ClipPlaneTrig> & trigs,
Array<ClipPlanePoint> & pts)
2009-01-13 04:40:13 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2014-01-07 16:42:30 +06:00
static int timer_vals = NgProfiler::CreateTimer ("ClipPlaneTrigs - vertex values");
2009-01-13 04:40:13 +05:00
static int timer1 = NgProfiler::CreateTimer ("ClipPlaneTrigs1");
2014-04-28 13:09:39 +06:00
// static int timer1a = NgProfiler::CreateTimer ("ClipPlaneTrigs1a");
2014-01-07 16:42:30 +06:00
// static int timer2 = NgProfiler::CreateTimer ("ClipPlaneTrigs2");
2009-01-13 04:40:13 +05:00
static int timer3 = NgProfiler::CreateTimer ("ClipPlaneTrigs3");
static int timer4 = NgProfiler::CreateTimer ("ClipPlaneTrigs4");
2014-01-07 16:42:30 +06:00
static int timer4b = NgProfiler::CreateTimer ("ClipPlaneTrigs4b");
2009-01-13 04:40:13 +05:00
NgProfiler::RegionTimer reg1 (timer1);
2014-01-07 16:42:30 +06:00
2009-01-13 04:40:13 +05:00
int ne = mesh->GetNE();
const int edgei[6][2] =
{ { 0, 1 }, { 0, 2 }, { 0, 3 },
{ 1, 2 }, { 1, 3 }, { 2, 3 } };
double edgelam[6];
2014-08-15 20:46:26 +06:00
// Point<3> edgep[6];
2009-01-13 04:40:13 +05:00
double nodevali[4];
int cntce;
int cpe1 = 0, cpe2 = 0, cpe3 = 0;
2009-01-25 17:35:25 +05:00
// Array<Element> loctets;
// Array<Element> loctetsloc;
// Array<Point<3> > pointsloc;
2009-01-13 04:40:13 +05:00
int n = 1 << subdivisions;
int n3 = (n+1)*(n+1)*(n+1);
2009-01-25 17:35:25 +05:00
Array<Point<3> > grid(n3);
Array<Point<3> > locgrid(n3);
Array<Mat<3,3> > trans(n3);
Array<double> val(n3);
2014-01-07 16:42:30 +06:00
Array<bool> locposval(n3);
2009-01-25 17:35:25 +05:00
Array<int> compress(n3);
2009-01-13 04:40:13 +05:00
2014-01-07 16:42:30 +06:00
NgProfiler::StartTimer (timer_vals);
Array<double,PointIndex::BASE> vertval(mesh->GetNV());
Array<bool,PointIndex::BASE> posval(mesh->GetNV());
for (PointIndex pi = vertval.Begin(); pi < vertval.End(); pi++)
{
Point<3> vert = (*mesh)[pi];
vertval[pi] =
vert(0) * clipplane[0] +
vert(1) * clipplane[1] +
vert(2) * clipplane[2] +
clipplane[3];
posval[pi] = vertval[pi] > 0;
}
NgProfiler::StopTimer (timer_vals);
INDEX_2_CLOSED_HASHTABLE<int> edges(8*n3); // point nr of edge
2009-01-13 04:40:13 +05:00
for (ElementIndex ei = 0; ei < ne; ei++)
{
2014-01-07 16:42:30 +06:00
// NgProfiler::RegionTimer reg1a (timer1a);
2009-01-13 04:40:13 +05:00
int first_point_of_element = pts.Size();
locgrid.SetSize(n3);
if(vispar.clipdomain > 0 && vispar.clipdomain != (*mesh)[ei].GetIndex()) continue;
if(vispar.donotclipdomain > 0 && vispar.donotclipdomain == (*mesh)[ei].GetIndex()) continue;
ELEMENT_TYPE type = (*mesh)[ei].GetType();
if (type == HEX || type == PRISM || type == TET || type == TET10 || type == PYRAMID)
{
const Element & el = (*mesh)[ei];
int ii = 0;
int cnt_valid = 0;
2014-01-07 16:42:30 +06:00
// NgProfiler::StartTimer (timer2);
if (!mesh->GetCurvedElements().IsElementHighOrder(ei))
{
bool has_pos = 0, has_neg = 0;
for (int i = 0; i < el.GetNP(); i++)
2014-01-16 16:02:51 +06:00
if (posval[el[i]])
2014-01-07 16:42:30 +06:00
has_pos = 1;
else
has_neg = 1;
if (!has_pos || !has_neg)
{
// NgProfiler::StopTimer (timer2);
continue;
}
}
2009-01-13 04:40:13 +05:00
if (type == TET || type == TET10)
{
for (int ix = 0; ix <= n; ix++)
for (int iy = 0; iy <= n; iy++)
for (int iz = 0; iz <= n; iz++, ii++)
{
if (ix+iy+iz <= n)
{
compress[ii] = cnt_valid;
locgrid[cnt_valid] =
Point<3> (double(ix) / n, double(iy) / n, double(iz) / n);
cnt_valid++;
}
else
compress[ii] = -1;
}
}
else
for (int ix = 0; ix <= n; ix++)
for (int iy = 0; iy <= n; iy++)
for (int iz = 0; iz <= n; iz++, ii++)
{
Point<3> ploc;
compress[ii] = ii;
switch (type)
{
case PRISM:
if (ix+iy <= n)
{
ploc = Point<3> (double(ix) / n, double(iy) / n, double(iz) / n);
compress[ii] = cnt_valid;
cnt_valid++;
}
else
compress[ii] = -1;
break;
case HEX:
ploc = Point<3> (double(ix) / n, double(iy) / n, double(iz) / n);
break;
case PYRAMID:
ploc = Point<3> (double(ix) / n * (1-double(iz)/n),
double(iy) / n * (1-double(iz)/n),
double(iz)/n);
if (iz == n) ploc = Point<3> (0,0,1-1e-8);
break;
2009-07-20 14:36:36 +06:00
default:
cerr << "clip plane trigs not implemented" << endl;
ploc = Point<3> (0,0,0);
2009-01-13 04:40:13 +05:00
}
if (compress[ii] != -1)
locgrid[compress[ii]] = ploc;
}
if (type != TET && type != TET10 && type != PRISM) cnt_valid = n3;
locgrid.SetSize(cnt_valid);
2014-01-07 16:42:30 +06:00
// NgProfiler::StopTimer (timer2);
// NgProfiler::RegionTimer reg4(timer4);
2009-01-13 04:40:13 +05:00
if (mesh->GetCurvedElements().IsHighOrder())
{
2014-01-07 16:42:30 +06:00
NgProfiler::RegionTimer reg4(timer4);
2009-01-13 04:40:13 +05:00
mesh->GetCurvedElements().
CalcMultiPointElementTransformation (&locgrid, ei, &grid, 0);
}
else
{
2014-01-07 16:42:30 +06:00
NgProfiler::RegionTimer reg4(timer4b);
2009-01-13 04:40:13 +05:00
Vector shape(el.GetNP());
MatrixFixWidth<3> pointmat(el.GetNP());
for (int k = 0; k < el.GetNP(); k++)
for (int j = 0; j < 3; j++)
pointmat(k,j) = (*mesh)[el[k]](j);
for (int i = 0; i < cnt_valid; i++)
{
2016-07-07 21:31:09 +05:00
el.GetShapeNew<double> (locgrid[i], shape);
2009-01-13 04:40:13 +05:00
Point<3> pglob;
for (int j = 0; j < 3; j++)
{
pglob(j) = 0;
for (int k = 0; k < el.GetNP(); k++)
pglob(j) += shape(k) * pointmat(k,j);
}
grid[i] = pglob;
}
}
NgProfiler::RegionTimer reg3(timer3);
2014-01-07 16:42:30 +06:00
bool has_pos = false, all_pos = true;
2009-01-13 04:40:13 +05:00
for (int i = 0; i < cnt_valid; i++)
{
val[i] =
grid[i](0) * clipplane[0] +
grid[i](1) * clipplane[1] +
grid[i](2) * clipplane[2] +
clipplane[3];
2014-01-07 16:42:30 +06:00
locposval[i] = val[i] > 0;
has_pos |= locposval[i];
all_pos &= locposval[i];
2009-01-13 04:40:13 +05:00
2014-01-07 16:42:30 +06:00
// if (val[i] > 0) has_pos = 1; else has_neg = 1;
}
// if (!has_pos || !has_neg) continue;
if (!has_pos || all_pos) continue;
edges.DeleteData();
2009-01-13 04:40:13 +05:00
for (int ix = 0; ix < n; ix++)
for (int iy = 0; iy < n; iy++)
for (int iz = 0; iz < n; iz++)
{
int base = iz + (n+1)*iy + (n+1)*(n+1)*ix;
int pi[8] =
{ base, base+(n+1)*(n+1), base+(n+1)*(n+1)+(n+1), base+(n+1),
base+1, base+(n+1)*(n+1)+1, base+(n+1)*(n+1)+(n+1)+1, base+(n+1)+1 };
for (int j = 0; j < 8; j++)
pi[j] = compress[pi[j]];
2014-01-07 16:42:30 +06:00
bool has_pos = false, all_pos = true;
for (int j = 0; j < 8; j++)
if (pi[j] != -1)
{
has_pos |= locposval[pi[j]];
all_pos &= locposval[pi[j]];
}
if (!has_pos || all_pos) continue;
2009-01-13 04:40:13 +05:00
const int tets[6][4] =
{ { 1, 2, 4, 5 },
{ 4, 5, 2, 8 },
{ 2, 8, 5, 6 },
{ 2, 3, 4, 8 },
{ 2, 3, 8, 6 },
{ 3, 8, 6, 7 } };
2014-01-07 16:42:30 +06:00
2009-01-13 04:40:13 +05:00
for (int ii = 0; ii < 6; ii++)
{
int teti[4];
for (int k = 0; k < 4; k++)
teti[k] = pi[tets[ii][k]-1];
2014-01-07 16:42:30 +06:00
bool is_valid = true;
2009-01-13 04:40:13 +05:00
for (int j = 0; j < 4; j++)
2014-01-07 16:42:30 +06:00
is_valid &= (teti[j] != -1);
2009-01-13 04:40:13 +05:00
if (!is_valid) continue;
2014-01-07 16:42:30 +06:00
bool has_pos = false, all_pos = true;
for (int j = 0; j < 4; j++)
{
has_pos |= locposval[teti[j]];
all_pos &= locposval[teti[j]];
}
if (!has_pos || all_pos) continue;
2009-01-13 04:40:13 +05:00
for (int j = 0; j < 4; j++)
nodevali[j] = val[teti[j]];
cntce = 0;
for (int j = 0; j < 6; j++)
{
int lpi1 = edgei[j][0];
int lpi2 = edgei[j][1];
2014-01-07 16:42:30 +06:00
if ( (nodevali[lpi1] > 0) != (nodevali[lpi2] > 0) )
2009-01-13 04:40:13 +05:00
{
cntce++;
cpe3 = cpe2;
cpe2 = cpe1;
cpe1 = j;
if (cntce >= 3)
{
ClipPlaneTrig cpt;
cpt.elnr = ei;
for (int k = 0; k < 3; k++)
{
int ednr;
switch (k)
{
case 0: ednr = cpe1; break;
case 1: ednr = cpe2; break;
case 2: ednr = cpe3; break;
}
2014-01-07 16:42:30 +06:00
2009-01-13 04:40:13 +05:00
int pi1 = edgei[ednr][0];
int pi2 = edgei[ednr][1];
int pnr = -1;
2014-01-07 16:42:30 +06:00
INDEX_2 pair (teti[pi1], teti[pi2]);
pair.Sort();
if (edges.Used(pair))
pnr = edges.Get(pair);
else
{
ClipPlanePoint cppt;
cppt.elnr = ei;
edgelam[ednr] = nodevali[pi2] / (nodevali[pi2] - nodevali[pi1]);
Point<3> gp1 = grid[teti[pi1]];
Point<3> gp2 = grid[teti[pi2]];
cppt.p = gp2 + edgelam[ednr] * (gp1-gp2);
Point<3> p1 = locgrid[teti[pi1]];
Point<3> p2 = locgrid[teti[pi2]];
cppt.lami = p2 + edgelam[ednr] * (p1-p2);
pts.Append (cppt);
pnr = pts.Size()-1;
2014-01-07 16:42:30 +06:00
edges.Set (pair, pnr);
}
2009-01-13 04:40:13 +05:00
cpt.points[k].pnr = pnr;
cpt.points[k].locpnr = pnr-first_point_of_element;
}
trigs.Append (cpt);
}
}
}
}
}
}
else
{ // other elements not supported (JS, June 2007)
2014-01-07 16:42:30 +06:00
continue; // return;
2009-01-13 04:40:13 +05:00
}
}
}
2009-01-25 17:35:25 +05:00
void VisualSceneSolution :: GetClippingPlaneGrid (Array<ClipPlanePoint> & pts)
2009-01-13 04:40:13 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2009-01-13 04:40:13 +05:00
Vec3d n(clipplane[0], clipplane[1], clipplane[2]);
double mu = -clipplane[3] / n.Length2();
Point3d p(mu*n.X(), mu * n.Y(), mu * n.Z());
2009-08-05 20:20:30 +06:00
// n /= n.Length();
n.Normalize();
2009-01-13 04:40:13 +05:00
Vec3d t1, t2;
n.GetNormal (t1);
t2 = Cross (n, t1);
double xi1, xi2;
double xi1mid = (center - p) * t1;
double xi2mid = (center - p) * t2;
pts.SetSize(0);
for (xi1 = xi1mid-rad+xoffset/gridsize; xi1 <= xi1mid+rad+xoffset/gridsize; xi1 += rad / gridsize)
for (xi2 = xi2mid-rad+yoffset/gridsize; xi2 <= xi2mid+rad+yoffset/gridsize; xi2 += rad / gridsize)
{
Point3d hp = p + xi1 * t1 + xi2 * t2;
int cindex(-1);
bool allowindex(true);
if(vispar.clipdomain > 0)
{
cindex = vispar.clipdomain;
}
else if(vispar.donotclipdomain > 0)
{
allowindex = false;
cindex = vispar.donotclipdomain;
}
2009-08-05 20:20:30 +06:00
double lami[3];
int elnr = mesh->GetElementOfPoint (hp, lami,0,cindex,allowindex)-1;
2009-01-13 04:40:13 +05:00
if (elnr != -1)
{
ClipPlanePoint cpp;
cpp.p = hp;
cpp.elnr = elnr;
cpp.lami(0) = lami[0];
cpp.lami(1) = lami[1];
cpp.lami(2) = lami[2];
pts.Append (cpp);
}
}
};
2009-08-05 20:20:30 +06:00
2011-11-03 17:02:05 +06:00
void VisualSceneSolution :: DrawClipPlaneTrigs ()
2009-01-13 04:40:13 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-02-15 21:22:05 +05:00
#ifdef PARALLELGL
if (id == 0 && ntasks > 1)
{
InitParallelGL();
Array<int> parlists (ntasks);
2011-07-15 03:36:19 +06:00
MyMPI_SendCmd ("redraw");
MyMPI_SendCmd ("clipplanetrigs");
2011-02-15 21:22:05 +05:00
for ( int dest = 1; dest < ntasks; dest++ )
2011-07-07 03:08:58 +06:00
MyMPI_Recv (parlists[dest], dest, MPI_TAG_VIS);
2011-02-15 21:22:05 +05:00
if (clipplanelist_scal)
glDeleteLists (clipplanelist_scal, 1);
clipplanelist_scal = glGenLists (1);
glNewList (clipplanelist_scal, GL_COMPILE);
for ( int dest = 1; dest < ntasks; dest++ )
glCallList (parlists[dest]);
glEndList();
return;
}
#endif
if (clipplanelist_scal)
glDeleteLists (clipplanelist_scal, 1);
clipplanelist_scal = glGenLists (1);
glNewList (clipplanelist_scal, GL_COMPILE);
Array<ClipPlaneTrig> trigs;
Array<ClipPlanePoint> points;
GetClippingPlaneTrigs (trigs, points);
glNormal3d (-clipplane[0], -clipplane[1], -clipplane[2]);
glColor3d (1.0, 1.0, 1.0);
SetTextureMode (usetexture);
SolData * sol = NULL;
if (scalfunction != -1)
sol = soldata[scalfunction];
2012-11-05 17:28:36 +06:00
if (sol -> draw_volume)
{
glBegin (GL_TRIANGLES);
2009-01-13 04:40:13 +05:00
2009-08-05 20:20:30 +06:00
int maxlpnr = 0;
for (int i = 0; i < trigs.Size(); i++)
for (int j = 0; j < 3; j++)
maxlpnr = max2 (maxlpnr, trigs[i].points[j].locpnr);
2009-01-13 04:40:13 +05:00
Array<double> vals(maxlpnr+1);
Array<complex<double> > valsc(maxlpnr+1);
Array<int> elnrs(maxlpnr+1);
Array<bool> trigok(maxlpnr+1);
Array<Point<3> > locpoints(maxlpnr+1);
Array<Point<3> > globpoints(maxlpnr+1);
Array<Mat<3> > jacobi(maxlpnr+1);
Array<double> mvalues( (maxlpnr+1) * sol->components);
2009-08-05 20:20:30 +06:00
trigok = false;
elnrs = -1;
2009-01-13 04:40:13 +05:00
2009-08-05 20:20:30 +06:00
Point<3> p[3];
// double val[3];
2012-04-27 00:22:49 +06:00
// complex<double> valc[3];
int lastelnr = -1;
int nlp = -1;
2013-03-14 05:34:30 +06:00
bool ok = false;
2009-08-05 20:20:30 +06:00
for (int i = 0; i < trigs.Size(); i++)
2009-01-13 04:40:13 +05:00
{
const ClipPlaneTrig & trig = trigs[i];
if (trig.elnr != lastelnr)
{
lastelnr = trig.elnr;
nlp = -1;
for (int ii = i; ii < trigs.Size(); ii++)
{
if (trigs[ii].elnr != trig.elnr) break;
for (int j = 0; j < 3; j++)
nlp = max (nlp, trigs[ii].points[j].locpnr);
}
nlp++;
locpoints.SetSize (nlp);
for (int ii = i; ii < trigs.Size(); ii++)
{
if (trigs[ii].elnr != trig.elnr) break;
for (int j = 0; j < 3; j++)
locpoints[trigs[ii].points[j].locpnr] = points[trigs[ii].points[j].pnr].lami;
}
mesh->GetCurvedElements().
CalcMultiPointElementTransformation (&locpoints, trig.elnr,
&globpoints, &jacobi);
bool
2012-04-27 00:22:49 +06:00
drawelem = GetMultiValues (sol, trig.elnr, -1, nlp,
&locpoints[0](0), &locpoints[1](0)-&locpoints[0](0),
&globpoints[0](0), &globpoints[1](0)-&globpoints[0](0),
&jacobi[0](0), &jacobi[1](0)-&jacobi[0](0),
&mvalues[0], sol->components);
2011-11-15 00:17:54 +06:00
// cout << "have multivalues, comps = " << sol->components << endl;
2012-11-05 17:28:36 +06:00
// if (!drawelem) ok = false;
ok = drawelem;
2011-11-15 00:17:54 +06:00
if (usetexture != 2 || !sol->iscomplex)
for (int ii = 0; ii < nlp; ii++)
vals[ii] = ExtractValue(sol, scalcomp, &mvalues[ii*sol->components]);
2011-11-15 00:17:54 +06:00
else
for (int ii = 0; ii < nlp; ii++)
valsc[ii] = complex<double> (mvalues[ii*sol->components + scalcomp-1],
mvalues[ii*sol->components + scalcomp]);
}
2011-11-15 00:17:54 +06:00
2009-08-05 20:20:30 +06:00
if(ok)
for(int j=0; j<3; j++)
{
if (usetexture != 2 || !sol->iscomplex)
SetOpenGlColor (vals[trig.points[j].locpnr]);
2009-08-05 20:20:30 +06:00
else
2011-11-15 00:17:54 +06:00
glTexCoord2f ( valsc[trig.points[j].locpnr].real(),
valsc[trig.points[j].locpnr].imag() );
p[j] = points[trig.points[j].pnr].p;
if (deform)
{
Point<3> ploc = points[trig.points[j].pnr].lami;
p[j] += GetDeformation (trig.elnr, ploc);
}
2009-08-05 20:20:30 +06:00
glVertex3dv (p[j]);
}
2009-01-13 04:40:13 +05:00
}
2009-08-05 20:20:30 +06:00
glEnd();
2012-11-05 17:28:36 +06:00
}
2011-02-15 21:22:05 +05:00
glEndList ();
#ifdef PARALLELGL
glFinish();
if (id > 0)
2011-07-07 03:08:58 +06:00
MyMPI_Send (clipplanelist_scal, 0, MPI_TAG_VIS);
2011-02-15 21:22:05 +05:00
#endif
2009-08-05 20:20:30 +06:00
}
2009-01-13 04:40:13 +05:00
void VisualSceneSolution ::
2009-08-05 20:20:30 +06:00
SetOpenGlColor(double val)
2009-01-13 04:40:13 +05:00
{
if (usetexture == 1 && !logscale)
{
2009-08-05 20:20:30 +06:00
glTexCoord1f ( val );
2009-01-13 04:40:13 +05:00
return;
}
2009-08-05 20:20:30 +06:00
double valmin = minval;
double valmax = maxval;
2009-01-13 04:40:13 +05:00
double value;
if (!logscale)
2009-08-05 20:20:30 +06:00
value = (val - valmin) / (valmax - valmin);
2009-01-13 04:40:13 +05:00
else
{
if (valmax <= 0) valmax = 1;
if (valmin <= 0) valmin = 1e-4 * valmax;
2009-08-05 20:20:30 +06:00
value = (log(fabs(val)) - log(valmin)) / (log(valmax) - log(valmin));
2009-01-13 04:40:13 +05:00
}
if (!invcolor)
value = 1 - value;
if (value > 1) value = 1;
if (value < 0) value = 0;
value *= 4;
static const double colp[][3] =
{
{ 1, 0, 0 },
{ 1, 1, 0 },
{ 0, 1, 0 },
{ 0, 1, 1 },
{ 0, 0, 1 },
{ 1, 0, 1 },
{ 1, 0, 0 },
};
int i = int(value);
double r = value - i;
GLdouble col[3];
for (int j = 0; j < 3; j++)
col[j] = (1-r) * colp[i][j] + r * colp[i+1][j];
2009-08-05 20:20:30 +06:00
glColor3dv (col);
}
void VisualSceneSolution ::
SetTextureMode (int texturemode) const
{
switch (texturemode)
{
case 0:
glDisable (GL_TEXTURE_1D);
glDisable (GL_TEXTURE_2D);
break;
case 1:
glEnable (GL_TEXTURE_1D);
glDisable (GL_TEXTURE_2D);
glColor3d (1.0, 1.0, 1.0);
break;
case 2:
glDisable (GL_TEXTURE_1D);
glEnable (GL_TEXTURE_2D);
glColor3d (1.0, 1.0, 1.0);
break;
}
2009-01-13 04:40:13 +05:00
}
void VisualSceneSolution ::
DrawCone (const Point<3> & p1, const Point<3> & p2, double r)
{
int n = 10, i;
Vec<3> p1p2 = p2 - p1;
p1p2.Normalize();
Vec<3> p2p1 = -p1p2;
Vec<3> t1 = p1p2.GetNormal();
Vec<3> t2 = Cross (p1p2, t1);
Point<3> oldp = p1 + r * t1;
Vec<3> oldn = t1;
Point<3> p;
Vec<3> normal;
Mat<2> rotmat;
Vec<2> cs, newcs;
cs(0) = 1;
cs(1) = 0;
rotmat(0,0) = rotmat(1,1) = cos(2*M_PI/n);
rotmat(1,0) = sin(2*M_PI/n);
rotmat(0,1) = -rotmat(1,0);
glBegin (GL_TRIANGLES);
for (i = 1; i <= n; i++)
{
/*
phi = 2 * M_PI * i / n;
normal = cos(phi) * t1 + sin(phi) * t2;
*/
newcs = rotmat * cs;
cs = newcs;
normal = cs(0) * t1 + cs(1) * t2;
p = p1 + r * normal;
// cone
glNormal3dv (normal);
glVertex3dv (p);
glVertex3dv (p2);
glNormal3dv (oldn);
glVertex3dv (oldp);
// base-circle
glNormal3dv (p2p1);
glVertex3dv (p);
glVertex3dv (p1);
glVertex3dv (oldp);
oldp = p;
oldn = normal;
}
glEnd ();
}
void VisualSceneSolution ::
DrawCylinder (const Point<3> & p1, const Point<3> & p2, double r)
{
int n = 10, i;
Vec<3> p1p2 = p2 - p1;
p1p2.Normalize();
2013-03-14 05:34:30 +06:00
// Vec<3> p2p1 = -p1p2;
2009-01-13 04:40:13 +05:00
Vec<3> t1 = p1p2.GetNormal();
Vec<3> t2 = Cross (p1p2, t1);
Point<3> oldhp1 = p1 + r * t1;
Point<3> oldhp2 = p2 + r * t1;
Vec<3> oldn = t1;
Point<3> hp1, hp2;
Vec<3> normal;
Mat<2> rotmat;
Vec<2> cs, newcs;
cs(0) = 1;
cs(1) = 0;
rotmat(0,0) = rotmat(1,1) = cos(2*M_PI/n);
rotmat(1,0) = sin(2*M_PI/n);
rotmat(0,1) = -rotmat(1,0);
glBegin (GL_QUADS);
for (i = 1; i <= n; i++)
{
newcs = rotmat * cs;
cs = newcs;
normal = cs(0) * t1 + cs(1) * t2;
hp1 = p1 + r * normal;
hp2 = p2 + r * normal;
// cylinder
glNormal3dv (normal);
glVertex3dv (hp1);
glVertex3dv (hp2);
glVertex3dv (oldhp2);
glVertex3dv (oldhp1);
oldhp1 = hp1;
oldhp2 = hp2;
oldn = normal;
}
glEnd ();
}
void VisualSceneSolution :: MouseDblClick (int px, int py)
{
vsmesh.SetClippingPlane();
2011-01-15 01:50:12 +05:00
// vsmesh.BuildFilledList();
2009-01-13 04:40:13 +05:00
vsmesh.MouseDblClick(px,py);
}
#ifdef PARALLELGL
void VisualSceneSolution :: Broadcast ()
{
2011-07-15 03:36:19 +06:00
MPI_Datatype type;
int blocklen[] =
{
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
2012-10-17 19:13:50 +06:00
1, 4, 1, 1,
1
2011-07-15 03:36:19 +06:00
};
MPI_Aint displ[] = { (char*)&usetexture - (char*)this,
(char*)&clipsolution - (char*)this,
(char*)&scalfunction - (char*)this,
(char*)&scalcomp - (char*)this,
(char*)&vecfunction - (char*)this,
(char*)&gridsize - (char*)this,
(char*)&autoscale - (char*)this,
(char*)&logscale - (char*)this,
(char*)&minval - (char*)this,
(char*)&maxval - (char*)this,
(char*)&numisolines - (char*)this,
(char*)&subdivisions - (char*)this,
2011-07-23 05:06:25 +06:00
(char*)&evalfunc - (char*)this,
2011-11-03 17:02:05 +06:00
(char*)&clipplane[0] - (char*)this,
2012-10-17 19:13:50 +06:00
(char*)&multidimcomponent - (char*)this,
(char*)&deform - (char*)this,
(char*)&scaledeform - (char*)this
2011-11-03 17:02:05 +06:00
};
2011-07-15 03:36:19 +06:00
MPI_Datatype types[] = {
MPI_INT, MPI_INT, MPI_INT, MPI_INT,
MPI_INT, MPI_INT, MPI_INT, MPI_INT,
MPI_DOUBLE, MPI_DOUBLE, MPI_INT, MPI_INT,
2012-10-17 19:13:50 +06:00
MPI_INT, MPI_DOUBLE, MPI_INT, MPI_INT,
MPI_DOUBLE
2011-07-15 03:36:19 +06:00
};
2012-10-17 19:13:50 +06:00
MPI_Type_create_struct (17, blocklen, displ, types, &type);
2011-07-15 03:36:19 +06:00
MPI_Type_commit ( &type );
MPI_Bcast (this, 1, type, 0, MPI_COMM_WORLD);
MPI_Type_free (&type);
2009-01-13 04:40:13 +05:00
}
#endif
2014-10-12 17:40:12 +06:00
}
2009-01-13 04:40:13 +05:00
2014-10-06 15:57:44 +06:00
2014-10-12 17:40:12 +06:00
#include "../include/nginterface.h"
2014-10-06 15:57:44 +06:00
void Ng_ClearSolutionData ()
{
#ifdef OPENGL
// if (nodisplay) return;
// netgen::vssolution.ClearSolutionData();
netgen::GetVSSolution().ClearSolutionData();
2014-10-06 15:57:44 +06:00
#endif
}
void Ng_InitSolutionData (Ng_SolutionData * soldata)
{
2017-06-25 21:22:46 +05:00
// soldata -> name = NULL;
2014-10-06 15:57:44 +06:00
soldata -> data = NULL;
soldata -> components = 1;
soldata -> dist = 1;
soldata -> order = 1;
soldata -> iscomplex = 0;
soldata -> draw_surface = 1;
soldata -> draw_volume = 1;
soldata -> soltype = NG_SOLUTION_NODAL;
soldata -> solclass = 0;
}
void Ng_SetSolutionData (Ng_SolutionData * soldata)
{
#ifdef OPENGL
// if (nodisplay) return;
// vssolution.ClearSolutionData ();
netgen::VisualSceneSolution::SolData * vss = new netgen::VisualSceneSolution::SolData;
2017-06-25 21:22:46 +05:00
// vss->name = new char[strlen (soldata->name)+1];
// strcpy (vss->name, soldata->name);
vss->name = soldata->name;
2014-10-06 15:57:44 +06:00
vss->data = soldata->data;
vss->components = soldata->components;
vss->dist = soldata->dist;
vss->order = soldata->order;
vss->iscomplex = bool(soldata->iscomplex);
vss->draw_surface = soldata->draw_surface;
vss->draw_volume = soldata->draw_volume;
vss->soltype = netgen::VisualSceneSolution::SolType (soldata->soltype);
vss->solclass = soldata->solclass;
// netgen::vssolution.AddSolutionData (vss);
netgen::GetVSSolution().AddSolutionData (vss);
2014-10-06 15:57:44 +06:00
#endif
2009-01-13 04:40:13 +05:00
}
2014-10-06 15:57:44 +06:00
2014-10-12 17:40:12 +06:00
namespace netgen
{
2014-12-04 15:24:45 +05:00
extern void Render (bool blocking);
2014-10-12 17:40:12 +06:00
}
2014-12-04 15:24:45 +05:00
void Ng_Redraw (bool blocking)
2014-10-12 17:40:12 +06:00
{
#ifdef OPENGL
//netgen::vssolution.UpdateSolutionTimeStamp();
netgen::GetVSSolution().UpdateSolutionTimeStamp();
2014-12-04 15:24:45 +05:00
netgen::Render(blocking);
2014-10-12 17:40:12 +06:00
#endif
}
#ifdef OPENGL
#ifdef WIN32
void (*glBindBuffer) (GLenum a, GLuint b);
void (*glDeleteBuffers) (GLsizei a, const GLuint *b);
void (*glGenBuffers) (GLsizei a, GLuint *b);
void (*glBufferData) (GLenum a, GLsizeiptr b, const GLvoid *c, GLenum d);
void (*glBufferSubData) (GLenum a, GLintptr b, GLsizeiptr c, const GLvoid *d);
DLL_HEADER void LoadOpenGLFunctionPointers() {
#ifdef USE_BUFFERS
glBindBuffer = (decltype(glBindBuffer)) wglGetProcAddress("glBindBuffer");
glBufferSubData = (decltype(glBufferSubData)) wglGetProcAddress("glBufferSubData");
glBufferData = (decltype(glBufferData)) wglGetProcAddress("glBufferData");
glDeleteBuffers = (decltype(glDeleteBuffers)) wglGetProcAddress("glDeleteBuffers");
glGenBuffers = (decltype(glGenBuffers)) wglGetProcAddress("glGenBuffers");
if(!glBindBuffer) throw std::runtime_error("Could not load OpenGL functions!");
#endif
}
#else // WIN32
DLL_HEADER void LoadOpenGLFunctionPointers() { }
#endif // WIN32
#endif // OPENGL