mirror of
https://github.com/NGSolve/netgen.git
synced 2025-04-15 11:01:22 +05:00
Clean up debugging code
This commit is contained in:
parent
08a00cb32a
commit
dd85220021
@ -8,7 +8,6 @@
|
|||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#include <core/array.hpp>
|
#include <core/array.hpp>
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
namespace netgen
|
namespace netgen
|
||||||
{
|
{
|
||||||
@ -219,11 +218,11 @@ namespace netgen
|
|||||||
|
|
||||||
// print array
|
// print array
|
||||||
template <typename T, int BASE, typename TIND>
|
template <typename T, int BASE, typename TIND>
|
||||||
inline std::ostream & operator<< (std::ostream & s, const NgFlatArray<T,BASE,TIND> & a)
|
inline ostream & operator<< (ostream & s, const NgFlatArray<T,BASE,TIND> & a)
|
||||||
{
|
{
|
||||||
// for (TIND i = a.Begin(); i < a.End(); i++)
|
// for (TIND i = a.Begin(); i < a.End(); i++)
|
||||||
for (auto i : a.Range())
|
for (auto i : a.Range())
|
||||||
s << i << ": " << a[i] << std::endl;
|
s << i << ": " << a[i] << endl;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,10 +555,10 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
inline std::ostream & operator<< (std::ostream & s, const NgIndirectArray<T1,T2> & ia)
|
inline ostream & operator<< (ostream & s, const NgIndirectArray<T1,T2> & ia)
|
||||||
{
|
{
|
||||||
for (int i = ia.Begin(); i < ia.End(); i++)
|
for (int i = ia.Begin(); i < ia.End(); i++)
|
||||||
s << i << ": " << ia[i] << std::endl;
|
s << i << ": " << ia[i] << endl;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,260 +1,100 @@
|
|||||||
#include "debugging.hpp"
|
#include <meshing.hpp>
|
||||||
|
|
||||||
#include <core/python_ngcore.hpp>
|
namespace netgen
|
||||||
|
{
|
||||||
|
unique_ptr<Mesh> GetOpenElements( const Mesh & m, int dom = 0 )
|
||||||
|
{
|
||||||
|
static Timer t("GetOpenElements"); RegionTimer rt(t);
|
||||||
|
auto mesh = make_unique<Mesh>();
|
||||||
|
*mesh = m;
|
||||||
|
|
||||||
#ifdef NETGEN_DEBUGGING_GUI
|
Array<bool, PointIndex> interesting_points(mesh->GetNP());
|
||||||
#include <libusockets.h>
|
interesting_points = false;
|
||||||
#include "websockets/App.h"
|
|
||||||
#endif // NETGEN_DEBUGGING_GUI
|
|
||||||
|
|
||||||
namespace netgen {
|
mesh->FindOpenElements(dom);
|
||||||
unique_ptr<Mesh> GetOpenElements(const Mesh& m, int dom) {
|
NgArray<Element2d> openelements;
|
||||||
static Timer t("GetOpenElements");
|
openelements = mesh->OpenElements();
|
||||||
RegionTimer rt(t);
|
|
||||||
auto mesh = make_unique<Mesh>();
|
|
||||||
*mesh = m;
|
|
||||||
|
|
||||||
Array<bool, PointIndex> interesting_points(mesh->GetNP());
|
for (auto & el : openelements)
|
||||||
interesting_points = false;
|
for (auto i : el.PNums())
|
||||||
|
interesting_points[i] = true;
|
||||||
|
|
||||||
mesh->FindOpenElements(dom);
|
for (auto & el : mesh->VolumeElements())
|
||||||
NgArray<Element2d> openelements;
|
{
|
||||||
openelements = mesh->OpenElements();
|
int num_interesting_points = 0;
|
||||||
|
|
||||||
for (auto& el : openelements)
|
for (auto pi : el.PNums())
|
||||||
for (auto i : el.PNums()) interesting_points[i] = true;
|
if(interesting_points[pi])
|
||||||
|
num_interesting_points++;
|
||||||
|
|
||||||
for (auto& el : mesh->VolumeElements()) {
|
if(num_interesting_points==0)
|
||||||
int num_interesting_points = 0;
|
el.Delete();
|
||||||
|
el.SetIndex(num_interesting_points);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto pi : el.PNums())
|
mesh->SetMaterial(1, "1_point");
|
||||||
if (interesting_points[pi]) num_interesting_points++;
|
mesh->SetMaterial(2, "2_points");
|
||||||
|
mesh->SetMaterial(3, "3_points");
|
||||||
|
mesh->SetMaterial(4, "4_points");
|
||||||
|
mesh->Compress();
|
||||||
|
|
||||||
if (num_interesting_points == 0) el.Delete();
|
mesh->ClearSurfaceElements();
|
||||||
el.SetIndex(num_interesting_points);
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh->SetMaterial(1, "1_point");
|
for (auto & el : openelements)
|
||||||
mesh->SetMaterial(2, "2_points");
|
mesh->AddSurfaceElement( el );
|
||||||
mesh->SetMaterial(3, "3_points");
|
|
||||||
mesh->SetMaterial(4, "4_points");
|
|
||||||
mesh->Compress();
|
|
||||||
|
|
||||||
mesh->ClearSurfaceElements();
|
return mesh;
|
||||||
|
}
|
||||||
for (auto& el : openelements) mesh->AddSurfaceElement(el);
|
|
||||||
|
unique_ptr<Mesh> FilterMesh( const Mesh & m, FlatArray<PointIndex> points, FlatArray<SurfaceElementIndex> sels, FlatArray<ElementIndex> els )
|
||||||
return mesh;
|
{
|
||||||
}
|
static Timer t("GetOpenElements"); RegionTimer rt(t);
|
||||||
|
auto mesh_ptr = make_unique<Mesh>();
|
||||||
unique_ptr<Mesh> FilterMesh(const Mesh& m, FlatArray<PointIndex> points,
|
auto & mesh = *mesh_ptr;
|
||||||
FlatArray<SurfaceElementIndex> sels,
|
mesh = m;
|
||||||
FlatArray<ElementIndex> els) {
|
|
||||||
static Timer t("GetOpenElements");
|
Array<bool, PointIndex> keep_point(mesh.GetNP());
|
||||||
RegionTimer rt(t);
|
Array<bool, SurfaceElementIndex> keep_sel(mesh.GetNSE());
|
||||||
auto mesh_ptr = make_unique<Mesh>();
|
Array<bool, ElementIndex> keep_el(mesh.GetNE());
|
||||||
auto& mesh = *mesh_ptr;
|
mesh.LineSegments().DeleteAll();
|
||||||
mesh = m;
|
|
||||||
|
keep_point = false;
|
||||||
Array<bool, PointIndex> keep_point(mesh.GetNP());
|
for(auto pi : points)
|
||||||
Array<bool, SurfaceElementIndex> keep_sel(mesh.GetNSE());
|
keep_point[pi] = true;
|
||||||
Array<bool, ElementIndex> keep_el(mesh.GetNE());
|
|
||||||
mesh.LineSegments().DeleteAll();
|
auto set_keep = [&] (auto & input, auto & keep_array, auto & els)
|
||||||
|
{
|
||||||
keep_point = false;
|
keep_array = false;
|
||||||
for (auto pi : points) keep_point[pi] = true;
|
for(auto ind : input)
|
||||||
|
keep_array[ind] = true;
|
||||||
auto set_keep = [&](auto& input, auto& keep_array, auto& els) {
|
|
||||||
keep_array = false;
|
for(auto ind : Range(els))
|
||||||
for (auto ind : input) keep_array[ind] = true;
|
{
|
||||||
|
bool & keep = keep_array[ind];
|
||||||
for (auto ind : Range(els)) {
|
if(keep) continue;
|
||||||
bool& keep = keep_array[ind];
|
|
||||||
if (keep) continue;
|
for(auto pi : mesh[ind].PNums())
|
||||||
|
keep |= keep_point[pi];
|
||||||
for (auto pi : mesh[ind].PNums()) keep |= keep_point[pi];
|
|
||||||
|
if(!keep)
|
||||||
if (!keep) mesh[ind].Delete();
|
mesh[ind].Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto i = 0; i<els.Size(); i++)
|
||||||
|
if(els[i].IsDeleted())
|
||||||
|
{
|
||||||
|
els.DeleteElement(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
set_keep(sels, keep_sel, mesh.SurfaceElements());
|
||||||
|
set_keep(els, keep_el, mesh.VolumeElements());
|
||||||
|
//mesh.Compress();
|
||||||
|
|
||||||
|
return mesh_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < els.Size(); i++)
|
|
||||||
if (els[i].IsDeleted()) {
|
|
||||||
els.DeleteElement(i);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
set_keep(sels, keep_sel, mesh.SurfaceElements());
|
|
||||||
set_keep(els, keep_el, mesh.VolumeElements());
|
|
||||||
// mesh.Compress();
|
|
||||||
|
|
||||||
return mesh_ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NETGEN_DEBUGGING_GUI
|
|
||||||
DebuggingGUI::DebuggingGUI() { Start(); }
|
|
||||||
DebuggingGUI::~DebuggingGUI() { Stop(); }
|
|
||||||
|
|
||||||
struct PerSocketData {};
|
|
||||||
using WebSocket = uWS::WebSocket<false, true, PerSocketData>;
|
|
||||||
|
|
||||||
void DebuggingGUI::Start() {
|
|
||||||
gui_thread = thread([&]() {
|
|
||||||
auto a = uWS::App();
|
|
||||||
loop = a.getLoop();
|
|
||||||
app = &a;
|
|
||||||
|
|
||||||
auto read_file = [](const string& path) {
|
|
||||||
std::ifstream in(path);
|
|
||||||
std::stringstream buffer;
|
|
||||||
buffer << in.rdbuf();
|
|
||||||
return buffer.str();
|
|
||||||
};
|
|
||||||
|
|
||||||
const string webgui_file = "/home/matthias/src/webgui/dist/webgui.js";
|
|
||||||
const string main_file = "/home/matthias/a.html";
|
|
||||||
|
|
||||||
a.get("/", [&](auto* res, auto* req) { res->end(read_file(main_file)); })
|
|
||||||
// .any("*", [&](auto* res, auto* req) { cout << "any " << endl; })
|
|
||||||
.get("/index.html",
|
|
||||||
[&](auto* res, auto* req) { res->end(read_file(main_file)); })
|
|
||||||
.get("/webgui.js",
|
|
||||||
[&](auto* res, auto* req) { res->end(read_file(webgui_file)); })
|
|
||||||
.connect("/*",
|
|
||||||
[&](auto* res, auto* req) {
|
|
||||||
cout << "connect " << req->getUrl() << endl;
|
|
||||||
})
|
|
||||||
|
|
||||||
.listen(7871, [&](auto* token_) {
|
|
||||||
token = token_;
|
|
||||||
if (token) {
|
|
||||||
cout << "Listening on port " << 7871 << endl;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
a.ws<PerSocketData>(
|
|
||||||
"/ws",
|
|
||||||
{.compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB |
|
|
||||||
uWS::DEDICATED_DECOMPRESSOR),
|
|
||||||
.maxPayloadLength = 100 * 1024 * 1024,
|
|
||||||
.idleTimeout = 16,
|
|
||||||
.maxBackpressure = 100 * 1024 * 1024,
|
|
||||||
.closeOnBackpressureLimit = false,
|
|
||||||
.resetIdleTimeoutOnSend = false,
|
|
||||||
.sendPingsAutomatically = true,
|
|
||||||
.upgrade = nullptr,
|
|
||||||
.open =
|
|
||||||
[&](auto* ws) {
|
|
||||||
/* Open event here, you may access ws->getUserData() which points
|
|
||||||
* to a PerSocketData struct */
|
|
||||||
// cout << "open websocket " << endl;
|
|
||||||
websockets.insert(ws);
|
|
||||||
Send(data);
|
|
||||||
},
|
|
||||||
.message =
|
|
||||||
[](auto* ws, std::string_view message, uWS::OpCode opCode) {
|
|
||||||
cout << "got message " << message << endl;
|
|
||||||
ws->send(message, opCode, message.length() > 16 * 1024);
|
|
||||||
},
|
|
||||||
.dropped =
|
|
||||||
[](auto* /*ws*/, std::string_view /*message*/,
|
|
||||||
uWS::OpCode /*opCode*/) {
|
|
||||||
/* A message was dropped due to set maxBackpressure and
|
|
||||||
* closeOnBackpressureLimit limit */
|
|
||||||
cout << "ws: dropped message" << endl;
|
|
||||||
},
|
|
||||||
.drain =
|
|
||||||
[](auto* /*ws*/) {
|
|
||||||
/* Check ws->getBufferedAmount() here */
|
|
||||||
cout << "ws: drain" << endl;
|
|
||||||
},
|
|
||||||
.close =
|
|
||||||
[&](auto* ws, int /*code*/, std::string_view /*message*/) {
|
|
||||||
/* You may access ws->getUserData() here */
|
|
||||||
// cout << "close" << endl;
|
|
||||||
websockets.erase(ws);
|
|
||||||
}});
|
|
||||||
a.run();
|
|
||||||
cout << "Exiting GUI thread" << endl;
|
|
||||||
loop = nullptr;
|
|
||||||
app = nullptr;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
void DebuggingGUI::Stop() {
|
|
||||||
cout << "close socket" << endl;
|
|
||||||
for (auto* ws : websockets) ((WebSocket*)ws)->close();
|
|
||||||
us_listen_socket_close(0, (struct us_listen_socket_t*)token);
|
|
||||||
cout << "join thread" << endl;
|
|
||||||
gui_thread.join();
|
|
||||||
cout << "joined thread" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebuggingGUI::DrawMesh(const Mesh& m) {
|
|
||||||
py::gil_scoped_acquire acquire;
|
|
||||||
const auto webgui = py::module::import("netgen.webgui");
|
|
||||||
const auto dumps = py::module::import("json").attr("dumps");
|
|
||||||
mesh = make_shared<Mesh>();
|
|
||||||
*mesh = m;
|
|
||||||
const auto py_data =
|
|
||||||
webgui.attr("Draw")(mesh, py::arg("show") = false).attr("GetData")();
|
|
||||||
const string d = py::cast<string>(dumps(py_data));
|
|
||||||
data = json::parse(d);
|
|
||||||
Send(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebuggingGUI::DrawPoints(FlatArray<Point<3>> position, string name,
|
|
||||||
string color) {
|
|
||||||
DrawObject(position, "points", name, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebuggingGUI::DrawLines(FlatArray<Point<3>> position, string name,
|
|
||||||
string color) {
|
|
||||||
DrawObject(position, "lines", name, color);
|
|
||||||
}
|
|
||||||
void DebuggingGUI::DrawTrigs(FlatArray<Point<3>> position, string name,
|
|
||||||
string color) {
|
|
||||||
// Array<Point<3>> pnts;
|
|
||||||
// cout << "trigs " << position << endl;
|
|
||||||
// for (auto i : Range(position.Size()/3)) {
|
|
||||||
// pnts.Append(position[3*i+0]);
|
|
||||||
// pnts.Append(position[3*i+1]);
|
|
||||||
// pnts.Append(position[3*i+1]);
|
|
||||||
// pnts.Append(position[3*i+2]);
|
|
||||||
// pnts.Append(position[3*i+2]);
|
|
||||||
// pnts.Append(position[3*i+0]);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// cout << "pnts size " << pnts.Size() << endl;
|
|
||||||
DrawObject(position, "trigs", name, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebuggingGUI::DrawObject(FlatArray<Point<3>> position, string type, string name, string color) {
|
|
||||||
json p = json::array_t();
|
|
||||||
for (auto pnt : position) {
|
|
||||||
p.push_back(pnt[0]);
|
|
||||||
p.push_back(pnt[1]);
|
|
||||||
p.push_back(pnt[2]);
|
|
||||||
}
|
|
||||||
json d;
|
|
||||||
d["type"] = type;
|
|
||||||
d["name"] = name;
|
|
||||||
d["color"] = color;
|
|
||||||
d["position"] = p;
|
|
||||||
data["objects"].push_back(d);
|
|
||||||
Send(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebuggingGUI::Send(const string& message) {
|
|
||||||
if (loop) {
|
|
||||||
((uWS::Loop*)loop)->defer([=]() {
|
|
||||||
for (auto* ws : websockets) {
|
|
||||||
((WebSocket*)ws)->send(message, uWS::OpCode::TEXT);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DebuggingGUI debug_gui = DebuggingGUI();
|
|
||||||
|
|
||||||
#endif // NETGEN_DEBUGGING_GUI
|
|
||||||
} // namespace netgen
|
|
||||||
|
@ -1,53 +1,12 @@
|
|||||||
#include "meshing.hpp"
|
#include "meshclass.hpp"
|
||||||
|
|
||||||
// #define NETGEN_DEBUGGING_GUI
|
|
||||||
|
|
||||||
#ifdef NETGEN_DEBUGGING_GUI
|
namespace netgen
|
||||||
#include "json.hpp"
|
{
|
||||||
using json = nlohmann::json;
|
unique_ptr<Mesh> GetOpenElements( const Mesh & m, int dom = 0 );
|
||||||
#endif // NETGEN_DEBUGGING_GUI
|
|
||||||
|
|
||||||
namespace netgen {
|
unique_ptr<Mesh> FilterMesh( const Mesh & m, FlatArray<PointIndex> points, FlatArray<SurfaceElementIndex> sels = Array<SurfaceElementIndex>{}, FlatArray<ElementIndex> els = Array<ElementIndex>{} );
|
||||||
unique_ptr<Mesh> GetOpenElements(const Mesh& m, int dom = 0);
|
|
||||||
|
|
||||||
unique_ptr<Mesh> FilterMesh(
|
|
||||||
const Mesh& m, FlatArray<PointIndex> points,
|
|
||||||
FlatArray<SurfaceElementIndex> sels = Array<SurfaceElementIndex>{},
|
|
||||||
FlatArray<ElementIndex> els = Array<ElementIndex>{});
|
|
||||||
|
|
||||||
#ifdef NETGEN_DEBUGGING_GUI
|
|
||||||
class DebuggingGUI {
|
|
||||||
public:
|
|
||||||
DebuggingGUI();
|
|
||||||
~DebuggingGUI();
|
|
||||||
|
|
||||||
void Start();
|
}
|
||||||
void Stop();
|
|
||||||
|
|
||||||
void DrawMesh(const Mesh& m);
|
|
||||||
void DrawPoints(FlatArray<Point<3>> position, string name = "points",
|
|
||||||
string color = "black");
|
|
||||||
void DrawLines(FlatArray<Point<3>> position, string name = "lines",
|
|
||||||
string color = "black");
|
|
||||||
void DrawTrigs(FlatArray<Point<3>> position, string name = "trigs",
|
|
||||||
string color = "black");
|
|
||||||
|
|
||||||
void DrawObject(FlatArray<Point<3>> position, string type, string name,
|
|
||||||
string color);
|
|
||||||
void ResetObjects() { data["objects"] = json::array_t(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
thread gui_thread;
|
|
||||||
void *app, *loop, *token;
|
|
||||||
std::set<void*> websockets;
|
|
||||||
json data;
|
|
||||||
shared_ptr<Mesh> mesh;
|
|
||||||
|
|
||||||
void Send(const json& data) { Send(data.dump()); }
|
|
||||||
void Send(const string& message);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern DebuggingGUI debug_gui;
|
|
||||||
#endif // NETGEN_DEBUGGING_GUI
|
|
||||||
|
|
||||||
} // namespace netgen
|
|
||||||
|
@ -1698,7 +1698,7 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
CalcSurfacesOfNode ();
|
CalcSurfacesOfNode ();
|
||||||
|
|
||||||
if (ntasks == 1) // sequential run only
|
if (ntasks == 1) // sequential run only
|
||||||
{
|
{
|
||||||
topology.Update();
|
topology.Update();
|
||||||
|
@ -563,18 +563,6 @@ namespace netgen
|
|||||||
el.SetIndex(m_.domain);
|
el.SetIndex(m_.domain);
|
||||||
mesh.AddVolumeElement(el);
|
mesh.AddVolumeElement(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto & part_ident = m.GetIdentifications().GetIdentifiedPoints();
|
|
||||||
// for (auto i : IntRange(1, part_ident.GetNBags()+1))
|
|
||||||
// for (auto j : IntRange(1, part_ident.GetBagSize(i)+1))
|
|
||||||
// {
|
|
||||||
// INDEX_2 i2;
|
|
||||||
// int nr;
|
|
||||||
// part_ident.GetData (i, j, i2, nr);
|
|
||||||
// i2.I1() = pmap[i2.I1()];
|
|
||||||
// i2.I2() = pmap[i2.I2()];
|
|
||||||
// ident_points.Set(i2, nr);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,8 +723,6 @@ namespace netgen
|
|||||||
// mesh3d.mglevels = 1;
|
// mesh3d.mglevels = 1;
|
||||||
MeshQuality3d (mesh3d);
|
MeshQuality3d (mesh3d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug_gui.DrawMesh("Mesh", mesh3d);
|
|
||||||
|
|
||||||
multithread.task = savetask;
|
multithread.task = savetask;
|
||||||
return MESHING3_OK;
|
return MESHING3_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user