def UpdateFluid(self,
                    f,
                    Update_du=True,
                    CalcPressure=False,
                    UpdateStress=True,
                    KeepUpdate=True):
        """Advance the fluid one timestep via a semi-implicit scheme.
		
		f is a force field applied to the fluid at the current time and must be a vector field."""

        # Calculate polymeric stress contribution
        self.CurrentStress = self.PolymericStress()
        f += self.CurrentStress

        # Update the fluid
        Fluid.UpdateFluid(self, f, Update_du, CalcPressure, KeepUpdate)

        # Update the fluid stress
        if UpdateStress and KeepUpdate:
            self.UpdateS()
예제 #2
0
# The simulation loop        
Time.StartTimer()
while Time.t < Time.T:
    Time.PrintStepInfo()

    X.CheckForExplosion()

    # The FE/BE method
    # First calculate the fiber force F (stored in X.F)
    X.CalcForceDistribution()

    # Spread F to the Eulerian grid, storing the result in the force field u.f
    X.ToGrid(u)

    # Evolve the fluid forward one time step
    u.UpdateFluid(u.f, CalcPressure = True)

    # Interpolate the fluid velocity to the fiber (stored in X.U)
    X.FromGrid(u)

    # Update the fiber position
    X.X += dt * X.U

    # Update the time
    Time.Incr()
    Time.PrintTimeInfo()

    # Plot the fluid/fiber and save to file
    if Time.CurStep % SavePeriod == 0:
        m.clf() # Clear the plotter
        u.Plot2D(PlotStyle.pressure) # Plot the fluid pressure
예제 #3
0
from Ellipse import Ellipse
from MatrixUtility import Stack, Unstack

# Simulation parameters
N = 128
RestrictToEulerian = False  # If True we restrict the fiber points to Eulerian intersections. When done the matrix should give EXACT results.

# Create the fiber in the shape of an ellipse
X = Ellipse(2 * N, s=10e6, c=[.5, .5], p1=[.8, .5], p2=[.5, .6])
if RestrictToEulerian:
    X.X = floor(X.X * N) / N

# Initialize the fluid solver
u = Fluid(dt=1. / N, N=[N, N], dims=[1., 1.])

# Calculate dX/dt (stored in X.U) using a fluid solve
X.CalcForceDistribution()
X.ToGrid(u)
u.UpdateFluid(u.f)
X.FromGrid(u)

# Calculate dX/dt (stored in U) using the fluid matrix
# First construt the fluid matrix
M = X.ConstructFluidMatrix(u)

# Then calculate U = M * F, where F is the fiber force
U = Unstack(dot(M, Stack(X.F)), 2)

# Calculate difference between X.U and U (the induced flow calculated via a fluid solve and via the matrix)
print abs(X.U - U).max() / abs(X.U).max()