Fluids

Fluids

Error In Computing Source Term

    • Venky_94
      Subscriber

      I've written a UDF for surface tension source term as per the below equations.

    • YasserSelima
      Subscriber
      the error is in line = C_UDSI_G ...nthe gradient has two components or three components .. x, y or x,y,z ... but n is defined as realnnmake it nreal n[ND_ND];n
    • DrAmine
      Ansys Employee
      What do you want to achieve with the UDF? That is the question which I have.n
    • YasserSelima
      Subscriber
      same problem will occur in k ... it should be declared k[ND_ND] ... and it can not fill C_UDSI , because they have different dimensionsn
    • Venky_94
      Subscriber

      What do you want to achieve with the UDF? That is the question which I have.https://forum.ansys.com/discussion/comment/112138#Comment_112138

      @DrAmine, I'm sorry I wasn't clearer earlier. Please refer to the picture in my original post above. I'm adding a source term to model the surface tension which is exactly the same as the CSF model by Brackbill et al. already implemented in Fluent, but there is one small change which is indicated in bold at the bottom of the image (I want to smoothen the interface by changing the definition of the cell phase fraction, and area-averaging it).nn
    • Venky_94
      Subscriber

      the error is in line n = C_UDSI_G ...the gradient has two components or three components .. x, y or x,y,z ... but "n" is defined as realmake it real n[ND_ND];https://forum.ansys.com/discussion/comment/112130#Comment_112130

      Thanks for your suggestions. I've made some modifications to the code, and was able to declare n as a vector using real n[ND_ND] and perform the corresponding operation using NV_V(n, =, C_UDSI_G(c,t,0)).nThe below are the concepts I'm struggling with right now.nncap is a vector that has the value ( n/NV_MAG(n) ), where n is also a vector. How would I perform the operation of dividing a vector by a scalar? As the command as it is gives me an error 'error C2296: '/': illegal, left operand has type 'real [2]'' Is there a NV macro that can handle this?nI need to calculate the divergence of the vector ncap (or simply said - the Laplacian) and store it in k. How would I go about this?n
    • YasserSelima
      Subscriber
      nfor the first one, try NV_S(n,/,NV_MAG(n)) ;nNot sure about the second, sorryn
    • Venky_94
      Subscriber

      for the first one, try NV_S(n,/,NV_MAG(n)) ;Not sure about the second, sorryhttps://forum.ansys.com/discussion/comment/112353#Comment_112353

      Thanks. I tried out the below command, I declared n and ncap as real n[ND_ND] and real ncap[ND_ND] respectively and stored a gradient in n using NV_V(n, =, C_UDSI_G(c,t,0)).nncap = NV_S(n, /, NV_MAG(n));nHowever I'm getting the below error using the above command, I'm not quite sure what's wrong.nerror C2440: '=': cannot convert from 'real' to 'real [2]'n
    • Venky_94
      Subscriber

      https://forum.ansys.com/discussion/comment/112138#Comment_112138@DrAmine I'm sorry I wasn't clearer earlier. Please refer to the picture in my original post above. I'm adding a source term to model the surface tension which is exactly the same as the CSF model by Brackbill et al. already implemented in Fluent, but there is one small change which is indicated in bold at the bottom of the image (I want to smoothen the interface by changing the definition of the cell phase fraction, and area-averaging it).https://forum.ansys.com/discussion/comment/112278#Comment_112278

      @DrAmine, @Rob, Could you please guide on how to calculate the laplacian of a scalar? The scalar in this case is stored in UDS0 right now. I know that I can get the first derivative of that using UDSI_G for that UDS0. I can get the unit vector by dividing the gradient by its magnitude. But for getting the divergence of the unit vector, I'll have to get the derivative of that and sum the x and y components right? How do I go about doing that?n
    • DrAmine
      Ansys Employee
      I am sure that smoothing is not required as it is anyway offered by Fluent. Check Smoothing steps under surface tension.n
    • DrAmine
      Ansys Employee
      For divergence calculation I recommend avoid using UDSS to get gradient of gradients. It is better to rely on Finite Volume Way to get gradients and to have then Laplacian. The code is bit tricky but very complex. n
    • YasserSelima
      Subscriber
      Try doing it this waynnNV_VS(ncap,= ,n,/ NV_MAG(n))nnThe rule that fluent use for this macro is ... V, stands for vector ... S, for scalar ... and D, for order .. try to arrange any operation using the three letters. The macros mentioned in the UDF manual are only examples. Some examples in many chapters used macros that were not mentioned.n
    • Venky_94
      Subscriber

      Try doing it this wayNV_VS(ncap,= ,n,/ NV_MAG(n))nThe rule that fluent use for this macro is ... V, stands for vector ... S, for scalar ... and D, for order .. try to arrange any operation using the three letters. The macros mentioned in the UDF manual are only examples. Some examples in many chapters used macros that were not mentioned.https://forum.ansys.com/discussion/comment/112558#Comment_112558

      Thanks a lot. It worked out this time. I tried out the same command earlier, but it gave me an error. I'm not sure what data type I declared ncap as earlier and maybe it was because of that.n
    • YasserSelima
      Subscriber
      You are welcome!n
    • Venky_94
      Subscriber

      For divergence calculation I recommend avoid using UDSS to get gradient of gradients. It is better to rely on Finite Volume Way to get gradients and to have then Laplacian. The code is bit tricky but very complex.https://forum.ansys.com/discussion/comment/112508#Comment_112508

      @DrAmine, Could you guide me on how to do that?nWith @YasserSelima, 's help, I was able to calculate and store the unit vector n̂. Now I just need to handle the term ∇⋅n̂, which is the divergence of the vector. Please suggest.n
    • YasserSelima
      Subscriber
      why don't you make an intermediate step and then store only the required component. nStore ncap components in 2/3 UDM and then recall the gradient .. take the required component onlynn
    • Venky_94
      Subscriber

      why don't you make an intermediate step and then store only the required component. Store ncap components in 2/3 UDM and then recall the gradient .. take the required component onlyhttps://forum.ansys.com/discussion/comment/112593#Comment_112593

      This is my understanding of the above. Please correct me if I'm wrong.nStore the x and y component of ncap in 2 separate UDS (UDS1 and UDS2).nGet the x-component gradient of UDS1 by UDSG1[0] and x-component gradient of UDS2 by UDSG2[1] and add UDSG1[0] and UDSG2[1] to get the term ∇⋅n̂ .nIs my understanding right? If it is, just suggest on how to obtain only the x and y components of ncap in a UDS. Will ncap[0] or ncap[1] work?n
    • Venky_94
      Subscriber

      why don't you make an intermediate step and then store only the required component. Store ncap components in 2/3 UDM and then recall the gradient .. take the required component onlyhttps://forum.ansys.com/discussion/comment/112593#Comment_112593

      This is the understanding of the above. Please correct me if I'm wrong.nGet the x and y components of the unit vector ncap and store them in 2 separate UDS (UDS1 and UDS2 respectively).nGet the x-component gradient of UDS1 as UDSG1[0] and y-component gradient of UDS2 as UDSG2[1]. Add the terms UDSG1[0] and UDSG[1] to get the term ∇⋅n̂.nIs the above approach what you suggested? If it is right, could you please suggest on how to obtain the x and y component of ncap separately? Would the commands ncap[0] and ncap[1] work?n
    • YasserSelima
      Subscriber
      yes, this is what I meant but UDM instead of UDS but still worknncap[0] is the x component of ncapn
    • YasserSelima
      Subscriber
      Just a hint ... the gradients you get will be a mix of the new values at the current iteration and the previous values, depending if the adjacent cells are updated or not n
    • Venky_94
      Subscriber

      yes, this is what I meant but UDM instead of UDS but still workncap[0] is the x component of ncaphttps://forum.ansys.com/discussion/comment/112612#Comment_112612

      I understood that but I didn't think there was a Macro, say C_UDMI_G to get the gradients from a UDM automatically. I wasn't sure how I would be getting the gradients from a UDM.n
    • YasserSelima
      Subscriber
      I am not sure it exist but I assume ...n
    • Venky_94
      Subscriber

      Just a hint ... the gradients you get will be a mix of the new values at the current iteration and the previous values, depending if the adjacent cells are updated or nothttps://forum.ansys.com/discussion/comment/112615#Comment_112615

      Can I avoid this if I do the entire calculation within a ADJUST udf and store the terms in UDMs, that I can call upon in my SOURCE udf?nSince ADJUST udfs are called before every iteration, this should ensure that the gradients are proper right?n
    • YasserSelima
      Subscriber
      yes, definitely ... Also if you want to have a gradient of a gradient inside Define adjust, you can use two separate loops and in between use PRF_GSYNC() to make sure no Node start the second loop until all finish the first. n
    • YasserSelima
      Subscriber
      Don't forget to disable solving the UDS equations where you store the valuesn
    • Venky_94
      Subscriber
      Thanks a lot. I'll try it out today. n
    • YasserSelima
      Subscriber
      You are welcome!n
Viewing 26 reply threads
  • You must be logged in to reply to this topic.