Computing FEM head model

Hello, I'm trying to script the FEM head model process in EEG source analysis. Before that, I have generated BEM surfaces and FEM mesh. When computing the head model, an error occurred in the command window. I used all the default settings in the FEM head model computing. The followings are the command lines and the error:

Script

% Process: Compute head model
sFiles = bst_process('CallProcess', 'process_headmodel', sFiles, [], ...
    'Comment',     '', ...
    'sourcespace', 2, ...  % MRI volume
    'volumegrid',  struct(...
         'Method',        'isotropic', ...
         'nLayers',       17, ...
         'Reduction',     3, ...
         'nVerticesInit', 4000, ...
         'Resolution',    0.005, ...
         'FileName',      []), ...
    'meg',         3, ...  % Overlapping spheres
    'eeg',         4, ...  % DUNEuro FEM
    'ecog',        2, ...  % OpenMEEG BEM
    'seeg',        2, ...  % OpenMEEG BEM
    'openmeeg',    struct(...
         'BemSelect',    [1, 1, 1], ...
         'BemCond',      [1, 0.0125, 1], ...
         'BemNames',     {{'Scalp', 'Skull', 'Brain'}}, ...
         'BemFiles',     {{}}, ...
         'isAdjoint',    0, ...
         'isAdaptative', 1, ...
         'isSplit',      0, ...
         'SplitLength',  4000), ...
    'duneuro',     struct(...
         'FemCond',             [], ...
         'FemSelect',           [], ...
         'UseTensor',           0, ...
         'Isotropic',           1, ...
         'SrcShrink',           0, ...
         'SrcForceInGM',        0, ...
         'FemType',             'fitted', ...
         'SolverType',          'cg', ...
         'GeometryAdapted',     0, ...
         'Tolerance',           1e-08, ...
         'ElecType',            'normal', ...
         'MegIntorderadd',      0, ...
         'MegType',             'physical', ...
         'SolvSolverType',      'cg', ...
         'SolvPrecond',         'amg', ...
         'SolvSmootherType',    'ssor', ...
         'SolvIntorderadd',     0, ...
         'DgSmootherType',      'ssor', ...
         'DgScheme',            'sipg', ...
         'DgPenalty',           20, ...
         'DgEdgeNormType',      'houston', ...
         'DgWeights',           1, ...
         'DgReduction',         1, ...
         'SolPostProcess',      1, ...
         'SolSubstractMean',    0, ...
         'SolSolverReduction',  1e-10, ...
         'SrcModel',            'venant', ...
         'SrcIntorderadd',      0, ...
         'SrcIntorderadd_lb',   2, ...
         'SrcNbMoments',        3, ...
         'SrcRefLen',           20, ...
         'SrcWeightExp',        1, ...
         'SrcRelaxFactor',      6, ...
         'SrcMixedMoments',     1, ...
         'SrcRestrict',         1, ...
         'SrcInit',             'closest_vertex', ...
         'BstSaveTransfer',     0, ...
         'BstEegTransferFile',  'eeg_transfer.dat', ...
         'BstMegTransferFile',  'meg_transfer.dat', ...
         'BstEegLfFile',        'eeg_lf.dat', ...
         'BstMegLfFile',        'meg_lf.dat', ...
         'UseIntegrationPoint', 1, ...
         'EnableCacheMemory',   0, ...
         'MegPerBlockOfSensor', 0), ...
    'channelfile', '');

Matlab Command Window

DUNEURO> System call: "C:\Users\Greatson_Wu\.brainstorm\plugins\duneuro\bst_duneuro\bin\bst_duneuro_meeg_win64.exe" "C:\Users\Greatson_Wu\.brainstorm\tmp\duneuro_240223_010844\duneuro_minifile.mini"
Reading 3d Gmsh grid... 
version 2.2 Gmsh file detected 
file contains 54932 nodes 
file contains 290432 elements 
number of real vertices = 54932 
number of boundary elements = 0 
number of elements = 290432 
volume_conductor.time_reading_gmsh = 16.3149 
tensors = 0 
time = 0 
volume_conductor.time_reading_tensors = 0 
Dune reported error: Dune::Exception [read:/home/juan/bst-duneuro/src/duneuro/duneuro/io/volume_conductor_reader.hh:176]: physical entitiy of element 0 is 2 but only 0 tensors have been read 
status =
    -1

The error seemed related to physical entitiy of element 0 and tensors. The error still existed even after I computed the FEM tensors. However, when I did the head model computing in the GUI, It worked successfully (also using the default settings).

I am wondering, what exactly caused this error? What can I do in the script to solve the problem?

From these lines, it seems that your FEM model does not have any layer or any conductivity.
You need to set the values of the conductivities for your model and also set "1" to the layer that you want to include.

It should look to something like that for the 5-layer model.

image

  Thank you so much! It is exactly the blank FemCond and FemSelect that caused the problem.
1 Like