Skip to content

Commit

Permalink
Generalize prune emissions option for user-defined test function.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiandenner committed Apr 13, 2024
1 parent 1d50c09 commit eb4ce8f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
3 changes: 2 additions & 1 deletion include/apecss.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ struct APECSS_Emissions

// Pruning the list of emission nodes
int pruneList; // Flag indicating whether the linked list is pruned
APECSS_FLOAT pruneTolerance; // Tolerance below which a node is pruned
int (*prune_test)(struct APECSS_EmissionNode *Node);

// Pointer to the function advancing the emission nodes
int (*advance)(struct APECSS_Bubble *Bubble);
Expand Down Expand Up @@ -519,6 +519,7 @@ int apecss_emissions_updatenone(struct APECSS_Bubble *Bubble);
int apecss_emissions_updatelinkedlist(struct APECSS_Bubble *Bubble);
int apecss_emissions_addnode(struct APECSS_Bubble *Bubble);
int apecss_emissions_prunelist(struct APECSS_Bubble *Bubble);
int apecss_emissions_prune_no_node(struct APECSS_EmissionNode *Node);
int apecss_emissions_removenode(struct APECSS_Bubble *Bubble);
int apecss_emissions_advance_finitespeedincompressible(struct APECSS_Bubble *Bubble);
int apecss_emissions_advance_quasiacoustic(struct APECSS_Bubble *Bubble);
Expand Down
14 changes: 10 additions & 4 deletions src/bubble.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ int apecss_bubble_readoptions(struct APECSS_Bubble *Bubble, char *OptionsDir)
else if (strncasecmp(option2, "pruneemissions", 14) == 0)
{
Bubble->Emissions->pruneList = 1;

l = apecss_readoneoption(OptionsFile, option3);
Bubble->Emissions->pruneTolerance = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "kbitertolerance", 15) == 0)
{
Expand Down Expand Up @@ -821,7 +818,16 @@ int apecss_bubble_initialize(struct APECSS_Bubble *Bubble)
// ---------------------------------------
// Emissions

if (Bubble->Emissions != NULL) Bubble->Emissions->CutOffDistance = APECSS_MAX(Bubble->Emissions->CutOffDistance, Bubble->R0);
if (Bubble->Emissions != NULL)
{
Bubble->Emissions->CutOffDistance = APECSS_MAX(Bubble->Emissions->CutOffDistance, Bubble->R0);

if (Bubble->Emissions->pruneList && Bubble->Emissions->prune_test == NULL)
{
apecss_erroronscreen(0, "Prune emissions option invoked but no test function defined. No nodes will be pruned!");
Bubble->Emissions->prune_test = apecss_emissions_prune_no_node;
}
}

// ---------------------------------------
// Results
Expand Down
27 changes: 18 additions & 9 deletions src/emissions.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int apecss_emissions_initializestruct(struct APECSS_Bubble *Bubble)
Bubble->Emissions->KB_IterTolerance = 1.0;
Bubble->Emissions->nNodes = 0;
Bubble->Emissions->pruneList = 0;
Bubble->Emissions->pruneTolerance = 1.0e-6;
Bubble->Emissions->prune_test = NULL;
Bubble->Emissions->FirstNode = NULL;
Bubble->Emissions->LastNode = NULL;
Bubble->Emissions->advance = NULL;
Expand Down Expand Up @@ -135,16 +135,13 @@ int apecss_emissions_addnode(struct APECSS_Bubble *Bubble)

int apecss_emissions_prunelist(struct APECSS_Bubble *Bubble)
{
struct APECSS_EmissionNode *Current = Bubble->Emissions->LastNode->backward;
APECSS_FLOAT tol = Bubble->Emissions->pruneTolerance;
APECSS_FLOAT pinf = Bubble->get_pressure_infinity(Bubble->t, Bubble);

if (Current != NULL)
if (Bubble->Emissions->nNodes > 2) // The list needs to consist of at least 3 nodes.
{
struct APECSS_EmissionNode *Current = Bubble->Emissions->LastNode->backward;

while (Current->backward != NULL)
{
if (APECSS_MAX(APECSS_ABS(Current->backward->p - Current->forward->p), APECSS_ABS(Current->backward->p - Current->p)) <
tol * APECSS_ABS(Current->p - pinf))
if (Bubble->Emissions->prune_test(Current))
{
struct APECSS_EmissionNode *Obsolete = Current;
Current->backward->forward = Current->forward;
Expand Down Expand Up @@ -932,4 +929,16 @@ APECSS_FLOAT apecss_emissions_f_kirkwoodbethe(struct APECSS_Bubble *Bubble, stru
(Bubble->get_dimensionalradius(Node->r) * Node->r * Node->u -
Node->r * Node->g / (Bubble->Liquid->get_soundspeed(Node->p, Bubble->Liquid->get_density(Node->p, Bubble->Liquid), Bubble->Liquid) + Node->u)) /
(Bubble->dimensionality + APECSS_SMALL));
}
}

// -------------------------------------------------------------------
// PRUNING OF EMISSION NODES
// -------------------------------------------------------------------
// Dummy test function for the pruning of emission nodes.
// -------------------------------------------------------------------
// This function is hooked up to the function pointer
// Bubble->Emissions->prune_test() if no user-defined test function
// has been defined. No nodes will be pruned.
// -------------------------------------------------------------------

int apecss_emissions_prune_no_node(struct APECSS_EmissionNode *Node) { return (0); }

0 comments on commit eb4ce8f

Please sign in to comment.