Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Error when trying to compile UDF

TAGGED: ,

    • Tim LS
      Subscriber

      Hi, I was just wondering what this error might be:

      udf_names.c(6): error C2449: found '{' at file scope (missing function header?)

      udf_names.c(20): fatal error C1004: unexpected end-of-file found

      I get it when I try to compile my UDF with "Microsoft Visual C++" compiler and linker

    • Rob
      Forum Moderator

      Check the syntax. I'd expect Parse errors for most of the missing/extra characters though. Did you write the all/sections of the code from scratch or copy from the documentation (CTRL+C & CTRL+P)?

    • Tim LS
      Subscriber

      I'll have another look at the syntax. 

      I have written like 95% of the code from scratch.

    • Tim LS
      Subscriber

      The code is running now. It seems like it was a syntax error, as you suggested. Had the starting { at the same line as DEFINE_SOURCE(), instead of one line below. Thank you for your help! :)

    • Tim LS
      Subscriber

      Hello again,

      I have another question. My model has two UDSs. However, only one of them changes in value during the simulation. This occurs even when I tried to use the same source term for both UDSs. So my question is if you have any idea on what might be causing this?

      Id don't know if its worth mentioning, but is is a multiphase simulation, with UDS defined in a gas phase, and the other is defined in a water phase.

    • Rob
      Forum Moderator

      Check which phase the UDS and source are assigned to. Multiphase may include a domain/mixture/phase thread as part of the cell loop. Review https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v241/en/flu_udf/flu_udf_MultiphaseDEFINE.html  for some examples. 

    • Tim LS
      Subscriber

      I have assigned them like this:

       

      I then hooked the sources to their corresponding UDS in their correct phase in the "Cell zone conditions tab."

      I access the threads like this: 

      Domain *water_domain;
      Domain *bubble_domain;
      w_domain = Get_Domain(2);
      b_domain = Get_Domain(3);

      int fluid_zone_ID = 322;
      Thread *tg = Lookup_Thread(b_domain, fluid_zone_ID);
      Thread *tw = Lookup_Thread(w_domain, fluid_zone_ID);
       
      Where the fluid_zone_ID is the ID found for the fluid under "Cell zone conditions". The threads seem to be correct, as when I print C_MU_L(c, t_i) I get the correct viscosity of phase i.
       
      Some weird behavior is that: 
      • When I initialize the UDS in the water phase as > 0, and UDS in the gas phase = 0, then UDS in the water phase doesn't change, but UDS in the gas phase grows
      • When I initialize the UDS in the water phase as > 0, and UDS in the gas phase > 0, the UDS in water phase doesn't change, but the UDS in gas phase drops to 0 in the first step and stays there.
      • When I initialize the UDS in the water phase as = 0 and UDS in the gas phase > 0, the UDS in the water phase doesn't change, but the UDS in the gas phase drops to 0 in the first step and stays there.
       
       
       
       

       

       

    • Rob
      Forum Moderator

      You may find the scalar value is shown where the phase fraction is near enough zero. In that case the scalar value is usually nonsense. Looking at the above, set UDS_0 as 0 in water, and UDS_1 as 0 in air. Depending on where the UDS is coming from the solver should then do something. 

    • Tim LS
      Subscriber

      So, I am trying to model a flotation column. The UDSs are supposed to account for the amount of oil in each phase. That is, UDS_0 is the number of oil droplets attached to bubbles, while UDS_1 is the number of oil droplets in the water phase. The process is semi-batch, where the air enters and leaves the column contineously, while the oil is added as a batch in the start of the process. Hence, UDS_1 is initialized to some value in the whole domain, while UDS_0 is initialized to 0. The initial condition of the column is a column of only water and oil.

      When I run the simulation UDS_0 increases very quickly, while UDS_1 alsmot doesnt change at all. I would expect them to chenge with equal, but opposite magnitude as all the oil the leaves the water phase shoud enter/get attached to the air phase. Also, I observe that UDS_0 cange quickly in regions where there are almost no air.

      I printed my source terms while running, and they seem to be of equal magnitude but opposite sign. 

      Do you have any idea what I might be doing wrong? 

       

       

    • Rob
      Forum Moderator

      Why would oil enter the air phase? By flotation column are you bubbling gas in at the bottom and trying to remove the last few oil droplets from the water? 

    • Tim LS
      Subscriber

      Yeah, "oil entering the air phase" was not the best way to put it, as it doesn't really enter it. The oil droplets coalesce with the air bubbles and thus attach to it as a lens on the bubble surface. The reason I have two transport equations, one for the amount attached to bubbles and one for the amount in the water phase is that they move at different speeds through the column. You want the oil to stick to the bubbles, such that they can be separated out faster.

      Your description of flotation is correct.

    • Rob
      Forum Moderator

      OK, thanks. I need to tread carefully as I'm not supposed to stray into giving engineering advice.... 

      Thinking about the mechanism. Oil droplets are present in the water, with a given volume fraction, and are probably small. Small gas bubbles are pushed in from the bottom from sparger bars.  The oil & gas stick & the whole lot goes out the top. In theory anyway! If we leave the scalar to one side. Are the oil droplets small enough to be considered as a species in the liquid? 

    • Tim LS
      Subscriber

      Yes, the oil droplets are small enough to be considered a species. 

      So, I tried to use species transport equations to account for the amount of oil droplets in each phase. The transfer of oil droplets was accounted for by using UDF source terms. 

      Once I start the run, the transport equation for oil in gas seem to update just fine. However, the oil in water transport equation (the one that is initialized to some value in the whole domain) has a very low residual of 1e-18 almost throughout the whole run. 

      I was thinking that this seems excessively small, and I'm worried that this might be a problem, e.g., they being so low that the transport equation isn't being solved properly.

      Do you have any suggestions on what might be causing the low residual?  

    • Rob
      Forum Moderator

      That suggests that there isn't any in the model - a species field with zero fraction may return a zero residual. Patching with multiphase multispecies does require more care as you're initialising & patching and the various patch regions/values can interact in odd ways. 

    • Tim LS
      Subscriber

      I think the field is properly patched, as the contour plot of the oil-in-water looks fine. I can also see that the oil is removed from the correct places. However, the quantities that are removed are quite small. Might something be off with the scaling of the residuals?

      I was also wondering if there is any difference between using DEFINE_SOURCE() and DEFINE_MASS_TRANSFER() to account for oil transfer between the two phases. For example, if it easier to achieve mass conversation with DEFINE_MASS_TRANSFER? 

       

       

    • Rob
      Forum Moderator

      Source terms will add/remove material or stuff from cells. You set the rates so you'd need contact area etc from the solver to get the phase change and would have to manually resolve everything.  DEFINE_MASS_TRANSFER should handle most/all of the mass & energy for you,  https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v241/en/flu_udf/flu_udf_MultiphaseDEFINE.html%23flu_udf_sec_define_mass_transfer

Viewing 15 reply threads
  • The topic ‘Error when trying to compile UDF’ is closed to new replies.