flowy-code / flowy

A code to simulate lava flows.
GNU General Public License v3.0
5 stars 1 forks source link

Vent flags #9

Closed MSallermann closed 7 months ago

MSallermann commented 7 months ago

Only the vent flags 0 and 2 are implemented so far.

MSallermann commented 7 months ago

A description of all vent_flags:

 This flag select how multiple initial coordinates are treated:
    vent_flag = 0 => the initial lobes are on the vents coordinates
                      and the flows start initially from the first vent,
                      then from the second and so on.
    vent_flag = 1 => the initial lobes are chosen randomly from the vents
                      coordinates and each vent has the same probability
    vent_flag = 2 => the initial lobes are on the polyline connecting
                      the vents and all the point of the polyline
                      have the same probability
    vent_flag = 3 => the initial lobes are on the polyline connecting
                      the vents and all the segments of the polyline
                      have the same probability
    vent_flag = 4 => the initial lobes are on multiple
                      fissures and all the point of the fissures
                      have the same probability
    vent_flag = 5 => the initial lobes are on multiple
                      fissures and all the fissures
                      have the same probability
    vent_flag = 6 => the initial lobes are on the polyline connecting
                      the vents and the probability of
                      each segment is fixed by "fissure probabilities"
    vent_flag = 7 => the initial lobes are on multiple
                      fissures and the probability of
                      each fissure is fixed by "fissure_probabilities"
    vent_flag = 8 => the initial lobes are chosen randomly from the vents
                      coordinates and the probability of each vent
MSallermann commented 7 months ago

Relevant parts of the Mr.LavaLoba code

n_vents = len(x_vent)

if (('x_vent_end' in globals()) and (len(x_vent_end) > 0) and (vent_flag > 3)):

    first_j = 0
    cum_fiss_length = np.zeros(n_vents+1)

else:

    first_j = 1
    cum_fiss_length = np.zeros(n_vents)

for j in range(first_j,n_vents):

    if (('x_vent_end' in globals()) and (len(x_vent_end) > 0) and (vent_flag > 3)):

        delta_xvent = x_vent_end[j] - x_vent[j]
        delta_yvent = y_vent_end[j] - y_vent[j]

        cum_fiss_length[j+1] = cum_fiss_length[j] + np.sqrt( delta_xvent**2 + delta_yvent**2 )

    else:

        delta_xvent =  x_vent[j] - x_vent[j-1]
        delta_yvent =  y_vent[j] - y_vent[j-1]

        cum_fiss_length[j] = cum_fiss_length[j-1] + np.sqrt( delta_xvent**2 + delta_yvent**2 )

if ('fissure_probabilities' in globals()):

    if ( vent_flag == 8 ):

        cum_fiss_length = np.cumsum(fissure_probabilities)

    elif ( vent_flag > 5):

        cum_fiss_length[1:] = np.cumsum(fissure_probabilities)

if ( n_vents >1 ):
    cum_fiss_length = cum_fiss_length.astype(float) / cum_fiss_length[-1]

and

 if ( vent_flag == 0 ):

                # vent_flag = 0  => the initial lobes are on the vents coordinates
                #                   and the flows start initially from the first vent,
                #                   then from the second and so on.

                i_vent = int(np.floor( flow * n_vents / n_flows ) )

                x[i] = x_vent[i_vent]
                y[i] = y_vent[i_vent]

            elif ( vent_flag == 1 ):

                # vent_flag = 1  => the initial lobes are chosen randomly from the vents
                #                   coordinates and each vent has the same probability

                i_vent = np.random.randint(n_vents, size=1)

                x[i] = x_vent[int(i_vent)]
                y[i] = y_vent[int(i_vent)]

            elif ( (vent_flag == 2) or (vent_flag==6) ):

                # vent_flag = 2  => the initial lobes are on the polyline connecting
                #                   the vents and all the point of the polyline
                #                   have the same probability

                # vent_flag = 6  => the initial lobes are on the polyline connecting
                #                   the vents and the probability of
                #                   each segment is fixed in the input file

                alfa_polyline = np.random.uniform(0, 1, size=1)

                idx_vent = np.argmax(cum_fiss_length>alfa_polyline)

                num = alfa_polyline - cum_fiss_length[idx_vent-1]
                den = cum_fiss_length[idx_vent] - cum_fiss_length[idx_vent-1]

                alfa_segment = num / den

                x[i] = alfa_segment * x_vent[idx_vent] + \
                       ( 1.0 - alfa_segment ) * x_vent[idx_vent-1] 

                y[i] = alfa_segment * y_vent[idx_vent] + \
                       ( 1.0 - alfa_segment ) * y_vent[idx_vent-1]

            elif ( vent_flag == 3 ):

                # vent_flag = 3  => the initial lobes are on the polyline connecting
                #                   the vents and all the segments of the polyline
                #                   have the same probability

                i_segment = randrange(n_vents)

                alfa_segment = np.random.uniform(0, 1, size=1)

                x[i] = alfa_segment * x_vent[i_segment] + \
                       ( 1.0 - alfa_segment ) * x_vent[i_segment-1] 

                y[i] = alfa_segment * y_vent[i_segment] + \
                       ( 1.0 - alfa_segment ) * y_vent[i_segment-1]

            elif ( (vent_flag == 4) or (vent_flag == 7) ):

                # vent_flag = 4  => the initial lobes are on multiple
                #                   fissures and all the point of the fissures
                #                   have the same probability

                # vent_flag = 7  => the initial lobes are on multiple
                #                   fissures and the probability of
                #                   each fissure is fixed in the input file

                alfa_polyline = np.random.uniform(0, 1, size=1)

                idx_vent = np.argmax(cum_fiss_length>alfa_polyline)

                num = alfa_polyline - cum_fiss_length[idx_vent-1]
                den = cum_fiss_length[idx_vent] - cum_fiss_length[idx_vent-1]

                alfa_segment = num / den
                print()
                print(idx_vent-1,alfa_segment)

                x[i] = alfa_segment * x_vent_end[idx_vent-1] + \
                       ( 1.0 - alfa_segment ) * x_vent[idx_vent-1] 

                y[i] = alfa_segment * y_vent_end[idx_vent-1] + \
                       ( 1.0 - alfa_segment ) * y_vent[idx_vent-1]

            elif ( vent_flag == 5 ):

                # vent_flag = 5  => the initial lobes are on multiple
                #                   fissures and all the fissures
                #                   have the same probability

                i_segment = randrange(n_vents)

                alfa_segment = np.random.uniform(0, 1, size=1)

                x[i] = alfa_segment * x_vent_end[i_segment] + \
                       ( 1.0 - alfa_segment ) * x_vent[i_segment] 

                y[i] = alfa_segment * y_vent_end[i_segment] + \
                       ( 1.0 - alfa_segment ) * y_vent[i_segment]

            elif ( vent_flag == 8 ):

                # vent_flag = 1  => the initial lobes are chosen randomly from the vents
                #                   coordinates and each vent has the same probability

                alfa_vent = np.random.uniform(0, 1, size=1)
                i_vent = np.argmax(cum_fiss_length>alfa_vent)

                x[i] = x_vent[int(i_vent)]
                y[i] = y_vent[int(i_vent)]
MSallermann commented 7 months ago

This has been mostly done now. See here: a99c9e2e0d97615d2141fd6fdbfecef16992f0d4. Can we have some kind of test for the vent flags?

MSallermann commented 7 months ago

I think this can be closed for now. There should be a separate issue for the question of tests.