Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 9 additions & 34 deletions glvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ enum InputOptions
};
int input = INPUT_SERVER_MODE;

thread_local GeometryRefiner GLVisGeometryRefiner;

void PrintSampleUsage(ostream &out);

class Session
Expand All @@ -77,19 +75,6 @@ class Session
std::thread handler;

public:
Session(bool fix_elem_orient,
bool save_coloring,
bool keep_attr,
string plot_caption,
bool headless)
{
win.data_state.fix_elem_orient = fix_elem_orient;
win.data_state.save_coloring = save_coloring;
win.data_state.keep_attr = keep_attr;
win.plot_caption = plot_caption;
win.headless = headless;
}

Session(Window other_win)
: win(std::move(other_win))
{ }
Expand Down Expand Up @@ -159,10 +144,7 @@ class Session

};

void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient,
bool save_coloring, bool keep_attr, string plot_caption,
bool secure, std::vector<std::array<double,3>> point_coords,
bool headless = false)
void GLVisServer(int portnum, bool save_stream, bool secure, Window win)
{
std::vector<Session> current_sessions;
string data_type;
Expand Down Expand Up @@ -314,9 +296,7 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient,
while (1);
}

Session new_session(fix_elem_orient, save_coloring, keep_attr,
plot_caption, headless);
if (!point_coords.empty()) { new_session.GetState().point_coords = point_coords; }
Session new_session(win.CloneEmpty());

constexpr int tmp_filename_size = 50;
char tmp_file[tmp_filename_size];
Expand Down Expand Up @@ -398,7 +378,6 @@ int main (int argc, char *argv[])
int multisample = GetMultisample();
double line_width = GetLineWidth();
double ms_line_width = GetLineWidthMS();
int geom_ref_type = Quadrature1D::ClosedUniform;
bool legacy_gl_ctx = false;
bool enable_hidpi = true;

Expand Down Expand Up @@ -457,7 +436,7 @@ int main (int argc, char *argv[])
"-ap", "--processor-attributes",
"When opening a parallel mesh, use the real mesh attributes"
" or replace them with the processor rank.");
args.AddOption(&geom_ref_type, "-grt", "--geometry-refiner-type",
args.AddOption(&win.data_state.geom_ref_type, "-grt", "--geometry-refiner-type",
"Set of points to use when refining geometry:"
" 3 = uniform, 1 = Gauss-Lobatto, (see mfem::Quadrature1D).");
args.AddOption(&win.data_state.save_coloring, "-sc", "--save-coloring",
Expand Down Expand Up @@ -622,8 +601,6 @@ int main (int argc, char *argv[])
BasePalettes.SetDefault(palette_name);
}

GLVisGeometryRefiner.SetType(geom_ref_type);

// Load points file if specified (Ctrl+l to toggle)
if (points_file != string_none)
{
Expand Down Expand Up @@ -712,21 +689,19 @@ int main (int argc, char *argv[])
// server mode, read the mesh and the solution from a socket
if (input == INPUT_SERVER_MODE)
{
// backup the headless flag as the window is moved
const bool headless = win.headless;

// Make sure the singleton object returned by GetMainThread() is
// initialized from the main thread.
GetMainThread(win.headless);
GetMainThread(headless);

// Run server in new thread
std::thread serverThread{GLVisServer, portnum, save_stream,
win.data_state.fix_elem_orient,
win.data_state.save_coloring,
win.data_state.keep_attr,
win.plot_caption, secure,
std::move(win.data_state.point_coords),
win.headless};
secure, std::move(win)};

// Start message loop in main thread
MainThreadLoop(win.headless, persistent);
MainThreadLoop(headless, persistent);
serverThread.detach();
}
else // input != 1, non-server mode
Expand Down
3 changes: 0 additions & 3 deletions lib/aux_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#include <emscripten/html5.h>
#include <emscripten/val.h>

// used in extern context
thread_local mfem::GeometryRefiner GLVisGeometryRefiner;

// either bitmap data or png bytes
std::vector<unsigned char> * screen_state = nullptr;

Expand Down
41 changes: 30 additions & 11 deletions lib/data_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,43 @@ int ReadPointLine(std::istream &in,
}


DataState &DataState::operator=(DataState &&ss)
DataState &DataState::operator=(DataState &&ds)
{
internal = std::move(ss.internal);
internal = std::move(ds.internal);

type = ss.type;
cmplx_sol = ss.cmplx_sol;
quad_sol = ss.quad_sol;
keys = std::move(ss.keys);
type = ds.type;
cmplx_sol = ds.cmplx_sol;
quad_sol = ds.quad_sol;
keys = std::move(ds.keys);

fix_elem_orient = ss.fix_elem_orient;
save_coloring = ss.save_coloring;
keep_attr = ss.keep_attr;
cmplx_phase = ss.cmplx_phase;
point_coords = std::move(ss.point_coords);
fix_elem_orient = ds.fix_elem_orient;
save_coloring = ds.save_coloring;
keep_attr = ds.keep_attr;
geom_ref_type = ds.geom_ref_type;
cmplx_phase = ds.cmplx_phase;
point_coords = std::move(ds.point_coords);

return *this;
}

DataState DataState::CloneEmpty() const
{
DataState ds;
ds.type = type;
ds.cmplx_sol = cmplx_sol;
ds.quad_sol = quad_sol;
ds.keys = keys;

ds.fix_elem_orient = fix_elem_orient;
ds.save_coloring = save_coloring;
ds.keep_attr = keep_attr;
ds.geom_ref_type = geom_ref_type;
ds.cmplx_phase = cmplx_phase;
ds.point_coords = point_coords;

return ds;
}

void DataState::SetMesh(Mesh *mesh_)
{
internal.mesh.reset(mesh_);
Expand Down
6 changes: 4 additions & 2 deletions lib/data_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ struct DataState
bool fix_elem_orient{false};
bool save_coloring{false};
bool keep_attr{false};
int geom_ref_type{mfem::Quadrature1D::ClosedUniform}; // geometry refiner type
double cmplx_phase{0.};
std::vector<std::array<double,3>> point_coords; // point line (from -pts)

DataState() = default;
DataState(DataState &&ss) { *this = std::move(ss); }
DataState& operator=(DataState &&ss);
DataState(DataState &&ds) { *this = std::move(ds); }
DataState& operator=(DataState &&ds);
DataState CloneEmpty() const;

/// Get type of the contained data
inline FieldType GetType() const { return type; }
Expand Down
4 changes: 3 additions & 1 deletion lib/vsdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,9 @@ void VisualizationSceneScalarData::SetAutoscale(Autoscale _autoscale,
}

VisualizationSceneScalarData::VisualizationSceneScalarData(
Window &win_, bool init) : VisualizationScene(*win_.wnd), win(win_)
Window &win_, bool init)
: VisualizationScene(*win_.wnd), win(win_),
geom_refiner(win.data_state.geom_ref_type)
{
mesh = win.data_state.mesh.get();
mesh_coarse = win.data_state.mesh_quad.get();
Expand Down
1 change: 1 addition & 0 deletions lib/vsdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class VisualizationSceneScalarData : public VisualizationScene
const DataState::Offsets *offsets{};

Window &win;
mfem::GeometryRefiner geom_refiner;

double minv, maxv;

Expand Down
31 changes: 15 additions & 16 deletions lib/vssolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ using namespace std;
using namespace mfem;

thread_local VisualizationSceneSolution *VisualizationSceneSolution::vssol;
extern thread_local GeometryRefiner GLVisGeometryRefiner;

#ifdef GLVIS_ISFINITE
/* This test for INFs or NaNs is the same as the one used in hypre's PCG and
Expand Down Expand Up @@ -1135,8 +1134,8 @@ void VisualizationSceneSolution::FindNewBox(double rx[], double ry[],
rx[1] = ry[1] = rval[1] = -rx[0];
for (i = 0; i < ne; i++)
{
RefG = GLVisGeometryRefiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
RefG = geom_refiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
GetRefinedValues(i, RefG->RefPts, values, pointmat);
for (j = 0; j < values.Size(); j++)
{
Expand Down Expand Up @@ -1396,8 +1395,8 @@ void VisualizationSceneSolution::PrepareFlat2()
{
if (!el_attr_to_show[mesh->GetAttribute(i)-1]) { continue; }

RefG = GLVisGeometryRefiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
RefG = geom_refiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
j = GetRefinedValuesAndNormals(i, RefG->RefPts, values, pointmat,
normals);
Array<int> &RG = RefG->RefGeoms;
Expand Down Expand Up @@ -1733,8 +1732,8 @@ void VisualizationSceneSolution::PrepareLevelCurves2()
gl3::GlBuilder build = lcurve_buf.createBuilder();
for (i = 0; i < ne; i++)
{
RefG = GLVisGeometryRefiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
RefG = geom_refiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
GetRefinedValues (i, RefG->RefPts, values, pointmat);
Array<int> &RG = RefG->RefGeoms;
int sides = mesh->GetElement(i)->GetNVertices();
Expand Down Expand Up @@ -2092,7 +2091,7 @@ void VisualizationSceneSolution::PrepareEdgeNumbering()
std::cerr << "Only TRIANGLE and SQUARE geometries are supported." << std::endl;
return;
}
const auto *RefG = GLVisGeometryRefiner.Refine(geom, 2, 2);
const auto *RefG = geom_refiner.Refine(geom, 2, 2);
GetRefinedValues(e, RefG->RefPts, vals, p);
const int ij3[3] = { 1, 4, 3 }, ie3[3] = { 0, 1, 2 };
const int ij4[4] = { 1, 3, 5, 7 }, ie4[4] = { 0, 3, 1, 2 };
Expand Down Expand Up @@ -2337,8 +2336,8 @@ void VisualizationSceneSolution::PrepareLines2()
{
if (!el_attr_to_show[mesh->GetAttribute(i)-1]) { continue; }

RefG = GLVisGeometryRefiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
RefG = geom_refiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
GetRefinedValues (i, RefG->RefPts, values, pointmat);
Array<int> &RG = RefG->RefGeoms;
int sides = mesh->GetElement(i)->GetNVertices();
Expand Down Expand Up @@ -2370,8 +2369,8 @@ void VisualizationSceneSolution::PrepareLines3()
for (i = 0; i < ne; i++)
{
if (!el_attr_to_show[mesh->GetAttribute(i)-1]) { continue; }
RefG = GLVisGeometryRefiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
RefG = geom_refiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
GetRefinedValues (i, RefG->RefPts, values, pointmat);
Array<int> &RE = RefG->RefEdges;

Expand Down Expand Up @@ -2485,8 +2484,8 @@ void VisualizationSceneSolution::PrepareBoundary()
int en;
FaceElementTransformations *T;
RefinedGeometry *RefG =
GLVisGeometryRefiner.Refine(Geometry::SEGMENT, TimesToRefine,
EdgeRefineFactor);
geom_refiner.Refine(Geometry::SEGMENT, TimesToRefine,
EdgeRefineFactor);
IntegrationRule &ir = RefG->RefPts;
IntegrationRule eir(ir.GetNPoints());
Vector vals;
Expand Down Expand Up @@ -2606,8 +2605,8 @@ void VisualizationSceneSolution::PrepareCP()

for (int i = 0; i < mesh->GetNE(); i++)
{
RefG = GLVisGeometryRefiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
RefG = geom_refiner.Refine(mesh->GetElementBaseGeometry(i),
TimesToRefine, EdgeRefineFactor);
GetRefinedValues (i, RefG->RefPts, values, pointmat);
Array<int> &RG = RefG->RefGeoms;
int sides = mesh->GetElement(i)->GetNVertices();
Expand Down
Loading
Loading