import febio

mesh = febio.MeshDef('ss1sets.inp','abq')

model = febio.Model(modelfile='ss1sets.feb',steps=[{'Displace': 'poro'}])
#ECM
mecm = febio.MatDef(matid=1,mname='ECM',mtype='biphasic',elsets=['ecm'],
        attributes={'phi0':'0.3'})
mecm.addBlock(branch=1,btype='solid',mtype='solid mixture',attributes={'mat_axis':['local','0, 0, 0']})
mecm.addBlock(branch=2,btype='solid',mtype='neo-Hookean',attributes={
    'density':'1','E':'.67','v':'0.2'})
mecm.addBlock(branch=2,btype='solid',mtype='ellipsoidal fiber distribution',
        attributes={'ksi':'10.0,1.0,1.0','beta':'2.0,2.0,2.0'})
mecm.addBlock(branch=1,btype='permeability',mtype='perm-ref-ortho',attributes={
        'perm0':'2e-4','perm1':'2.5e-3,1.6e-3,1.6e-3','perm2':'0,0,0','M0':'1',
        'alpha0':'0','M':'0,0,0','alpha':'2,2,2'})
#PCM assume roughly 0.3 as stiff as ECM
mpcm = febio.MatDef(matid=2,mname='PCM',mtype='biphasic',elsets=['pcm01','pcm02',
'pcm03','pcm04','pcm05','pcm06','pcm07','pcm08','pcm09','pcm10','pcm11'],attributes={'phi0':'0.3'})
mpcm.addBlock(branch=1,btype='solid',mtype='solid mixture',attributes={'mat_axis':['local','0, 0, 0']})
mpcm.addBlock(branch=2,btype='solid',mtype='neo-Hookean',attributes={
    'density':'1','E':'.2','v':'0.2'})
mpcm.addBlock(branch=2,btype='solid',mtype='ellipsoidal fiber distribution',
        attributes={'ksi':'10.0,1.0,1.0','beta':'2.0,2.0,2.0'})
mpcm.addBlock(branch=1,btype='permeability',mtype='perm-ref-ortho',attributes={
        'perm0':'2e-4','perm1':'2.5e-3,1.6e-3,1.6e-3','perm2':'0,0,0','M0':'1',
        'alpha0':'0','M':'0,0,0','alpha':'2,2,2'})
#cells
mcell = febio.MatDef(matid=3,mname='Cell',mtype='biphasic',elsets=['cell01',
    'cell02','cell03','cell04','cell05','cell06','cell07','cell08','cell09',
    'cell10','cell11'],attributes={'phi0':'0.3'})
mcell.addBlock(branch=1,btype='solid',mtype='neo-Hookean',attributes={'E':'0.001',
    'v':'0.4'})
mcell.addBlock(branch=1,btype='permeability',mtype='perm-const-iso',
        attributes={'perm':'1e-3'})
model.addMaterial(mecm)
model.addMaterial(mpcm)
model.addMaterial(mcell)

model.addGeometry(mesh=mesh,mats=[mecm,mpcm,mcell])
# boundary condtions
boundary = febio.Boundary(steps=1)
boundary.addFixed(nset=mesh.nsets['necm'],dof='xyz')
model.addBoundary(boundary)
ctrl = febio.Control()
ctrl.setAttributes({'time_steps': '2743','step_size': '1','plot_level':'PLOT_MUST_POINTS','time_stepper': {'aggressiveness': '0', 'dtmin': '0.01', 'dtmax': 'lc=1', 'max_retries': '10', 'opt_iter': '10'},'max_ups':'0','max_refs':'25','dtol':'0.01','etol':'0','lstol':'0.9'})
model.addLoadCurve(lc='1',lctype='linear',points=[0,0,14.3,14.3,15.3,1,16.3,1,17.3,1,18.3,1,19.3,1,20.3,1,25,4.7,30,5,35,5,40,5,45,5,50,5,75,25,100,25,125,25,150,25,175,25,200,25,225,25,250,25,350,100,450,100,550,100,650,100,750,100,850,100,914.3,64.3,928.6,14.3,929.6,1,930.6,1,931.6,1,932.6,1,933.6,1,934.6,1,939.3,4.7,944.3,5,949.3,5,954.3,5,959.3,5,964.3,5,989.3,25,1014.3,25,1039.3,25,1064.3,25,1089.3,25,1114.3,25,1139.3,25,1164.3,25,1264.3,100,1364.3,100,1464.3,100,1564.3,100,1664.3,100,1764.3,100,1828.6,64.3,1842.9,14.3,1843.9,1,1844.9,1,1845.9,1,1846.9,1,1847.9,1,1848.9,1,1853.6,4.7,1858.6,5,1863.6,5,1868.6,5,1873.6,5,1878.6,5,1903.6,25,1928.6,25,1953.6,25,1978.6,25,2003.6,25,2028.6,25,2053.6,25,2078.6,25,2178.6,100,2278.6,100,2378.6,100,2478.6,100,2578.6,100,2678.6,100,2742.9,64.3])
model.addControl(ctrl=ctrl)
model.writeModel()
