Skip to content

Commit

Permalink
evap_trans refactoring (#404)
Browse files Browse the repository at this point in the history
Move initialization of evap_trans to the SetupRichards function.  

Change summary:

    Made Vector *evap_trans part of InstanceXtra structure
    Initialized evap_trans in SetupRichards()
    Deallocated evap_trans in TeardownRichards()

Co-authored-by: Steven Smith <smith84@llnl.gov>
  • Loading branch information
kvrigor and smithsg84 committed Jun 30, 2022
1 parent 4fbf4b9 commit 17b296f
Showing 1 changed file with 21 additions and 32 deletions.
53 changes: 21 additions & 32 deletions pfsimulator/parflow_lib/solver_richards.c
Expand Up @@ -234,6 +234,7 @@ typedef struct {
Vector *old_pressure;
Vector *mask;

Vector *evap_trans; /* sk: Vector that contains the sink terms from the land surface model */
Vector *evap_trans_sum; /* running sum of evaporation and transpiration */
Vector *overland_sum;
Vector *ovrl_bc_flx; /* vector containing outflow at the boundary */
Expand Down Expand Up @@ -830,6 +831,19 @@ SetupRichards(PFModule * this_module)
NewVectorType(z_grid, 1, 2, vector_side_centered_z);
InitVectorAll(instance_xtra->z_velocity, 0.0);

/*sk Initialize LSM terms */
instance_xtra->evap_trans = NewVectorType(grid, 1, 1, vector_cell_centered);
InitVectorAll(instance_xtra->evap_trans, 0.0);

if (public_xtra->evap_trans_file)
{
//sprintf(filename, "%s", public_xtra->evap_trans_filename);
//printf("%s %s \n",filename, public_xtra -> evap_trans_filename);
ReadPFBinary(public_xtra->evap_trans_filename, instance_xtra->evap_trans);

handle = InitVectorUpdate(instance_xtra->evap_trans, VectorUpdateAll);
FinalizeVectorUpdate(handle);
}

/* IMF: the following are only used w/ CLM */
#ifdef HAVE_CLM
Expand Down Expand Up @@ -1535,6 +1549,11 @@ AdvanceRichards(PFModule * this_module, double start_time, /* Starting time
Vector *evap_trans_sum = instance_xtra->evap_trans_sum;
Vector *overland_sum = instance_xtra->overland_sum; /* sk: Vector of outflow at the boundary */

if (evap_trans == NULL)
{
evap_trans = instance_xtra->evap_trans;
}

#ifdef HAVE_OAS3
Grid *grid = (instance_xtra->grid);
Subgrid *subgrid;
Expand Down Expand Up @@ -3903,6 +3922,7 @@ TeardownRichards(PFModule * this_module)
FreeVector(instance_xtra->x_velocity);
FreeVector(instance_xtra->y_velocity);
FreeVector(instance_xtra->z_velocity);
FreeVector(instance_xtra->evap_trans);

if (instance_xtra->evap_trans_sum)
{
Expand Down Expand Up @@ -5950,59 +5970,28 @@ SolverRichards()
{
PFModule *this_module = ThisPFModule;
PublicXtra *public_xtra = (PublicXtra*)PFModulePublicXtra(this_module);
InstanceXtra *instance_xtra =
(InstanceXtra*)PFModuleInstanceXtra(this_module);

Problem *problem = (public_xtra->problem);

double start_time = ProblemStartTime(problem);
double stop_time = ProblemStopTime(problem);

Grid *grid = (instance_xtra->grid);

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

char filename[2048];

VectorUpdateCommHandle *handle;

/*
* sk: Vector that contains the sink terms from the land surface model
*/
Vector *evap_trans;

SetupRichards(this_module);

/*sk Initialize LSM terms */
evap_trans = NewVectorType(grid, 1, 1, vector_cell_centered);
InitVectorAll(evap_trans, 0.0);

if (public_xtra->evap_trans_file)
{
sprintf(filename, "%s", public_xtra->evap_trans_filename);
//printf("%s %s \n",filename, public_xtra -> evap_trans_filename);
ReadPFBinary(filename, evap_trans);

handle = InitVectorUpdate(evap_trans, VectorUpdateAll);
FinalizeVectorUpdate(handle);
}

AdvanceRichards(this_module,
start_time,
stop_time,
NULL,
evap_trans, &pressure_out, &porosity_out, &saturation_out);
NULL, &pressure_out, &porosity_out, &saturation_out);

/*
* Record amount of memory in use.
*/
recordMemoryInfo();

TeardownRichards(this_module);

FreeVector(evap_trans);
}

/*
Expand Down

0 comments on commit 17b296f

Please sign in to comment.