//------------------------------------------------------------------ void multiply_scalar(double s, doubleArray* toArray_p) { int i; double val; for(i = 0; i < toArray_p->m_size ; i++) { val = s * value_at(toArray_p, i); set_value_at(toArray_p, i, val); } }
//------------------------------------------------------------------ void cube(doubleArray* array_p, doubleArray* toArray_p) { int i; double val, cv; for(i = 0; i < array_p->m_size ; i++) { val = value_at(array_p, i); cv = val*val*val; set_value_at(toArray_p, i, cv); } }
//------------------------------------------------------------------ void sum_array(doubleArray* array_p, doubleArray* toArray_p) { int i; double val_one, val_two, sum; for(i = 0; i < array_p->m_size ; i++) { val_one = value_at(array_p, i); val_two = value_at(toArray_p, i); sum = val_one + val_two; set_value_at(toArray_p, i, sum); } }
void laplace(doubleArray* array_p, doubleArray* toArray_p, double dx) { double fdown, f, fup, newval; int i, arraySize; arraySize = array_p->m_size; for(i = 0; i < arraySize; i++) { fdown = value_at(array_p, i - 1); f = value_at(array_p, i); fup = value_at(array_p, i + 1); newval = central_second_deriv(fdown, f, fup, dx); set_value_at(toArray_p, i, newval); } }
void shift_rows_down(int *board, int r) { if (r > 0 && r < BOARD_HEIGHT - 1) { // For each column, for (int c = 0; c < BOARD_WIDTH; c++) { int prev = 0; // Go down each row, for (int ri = 0; ri <= r; ri++) { // Get the value of the current row int next = value_at(board, ri, c); // And replace it with the one from above set_value_at(board, ri, prev); prev = next; } } } }
void buildmatrix(RAIteratorI i_it, RAIteratorJ j_it, RAIteratorV v_it, IndexType n, AccumT accum = AccumT()) { for (IndexType idx = 0; idx < n; ++idx) { IndexType i = i_it[idx]; IndexType j = j_it[idx]; if ((i >= m_num_rows) || (j >= m_num_cols)) { throw DimensionException(); } set_value_at(i, j, accum(get_value_at(i, j), v_it[idx])); } }
//------------------------------------------------------------------ int do_time_step(doubleArray* valArray_p, doubleArray* dArray_p, double dt) { int i; double dval, fval, newval; if (valArray_p->m_size != dArray_p->m_size) { return 0; } for(i = 0; i < valArray_p->m_size; i++) { fval = value_at(valArray_p, i); dval = value_at(dArray_p, i); newval = singe_time_step(fval, dval, dt); set_value_at(valArray_p, i, newval); //valArray_p->m_elements[i] = singe_time_step(valArray_p->m_elements[i], // dArray_p->m_elements[i], // dt); } return 1; }