# 3.9. Internal classes¶

class opentidalfarm.memoize.MemoizeMutable(fn, hash_keys=False)[source]

Implements a memoization function to avoid duplicated functional (derivative) evaluations

class opentidalfarm.functionals.time_integrator.TimeIntegrator(problem, functional, final_only)[source]

Bases: object

add(time, state, tf, is_final)[source]
dolfin_adjoint_functional(state)[source]

integrate()[source]

Integrats the functional with a second order scheme.

class opentidalfarm.helpers.FrozenClass[source]

Bases: object

A class which can be (un-)frozen. If the class is frozen, no attributes can be added to the class.

class opentidalfarm.helpers.OutputWriter(functional)[source]

Bases: object

Suite of tools to write output to disk

individual_turbine_power(solver)[source]

Print out the individual turbine’s power or save it to file.

class opentidalfarm.helpers.StateWriter(solver, callback=None)[source]
output_files(basename)[source]
p_output_projector(mesh)[source]
u_output_projector(mesh)[source]
write(state)[source]
opentidalfarm.helpers.cpu0only(f)[source]

A decorator class that only evaluates on the first CPU in a parallel environment.

opentidalfarm.helpers.function_eval(func, point)[source]

A parallel safe evaluation of dolfin functions

opentidalfarm.helpers.get_rank()[source]

The processor number.

Returns: int – The processor number.
opentidalfarm.helpers.norm_approx(u, alpha=0.0001)[source]

A smooth approximation to $$\|u\|$$:

$\|u\|_\alpha = \sqrt(u^2 + alpha^2)$
Parameters: u – The coefficient. alpha – The approximation coefficient. ufl expression – the approximate norm of u.
opentidalfarm.helpers.smooth_uflmin(a, b, alpha=1e-08)[source]

A smooth approximation to $$\min(a, b)$$:

$\text{min}_\alpha(a, b) = \frac{1}{2} (a + b - \|a - b\|_\alpha)$
Parameters: a – First argument to $$\min$$. b – Second argument to $$\min$$. alpha – The approximation coefficient. ufl expression – the approximate $$\min$$ function.
opentidalfarm.helpers.test_gradient_array(J, dJ, x, seed=0.01, perturbation_direction=None, number_of_tests=5, plot_file=None)[source]

Checks the correctness of the derivative dJ. x must be an array that specifies at which point in the parameter space the gradient is to be checked. The functions J(x) and dJ(x) must return the functional value and the functional derivative respectivaly.

This function returns the order of convergence of the Taylor series remainder, which should be 2 if the gradient is correct.

class opentidalfarm.solvers.les.LES(V, u, smagorinsky_coefficient)[source]

Bases: object

A solver for computing the eddy viscosity by solving:

$e = (s w)^2I$

where $$e$$ is the eddy viscosity, $$s$$ is the smagorinsky coefficient, $$w = \sqrt{\text{cell volume}}$$ is the filter width, and $$I$$ is the second invariant defined as:

$I = \sum_{1 \le i, j \le 2} 2S_{i, j}^2, \quad S = \frac{1}{2} \left(\nabla u + \nabla u^T\right)$

Parameters:

Parameters: V – The function space for the the eddy viscosity. u – The velocity function. smagorinsky_coefficient – The smagorinsky coefficient. eddy_viscosity – The smagorinsky coefficient.
solve()[source]

Update the eddy viscosity solution for the current velocity.

Returns: The eddy viscosity.