Ticket #78 (new task)

Opened 4 years ago

Last modified 4 years ago

pseudo-fields and the FieldTypeIsDensity macro

Reported by: dreynolds Owned by: somebody
Priority: minor Milestone: Enzo 1.5 Code Development
Component: enzo Version: 1.5
Keywords: Cc:

Description

In the conversion to Enzo 1.5, a number of additional field types were added to typedefs.h (pseudo-fields). Immediately following their definition is an existing macro, FieldTypeIsDensity?, that returns TRUE or FALSE depending on whether the argument is a density field or not. This macro is now incorrect, given the newly-defined fields.

My question is this: will that cause a problem? The FieldTypeIsDensity? macro is used throughout the AMR handling of parent/child interfaces, so I would be somewhat concerned that any 'pseudo-field' (or for that matter a new emissivity field -- Geoffrey), would be treated incorrectly.

Change History

Changed 4 years ago by rpwagner

This probably isn't tripping anything up, since the pseudo-fields, and things like GravPotential are never baryon fields. But, to keep things correct, I would suggest changing the current macro to exclude fields above ExtraType1.

From this:

#define FieldTypeIsDensity(A) (((A) >= TotalEnergy && (A) <= Velocity3) ? FALSE : TRUE)

to

#define FieldTypeIsDensity(A) (((A) >= TotalEnergy && (A) <= Velocity3 \
                                    || (A) >= ExtraType1) ? FALSE : TRUE)

Either that or shove all the density fields to the beginning of the list.

Changed 4 years ago by jbordner

Current definition of FieldTypeIsDensity in the devel branch, as of revision 2224 (formatted for readability):

#define FieldTypeIsDensity(A) 
   ( 
     ( 
       (
         (A) >= TotalEnergy 
           && 
         (A) <= Velocity3
       ) 
         || 
       ( 
         (A) >= Mach 
           && 
         ( 
           (A) <= (Mach + 2 + CRModel - 1) 
             && 
           (A) <= Mach + 3
         ) 
       ) 
     ) ? FALSE : TRUE
   )

Below are all occurrences of FieldTypeIsDensity with additional logic:

A

  • FluxFix_Grid_CorrectForRefinedFluxes.C:330
  • FluxFix_Grid_CorrectForRefinedFluxes.C:461
  • Grid_CorrectForRefinedFluxes.C:196
  • Grid_CorrectForRefinedFluxes.C:328
        FieldTypeIsDensity(FieldType[field]) == FALSE
          &&
        (
           RadiativeCooling == 0 
             || 
           (
             FieldType[field] != TotalEnergy 
               &&
             FieldType[field] != InternalEnergy
           )
        )
    

B

  • FluxFix_Grid_CorrectForRefinedFluxes.C:440
        (
           FieldTypeIsDensity(FieldType[field]) == TRUE 
             ||
           FieldType[field] == TotalEnergy 
             ||
           FieldType[field] == InternalEnergy
        )
          &&
        (
           BaryonField[field][FieldIndex] <= 0 
             ||
           BaryonField[field][FieldIndex+Offset] <= 0
        )
    

C

  • Grid_CorrectForRefinedFluxes.C:263
        (
           FieldTypeIsDensity(FieldType[field]) == TRUE 
             ||
           FieldType[field] == TotalEnergy 
             ||
           FieldType[field] == InternalEnergy
        )
          &&
        BaryonField[field][FieldIndex] <= 0
    

D

  • Grid_CorrectForRefinedFluxes.C:298
        (
           FieldTypeIsDensity(FieldType[field]) == TRUE 
             ||
           FieldType[field] == TotalEnergy 
             ||
           FieldType[field] == InternalEnergy
         )
           &&
         BaryonField[field][FieldIndex + Offset] <= 0.0
    

E

  • Grid_InterpolateBoundaryFromParent.C:298
  • Grid_InterpolateBoundaryFromParent.C:344
  • Grid_InterpolateFieldValues.C:272
  • Grid_InterpolateFieldValues.C:317
        FieldTypeIsDensity(FieldType[field]) == FALSE
    

F

  • Grid_ProjectSolutionToParentGrid.C:130
  • Grid_ProjectSolutionToParentGrid.C:215
        FieldTypeIsDensity(FieldType[field]) == FALSE 
          && 
        (
          (
             FieldType[field] < Velocity1 
               || 
             FieldType[field] > Velocity3
          ) 
            || 
          HydroMethod != Zeus_Hydro      
        )
    

Questions/issues/suggestions, etc.:

  • FieldTypeIsDensity is getting too complicated for a macro and should be rewritten as a function.
  • The top level definition "(X) ? FALSE : TRUE" is read as "if X is true then return false, else if X is false return true", which is confusing.
  • Some of the additional logic in the conditionals where FieldTypeIsDensity is called seems suspicious: in particular, A and the first clause of B above are almost-but-not-quite negations of each other (only A includes RadiativeCooling == 0 ).
  • Perhaps subsuming some of the additional logic into multiple aptly-named variations of FieldTypeIsDensity would be helpful in maintaining correctness.
Note: See TracTickets for help on using tickets.