Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash when using face meshes and element IDs don't start to 0 #95

Merged
merged 8 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions adapter/CCXHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ enum CouplingDataType { TEMPERATURE,
VELOCITIES,
POSITIONS };

/**
* @brief Type of element used for faces mesh, where we assume only one type of element is used.
* TETRAHEDRA - C3D4 or C3D10 element
* HEXAEDRA - C3D8 or C3D20 elment
boris-martin marked this conversation as resolved.
Show resolved Hide resolved
* INVALID_ELEMENT - Anything else
*/
enum ElemType { TETRAHEDRA,
HEXAEDRA,
boris-martin marked this conversation as resolved.
Show resolved Hide resolved
INVALID_ELEMENT,
};

/**
* @brief Returns node set name with internal CalculiX format
* Prepends and appends an N: e.g. If the input name is "interface",
Expand Down
30 changes: 27 additions & 3 deletions adapter/PreciceInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,28 @@ void PreciceInterface_Create(PreciceInterface *interface, SimulationData *sim, I
PreciceInterface_ConfigureCouplingData(interface, sim, config);
}

static enum ElemType findSimulationMeshType(SimulationData *sim)
{
// Assuming only tetrahedra are used, or only hexaedral, for faces meshes.
// Return first non-zero mesh type.
// lakon tab takes 8 chars per element

const char *lakon_ptr = sim->lakon;
for (int i = 0; i < sim->ne; ++i) {
if (startsWith(lakon_ptr, "C3D4") || startsWith(lakon_ptr, "C3D10")) {
return TETRAHEDRA;
} else if (startsWith(lakon_ptr, "C3D8") || startsWith(lakon_ptr, "C3D20")) {
return HEXAEDRA;
boris-martin marked this conversation as resolved.
Show resolved Hide resolved
}
lakon_ptr += 8;
}

return INVALID_ELEMENT;
}

void PreciceInterface_ConfigureFaceCentersMesh(PreciceInterface *interface, SimulationData *sim)
{
//printf("Entering ConfigureFaceCentersMesh \n");
// printf("Entering ConfigureFaceCentersMesh \n");
char *faceSetName = toFaceSetName(interface->name);
interface->faceSetID = getSetID(faceSetName, sim->set, sim->nset);
interface->numElements = getNumSetElements(interface->faceSetID, sim->istartset, sim->iendset);
Expand All @@ -499,9 +518,14 @@ void PreciceInterface_ConfigureFaceCentersMesh(PreciceInterface *interface, Simu

interface->faceCenterCoordinates = malloc(interface->numElements * 3 * sizeof(double));
interface->preciceFaceCenterIDs = malloc(interface->numElements * 3 * sizeof(int));
if (startsWith(&sim->lakon[1 * 8], "C3D4") || startsWith(&sim->lakon[1 * 8], "C3D10")) {

enum ElemType elemType = findSimulationMeshType(sim);

if (elemType == TETRAHEDRA) {
printf("Configuring faces mesh with tetrahedra.\n");
getTetraFaceCenters(interface->elementIDs, interface->faceIDs, interface->numElements, sim->kon, sim->ipkon, sim->co, interface->faceCenterCoordinates);
} else if (startsWith(&sim->lakon[1 * 8], "C3D8") || startsWith(&sim->lakon[1 * 8], "C3D20")) {
} else if (elemType == HEXAEDRA) {
boris-martin marked this conversation as resolved.
Show resolved Hide resolved
printf("Configuring faces mesh with hexahedra.\n");
getHexaFaceCenters(interface->elementIDs, interface->faceIDs, interface->numElements, sim->kon, sim->ipkon, sim->co, interface->faceCenterCoordinates);
} else {
supportedElementError();
Expand Down
1 change: 1 addition & 0 deletions adapter/PreciceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef struct SimulationData {
int nload;
char * sideload;
double nk;
ITG ne;
ITG mt;
double *theta;
double *dtheta;
Expand Down
1 change: 1 addition & 0 deletions dyna_precice.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ void dyna_precice(double **cop, ITG *nk, ITG **konp, ITG **ipkonp, char **lakonp
.sideload = sideload,
.mt = mt,
.nk = *nk,
.ne = *ne,
.theta = &theta,
.dtheta = &dtheta,
.tper = tper,
Expand Down
1 change: 1 addition & 0 deletions nonlingeo_precice.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ void nonlingeo_precice(double **cop, ITG *nk, ITG **konp, ITG **ipkonp, char **l
.sideload = sideload,
.mt = mt,
.nk = *nk,
.ne = *ne,
.theta = &theta,
.dtheta = &dtheta,
.tper = tper,
Expand Down