Brain Deformation From Craniotomy FEM model #137
Replies: 12 comments 16 replies
-
Hi @alexrockhill, although the topic is way out of my scope I think I can help you with your FElupe code you provided above. I'll try to explain some things here for you tomorrow. Best regards, |
Beta Was this translation helpful? Give feedback.
-
If you have the time, that would be fantastic! I didn't realize that GitHub has a discussion feature instead of issues, thanks for changing it for me to the appropriate label. |
Beta Was this translation helpful? Give feedback.
-
I assume you would like to perform a nonlinear analysis on a mesh with hexahedrons (voxels) in combination with a nearly incompressible material? The following code snippets should do the magic. First I hope you've installed Numba and Pypardiso (if you installed FElupe with all its requirements...) - else, run a terminal and type In one of my later comments you'll find a link to a shared Google Colab Notebook which contains all your code with my extensions. |
Beta Was this translation helpful? Give feedback.
-
First, let's try to export the mesh. mesh = fe.mesh.Mesh(points, cells, cell_type='hexahedron')
mesh.save("mesh.vtk") |
Beta Was this translation helpful? Give feedback.
-
Both the (though very basic) brain = fe.ThreeFieldVariation(fe.NeoHooke(mu=1000, bulk=50000))
csf = fe.ThreeFieldVariation(fe.NeoHooke(mu=100/3, bulk=1650)) |
Beta Was this translation helpful? Give feedback.
-
Next, let's setup the fields. As I already mentioned, we need the cell-wise constant pressure and volume-ratio as additional fields in order to avoid volumetric locking. displacement = fe.Field(region, dim=3)
pressure = fe.Field(region0)
volumeratio = fe.Field(region0, values=1)
fields = fe.FieldMixed((displacement, pressure, volumeratio)) |
Beta Was this translation helpful? Give feedback.
-
Your approach for the definition of the boundaries was already right - but it may be a bit simplified (and of course, adopted to the mixed-field formulation). In the latest version of FElupe the Hint: The Boundary class in FElupe only handles prescribed or fixed field values (e.g. displacement components) on mesh points (=nodes). kdtree = scipy.spatial.cKDTree(points)
shift = fe.Boundary(displacement, mask=kdtree.query(ch_pos_orig)[1])
boundaries = {"shift": shift}
dof0, dof1, offsets = fe.dof.partition(fields, boundaries)
ext0 = fe.dof.apply(displacement, boundaries, dof0) |
Beta Was this translation helpful? Give feedback.
-
I highly recommend from pypardiso import spsolve
res = fe.newtonrhapson(
fields,
umat=brain,
dof1=dof1,
dof0=dof0,
ext0=ext0,
offsets=offsets,
solver=spsolve,
kwargs={"parallel": True}
)
fe.save(region, res.x[0], filename="brain.vtk") |
Beta Was this translation helpful? Give feedback.
-
I've prepared a Google Colab Notebook but unfortunately the RAM is too small. I hope you have more on your local workstation 👍🏻 . Probably the Neo-Hooke material and the mixed field approach is a bit of an overkill - but the code simplifications to a displacement based formulation are straightforward. The Good luck, I hope the above code snippets help! My day is your night 😴 |
Beta Was this translation helpful? Give feedback.
-
Ah, I think I missed something! Do you wish to apply both materials import matadi
import felupe as fe
brain = matadi.ThreeFieldVariation(
matadi.MaterialHyperelastic(matadi.models.neo_hooke, C10=500, bulk=50000)
)
csf = matadi.ThreeFieldVariation(
matadi.MaterialHyperelastic(matadi.models.neo_hooke, C10=100/6, bulk=1650)
)
umat = fe.MatadiMaterial(matadi.MaterialComposite([brain, csf])) |
Beta Was this translation helpful? Give feedback.
-
Wow thanks so much @adtzlr for taking so much time out of your day to help me with this task! I really appreciate it! To answer your questions:
I have plenty of RAM on a workstation and I'll execute the code now and post here if I'm able to get it working. Thanks so much again, and good evening from the west coast US :) |
Beta Was this translation helpful? Give feedback.
-
This response was very delayed, apologies! (I lost track of quite a few things having a new baby!) I guess 8 GB of RAM wasn't enough, the process was killed after I tried to run it over night. I'm not sure where to go from here with Thanks for all your help @adtzlr! You have been more than kind with your time! |
Beta Was this translation helpful? Give feedback.
-
I'm attempting to replicate the general procedure in https://doi.org/10.1016/j.media.2019.06.004. The idea is to apply a shift to the boundary condition at a surface. The surface is an ECoG grid that it is apparent is shifted into the brain on a CT compared to the surface of the brain in an MRI before the operation. The voxels of the image can then be shifted appropriately to match this. The code I have so far is below but I'm a bit stuck on implementing this in
felupe
. Is this possible? And would anyone mind pointing me in the right direction as far as how to do it?(Requires mne
pip install mne pooch nibabel
)Beta Was this translation helpful? Give feedback.
All reactions