Skip to content

Commit

Permalink
Changed init of PdeProblem to take a Grid/GridBucket
Browse files Browse the repository at this point in the history
  • Loading branch information
Runar committed Oct 18, 2017
1 parent fc96250 commit 29537d6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
58 changes: 56 additions & 2 deletions src/porepy/numerics/compressible/problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@


class SlightlyCompressible(PdeProblem):
def __init__(self, physics='flow'):
PdeProblem.__init__(self, physics)
'''
Inherits from PdeProblem
This class solves equations of the type:
phi *c_p dp/dt - \nabla K \nabla p = q
Init:
- gb (Grid/GridBucket) Grid or grid bucket for the problem
- physics (string) Physics key word. See Parameters class for valid physics
functions:
discharge(): computes the discharges and saves it in the grid bucket as 'p'
Also see functions from PdeProblem
Example:
# We create a problem with standard data
gb = meshing.cart_grid([], [10,10], physdims=[1,1])
for g, d in gb:
d['problem'] = SlightlyCompressibleData(g, d)
problem = SlightlyCompressible(gb)
problem.solve()
'''

def __init__(self, gb, physics='flow'):
PdeProblem.__init__(self, gb, physics)

def space_disc(self):
return self.diffusive_disc(), self.source_disc()
Expand All @@ -39,6 +62,37 @@ def discharge(self):


class SlightlyCompressibleData(PdeProblemData):
'''
Inherits from PdeProblemData
Base class for assigning valid data for a slighly compressible problem.
Init:
- g (Grid) Grid that data should correspond to
- d (dictionary) data dictionary that data will be assigned to
- physics (string) Physics key word. See Parameters class for valid physics
Functions:
compressibility: (float) the compressibility of the fluid
permeability: (tensor.SecondOrder) The permeability tensor for the rock.
Setting the permeability is equivalent to setting
the PdeProblemData.diffusivity() function.
Example:
# We set an inflow and outflow boundary condition by overloading the
# bc_val term
class ExampleData(SlightlyCompressibleData):
def __init__(g, d):
SlightlyCompressibleData.__init__(self, g, d)
def bc_val(self):
left = self.grid().nodes[0] < 1e-6
right = self.grid().nodes[0] > 1 - 1e-6
val = np.zeros(g.num_faces)
val[left] = 1
val[right] = -1
return val
gb = meshing.cart_grid([], [10,10], physdims=[1,1])
for g, d in gb:
d['problem'] = ExampleData(g, d)
'''

def __init__(self, g, data, physics='flow'):
PdeProblemData.__init__(self, g, data, physics)

Expand Down
10 changes: 6 additions & 4 deletions src/porepy/numerics/pdeproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class PdeProblem():
dT/dt + v*\nabla T - \nabla K \nabla T = q
Init:
- gb (Grid/GridBucket) Grid or grid bucket for the problem
- physics (string) Physics key word. See Parameters class for valid physics
Functions that should be overloaded:
grid(): returns the grid bucket for the problem
functions:
data(): returns data dictionary. Is only used for single grids (I.e. not
Expand All @@ -39,6 +39,7 @@ class PdeProblem():
the problem without diffusion
time_disc(): returns the time discretization
initial_condition(): returns the initial condition for global variable
grid(): returns the grid bucket for the problem
time_step(): returns time step length
end_time(): returns end time
save(save_every=1): save solution. Parameter: save_every, save only every
Expand All @@ -61,7 +62,8 @@ def space_disc(self):
problem.solve()
'''

def __init__(self, physics='transport'):
def __init__(self, gb, physics='transport'):
self._gb = gb
self.physics = physics
self._data = dict()
self._set_data()
Expand Down Expand Up @@ -137,8 +139,8 @@ def initial_condition(self):
return global_variable

def grid(self):
'Returns initial condition for global variable'
raise NotImplementedError('subclass must overload function grid()')
'Returns grid/grid_bucket'
return self._gb

def time_step(self):
'Returns the time step'
Expand Down
18 changes: 3 additions & 15 deletions test/integration/test_advective_diffusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ def test_constant_temp(self):

class SourceProblem(PdeProblem):
def __init__(self, g):
self._g = g
PdeProblem.__init__(self)

def grid(self):
return self._g
PdeProblem.__init__(self, g)

def space_disc(self):
return self.source_disc()
Expand All @@ -120,11 +116,7 @@ def time_step(self):

class SourceAdvectiveProblem(PdeProblem):
def __init__(self, g):
self._g = g
PdeProblem.__init__(self)

def grid(self):
return self._g
PdeProblem.__init__(self, g)

def space_disc(self):
return self.source_disc(), self.advective_disc()
Expand All @@ -135,11 +127,7 @@ def time_step(self):

class SourceAdvectiveDiffusiveProblem(PdeProblem):
def __init__(self, g):
self._g = g
PdeProblem.__init__(self)

def grid(self):
return self._g
PdeProblem.__init__(self, g)

def space_disc(self):
return self.source_disc(), self.advective_disc(), self.diffusive_disc()
Expand Down
8 changes: 1 addition & 7 deletions test/integration/test_pdesolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,11 @@ def test_CrankNicolson_solver(self):
class UnitSquareInjectionMultiDim(PdeProblem):
def __init__(self, gb):
# Initialize base class
self._g = gb
PdeProblem.__init__(self)
PdeProblem.__init__(self, gb)

def space_disc(self):
return self.source_disc()

#--------grid function--------

def grid(self):
return self._g

#--------Time stepping------------

def update(self, t):
Expand Down

0 comments on commit 29537d6

Please sign in to comment.