Example i62: Normal Stomach Electrical Activity on a Half Stomach Slice

This example simulates normal slow wave activity on half of a slice of the visible human stomach. It corresponds to a 4 groups of elements covering the mid-corpus and fundus. Shown below are the virtual electrode traces (2 in the fundus and 2 in each of the mid-corpus elements) as well as the spatial potential plots at 5, 10 and 15 seconds.


The comfile run by this example is as follows:

# Half Stomach Slice

if (!defined $example)
{
    $OUT="output"; unless (-d $OUT) {mkdir $OUT};
    $example ='.';
} else
{
    $OUT=".";
}


$EXPORT=1;
$HISTORY=1; #to export to unemap
$HISTFILE="$OUT/stomach";

if(1)
{
    #
    #export the full stomach for visualisation
    #
    fem define para;r;$example/min;
    fem define coor 3,1;
    fem define node;r;$example/refinedstomach;
    fem define base;r;$example/refinedstomach;
    fem define elem;r;$example/refinedstomach;
	

    # This is from Martin's transform.com (VHToComp)
    #
    # Translate the centre of the model to the origin before the rotation
    fem change node translate by -288.0,-202.66667,0.0;

    # Make sure we do the 180 degree rotation before the 2nd translation
    fem change node rotate by 180 by 0,0,0 axis 0,0,1;

    # By eye I think the final translation should be
    fem change node translate by 0.0,-160.0,540.0;

#    fem define fibr;r;$example/stomach_slice;
#    fem define elem;r;$example/stomach_slice fibre;

    if($EXPORT)
    {
	fem export node;"$OUT/fullstomach" as fullstomach offset 10000;
	fem export elem;"$OUT/fullstomach" as fullstomach offset 10000 offset_elem 10000;
    }
    fem reallocate; #clear the memory
}


#
# Read in the half stomach slice
#

fem define para;r;$example/min;
fem define coor 3,1;
fem define node;r;$example/stomach_slice;
fem define base;r;$example/refinedstomach;
fem define elem;r;$example/stomach_slice;


# This is from Martin's transform.com (VHToComp)
#
# Translate the centre of the model to the origin before the rotation
fem change node translate by -288.0,-202.66667,0.0;

# Make sure we do the 180 degree rotation before the 2nd translation
fem change node rotate by 180 by 0,0,0 axis 0,0,1;

# By eye I think the final translation should be
fem change node translate by 0.0,-160.0,540.0;

#fem define fibr;r;$example/stomach_slice;
#fem define elem;r;$example/stomach_slice fibre;

# Group the elements in different layers (for ipgrid, ipmate and ipmatc files)
fem group element 33..36 as LM;
fem group element 25..28 as ICC_MY;
fem group element 9..12 as CM1; 
fem group element 17..20 as ICC_SEP; 
fem group element 1..4 as CM2;

fem group element 33,34,25,26,9,10,17,18,1,2 as FUNDUS
fem group element 25,26,17,18    as FUNDUS_ICC
fem group element 9,10,1,2 as FUNDUS_CM
fem group element 33,34 as FUNDUS_LM

fem define grid;r;$example/stomach_slice
fem update grid geometry

fem group grid external as BOUNDARY;
fem group grid element 33,34,25,26,9,10,17,18,1,2 as FUNDUS

# Group the grid points in different layers
fem group grid element 33..36 as LM;
fem group grid element 25..28 as ICC_MY;
fem group grid element 9..12 as CM1; 
fem group grid element 17..20 as ICC_SEP; 
fem group grid element 1..4 as CM2; 

# Group the faces to allow connection
fem group grid face xi3 low element 33..36 as ICC1;
fem group grid face xi3 low element 25..28 as ICC2; 
fem group grid face xi3 low element 9..12 as ICC3;
fem group grid face xi3 low element 17..20 as ICC4; 

fem update grid conn grid ICC1 direction 3;
fem update grid conn grid ICC2 direction -3;
fem update grid conn grid ICC3 direction 3;
fem update grid conn grid ICC4 direction -3;

fem define equa;r;$example/refinedstomach class 1,2;
fem define cell;r;$example/refinedstomach class 1,2;

if($EXPORT)
{
   fem export node;"$OUT/stomach" as stomach;
   fem export elem;"$OUT/stomach" as stomach;
   fem export elem;"$OUT/grid"    as stomach grid_numbers;
   fem export elem;"$OUT/field"   as stomach field;
}


fem define mate;r;$example/epsilon_control_curves/generated class 1,2 cell
fem define mate;r;$example/sigma_control_curves/generated class 1,2


fem define init;r;$example/refinedstomach class 1,2
fem define solv;r;$example/refinedstomach class 1
fem define solv;r;$example/refinedstomach2 class 2


if ($HISTORY)
{
   # Open a history file.
   fem open history;$HISTFILE write variables yqs niqlist 1 binary;
}


# Solve.

#$STEP_TOTAL=6000; #300 seconds
$STEP_TOTAL=500;   #25 seconds

foreach $STEP ( 0..$STEP_TOTAL ) 
{
   $TIME = $STEP/20.0; #this sets the solution time step to be 0.05

   if ($STEP == 0)
   {
       fem solve to 0 class 1,2;
   }

   else 
   {
       fem update grid stimulus grid ICC_MY,ICC_SEP up_potential diffusion 0.03 direction 3;
       fem solve restart to $TIME class 1,2;
   }


   if ($EXPORT)
   {
       if ( ($STEP%20 == 0) & ($TIME <= 300) )
       {
         $FILENAME=sprintf("field%05d",$TIME);
         print "*** Exporting at Time $TIME and Step $STEP of ${STEP_TOTAL}\n";      
         fem export elem;"$OUT/$FILENAME" field as stomach;
         system( "gzip -f \"$OUT/$FILENAME.exelem\" &" );

         print "*** Calculating dipole sources\n";
         fem def source;c grid one_dipole grregion 1 grclass 1 time $TIME;
      }
   }


   if ($HISTORY)
   {
      if ($STEP%20 == 0) 
      {
         # Write history information.
         fem write history time $TIME variables yqs niqlist 1 class 1,2 hist all binary;
      }
   }
}


#
# Write out the dipole source
#
fem define sour;w;dipole grid grregion 1 grclass 1;
fem export sour;$OUT/dipole_all as dipole;


if ($HISTORY)
{
   # Close the history file.
   fem close history binary;

   # Grid point numbers have been picked in cmgui.
   # Using a discretisation of 4*4*2 with cell_corners
   # the middle point in each layer separated was picked.
   # This resulted in 2 grid point for the bottom 3 
   # elements for each layer (with a total of 6 in each layer)

   # Export electrode for the LM layer to unemap.
   $SIGNALFILE="$OUT/LM";
   $COMPPTS="17811,17851,18671,18971,20411,20711";
   fem eval elect;$SIGNALFILE history $HISTFILE from grid yqs iy 1 elect $COMPPTS binary;
   fem def export;r;$example/unemap_6;
   fem export sign;$SIGNALFILE signal $SIGNALFILE electrodes;
   if($TESTING)
   {
       fem conv signal from bin infile $SIGNALFILE outfile $SIGNALFILE;
   }

   # Export electrode for the ICC_MY layer to unemap.
   $SIGNALFILE="$OUT/ICC_MY";
   $COMPPTS="14951,14991,15231,15531,16391,16691";
   fem eval elect;$SIGNALFILE history $HISTFILE from grid yqs iy 1 elect $COMPPTS binary;
   fem def export;r;$example/unemap_6;
   fem export sign;$SIGNALFILE signal $SIGNALFILE electrodes;
   if($TESTING)
   {
       fem conv signal from bin infile $SIGNALFILE outfile $SIGNALFILE;
   }

   # Export electrode for the CM1 layer to unemap.
   $SIGNALFILE="$OUT/CM1";
   $COMPPTS="7371,7411,8891,9191,11791,12091";

   fem eval elect;$SIGNALFILE history $HISTFILE from grid yqs iy 1 elect $COMPPTS binary;
   fem def export;r;$example/unemap_6;
   fem export sign;$SIGNALFILE signal $SIGNALFILE electrodes;
   if($TESTING)
   {
       fem conv signal from bin infile $SIGNALFILE outfile $SIGNALFILE;
   }

   # Export electrode for the ICC_SEP layer to unemap.
   $SIGNALFILE="$OUT/ICC_SEP";
   $COMPPTS="13511,13511,13711,14011,14291,14591";
   fem eval elect;$SIGNALFILE history $HISTFILE from grid yqs iy 1 elect $COMPPTS binary;
   fem def export;r;$example/unemap_6;
   fem export sign;$SIGNALFILE signal $SIGNALFILE electrodes;
   if($TESTING)
   {
       fem conv signal from bin infile $SIGNALFILE outfile $SIGNALFILE;
   }

   # Export electrode for the CM2 layer to unemap.
   $SIGNALFILE="$OUT/CM2";
   $COMPPTS="671,711,2191,2491,5091,5391";
   fem eval elect;$SIGNALFILE history $HISTFILE from grid yqs iy 1 elect $COMPPTS binary;
   fem def export;r;$example/unemap_6;
   fem export sign;$SIGNALFILE signal $SIGNALFILE electrodes;
   if($TESTING)
   {
       fem conv signal from bin infile $SIGNALFILE outfile $SIGNALFILE;
   }

   # Tidy up temporary files
   system(" rm $HISTFILE.binhis ");
}


Files used by this example are:

Name                     Modified     Size

example_i62.com 03-Jul-2008 7.5k ICCcmiss_new.cml 30-Jun-2008 8.9k draw.com 03-Jul-2008 3.5k epsilon_control_curves/ 03-Jul-2008 - min.ippara 30-Jun-2008 5.9k refinedstomach.ipbase 30-Jun-2008 8.3k refinedstomach.ipcell 30-Jun-2008 3.5k refinedstomach.ipelem 30-Jun-2008 133k refinedstomach.ipequa 30-Jun-2008 1.5k refinedstomach.ipinit 30-Jun-2008 768 refinedstomach.ipnode 30-Jun-2008 382k refinedstomach.ipsolv 30-Jun-2008 2.2k refinedstomach2.ipsolv 30-Jun-2008 2.4k sigma_control_curves/ 03-Jul-2008 - stomach_slice.ipelem 30-Jun-2008 8.2k stomach_slice.ipelfb 30-Jun-2008 8.3k stomach_slice.ipfibr 30-Jun-2008 55k stomach_slice.ipgrid 03-Jul-2008 2.8k stomach_slice.ipnode 30-Jun-2008 95k unemap_6.ipexpo 30-Jun-2008 712

Download the entire example:

Name                      Modified     Size

examples_i_i6_i62.tar.gz 04-Jul-2008 362k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmSuccessSun Mar 6 00:18:24 201633
cm-debugSuccessSat Mar 5 01:41:00 2016153
rs6000-aix
cmSuccessWed Mar 4 01:26:40 200952
cm-debugSuccessMon Mar 2 02:24:19 2009540
cm64SuccessWed Mar 4 01:26:06 200953
cm64-debugSuccessTue Mar 3 02:16:27 2009554
x86_64-linux
cmSuccessSun Mar 6 00:02:14 201619
cm-debugSuccessSat Mar 5 00:07:56 201694

Testing status by file:


Html last generated: Sun Mar 6 05:51:40 2016

Input last modified: Thu Jul 3 16:08:02 2008


CMISS Help / Examples / i / i6 / i62