From f839c665e8ec9e1ea0b6a25de30339aa36f0b05b Mon Sep 17 00:00:00 2001 From: Tzanio Kolev Date: Thu, 20 Jun 2024 12:25:38 -0700 Subject: [PATCH 01/34] Increase auto_ref_max and auto_ref_max_surf_elem --- lib/vsdata.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 1934414f..7b47f6be 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -1270,8 +1270,8 @@ void VisualizationSceneScalarData::Init() arrow_type = arrow_scaling_type = 0; scaling = 0; drawaxes = colorbar = 0; - auto_ref_max = 16; - auto_ref_max_surf_elem = 20000; + auto_ref_max = 32; + auto_ref_max_surf_elem = 5000000; minv = 0.0; maxv = 1.0; logscale = false; From 873dfa5204e1d3d51dc36f33da9b495daf984569 Mon Sep 17 00:00:00 2001 From: Tzanio Kolev Date: Thu, 20 Jun 2024 12:28:12 -0700 Subject: [PATCH 02/34] Updated CHANGELOG --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5b74e135..12c76af4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,10 @@ Version 4.2.1 (development) =========================== +- Increased the default auto-refinement limits to maximum of 32 refinement + levels or 5M elements. Note that you may still need to press 'o' if the mesh + is larger and/or appears not as curved as it should be. + - Significantly improved memory usage. - Add support to visualize solutions on 1D elements embedded in 2D and 3D. From 88993d4efaafd2028c63ee2540398ebc8aab9870 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 11:41:13 -0700 Subject: [PATCH 03/34] Improved scalar 2D auto refinement. --- lib/vsdata.cpp | 5 +++-- lib/vsdata.hpp | 2 +- lib/vssolution.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 21fa98f4..ea323dac 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -1271,8 +1271,9 @@ void VisualizationSceneScalarData::Init() arrow_type = arrow_scaling_type = 0; scaling = 0; drawaxes = colorbar = 0; - auto_ref_max = 32; - auto_ref_max_surf_elem = 5000000; + auto_ref_max = 16; + auto_ref_min_surf_elem = 100000; + auto_ref_max_surf_elem = 2000000; minv = 0.0; maxv = 1.0; logscale = false; diff --git a/lib/vsdata.hpp b/lib/vsdata.hpp index 92683110..3705b301 100644 --- a/lib/vsdata.hpp +++ b/lib/vsdata.hpp @@ -77,7 +77,7 @@ class VisualizationSceneScalarData : public VisualizationScene int scaling, colorbar, drawaxes; Shading shading; - int auto_ref_max, auto_ref_max_surf_elem; + int auto_ref_max, auto_ref_min_surf_elem, auto_ref_max_surf_elem; vector updated_bufs; gl3::GlDrawable axes_buf; diff --git a/lib/vssolution.cpp b/lib/vssolution.cpp index bab6d0d5..779c3aa1 100644 --- a/lib/vssolution.cpp +++ b/lib/vssolution.cpp @@ -988,13 +988,48 @@ void VisualizationSceneSolution::SetRefineFactors(int tot, int bdr) int VisualizationSceneSolution::GetAutoRefineFactor() { - int ne = mesh->GetNE(), ref = 1; + const int ne = mesh->GetNE(); + + //determine the refinement based on the order of the mesh and grid function + int order_ref = 1; + + //grid function + if (rsol) + { + for (int i = 0; i < ne; i++) + { + const FiniteElement &fe = *rsol->FESpace()->GetFE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetElementTransformation(i)->OrderW(); + } + order_ref = std::max(order_ref, 2 * order); + } + } + else + { + order_ref = (sol->Size() == mesh->GetNV())?(2):(1); + } - while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_max_surf_elem) + //mesh + const FiniteElementSpace *nfes = mesh->GetNodalFESpace(); + if (nfes) { - ref++; + const int order = nfes->GetMaxElementOrder(); + order_ref = std::max(order_ref, 2 * order); } + //limit the total number of elements + int auto_ref_surf_elem = ne*(order_ref+1)*(order_ref+1); + auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, + auto_ref_min_surf_elem), auto_ref_max_surf_elem); + + //approach the given number of elements + int ref = 1; + while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) + { ref++; } + return ref; } From f1b6ba2bd019da2a13ff963674a4f1ba88ecc195 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 11:57:46 -0700 Subject: [PATCH 04/34] Improved scalar 3D auto refinement. --- lib/vssolution3d.cpp | 50 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/lib/vssolution3d.cpp b/lib/vssolution3d.cpp index bc135ab2..8044284f 100644 --- a/lib/vssolution3d.cpp +++ b/lib/vssolution3d.cpp @@ -919,17 +919,57 @@ void VisualizationSceneSolution3d::SetRefineFactors(int f, int ignored) int VisualizationSceneSolution3d::GetAutoRefineFactor() { - int ne = mesh->GetNBE(), ref = 1; - if (mesh->Dimension() == 2) + const int dim = mesh->Dimension(); + const int ne = (dim == 3)?(mesh->GetNBE()):(mesh->GetNE()); + + //determine the refinement based on the order of the mesh and grid function + int order_ref = 1; + + //grid function + if (GridF) { - ne = mesh->GetNE(); + for (int i = 0; i < ne; i++) + { + const FiniteElement &fe = (dim == 3)?(*GridF->FESpace()->GetBE(i)) + :(*GridF->FESpace()->GetFE(i)); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + if (dim == 3) + { + order += mesh->GetBdrElementTransformation(i)->OrderW(); + } + else + { + order += mesh->GetElementTransformation(i)->OrderW(); + } + } + order_ref = std::max(order_ref, 2 * order); + } + } + else + { + order_ref = (sol->Size() == mesh->GetNV())?(2):(1); } - while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_max_surf_elem) + //mesh + const FiniteElementSpace *nfes = mesh->GetNodalFESpace(); + if (nfes) { - ref++; + const int order = nfes->GetMaxElementOrder(); + order_ref = std::max(order_ref, 2 * order); } + //limit the total number of elements + int auto_ref_surf_elem = ne*(order_ref+1)*(order_ref+1); + auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, + auto_ref_min_surf_elem), auto_ref_max_surf_elem); + + //approach the given number of elements + int ref = 1; + while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) + { ref++; } + return ref; } From f1761bd6b37ca386985786fb296d85a1a0f838ea Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 12:12:02 -0700 Subject: [PATCH 05/34] Centralized the auto refinement algorithm. --- lib/vsdata.cpp | 36 +++++++++++++++++++++++++++ lib/vsdata.hpp | 3 +++ lib/vssolution.cpp | 47 +++++++++-------------------------- lib/vssolution.hpp | 2 +- lib/vssolution3d.cpp | 58 +++++++++++++++----------------------------- lib/vssolution3d.hpp | 2 +- 6 files changed, 72 insertions(+), 76 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index ea323dac..49cdae2d 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -47,6 +47,42 @@ void VisualizationSceneScalarData::FixValueRange() } } +int VisualizationSceneScalarData::GetFunctionAutoRefineFactor() +{ + if (!sol) { return 1; } + + return (sol->Size() == mesh->GetNV())?(2):(1); +} + +int VisualizationSceneScalarData::GetAutoRefineFactor() +{ + const int dim = mesh->Dimension(); + const int ne = (dim == 3)?(mesh->GetNBE()):(mesh->GetNE()); + + //determine the refinement based on the order of the mesh and grid function + int order_ref = GetFunctionAutoRefineFactor(); + + //mesh + const FiniteElementSpace *nfes = mesh->GetNodalFESpace(); + if (nfes) + { + const int order = nfes->GetMaxElementOrder(); + order_ref = std::max(order_ref, 2 * order); + } + + //limit the total number of elements + int auto_ref_surf_elem = ne*(order_ref+1)*(order_ref+1); + auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, + auto_ref_min_surf_elem), auto_ref_max_surf_elem); + + //approach the given number of elements + int ref = 1; + while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) + { ref++; } + + return ref; +} + void VisualizationSceneScalarData::DoAutoscale(bool prepare) { if (autoscale == 1) diff --git a/lib/vsdata.hpp b/lib/vsdata.hpp index 3705b301..72543fd7 100644 --- a/lib/vsdata.hpp +++ b/lib/vsdata.hpp @@ -138,6 +138,9 @@ class VisualizationSceneScalarData : public VisualizationScene void FixValueRange(); + virtual int GetFunctionAutoRefineFactor(); + virtual int GetAutoRefineFactor(); + void Cone(gl3::GlDrawable& buf, glm::mat4 transform, double cval); public: diff --git a/lib/vssolution.cpp b/lib/vssolution.cpp index 779c3aa1..1b792cc1 100644 --- a/lib/vssolution.cpp +++ b/lib/vssolution.cpp @@ -986,49 +986,24 @@ void VisualizationSceneSolution::SetRefineFactors(int tot, int bdr) } } -int VisualizationSceneSolution::GetAutoRefineFactor() +int VisualizationSceneSolution::GetFunctionAutoRefineFactor() { - const int ne = mesh->GetNE(); - - //determine the refinement based on the order of the mesh and grid function - int order_ref = 1; + if (!rsol) { return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(); } //grid function - if (rsol) + + const int ne = mesh->GetNE(); + int ref = 1; + for (int i = 0; i < ne; i++) { - for (int i = 0; i < ne; i++) + const FiniteElement &fe = *rsol->FESpace()->GetFE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) { - const FiniteElement &fe = *rsol->FESpace()->GetFE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetElementTransformation(i)->OrderW(); - } - order_ref = std::max(order_ref, 2 * order); + order += mesh->GetElementTransformation(i)->OrderW(); } + ref = std::max(ref, 2 * order); } - else - { - order_ref = (sol->Size() == mesh->GetNV())?(2):(1); - } - - //mesh - const FiniteElementSpace *nfes = mesh->GetNodalFESpace(); - if (nfes) - { - const int order = nfes->GetMaxElementOrder(); - order_ref = std::max(order_ref, 2 * order); - } - - //limit the total number of elements - int auto_ref_surf_elem = ne*(order_ref+1)*(order_ref+1); - auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, - auto_ref_min_surf_elem), auto_ref_max_surf_elem); - - //approach the given number of elements - int ref = 1; - while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) - { ref++; } return ref; } diff --git a/lib/vssolution.hpp b/lib/vssolution.hpp index d46c6ef0..4b83e078 100644 --- a/lib/vssolution.hpp +++ b/lib/vssolution.hpp @@ -77,7 +77,7 @@ class VisualizationSceneSolution : public VisualizationSceneScalarData Vector &values, int sides, Array &lvl, int flat = 0); - int GetAutoRefineFactor(); + virtual int GetFunctionAutoRefineFactor() override; // Used for drawing markers for element and vertex numbering double GetElementLengthScale(int k); diff --git a/lib/vssolution3d.cpp b/lib/vssolution3d.cpp index 8044284f..208c0662 100644 --- a/lib/vssolution3d.cpp +++ b/lib/vssolution3d.cpp @@ -917,59 +917,41 @@ void VisualizationSceneSolution3d::SetRefineFactors(int f, int ignored) } } -int VisualizationSceneSolution3d::GetAutoRefineFactor() +int VisualizationSceneSolution3d::GetFunctionAutoRefineFactor() { - const int dim = mesh->Dimension(); - const int ne = (dim == 3)?(mesh->GetNBE()):(mesh->GetNE()); - - //determine the refinement based on the order of the mesh and grid function - int order_ref = 1; + if (!GridF) { return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(); } //grid function - if (GridF) + + const int dim = mesh->Dimension(); + int ref = 1; + if (dim == 3) { - for (int i = 0; i < ne; i++) + for (int i = 0; i < mesh->GetNBE(); i++) { - const FiniteElement &fe = (dim == 3)?(*GridF->FESpace()->GetBE(i)) - :(*GridF->FESpace()->GetFE(i)); + const FiniteElement &fe = *GridF->FESpace()->GetBE(i); int order = fe.GetOrder(); if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) { - if (dim == 3) - { - order += mesh->GetBdrElementTransformation(i)->OrderW(); - } - else - { - order += mesh->GetElementTransformation(i)->OrderW(); - } + order += mesh->GetBdrElementTransformation(i)->OrderW(); } - order_ref = std::max(order_ref, 2 * order); + ref = std::max(ref, 2 * order); } } else { - order_ref = (sol->Size() == mesh->GetNV())?(2):(1); - } - - //mesh - const FiniteElementSpace *nfes = mesh->GetNodalFESpace(); - if (nfes) - { - const int order = nfes->GetMaxElementOrder(); - order_ref = std::max(order_ref, 2 * order); + for (int i = 0; i < mesh->GetNE(); i++) + { + const FiniteElement &fe = *GridF->FESpace()->GetFE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetElementTransformation(i)->OrderW(); + } + ref = std::max(ref, 2 * order); + } } - //limit the total number of elements - int auto_ref_surf_elem = ne*(order_ref+1)*(order_ref+1); - auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, - auto_ref_min_surf_elem), auto_ref_max_surf_elem); - - //approach the given number of elements - int ref = 1; - while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) - { ref++; } - return ref; } diff --git a/lib/vssolution3d.hpp b/lib/vssolution3d.hpp index 1b3336ce..f798406c 100644 --- a/lib/vssolution3d.hpp +++ b/lib/vssolution3d.hpp @@ -101,7 +101,7 @@ class VisualizationSceneSolution3d : public VisualizationSceneScalarData const int nh, const int face_splits, const DenseMatrix *grad = NULL); - int GetAutoRefineFactor(); + virtual int GetFunctionAutoRefineFactor() override; bool CheckPositions(Array &vertices) const { From 9033ce8a4b5dda664a1076e8700101764d2315ff Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 12:27:00 -0700 Subject: [PATCH 06/34] Added auto refinement to 2D vectors. --- lib/vsvector.cpp | 25 +++++++++++++++++++++++++ lib/vsvector.hpp | 2 ++ 2 files changed, 27 insertions(+) diff --git a/lib/vsvector.cpp b/lib/vsvector.cpp index 96e3b317..0b8e8d4d 100644 --- a/lib/vsvector.cpp +++ b/lib/vsvector.cpp @@ -883,6 +883,31 @@ void VisualizationSceneVector::DrawVector(double px, double py, double vx, } } +int VisualizationSceneVector::GetFunctionAutoRefineFactor() +{ + if (!VecGridF) + { + return (solx->Size() == mesh->GetNV() || soly->Size() == mesh->GetNV())?(2):(1); + } + + //grid function + + const int ne = mesh->GetNE(); + int ref = 1; + for (int i = 0; i < ne; i++) + { + const FiniteElement &fe = *VecGridF->FESpace()->GetFE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetElementTransformation(i)->OrderW(); + } + ref = std::max(ref, 2 * order); + } + + return ref; +} + void VisualizationSceneVector::PrepareVectorField() { int rerun; diff --git a/lib/vsvector.hpp b/lib/vsvector.hpp index 5593f466..ee3b8962 100644 --- a/lib/vsvector.hpp +++ b/lib/vsvector.hpp @@ -45,6 +45,8 @@ class VisualizationSceneVector : public VisualizationSceneSolution Vector vc0; IsoparametricTransformation T0; + virtual int GetFunctionAutoRefineFactor() override; + public: VisualizationSceneVector(Mesh &m, Vector &sx, Vector &sy, Mesh *mc = NULL); VisualizationSceneVector(GridFunction &vgf); From 22a2c6a32b2c8fc6dc2d5cb48c288b7c495d3654 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 12:31:54 -0700 Subject: [PATCH 07/34] Added auto refinement to 3D vectors. --- lib/vsvector3d.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/vsvector3d.hpp | 2 ++ 2 files changed, 46 insertions(+) diff --git a/lib/vsvector3d.cpp b/lib/vsvector3d.cpp index 244ed611..2de43db9 100644 --- a/lib/vsvector3d.cpp +++ b/lib/vsvector3d.cpp @@ -440,6 +440,50 @@ void VisualizationSceneVector3d::Init() } } +int VisualizationSceneVector3d::GetFunctionAutoRefineFactor() +{ + if (!VecGridF) + { + return (solx->Size() == mesh->GetNV() + || soly->Size() == mesh->GetNV() + || solz->Size() == mesh->GetNV()) + ?(2):(1); + } + + //grid function + + const int dim = mesh->Dimension(); + int ref = 1; + if (dim == 3) + { + for (int i = 0; i < mesh->GetNBE(); i++) + { + const FiniteElement &fe = *VecGridF->FESpace()->GetBE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetBdrElementTransformation(i)->OrderW(); + } + ref = std::max(ref, 2 * order); + } + } + else + { + for (int i = 0; i < mesh->GetNE(); i++) + { + const FiniteElement &fe = *VecGridF->FESpace()->GetFE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetElementTransformation(i)->OrderW(); + } + ref = std::max(ref, 2 * order); + } + } + + return ref; +} + VisualizationSceneVector3d::~VisualizationSceneVector3d() { delete sol; diff --git a/lib/vsvector3d.hpp b/lib/vsvector3d.hpp index 204bc735..a4cf6808 100644 --- a/lib/vsvector3d.hpp +++ b/lib/vsvector3d.hpp @@ -33,6 +33,8 @@ class VisualizationSceneVector3d : public VisualizationSceneSolution3d Array vflevel; Array dvflevel; + virtual int GetFunctionAutoRefineFactor() override; + public: int ianim, ianimd, ianimmax, drawdisp; From f899b96df4a76d6c487a0835d8a3df2f0c1781a8 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 13:04:56 -0700 Subject: [PATCH 08/34] Removed overrides. --- lib/vssolution.hpp | 2 +- lib/vssolution3d.hpp | 2 +- lib/vsvector.hpp | 2 +- lib/vsvector3d.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vssolution.hpp b/lib/vssolution.hpp index 4b83e078..8a2c3745 100644 --- a/lib/vssolution.hpp +++ b/lib/vssolution.hpp @@ -77,7 +77,7 @@ class VisualizationSceneSolution : public VisualizationSceneScalarData Vector &values, int sides, Array &lvl, int flat = 0); - virtual int GetFunctionAutoRefineFactor() override; + virtual int GetFunctionAutoRefineFactor(); // Used for drawing markers for element and vertex numbering double GetElementLengthScale(int k); diff --git a/lib/vssolution3d.hpp b/lib/vssolution3d.hpp index f798406c..28696d64 100644 --- a/lib/vssolution3d.hpp +++ b/lib/vssolution3d.hpp @@ -101,7 +101,7 @@ class VisualizationSceneSolution3d : public VisualizationSceneScalarData const int nh, const int face_splits, const DenseMatrix *grad = NULL); - virtual int GetFunctionAutoRefineFactor() override; + virtual int GetFunctionAutoRefineFactor(); bool CheckPositions(Array &vertices) const { diff --git a/lib/vsvector.hpp b/lib/vsvector.hpp index ee3b8962..4dc6817b 100644 --- a/lib/vsvector.hpp +++ b/lib/vsvector.hpp @@ -45,7 +45,7 @@ class VisualizationSceneVector : public VisualizationSceneSolution Vector vc0; IsoparametricTransformation T0; - virtual int GetFunctionAutoRefineFactor() override; + virtual int GetFunctionAutoRefineFactor(); public: VisualizationSceneVector(Mesh &m, Vector &sx, Vector &sy, Mesh *mc = NULL); diff --git a/lib/vsvector3d.hpp b/lib/vsvector3d.hpp index a4cf6808..158e4834 100644 --- a/lib/vsvector3d.hpp +++ b/lib/vsvector3d.hpp @@ -33,7 +33,7 @@ class VisualizationSceneVector3d : public VisualizationSceneSolution3d Array vflevel; Array dvflevel; - virtual int GetFunctionAutoRefineFactor() override; + virtual int GetFunctionAutoRefineFactor(); public: int ianim, ianimd, ianimmax, drawdisp; From 4dcc1ac064052bab2479720cb99d1ecf9631be3b Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 13:36:54 -0700 Subject: [PATCH 09/34] Centralized GF auto refinement order calculation. --- lib/vsdata.cpp | 35 +++++++++++++++++++++++++++++++++++ lib/vsdata.hpp | 1 + lib/vssolution.cpp | 17 +---------------- lib/vssolution3d.cpp | 33 +-------------------------------- lib/vsvector.cpp | 17 +---------------- lib/vsvector3d.cpp | 33 +-------------------------------- 6 files changed, 40 insertions(+), 96 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 49cdae2d..64fea8cc 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -47,6 +47,41 @@ void VisualizationSceneScalarData::FixValueRange() } } +int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) +{ + Mesh *mesh = gf.FESpace()->GetMesh(); + const int dim = mesh->Dimension(); + int ref = 1; + if (dim == 3) + { + for (int i = 0; i < mesh->GetNBE(); i++) + { + const FiniteElement &fe = *gf.FESpace()->GetBE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetBdrElementTransformation(i)->OrderW(); + } + ref = std::max(ref, 2 * order); + } + } + else + { + for (int i = 0; i < mesh->GetNE(); i++) + { + const FiniteElement &fe = *gf.FESpace()->GetFE(i); + int order = fe.GetOrder(); + if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetElementTransformation(i)->OrderW(); + } + ref = std::max(ref, 2 * order); + } + } + + return ref; +} + int VisualizationSceneScalarData::GetFunctionAutoRefineFactor() { if (!sol) { return 1; } diff --git a/lib/vsdata.hpp b/lib/vsdata.hpp index 72543fd7..5d230266 100644 --- a/lib/vsdata.hpp +++ b/lib/vsdata.hpp @@ -138,6 +138,7 @@ class VisualizationSceneScalarData : public VisualizationScene void FixValueRange(); + static int GetFunctionAutoRefineFactor(GridFunction &gf); virtual int GetFunctionAutoRefineFactor(); virtual int GetAutoRefineFactor(); diff --git a/lib/vssolution.cpp b/lib/vssolution.cpp index 1b792cc1..7742dd87 100644 --- a/lib/vssolution.cpp +++ b/lib/vssolution.cpp @@ -990,22 +990,7 @@ int VisualizationSceneSolution::GetFunctionAutoRefineFactor() { if (!rsol) { return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(); } - //grid function - - const int ne = mesh->GetNE(); - int ref = 1; - for (int i = 0; i < ne; i++) - { - const FiniteElement &fe = *rsol->FESpace()->GetFE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetElementTransformation(i)->OrderW(); - } - ref = std::max(ref, 2 * order); - } - - return ref; + return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*rsol); } void VisualizationSceneSolution::AutoRefine() diff --git a/lib/vssolution3d.cpp b/lib/vssolution3d.cpp index 208c0662..99212b83 100644 --- a/lib/vssolution3d.cpp +++ b/lib/vssolution3d.cpp @@ -921,38 +921,7 @@ int VisualizationSceneSolution3d::GetFunctionAutoRefineFactor() { if (!GridF) { return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(); } - //grid function - - const int dim = mesh->Dimension(); - int ref = 1; - if (dim == 3) - { - for (int i = 0; i < mesh->GetNBE(); i++) - { - const FiniteElement &fe = *GridF->FESpace()->GetBE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetBdrElementTransformation(i)->OrderW(); - } - ref = std::max(ref, 2 * order); - } - } - else - { - for (int i = 0; i < mesh->GetNE(); i++) - { - const FiniteElement &fe = *GridF->FESpace()->GetFE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetElementTransformation(i)->OrderW(); - } - ref = std::max(ref, 2 * order); - } - } - - return ref; + return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*GridF); } void VisualizationSceneSolution3d::AutoRefine() diff --git a/lib/vsvector.cpp b/lib/vsvector.cpp index 0b8e8d4d..7f52d049 100644 --- a/lib/vsvector.cpp +++ b/lib/vsvector.cpp @@ -890,22 +890,7 @@ int VisualizationSceneVector::GetFunctionAutoRefineFactor() return (solx->Size() == mesh->GetNV() || soly->Size() == mesh->GetNV())?(2):(1); } - //grid function - - const int ne = mesh->GetNE(); - int ref = 1; - for (int i = 0; i < ne; i++) - { - const FiniteElement &fe = *VecGridF->FESpace()->GetFE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetElementTransformation(i)->OrderW(); - } - ref = std::max(ref, 2 * order); - } - - return ref; + return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*VecGridF); } void VisualizationSceneVector::PrepareVectorField() diff --git a/lib/vsvector3d.cpp b/lib/vsvector3d.cpp index 2de43db9..9bbbfedb 100644 --- a/lib/vsvector3d.cpp +++ b/lib/vsvector3d.cpp @@ -450,38 +450,7 @@ int VisualizationSceneVector3d::GetFunctionAutoRefineFactor() ?(2):(1); } - //grid function - - const int dim = mesh->Dimension(); - int ref = 1; - if (dim == 3) - { - for (int i = 0; i < mesh->GetNBE(); i++) - { - const FiniteElement &fe = *VecGridF->FESpace()->GetBE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetBdrElementTransformation(i)->OrderW(); - } - ref = std::max(ref, 2 * order); - } - } - else - { - for (int i = 0; i < mesh->GetNE(); i++) - { - const FiniteElement &fe = *VecGridF->FESpace()->GetFE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetElementTransformation(i)->OrderW(); - } - ref = std::max(ref, 2 * order); - } - } - - return ref; + return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*VecGridF); } VisualizationSceneVector3d::~VisualizationSceneVector3d() From 41c88f25794e44148ac85a45203ba3f710d72379 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 13:53:01 -0700 Subject: [PATCH 10/34] Updated changelog. --- CHANGELOG | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 875a3e33..5465b3d0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,9 +12,11 @@ Version 4.2.1 (development) =========================== -- Increased the default auto-refinement limits to maximum of 32 refinement - levels or 5M elements. Note that you may still need to press 'o' if the mesh - is larger and/or appears not as curved as it should be. +- Changed the auto refinement algorithm, which is now based on the order of + the grid function and mesh. The total number of elements is limited to the + range between 100k and 2M. If the upper limit is reached a warning is shown + and you may still need to press 'o' if you want to increase the refinement + even further. - Significantly improved memory usage. From 616c6ee99f77573272052a001202464d916c78e2 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 14:01:51 -0700 Subject: [PATCH 11/34] Added a warning for under-resolved function. --- lib/vsdata.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 64fea8cc..4d30957a 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -115,6 +115,12 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) { ref++; } + if (ref < order_ref) + { + cout << "Warning: the automatic refinement does not resolve the function fully" + << endl; + } + return ref; } From 990923f4c6ec11928608427ba22e808d1a45f43b Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 15:04:47 -0700 Subject: [PATCH 12/34] Fix for spaces without faces. --- lib/vsdata.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 4d30957a..a93366fd 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -56,11 +56,27 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) { for (int i = 0; i < mesh->GetNBE(); i++) { - const FiniteElement &fe = *gf.FESpace()->GetBE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) + const int f = mesh->GetBdrElementFaceIndex(i); + const FiniteElement *fe = gf.FESpace()->GetFaceElement(f); + int order; + if (fe) { - order += mesh->GetBdrElementTransformation(i)->OrderW(); + order = fe->GetOrder(); + if (fe->GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetBdrElementTransformation(i)->OrderW(); + } + } + else + { + int ivol, info; + mesh->GetBdrElementAdjacentElement(i, ivol, info); + const FiniteElement *fevol = gf.FESpace()->GetFE(ivol); + order = fevol->GetOrder() - 1; + if (fevol->GetMapType() == FiniteElement::MapType::INTEGRAL) + { + order += mesh->GetElementTransformation(ivol)->OrderW(); + } } ref = std::max(ref, 2 * order); } From a69ce90ec92bd793b8b79d6f7fb90f01d6895708 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 15:30:04 -0700 Subject: [PATCH 13/34] Fix for aborting FE collections. --- lib/vsdata.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index a93366fd..1136eb86 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -57,7 +57,12 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) for (int i = 0; i < mesh->GetNBE(); i++) { const int f = mesh->GetBdrElementFaceIndex(i); - const FiniteElement *fe = gf.FESpace()->GetFaceElement(f); + const FiniteElementCollection *fec = gf.FESpace()->FEColl(); + const FiniteElement *fe = NULL; + if (fec && fec->GetContType() != FiniteElementCollection::DISCONTINUOUS) + { + fe = gf.FESpace()->GetFaceElement(f);//might abort instead of returning NULL! + } int order; if (fe) { From 3048c16cd5c0f8f3105685a1c209f04a2975a49b Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 22 Jul 2024 17:08:59 -0700 Subject: [PATCH 14/34] Rebalanced data --- tests/data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data b/tests/data index 81de802a..1b14fa58 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 81de802ad63ba41cd1fcd3825fbb3d2471538ace +Subproject commit 1b14fa584e92bc73aaedc1183b551849a814e8c0 From 89b3907d7a454f4473bd46ee19441d30fb2d478a Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Tue, 23 Jul 2024 08:28:44 -0700 Subject: [PATCH 15/34] Changed the function refinement to 2*order-1. --- lib/vsdata.cpp | 13 +++---------- lib/vsdata.hpp | 2 +- lib/vssolution.cpp | 2 +- lib/vssolution3d.cpp | 2 +- lib/vsvector.cpp | 5 +---- lib/vsvector3d.cpp | 8 +------- tests/data | 2 +- 7 files changed, 9 insertions(+), 25 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 1136eb86..ef788333 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -83,7 +83,7 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) order += mesh->GetElementTransformation(ivol)->OrderW(); } } - ref = std::max(ref, 2 * order); + ref = std::max(ref, 2 * order - 1); } } else @@ -96,20 +96,13 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) { order += mesh->GetElementTransformation(i)->OrderW(); } - ref = std::max(ref, 2 * order); + ref = std::max(ref, 2 * order - 1); } } return ref; } -int VisualizationSceneScalarData::GetFunctionAutoRefineFactor() -{ - if (!sol) { return 1; } - - return (sol->Size() == mesh->GetNV())?(2):(1); -} - int VisualizationSceneScalarData::GetAutoRefineFactor() { const int dim = mesh->Dimension(); @@ -123,7 +116,7 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() if (nfes) { const int order = nfes->GetMaxElementOrder(); - order_ref = std::max(order_ref, 2 * order); + order_ref = std::max(order_ref, 2 * order - 1); } //limit the total number of elements diff --git a/lib/vsdata.hpp b/lib/vsdata.hpp index 5d230266..3213da16 100644 --- a/lib/vsdata.hpp +++ b/lib/vsdata.hpp @@ -139,7 +139,7 @@ class VisualizationSceneScalarData : public VisualizationScene void FixValueRange(); static int GetFunctionAutoRefineFactor(GridFunction &gf); - virtual int GetFunctionAutoRefineFactor(); + virtual int GetFunctionAutoRefineFactor() = 0; virtual int GetAutoRefineFactor(); void Cone(gl3::GlDrawable& buf, glm::mat4 transform, double cval); diff --git a/lib/vssolution.cpp b/lib/vssolution.cpp index 7742dd87..1e301df3 100644 --- a/lib/vssolution.cpp +++ b/lib/vssolution.cpp @@ -988,7 +988,7 @@ void VisualizationSceneSolution::SetRefineFactors(int tot, int bdr) int VisualizationSceneSolution::GetFunctionAutoRefineFactor() { - if (!rsol) { return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(); } + if (!rsol) { return 1; } return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*rsol); } diff --git a/lib/vssolution3d.cpp b/lib/vssolution3d.cpp index 99212b83..92dcd744 100644 --- a/lib/vssolution3d.cpp +++ b/lib/vssolution3d.cpp @@ -919,7 +919,7 @@ void VisualizationSceneSolution3d::SetRefineFactors(int f, int ignored) int VisualizationSceneSolution3d::GetFunctionAutoRefineFactor() { - if (!GridF) { return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(); } + if (!GridF) { return 1; } return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*GridF); } diff --git a/lib/vsvector.cpp b/lib/vsvector.cpp index 7f52d049..8c71e7fe 100644 --- a/lib/vsvector.cpp +++ b/lib/vsvector.cpp @@ -885,10 +885,7 @@ void VisualizationSceneVector::DrawVector(double px, double py, double vx, int VisualizationSceneVector::GetFunctionAutoRefineFactor() { - if (!VecGridF) - { - return (solx->Size() == mesh->GetNV() || soly->Size() == mesh->GetNV())?(2):(1); - } + if (!VecGridF) { return 1;} return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*VecGridF); } diff --git a/lib/vsvector3d.cpp b/lib/vsvector3d.cpp index 9bbbfedb..99e33bba 100644 --- a/lib/vsvector3d.cpp +++ b/lib/vsvector3d.cpp @@ -442,13 +442,7 @@ void VisualizationSceneVector3d::Init() int VisualizationSceneVector3d::GetFunctionAutoRefineFactor() { - if (!VecGridF) - { - return (solx->Size() == mesh->GetNV() - || soly->Size() == mesh->GetNV() - || solz->Size() == mesh->GetNV()) - ?(2):(1); - } + if (!VecGridF) { return 1; } return VisualizationSceneScalarData::GetFunctionAutoRefineFactor(*VecGridF); } diff --git a/tests/data b/tests/data index 1b14fa58..cba23ca9 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 1b14fa584e92bc73aaedc1183b551849a814e8c0 +Subproject commit cba23ca9af827fcbf2d4a89184016555a408103c From 9c02e56cb72a2a4943fd1d234c4089f58c937084 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Thu, 25 Jul 2024 09:14:21 -0700 Subject: [PATCH 16/34] Removed minus one in volumetric elements. --- lib/vsdata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 78e86b26..b516d94d 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -77,7 +77,7 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) int ivol, info; mesh->GetBdrElementAdjacentElement(i, ivol, info); const FiniteElement *fevol = gf.FESpace()->GetFE(ivol); - order = fevol->GetOrder() - 1; + order = fevol->GetOrder(); if (fevol->GetMapType() == FiniteElement::MapType::INTEGRAL) { order += mesh->GetElementTransformation(ivol)->OrderW(); From 16c53191bc9ca77b28134b6ebb1520a6074efccc Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 09:06:56 -0700 Subject: [PATCH 17/34] Reduced mesh-based refinement to order. --- lib/vsdata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 30250dde..f19b7a91 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -116,7 +116,7 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() if (nfes) { const int order = nfes->GetMaxElementOrder(); - order_ref = std::max(order_ref, 2 * order - 1); + order_ref = std::max(order_ref, order); } //limit the total number of elements From 114bfdfb703e03999b658a07791c71b3ef7b5877 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 09:09:26 -0700 Subject: [PATCH 18/34] Reduced function-based refinement to the max FE order. --- lib/vsdata.cpp | 51 ++------------------------------------------------ 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index f19b7a91..40dec834 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -51,56 +51,9 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) { Mesh *mesh = gf.FESpace()->GetMesh(); const int dim = mesh->Dimension(); - int ref = 1; - if (dim == 3) - { - for (int i = 0; i < mesh->GetNBE(); i++) - { - const int f = mesh->GetBdrElementFaceIndex(i); - const FiniteElementCollection *fec = gf.FESpace()->FEColl(); - const FiniteElement *fe = NULL; - if (fec && fec->GetContType() != FiniteElementCollection::DISCONTINUOUS) - { - fe = gf.FESpace()->GetFaceElement(f);//might abort instead of returning NULL! - } - int order; - if (fe) - { - order = fe->GetOrder(); - if (fe->GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetBdrElementTransformation(i)->OrderW(); - } - } - else - { - int ivol, info; - mesh->GetBdrElementAdjacentElement(i, ivol, info); - const FiniteElement *fevol = gf.FESpace()->GetFE(ivol); - order = fevol->GetOrder(); - if (fevol->GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetElementTransformation(ivol)->OrderW(); - } - } - ref = std::max(ref, 2 * order - 1); - } - } - else - { - for (int i = 0; i < mesh->GetNE(); i++) - { - const FiniteElement &fe = *gf.FESpace()->GetFE(i); - int order = fe.GetOrder(); - if (fe.GetMapType() == FiniteElement::MapType::INTEGRAL) - { - order += mesh->GetElementTransformation(i)->OrderW(); - } - ref = std::max(ref, 2 * order - 1); - } - } + const int order = gf.FESpace()->GetMaxElementOrder(); - return ref; + return order; } int VisualizationSceneScalarData::GetAutoRefineFactor() From 19a1d32fd4ddbe4a2b8466ed0a49411a45ad0417 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 09:23:56 -0700 Subject: [PATCH 19/34] Added a check for integral finite elements and showing a warning. --- lib/vsdata.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 40dec834..c0369ef2 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -50,9 +50,18 @@ void VisualizationSceneScalarData::FixValueRange() int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) { Mesh *mesh = gf.FESpace()->GetMesh(); - const int dim = mesh->Dimension(); const int order = gf.FESpace()->GetMaxElementOrder(); + //check for integral elements + const int dim = mesh->Dimension(); + const FiniteElementCollection *fec = gf.FESpace()->FEColl(); + if (fec && fec->GetMapType(dim) == FiniteElement::INTEGRAL) + { + cout << "Warning: integral elements are non-polynomial in the physical space,\n" + << " consider increasing the refinement by the key 'o'." + << endl; + } + return order; } From 5f6ca6f187912a9167988e9be1919c5db536b484 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 09:41:02 -0700 Subject: [PATCH 20/34] Minor fix to return refinement 1 for constant elements. --- lib/vsdata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index c0369ef2..34aefdef 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -62,7 +62,7 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) << endl; } - return order; + return std::max(order, 1); } int VisualizationSceneScalarData::GetAutoRefineFactor() From d479ac8eeb922a38421d047743076e0ddec83bb5 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 10:12:34 -0700 Subject: [PATCH 21/34] Rebalanced tests/data. --- tests/data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data b/tests/data index f86e3c4a..2c431f13 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit f86e3c4acdf8420a4f36dff0b36cbbe6936caa49 +Subproject commit 2c431f13a6ecb5abb1a2d87a5747497bd29746ea From 19ed072a84c950de52d246ae705c23bbc02bcaba Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 15:01:22 -0700 Subject: [PATCH 22/34] Fixed comments. --- lib/vsdata.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 34aefdef..d2bf29c7 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -52,7 +52,7 @@ int VisualizationSceneScalarData::GetFunctionAutoRefineFactor(GridFunction &gf) Mesh *mesh = gf.FESpace()->GetMesh(); const int order = gf.FESpace()->GetMaxElementOrder(); - //check for integral elements + // check for integral elements const int dim = mesh->Dimension(); const FiniteElementCollection *fec = gf.FESpace()->FEColl(); if (fec && fec->GetMapType(dim) == FiniteElement::INTEGRAL) @@ -70,10 +70,10 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() const int dim = mesh->Dimension(); const int ne = (dim == 3)?(mesh->GetNBE()):(mesh->GetNE()); - //determine the refinement based on the order of the mesh and grid function + // determine the refinement based on the order of the mesh and grid function int order_ref = GetFunctionAutoRefineFactor(); - //mesh + // mesh const FiniteElementSpace *nfes = mesh->GetNodalFESpace(); if (nfes) { @@ -81,12 +81,12 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() order_ref = std::max(order_ref, order); } - //limit the total number of elements + // limit the total number of elements int auto_ref_surf_elem = ne*(order_ref+1)*(order_ref+1); auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, auto_ref_min_surf_elem), auto_ref_max_surf_elem); - //approach the given number of elements + // approach the given number of elements int ref = 1; while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) { ref++; } From 2c34c1327d57df9d3f91b3255ff70172e303ecf3 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 15:02:57 -0700 Subject: [PATCH 23/34] Improved refinement warning. --- lib/vsdata.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index d2bf29c7..bc9b5ce2 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -93,7 +93,8 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() if (ref < order_ref) { - cout << "Warning: the automatic refinement does not resolve the function fully" + cout << "Warning: the automatic refinement does not resolve the data fully,\n" + << " consider increasing the refinement by the key 'o'." << endl; } From 73a01745957e62fa8d66c170044c7c5698c68d5b Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Fri, 26 Jul 2024 16:51:51 -0700 Subject: [PATCH 24/34] Fixed auto-refinement formula. --- lib/vsdata.cpp | 2 +- tests/data | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index bc9b5ce2..23ddc4c7 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -82,7 +82,7 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() } // limit the total number of elements - int auto_ref_surf_elem = ne*(order_ref+1)*(order_ref+1); + int auto_ref_surf_elem = ne * order_ref * order_ref; auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, auto_ref_min_surf_elem), auto_ref_max_surf_elem); diff --git a/tests/data b/tests/data index 2c431f13..b8d4bee1 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 2c431f13a6ecb5abb1a2d87a5747497bd29746ea +Subproject commit b8d4bee12f30c503875bcb2cad5531c01c8af1b7 From 70a13e49266286a455c850b322c4cc7f8abb4cb0 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 29 Jul 2024 09:45:25 -0700 Subject: [PATCH 25/34] Improved changelog a bit. --- CHANGELOG | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2518e5ec..8a554346 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,10 +13,12 @@ Version 4.2.1 (development) =========================== - Changed the auto refinement algorithm, which is now based on the order of - the grid function and mesh. The total number of elements is limited to the - range between 100k and 2M. If the upper limit is reached a warning is shown - and you may still need to press 'o' if you want to increase the refinement - even further. + the grid function and mesh. The total number of drawn elements (with the + non-conforming refinement shading) is limited to the range between 100k and + 2M, while the maximum refiment is still limited to 16. If one of the upper + limits is reached a warning is shown that the data are potentially not resolved + and you may still need to press 'o' if you want to increase the refinement even + further. - Significantly improved memory usage. From 9d67ef831e9f7c55f8c4dab188b3650920913391 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 29 Jul 2024 10:08:11 -0700 Subject: [PATCH 26/34] Fixed a typo in ToggleShading(). --- lib/vsdata.hpp | 2 +- lib/vssolution.cpp | 2 +- lib/vssolution3d.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vsdata.hpp b/lib/vsdata.hpp index 7b95ad90..6130b77c 100644 --- a/lib/vsdata.hpp +++ b/lib/vsdata.hpp @@ -206,7 +206,7 @@ class VisualizationSceneScalarData : public VisualizationScene void SetValueRange(double, double); virtual void SetShading(Shading, bool) = 0; - virtual void ToogleShading() { SetShading((Shading)(((int)shading + 1) % (int)Shading::Max), true); } + virtual void ToggleShading() { SetShading((Shading)(((int)shading + 1) % (int)Shading::Max), true); } virtual Shading GetShading() { return shading; } virtual void SetRefineFactors(int, int) = 0; void SetAutoRefineLimits(int max_ref, int max_surf_elem) diff --git a/lib/vssolution.cpp b/lib/vssolution.cpp index 2243ce8d..9cd556ab 100644 --- a/lib/vssolution.cpp +++ b/lib/vssolution.cpp @@ -881,7 +881,7 @@ void VisualizationSceneSolution::ToggleShading() { if (rsol) { - VisualizationSceneScalarData::ToogleShading(); + VisualizationSceneScalarData::ToggleShading(); } else { diff --git a/lib/vssolution3d.cpp b/lib/vssolution3d.cpp index 1416a836..9461339b 100644 --- a/lib/vssolution3d.cpp +++ b/lib/vssolution3d.cpp @@ -892,7 +892,7 @@ void VisualizationSceneSolution3d::ToggleShading() { if (GridF) { - VisualizationSceneScalarData::ToogleShading(); + VisualizationSceneScalarData::ToggleShading(); } else { From f5e68c25ed06401d00d761503bdc40de07b580e3 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 29 Jul 2024 10:24:36 -0700 Subject: [PATCH 27/34] Added overrides to visualization scenes. --- lib/vssolution.hpp | 42 +++++++++++++++++++++--------------------- lib/vssolution3d.hpp | 34 +++++++++++++++++----------------- lib/vsvector.hpp | 24 ++++++++++++------------ lib/vsvector3d.hpp | 16 ++++++++-------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/lib/vssolution.hpp b/lib/vssolution.hpp index b200418a..1e12d136 100644 --- a/lib/vssolution.hpp +++ b/lib/vssolution.hpp @@ -77,7 +77,7 @@ class VisualizationSceneSolution : public VisualizationSceneScalarData Vector &values, int sides, Array &lvl, int flat = 0); - virtual int GetFunctionAutoRefineFactor(); + int GetFunctionAutoRefineFactor() override; // Used for drawing markers for element and vertex numbering double GetElementLengthScale(int k); @@ -92,35 +92,35 @@ class VisualizationSceneSolution : public VisualizationSceneScalarData virtual ~VisualizationSceneSolution(); - virtual std::string GetHelpString() const; + std::string GetHelpString() const override; void SetGridFunction(GridFunction & u) { rsol = &u; } void NewMeshAndSolution(Mesh *new_m, Mesh *new_mc, Vector *new_sol, GridFunction *new_u = NULL); - virtual void SetNewScalingFromBox(); - virtual void FindNewBox(bool prepare); - virtual void FindNewValueRange(bool prepare); - virtual void FindNewBoxAndValueRange(bool prepare) + void SetNewScalingFromBox() override; + void FindNewBox(bool prepare) override; + void FindNewValueRange(bool prepare) override; + void FindNewBoxAndValueRange(bool prepare) override { FindNewBox(prepare); } - virtual void FindMeshBox(bool prepare); + void FindMeshBox(bool prepare) override; - virtual void ToggleLogscale(bool print); - virtual void EventUpdateBackground(); - virtual void EventUpdateColors(); - virtual void UpdateLevelLines() { PrepareLevelCurves(); } - virtual void UpdateValueRange(bool prepare); + void ToggleLogscale(bool print) override; + void EventUpdateBackground() override; + void EventUpdateColors() override; + void UpdateLevelLines() override { PrepareLevelCurves(); } + void UpdateValueRange(bool prepare) override; void PrepareWithNormals(); void PrepareFlat(); void PrepareFlat2(); - virtual void PrepareLines(); + void PrepareLines() override; void PrepareLines2(); void PrepareLines3(); - virtual void Prepare(); + void Prepare() override; void PrepareLevelCurves(); void PrepareLevelCurves2(); @@ -140,12 +140,12 @@ class VisualizationSceneSolution : public VisualizationSceneScalarData void PrepareCP(); - virtual gl3::SceneInfo GetSceneObjs(); + gl3::SceneInfo GetSceneObjs() override; void glTF_ExportBoundary(glTF_Builder &bld, glTF_Builder::buffer_id buffer, glTF_Builder::material_id black_mat); - virtual void glTF_Export(); + void glTF_Export() override; void ToggleDrawBdr(); @@ -164,17 +164,17 @@ class VisualizationSceneSolution : public VisualizationSceneScalarData PrepareNumbering(false); } - virtual void SetShading(Shading, bool); - virtual void ToggleShading(); + void SetShading(Shading, bool) override; + void ToggleShading() override; void ToggleDrawCP() { draw_cp = !draw_cp; PrepareCP(); } void ToggleRefinements(); void ToggleRefinementFunction(); - virtual void SetRefineFactors(int, int); - virtual void AutoRefine(); - virtual void ToggleAttributes(Array &attr_list); + void SetRefineFactors(int, int) override; + void AutoRefine() override; + void ToggleAttributes(Array &attr_list) override; virtual void SetDrawMesh(int i) { drawmesh = i % 3; } virtual int GetDrawMesh() { return drawmesh; } diff --git a/lib/vssolution3d.hpp b/lib/vssolution3d.hpp index 991dae08..ce12bdf1 100644 --- a/lib/vssolution3d.hpp +++ b/lib/vssolution3d.hpp @@ -101,7 +101,7 @@ class VisualizationSceneSolution3d : public VisualizationSceneScalarData const int nh, const int face_splits, const DenseMatrix *grad = NULL); - virtual int GetFunctionAutoRefineFactor(); + int GetFunctionAutoRefineFactor() override; bool CheckPositions(Array &vertices) const { @@ -129,22 +129,22 @@ class VisualizationSceneSolution3d : public VisualizationSceneScalarData virtual ~VisualizationSceneSolution3d(); - virtual std::string GetHelpString() const; + std::string GetHelpString() const override; - virtual void FindNewBox(bool prepare); - virtual void FindNewValueRange(bool prepare); + void FindNewBox(bool prepare) override; + void FindNewValueRange(bool prepare) override; - virtual void PrepareRuler() + void PrepareRuler() override { VisualizationSceneScalarData::PrepareRuler(false); } virtual void PrepareFlat(); - virtual void PrepareLines(); - virtual void Prepare(); + void PrepareLines() override; + void Prepare() override; virtual void PrepareOrderingCurve(); virtual void PrepareOrderingCurve1(gl3::GlDrawable& buf, bool arrows, bool color); - virtual gl3::SceneInfo GetSceneObjs(); + gl3::SceneInfo GetSceneObjs() override; - virtual void glTF_Export(); + void glTF_Export() override; void ToggleDrawElems() { drawelems = !drawelems; Prepare(); } @@ -155,11 +155,11 @@ class VisualizationSceneSolution3d : public VisualizationSceneScalarData // 3 - no arrows (black), 4 - with arrows (black) void ToggleDrawOrdering() { draworder = (draworder+1)%5; } - virtual void SetShading(Shading, bool); - virtual void ToggleShading(); - virtual void SetRefineFactors(int, int); - virtual void AutoRefine(); - virtual void ToggleAttributes(Array &attr_list); + void SetShading(Shading, bool) override; + void ToggleShading() override; + void SetRefineFactors(int, int) override; + void AutoRefine() override; + void ToggleAttributes(Array &attr_list) override; void FindNodePos(); @@ -188,10 +188,10 @@ class VisualizationSceneSolution3d : public VisualizationSceneScalarData void ToggleCPAlgorithm(); void MoveLevelSurf(int); void NumberOfLevelSurf(int); - virtual void EventUpdateColors(); - virtual void UpdateLevelLines() + void EventUpdateColors() override; + void UpdateLevelLines() override { PrepareLines(); PrepareCuttingPlaneLines(); } - virtual void UpdateValueRange(bool prepare); + void UpdateValueRange(bool prepare) override; virtual void SetDrawMesh(int i) { diff --git a/lib/vsvector.hpp b/lib/vsvector.hpp index 48c1963f..46dd8209 100644 --- a/lib/vsvector.hpp +++ b/lib/vsvector.hpp @@ -30,11 +30,11 @@ class VisualizationSceneVector : public VisualizationSceneSolution void Init(); - virtual void GetRefinedValues(int i, const IntegrationRule &ir, - Vector &vals, DenseMatrix &tr); - virtual int GetRefinedValuesAndNormals(int i, const IntegrationRule &ir, - Vector &vals, DenseMatrix &tr, - DenseMatrix &normals); + void GetRefinedValues(int i, const IntegrationRule &ir, + Vector &vals, DenseMatrix &tr) override; + int GetRefinedValuesAndNormals(int i, const IntegrationRule &ir, + Vector &vals, DenseMatrix &tr, + DenseMatrix &normals) override; double (*Vec2Scalar)(double, double); @@ -45,7 +45,7 @@ class VisualizationSceneVector : public VisualizationSceneSolution Vector vc0; IsoparametricTransformation T0; - virtual int GetFunctionAutoRefineFactor(); + int GetFunctionAutoRefineFactor() override; public: VisualizationSceneVector(Mesh &m, Vector &sx, Vector &sy, Mesh *mc = NULL); @@ -55,14 +55,14 @@ class VisualizationSceneVector : public VisualizationSceneSolution virtual ~VisualizationSceneVector(); - virtual std::string GetHelpString() const; + std::string GetHelpString() const override; void NPressed(); void PrepareDisplacedMesh(); - virtual void PrepareLines() + void PrepareLines() override { VisualizationSceneSolution::PrepareLines(); PrepareDisplacedMesh(); } - virtual void ToggleDrawElems(); + void ToggleDrawElems() override; virtual void PrepareVectorField(); void ToggleVectorField(); @@ -76,11 +76,11 @@ class VisualizationSceneVector : public VisualizationSceneSolution } } - virtual gl3::SceneInfo GetSceneObjs(); + gl3::SceneInfo GetSceneObjs() override; - virtual void glTF_Export(); + void glTF_Export() override; - virtual void EventUpdateColors() { Prepare(); PrepareVectorField(); } + void EventUpdateColors() override { Prepare(); PrepareVectorField(); } // refinement factor for the vectors int RefineFactor; diff --git a/lib/vsvector3d.hpp b/lib/vsvector3d.hpp index b7349067..0efcffd6 100644 --- a/lib/vsvector3d.hpp +++ b/lib/vsvector3d.hpp @@ -33,7 +33,7 @@ class VisualizationSceneVector3d : public VisualizationSceneSolution3d Array vflevel; Array dvflevel; - virtual int GetFunctionAutoRefineFactor(); + int GetFunctionAutoRefineFactor() override; public: int ianim, ianimd, ianimmax, drawdisp; @@ -46,12 +46,12 @@ class VisualizationSceneVector3d : public VisualizationSceneSolution3d virtual ~VisualizationSceneVector3d(); - virtual std::string GetHelpString() const; + std::string GetHelpString() const override; void NPressed(); - virtual void PrepareFlat(); - virtual void Prepare(); - virtual void PrepareLines(); + void PrepareFlat() override; + void Prepare() override; + void PrepareLines() override; void PrepareFlat2(); void PrepareLines2(); @@ -66,13 +66,13 @@ class VisualizationSceneVector3d : public VisualizationSceneSolution3d void SetScalarFunction(); void ToggleScalarFunction(); - virtual void PrepareCuttingPlane(); + void PrepareCuttingPlane() override; void ToggleDisplacements() {drawdisp = (drawdisp+1)%2;}; - virtual gl3::SceneInfo GetSceneObjs(); + gl3::SceneInfo GetSceneObjs() override; - virtual void EventUpdateColors() + void EventUpdateColors() override { Prepare(); PrepareVectorField(); PrepareCuttingPlane(); }; void ToggleVectorFieldLevel(int v); From f5c210ead87606ca8686d55367102e0d76f261c1 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 29 Jul 2024 11:24:14 -0700 Subject: [PATCH 28/34] Fixed NewMeshSolution() updates with auto-refinement. --- lib/vssolution.cpp | 13 +++++++------ lib/vssolution3d.cpp | 18 ++++++++++-------- lib/vsvector.cpp | 10 +++++----- lib/vsvector3d.cpp | 15 ++++++++------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/vssolution.cpp b/lib/vssolution.cpp index 9cd556ab..a529d47f 100644 --- a/lib/vssolution.cpp +++ b/lib/vssolution.cpp @@ -589,10 +589,15 @@ void VisualizationSceneSolution::ToggleDrawElems() void VisualizationSceneSolution::NewMeshAndSolution( Mesh *new_m, Mesh *new_mc, Vector *new_sol, GridFunction *new_u) { + Mesh *old_m = mesh; + mesh = new_m; + mesh_coarse = new_mc; + sol = new_sol; + rsol = new_u; + // If the number of elements changes, recompute the refinement factor - if (mesh->GetNE() != new_m->GetNE()) + if (mesh->GetNE() != old_m->GetNE()) { - mesh = new_m; int ref = GetAutoRefineFactor(); if (TimesToRefine != ref || EdgeRefineFactor != 1) { @@ -601,10 +606,6 @@ void VisualizationSceneSolution::NewMeshAndSolution( cout << "Subdivision factors = " << TimesToRefine << ", 1" << endl; } } - mesh = new_m; - mesh_coarse = new_mc; - sol = new_sol; - rsol = new_u; have_sol_range = false; DoAutoscale(false); diff --git a/lib/vssolution3d.cpp b/lib/vssolution3d.cpp index 9461339b..20452f3a 100644 --- a/lib/vssolution3d.cpp +++ b/lib/vssolution3d.cpp @@ -829,12 +829,18 @@ void VisualizationSceneSolution3d::NewMeshAndSolution( delete [] node_pos; node_pos = new double[new_m->GetNV()]; } + + Mesh *old_m = mesh; + mesh = new_m; + mesh_coarse = new_mc; + sol = new_sol; + GridF = new_u; + // If the number of surface elements changes, recompute the refinement factor - if (mesh->Dimension() != new_m->Dimension() || - (mesh->Dimension() == 2 && mesh->GetNE() != new_m->GetNE()) || - (mesh->Dimension() == 3 && mesh->GetNBE() != new_m->GetNBE())) + if (mesh->Dimension() != old_m->Dimension() || + (mesh->Dimension() == 2 && mesh->GetNE() != old_m->GetNE()) || + (mesh->Dimension() == 3 && mesh->GetNBE() != old_m->GetNBE())) { - mesh = new_m; int ref = GetAutoRefineFactor(); if (TimesToRefine != ref) { @@ -842,10 +848,6 @@ void VisualizationSceneSolution3d::NewMeshAndSolution( cout << "Subdivision factor = " << TimesToRefine << endl; } } - mesh = new_m; - mesh_coarse = new_mc; - sol = new_sol; - GridF = new_u; FindNodePos(); DoAutoscale(false); diff --git a/lib/vsvector.cpp b/lib/vsvector.cpp index cf924547..2e5a3fe8 100644 --- a/lib/vsvector.cpp +++ b/lib/vsvector.cpp @@ -418,13 +418,15 @@ void VisualizationSceneVector::NewMeshAndSolution(GridFunction &vgf, Mesh *mc) delete solx; } + Mesh *old_m = mesh; + Mesh *new_mesh = vgf.FESpace()->GetMesh(); + mesh = new_mesh; + mesh_coarse = mc; VecGridF = &vgf; // If the number of elements changes, recompute the refinement factor - Mesh *new_mesh = vgf.FESpace()->GetMesh(); - if (mesh->GetNE() != new_mesh->GetNE()) + if (mesh->GetNE() != old_m->GetNE()) { - mesh = new_mesh; int ref = GetAutoRefineFactor(); if (TimesToRefine != ref || EdgeRefineFactor != 1) { @@ -438,8 +440,6 @@ void VisualizationSceneVector::NewMeshAndSolution(GridFunction &vgf, Mesh *mc) cout << "Vector subdivision factor = 1" << endl; } } - mesh = new_mesh; - mesh_coarse = mc; solx = new Vector(mesh->GetNV()); soly = new Vector(mesh->GetNV()); diff --git a/lib/vsvector3d.cpp b/lib/vsvector3d.cpp index 2d80d982..15bf0119 100644 --- a/lib/vsvector3d.cpp +++ b/lib/vsvector3d.cpp @@ -481,12 +481,16 @@ void VisualizationSceneVector3d::NewMeshAndSolution( node_pos = new double[new_m->GetNV()]; } + Mesh *old_m = mesh; + VecGridF = new_v; + mesh = new_m; + mesh_coarse = new_mc; + // If the number of surface elements changes, recompute the refinement factor - if (mesh->Dimension() != new_m->Dimension() || - (mesh->Dimension() == 2 && mesh->GetNE() != new_m->GetNE()) || - (mesh->Dimension() == 3 && mesh->GetNBE() != new_m->GetNBE())) + if (mesh->Dimension() != old_m->Dimension() || + (mesh->Dimension() == 2 && mesh->GetNE() != old_m->GetNE()) || + (mesh->Dimension() == 3 && mesh->GetNBE() != old_m->GetNBE())) { - mesh = new_m; int ref = GetAutoRefineFactor(); if (TimesToRefine != ref) { @@ -497,9 +501,6 @@ void VisualizationSceneVector3d::NewMeshAndSolution( FiniteElementSpace *new_fes = new_v->FESpace(); - VecGridF = new_v; - mesh = new_m; - mesh_coarse = new_mc; FindNodePos(); sfes = new FiniteElementSpace(mesh, new_fes->FEColl(), 1, From b363f7c05913bbb149298f2f1bcd042d6f571ffa Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Tue, 30 Jul 2024 12:20:48 -0700 Subject: [PATCH 29/34] Changed the auto-refinemt to vertex-based. --- lib/vsdata.cpp | 12 ++++++------ lib/vsdata.hpp | 6 +++--- tests/data | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 23ddc4c7..74e2c22e 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -82,13 +82,13 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() } // limit the total number of elements - int auto_ref_surf_elem = ne * order_ref * order_ref; - auto_ref_surf_elem = std::min(std::max(auto_ref_surf_elem, - auto_ref_min_surf_elem), auto_ref_max_surf_elem); + int auto_ref_surf_vert = ne * (order_ref+1) * (order_ref+1); + auto_ref_surf_vert = std::min(std::max(auto_ref_surf_vert, + auto_ref_min_surf_vert), auto_ref_max_surf_vert); // approach the given number of elements int ref = 1; - while (ref < auto_ref_max && ne*(ref+1)*(ref+1) <= auto_ref_surf_elem) + while (ref < auto_ref_max && ne*(ref+2)*(ref+2) <= auto_ref_surf_vert) { ref++; } if (ref < order_ref) @@ -1375,8 +1375,8 @@ void VisualizationSceneScalarData::Init() scaling = 0; drawaxes = colorbar = 0; auto_ref_max = 16; - auto_ref_min_surf_elem = 100000; - auto_ref_max_surf_elem = 2000000; + auto_ref_min_surf_vert = 100000; + auto_ref_max_surf_vert = 2000000; minv = 0.0; maxv = 1.0; logscale = false; diff --git a/lib/vsdata.hpp b/lib/vsdata.hpp index 6130b77c..9d444a30 100644 --- a/lib/vsdata.hpp +++ b/lib/vsdata.hpp @@ -78,7 +78,7 @@ class VisualizationSceneScalarData : public VisualizationScene int scaling, colorbar, drawaxes; Shading shading; - int auto_ref_max, auto_ref_min_surf_elem, auto_ref_max_surf_elem; + int auto_ref_max, auto_ref_min_surf_vert, auto_ref_max_surf_vert; // Formatter for axes & colorbar numbers. Set defaults. function axis_formatter = NumberFormatter(4, 'd', false); @@ -209,10 +209,10 @@ class VisualizationSceneScalarData : public VisualizationScene virtual void ToggleShading() { SetShading((Shading)(((int)shading + 1) % (int)Shading::Max), true); } virtual Shading GetShading() { return shading; } virtual void SetRefineFactors(int, int) = 0; - void SetAutoRefineLimits(int max_ref, int max_surf_elem) + void SetAutoRefineLimits(int max_ref, int max_surf_vert) { auto_ref_max = max_ref; - auto_ref_max_surf_elem = max_surf_elem; + auto_ref_max_surf_vert = max_surf_vert; } virtual void AutoRefine() = 0; virtual void ToggleAttributes(Array &attr_list) = 0; diff --git a/tests/data b/tests/data index b8d4bee1..a13ecd98 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit b8d4bee12f30c503875bcb2cad5531c01c8af1b7 +Subproject commit a13ecd98ec1fb01a3a41db97058f425e5d2f7c17 From 7bc87090e2fe740ce0fd80df366c96b118d08a37 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Tue, 30 Jul 2024 14:59:07 -0700 Subject: [PATCH 30/34] Updated comments to vertices. --- lib/vsdata.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vsdata.cpp b/lib/vsdata.cpp index 74e2c22e..37338acd 100644 --- a/lib/vsdata.cpp +++ b/lib/vsdata.cpp @@ -81,12 +81,12 @@ int VisualizationSceneScalarData::GetAutoRefineFactor() order_ref = std::max(order_ref, order); } - // limit the total number of elements + // limit the total number of vertices int auto_ref_surf_vert = ne * (order_ref+1) * (order_ref+1); auto_ref_surf_vert = std::min(std::max(auto_ref_surf_vert, auto_ref_min_surf_vert), auto_ref_max_surf_vert); - // approach the given number of elements + // approach the given number of vertices int ref = 1; while (ref < auto_ref_max && ne*(ref+2)*(ref+2) <= auto_ref_surf_vert) { ref++; } From db0e2f66eb87a02ab4a1761993d76be663b806b7 Mon Sep 17 00:00:00 2001 From: Tzanio Kolev Date: Tue, 30 Jul 2024 16:30:58 -0700 Subject: [PATCH 31/34] Updated CHANGELOG --- CHANGELOG | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8a554346..e4efc617 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,13 +12,11 @@ Version 4.2.1 (development) =========================== -- Changed the auto refinement algorithm, which is now based on the order of - the grid function and mesh. The total number of drawn elements (with the - non-conforming refinement shading) is limited to the range between 100k and - 2M, while the maximum refiment is still limited to 16. If one of the upper - limits is reached a warning is shown that the data are potentially not resolved - and you may still need to press 'o' if you want to increase the refinement even - further. +- The GLVis auto refinement algorithm now takes into account the order of the + data (mesh and grid function). The new refinement is chosen to be sufficient + for resolving the curvature of the data, but only if we can do that with less + than 2M vertices and 16 refinements. Otherwise, we print a warning and the + user may still needs to press 'o' to fully resolve the data. - Significantly improved memory usage. From 570e57dea92881536fcc75820743f6f162a819c1 Mon Sep 17 00:00:00 2001 From: Veselin Dobrev Date: Wed, 31 Jul 2024 15:02:24 -0700 Subject: [PATCH 32/34] Add 'Auto-refinement' section at the end of README.md and reference it in CHANGELOG and the beginning of README.md. --- CHANGELOG | 3 ++- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index e4efc617..6bdf0c0f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,7 +16,8 @@ Version 4.2.1 (development) data (mesh and grid function). The new refinement is chosen to be sufficient for resolving the curvature of the data, but only if we can do that with less than 2M vertices and 16 refinements. Otherwise, we print a warning and the - user may still needs to press 'o' to fully resolve the data. + user may still need to press 'o' to fully resolve the data. For more details, + see the section Auto-refinement in README.md. - Significantly improved memory usage. diff --git a/README.md b/README.md index 530fbe73..1c42c7e4 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,12 @@ is a partial list of the available functionality. Some of these keys can also be provided as input, using the `-k` command-line option and the `keys` script command. +For high-order meshes and/or solution data, GLVis performs element subdivision +to try to represent the data more accurately. However, for highly-varying data +or large meshes, the auto-selected subdivision factor (see the +[Auto-refinement](#auto-refinement) section below) may not be sufficient -- use +the keys o / O, described below, to manually adjust the +subdivision factor. SPDX-License-Identifier: BSD-3-Clause
LLNL Release Number: LLNL-CODE-443271
@@ -298,3 +304,46 @@ Key commands - `x`-component: `v_x` - `y`-component: `v_y` - `z`-component: `v_z` + +## Auto-refinement + +The GLVis auto-refinement algorithm selects a subdivision factor trying to +achieve an accurate representation of high-order meshes and solution data while +keeping the initial time to visualize the data reasonable. The algorithm can be +summarized as follows: +- GLVis draws surface elements; the number of drawn elements, `ne`, is either: + - the number of elements in the mesh for 2D meshes (including surface meshes, + i.e. 2D meshes embedded in 3D space), or + - the number of boundary mesh elements described by the mesh in 3D. +- A tentative upper limit on the number of vertices to be drawn is defined based + on the maximum order of the mesh and the solution, `max_order`: + ``` + max_vert = ne * (max_order + 1) * (max_order + 1) + ``` +- To allow more accurate representation for small meshes, this number is + potentially increased: + ``` + max_vert = max(max_vert, 100 000) + ``` +- To keep the time to initially visualize the data reasonable, this number is + potentially reduced: + ``` + max_vert = min(max_vert, 2 000 000) + ``` +- Finally, the subdivision factor `ref` is chosen to be the largest number such + that: + - the number of vertices needed to draw the `ne` surface elements with `ref` + subdivisions does not exceed `max_vert`: + ``` + ne * (ref + 1) * (ref + 1) <= max_vert + ``` + - for large meshes where the above limit cannot be satisfied, set `ref = 1` + - for small meshes, avoid excessive refinements: + ``` + ref <= 16 + ``` + +Note that, for highly-varying data or large meshes, this auto-selected +subdivision factor may not be sufficient for accurate representation. In such +cases the sudivision can be manually adjusted using the keys o / +O, described above. From 05cdf0a9003e5e22f54116e337f68cbd8140709f Mon Sep 17 00:00:00 2001 From: Tzanio Kolev Date: Wed, 31 Jul 2024 16:28:12 -0700 Subject: [PATCH 33/34] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c42c7e4..ad287e42 100644 --- a/README.md +++ b/README.md @@ -345,5 +345,5 @@ summarized as follows: Note that, for highly-varying data or large meshes, this auto-selected subdivision factor may not be sufficient for accurate representation. In such -cases the sudivision can be manually adjusted using the keys o / +cases the subdivision can be manually adjusted using the keys o / O, described above. From a37ae482d05dbb689f5ce6d8e4061bd8e723251b Mon Sep 17 00:00:00 2001 From: Tzanio Kolev Date: Wed, 31 Jul 2024 16:34:13 -0700 Subject: [PATCH 34/34] Switched to updated data files --- tests/data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data b/tests/data index a13ecd98..75f1a071 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit a13ecd98ec1fb01a3a41db97058f425e5d2f7c17 +Subproject commit 75f1a0714b7176a3c9445bd83d2a90e52e1bde48