void model_addgroup(struct model *m, const struct mesh *g, const vector *offset) { DEBUG(2, "Adding group to model, total = %d\n", m->ngroups + 1); REALLOC(m->groups, m->ngroups + 1); REALLOC(m->offsets, m->ngroups + 1); mesh_copy(&m->groups[m->ngroups], g); m->offsets[m->ngroups] = *offset; m->ngroups++; }
/* For diffusion step in the flow problem */ int mesh_diffusion_iteration(mesh_t *mesh, mesh_t *mesh_old, double conv_cutoff, int block_type, int rank, send_vectors_t *send_vec, receive_vectors_t *rec_vec) { int itr = 0; mesh_t *temp; mesh_compute_diffusion_coef_source(mesh); mesh_compute_diffusion_coef_source(mesh_old); mesh_compute_beta_A(mesh, &cell_diff_ops); mesh_update_robin(mesh, &cell_diff_ops); mesh_compute_beta_A(mesh_old, &cell_diff_ops); mesh_update_robin(mesh_old, &cell_diff_ops); mpi_comm(mesh, send_vec, rec_vec, block_type, rank, ROBIN_MODE); mpi_comm(mesh_old, send_vec, rec_vec, block_type, rank, ROBIN_MODE); for (;;) { itr++; // diffusion_test_update(mesh, mesh_old); mesh_update(mesh, mesh_old, block_type, &cell_diff_ops); // break; if ((mesh_diff_convergence_check(mesh, mesh_old, conv_cutoff, rank)) && (itr > 2)) { break; } if (!(itr % 100)) { printf("Iteration: %d\n", itr); } mesh_update_robin(mesh, &cell_diff_ops); mpi_comm(mesh, send_vec, rec_vec, block_type, rank, ROBIN_MODE); temp = mesh; mesh = mesh_old; mesh_old = temp; } mesh_update_saturation_time(mesh); mesh_copy(mesh, mesh_old); return itr; }
/* For the pressure step in the flow problem */ int mesh_pressure_iteration(mesh_t *mesh, mesh_t *mesh_old, double conv_cutoff, int block_type, int rank, send_vectors_t *send_vec, receive_vectors_t *rec_vec) { int itr = 0; mesh_t *temp; mesh_compute_beta_A(mesh, &cell_press_ops); mesh_update_robin(mesh, &cell_press_ops); mesh_compute_beta_A(mesh_old, &cell_press_ops); mesh_update_robin(mesh_old, &cell_press_ops); mpi_comm(mesh_old, send_vec, rec_vec, block_type, rank, ROBIN_MODE); mpi_comm(mesh, send_vec, rec_vec, block_type, rank, ROBIN_MODE); for (;;) { itr++; mesh_update(mesh, mesh_old, block_type, &cell_press_ops); if (mesh_press_convergence_check(mesh, mesh_old, conv_cutoff, rank)) { break; } // if (rank == 0) { // print_attribute(mesh, "saturation"); // } // break; mesh_press_impose_0_average(mesh, rank); mesh_update_robin(mesh, &cell_press_ops); mpi_comm(mesh, send_vec, rec_vec, block_type, rank, ROBIN_MODE); temp = mesh; mesh = mesh_old; mesh_old = temp; } mesh_compute_velocity(mesh); mesh_set_velocity(mesh, mesh_old); mesh_copy(mesh, mesh_old); return itr; }
struct model *model_create(const struct mesh *data) { struct model *m; m = CALLOC1(struct model); if (data) { DEBUG(3, "model_create(%p) = %p\n", data, m); DEBUG(2, "Created new model\n"); m->ngroups = 1; m->groups = mesh_create(); mesh_copy(m->groups, data); m->offsets = CALLOC1(vector); } else { DEBUG(3, "model_create(NULL) = %p\n", m); DEBUG(2, "Created new empty model\n"); } return m; }
/* Time step for the transport problem */ int mesh_transport_iteration(mesh_t *mesh, mesh_t *mesh_old, int block_type, int rank, send_vectors_t *send_vec, receive_vectors_t *rec_vec) { mesh_t *temp; /* Computes phase mobility of water derivative*/ set_phase_mob_deriv(mesh, mesh_old); /* Computes dt_transport for both meshes */ mesh_max_time_step(mesh, mesh_old); double dtt = mesh->dim.dt_transport; int num_ts = (int) (mesh->dim.dt / dtt) + 1; double remainder_ts = mesh->dim.dt - ((double) (num_ts - 1) * dtt); // for (int i = 0; i < (num_ts - 1); i++) { for (int i = 0; i < num_ts; i++) { mesh_update(mesh, mesh_old, block_type, &cell_trans_ops); mpi_comm(mesh, send_vec, rec_vec, block_type, rank, SAT_MODE); temp = mesh; mesh = mesh_old; mesh_old = temp; } mesh->dim.dt_transport = remainder_ts; mesh_old->dim.dt_transport = remainder_ts; mesh_update(mesh, mesh_old, block_type, &cell_trans_ops); mpi_comm(mesh, send_vec, rec_vec, block_type, rank, SAT_MODE); /* sets current s to s_prev */ mesh_update_saturation_time(mesh); mesh_copy(mesh, mesh_old); return num_ts; }