Define FEniCS function from data (time-dependent)


58
views
0
5 weeks ago by
Tecs  
I have irregular density data (data) for several time-steps that I want to use to solve the equations for gravity driven Stokes flow. I have made the density as an expression like shown below. The class has a define_data function that I use to pass it the data. It has interpl_from_data function that for every point on the FEM mesh it finds the Nm number of closest data points and gives it a value based on a weighted average.

This work fine for the first time-step, but it seems like I’m unable to update the data since the solution remains the same.

Is there a better way to do this? Or just a way to fix what I’m already doing?


class density(Expression):

    def define_data(self,X,Y,data):
        self.X = X
        self.Y = Y
        self.data = data

    def interpl_from_data(self,x_node,y_node,data):

        Nm = 5 # Number of data points used for interpolation

        x_dist = abs(x_node-self.X)
        y_dist = abs(y_node-self.Y)

        # find n closest data points
        dist = np.sqrt(x_dist**2 + y_dist**2)
        closest_data_points = np.argsort(dist)
        closest_data_points = closest_data_points[:Nm] 	# indicies
        data_values = np.take(prop_m,closest_data_points)
        weights = np.take(dist,closest_data_points)
        weights = weights**(-1)

        avg = np.average(data_values, weights=weights)

        return avg

    def eval(self, value, x):
        value[0] = self.interpl_from_data(x[0],x[1],self.data)
.
.
.

# Time-loop
for i in range(0,N):

    data = np.loadtxt(“data”+str(i)+”.txt”)
    X = data[:,0]
    Y = data[:,1]
    density_data = data[:,2]

    # Update density field
    rho.define_data(X,Y,density_data)

    # Solve for flow (Stokes equations)
    solver.solve(w.vector(),b)
    u,p = w.split(deepcopy=True)
​
Community: FEniCS Project
Please login to add an answer/comment or follow this question.

Similar posts:
Search »