Skip to content

Commit ba55d58

Browse files
authored
Merge pull request #14 from simpeg-research/simulation
Simulation
2 parents e68e4c8 + 98d5a4a commit ba55d58

13 files changed

Lines changed: 216 additions & 250 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[bumpversion]
2-
current_version = 0.0.7
2+
current_version = 0.1.0
33
files = casingSimulations/info.py setup.py docs/conf.py
44

.travis.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
language: python
22
python:
33
- 3.6
4-
- "3.7-dev"
5-
matrix:
6-
allow_failures:
7-
- python: "3.7-dev"
84

95
env:
106
- TEST_DIR=tests
117

128
sudo: false
139

1410
before_install:
15-
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then
16-
wget http://repo.continuum.io/miniconda/Miniconda-3.8.3-Linux-x86_64.sh -O miniconda.sh;
17-
else
18-
wget http://repo.continuum.io/miniconda/Miniconda3-3.8.3-Linux-x86_64.sh -O miniconda.sh;
19-
fi
11+
- wget http://repo.continuum.io/miniconda/Miniconda3-3.8.3-Linux-x86_64.sh -O miniconda.sh;
2012
- chmod +x miniconda.sh
2113
- ./miniconda.sh -b -p $HOME/miniconda
2214
- export PATH=/home/travis/anaconda/bin:/home/travis/miniconda/bin:$PATH
2315
- conda update --yes conda
2416

2517
install:
26-
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then
27-
conda install --yes pip python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib cython ipython jupyter mkl;
28-
else
29-
conda install --yes pip python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib cython ipython jupyter mkl;
30-
fi
18+
- conda install --yes pip python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib cython ipython jupyter mkl;
3119
- python setup.py install
3220
- pip install -r requirements_dev.txt
3321

casingSimulations/info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.0.7'
1+
__version__ = '0.1.0'
22
__author__ = 'Lindsey Heagy'
33
__license__ = 'MIT'
4-
__copyright__ = 'Copyright 2018 Lindsey Heagy'
4+
__copyright__ = 'Copyright 2018-2019 Lindsey Heagy'

casingSimulations/mesh.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import inspect
77

88
import properties
9-
from SimPEG import Utils
9+
from SimPEG.utils import setKwargs
1010

1111
import discretize
1212
from discretize import utils
@@ -48,7 +48,7 @@ class BaseMeshGenerator(BaseCasing):
4848
)
4949

5050
def __init__(self, **kwargs):
51-
Utils.setKwargs(self, **kwargs)
51+
setKwargs(self, **kwargs)
5252

5353
@property
5454
def mesh(self):
@@ -411,7 +411,7 @@ def hz(self):
411411
"""
412412
if getattr(self, '_hz', None) is None:
413413

414-
self._hz = Utils.meshTensor([
414+
self._hz = utils.meshTensor([
415415
(self.csz, self.npadz, -self.pfz),
416416
(self.csz, self.ncz),
417417
(self.csz, self.npadz, self.pfz)
@@ -531,7 +531,10 @@ def __init__(self, **kwargs):
531531
@property
532532
def ncx1(self):
533533
"""number of cells with size csx1"""
534-
return np.ceil(self.modelParameters.casing_b/self.csx1+2)
534+
if getattr(self, '_ncx1', None) is None:
535+
self._ncx1 = np.ceil(self.modelParameters.casing_b/self.csx1+2)
536+
return self._ncx1
537+
535538

536539
@property
537540
def npadx1(self):
@@ -546,22 +549,22 @@ def hx(self):
546549
if getattr(self, '_hx', None) is None:
547550

548551
# finest uniform region
549-
hx1a = Utils.meshTensor([(self.csx1, self.ncx1)])
552+
hx1a = utils.meshTensor([(self.csx1, self.ncx1)])
550553

551554
# pad to second uniform region
552-
hx1b = Utils.meshTensor([(self.csx1, self.npadx1, self.pfx1)])
555+
hx1b = utils.meshTensor([(self.csx1, self.npadx1, self.pfx1)])
553556

554557
# scale padding so it matches cell size properly
555-
dx1 = sum(hx1a)+sum(hx1b)
556-
dx1 = np.floor(dx1/self.csx2)
557-
hx1b *= (dx1*self.csx2 - sum(hx1a))/sum(hx1b)
558+
dx1 = np.sum(hx1a)+np.sum(hx1b)
559+
dx1 = 3 #np.floor(dx1/self.csx2)
560+
hx1b *= (dx1*self.csx2 - np.sum(hx1a))/np.sum(hx1b)
558561

559562
# second uniform chunk of mesh
560563
ncx2 = np.ceil((self.domain_x - dx1)/self.csx2)
561-
hx2a = Utils.meshTensor([(self.csx2, ncx2)])
564+
hx2a = utils.meshTensor([(self.csx2, ncx2)])
562565

563566
# pad to infinity
564-
hx2b = Utils.meshTensor([(self.csx2, self.npadx, self.pfx2)])
567+
hx2b = utils.meshTensor([(self.csx2, self.npadx, self.pfx2)])
565568

566569
self._hx = np.hstack([hx1a, hx1b, hx2a, hx2b])
567570

casingSimulations/model.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import properties
33
import json
44
import os
5-
from SimPEG import Maps, Utils
5+
from SimPEG import maps
6+
from SimPEG.utils import setKwargs
67
from scipy.constants import mu_0
78

89
import discretize
@@ -132,7 +133,7 @@ class Wholespace(SurveyParametersMixin, BaseCasing):
132133
)
133134

134135
def __init__(self, filename=None, **kwargs):
135-
Utils.setKwargs(self, **kwargs)
136+
setKwargs(self, **kwargs)
136137

137138
def __str__(self):
138139
return self.info
@@ -858,10 +859,10 @@ def wires(self):
858859
"""
859860
wires to hook up maps to sigma, mu
860861
861-
:rtype: SimPEG.Maps.Wires
862+
:rtype: SimPEG.maps.Wires
862863
"""
863864
if getattr(self, '_wires', None) is None:
864-
self._wires = Maps.Wires(
865+
self._wires = maps.Wires(
865866
('sigma', self.mesh.nC), ('mu', self.mesh.nC)
866867
)
867868
return self._wires

casingSimulations/physics.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from SimPEG import Utils
1+
from SimPEG.utils import ndgrid, mkvc, sdiag
22
import discretize
33

44
import numpy as np
@@ -40,9 +40,9 @@ def casing_currents(j, mesh, model_parameters):
4040
(mesh.gridFz[:, 2] >= casing_z[0])
4141
)
4242

43-
jA = Utils.sdiag(mesh.area) * j
43+
jA = sdiag(mesh.area) * j
4444

45-
jACasing = Utils.sdiag(
45+
jACasing = sdiag(
4646
np.hstack([casing_faces_x, casing_faces_y, casing_faces_z])
4747
) * jA
4848

@@ -187,7 +187,7 @@ def plot_currents_over_freq(
187187
for i, f in enumerate(modelParameters.freqs):
188188
for srcind in srcinds:
189189
# src = survey.getSrcByFreq(survey.freqs[freqind])[srcind]
190-
# j = Utils.mkvc(fields[mur][src, 'j'].copy())
190+
# j = mkvc(fields[mur][src, 'j'].copy())
191191

192192
Iind = i + srcind*len(modelParameters.freqs)
193193

@@ -360,7 +360,7 @@ def plot_j_over_mu_z(
360360
x_plt = np.r_[r]
361361
z_plt = np.linspace(xlim[0], xlim[1], int(xlim[1]-xlim[0]))
362362

363-
XYZ = Utils.ndgrid(x_plt, np.r_[0], z_plt)
363+
XYZ = ndgrid(x_plt, np.r_[0], z_plt)
364364

365365
Pfx = mesh.getInterpolationMat(XYZ, 'Fx')
366366
Pfz = mesh.getInterpolationMat(XYZ, 'Fz')
@@ -391,10 +391,10 @@ def plot_j_over_mu_z(
391391
for i, mur in enumerate(modelParameters.muModels):
392392
for srcind in srcinds:
393393
src = survey.getSrcByFreq(survey.freqs[freqind])[srcind]
394-
j = Utils.mkvc(fields[mur][src, 'j'].copy())
394+
j = mkvc(fields[mur][src, 'j'].copy())
395395

396396
if subtract is not None:
397-
j = j - Utils.mkvc(
397+
j = j - mkvc(
398398
fields[subtract][src, 'j'].copy()
399399
)
400400

@@ -469,7 +469,7 @@ def plot_j_over_freq_z(
469469
x_plt = np.r_[r]
470470
z_plt = np.linspace(xlim[0], xlim[1], int(xlim[1]-xlim[0]))
471471

472-
XYZ = Utils.ndgrid(x_plt, np.r_[0], z_plt)
472+
XYZ = ndgrid(x_plt, np.r_[0], z_plt)
473473

474474
Pfx = mesh.getInterpolationMat(XYZ, 'Fx')
475475
Pfz = mesh.getInterpolationMat(XYZ, 'Fz')
@@ -498,10 +498,10 @@ def plot_j_over_freq_z(
498498
for i, freq in enumerate(modelParameters.freqs):
499499
for srcind in srcinds:
500500
src = survey.getSrcByFreq(freq)[srcind]
501-
j = Utils.mkvc(fields[mur][src, 'j'].copy())
501+
j = mkvc(fields[mur][src, 'j'].copy())
502502

503503
if subtract is not None:
504-
j = j - Utils.mkvc(
504+
j = j - mkvc(
505505
fields[subtract][src, 'j'].copy()
506506
)
507507

@@ -576,7 +576,7 @@ def plot_j_over_mu_x(
576576
x_plt = np.linspace(xlim[0], xlim[1], xlim[1])
577577
z_plt = np.r_[z]
578578

579-
XYZ = Utils.ndgrid(x_plt, np.r_[0], z_plt)
579+
XYZ = ndgrid(x_plt, np.r_[0], z_plt)
580580

581581
Pfx = mesh.getInterpolationMat(XYZ, 'Fx')
582582
Pfz = mesh.getInterpolationMat(XYZ, 'Fz')
@@ -605,10 +605,10 @@ def plot_j_over_mu_x(
605605
for i, f in enumerate(modelParameters.freqs):
606606
for srcind in srcinds:
607607
src = survey.getSrcByFreq(survey.freqs[freqind])[srcind]
608-
j = Utils.mkvc(fields[mur][src, 'j'].copy())
608+
j = mkvc(fields[mur][src, 'j'].copy())
609609

610610
if subtract is not None:
611-
j = j - Utils.mkvc(
611+
j = j - mkvc(
612612
fields[subtract][src, 'j'].copy()
613613
)
614614

casingSimulations/run.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import discretize
99
from discretize import utils
1010
import properties
11-
from SimPEG.EM import FDEM, TDEM
12-
from SimPEG import Utils, Maps
13-
from SimPEG.EM.Static import DC
11+
from SimPEG import maps
12+
from SimPEG.electromagnetics import frequency_domain as fdem
13+
from SimPEG.electromagnetics import time_domain as tdem
14+
from SimPEG.electromagnetics import resistivity as dc
15+
from SimPEG.utils import setKwargs
1416

1517
try:
1618
from pymatsolver import Pardiso as Solver
@@ -81,7 +83,7 @@ class BaseSimulation(BaseCasing):
8183

8284
def __init__(self, **kwargs):
8385
# set keyword arguments
84-
Utils.setKwargs(self, **kwargs)
86+
setKwargs(self, **kwargs)
8587

8688
# if the working directory does not exsist, create it
8789
if not os.path.isdir(self.directory):
@@ -121,6 +123,11 @@ def prob(self):
121123
def survey(self):
122124
return self._survey
123125

126+
@property
127+
def mesh(self):
128+
return self.meshGenerator.mesh
129+
130+
124131
def write_py(self, includeDC=True, include2D=True):
125132
"""
126133
Write a python script for running the simulation
@@ -222,7 +229,7 @@ class SimulationFDEM(BaseSimulation):
222229
choices=["e", "b", "h", "j"]
223230
)
224231

225-
physics = "FDEM"
232+
physics = "fdem"
226233

227234
def __init__(self, **kwargs):
228235
super(SimulationFDEM, self).__init__(**kwargs)
@@ -231,7 +238,7 @@ def __init__(self, **kwargs):
231238
def prob(self):
232239
if getattr(self, '_prob', None) is None:
233240
self._prob = getattr(
234-
FDEM, 'Problem3D_{}'.format(self.formulation)
241+
fdem, 'Problem3D_{}'.format(self.formulation)
235242
)(
236243
self.meshGenerator.mesh,
237244
sigmaMap=self.physprops.wires.sigma,
@@ -241,12 +248,12 @@ def prob(self):
241248
)
242249

243250
if getattr(self, 'srcList') is not None:
244-
self._survey = FDEM.Survey(self.srcList.srcList)
251+
self._survey = fdem.Survey(self.srcList.srcList)
245252
elif getattr(self, 'src') is not None:
246-
self._survey = FDEM.Survey(self.src.srcList)
253+
self._survey = fdem.Survey(self.src.srcList)
247254
else:
248255
raise Exception("one of src, srcList must be set")
249-
self._prob.pair(self._survey)
256+
self._prob.survey = self._survey
250257
return self._prob
251258

252259
@property
@@ -269,7 +276,7 @@ class SimulationTDEM(BaseSimulation):
269276
choices=["e", "b", "h", "j"]
270277
)
271278

272-
physics = "TDEM"
279+
physics = "tdem"
273280

274281
def __init__(self, **kwargs):
275282
super(SimulationTDEM, self).__init__(**kwargs)
@@ -278,7 +285,7 @@ def __init__(self, **kwargs):
278285
def prob(self):
279286
if getattr(self, '_prob', None) is None:
280287
self._prob = getattr(
281-
TDEM, 'Problem3D_{}'.format(self.formulation)
288+
tdem, 'Problem3D_{}'.format(self.formulation)
282289
)(
283290
self.meshGenerator.mesh,
284291
timeSteps=self.modelParameters.timeSteps,
@@ -288,9 +295,9 @@ def prob(self):
288295
verbose=self.verbose
289296
)
290297

291-
self._survey = TDEM.Survey(self.srcList.srcList)
298+
self._survey = tdem.Survey(self.srcList.srcList)
292299

293-
self._prob.pair(self._survey)
300+
self._prob.survey = self._survey
294301
return self._prob
295302

296303
@property
@@ -324,22 +331,22 @@ class SimulationDC(BaseSimulation):
324331
default="phi"
325332
)
326333

327-
physics = "DC"
334+
physics = "dc"
328335

329336
def __init__(self, **kwargs):
330337
super(SimulationDC, self).__init__(**kwargs)
331338

332-
self._prob = DC.Problem3D_CC(
339+
self._prob = dc.Problem3D_CC(
333340
self.meshGenerator.mesh,
334341
sigmaMap=self.physprops.wires.sigma,
335342
bc_type='Dirichlet',
336343
Solver=Solver
337344
)
338345
self._srcList = [
339-
DC.Src.Dipole([], self.src_a[i, :], self.src_b[i, :])
346+
dc.sources.Dipole([], self.src_a[i, :], self.src_b[i, :])
340347
for i in range(self.src_a.shape[0])
341348
]
342349
# self._src = DC.Src.Dipole([], self.src_a, self.src_b)
343-
self._survey = DC.Survey(self._srcList)
350+
self._survey = dc.Survey(self._srcList)
344351

345-
self._prob.pair(self._survey)
352+
self._prob.survey = self._survey

0 commit comments

Comments
 (0)