cbcflow.core.nsproblem module

Classes

class cbcflow.core.nsproblem.NSProblem(params)

Bases: cbcflow.core.parameterized.Parameterized

Base class for all Navier-Stokes problems.

analytical_solution(spaces, t)

Return analytical solution.

Can be ignored when no such solution exists, this is only used in the validation frameworks to validate schemes and test grid convergence etc.

TODO: Document expected analytical_solution behaviour here.

Returns: u, p

body_force(spaces, t)

Return body force, defaults to 0.

If not overridden by subclass this function will return zero.

Returns: list of scalars.

boundary_conditions(spaces, u, p, t, controls)

Return boundary conditions in raw format.

Boundary conditions should . The boundary conditions can be specified as follows:

# Specify u=(0,0,0) on mesh domain 0 and u=(x,y,z) on mesh domain 1
bcu = [
    ([Constant(0), Constant(0), Constant(0)], 0),
    ([Expression("x[0]"), Expression("x[1]"), Expression("x[2]")], 1)
    ]

# Specify p=x^2+y^2 on mesh domain 2 and p=0 on mesh domain 3
bcp = [
    (Expression("x[0]*x[0]+x[1]*x[1]"), 2),
    (Constant(0), 3)
]

return bcu, bcp

Note that the velocity is specified as a list of scalars instead of vector expressions.

For schemes applying Dirichlet boundary conditions, the domain argument(s) are parsed to DirichletBC and can be specified in a matter that matches the signature of this class.

This function must be overridden py subclass.

Returns: a tuple with boundary conditions for velocity and pressure

controls(spaces)

Return controls for optimization problem.

Optimization problem support is currently experimental. Can be ignored for non-control problems.

TODO: Document expected controls behaviour here.

classmethod default_params()

Returns the default parameters for a problem.

Explanation of parameters:

Time parameters:

  • start_timestep: int, initial time step number
  • dt: float, time discretization value
  • T0: float, initial time
  • T: float, end time
  • period: float, length of period
  • num_periods: float, number of periods to run

Either T or period and num_period must be set. If T is not set, T=T0+period*num_periods is used.

Physical parameters:

  • mu: float, kinematic viscosity
  • rho: float, mass density

Space discretization parameters:

  • mesh_file: str, filename to load mesh from (if any)
initial_conditions(spaces, controls)

Return initial conditions.

The initial conditions should be specified as follows: ::
# Return u=(x,y,0) and p=0 as initial conditions u0 = [Expression(“x[0]”), Expression(“x[1]”), Constant(0)] p0 = Constant(0) return u0, p0

Note that the velocity is specified as a list of scalars instead of vector expressions.

This function must be overridden py subclass.

Returns: u, p

initialize_geometry(mesh, facet_domains=None, cell_domains=None)

Stores mesh, domains and related quantities in a canonical member naming.

Creates attributes on self:

  • mesh
  • facet_domains
  • cell_domains
  • ds
  • dS
  • dx
observations(spaces, t)

Return observations of velocity for optimization problem.

Optimization problem support is currently experimental. Can be ignored for non-control problems.

TODO: Document expected observations behaviour here.

test_functionals(spaces)

Return fields to be used by regression tests.

Can be ignored when no such solution exists, this is only used in the validation frameworks to validate schemes and test grid convergence etc.

Returns: list of fields.

test_references()

Return reference values corresponding to test_functionals to be used by regression tests.

Can be ignored when no such solution exists, this is only used in the validation frameworks to validate schemes and test grid convergence etc.

Returns: list of reference values.

update(spaces, u, p, t, timestep, boundary_conditions, observations=None, controls=None)

Update functions previously returned to new timestep.

This function is called before computing the solution at a new timestep.

The arguments boundary_conditions, observations, controls should be the exact lists of objects returned by boundary_conditions, observations, controls.

Typical usage of this function would be to update time-dependent boundary conditions:

bcu, bcp = boundary_conditions
for bc, _ in bcu:
    bc.t = t

for bc, _ in bcp:
    bc.t = t

returns None