Skip to content

Commit

Permalink
Modify PointList to also hold orig. coords. for pole point fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
oehmke committed Sep 23, 2023
1 parent e0e175b commit c3f598e
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 9 deletions.
21 changes: 19 additions & 2 deletions src/Infrastructure/PointList/include/ESMCI_PointList.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,28 @@ namespace ESMCI {

point *points;

int orig_coord_dim;
point *orig_points; // Contains original coord points. Id is repeated from above to allow sorting. In separate list to
// keep typical implementation as standard as possible. i


public:
// Construct
PointList(int max_size, int coord_dim);

// Construct
PointList(int max_size, int coord_dim, int orig_coord_dim=0);

// Destruct
~PointList();

// Detect original coords
bool hasOrigCoords() const {return (orig_points != NULL);}

// Add Point to List
int add(int _id, const double *_coord);

// Add Point to List including original coords
int add(int _id, const double *_coord, const double *_orig_coord);

// diagnostic print to file
int WriteVTK(const char *filename);

Expand All @@ -87,11 +99,16 @@ namespace ESMCI {
// Get a pointer to the coordinates for a particular location
const double *get_coord_ptr(int loc) const;

// Get a pointer to the original coordinates for a particular location
const double *get_orig_coord_ptr(int loc) const;

// Get a pointer to the id for a particular location
const int *get_id_ptr(int loc) const;

void get_coord(int loc, double *_coord) const;

void get_orig_coord(int loc, double *_orig_coord) const;

// Get id for a particular location
int get_id(int loc) const;

Expand Down
212 changes: 205 additions & 7 deletions src/Infrastructure/PointList/src/ESMCI_PointList.C
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ namespace ESMCI {
//
// !ARGUMENTS:
int _max_num_pts,
int _coord_dim
int _coord_dim,
int _orig_coord_dim // If 0, no original coords allocated
// Defaults to 0.
){
//
// !DESCRIPTION:
Expand All @@ -80,21 +82,25 @@ namespace ESMCI {
//-----------------------------------------------------------------------------
// Set values
coord_dim=_coord_dim;
orig_coord_dim=_orig_coord_dim;
max_num_pts=_max_num_pts;
curr_num_pts=0;

// allocate memory
// Allocate point memory
points = NULL;

if (max_num_pts>=0) {
points=new point [max_num_pts];
}

// return successfully
// Allocate orig coords memory, if it's asked for
orig_points = NULL;
if ( (_orig_coord_dim > 0) && (max_num_pts >= 0)) {
orig_points=new point [max_num_pts];
}
}



// STOPPED HERE ///

#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::~PointList()"
Expand All @@ -121,10 +127,15 @@ namespace ESMCI {
max_num_pts=0;
curr_num_pts=0;
coord_dim=0;

orig_coord_dim=0;

// Deallocate memory
if (points!=NULL) delete [] points;
points=NULL;

if (orig_points!=NULL) delete [] orig_points;
orig_points=NULL;

}


Expand All @@ -145,7 +156,7 @@ namespace ESMCI {
//
int _id,
const double *_coord
) {
) {
//
// !DESCRIPTION:
// Add a point to the PointList.
Expand Down Expand Up @@ -177,6 +188,85 @@ namespace ESMCI {
points[curr_num_pts].coords[i] = _coord[i];
}


// Advance to next position
curr_num_pts++;

// return successfully
rc = ESMF_SUCCESS;
return rc;


}

#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::PointList::add()"
//BOPI
// !IROUTINE: add
//
// !INTERFACE:
int PointList::add(

//
// !RETURN VALUE:
// none
//
// !ARGUMENTS:
//
int _id,
const double *_coord,
const double *_orig_coord
) {
//
// !DESCRIPTION:
// Add a point to the PointList.
//
//EOPI
//-----------------------------------------------------------------------------

// initialize return code; assume routine not implemented
int localrc = ESMC_RC_NOT_IMPL; // local return code
int rc = ESMC_RC_NOT_IMPL; // final return code

// Error checks
if (curr_num_pts >= max_num_pts) {
int localrc;
ESMC_LogDefault.MsgFoundError(ESMC_RC_VAL_WRONG,
" attempting to add to a full PointList ",
ESMC_CONTEXT, &localrc);
throw localrc;
}

if (!hasOrigCoords()) {
int localrc;
ESMC_LogDefault.MsgFoundError(ESMC_RC_VAL_WRONG,
" attempting to add original coords to a PointList that wasn't created to hold them.",
ESMC_CONTEXT, &localrc);
throw localrc;
}




// IF START EXTENDING POINT LIST WHEN OVER SIZE, THEN SWITCH TO VECTORS

// Add point id
points[curr_num_pts].id = _id;

// Add point coords
for (int i=0; i<coord_dim; i++) {
points[curr_num_pts].coords[i] = _coord[i];
}

// Add id for original points
orig_points[curr_num_pts].id=_id; // for sorting

// Add point original coords
for (int i=0; i<orig_coord_dim; i++) {
orig_points[curr_num_pts].coords[i] = _orig_coord[i];
}


// Advance to next position
curr_num_pts++;

Expand All @@ -187,6 +277,9 @@ namespace ESMCI {

}




#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::PointList::sort_by_id()"
//BOPI
Expand Down Expand Up @@ -225,6 +318,11 @@ namespace ESMCI {
// printf("sort time= %.4f\n",tend-tbeg);
// fflush(stdout);

// If present, also sort original coords
if (hasOrigCoords()) {
std::sort(orig_points,orig_points+curr_num_pts);
}

// return successfully
rc = ESMF_SUCCESS;
return rc;
Expand Down Expand Up @@ -492,6 +590,61 @@ namespace ESMCI {
return;
}

#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::PointList::get_orig_coord()"
//BOPI
// !IROUTINE: get_orig_coord
//
// !INTERFACE:
void PointList::get_orig_coord(

//
// !RETURN VALUE:
// none
//
// !ARGUMENTS:
//
int loc, double *_orig_coord) const {
//
// !DESCRIPTION:
// copy original coordinates corresponding to given location into a given array.
//
//EOPI
//-----------------------------------------------------------------------------

// Error checks
if (loc<0 || loc>=curr_num_pts) {
int localrc;
ESMC_LogDefault.MsgFoundError(ESMC_RC_VAL_WRONG,
" invalid location in PointList ",
ESMC_CONTEXT, &localrc);
throw localrc;
}

if (!hasOrigCoords()) {
int localrc;
ESMC_LogDefault.MsgFoundError(ESMC_RC_VAL_WRONG,
" attempting to get original coord. from a PointList that doesn't have them.",
ESMC_CONTEXT, &localrc);
throw localrc;
}

if (_orig_coord == NULL) {
int localrc;
ESMC_LogDefault.MsgFoundError(ESMC_RC_VAL_WRONG,
" provided array pointer is NULL ",
ESMC_CONTEXT, &localrc);
throw localrc;
}

// Copy coordinates
for (int i=0; i<orig_coord_dim; i++) {
_orig_coord[i]=orig_points[loc].coords[i];
}

return;
}


#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::PointList::get_id()"
Expand Down Expand Up @@ -597,4 +750,49 @@ namespace ESMCI {
return points[loc].coords;
}


#undef ESMC_METHOD
#define ESMC_METHOD "ESMCI::PointList::get_orig_coord_ptr()"
//BOPI
// !IROUTINE: get_coord_ptr
//
// !INTERFACE:
const double *PointList::get_orig_coord_ptr(

//
// !RETURN VALUE:
// double *
//
// !ARGUMENTS:
//
int loc) const {
//
// !DESCRIPTION:
// return pointer to original coordinates corresponding to given location.
//
//EOPI
//-----------------------------------------------------------------------------

// Error check
if (loc<0 || loc>=curr_num_pts) {
int localrc;
ESMC_LogDefault.MsgFoundError(ESMC_RC_VAL_WRONG,
"- invalid location in PointList ",
ESMC_CONTEXT, &localrc);
throw localrc;
}

if (!hasOrigCoords()) {
int localrc;
ESMC_LogDefault.MsgFoundError(ESMC_RC_VAL_WRONG,
" attempting to get original coord. from a PointList that doesn't have them.",
ESMC_CONTEXT, &localrc);
throw localrc;
}

// Pass back pointer
return orig_points[loc].coords;
}


} // namespace ESMCI

0 comments on commit c3f598e

Please sign in to comment.