Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
display.h File Reference
#include <netdb.h>
#include <wsServer/include/ws.h>
#include "view.h"
#include "khash.h"
Include dependency graph for display.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  DisplayClient
 
struct  kh_strhash_s
 
struct  DisplayControl
 

Macros

#define DISPLAY_JS   "http://basilisk.ida.upmc.fr/three.js/editor/index.html"
 
#define DISPLAY_HOST   "localhost"
 
#define DISPLAY_RANGE   "7100:7200"
 
#define debug(...)   do { if (Display.debug) fprintf (qerr, __VA_ARGS__), fflush(qerr); } while(0)
 
#define JSON_BUILD(...)
 
#define display_control(val, ...)
 

Typedefs

typedef struct kh_strhash_s kh_strhash_t
 

Functions

static kh_strhash_tkh_init_strhash (void)
 
static void kh_destroy_strhash (kh_strhash_t *h)
 
static void kh_clear_strhash (kh_strhash_t *h)
 
static khint_t kh_get_strhash (const kh_strhash_t *h, kh_cstr_t key)
 
static int kh_resize_strhash (kh_strhash_t *h, khint_t new_n_buckets)
 
static khint_t kh_put_strhash (kh_strhash_t *h, kh_cstr_t key, int *ret)
 
static void kh_del_strhash (kh_strhash_t *h, khint_t x)
 
static void display_display ()
 
static charread_file_into_buffer (FILE *fp)
 
static void display_command (const char *command)
 
static int ws_send_array (int fd, Array *a, int status, int type, unsigned int *shift)
 
static int display_send (const char *command, int fd)
 
static void display_add (const char *command, int fd)
 
static void array_remove (khiter_t k, int fd)
 
static void display_remove (const char *command, int fd)
 
static chardisplay_control_json ()
 
static DisplayControldisplay_control_lookup (const char *name)
 
void display_control_internal (void *ptr, double min, double max, char *name=NULL, char *tooltip=NULL, char *ptr_name, int size)
 
static void display_control_update (const char *command, int fd)
 
static charbview_interface_json ()
 
void display_onclose (int fd)
 
void display_onmessage (int fd, const char *msg, size_t size, int type)
 
void display_onopen (int fd)
 
static void display_update (int i)
 
int display_poll (int timeout)
 
void display_url (FILE *fp)
 
static void display_destroy ()
 
init_solver void display_init ()
 
void event_refresh_display (void)
 Event: refresh_display (i++, last)
 

Variables

struct { 
 
   kh_strhash_t *   objects 
 
   int   sock 
 
   int   port 
 
   char *   error 
 
   Array *   controls 
 
   bool   debug 
 
Display = { .sock = -1 } 
 
int display_usage = 20
 
int display_play = 0 < 0 ? -1 : 0
 

Macro Definition Documentation

◆ debug

#define debug (   ...)    do { if (Display.debug) fprintf (qerr, __VA_ARGS__), fflush(qerr); } while(0)

Definition at line 82 of file display.h.

◆ display_control

#define display_control (   val,
  ... 
)
Value:
(&(val), __VA_ARGS__, size = sizeof(val), ptr_name = #val)
if TRASH define &&NewPid *& val(newpid, 0, 0, 0)) -> pid > 0) @else @ define is_newpid()(((NewPid *)&val(newpid, 0, 0, 0)) ->pid > 0) @endif Array *linear_tree(size_t size, scalar newpid)
Definition balance.h:13
int x
Definition common.h:76
void display_control_internal(void *ptr, double min, double max, char *name=NULL, char *tooltip=NULL, char *ptr_name, int size)
Definition display.h:435
size_t size

Definition at line 462 of file display.h.

◆ DISPLAY_HOST

#define DISPLAY_HOST   "localhost"

Definition at line 75 of file display.h.

◆ DISPLAY_JS

Server-side display

This file implements the server-side of the interactive display of a running Basilisk code. The client-side is typically done by the javascript implementation.

This works using two main components:

The wsServer WebSocket library Vertex buffers

The initial state of the display can be controlled using the DISPLAY macro, following these rules:

-DDISPLAY=1, -DDISPLAY: play controls, start running immediately. -DDISPLAY=-1: play controls, initially paused. -DDISPLAY=0: no play controls, start running immediately. #include "display.h": play controls, initially paused.

This can also be changed by setting display_play = 0; in main().

Display port

Multiple servers can run simultaneously on the same machine but must use different ports. When connecting, the server looks for a free port in the default range (typically 7100 to 7200, see the DISPLAY_RANGE macro below). The corresponding connection information (including the URL of the javascript interface) is written in the display.html file, which can be used to open the connection on the client side (i.e. the web browser).

Display control

The values of integer or double variables can be controlled interactively using the display_control() macro, for example:

display_control (value, 0, 100, "Short Name", "Long tooltip");

where the first argument is the name of the variable and the numbers indicate the (optional) range (min and max values). The (optional) name and tooltip are used to generate the Basilisk View interface. The only compulsory argument is the variable name.

Default display

Default drawing function calls, which will be sent to an empty javascript client, can be setup using something like:

display ("squares (color = 'u.x', spread = -1);");

where the single quotes will be expanded to doubles quotes when interpreted. Do not forget the trailing semi-column.

Note that these function calls will be appended to existing ones. To overwrite existing calls, use:

display ("squares (color = 'u.x', spread = -1);", true);

Definition at line 71 of file display.h.

◆ DISPLAY_RANGE

#define DISPLAY_RANGE   "7100:7200"

Definition at line 79 of file display.h.

◆ JSON_BUILD

#define JSON_BUILD (   ...)
Value:
len += snprintf (build + len, 4096, __VA_ARGS__), \
build = realloc (build, len + 4096)
define sysmalloc malloc define syscalloc calloc define sysrealloc realloc define sysfree free define systrdup strdup define line line realloc(p, s) @ define pfree(p

Definition at line 348 of file display.h.

Typedef Documentation

◆ kh_strhash_t

Function Documentation

◆ array_remove()

static void array_remove ( khiter_t  k,
int  fd 
)
static

Definition at line 351 of file display.h.

References debug, Display, free(), i, j, k, kh_del, kh_key, kh_value, and x.

Referenced by display_onclose(), and display_remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bview_interface_json()

static char * bview_interface_json ( )
static

Definition at line 493 of file display.h.

References bview_interface, i, json, JSON_BUILD, realloc(), and x.

Referenced by display_onopen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_add()

static void display_add ( const char command,
int  fd 
)
static

Definition at line 320 of file display.h.

References debug, Display, display_display(), k, kh_end, kh_get, kh_put, kh_value, realloc(), strdup(), and x.

Referenced by display_onmessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_command()

static void display_command ( const char command)
static

Definition at line 140 of file display.h.

References debug, Display, fflush(), fp, free(), line, process_line(), read_file_into_buffer(), strdup(), vertex_buffer_setup(), VertexBuffer, and x.

Referenced by display_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_control_internal()

void display_control_internal ( void ptr,
double  min,
double  max,
char name = NULL,
char tooltip = NULL,
char ptr_name,
int  size 
)

Definition at line 435 of file display.h.

References array_append(), controls, d, Display, display_control_json(), display_control_lookup(), free(), max, min, DisplayControl::name, size, sizeof(), strdup(), and x.

Here is the call graph for this function:

◆ display_control_json()

static char * display_control_json ( )
static

Definition at line 396 of file display.h.

References assert, d, Display, i, JSON_BUILD, and x.

Referenced by display_control_internal(), display_control_update(), and display_onopen().

Here is the caller graph for this function:

◆ display_control_lookup()

static DisplayControl * display_control_lookup ( const char name)
static

Definition at line 426 of file display.h.

References d, Display, i, and x.

Referenced by display_control_internal(), and display_control_update().

Here is the caller graph for this function:

◆ display_control_update()

static void display_control_update ( const char command,
int  fd 
)
static

Definition at line 465 of file display.h.

References assert, clamp(), controls, d, debug, display_control_json(), display_control_lookup(), free(), s, strdup(), val(), and x.

Referenced by display_onmessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_destroy()

static void display_destroy ( )
static

Definition at line 720 of file display.h.

References array_free(), d, Display, free(), i, k, kh_begin, kh_destroy, kh_end, kh_exist, kh_key, kh_value, and x.

Referenced by display_init(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_display()

static void display_display ( )
static

Definition at line 106 of file display.h.

References debug, Display, k, kh_begin, kh_end, kh_exist, kh_key, kh_value, and x.

Referenced by display_add(), display_onclose(), and display_remove().

Here is the caller graph for this function:

◆ display_init()

init_solver void display_init ( )

Definition at line 746 of file display.h.

References array_new(), Display, display_control, display_destroy(), display_play, DISPLAY_RANGE, display_url(), display_usage, fp, free(), free_solver_func_add(), kh_init, port, s, strdup(), and x.

Here is the call graph for this function:

◆ display_onclose()

void display_onclose ( int  fd)

Definition at line 512 of file display.h.

References array_remove(), debug, Display, display_display(), k, kh_begin, kh_end, and kh_exist.

Referenced by display_onopen(), display_poll(), and display_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_onmessage()

void display_onmessage ( int  fd,
const char msg,
size_t  size,
int  type 
)

Definition at line 522 of file display.h.

References display_add(), display_control_update(), display_remove(), type, and x.

Referenced by display_poll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_onopen()

void display_onopen ( int  fd)

Definition at line 542 of file display.h.

References bview_interface_json(), controls, debug, display_control_json(), display_defaults, display_onclose(), free(), and x.

Referenced by display_poll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_poll()

int display_poll ( int  timeout)

Definition at line 645 of file display.h.

References array_free(), assert, calloc(), Display, display_onclose(), display_onmessage(), display_onopen(), and x.

Referenced by event_refresh_display(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_remove()

static void display_remove ( const char command,
int  fd 
)
static

Definition at line 377 of file display.h.

References array_remove(), debug, Display, display_display(), k, kh_end, kh_get, and x.

Referenced by display_onmessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_send()

static int display_send ( const char command,
int  fd 
)
static

Definition at line 248 of file display.h.

References c, debug, Display, free(), i, int, npe, type, VertexBuffer, ws_send_array(), and x.

Referenced by display_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_update()

static void display_update ( int  i)
static

Definition at line 569 of file display.h.

References debug, Display, display_command(), display_onclose(), display_send(), free(), i, k, kh_begin, kh_del, kh_end, kh_exist, kh_key, kh_value, vertex_buffer_free(), and x.

Referenced by event_refresh_display(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ display_url()

void display_url ( FILE fp)

Definition at line 697 of file display.h.

References Display, DISPLAY_JS, fp, h, LINENO, and x.

Referenced by display_init(), and main().

Here is the caller graph for this function:

◆ event_refresh_display()

void event_refresh_display ( void  )

Event: refresh_display (i++, last)

Definition at line 798 of file display.h.

References display_play, display_poll(), display_update(), display_usage, i, timer_elapsed(), timer_start(), and x.

Here is the call graph for this function:

◆ kh_clear_strhash()

static void kh_clear_strhash ( kh_strhash_t h)
inlinestatic

Definition at line 96 of file display.h.

◆ kh_del_strhash()

static void kh_del_strhash ( kh_strhash_t h,
khint_t  x 
)
inlinestatic

Definition at line 96 of file display.h.

◆ kh_destroy_strhash()

static void kh_destroy_strhash ( kh_strhash_t h)
inlinestatic

Definition at line 96 of file display.h.

◆ kh_get_strhash()

static khint_t kh_get_strhash ( const kh_strhash_t h,
kh_cstr_t  key 
)
inlinestatic

Definition at line 96 of file display.h.

◆ kh_init_strhash()

static kh_strhash_t * kh_init_strhash ( void  )
inlinestatic

Definition at line 96 of file display.h.

◆ kh_put_strhash()

static khint_t kh_put_strhash ( kh_strhash_t h,
kh_cstr_t  key,
int ret 
)
inlinestatic

Definition at line 96 of file display.h.

◆ kh_resize_strhash()

static int kh_resize_strhash ( kh_strhash_t h,
khint_t  new_n_buckets 
)
inlinestatic

Definition at line 96 of file display.h.

◆ read_file_into_buffer()

static char * read_file_into_buffer ( FILE fp)
static

Definition at line 123 of file display.h.

References buf, fp, free(), and x.

Referenced by display_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ws_send_array()

static int ws_send_array ( int  fd,
Array a,
int  status,
int  type,
unsigned int shift 
)
static

Definition at line 205 of file display.h.

References a, free(), i, int, npe, p, type, and x.

Referenced by display_send().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ controls

Array* controls

Definition at line 102 of file display.h.

Referenced by display_control_internal(), display_control_update(), and display_onopen().

◆ debug

bool debug

Definition at line 103 of file display.h.

◆ [struct]

◆ display_play

int display_play = 0 < 0 ? -1 : 0

Definition at line 715 of file display.h.

Referenced by display_init(), and event_refresh_display().

◆ display_usage

int display_usage = 20

Definition at line 711 of file display.h.

Referenced by display_init(), and event_refresh_display().

◆ error

char* error

Definition at line 101 of file display.h.

Referenced by createShaderFromString(), input_fatal_error(), and merge().

◆ objects

kh_strhash_t* objects

Definition at line 99 of file display.h.

◆ port

int port

Definition at line 100 of file display.h.

Referenced by display_init().

◆ sock

int sock

Definition at line 100 of file display.h.