function particleclaw_network_ex_diamond
%PARTICLECLAW_NETWORK_EX_DIAMOND
%   Particle method for scalar hyperbolic conservation laws
%   laws on networks.
%   Example of a diamond network with the Lighthill-Whitham-
%   Richards (LWR) traffic model on each edge.
%
%   Description of method:
%   https://link.springer.com/chapter/10.1007/978-3-642-32979-1_13
%   https://arxiv.org/abs/1201.0057
%
% 12/2010 by Benjamin Seibold and Yossi Farjoun
%            http://www.math.temple.edu/~seibold/

%========================================================================
% Problem Parameters
%========================================================================
par = struct(...
'name','Diamond Network',... % name for title
'name_figure','diamond',... % name for data and figure files
'h',2e-1,... % initial/desired distance of particles
'd',5e-2,... % distance of particles near shock
'framenr',0,...
'tfinal',5,...
'flag_plot',1,...
'flag_color',1,...
'flag_save_figure',0,...
'plot_style',2,...
'flag_plot_edge_truncate',0,...
'dt',1e-1... % synchronization time step
);

%========================================================================
% Solver Execution
%========================================================================
[V,E] = network(par.h);
particleclaw_network_solver(par,V,E)                         % run solver

%========================================================================
% Problem Specific Functions
%========================================================================
function [V,E] = network(h)
% list of vertices
% in-edges, out-edges, position, distribution matrix
V = {...
    {}   ,{1}  ,[0, -.25],[];...
    {1}  ,{2,3},[1, 0],[.6];...
    {2}  ,{4,5},[2, 1],[.5];...
    {3,4},{6}  ,[2,-1],[];...
    {5,6},{7}  ,[3, 0],[];...
    {7}  ,{}   ,[4, -.25],[];...
    };
% list of edges
x = linspace(0,1,ceil(1/h*2.5));
u = .5+.4*sin(3*pi*x);
% [in node,out node], length, {rho_M,u_M}, solution
dl = sqrt(2);
E = {...
    [1,2],1 ,{1,1},x,u*.1;...
    [2,3],dl,{1,1},x*dl,u;...
    [2,4],dl,{1,1},x*dl,u*.5;...
    [3,4],2 ,{1,1},x*2,.7-u*.5;...
    [3,5],dl,{1,1},x*dl,u*.5;...
    [4,5],dl,{1,1},x*dl,u*.5;...
    [5,6],1 ,{1,1},x,u;...
    };
