Commit 4a038a83 by Jigyasa Watwani

passive stress field instead of total stress field, and d-dim derivatives

parent 920268c0
......@@ -24,106 +24,141 @@ class Tissue(object):
self.system_size/2)
scalar_element = df.FiniteElement('P', self.mesh.ufl_cell(), 1)
vector_element = df.VectorElement('P', self.mesh.ufl_cell(), 1)
tensor_element = df.TensorElement('P', self.mesh.ufl_cell(), 1)
# stress, v, rho
mixed_element = df.MixedElement([scalar_element, scalar_element, scalar_element])
# v, p_stress, rho
mixed_element = df.MixedElement([vector_element,
tensor_element,
scalar_element])
# define function space with this mixed element
self.function_space = df.FunctionSpace(self.mesh, mixed_element)
self.bc = df.DirichletBC(self.function_space.sub(2), df.Constant(0.0), 'on_boundary')
self.bc = df.DirichletBC(self.function_space.sub(2),
df.Constant(0.0),
'on_boundary'),
self.function0 = df.Function(self.function_space)
self.function = df.Function(self.function_space)
self.relaxation_time = self.viscosity/self.elasticity
self.tau = self.viscosity/self.elasticity
def advection(self, conc, vel, tconc):
return df.inner(df.div(vel * conc), tconc)
def active_stress(self, rho):
if self.active_death:
return (-self.lamda * rho * (rho - self.active_stress_setpoint)/(rho**2 + self.saturation_rho**2)
* df.Identity(1))
else:
return (-self.lamda * rho /(rho + self.saturation_rho)
* df.Identity(1))
def epsilon(self, v):
return df.sym(df.nabla_grad(v))
def stress(self, pstress, rho):
return (pstress + self.active_stress(rho))
def diffusion_reaction_rho(self, rho, trho):
return (self.diffusion_rho * df.inner(df.nabla_grad(rho),
df.nabla_grad(trho))
- self.turnover_rho * df.inner(rho*(1 - rho/self.average_rho), trho)
)
def setup_initial_conditions(self):
# ic for stress
rho0 = df.interpolate(df.Expression('cos(pi * x[0]/L) * cos(pi * x[0]/L)', pi = np.pi, L = self.system_size, degree=1), self.function_space.sub(2).collapse())
stress0 = df.interpolate(df.Constant(0.0), self.function_space.sub(0).collapse())
SFS = self.function_space.sub(1).collapse()
v0 = df.Function(SFS)
tv0 = df.TestFunction(SFS)
zero_tensor = df.Constant(((0.0,),))
pstress0 = df.interpolate(zero_tensor,
self.function_space.sub(1).collapse())
rho0 = df.interpolate(df.Expression(
'0.1 * cos(PI*x[0]/L)*cos(PI*x[0]/L)',
L=self.system_size,
degree=1, PI=np.pi),
self.function_space.sub(2).collapse())
# add noise
noise_rho = (self.noise_level
* (2 * np.random.random(rho0.vector().size()) - 1))
rho0.vector()[:] = rho0.vector()[:] + noise_rho
VFS = self.function_space.sub(0).collapse()
v0 = df.Function(VFS)
tv0 = df.TestFunction(VFS)
v0form = (self.friction * df.inner(v0, tv0)
+ df.inner(stress0, tv0.dx(0))
) * df.dx
+ df.inner(self.stress(pstress0, rho0),
self.epsilon(tv0))
) * df.dx
df.solve(v0form == 0, v0)
df.assign(self.function0, [stress0, v0, rho0])
def active_stress(self, rho):
return -self.lamda * rho/(rho + self.saturation_rho)
df.assign(self.function0, [v0, pstress0, rho0])
def setup_weak_forms(self):
stress0, v0, rho0 = df.split(self.function0)
stress, v, rho = df.split(self.function)
tstress, tv, trho = df.TestFunctions(self.function_space)
vform = self.friction * df.inner(v, tv) + df.inner(stress, tv.dx(0))
stressform = ( df.inner(stress - self.active_stress(rho), tstress)
+ self.relaxation_time *
df.inner((1/self.timestep) * (stress - stress0 - self.active_stress(rho) + self.active_stress(rho0)), tstress)
+ self.relaxation_time *
df.inner(v0 * (stress0 - self.active_stress(rho0)).dx(0), tstress)
- (self.viscosity) *
df.inner(v.dx(0), tstress)
)
v0, pstress0, rho0 = df.split(self.function0)
v, pstress, rho = df.split(self.function)
tv, tpstress, trho = df.TestFunctions(self.function_space)
vform = (self.friction * df.inner(v, tv)
+ df.inner(self.stress(pstress, rho),
self.epsilon(tv)))
rhoform = (df.inner((rho - rho0)/self.timestep, trho)
+ df.inner((rho0 * v0).dx(0), trho)
+ self.diffusion_rho * df.inner(rho.dx(0), trho.dx(0))
- self.turnover_rho * df.inner(rho * (1 - rho/self.average_rho), trho)
)
+ self.advection(rho0, v0, trho)
+ self.diffusion_reaction_rho(rho, trho))
pstressform = ( self.tau * df.inner((pstress - pstress0)/self.timestep, tpstress)
+ self.tau * df.inner(df.dot(v, df.nabla_grad(pstress)), tpstress)
+ df.inner(pstress, tpstress)
- self.viscosity * df.inner(self.epsilon(v), tpstress)
)
self.form = (vform + stressform + rhoform)*df.dx
self.form = (pstressform + vform + rhoform) * df.dx
def solve(self, DIR=''):
self.stressFile = df.XDMFFile(os.path.join(DIR,
'%s_stress.xdmf' % self.timestamp))
self.vFile = df.XDMFFile(os.path.join(DIR,
self.pstressFile = df.XDMFFile(os.path.join(DIR,
'%s_pstress.xdmf' % self.timestamp))
self.vFile = df.XDMFFile(os.path.join(DIR,
'%s_velocity.xdmf' % self.timestamp))
self.rhoFile = df.XDMFFile(os.path.join(DIR,
'%s_density.xdmf' % self.timestamp))
self.setup_initial_conditions()
self.setup_weak_forms()
# time-variables
self.time = 0.0
savesteps = int(self.savetime/self.timestep)
maxsteps = int(self.maxtime/self.timestep)
stress, v, rho = self.function0.split(deepcopy=True)
self.stressFile.write_checkpoint(stress, 'stress', self.time)
self.rhoFile.write_checkpoint(rho, 'density', self.time)
v, pstress, rho = self.function0.split(deepcopy=True)
self.pstressFile.write_checkpoint(pstress, 'pstress', self.time)
self.vFile.write_checkpoint(v, 'velocity', self.time)
self.rhoFile.write_checkpoint(rho, 'density', self.time)
for steps in progressbar.progressbar(range(1, maxsteps + 1)):
df.solve(self.form == 0, self.function, self.bc)
self.function0.assign(self.function)
self.time += self.timestep
stress, v, rho = self.function0.split(deepcopy=True)
v, pstress, rho = self.function0.split(deepcopy=True)
if steps % savesteps == 0:
self.stressFile.write_checkpoint(stress, 'stress',
self.pstressFile.write_checkpoint(pstress, 'pstress',
self.time, append=True)
self.rhoFile.write_checkpoint(rho, 'density',
self.time, append=True)
self.vFile.write_checkpoint(v, 'velocity',
self.time, append=True)
self.rhoFile.write_checkpoint(rho, 'density',
self.time, append=True)
# move mesh
dr = df.project(v * self.timestep, self.function_space.sub(1).collapse())
dr = df.project(v*self.timestep, self.function_space.sub(0).collapse())
df.ALE.move(self.mesh, dr)
self.stressFile.close()
self.pstressFile.close()
self.vFile.close()
self.rhoFile.close()
if __name__ == '__main__':
import json, datetime
......@@ -141,8 +176,7 @@ if __name__ == '__main__':
tissue.solve()
with open(params['timestamp'] + '_parameters.json', "w") as fp:
json.dump(params, fp, indent=4)
json.dump(params, fp, indent=4)
from viz_tissue_maxwell import visualize
visualize(params, DIR='')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment