Skip to content
Draft
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
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
add_subdirectory(lib)
add_subdirectory(share)

if (GLVIS_BUILD_LIB_ONLY)
return()
endif()

if(NOT EMSCRIPTEN)

# Setup the GLVis executable
Expand Down Expand Up @@ -392,7 +396,6 @@ if(NOT EMSCRIPTEN)
execute_process(COMMAND codesign --force --sign - ${CMAKE_INSTALL_PREFIX}/GLVis.app)
]] COMPONENT RUNTIME)
endif(APPLE)

endif(NOT EMSCRIPTEN)

if(ENABLE_TESTS)
Expand Down
89 changes: 2 additions & 87 deletions glvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// GLVis - an OpenGL visualization server based on the MFEM library

#include <limits>
// #include <limits>
#include <iostream>
#include <fstream>
#include <string>
Expand All @@ -35,6 +35,7 @@
#endif

#include <mfem.hpp>
#include "lib/session.hpp"
#include "lib/visual.hpp"
#include "lib/window.hpp"
#include "lib/script_controller.hpp"
Expand Down Expand Up @@ -69,92 +70,6 @@ thread_local GeometryRefiner GLVisGeometryRefiner;

void PrintSampleUsage(ostream &out);

class Session
{
StreamCollection input_streams;
Window win;
std::thread handler;

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

Session(Window other_win)
: win(std::move(other_win))
{ }

~Session() = default;

Session(Session&& from) = default;
Session& operator= (Session&& from) = default;

inline DataState& GetState() { return win.data_state; }
inline const DataState& GetState() const { return win.data_state; }

void StartSession()
{
auto funcThread = [](Window w, StreamCollection is)
{
if (w.GLVisInitVis(std::move(is)))
{
w.GLVisStartVis();
}
};
handler = std::thread {funcThread,
std::move(win), std::move(input_streams)};
handler.detach();
}

bool StartSavedSession(std::string stream_file)
{
unique_ptr<ifstream> ifs(new ifstream(stream_file));
if (!(*ifs))
{
cout << "Can not open stream file: " << stream_file << endl;
return false;
}
string data_type;
*ifs >> data_type >> ws;
StreamReader reader(win.data_state);
reader.ReadStream(*ifs, data_type);
input_streams.emplace_back(std::move(ifs));

StartSession();
return true;
}

int StartStreamSession(std::unique_ptr<mfem::socketstream> &&stream,
const std::string &data_type)
{
StreamReader reader(win.data_state);
int ierr = reader.ReadStream(*stream, data_type);
if (ierr) { return ierr; }
input_streams.emplace_back(std::move(stream));

StartSession();
return 0;
}

int StartStreamSession(StreamCollection &&streams)
{
StreamReader reader(win.data_state);
int ierr = reader.ReadStreams(streams);
if (ierr) { return ierr; }
input_streams = std::move(streams);

StartSession();
return 0;
}

};

void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient,
bool save_coloring, string plot_caption, bool headless = false)
Expand Down
3 changes: 3 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ list(APPEND SOURCES
palettes_default.cpp
palettes_base.cpp
script_controller.cpp
session.cpp
stream_reader.cpp
stream_session.cpp
vsdata.cpp
vssolution.cpp
vssolution3d.cpp
Expand Down Expand Up @@ -67,6 +69,7 @@ list(APPEND HEADERS
palettes.hpp
palettes_base.hpp
script_controller.hpp
session.hpp
stream_reader.hpp
visual.hpp
vsdata.hpp
Expand Down
83 changes: 83 additions & 0 deletions lib/session.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-443271.
//
// This file is part of the GLVis visualization tool and library. For more
// information and source code availability see https://glvis.org.
//
// GLVis is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#include "threads.hpp" // IWYU pragma: keep for GLVisCommand

#include <memory>

#include "session.hpp"

void Session::StartSession()
{
auto funcThread = [](Window w, StreamCollection is)
{
if (w.GLVisInitVis(std::move(is)))
{
w.GLVisStartVis();
}
};
handler = std::thread {funcThread,
std::move(win), std::move(input_streams)};
handler.detach();
}

bool Session::StartSavedSession(std::string stream_file)
{
std::unique_ptr<std::ifstream> ifs(new std::ifstream(stream_file));
if (!(*ifs))
{
std::cout << "Can not open stream file: " << stream_file << std::endl;
return false;
}
std::string data_type;
*ifs >> data_type >> std::ws;
StreamReader reader(win.data_state);
reader.ReadStream(*ifs, data_type);
input_streams.emplace_back(std::move(ifs));

StartSession();
return true;
}

int Session::StartStreamSession(std::unique_ptr<mfem::socketstream> &&stream,
const std::string &data_type)
{
StreamReader reader(win.data_state);
int ierr = reader.ReadStream(*stream, data_type);
if (ierr) { return ierr; }
input_streams.emplace_back(std::move(stream));

StartSession();
return 0;
}

int Session::StartStreamSession(StreamCollection &&streams)
{
StreamReader reader(win.data_state);
int ierr = reader.ReadStreams(streams);
if (ierr) { return ierr; }
input_streams = std::move(streams);

StartSession();
return 0;
}

int Session::StartStreamSession(std::unique_ptr<std::istream> &&stream,
const std::string &data_type)
{
StreamReader reader(win.data_state);
int ierr = reader.ReadStream(*stream, data_type);
if (ierr) { return ierr; }
input_streams.emplace_back(std::move(stream));

StartSession();
return 0;
}
61 changes: 61 additions & 0 deletions lib/session.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-443271.
//
// This file is part of the GLVis visualization tool and library. For more
// information and source code availability see https://glvis.org.
//
// GLVis is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.
#pragma once

#include "stream_reader.hpp"
#include "window.hpp"

#include <thread>

class Session
{
StreamCollection input_streams;
Window win;
std::thread handler;

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

Session(Window other_win): win(std::move(other_win)) { }

~Session() = default;

Session(Session&& from) = default;
Session& operator= (Session&& from) = default;

inline DataState& GetState() { return win.data_state; }
inline const DataState& GetState() const { return win.data_state; }

void StartSession();

bool StartSavedSession(std::string stream_file);

int StartStreamSession(std::unique_ptr<mfem::socketstream> &&stream,
const std::string &data_type);

int StartStreamSession(std::unique_ptr<std::istream> &&stream,
const std::string &data_type);

int StartStreamSession(StreamCollection &&streams);

int StartSerialStreamSession(std::istream &stream,
const std::string &data_type);

};
62 changes: 62 additions & 0 deletions lib/stream_session.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-443271.
//
// This file is part of the GLVis visualization tool and library. For more
// information and source code availability see https://glvis.org.
//
// GLVis is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#include "threads.hpp" // IWYU pragma: keep for GLVisCommand
#include "aux_vis.hpp" // SetUseHiDPI

#include "session.hpp"

#include <fem/geom.hpp>

extern thread_local mfem::GeometryRefiner GLVisGeometryRefiner;

int GLVisStreamSession(const bool fix_elem_orient,
const bool save_coloring,
const bool headless,
const std::string &plot_caption,
const std::string &data_type,
StreamCollection &&streams)
{
const int geom_ref_type = mfem::Quadrature1D::ClosedUniform;
const bool enable_hidpi = true;

Window win;

std::cout << std::endl
<< " _/_/_/ _/ _/ _/ _/" << std::endl
<< " _/ _/ _/ _/ _/_/_/" << std::endl
<< " _/ _/_/ _/ _/ _/ _/ _/_/" << std::endl
<< " _/ _/ _/ _/ _/ _/ _/_/" << std::endl
<< " _/_/_/ _/_/_/_/ _/ _/ _/_/_/" << std::endl
<< std::endl;

SetUseHiDPI(enable_hidpi);
GLVisGeometryRefiner.SetType(geom_ref_type);

GetMainThread(false);

Session new_session(fix_elem_orient, save_coloring, plot_caption, headless);
if (streams.size() == 1 && data_type == "solution")
{
new_session.StartStreamSession(std::move(streams[0]), data_type);
}
else
{
new_session.StartStreamSession(std::move(streams));
}

std::vector<Session> current_sessions;
current_sessions.emplace_back(std::move(new_session));

MainThreadLoop(false, false);

return EXIT_SUCCESS;
}
18 changes: 10 additions & 8 deletions lib/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,12 +1630,14 @@ void communication_thread::execute()
}
}

for (size_t i = 0; i < is.size(); i++)
{
socketstream *isock = dynamic_cast<socketstream *>(is[i].get());
if (isock)
{
isock->close();
}
}
// avoid 'typeinfo for mfem::socketstream' rtti error
// until two stage compilation
// for (size_t i = 0; i < is.size(); i++)
// {
// socketstream *isock = dynamic_cast<socketstream *>(is[i].get());
// if (isock)
// {
// isock->close();
// }
// }
}
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ ALL_SOURCE_FILES = \
lib/palettes_base.cpp lib/palettes.cpp lib/palettes_default.cpp \
lib/script_controller.cpp lib/stream_reader.cpp lib/threads.cpp \
lib/vsdata.cpp lib/vssolution.cpp lib/vssolution3d.cpp \
lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp
lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp \
lib/session.cpp lib/stream_session.cpp
OBJC_SOURCE_FILES = $(if $(NOTMAC),,lib/sdl/sdl_mac.mm)
DESKTOP_ONLY_SOURCE_FILES = \
lib/gl/renderer_ff.cpp lib/gl2ps.c lib/script_controller.cpp \
Expand All @@ -300,7 +301,7 @@ HEADER_FILES = \
lib/openglvis.hpp lib/palettes_base.hpp lib/palettes.hpp \
lib/script_controller.hpp lib/stream_reader.hpp lib/threads.hpp \
lib/visual.hpp lib/vsdata.hpp lib/vssolution.hpp lib/vssolution3d.hpp \
lib/vsvector.hpp lib/vsvector3d.hpp lib/window.hpp
lib/vsvector.hpp lib/vsvector3d.hpp lib/window.hpp lib/session.hpp

DESKTOP_SOURCE_FILES = $(COMMON_SOURCE_FILES) $(DESKTOP_ONLY_SOURCE_FILES) $(LOGO_FILE_CPP)
WEB_SOURCE_FILES = $(COMMON_SOURCE_FILES) $(WEB_ONLY_SOURCE_FILES)
Expand Down
Loading