User Manual: Code: model.c

From FLUX

Jump to: navigation, search

(Return to Code or the User Manual)

model.c contains the high level entry points for running a simulation.

Contents

Entry points

world_check

int world_check(WORLD *a)

Performs some cursory checks on validness of a WORLD. This gets called automatically by read_world, but could be handy elsewhere too. If the world was OK, returns 0. Minor tweaks are performed on the World in the course of checking (such as deleting duplicate VERTEXes). If these happened, then it returns 1. If the world seems to be incorrectably bad, returns -1. Error/warning messages are printed to stderr.

world_update_neighbors

void world_update_neighbors(WORLD *a, char global)

Performs a neighbor update on the whole WORLD: walks through the WORLD tree, calling fluxon_update_neighbors for each fluxon.

world_update_mag

NUM *world_update_mag(WORLD *a, char global)

Performs a force update on the whole WORLD: walks through the WORLD tree, calling fluxon_update_mag for each fluxon.

world_relax_step

world_relax_step(WORLD *a, NUM dtau)

This is the main stepper entry point: performs a neighbor and force update on the whole world, calculates test steps, executes the step (with optional acceleration), and updates the fluxon end conditions.

Relaxation handling

fluxon_update_neighbors

void fluxon_update_neighbors(FLUXON *fl, char global)

Loops over the VERTEXes in a FLUXON, calling vertex_update_neighbors on each. This is useful as part of an arena-wide neighbor update, but not as part of a step or force law update (which requires temporary variables in each VERTEX's neighbor VERTEXes; these temporary variables that are overwritten as the neighbor process proceeds).

fluxon_update_mag

fluxon_update_mag(FLUXON *fl, char global, void ((**f_funcs)()), NUM *minmax)

Loops over the VERTEXes in a FLUXON, updating neighbors (with vertex_update_neighbors)) calling the relevant force routines for each one to update the relevant force-per-unit-length accumulators.

fluxon_calc_step

void fluxon_calc_step(FLUXON *fl, NUM t)

Loops over the VERTEXes, updating neighbors (with vertex_update_neighbors) and calling the relevant force routines for each one. The resulting force-per-unit-length values are used to determine a planned step length. No step is actually made.

fluxon_relax_step

void fluxon_relax_step(FLUXON *fl, NUM t)

Actually executes fluxon position steps previously calculated by fluxon_calc_step. This is separated out to allow post-processing to accelerate relaxation of large regions that contain many fluxons in overall bulk motion.

Neighbor handling

vertex_update_neighbors

HULL_VERTEX *vertex_update_neighbors(VERTEX *v, char global)

Calculates and updates the neighbor list for a single VERTEX, and the corresponding nearby lists for its adjacent vertices. The global flag indicates whether to include every single vertex in the simulation as a candidate neighbor, or only the nearest and next-nearest. Suitable values of the GLOBAL flag are:

  • 0 - normal non-global operation (typically about 300 candidates)
  • 1 - global operation (every single vertex is a candidate)
  • 2 - reduced operation (neighbors, next-neighbors, and neighbors' next/prev only: about 60-70 candidates)
  • 3 - stripped-down operation (neighbors and their next/prev only: about 24 candidates)
  • 4 - gonzo operation (current neighbors only: about 7 candidates)

In normal use, use 0 or 1.

gather_neighbor_candidates

DUMBLIST *gather_neighbor_candidates(VERTEX *v, char global)

Collects neighbor candidates into a global stash. Internal helper routine for vertex_update_neighbors.

winnow_neighbor_candidates

void winnow_neighbor_candidates(VERTEX *v, DUMBLIST *horde)

Removes duplicates from the neighbor candidate list - internal to vertex_update_neighbors.

hull_neighbors

HULL_VERTEX *hull_neighbors(VERTEX *v, DUMBLIST *horde)

Executes the hull algorithm in geometry.c to select real neighbors from a large collection of candidates. Internal to vertex_update_neighbors.

Grid refinement

fix_proximity

fix_proximity(VERTEX *V, NUM scale_thresh) Proximity grid refinement on a single vertex - adds vertices if the intervertex separation to the next vertex is longer than the distance between the vertex and its closest neighbor.

fluxon_fix_proximity

int fluxon_fix_proximity(FLUXON *f, NUM scale_thresh)

Loops along a fluxon, calling fix_proximity for each VERTEX on it.

global_fix_proximity

int global_fix_proximity(FLUXON *F, NUM scale_thresh)

Loops over every fluxon in the WORLD, calling fluxon_fix_proximity on each one.

fix_curvature

int fix_curvature(VERTEX *V, NUM curve_thresh_high, NUM curve_thresh_low)

This is the curvature maintenance code -- adds vertices or deletes the current vertex depending on the amount of bend at the vertex. If the bend is greater than the curve_thresh_high, then more vertices are added. If the bend is less than curve_thresh_low, then the vertex is deleted.

fluxon_fix_curvature

int fluxon_fix_curvature(FLUXON *F, NUM curve_thresh_high, NUM curve_thresh_low)

Loops over all the vertices in a fluxon, calling fix_curvature on each one.

global_fix_curvature

int global_fix_curvature(WORLD *w, NUM curve_thresh_high, NUM curve_thresh_low)

Loops over the whole WORLD, calling fluxon_fix_curvature on each fluxon in it.

Reconnection

reconnect_vertices

void reconnect_vertices( VERTEX *v1, VERTEX *v2 )

Given two vertices, reconnect the fluxons that hold them. Supports self-reconnection (which creates a plasmoid) and heterogeneous plasmoid reconnection (which destroys a plasmoid).

vertex_recon_check

int vertex_recon_check(VERTEX *v1)

Runs through the list of reconnection criteria to see if the current VERTEX needs to be reconnected to anyone.

fluxon_recon_check

long fluxon_recon_check( FLUXON *f )

Loops vertex_recon_check over all the VERTEXes in a fluxon.

global_recon_check

long global_recon_check( WORLD *w )

Loops fluxon_recon_check over all the fluxons in the world.

Statistics

world_collect_stats

VERTEX_STATS *world_collect_stats(WORLD *w)

fluxon_collect_stats

void fluxon_collect_stats(FLUXON *fl, VERTEX_STATS *st)

Boundary conditions

world_update_ends

void world_update_ends(WORLD *a)

Walks through every fluxon and calls fluxon_update_ends, below, for each one. Not normally used (fluxon_update_ends gets called directly from the stepping code.)

fluxon_update_ends

void fluxon_update_ends(FLUXON *fl)

Calls the end condition handlers associated with both FLUX_CONCENTRATIONS that end a fluxon. That keeps the fluxon consistent with, e.g., plasmoid and open-field end conditions. Also checks the associated WORLD and, if the auto_open flag is set, it calls fluxon_auto_open (below) to handle newly opened fluxons.

fluxon_auto_open

void fluxon_auto_open(FLUXON *f)

Handles cutting-and-splicing of fluxons that penetrate the open-field locus specified in the WORLD's open FLUX_CONCENTRATIONs (world.fc_ob and world.fc_oe). Normally called from fluxon_update_ends.

fluxon end-condition handlers

The end-condition handlers are called by fluxon_relax_step after the vertex locations on each fluxon have been moved. The handlers update the ends of the fluxon by forcing them into compliance with the end condition for the fluxon. Each fluxon starts at once FLUX_CONCENTRATION and ends at another, and all FLUX_CONCENTRATIONs contain a function pointer to an end condition (or 0).

fl_b_tied_inject

Handles line-tied conditions. Normally fluxon_relax_step does not update the positions of the ends of its fluxon, but fl_b_tied_inject forces them to the locations of the corresponding FLUX_CONCENTRATION anyway. More importantly, it maintains a tight VERTEX spacing: the first non-end VERTEX is required to be within the locale radius (stored in the locale_radius field of the FLUX_CONCENTRATION) of the concentration's location. If it isn't, then the code generates a new VERTEX that is within the radius. Works on either start or end vertices.

fl_b_tied_force

Handles line-tied conditions. Normally fluxon_relax_step does not update the positions of the ends of its fluxon, but fl_b_tied_force forces them to the locations of the corresponding FLUX_CONCENTRATION anyway. More importantly, it maintains a tight VERTEX spacing: the first non-end VERTEX is required to be within the locale radius (stored in the locale_radius field of the FLUX_CONCENTRATION) of the concentration's location. If it isn't, then the code forces it to have the maximum allowed distance. Works on either start or end vertices.

fl_b_start_open

Handles open boundary conditions, by forcing a start vertex onto the sphere set by the corresponding FLUX_CONCENTRATION's locale radius and location (the locale_radius and x fields). The vertex is moved radially outward or inward to the surface of the sphere.

Only works on start vertices.

Normally, the only FLUX_CONCENTRATION set to fl_b_start_open is the special open-start concentration stored in the WORLD's fc_ob field.

fl_b_end_open

Handles open boundary conditions, by forcing an end vertex onto the sphere set by the corresponding FLUX_CONCENTRATION's locale radius and location (the locale_radius and x fields). The vertex is moved radially outward or inward to the surface of the sphere.

Only works on end vertices.

Normally, the only FLUX_CONCENTRATION set to fl_b_end_open is the special open-end concentration stored in the WORLD's fc_oe field.


fl_b_start_plasmoid

Handles the start-of-plasmoid boundary condition, by copying the location of the second-to-last VERTEX on the fluxon into the start VERTEX.

Only works on start vertices.

Normally, the only FLUX_CONCENTRATION set to fl_b_start_plasmoid is the special plasmoid-start concentration stored in the WORLD's fc_pb field.


fl_b_end_plasmoid

Handles the end-of-plasmoid boundary condition, by copying the location of the second VERTEX on the fluxon into the end VERTEX.

Only works on end vertices.

Normally, the only FLUX_CONCENTRATION set to fl_b_end_plasmoid is the special plasmoid-end concentration stored in the WORLD's fc_pe field.