Skip to content

Commit

Permalink
Make detection of XGrid regriding information in a Mesh more consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
oehmke committed Dec 12, 2024
1 parent 69450f4 commit 51fa524
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
9 changes: 8 additions & 1 deletion src/Infrastructure/Mesh/include/ESMCI_XGridUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace ESMCI {



/**
*\brief generate a mesh based on the nodes and cells vector. The cells are unique and refer to the nodes.
* @param[in] sintd_nodes vector to allocated intersecting nodal points
Expand Down Expand Up @@ -306,7 +308,12 @@ void test_clip3D(int pdim, int sdim, int num_s, double * s_coord, int num_c, dou
void dump_sph_coords(int num, const double * coord);
void dump_cart_coords(int num, const double * coord, bool only_sph=false);
void dump_polygon(const polygon & poly, bool only_sph=false);


// Whether XGrid is being used for regridding
enum XGRID_USE {XGRID_USE_NONE, XGRID_USE_SRC, XGRID_USE_DST};

// Deterimine if the input meshes have XGrid regridding information and if so what type
XGRID_USE detect_xgrid_regrid_info_type(Mesh &srcmesh, Mesh &dstmesh);


} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Mesh/include/Legacy/ESMCI_MCoord.h>
#include <Mesh/include/Legacy/ESMCI_Sintdnode.h>
#include <Mesh/include/Legacy/ESMCI_SM.h>
#include <Mesh/include/ESMCI_XGridUtil.h>

#include <vector>

Expand Down Expand Up @@ -52,9 +53,6 @@ namespace ESMCI {
} SM_CELL;
#endif

enum XGRID_USE {XGRID_USE_NONE, XGRID_USE_SRC, XGRID_USE_DST};


void calc_2nd_order_weights_2D_3D_sph(const MeshObj *src_elem, MEField<> *src_cfield, MEField<> *src_mask_field,
std::vector<const MeshObj *> dst_elems, MEField<> *dst_cfield, MEField<> * dst_mask_field, MEField<> * dst_frac2_field, XGRID_USE xgrid_use,
double *src_elem_area,
Expand Down
24 changes: 24 additions & 0 deletions src/Infrastructure/Mesh/src/ESMCI_XGridUtil.C
Original file line number Diff line number Diff line change
Expand Up @@ -2978,6 +2978,30 @@ void calc_wgts_from_xgrid_to_side_mesh(Mesh *src_xgrid_mesh, Mesh *dst_side_mesh
else Throw() << "Unexpectedly neither src or dst Mesh is an XGrid.";

}

// Detect if we should use XGrid information for regridding and how
XGRID_USE detect_xgrid_regrid_info_type(Mesh &srcmesh, Mesh &dstmesh) {

XGRID_USE xgrid_use=XGRID_USE_NONE;
if (srcmesh.side==3) {
// Extra check to ensure that it's actually a side mesh going to XGrid
if ((dstmesh.side == 1) || (dstmesh.side == 2)) {
xgrid_use=XGRID_USE_SRC;
}
} else if (dstmesh.side==3) {
// Extra check to ensure that it's actually a side mesh going to XGrid
if ((srcmesh.side == 1) || (srcmesh.side == 2)) {
xgrid_use=XGRID_USE_DST;
}
}

return xgrid_use;
}







} //namespace
43 changes: 10 additions & 33 deletions src/Infrastructure/Mesh/src/Regridding/ESMCI_Interp.C
Original file line number Diff line number Diff line change
Expand Up @@ -768,19 +768,7 @@ void calc_2nd_order_conserve_mat_serial_2D_3D_sph(Mesh &srcmesh, Mesh &dstmesh,
Trace __trace("calc_conserve_mat_serial(Mesh &srcmesh, Mesh &dstmesh, SearchResult &sres, IWeights &iw)");

// See if we're using an XGrid
XGRID_USE xgrid_use=XGRID_USE_NONE;
if (srcmesh.side==3) {
// Extra check to ensure that it's actually a side mesh going to XGrid
if ((dstmesh.side == 1) || (dstmesh.side == 2)) {
xgrid_use=XGRID_USE_SRC;
}
} else if (dstmesh.side==3) {
// Extra check to ensure that it's actually a side mesh going to XGrid
if ((srcmesh.side == 1) || (srcmesh.side == 2)) {
xgrid_use=XGRID_USE_DST;
}
}

XGRID_USE xgrid_use=detect_xgrid_regrid_info_type(srcmesh, dstmesh);

// Get src coord field
MEField<> *src_cfield = srcmesh.GetCoordField();
Expand Down Expand Up @@ -1102,18 +1090,7 @@ void calc_2nd_order_conserve_mat_serial_2D_2D_cart(Mesh &srcmesh, Mesh &dstmesh,
Trace __trace("calc_conserve_mat_serial(Mesh &srcmesh, Mesh &dstmesh, SearchResult &sres, IWeights &iw)");

// See if we're using an XGrid
XGRID_USE xgrid_use=XGRID_USE_NONE;
if (srcmesh.side==3) {
// Extra check to ensure that it's actually a side mesh going to XGrid
if ((dstmesh.side == 1) || (dstmesh.side == 2)) {
xgrid_use=XGRID_USE_SRC;
}
} else if (dstmesh.side==3) {
// Extra check to ensure that it's actually a side mesh going to XGrid
if ((srcmesh.side == 1) || (srcmesh.side == 2)) {
xgrid_use=XGRID_USE_DST;
}
}
XGRID_USE xgrid_use=detect_xgrid_regrid_info_type(srcmesh, dstmesh);

// Get src coord field
MEField<> *src_cfield = srcmesh.GetCoordField();
Expand Down Expand Up @@ -3043,11 +3020,11 @@ interp_method(imethod)
// If 2nd order see if it's an XGrid and then use that
if (interp_method == Interp::INTERP_CONSERVE_2ND) {

// If an XGrid is involved, then do a search using that
if ((grend.GetSrcRend().side==3) || (grend.GetDstRend().side==3)) {
XGridGatherOverlappingElems(grend.GetSrcRend(), grend.GetDstRend(), sres);
} else { // ...otherwise just use the regular search
// If an XGrid isn't involved, then do a search using regular method
if (detect_xgrid_regrid_info_type(grend.GetSrcRend(), grend.GetDstRend()) == XGRID_USE_NONE) {
OctSearchElems(grend.GetSrcRend(), ESMCI_UNMAPPEDACTION_IGNORE, grend.GetDstRend(), unmappedaction, 1e-8, sres);
} else { // ...otherwise use XGrid information
XGridGatherOverlappingElems(grend.GetSrcRend(), grend.GetDstRend(), sres);
}
} else { // ...otherwise just use the regular search
OctSearchElems(grend.GetSrcRend(), ESMCI_UNMAPPEDACTION_IGNORE, grend.GetDstRend(), unmappedaction, 1e-8, sres);
Expand Down Expand Up @@ -3089,11 +3066,11 @@ interp_method(imethod)
// If 2nd order see if it's an XGrid and then use that
if (interp_method == Interp::INTERP_CONSERVE_2ND) {

// If an XGrid is involved, then do a search using that
if ((src->side==3) || (dest->side==3)) {
XGridGatherOverlappingElems(*src, *dest, sres);
} else { // ...otherwise just use the regular search
// If an XGrid isn't involved, then do a search using regular method
if (detect_xgrid_regrid_info_type(*src, *dest) == XGRID_USE_NONE) {
OctSearchElems(*src, ESMCI_UNMAPPEDACTION_IGNORE, *dest, unmappedaction, 1e-8, sres);
} else { // ...otherwise use XGrid info to do search
XGridGatherOverlappingElems(*src, *dest, sres);
}
} else { // ...otherwise just use the regular search
OctSearchElems(*src, ESMCI_UNMAPPEDACTION_IGNORE, *dest, unmappedaction, 1e-8, sres);
Expand Down

0 comments on commit 51fa524

Please sign in to comment.