Example #1
0
void AllocateAlquimiaProperties(const AlquimiaSizes* const sizes,
                                AlquimiaProperties* props) {
  AllocateAlquimiaVectorDouble(sizes->num_isotherm_species,
                               &(props->isotherm_kd));
  AllocateAlquimiaVectorDouble(sizes->num_isotherm_species,
                               &(props->freundlich_n));
  AllocateAlquimiaVectorDouble(sizes->num_isotherm_species,
                               &(props->langmuir_b));
  AllocateAlquimiaVectorDouble(sizes->num_minerals,
                               &(props->mineral_rate_cnst));
  AllocateAlquimiaVectorDouble(sizes->num_aqueous_kinetics,
                               &(props->aqueous_kinetic_rate_cnst));

}  /* end AllocateAlquimiaProperties() */
Example #2
0
void AllocateAlquimiaAuxiliaryData(const AlquimiaSizes* const sizes,
                                   AlquimiaAuxiliaryData* aux_data) {
  AllocateAlquimiaVectorInt(sizes->num_aux_integers,
                            &(aux_data->aux_ints));

  AllocateAlquimiaVectorDouble(sizes->num_aux_doubles,
                               &(aux_data->aux_doubles));

}  /* end AllocateAlquimiaAuxiliaryData() */
Example #3
0
void DriverOutput_WriteMulticompVector(DriverOutput* output, 
                                       const char* filename,
                                       AlquimiaVectorString comp_names,
                                       AlquimiaVectorDouble multicomp_vector)
{
  int num_comps = comp_names.size;
  if ((multicomp_vector.size % num_comps) != 0)
  {
    alquimia_error("DriverOutput_WriteMulticompVector: multicomp_vector data has invalid size for %d components (%d).", 
                   num_comps, multicomp_vector.size);
  }
  int vec_size = multicomp_vector.size / num_comps;
  AlquimiaVectorDouble var_vectors[num_comps];
  for (int i = 0; i < num_comps; ++i)
  {
    AllocateAlquimiaVectorDouble(vec_size, &var_vectors[i]);
    for (int j = 0; j < vec_size; ++j)
      var_vectors[i].data[j] = multicomp_vector.data[num_comps*j+i];
  }
  DriverOutput_WriteVectors(output, filename, comp_names, var_vectors);
  for (int i = 0; i < num_comps; ++i)
    FreeAlquimiaVectorDouble(&var_vectors[i]);
}
Example #4
0
void AllocateAlquimiaState(const AlquimiaSizes* const sizes,
                           AlquimiaState* state) {
  AllocateAlquimiaVectorDouble(sizes->num_primary, &(state->total_mobile));
  ALQUIMIA_ASSERT(state->total_mobile.data != NULL);

  AllocateAlquimiaVectorDouble(sizes->num_sorbed, &(state->total_immobile));

  AllocateAlquimiaVectorDouble(sizes->num_surface_sites,
                               &(state->surface_site_density));

  AllocateAlquimiaVectorDouble(sizes->num_ion_exchange_sites,
                               &(state->cation_exchange_capacity));

  AllocateAlquimiaVectorDouble(sizes->num_minerals,
                               &(state->mineral_volume_fraction));

  AllocateAlquimiaVectorDouble(sizes->num_minerals,
                               &(state->mineral_specific_surface_area));
}  /* end AllocateAlquimiaState() */
Example #5
0
void AllocateAlquimiaAuxiliaryOutputData(const AlquimiaSizes* const sizes,
                                         AlquimiaAuxiliaryOutputData* aux_output) {
  aux_output->pH = -999.9;
  AllocateAlquimiaVectorDouble(sizes->num_minerals,
                               &(aux_output->mineral_saturation_index));

  AllocateAlquimiaVectorDouble(sizes->num_aqueous_kinetics,
                               &(aux_output->aqueous_kinetic_rate));

  AllocateAlquimiaVectorDouble(sizes->num_minerals,
                               &(aux_output->mineral_reaction_rate));

  AllocateAlquimiaVectorDouble(sizes->num_primary,
                               &(aux_output->primary_free_ion_concentration));
  AllocateAlquimiaVectorDouble(sizes->num_primary,
                               &(aux_output->primary_activity_coeff));

  AllocateAlquimiaVectorDouble(sizes->num_aqueous_complexes,
                               &(aux_output->secondary_free_ion_concentration));
  AllocateAlquimiaVectorDouble(sizes->num_aqueous_complexes,
                               &(aux_output->secondary_activity_coeff));

}  /* end AllocateAlquimiaAuxiliaryOutputData() */
Example #6
0
void TransportDriver_GetSoluteAndAuxData(TransportDriver* driver,
                                         double* time,
                                         AlquimiaVectorString* var_names,
                                         AlquimiaVectorDouble* var_data)
{
  // Destroy the contents of the vectors we're given.
  if (var_names->size > 0)
    FreeAlquimiaVectorString(var_names);
  if (var_data->size > 0)
    FreeAlquimiaVectorDouble(var_data);

  // Construct a list of all variables, which are those in the state and 
  // the auxiliary output data, and fill their data.
  int num_cells = driver->num_cells;
  int num_primary = driver->chem_sizes.num_primary;
  int num_sorbed = driver->chem_sizes.num_sorbed;
  int num_minerals = driver->chem_sizes.num_minerals;
  int num_surface_sites = driver->chem_sizes.num_surface_sites;
  int num_ion_exchange_sites = driver->chem_sizes.num_ion_exchange_sites;
  int num_aqueous_complexes = driver->chem_sizes.num_aqueous_complexes;
  int num_aqueous_kinetics = driver->chem_sizes.num_aqueous_kinetics;
  int num_vars = 1 +                        // grid cell locations 
                 num_primary +              // total mobile
                 num_sorbed +               // total immobile
                 2 * num_minerals +         // mineral volume fractions, specific surface area
                 num_surface_sites +        // surface site density
                 num_ion_exchange_sites +   // cation exchange capacity
                 1 +                        // pH
                 num_aqueous_kinetics +     // aqueous kinetic rate
                 2 * num_minerals +         // mineral saturation index, reaction rate
                 2 * num_primary +          // primary free ion concentration, activity coeff
                 2 * num_aqueous_complexes; // secondary free ion concentration, activity coeff
  int counter = 0;
  AllocateAlquimiaVectorString(num_vars, var_names);
  AllocateAlquimiaVectorDouble(num_vars * driver->num_cells, var_data);
  {
    var_names->data[counter] = AlquimiaStringDup("x");
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->x_min + (j+0.5) * (driver->x_max - driver->x_min) / driver->num_cells;
    ++counter;
  }
  for (int i = 0; i < num_primary; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "total_mobile[%s]", driver->chem_metadata.primary_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_state[j].total_mobile.data[i];
  }
  for (int i = 0; i < num_sorbed; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "total_immobile[%d]", i);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_state[j].total_immobile.data[i];
  }
  for (int i = 0; i < num_minerals; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "mineral_volume_fractions[%s]", driver->chem_metadata.mineral_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_state[j].mineral_volume_fraction.data[i];
  }
  for (int i = 0; i < num_minerals; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "mineral_specific_surface_area[%s]", driver->chem_metadata.mineral_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_state[j].mineral_specific_surface_area.data[i];
  }
  for (int i = 0; i < num_surface_sites; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "surface_site_density[%s]", driver->chem_metadata.surface_site_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_state[j].surface_site_density.data[i];
  }
  for (int i = 0; i < num_ion_exchange_sites; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "cation_exchange_capacity[%s]", driver->chem_metadata.ion_exchange_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_state[j].cation_exchange_capacity.data[i];
  }
  {
    var_names->data[counter] = AlquimiaStringDup("pH");
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].pH;
    ++counter;
  }
  for (int i = 0; i < num_aqueous_kinetics; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "aqueous_kinetic_rate[%s]", driver->chem_metadata.aqueous_kinetic_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].aqueous_kinetic_rate.data[i];
  }
  for (int i = 0; i < num_minerals; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "mineral_saturation_index[%s]", driver->chem_metadata.mineral_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].mineral_saturation_index.data[i];
  }
  for (int i = 0; i < num_minerals; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "mineral_reaction_rate[%s]", driver->chem_metadata.mineral_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].mineral_reaction_rate.data[i];
  }
  for (int i = 0; i < num_primary; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "primary_free_ion_concentration[%s]", driver->chem_metadata.primary_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].primary_free_ion_concentration.data[i];
  }
  for (int i = 0; i < num_primary; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "primary_activity_coeff[%s]", driver->chem_metadata.primary_names.data[i]);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].primary_activity_coeff.data[i];
  }
  for (int i = 0; i < num_aqueous_complexes; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "secondary_free_ion_concentration[%d]", i);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].secondary_free_ion_concentration.data[i];
  }
  for (int i = 0; i < num_aqueous_complexes; ++i, ++counter)
  {
    char var_name[1024];
    snprintf(var_name, 1023, "secondary_activity_coeff[%d]", i);
    var_names->data[counter] = AlquimiaStringDup(var_name);
    for (int j = 0; j < num_cells; ++j)
      var_data->data[num_vars*j + counter] = driver->chem_aux_output[j].secondary_activity_coeff.data[i];
  }
}