FEM Simulations

In NRV, FEM models are represented by the FEM_stimulation object. This class defines the nerve’s geometry, the number and shape of fascicles, and related parameters.

If the model_fname argument is set to None during instantiation, NRV will use FEniCSx to solve the FEM model. You can find the FEniCSx documentation here: FEniCS Project.

If model_fname is provided and comsol=True, NRV will instead use COMSOL with the corresponding template. More information about COMSOL can be found here: COMSOL Multiphysics.

Warning

Use FEM multiprocessing with caution. We currently recommend setting Ncore=None for now.

COMSOL Support

To use COMSOL-based FEM simulations, you must provide a parametric .mph file. NRV currently includes three COMSOL templates:

  • Nerve_1_Fascicle_1_CUFF.mph — Monofascicular nerve with a monopolar CUFF electrode

  • Nerve_1_Fascicle_1_LIFE.mph — Monofascicular nerve with a single LIFE electrode

  • Nerve_1_Fascicle_2_LIFE.mph — Monofascicular nerve with two LIFE electrodes

Warning

COMSOL support is limited and may be deprecated in future versions.

Geometry Manipulation

You can modify the nerve and fascicle geometries using:

Note

To define multiple fascicles, call reshape_nerve() with different ID values:

my_FEM.reshape_fascicle(cshape_1, ID=0)  # Create fascicle ID 0
my_FEM.reshape_fascicle(cshape_2, ID=1)  # Create fascicle ID 1
my_FEM.reshape_fascicle(cshape_3, ID=0)  # Modify fascicle ID 0

Electrodes

Any electrode object can be added to the FEM model using add_electrode(). This method also links the electrode to a corresponding stimulus object.

Warning

If using a COMSOL template, the number of fascicles and electrode model must match the template. These elements cannot be fully customized afterward.

Usage with a Simulable Object

A FEM_stimulation object can be attached to any NRV_simulable object using attach_extracellular_stimulation().

Note

Although technically possible, we do not recommend attaching a FEM model to a fascicle object. Instead, use a monofascicular nerve object.

Examples

- For an Axon:

import nrv
my_axon = nrv.myelinated(...)                    # Create an axon
my_FEM = nrv.FEM_stimulation()                   # Create FEM model
my_FEM.reshape_nerve(nerve_d, nerve_l)           # Set nerve geometry
my_FEM.reshape_outerBox(outer_d)                 # Set simulation box size
my_FEM.reshape_fascicle(cshape_1, ID=0)          # Add fascicle 0
my_FEM.reshape_fascicle(cshape_2, ID=1)          # Add fascicle 1
my_FEM.add_electrode(my_electrode, my_stimulus)  # Add electrode and stimulus
my_axon.attach_extracellular_stimulation(my_FEM) # Attach FEM model to axon
my_result = my_axon(t_sim)                       # Run simulation

See also

Tutorial 3 — Stimulating single fibers with NRV.

Example with a Nerve

- For a Nerve:

import nrv
my_nerve = nrv.nerve(...)                         # Create a Nerve
my_FEM = nrv.FEM_stimulation()                    # Create FEM model
my_FEM.add_electrode(my_electrode, my_stimulus)   # Add electrode and stimulus
my_nerve.attach_extracellular_stimulation(my_FEM) # Attach FEM model to nerve
my_result = my_nerve(t_sim)                       # Run simulation

See also

Tutorial 4 — Stimulating nerves with NRV.

Note

When attaching a FEM model to a nerve, the nerve’s geometry (e.g., diameter, number of fascicles) is automatically overwritten to ensure consistency with the properties of the neural model.