コード例 #1
0
/*!
 * \brief Compute the transmission boundary condition in 2d
 *
 * This function calculates the transmission boundary condition
 * for each cell with status N_CELL_TRANSMISSION. The surrounding
 * gradient field is used to verfiy the flow direction. If a flow
 * goes into a cell, the concentration (data->c) from the neighbour cell is
 * added to the transmission cell. If the flow from several neighbour 
 * cells goes into the cell, the concentration mean is calculated.
 * 
 * The new concentrations are written into the data->c_start array,
 * so they can be handled by the matrix assembling function.
 *
 * \param data N_solute_transport_data2d *
 * \return void *
 * */
void N_calc_solute_transport_transmission_2d(N_solute_transport_data2d * data)
{
    int i, j, count = 1;
    int cols, rows;
    double c;
    N_gradient_2d grad;

    cols = data->grad->cols;
    rows = data->grad->rows;

    G_debug(2,
	    "N_calc_solute_transport_transmission_2d: calculating transmission boundary");

    for (j = 0; j < rows; j++) {
	for (i = 0; i < cols; i++) {
	    if (N_get_array_2d_d_value(data->status, i, j) ==
		N_CELL_TRANSMISSION) {
		count = 0;
		/*get the gradient neighbours */
		N_get_gradient_2d(data->grad, &grad, i, j);
		c = 0;
		/*
		   c = N_get_array_2d_d_value(data->c_start, i, j);
		   if(c > 0)
		   count++;
		 */

		if (grad.WC > 0 &&
		    !N_is_array_2d_value_null(data->c, i - 1, j)) {
		    c += N_get_array_2d_d_value(data->c, i - 1, j);
		    count++;
		}
		if (grad.EC < 0 &&
		    !N_is_array_2d_value_null(data->c, i + 1, j)) {
		    c += N_get_array_2d_d_value(data->c, i + 1, j);
		    count++;
		}
		if (grad.NC < 0 &&
		    !N_is_array_2d_value_null(data->c, i, j - 1)) {
		    c += N_get_array_2d_d_value(data->c, i, j - 1);
		    count++;
		}
		if (grad.SC > 0 &&
		    !N_is_array_2d_value_null(data->c, i, j + 1)) {
		    c += N_get_array_2d_d_value(data->c, i, j + 1);
		    count++;
		}
		if (count != 0)
		    c = c / (double)count;
		/*make sure it is not NAN */
		if (c > 0 || c == 0 || c < 0)
		    N_put_array_2d_d_value(data->c_start, i, j, c);
	    }
	}
    }

    return;
}
コード例 #2
0
ファイル: test_arrays.c プロジェクト: AsherBond/MondocosmOS
/* ************************************************************************* */
int fill_array_2d_null(N_array_2d * a)
{
    int rows, cols;
    int i, j, res = 0;

    cols = a->cols;
    rows = a->rows;

    #pragma omp parallel for private (i, j) shared (rows, cols, a) reduction(+:res)
    for (j = 0; j < rows; j++) {
        for (i = 0; i < cols; i++) {
            N_put_array_2d_value_null(a, i, j);
            if (!N_is_array_2d_value_null(a, i, j))
                res++;
        }
    }

    return res;
}