CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   How to set bounds for additional variables (https://www.cfd-online.com/Forums/cfx/251343-how-set-bounds-additional-variables.html)

NatpJ August 10, 2023 10:30

How to set bounds for additional variables
 
Hi everyone,

I created an additional variable as a scalar value in CFX which represent a concentration running from 0-1, but after the run and I opened in CFX-post, the values were out of bound (it went down to -0.33 and up to 1.34 for instance). This will greatly affect the results because the expressions that use this additional variable run with the bound. Is there a way to set the additional variable to be within the bound [0,1]? Or are there any chapters in the theory/modeling guide that I can read and follow? Thanks.

Opaque August 10, 2023 16:17

It all depends on what equation you are solving for the additional variable.

Advice: do not bound/clip a solved variable ever. If you do, the non-linear equations can never be solved as stated; therefore, you are not solving the mathematical problem you formulated.

If you bound/clip them, you must be 1000% sure that step goes away as the residual reaches convergence, i.e. 0.

If you read the documentation theory for the transport of the species, you may find what you are looking for.

NatpJ August 17, 2023 10:02

Quote:

Originally Posted by Opaque (Post 855057)
It all depends on what equation you are solving for the additional variable.

Advice: do not bound/clip a solved variable ever. If you do, the non-linear equations can never be solved as stated; therefore, you are not solving the mathematical problem you formulated.

If you bound/clip them, you must be 1000% sure that step goes away as the residual reaches convergence, i.e. 0.

If you read the documentation theory for the transport of the species, you may find what you are looking for.

Thank you so much for your reply.

In my case, I’m using the additional variable as a scalar quantity to solve the equation for viscosity. And this viscosity will be use to solve the transport equation. So I don’t think there’s a problem with setting the bounds in this case.

I tried to read through the documents, but I still don’t find where it mentioned ways on how to bound additional variable. So, can you please give me an insight on how to do that or where exactly they mention it? That would be very helpful. Thank you.

Opaque August 17, 2023 11:13

Would you mind posting the transport equation you are trying to solve?

If your transport equation has sources and sinks, you need to improve the setup of the sources and sinks; otherwise, you will have convergence difficulties. Bounding will NOT help you but postpone the issue as I mentioned earlier.

Even if you do not have sources and sink, but your mesh aspect ratio or skewness is on edge, you will get unexpected "out of bounds" values that ARE correct. Clipping is not the solution here either. In this situation, you have a mesh problem and need to fix your mesh.

Summary: clipping is an overused approach, and needs to be understood deeply before is used; otherwise, you are hiding a problem

NatpJ August 17, 2023 12:06

Quote:

Originally Posted by Opaque (Post 855435)
Would you mind posting the transport equation you are trying to solve?

If your transport equation has sources and sinks, you need to improve the setup of the sources and sinks; otherwise, you will have convergence difficulties. Bounding will NOT help you but postpone the issue as I mentioned earlier.

Even if you do not have sources and sink, but your mesh aspect ratio or skewness is on edge, you will get unexpected "out of bounds" values that ARE correct. Clipping is not the solution here either. In this situation, you have a mesh problem and need to fix your mesh.

Summary: clipping is an overused approach, and needs to be understood deeply before is used; otherwise, you are hiding a problem

I see your point. Thanks for the clarification.
So this is some of the code that I'm using to solve for dynamic viscosity of a material called Onyx. This is a multiphase of continuous liquid btw. I don't know if this is enough or what your asking for, but hopefully it is.

LIBRARY:
CEL:
EXPRESSIONS:
On = 0.018[kg/m/s]* (1+ 500 * (1 - min(DMSO,1))) *** cannot go below 0.018 kg/m/s when DMSO is greater than 1 ***
VisOnyx = (Blood.Mass Fraction*0.004[kg/m/s])+(Onyx.Mass Fraction*On)
Visblood = (Blood.Volume Fraction* 0.004[kg/m/s])+((1-Blood.Volume \
Fraction)*On)
END
END
ADDITIONAL VARIABLE: DMSO
Option = Definition
Tensor Type = SCALAR
Units = []
Variable Type = Specific
END
.....

MATERIAL: Onyx
Material Group = User
Option = Pure Substance
PROPERTIES:
Option = General Material
EQUATION OF STATE:
Density = 1063 [kg m^-3]
Molar Mass = 1.0 [kg kmol^-1]
Option = Value
END
DYNAMIC VISCOSITY:
Dynamic Viscosity = VisOnyx
Option = Value
END
END
END
....

ANALYSIS TYPE:
Option = Transient
EXTERNAL SOLVER COUPLING:
Option = None
END
INITIAL TIME:
Option = Automatic with Value
Time = 0 [s]
END
TIME DURATION:
Option = Total Time
Total Time = 2.5 [s]
END
TIME STEPS:
Option = Timesteps
Timesteps = 0.01 [s]
END
END
DOMAIN: Default Domain
Coord Frame = Coord 0
Domain Type = Fluid
Location = B24
BOUNDARY: Default Domain Default
Boundary Type = WALL
Location = F73.24,F75.24
BOUNDARY CONDITIONS:
ADDITIONAL VARIABLE: DMSO
Option = Fluid Dependent
END
MASS AND MOMENTUM:
Option = No Slip Wall
END
WALL CONTACT MODEL:
Option = Use Volume Fraction
END
END
FLUID: Blood
BOUNDARY CONDITIONS:
ADDITIONAL VARIABLE: DMSO
Option = Zero Flux
END
END
END
FLUID: Onyx
BOUNDARY CONDITIONS:
ADDITIONAL VARIABLE: DMSO
Option = Zero Flux
END
END
END
END
BOUNDARY: Inlet
Boundary Type = INLET
Location = F72.24
BOUNDARY CONDITIONS:
ADDITIONAL VARIABLE: DMSO
Additional Variable Value = 1 []
Option = Value
END
FLOW REGIME:
Option = Subsonic
END
MASS AND MOMENTUM:
Normal Speed = 0.2 [m s^-1]
Option = Normal Speed
END
END
FLUID: Blood
BOUNDARY CONDITIONS:
VOLUME FRACTION:
Option = Value
Volume Fraction = 0
END
END
END
FLUID: Onyx
BOUNDARY CONDITIONS:
VOLUME FRACTION:
Option = Value
Volume Fraction = 1
END
END
END
END
BOUNDARY: Outlet
Boundary Type = OUTLET
Location = F74.24
BOUNDARY CONDITIONS:
FLOW REGIME:
Option = Subsonic
END
MASS AND MOMENTUM:
Option = Static Pressure
Relative Pressure = 0 [Pa]
END
END
END
BOUNDARY: Wall
Boundary Type = WALL
Location = F25.24,F26.24,F27.24,F28.24,F29.24,F30.24,F54.24,F 82.24
BOUNDARY CONDITIONS:
ADDITIONAL VARIABLE: DMSO
Option = Fluid Dependent
END
MASS AND MOMENTUM:
Option = No Slip Wall
END
WALL CONTACT MODEL:
Option = Use Volume Fraction
END
END
FLUID: Blood
BOUNDARY CONDITIONS:
ADDITIONAL VARIABLE: DMSO
Option = Zero Flux
END
END
END
FLUID: Onyx
BOUNDARY CONDITIONS:
ADDITIONAL VARIABLE: DMSO
Option = Zero Flux
END
END
END
END
DOMAIN MODELS:
BUOYANCY MODEL:
Option = Non Buoyant
END
DOMAIN MOTION:
Option = Stationary
END
MESH DEFORMATION:
Option = None
END
REFERENCE PRESSURE:
Reference Pressure = 0 [atm]
END
END
FLUID DEFINITION: Blood
Material = Blood
Option = Material Library
MORPHOLOGY:
Option = Continuous Fluid
END
END
FLUID DEFINITION: Onyx
Material = Onyx
Option = Material Library
MORPHOLOGY:
Option = Continuous Fluid
END
END
FLUID MODELS:
ADDITIONAL VARIABLE: DMSO
Option = Fluid Dependent
END
FLUID: Blood
ADDITIONAL VARIABLE: DMSO
Kinematic Diffusivity = 10e-5 [m^2 s^-1]
Option = Transport Equation
END
END
FLUID: Onyx
ADDITIONAL VARIABLE: DMSO
Kinematic Diffusivity = 10e-5 [m^2 s^-1]
Option = Transport Equation
END
END
HEAT TRANSFER MODEL:
Homogeneous Model = False
Option = None
END
THERMAL RADIATION MODEL:
Option = None
END
TURBULENCE MODEL:
Homogeneous Model = False
Option = Laminar
END
END
FLUID PAIR: Blood | Onyx
INTERPHASE TRANSFER MODEL:
Interface Length Scale = 0.1 [mm]
Option = Mixture Model
END
MASS TRANSFER:
Option = Specified Mass Transfer
SPECIFIED MASS TRANSFER:
Fluid1to2 Mass Flow = 0.1 [kg s^-1 m^-3]
Option = Interfacial Mass Flow
END
END
MOMENTUM TRANSFER:
DRAG FORCE:
Drag Coefficient = 0.44
Option = Drag Coefficient
END
END
END
INITIALISATION:
Coord Frame = Coord 0
Option = Automatic
FLUID: Blood
INITIAL CONDITIONS:
Velocity Type = Cartesian
ADDITIONAL VARIABLE: DMSO
Additional Variable Value = 0 []
Option = Automatic with Value
END
CARTESIAN VELOCITY COMPONENTS:
Option = Automatic with Value
U = 0 [m s^-1]
V = 0 [m s^-1]
W = 0 [m s^-1]
END
VOLUME FRACTION:
Option = Automatic with Value
Volume Fraction = 1
END
END
END
FLUID: Onyx
INITIAL CONDITIONS:
Velocity Type = Cartesian
ADDITIONAL VARIABLE: DMSO
Additional Variable Value = 0 []
Option = Automatic with Value
END
CARTESIAN VELOCITY COMPONENTS:
Option = Automatic with Value
U = 0 [m s^-1]
V = 0 [m s^-1]
W = 0 [m s^-1]
END
VOLUME FRACTION:
Option = Automatic with Value
Volume Fraction = 0
END
END
END
INITIAL CONDITIONS:
STATIC PRESSURE:
Option = Automatic with Value
Relative Pressure = 0 [Pa]
END
END
END
MULTIPHASE MODELS:
Homogeneous Model = Off
FREE SURFACE MODEL:
Option = None
END
END
END
SOLVER CONTROL:
ADVECTION SCHEME:
Option = High Resolution
END
CONVERGENCE CONTROL:
Maximum Number of Coefficient Loops = 10
Minimum Number of Coefficient Loops = 1
Timescale Control = Coefficient Loops
END
CONVERGENCE CRITERIA:
Residual Target = 1.E-4
Residual Type = RMS
END
EQUATION CLASS: continuity
ADVECTION SCHEME:
Option = High Resolution
END
END
EQUATION CLASS: momentum
ADVECTION SCHEME:
Option = High Resolution
END
END
INTERRUPT CONTROL:
Option = Any Interrupt
CONVERGENCE CONDITIONS:
Option = Default Conditions
END
END
MULTIPHASE CONTROL:
Initial Volume Fraction Smoothing = Volume-Weighted
Volume Fraction Coupling = Segregated
END
TRANSIENT SCHEME:
Option = Second Order Backward Euler
TIMESTEP INITIALISATION:
Option = Automatic
END
END
VELOCITY PRESSURE COUPLING:
Rhie Chow Option = High Resolution
END
END
END

Opaque August 17, 2023 14:10

You are solving an additional variable for each fluid: Onyx and Blood.

The transport equation is extremely simple: transient + advection + diffusion

The diffusion coefficient is set to 1.E-4

The inlet condition is simple. I see no reason why your AV can be anything but 1 wherever is advected to, and because your initial value inside the domain is 0, there would be some diffusion until it is advected out.

Advice:
1 - disconnect the additional variable from the viscosities of Onyx and Blood.
2 - post-process the results to see if the solution makes any sense for the two phases, and if the additional variable is sensible (it has to be)
3 - Noticed you used .Mass Fraction for a simple material fluid. Check in CFD-Post that variable makes any sense.
4 - Once your vanilla setup makes sense, you can activate only 1 of your viscosities.
5 - Check and balances
6 - Activate next, check and balances.

Summary: reduce your problem to simple verifiable steps before committing to complex problems where it is not clear what the interactions are.

ghorrocks August 17, 2023 21:14

Also: You are modelling this as a multiphase model. Are you sure this is a multiphase model? If the fluid is better modelled as a single phase fluid with a variable concentration of components then a multicomponent model is model appropriate. You should only use a multiphase model when the two fluids are separable into different phases.

As this appears to be a model of blood it makes sense to model the platelets as multiphase particles (if that is relevant to what you want to do). But you appear to be modelling blood as a fluid and then a multicomponent mixture might be more appropriate.

NatpJ August 18, 2023 04:25

Quote:

Originally Posted by ghorrocks (Post 855457)
Also: You are modelling this as a multiphase model. Are you sure this is a multiphase model? If the fluid is better modelled as a single phase fluid with a variable concentration of components then a multicomponent model is model appropriate. You should only use a multiphase model when the two fluids are separable into different phases.

As this appears to be a model of blood it makes sense to model the platelets as multiphase particles (if that is relevant to what you want to do). But you appear to be modelling blood as a fluid and then a multicomponent mixture might be more appropriate.

That makes a lot of sense, but I’m pretty sure that it’s multiphase model because the referenced paper mentioned a two-fluid model where the blood and the onyx (more or less a polymer) have different material properties. In my case, I’m trying to see how this material’s viscosity behaves in blood. And I’m trying to replicate the case in the paper where it is trying to constructed a simple domain filled with blood while the inlet is injecting this material at constant speed. What’s your input on this as I could be wrong. Thanks.

NatpJ August 18, 2023 04:29

Quote:

Originally Posted by Opaque (Post 855445)
You are solving an additional variable for each fluid: Onyx and Blood.

The transport equation is extremely simple: transient + advection + diffusion

The diffusion coefficient is set to 1.E-4

The inlet condition is simple. I see no reason why your AV can be anything but 1 wherever is advected to, and because your initial value inside the domain is 0, there would be some diffusion until it is advected out.

Advice:
1 - disconnect the additional variable from the viscosities of Onyx and Blood.
2 - post-process the results to see if the solution makes any sense for the two phases, and if the additional variable is sensible (it has to be)
3 - Noticed you used .Mass Fraction for a simple material fluid. Check in CFD-Post that variable makes any sense.
4 - Once your vanilla setup makes sense, you can activate only 1 of your viscosities.
5 - Check and balances
6 - Activate next, check and balances.

Summary: reduce your problem to simple verifiable steps before committing to complex problems where it is not clear what the interactions are.

Thank you so much for taking your time to analyze the codes. I will try to follow the steps and see if my results make any sense.

ghorrocks August 18, 2023 05:10

Quote:

That makes a lot of sense, but I’m pretty sure that it’s multiphase model because the referenced paper mentioned a two-fluid model where the blood and the onyx (more or less a polymer) have different material properties.
Wrong answer :). A multicomponent fluid can model material property change through concentration changes, a multiphase model cannot. This suggests you are using a fundamentally incorrect physical approach.

Note that if you model this using mass fractions as you would in a multicomponent model I bet you will not have boundedness problems and require horrible fudges like clipping variables.

Quoting the first line of the CFX Solver Modelling Guide, Ch 7: "Multiphase flow refers to the situation where more than one fluid is present. Each fluid may possess its own flow field, or all fluids may share a common flow field. Unlike multicomponent flow, the fluids are not mixed on a microscopic scale in multiphase flow. Rather, they are mixed on a macroscopic scale, with a discernible interface between the fluids."

Aren't your materials mixed on a microscopic scale, and therefore you have a multicomponent fluid, not a multiphase one?

Opaque August 18, 2023 08:17

Quote:

Originally Posted by NatpJ (Post 855477)
That makes a lot of sense, but I’m pretty sure that it’s multiphase model because the referenced paper mentioned a two-fluid model where the blood and the onyx (more or less a polymer) have different material properties. In my case, I’m trying to see how this material’s viscosity behaves in blood. And I’m trying to replicate the case in the paper where it is trying to constructed a simple domain filled with blood while the inlet is injecting this material at constant speed. What’s your input on this as I could be wrong. Thanks.

Be careful when reading papers with reference to multi-XXX. Sometimes authors mix, using Ansys CFX speak/vocabulary, multicomponent material fluid as multiphase. Also, mix thermodynamic phases with CFD modeling phases.

You need to differentiate the vocabulary in the papers from yours and use a "context-based translator". To know the exact differences, in my opinion, the mathematical equations MUST be written explicitly, not described in words.

NatpJ August 20, 2023 10:13

1 Attachment(s)
Quote:

Originally Posted by ghorrocks (Post 855485)
Wrong answer :). A multicomponent fluid can model material property change through concentration changes, a multiphase model cannot. This suggests you are using a fundamentally incorrect physical approach.

Note that if you model this using mass fractions as you would in a multicomponent model I bet you will not have boundedness problems and require horrible fudges like clipping variables.

Quoting the first line of the CFX Solver Modelling Guide, Ch 7: "Multiphase flow refers to the situation where more than one fluid is present. Each fluid may possess its own flow field, or all fluids may share a common flow field. Unlike multicomponent flow, the fluids are not mixed on a microscopic scale in multiphase flow. Rather, they are mixed on a macroscopic scale, with a discernible interface between the fluids."

Aren't your materials mixed on a microscopic scale, and therefore you have a multicomponent fluid, not a multiphase one?

Thank you for taking your time to answer my questions. It was super insightful. I believe that they mix on microscopic scale as what you've said. But for some reason, when I tried with multicomponent, the results looks completely different from the paper while the multiphase is very similar except for viscosity patterns which I think could be due to my expression for ideal viscosity mixture:

On = 0.018[kg/m/s]* (1+ 500 * (1 - min(DMSO,1))) *** equation from paper and cannot go below 0.018 kg/m/s when DMSO is greater than 1 ***
VisOnyx = (Blood.Mass Fraction*0.004[kg/m/s])+(Onyx.Mass Fraction*On) ***I formulated it to put in dynamic viscosity for the Onyx (the other material not the blood while the blood have constant viscosity)***

And I'm just solely analyzing the qualitative aspects like the flow patterns.

I looked into the governing equations as suggested by Opaque and I captured the equation from the paper. The description also said that they are solving for "six momentum equation, together with mass conservation and an equation for the phrase fraction." I still believe that it's multiphase flow based on the reasons above. Is it possible that they are mixing on macroscopic instead of microscopic? Or do you suggest otherwise?

ghorrocks August 20, 2023 19:39

If the paper you are comparing against used 6 momentum equations (which is presumably XYZ momentum for two phases) that suggests they used a multiphase approach. But just because that is what they did does not mean it is correct. If the fluid is mixed at the microscopic level then there will be no interphase slip, and then the 6 momentum equations are redundant - the velocity field for both "phases" will be the same. So lots of wasted computing there. But more fundamentally, multiphase models do not combine the phases together to give an overall viscosity. You need a multicomponent model for that.

When you ran your model as multicomponent mixture, did you use your viscosity equation? The default viscosity calculation is ideal fluids which I recall is just mass fraction weighted.

How confident are you that the flow predicted by the paper you are comparing to is correct?

NatpJ August 23, 2023 08:17

Quote:

Originally Posted by ghorrocks (Post 855569)
If the paper you are comparing against used 6 momentum equations (which is presumably XYZ momentum for two phases) that suggests they used a multiphase approach. But just because that is what they did does not mean it is correct. If the fluid is mixed at the microscopic level then there will be no interphase slip, and then the 6 momentum equations are redundant - the velocity field for both "phases" will be the same. So lots of wasted computing there. But more fundamentally, multiphase models do not combine the phases together to give an overall viscosity. You need a multicomponent model for that.

When you ran your model as multicomponent mixture, did you use your viscosity equation? The default viscosity calculation is ideal fluids which I recall is just mass fraction weighted.

How confident are you that the flow predicted by the paper you are comparing to is correct?

Sorry for the late reply. I was reading through the papers again and they were using a different solver called CFD-ACE+, where the two fluid model of them “obtain macroscopic forms of the equations for which solutions are sought.” So I think that I have to use multiphase, then. But maybe I could select homogenous model to have the same velocity field and select interphase transfer as non to satisfy the equation.
As for the confidentiality of the paper, I would say it’s a well established one, and their results makes sense. “When the onyx penetrates the meshed volume its viscosity changed first at the onyx-blood interphase and subsequently throughout the onyx volume as solvent(additional variable) diffuses further.” This quote reflects the property of the material really well. But the problem is the viscosity pattern, so I thought that maybe it’s my expression of ideal mixture to be put as the viscosity of onyx. Do you think this could be the case? The paper didn’t give any correlation between the two viscosity at all (I assumed that maybe the CFD-ACE+could solve for the dynamic viscosity of the two using ideal mixture), so I assumed ideal mixture for onyx.

I also checked my mesh quality and it has no effect to the results or the convergence of the additional variable. As Opaque said that my code is very simple and shouldn’t have difficulty converging, but that’s not the case. What do you think could be the problem?

ghorrocks August 23, 2023 18:34

Quote:

I was reading through the papers again and they were using a different solver called CFD-ACE+, where the two fluid model of them “obtain macroscopic forms of the equations for which solutions are sought.”
Yes, that sounds like the equivalent of CFX's multiphase model.

Quote:

But maybe I could select homogenous model to have the same velocity field and select interphase transfer as non to satisfy the equation.
No! Don't try to fit a square peg in a round hole. If it is a multicomponent mixture model then no amount of trying to contort a multiphase model will work.

Quote:

When the onyx penetrates the meshed volume its viscosity changed first at the onyx-blood interphase and subsequently throughout the onyx volume as solvent(additional variable) diffuses further.
This says the important physics is convection, diffusion and viscosity as a function of concentration. The model for this is a multicomponent mixture as it models all these things. Multiphase models model convection and interphase slip - it cannot model diffusion and it cannot model viscosity as a function of concentration.

Quote:

my code is very simple and shouldn’t have difficulty converging, but that’s not the case. What do you think could be the problem?
I really cannot say this any clearer. All your problems are because you are trying to use a multiphase model to simulate something which is a multicomponent mixture. Multiphase models do not have the physics for what you are trying to do and the multicomponent mixture model does.

You have found that the paper you are referring to has made a fundamental mistake in how to model this. Do not copy their mistake.


All times are GMT -4. The time now is 14:00.