PFModule  *DupPFModule(PFModule  *pf_module)
{
    return  NewPFModule((void *)(pf_module -> call),
			(void *)(pf_module -> init_instance_xtra),
			(void *)(pf_module -> free_instance_xtra),
			(void *)(pf_module -> new_public_xtra),
			(void *)(pf_module -> free_public_xtra),
			(void *)(pf_module -> sizeof_temp_data),
			PFModuleInstanceXtra(pf_module),
			PFModulePublicXtra(pf_module));
}
Beispiel #2
0
void wrfparflowadvance_(double *current_time,
                        double *dt,
                        float * wrf_flux,
                        float * wrf_pressure,
                        float * wrf_porosity,
                        float * wrf_saturation,
                        int *   num_soil_layers,
                        int *   ghost_size_i_lower,
                        int *   ghost_size_j_lower,
                        int *   ghost_size_i_upper,
                        int *   ghost_size_j_upper)

{
  ProblemData *problem_data = GetProblemDataRichards(amps_ThreadLocal(solver));

  double stop_time = *current_time + *dt;

  Vector       *pressure_out;
  Vector       *porosity_out;
  Vector       *saturation_out;

  VectorUpdateCommHandle   *handle;

  WRF2PF(wrf_flux, *num_soil_layers,
         *ghost_size_i_lower, *ghost_size_j_lower,
         *ghost_size_i_upper, *ghost_size_j_upper,
         amps_ThreadLocal(evap_trans),
         ProblemDataIndexOfDomainTop(problem_data));

  /*
   * Exchange ghost layer data for the newly set fluxes
   */
  handle = InitVectorUpdate(evap_trans, VectorUpdateAll);
  FinalizeVectorUpdate(handle);

  // SGS this is somewhat inefficient as we are allocating
  // a pf module for each timestep.
  double initial_step = *dt;
  double growth_factor = 2.0;
  double max_step = *dt;
  // SGS what should this be set to?
  double min_step = *dt * 1e-8;

  PFModule *time_step_control;

  time_step_control = NewPFModule((void*)SelectTimeStep,
                                  (void*)WRFSelectTimeStepInitInstanceXtra, \
                                  (void*)SelectTimeStepFreeInstanceXtra, \
                                  (void*)WRFSelectTimeStepNewPublicXtra, \
                                  (void*)WRFSelectTimeStepFreePublicXtra, \
                                  (void*)SelectTimeStepSizeOfTempData, \
                                  NULL, NULL);

  ThisPFModule = time_step_control;
  WRFSelectTimeStepNewPublicXtra(initial_step,
                                 growth_factor,
                                 max_step,
                                 min_step);
  ThisPFModule = NULL;

  PFModule *time_step_control_instance = PFModuleNewInstance(time_step_control, ());

  AdvanceRichards(amps_ThreadLocal(solver),
                  *current_time,
                  stop_time,
                  time_step_control_instance,
                  amps_ThreadLocal(evap_trans),
                  &pressure_out,
                  &porosity_out,
                  &saturation_out);

  PFModuleFreeInstance(time_step_control_instance);
  PFModuleFreeModule(time_step_control);

  /* TODO: SGS
   * Are these needed here?  Decided to put them in just be safe but
   * they could be unnecessary.
   */
  handle = InitVectorUpdate(pressure_out, VectorUpdateAll);
  FinalizeVectorUpdate(handle);
  handle = InitVectorUpdate(porosity_out, VectorUpdateAll);
  FinalizeVectorUpdate(handle);
  handle = InitVectorUpdate(saturation_out, VectorUpdateAll);
  FinalizeVectorUpdate(handle);

  PF2WRF(pressure_out, wrf_pressure, *num_soil_layers,
         *ghost_size_i_lower, *ghost_size_j_lower,
         *ghost_size_i_upper, *ghost_size_j_upper,
         ProblemDataIndexOfDomainTop(problem_data));

  PF2WRF(porosity_out, wrf_porosity, *num_soil_layers,
         *ghost_size_i_lower, *ghost_size_j_lower,
         *ghost_size_i_upper, *ghost_size_j_upper,
         ProblemDataIndexOfDomainTop(problem_data));

  PF2WRF(saturation_out, wrf_saturation, *num_soil_layers,
         *ghost_size_i_lower, *ghost_size_j_lower,
         *ghost_size_i_upper, *ghost_size_j_upper,
         ProblemDataIndexOfDomainTop(problem_data));
}