... | @@ -79,64 +79,8 @@ Withon the python script, we use `numpy` to perform error calculations. To insta |
... | @@ -79,64 +79,8 @@ Withon the python script, we use `numpy` to perform error calculations. To insta |
|
pip install --user numpy
|
|
pip install --user numpy
|
|
```
|
|
```
|
|
|
|
|
|
The python script that we will use is
|
|
The python script that we will use can be found at duneuro/duneuro-py$36.
|
|
```python
|
|
|
|
import duneuropy as dp
|
|
|
|
import simbiopy as sp
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
# read electrodes
|
|
|
|
electrodes = dp.read_field_vectors_3d('test_sphere_electrodes.txt')
|
|
|
|
|
|
|
|
# read dipoles
|
|
|
|
dipoles = dp.read_dipoles_3d('test_sphere_dipoles.txt')
|
|
|
|
|
|
|
|
# construct driver object
|
|
|
|
config = {
|
|
|
|
'type' : 'fitted',
|
|
|
|
'solver_type' : 'cg',
|
|
|
|
'element_type' : 'tetrahedron',
|
|
|
|
'volume_conductor' : {
|
|
|
|
'grid.filename' : 'test_sphere_tet.msh',
|
|
|
|
'tensors.filename' : 'test_sphere_tet.cond'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
driver = dp.MEEGDriver3d(config)
|
|
|
|
driver.setElectrodes(electrodes, {'type' : 'closest_subentity_center', 'codims' : [3] })
|
|
|
|
|
|
|
|
# compute numerical forward solution
|
|
|
|
numerical = list()
|
|
|
|
solution = driver.makeDomainFunction()
|
|
|
|
for dip in dipoles:
|
|
|
|
driver.solveEEGForward(dip, solution, {
|
|
|
|
'source_model.type' : 'partial_integration',
|
|
|
|
'solver.reduction' : 1e-8,
|
|
|
|
'post_process' : True,
|
|
|
|
'subtract_mean' : False})
|
|
|
|
numerical.append(driver.evaluateAtElectrodes(solution))
|
|
|
|
|
|
|
|
# compute analytical forward solution
|
|
|
|
radii = [92, 86, 80, 78]
|
|
|
|
center = [127, 127, 127]
|
|
|
|
conductivities = [0.00043, 0.00001, 0.00179, 0.00033]
|
|
|
|
tmpelectrodes = [np.array(x).tolist() for x in electrodes]
|
|
|
|
analytical = list()
|
|
|
|
for dip in dipoles:
|
|
|
|
current = sp.analytic_solution(radii, center, conductivities, tmpelectrodes,
|
|
|
|
np.array(dip.position()).tolist(),
|
|
|
|
np.array(dip.moment()).tolist())
|
|
|
|
analytical.append(current)
|
|
|
|
|
|
|
|
# subtract mean over electrodes
|
|
|
|
numerical = np.array(numerical).T
|
|
|
|
analytical = np.array(analytical).T
|
|
|
|
numerical -= numerical.mean(axis=0)
|
|
|
|
analytical -= analytical.mean(axis=0)
|
|
|
|
|
|
|
|
# print relative errors
|
|
|
|
re = 100.*np.linalg.norm(numerical-analytical, axis=0)/np.linalg.norm(analytical, axis=0 )
|
|
|
|
print('Relative errors for all dipoles (in percent):\n%s' % re)
|
|
|
|
```
|
|
|
|
You can copy it and store it in a file `sphere.py` in the scripts directory.
|
|
You can copy it and store it in a file `sphere.py` in the scripts directory.
|
|
Finally, we can run the script:
|
|
Finally, we can run the script:
|
|
```bash
|
|
```bash
|
... | | ... | |