top of page

Forum Comments

About wind vector field simulation
In Questions & Answers
Conor
Jul 22, 2024
Hi Wei, Sorry, I understand what you're asking now - thanks for bearing with me! Our demo for flow around a cylinder uses a custom FluidZone, not the default one. We wrote a velocity function specifically for that demo which looked at the cylinder object and created a flow field based on the free stream velocity and the rotation of the cylinder. That particular code wasn't released with the AO package and my colleague is on leave at the moment so I don't have access to the code he wrote. We are working on releasing more features and tools for flow simulation in the next update to AO. I have thrown together a quick example of how you can go about this. Please only consider this as an example, I can't guarantee that it's accurate and working for all cases but it does give something that looks appropriate. The example code: using AerodynamicObjects; using UnityEngine; public class RotatingCylinderFluidZone : FluidZone { public AeroObject cylinder; public float freeStreamVelocity = 1; public override Vector3 VelocityFunction(Vector3 position) { // Get the position relative to the cylinder's position position -= cylinder.transform.position; // Assuming the cylinder is extruded along the z axis for simplicity float radialDistanceSquared = (position.x * position.x) + (position.y * position.y); float radialDistance = Mathf.Sqrt(radialDistanceSquared); float cylinderRadius = 0.5f * cylinder.dimensions.x; // Non-physical, we're inside the cylinder if (radialDistance <= cylinderRadius) { return Vector3.zero; } float cosTheta = position.x / radialDistance; float sinTheta = position.y / radialDistance; float omega = cylinder.rb.angularVelocity.z; float circulation = -omega * cylinderRadius * 2f * Mathf.PI * cylinderRadius; float rr = cylinderRadius * cylinderRadius / (radialDistance * radialDistance); float vr = (freeStreamVelocity - rr) * cosTheta; float vtheta = (-(freeStreamVelocity + rr) * sinTheta) - (circulation / (2f * Mathf.PI * radialDistance)); return new Vector3((vr * cosTheta) - (vtheta * sinTheta), (vr * sinTheta) + (vtheta * cosTheta)); } } I hope that's helpful! A side note, the communication between AeroObjects and FluidZones is one way, i.e. an AeroObject gets flow information from a FluidZone but a FluidZone does not get information about AeroObjects. Best, Conor
Content media
Birds possible?
In Questions & Answers
Conor
Nov 01, 2023
Hi Zalz, Your fluid properties look fine! If you're using the latest verison of Unity you can look at https://docs.unity3d.com/ScriptReference/Rigidbody.GetAccumulatedForce.html to find the total force acting on a body - you can then compensate for large forces by adding forces in the opposite direction of the accumulated force. Note you would need a script running in a larger execution order to ensure all the forces have been added to the rigid body before saturating them. Check out this for more on execution orders: https://docs.unity3d.com/Manual/class-MonoManager.html For your test, you can check the expected terminal velocity of an object using the following equation: v = sqrt( 2mg / pACd ) Where v is the terminal velocity, m is mass, g is acceleration due to gravity, rho (p) is the density of the fluid (1.23 by default), A is the area (0.785 m^2 for your cube - note we use ellipsoids to approximate bodies) and Cd is the drag coefficient (0.5 is a good approximation for a cube). I get 6.37 m/s for a 1x1x1 m cube at 1 kg. Our drag model is a bit more involved than that equation which will explain the discrepancy, the cube actually reaches 6.33 m/s in my tests. During development we decided it was best to use Unity's physics solver so that our tools are fully compatible with Rigidbodies. Unfortunately, this means that drag can become unstable when the drag force and the weight of an object are close in magnitude. A rough estimate for instability is to compute the value of: 4m / (p S Cd v) (m is mass of an object, rho (p) is the density of the fluid (1.23), S is the largest area on the object, Cd is drag coefficient (in this case use the max of 1.2), v is an expected velocity for the object). If that value is less than the fixed delta time in your simulation, then you will likely have instability and objects will shoot off. The cube experiment for example gives a value of 0.545 so a simulation of that cube falling at 6.33 m/s should be stable with a time step of around 0.5 seconds - though I would advise using a much smaller one! You can ensure stability by either: reducing the fixed delta time, increasing the mass of your objects, or reducing their areas. We have found a good value for fixed delta time to be 0.002 seconds. Hope that helps!
Content media

Conor

Admin
More actions
bottom of page