optimism package

Subpackages

Submodules

optimism.AlSolver module

class optimism.AlSolver.Settings(penalty_scaling, target_constraint_decrease_factor, relative_gmres_tol, max_gmres_iters, use_second_order_update, use_newton_only, num_initial_low_order_iterations, inverse_ncp_hessian_bound, max_al_iters, tol)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('penalty_scaling', 'target_constraint_decrease_factor', 'relative_gmres_tol', 'max_gmres_iters', 'use_second_order_update', 'use_newton_only', 'num_initial_low_order_iterations', 'inverse_ncp_hessian_bound', 'max_al_iters', 'tol')
classmethod _make(iterable)

Make a new Settings object from a sequence or iterable

_replace(**kwds)

Return a new Settings object replacing specified fields with new values

inverse_ncp_hessian_bound

Alias for field number 7

max_al_iters

Alias for field number 8

max_gmres_iters

Alias for field number 3

num_initial_low_order_iterations

Alias for field number 6

penalty_scaling

Alias for field number 0

relative_gmres_tol

Alias for field number 2

target_constraint_decrease_factor

Alias for field number 1

tol

Alias for field number 9

use_newton_only

Alias for field number 5

use_second_order_update

Alias for field number 4

optimism.AlSolver.augmented_lagrange_solve(alObjective, x, p, alSettings, subSettings, callback=None, sub_problem_callback=None, sub_problem_solver=<function trust_region_minimize>, useWarmStart=True, updatePrecond=True, updatePrecondBeforeWarmStart=True)[source]
optimism.AlSolver.get_settings(penalty_scaling=4.0, target_constraint_decrease_factor=0.75, relative_gmres_tol=0.02, max_gmres_iters=100, use_second_order_update=True, use_newton_only=False, num_initial_low_order_iterations=3, inverse_ncp_hessian_bound=0.01, max_al_iters=100, tol=1e-08)[source]
optimism.AlSolver.linear_update(alObjective, x, rhs_func, alSettings)[source]
optimism.AlSolver.solve_sub_step(alObjective, x, ncpErrorOld, alSettings, subSettings, sub_problem_solver, sub_problem_callback=None)[source]

optimism.BoundConstrainedObjective module

class optimism.BoundConstrainedObjective.BoundConstrainedObjective(objective_func, x0, p, constrainedIndices, constraintStiffnessScaling=1.0, precondStrategy=None)[source]

Bases: ConstrainedObjective

get_multipliers()[source]
get_residual(x)[source]
get_total_residual(x)[source]
get_value(x)[source]
class optimism.BoundConstrainedObjective.ScaledPrecondStrategy(precondStrategy, scaled_constraint_hessian, dofScaling, constrainedIndices)[source]

Bases: PrecondStrategy

initialize(x, p, lam, kappa)[source]
precond_at_attempt(attempt)[source]

optimism.BoundConstrainedSolver module

optimism.BoundConstrainedSolver.bound_constrained_solve(boundConstrainedObjective, x0, p, alSettings, subSettings, callback=None, sub_problem_callback=None, useWarmStart=True, updatePrecond=True, sub_problem_solver=<function trust_region_minimize>)[source]

optimism.ConstrainedObjective module

class optimism.ConstrainedObjective.ConstrainedObjective(objective_func, constraint_func, x, p, lam, kappa, precondStrategy=None)[source]

Bases: Objective

constrained_jacobian_p_vec(xl, vp)[source]
constrained_jacobian_vec(xl, vxl)[source]
constrained_residual(xl)[source]
constraint(x)[source]
create_augmented_lagrangian(objective_func, constraint_func)[source]
gradient(x)[source]
gradient_l(x)[source]
gradient_p(x)[source]
hessian(x)[source]
hessian_vec(x, vx)[source]
jacobian_l_vec(x, vl)[source]
jacobian_p_vec(x, vp)[source]
ncp(x)[source]
ncp_hessian(x)[source]
reset_kappa()[source]
total_residual(x)[source]
update_precond(x)[source]
value(x)[source]
class optimism.ConstrainedObjective.ConstrainedQuasiObjective(objective_func, constraint_func, x, p, lam, kappa, precondStrategy=None)[source]

Bases: ConstrainedObjective

create_augmented_lagrangian(objective_func, constraint_func)[source]
class optimism.ConstrainedObjective.PrecondStrategy(objective_precond, constraint_precond)[source]

Bases: object

initialize(x, p, lam, kappa)[source]
precond_at_attempt(attempt)[source]
optimism.ConstrainedObjective.fischer_burmeister(c, l, k)[source]
optimism.ConstrainedObjective.fischer_burmeister_jac_l(c, l, k)[source]

optimism.EquationSolver module

class optimism.EquationSolver.Settings(t1, t2, eta1, eta2, eta3, max_trust_iters, tol, max_cg_iters, max_cumulative_cg_iters, cg_tol, cg_inexact_solve_ratio, tr_size, min_tr_size, check_stability, use_preconditioned_inner_product_for_cg, use_incremental_objective, debug_info, over_iters)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('t1', 't2', 'eta1', 'eta2', 'eta3', 'max_trust_iters', 'tol', 'max_cg_iters', 'max_cumulative_cg_iters', 'cg_tol', 'cg_inexact_solve_ratio', 'tr_size', 'min_tr_size', 'check_stability', 'use_preconditioned_inner_product_for_cg', 'use_incremental_objective', 'debug_info', 'over_iters')
classmethod _make(iterable)

Make a new Settings object from a sequence or iterable

_replace(**kwds)

Return a new Settings object replacing specified fields with new values

cg_inexact_solve_ratio

Alias for field number 10

cg_tol

Alias for field number 9

check_stability

Alias for field number 13

debug_info

Alias for field number 16

eta1

Alias for field number 2

eta2

Alias for field number 3

eta3

Alias for field number 4

max_cg_iters

Alias for field number 7

max_cumulative_cg_iters

Alias for field number 8

max_trust_iters

Alias for field number 5

min_tr_size

Alias for field number 12

over_iters

Alias for field number 17

t1

Alias for field number 0

t2

Alias for field number 1

tol

Alias for field number 6

tr_size

Alias for field number 11

use_incremental_objective

Alias for field number 15

use_preconditioned_inner_product_for_cg

Alias for field number 14

optimism.EquationSolver.cg_inner_products_preconditioned(alpha, beta, zd, dd, rPr, z, d)[source]
optimism.EquationSolver.cg_inner_products_unpreconditioned(alpha, beta, zd, dd, rPr, z, d)[source]
optimism.EquationSolver.dogleg_step(cp, newtonP, trSize, mat_mul)[source]
optimism.EquationSolver.get_settings(t1=0.25, t2=1.75, eta1=1e-10, eta2=0.1, eta3=0.5, max_trust_iters=100, tol=1e-08, max_cg_iters=50, max_cumulative_cg_iters=1000, cg_tol=None, cg_inexact_solve_ratio=1e-05, tr_size=2.0, min_tr_size=1e-08, check_stability=False, use_preconditioned_inner_product_for_cg=False, use_incremental_objective=False, debug_info=True, over_iters=0)[source]
optimism.EquationSolver.is_converged(objective, x, realO, modelO, realRes, modelRes, cgIters, trSize, settings)[source]
optimism.EquationSolver.is_on_boundary(stepType)[source]
optimism.EquationSolver.newton(objective, x, settings, callback=None)[source]
optimism.EquationSolver.newton_solve(objective_func, solution, maxSteps=1)[source]
optimism.EquationSolver.nonlinear_equation_solve(objective, x0, p, settings, solver_algorithm=<function trust_region_minimize>, callback=None, useWarmStart=True, updatePrecond=True)[source]
optimism.EquationSolver.output_matrix(objective, x)[source]
optimism.EquationSolver.preconditioned_project_to_boundary(z, d, trSize, zz, mult_by_approx_hessian)[source]
optimism.EquationSolver.print_banner(objective, modelObjective, cgIters, trSize, onBoundary, willAccept)[source]
optimism.EquationSolver.print_min_banner(objective, modelObjective, res, modelRes, cgIters, trSize, onBoundary, willAccept, settings)[source]
optimism.EquationSolver.project_to_boundary(z, d, trSize, zz)[source]
optimism.EquationSolver.project_to_boundary_with_coefs(z, d, trSize, zz, zd, dd)[source]
optimism.EquationSolver.settings_with_new_tol(oldSettings, newTol)[source]
optimism.EquationSolver.solve_trust_region_equality_constraint(x, g, J, trSize, settings)[source]
optimism.EquationSolver.solve_trust_region_minimization(x, r, hess_vec_func, precond, trSize, settings)[source]
optimism.EquationSolver.trust_region_least_squares_solve(objective, x, settings)[source]
optimism.EquationSolver.trust_region_minimize(objective, x, settings, callback=None)[source]
optimism.EquationSolver.update_step_length_squared(alpha, zz, zd, dd)[source]

optimism.EquationSolverSubspace module

class optimism.EquationSolverSubspace.ModelProblem(g)[source]

Bases: object

add_vector(v, Kv)[source]
is_initialized()[source]
setup_system()[source]
solve(Delta)[source]
optimism.EquationSolverSubspace.project_to_boundary_with_coefs(z, d, trSize, zz, zd, dd)[source]
optimism.EquationSolverSubspace.spectral_gradient_minimize(x, g, hess_vec_func, trSize, settings)[source]
optimism.EquationSolverSubspace.trust_region_cg(x, r, Pr, HPr, hess_vec_func, precond, trSize, settings)[source]
optimism.EquationSolverSubspace.trust_region_subspace_minimize(objective, x, settings, callback=None)[source]

optimism.FunctionSpace module

class optimism.FunctionSpace.DofManager(functionSpace, dim, EssentialBCs)[source]

Bases: object

_make_hessian_bc_mask(conns)[source]
_make_hessian_coordinates(conns)[source]
create_field(Uu, Ubc=0.0)[source]
get_bc_size()[source]
get_bc_values(U)[source]
get_unknown_size()[source]
get_unknown_values(U)[source]
slice_unknowns_with_dof_indices(Uu, dofIndexSlice)[source]
class optimism.FunctionSpace.EssentialBC(nodeSet, component)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('nodeSet', 'component')
classmethod _make(iterable)

Make a new EssentialBC object from a sequence or iterable

_replace(**kwds)

Return a new EssentialBC object replacing specified fields with new values

component

Alias for field number 1

nodeSet

Alias for field number 0

class optimism.FunctionSpace.FunctionSpace(shapes, vols, shapeGrads, mesh, quadratureRule, isAxisymmetric)

Bases: tuple

Data needed for calculus on functions in the discrete function space.

In describing the shape of the attributes, ne is the number of elements in the mesh, nqpe is the number of quadrature points per element, npe is the number of nodes per element, and nd is the spatial dimension of the domain.

shapes

Shape function values on each element, shape (ne, nqpe, npe)

vols

Volume attributed to each quadrature point. That is, the quadrature weight (on the parameteric element domain) multiplied by the Jacobian determinant of the map from the parent element to the element in the domain. Shape (ne, nqpe).

shapeGrads

Derivatives of the shape functions with respect to the spatial coordinates of the domain. Shape (ne, nqpe, npe, nd).

mesh

The Mesh object of the domain.

quadratureRule

The QuadratureRule on which to sample the shape functions.

isAxisymmetric

boolean indicating if the function space data are axisymmetric.

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('shapes', 'vols', 'shapeGrads', 'mesh', 'quadratureRule', 'isAxisymmetric')
classmethod _make(iterable)

Make a new FunctionSpace object from a sequence or iterable

_replace(**kwds)

Return a new FunctionSpace object replacing specified fields with new values

isAxisymmetric

Alias for field number 5

mesh

Alias for field number 3

quadratureRule

Alias for field number 4

shapeGrads

Alias for field number 2

shapes

Alias for field number 0

vols

Alias for field number 1

optimism.FunctionSpace.average_quadrature_field_over_element(elemQPData, vols)[source]
optimism.FunctionSpace.compute_element_field_gradient(U, coords, elemShapes, elemShapeGrads, elemVols, elemConnectivity, modify_element_gradient)[source]
optimism.FunctionSpace.compute_element_volumes(coordField, nodeOrdinals, parentElement, shapes, weights)[source]
optimism.FunctionSpace.compute_element_volumes_axisymmetric(coordField, nodeOrdinals, parentElement, shapes, weights)[source]
optimism.FunctionSpace.compute_field_gradient(functionSpace, nodalField, modify_element_gradient=<function default_modify_element_gradient>)[source]
optimism.FunctionSpace.compute_quadrature_point_field_gradient(u, shapeGrad)[source]
optimism.FunctionSpace.construct_function_space(mesh, quadratureRule, mode2D='cartesian')[source]

Construct a discrete function space.

Parameters:
  • mesh (The mesh of the domain.)

  • quadratureRule (The quadrature rule to be used for integrating on the) – domain.

  • mode2D (A string indicating how the 2D domain is interpreted for) – integration. Valid values are cartesian and axisymmetric. Axisymetric mode will include the factor of 2*pi*r in the vols attribute.

Return type:

The FunctionSpace object.

optimism.FunctionSpace.construct_function_space_from_parent_element(mesh, shapeOnRef, quadratureRule, mode2D='cartesian')[source]

Construct a function space with precomputed shape function data on the parent element.

This version of the function space constructor is Jax-transformable, and in particular can be jitted. The computation of the shape function values and derivatives on the parent element is not transformable in general. However, the mapping of the shape function data to the elements in the mesh is transformable. One can precompute the parent element shape functions once and for all, and then use this special factory function to construct the function space and avoid the non-transformable part of the operation. The primary use case is for shape sensitivities: the coordinates of the mesh change, and we want Jax to pick up the sensitivities of the shape function derivatives in space to the coordinate changes (which occurs through the mapping from the parent element to the spatial domain).

Parameters:
  • mesh (The mesh of the domain.)

  • shapeOnRef (A tuple of the shape function values and gradients on the) – parent element, evaluated at the quadrature points. The caller must take care to ensure the shape functions are evaluated at the same points as contained in the quadratureRule parameter.

  • quadratureRule (The quadrature rule to be used for integrating on the) – domain.

  • mode2D (A string indicating how the 2D domain is interpreted for) – integration. See the default factory function for details.

Return type:

The FunctionSpace object.

optimism.FunctionSpace.construct_weighted_function_space(mesh, quadratureRule, quadratureWeights=1.0)[source]
optimism.FunctionSpace.default_modify_element_gradient(elemGrads, elemShapes, elemVols, elemNodalDisps, elemNodalCoords)[source]
optimism.FunctionSpace.evaluate_on_block(functionSpace, U, stateVars, dt, func, block, *params, modify_element_gradient=<function default_modify_element_gradient>)[source]

Evaluates a density function at every quadrature point in a block of the mesh.

Parameters:
  • functionSpace – Function space object to do the evaluation with.

  • U – The vector of dofs for the primal field in the functional.

  • stateVars – Internal state variable array.

  • dt – Current time increment

  • func – Lagrangian density function to evaluate, Must have the signature func(u, dudx, q, x, *params) -> scalar, where u is the primal field, q is the value of the internal variables, x is the current point coordinates, and *params is a variadic set of additional parameters, which correspond to the *params argument.

  • block – Group of elements to evaluate over. This is an array of element indices. For performance, the elements within the block should be numbered consecutively.

  • *params – Optional parameter fields to pass into Lagrangian density function. These are represented as a single value per element.

  • modify_element_gradient – Optional function that modifies the gradient at the element level. This can be to set the particular 2D mode, and additionally to enforce volume averaging on the gradient operator. This is a keyword-only argument.

Returns:

An array of shape (numElements, numQuadPtsPerElement) that contains the scalar values of the density functional func at every quadrature point in the block.

optimism.FunctionSpace.evaluate_on_element(U, coords, elemStates, dt, elemShapes, elemShapeGrads, elemVols, elemConn, kernelFunc, modify_element_gradient, *params)[source]
optimism.FunctionSpace.get_nodal_values_on_edge(functionSpace, nodalField, edge)[source]

Get nodal values of a field on an element edge.

Arguments: functionSpace: a FunctionSpace object nodalField: The nodal vector defined over the mesh (shape is number of

nodes by number of field components)

edge: tuple containing the element number containing the edge and the

permutation (0, 1, or 2) of the edge within the triangle

optimism.FunctionSpace.integrate_element(U, coords, elemStates, elemShapes, elemShapeGrads, elemVols, elemConn, func, modify_element_gradient)[source]
optimism.FunctionSpace.integrate_element_from_local_field(elemNodalField, elemNodalCoords, elemStates, dt, elemShapes, elemShapeGrads, elemVols, func, modify_element_gradient=<function default_modify_element_gradient>)[source]

Integrate over element with element nodal field as input. This allows element residuals and element stiffness matrices to computed.

optimism.FunctionSpace.integrate_function_on_edge(functionSpace, func, U, quadRule, edge)[source]
optimism.FunctionSpace.integrate_function_on_edges(functionSpace, func, U, quadRule, edges)[source]
optimism.FunctionSpace.integrate_over_block(functionSpace, U, stateVars, dt, func, block, *params, modify_element_gradient=<function default_modify_element_gradient>)[source]

Integrates a density function over a block of the mesh.

Parameters:
  • functionSpace – Function space object to do the integration with.

  • U – The vector of dofs for the primal field in the functional.

  • stateVars – Internal state variable array.

  • dt – Current time increment

  • func – Lagrangian density function to integrate, Must have the signature func(u, dudx, q, x, *params) -> scalar, where u is the primal field, q is the value of the internal variables, x is the current point coordinates, and *params is a variadic set of additional parameters, which correspond to the *params argument.

  • block – Group of elements to integrate over. This is an array of element indices. For performance, the elements within the block should be numbered consecutively.

  • *params – Optional parameter fields to pass into Lagrangian density function. These are represented as a single value per element.

  • modify_element_gradient – Optional function that modifies the gradient at the element level. This can be to set the particular 2D mode, and additionally to enforce volume averaging on the gradient operator. This is a keyword-only argument.

Returns:

A scalar value for the integral of the density functional func integrated over the block of elements.

optimism.FunctionSpace.interpolate_nodal_field_on_edge(functionSpace, U, interpolationPoints, edge)[source]

Interpolate a nodal field to specified points on an element edge.

Arguments: functionSpace: a FunctionSpace object U: the nodal values array interpolationPoints: coordinates of points (in the 1D parametric space) to

interpolate to

edge: tuple containing the element number containing the edge and the

permutation (0, 1, or 2) of the edge within the triangle

optimism.FunctionSpace.interpolate_to_element_points(U, elemShapes, elemConnectivity)[source]
optimism.FunctionSpace.interpolate_to_point(elementNodalValues, shape)[source]
optimism.FunctionSpace.interpolate_to_points(functionSpace, nodalField)[source]
optimism.FunctionSpace.map_element_shape_grads(coordField, nodeOrdinals, parentElement, shapeGradients)[source]
optimism.FunctionSpace.project_quadrature_field_to_element_field(functionSpace, quadField)[source]

optimism.IncompleteCholesky module

optimism.Interpolants module

optimism.Interpolants.ParentElement

alias of NodalBasis

class optimism.Interpolants.ShapeFunctions(values, gradients)

Bases: tuple

Shape functions and shape function gradients (in the parametric space).

values

Values of the shape functions at a discrete set of points. Shape is (nPts, nNodes), where nPts is the number of points at which the shame functinos are evaluated, and nNodes is the number of nodes in the element (which is equal to the number of shape functions).

gradients

Values of the parametric gradients of the shape functions. Shape is (nPts, nDim, nNodes), where nDim is the number of spatial dimensions. Line elements are an exception, which have shape (nPts, nNdodes).

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('values', 'gradients')
classmethod _make(iterable)

Make a new ShapeFunctions object from a sequence or iterable

_replace(**kwds)

Return a new ShapeFunctions object replacing specified fields with new values

gradients

Alias for field number 1

values

Alias for field number 0

optimism.Interpolants.compute_shapes(parentElement, evaluationPoints)[source]
optimism.Interpolants.get_lobatto_nodes_1d(degree)[source]
optimism.Interpolants.make_parent_element_1d(degree)[source]

Gauss-Lobatto Interpolation points on the unit interval.

optimism.Interpolants.make_parent_element_2d(degree)[source]

Interpolation points on the triangle that are Lobatto points on the edges. Points have threefold rotational symmetry and low Lebesgue constants.

Reference: M.G. Blyth and C. Pozrikidis. “A Lobatto interpolation grid over the triangle” IMA Journal of Applied Mathematics (2005) 1-17. doi:10.1093/imamat/hxh077

Convention for numbering: example: degree = 3

3 o | 6 o o 2 interior node is 5 | 8 o o o 1 | o–o–o–o 9 7 4 0

optimism.Interpolants.make_parent_element_2d_with_bubble(degree)[source]
optimism.Interpolants.make_parent_elements(degree)[source]

Returns a triangle element and the corresponding line element.

optimism.Interpolants.num_nodes(master)[source]
optimism.Interpolants.pascal_triangle_monomials(degree)[source]
optimism.Interpolants.shape1d(degree, nodalPoints, evaluationPoints)[source]

Evaluate shape functions and derivatives at points in the master element.

Parameters:
  • master1d – 1D MasterElement to evaluate the shape function data on

  • evaluationPoints – Array of points in the master element domain at which to evaluate the shape functions and derivatives.

Returns:

Shape function values and shape function derivatives at evaluationPoints, in a tuple (shape, dshape). shapes: [nNodes, nEvalPoints] dshapes: [nNodes, nEvalPoints]

optimism.Interpolants.shape2d(degree, nodalPoints, evaluationPoints)[source]
optimism.Interpolants.shape2dBubble(refElement, evaluationPoints)[source]
optimism.Interpolants.vander1d(x, degree)[source]
optimism.Interpolants.vander2d(x, degree)[source]

optimism.J2PlasticPhaseField module

optimism.J2PlasticPhaseField._compute_elastic_infinitesimal_strain(dispGrad, state)[source]
optimism.J2PlasticPhaseField.compute_flow_direction(elasticStrain)[source]
optimism.J2PlasticPhaseField.compute_logarithmic_elastic_strain(dispGrad, state)[source]
optimism.J2PlasticPhaseField.compute_state_increment(elasticTrialStrain, stateOld, props)[source]
optimism.J2PlasticPhaseField.compute_state_new(dispGrad, stateOld, props)[source]
optimism.J2PlasticPhaseField.dr_dstrain_and_deqps(elasticTrialStrain, eqps, eqpsOld, props)

Jacobian of incremental_potential with respect to positional argument(s) (0, 1). Takes the same arguments as incremental_potential but returns the jacobian of the output with respect to the arguments at positions (0, 1).

optimism.J2PlasticPhaseField.elastic_deviatoric_free_energy(elasticStrain, props)[source]
optimism.J2PlasticPhaseField.elastic_free_energy(elasticStrain, props)[source]
optimism.J2PlasticPhaseField.elastic_volumetric_free_energy(strain, props)[source]
optimism.J2PlasticPhaseField.energy_density(dispGrad, state, props, doUpdate=True)[source]
optimism.J2PlasticPhaseField.energy_density_generic(elStrain, state, props, doUpdate)[source]
optimism.J2PlasticPhaseField.hardening_energy_density(eqps, props)[source]
optimism.J2PlasticPhaseField.incremental_potential(elasticTrialStrain, eqps, eqpsOld, props)[source]
optimism.J2PlasticPhaseField.make_initial_state(shape=(1,))[source]
optimism.J2PlasticPhaseField.make_properties(E, nu, Y0, H)[source]
optimism.J2PlasticPhaseField.r(elasticTrialStrain, eqps, eqpsOld, props)

Jacobian of incremental_potential with respect to positional argument(s) 1. Takes the same arguments as incremental_potential but returns the jacobian of the output with respect to the arguments at positions 1.

optimism.J2PlasticPhaseField.r_and_deqps(elasticTrialStrain, eqps, eqpsOld, props)

Value and gradient of incremental_potential with respect to positional argument(s) 1. Takes the same arguments as incremental_potential but returns a two-element tuple where the first element is the value of incremental_potential and the second element is the gradient, which has the same shape as the arguments at positions 1.

optimism.J2PlasticPhaseField.update_state(elasticTrialStrain, stateOld, stateNewGuess, props)[source]

optimism.JaxConfig module

optimism.JaxConfig.hessrayleigh(f)[source]
optimism.JaxConfig.hessvec(f)[source]
optimism.JaxConfig.if_then_else(cond, val1, val2)[source]

optimism.LU module

class optimism.LU.LU(A)[source]

Bases: object

dot(b)[source]
multiply_by_transpose(b)[source]
solve(b, transpose=0)[source]
solve_transpose(b)[source]
update(A)[source]

optimism.LinAlg module

optimism.LinAlg._logm_iss(A)[source]

Logarithmic map by inverse scaling and squaring and Padé approximants

Translated from the Matrix Function Toolbox http://www.ma.man.ac.uk/~higham/mftoolbox Nicholas J. Higham, Functions of Matrices: Theory and Computation, SIAM, Philadelphia, PA, USA, 2008. ISBN 978-0-898716-46-7,

optimism.LinAlg.jvp_sqrtm(primals, tangents)[source]
optimism.LinAlg.log_pade_pf(A, n)[source]

Logarithmic map by Padé approximant and partial fractions

optimism.LinAlg.logm_jvp(primals, tangents)[source]
optimism.LinAlg.sqrtm_dbp(A)[source]

Matrix square root by product form of Denman-Beavers iteration.

Translated from the Matrix Function Toolbox http://www.ma.man.ac.uk/~higham/mftoolbox Nicholas J. Higham, Functions of Matrices: Theory and Computation, SIAM, Philadelphia, PA, USA, 2008. ISBN 978-0-898716-46-7,

optimism.Math module

optimism.Math._float_split(a)[source]
optimism.Math._two_product(a, b)[source]
optimism.Math._two_sum(a, b)[source]
optimism.Math.dot2(x, y)[source]

Compute inner product of 2 vectors to much higher accuracy than numpy.dot.

Parameters:
  • x (ndarray, with only one axis (shape [n,]))

  • y (ndarray, with only one axis (shape [n,]))

Returns:

dotprod – The inner product of the input vectors.

Return type:

real

This special inner product method computes the result as accurate as if computed in quadruple precision. This algorithm is useful to computing objective functions from numerical integration. It avoids accumulation of floating point cancellation error that can obscure whether an objective function has truly decreased.

The environment variable setting

‘XLA_FLAGS = “–xla_cpu_enable_fast_math=false”’

is critical for this function to work on the CPU. Otherwise, xla apparently sets a flag for LLVM that allows unsafe floating point optimizations that can change associativity.

Reference: T. Ogita, S. M. Rump, and S. Oishi. Accurate sum and dot product. SIAM J. Sci. Comput., Vol 26, No 6, pp. 1955-1988. doi: 10.1137/030601818

optimism.Math.safe_sqrt_jvp(xt, vt)[source]
optimism.Math.sum2(a)[source]

Sum a vector to much higher accuracy than numpy.sum.

Parameters:

a (ndarray, with only one axis (shape [n,]))

Returns:

sum – The sum of the numbers in the array

Return type:

real

This special sum method computes the result as accurate as if computed in quadruple precision.

Reference: T. Ogita, S. M. Rump, and S. Oishi. Accurate sum and dot product. SIAM J. Sci. Comput., Vol 26, No 6, pp. 1955-1988. doi: 10.1137/030601818

optimism.Mechanics module

class optimism.Mechanics.DynamicsFunctions(compute_algorithmic_energy, compute_updated_internal_variables, compute_element_hessians, compute_output_energy_densities_and_stresses, compute_output_kinetic_energy, compute_output_strain_energy, compute_initial_state, compute_element_masses, predict, correct)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('compute_algorithmic_energy', 'compute_updated_internal_variables', 'compute_element_hessians', 'compute_output_energy_densities_and_stresses', 'compute_output_kinetic_energy', 'compute_output_strain_energy', 'compute_initial_state', 'compute_element_masses', 'predict', 'correct')
classmethod _make(iterable)

Make a new DynamicsFunctions object from a sequence or iterable

_replace(**kwds)

Return a new DynamicsFunctions object replacing specified fields with new values

compute_algorithmic_energy

Alias for field number 0

compute_element_hessians

Alias for field number 2

compute_element_masses

Alias for field number 7

compute_initial_state

Alias for field number 6

compute_output_energy_densities_and_stresses

Alias for field number 3

compute_output_kinetic_energy

Alias for field number 4

compute_output_strain_energy

Alias for field number 5

compute_updated_internal_variables

Alias for field number 1

correct

Alias for field number 9

predict

Alias for field number 8

class optimism.Mechanics.MechanicsFunctions(compute_strain_energy, compute_updated_internal_variables, compute_element_stiffnesses, compute_output_energy_densities_and_stresses, compute_initial_state, integrated_material_qoi, compute_output_material_qoi)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('compute_strain_energy', 'compute_updated_internal_variables', 'compute_element_stiffnesses', 'compute_output_energy_densities_and_stresses', 'compute_initial_state', 'integrated_material_qoi', 'compute_output_material_qoi')
classmethod _make(iterable)

Make a new MechanicsFunctions object from a sequence or iterable

_replace(**kwds)

Return a new MechanicsFunctions object replacing specified fields with new values

compute_element_stiffnesses

Alias for field number 2

compute_initial_state

Alias for field number 4

compute_output_energy_densities_and_stresses

Alias for field number 3

compute_output_material_qoi

Alias for field number 6

compute_strain_energy

Alias for field number 0

compute_updated_internal_variables

Alias for field number 1

integrated_material_qoi

Alias for field number 5

class optimism.Mechanics.NewmarkParameters(gamma, beta)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {'beta': 0.25, 'gamma': 0.5}
_fields = ('gamma', 'beta')
classmethod _make(iterable)

Make a new NewmarkParameters object from a sequence or iterable

_replace(**kwds)

Return a new NewmarkParameters object replacing specified fields with new values

beta

Alias for field number 1

gamma

Alias for field number 0

optimism.Mechanics._compute_element_masses(functionSpace, U, internals, density, modify_element_gradient)[source]
optimism.Mechanics._compute_element_stiffnesses(U, internals, dt, functionSpace, compute_energy_density, modify_element_gradient)[source]
optimism.Mechanics._compute_element_stiffnesses_multi_block(U, stateVariables, functionSpace, blockModels, modify_element_gradient)[source]
optimism.Mechanics._compute_initial_state_multi_block(fs, blockModels)[source]
optimism.Mechanics._compute_kinetic_energy(functionSpace, V, internals, density)[source]
optimism.Mechanics._compute_newmark_element_hessians(functionSpace, U, UPredicted, internals, density, dt, newmarkBeta, strain_energy_density, modify_element_gradient)[source]
optimism.Mechanics._compute_strain_energy(functionSpace, UField, stateField, dt, compute_energy_density, modify_element_gradient)[source]
optimism.Mechanics._compute_strain_energy_multi_block(functionSpace, UField, stateField, dt, blockModels, modify_element_gradient)[source]
optimism.Mechanics._compute_updated_internal_variables(functionSpace, U, states, dt, compute_state_new, modify_element_gradient)[source]
optimism.Mechanics._compute_updated_internal_variables_multi_block(functionSpace, U, states, dt, blockModels, modify_element_gradient)[source]
optimism.Mechanics.axisymmetric_element_gradient_transformation(elemDispGrads, elemShapes, elemVols, elemNodalDisps, elemNodalCoords)[source]
optimism.Mechanics.axisymmetric_gradient(dispGrad, disp, coord)[source]
optimism.Mechanics.compute_element_stiffness_from_global_fields(U, coords, elInternals, dt, elConn, elShapes, elShapeGrads, elVols, lagrangian_density, modify_element_gradient)[source]
optimism.Mechanics.compute_newmark_lagrangian(functionSpace, U, UPredicted, internals, density, dt, newmarkBeta, strain_energy_density, modify_element_gradient)[source]
optimism.Mechanics.compute_traction_potential_energy(fs, U, quadRule, edges, load)[source]

Compute potential energy of surface tractions.

Arguments: fs: a FunctionSpace object U: the nodal displacements quadRule: the 1D quadrature rule to use for the integration edges: array of edges, each row is an edge. Each edge has two entries, the

element ID, and the permutation of that edge in the triangle (0, 1, 2).

load: Callable that returns the traction vector. The signature is

load(X, n), where X is coordinates of a material point, and n is the outward unit normal.

time: current time

optimism.Mechanics.create_dynamics_functions(functionSpace, mode2D, materialModel, newmarkParameters, pressureProjectionDegree=None)[source]
optimism.Mechanics.create_mechanics_functions(functionSpace, mode2D, materialModel, pressureProjectionDegree=None)[source]
optimism.Mechanics.create_multi_block_mechanics_functions(functionSpace, mode2D, materialModels, pressureProjectionDegree=None)[source]
optimism.Mechanics.define_pressure_projection_gradient_tranformation(pressureProjectionDegree, modify_element_gradient)[source]
optimism.Mechanics.kinetic_energy_density(V, density)[source]
optimism.Mechanics.parse_2D_to_3D_gradient_transformation(mode2D)[source]
optimism.Mechanics.plane_strain_gradient_transformation(elemDispGrads, elemShapes, elemVols, elemNodalDisps, elemNodalCoords)[source]
optimism.Mechanics.strain_energy_density_to_lagrangian_density(strain_energy_density)[source]
optimism.Mechanics.volume_average_J_gradient_transformation(elemDispGrads, elemVols, pShapes)[source]

optimism.Mesh module

class optimism.Mesh.Mesh(coords, conns, simplexNodesOrdinals, parentElement, parentElement1d, blocks=None, nodeSets=None, sideSets=None)

Bases: tuple

Triangle mesh representing a domain.

coords

Coordinates of the nodes, shape (nNodes, nDim).

conns

Nodal connectivity table of the elements.

simplexNodesOrdinals

Indices of the nodes that are vertices.

parentElement

A ParentElement that is the element type in parametric space. A mesh can contain only 1 element type.

parentElement1d
blocks

A dictionary mapping element block names to the indices of the elements in the block.

nodeSets

A dictionary mapping node set names to the indices of the nodes.

sideSets

A dictionary mapping side set names to the edges. The edge data structure is a tuple of the element index and the local number of the edge within that element. For example, triangle elements will have edge 0, 1, or 2 for this entry.

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {'blocks': None, 'nodeSets': None, 'sideSets': None}
_fields = ('coords', 'conns', 'simplexNodesOrdinals', 'parentElement', 'parentElement1d', 'blocks', 'nodeSets', 'sideSets')
classmethod _make(iterable)

Make a new Mesh object from a sequence or iterable

_replace(**kwds)

Return a new Mesh object replacing specified fields with new values

blocks

Alias for field number 5

conns

Alias for field number 1

coords

Alias for field number 0

nodeSets

Alias for field number 6

parentElement

Alias for field number 3

parentElement1d

Alias for field number 4

sideSets

Alias for field number 7

simplexNodesOrdinals

Alias for field number 2

optimism.Mesh.combine_blocks(set1, set2, elemOffset)[source]
optimism.Mesh.combine_mesh(m1, m2)[source]
optimism.Mesh.combine_nodesets(set1, set2, nodeOffset)[source]
optimism.Mesh.combine_sidesets(set1, set2, elemOffset)[source]
optimism.Mesh.compute_edge_vectors(mesh: Mesh, edgeCoords)[source]

Get geometric vectors for an element edge.

Assumes that the edgs has a constant shape jacobian, that is, the transformation from the parent element is affine.

Arguments: mesh: a Mesh object edgeCoords: coordinates of all nodes on the edge, in the order

defined by the 1D parent element convention

Returns: tuple (t, n, j) with t: the unit tangent vector n: the outward unit normal vector j: jacobian of the transformation from parent to physical space

optimism.Mesh.construct_mesh_from_basic_data(coords, conns, blocks, nodeSets=None, sideSets=None)[source]
optimism.Mesh.construct_structured_mesh(Nx, Ny, xExtent, yExtent, elementOrder=1, useBubbleElement=False)[source]
optimism.Mesh.create_edges(conns)[source]

Generate topological information about edges in a triangulation.

Parameters:

conns ((nTriangles, 3) array) – Connectivity table of the triangulation.

Returns:

  • edgeConns ((nEdges, 2) array) – Vertices of each edge. Boundary edges are always in the counter-clockwise sense, so that the interior of the body is on the left side when walking from the first vertex to the second.

  • edges ((nEdges, 4) array) – Edge-to-triangle topological information. Each row provides the follwing information for each edge: [leftT, leftP, rightT, rightP], where leftT is the ID of the triangle to the left, leftP is the permutation of the edge in the left triangle (edge 0, 1, or 2), rightT is the ID of the triangle to the right, and rightP is the permutation of the edge in the right triangle. If the edge is a boundary edge, the values of rightT and rightP are -1.

optimism.Mesh.create_higher_order_mesh_from_simplex_mesh(mesh, order, useBubbleElement=False, copyNodeSets=False, createNodeSetsFromSideSets=False)[source]
optimism.Mesh.create_nodesets_from_sidesets(mesh)[source]
optimism.Mesh.create_structured_mesh_data(Nx, Ny, xExtent, yExtent)[source]
optimism.Mesh.get_blocks(mesh, blockNames)[source]
optimism.Mesh.get_edge_coords(mesh: Mesh, edge)[source]
optimism.Mesh.get_edge_field(mesh: Mesh, edge, field)[source]

Evaluate field on nodes of an element edge. Arguments:

mesh: a Mesh object edge: tuple containing the element number containing the edge and the

permutation (0, 1, or 2) of the edge within the triangle

optimism.Mesh.get_edge_node_indices(mesh: Mesh, edge)[source]
optimism.Mesh.mesh_with_blocks(mesh, blocks)[source]
optimism.Mesh.mesh_with_coords(mesh, coords)[source]
optimism.Mesh.mesh_with_nodesets(mesh, nodeSets)[source]
optimism.Mesh.num_elements(mesh)[source]
optimism.Mesh.num_nodes(mesh)[source]

optimism.MeshPlot module

optimism.MeshPlot.plot_mesh(mesh)[source]
optimism.MeshPlot.plot_mesh_with_field(mesh, field, fast=False, direction=0, plotName='sol.png')[source]

optimism.MinimizeScalar module

class optimism.MinimizeScalar.Settings(tol, max_iters)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('tol', 'max_iters')
classmethod _make(iterable)

Make a new Settings object from a sequence or iterable

_replace(**kwds)

Return a new Settings object replacing specified fields with new values

max_iters

Alias for field number 1

tol

Alias for field number 0

optimism.MinimizeScalar.get_settings(tol=1e-08, max_iters=25)[source]
optimism.MinimizeScalar.line_search_backtrack(x, f, g, p, alpha, F)[source]
optimism.MinimizeScalar.line_search_bidirectional(x, f, g, p, alpha, F)[source]
optimism.MinimizeScalar.line_search_forwardtrack(x, f, g, p, alpha, F)[source]
optimism.MinimizeScalar.minimize_scalar(objective, x0, diffArgs, nondiffArgs, settings)[source]
optimism.MinimizeScalar.while_loop(cond_fun, body_fun, init_val)[source]

optimism.NewtonSolver module

class optimism.NewtonSolver.Settings(relative_gmres_tol, max_gmres_iters)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('relative_gmres_tol', 'max_gmres_iters')
classmethod _make(iterable)

Make a new Settings object from a sequence or iterable

_replace(**kwds)

Return a new Settings object replacing specified fields with new values

max_gmres_iters

Alias for field number 1

relative_gmres_tol

Alias for field number 0

optimism.NewtonSolver.compute_min_p(ps, bounds)[source]
optimism.NewtonSolver.construct_quadratic(ps)[source]
optimism.NewtonSolver.globalized_newton_step(residual, linear_op, x, etak=0.001, t=0.0001, maxLinesearchIters=4, precond=None)[source]
optimism.NewtonSolver.newton_step(residual, linear_op, x, settings=(0.01, 100), precond=None)[source]

optimism.Objective module

class optimism.Objective.Objective(f, x, p, precondStrategy=None)[source]

Bases: object

apply_precond(vx)[source]
check_stability(x)[source]
gradient(x)[source]
gradient_and_tangent(x)[source]
gradient_p(x)[source]
hessian(x)[source]
hessian_vec(x, vx)[source]
jacobian_p2_vec(x, vp)[source]
jacobian_p_vec(x, vp)[source]
multiply_by_approx_hessian(vx)[source]
update_precond(x)[source]
value(x)[source]
vec_hessian(x, vx)[source]
vec_jacobian_p0(x, vp)[source]
vec_jacobian_p1(x, vp)[source]
vec_jacobian_p2(x, vp)[source]
vec_jacobian_p4(x, vp)[source]
class optimism.Objective.Params(bc_data, state_data, design_data, app_data, time, dynamic_data)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {'app_data': None, 'bc_data': None, 'design_data': None, 'dynamic_data': None, 'state_data': None, 'time': None}
_fields = ('bc_data', 'state_data', 'design_data', 'app_data', 'time', 'dynamic_data')
classmethod _make(iterable)

Make a new Params object from a sequence or iterable

_replace(**kwds)

Return a new Params object replacing specified fields with new values

app_data

Alias for field number 3

bc_data

Alias for field number 0

design_data

Alias for field number 2

dynamic_data

Alias for field number 5

state_data

Alias for field number 1

time

Alias for field number 4

class optimism.Objective.PrecondStrategy(objective_precond)[source]

Bases: object

initialize(x, p)[source]
precond_at_attempt(attempt)[source]
class optimism.Objective.ScaledObjective(objective_func, x0, p, precondStrategy=None)[source]

Bases: Objective

get_residual(x)[source]
get_value(x)[source]
class optimism.Objective.ScaledPrecondStrategy(precondStrategy, dofScaling)[source]

Bases: PrecondStrategy

initialize(x, p)[source]
precond_at_attempt(attempt)[source]
class optimism.Objective.TwoTryPrecondStrategy(f1, f2)[source]

Bases: PrecondStrategy

initialize(x, p)[source]
precond_at_attempt(attempt)[source]
optimism.Objective.param_index_update(p, index, newParam)[source]

optimism.QuadratureRule module

class optimism.QuadratureRule.QuadratureRule(xigauss, wgauss)

Bases: tuple

Quadrature rule points and weights. A namedtuple containing xigauss, a numpy array of the coordinates of the sample points in the reference domain, and wgauss, a numpy array with the weights.

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('xigauss', 'wgauss')
classmethod _make(iterable)

Make a new QuadratureRule object from a sequence or iterable

_replace(**kwds)

Return a new QuadratureRule object replacing specified fields with new values

wgauss

Alias for field number 1

xigauss

Alias for field number 0

optimism.QuadratureRule._gauss_quad_1D_1pt(_)[source]
optimism.QuadratureRule._gauss_quad_1D_2pt(_)[source]
optimism.QuadratureRule._gauss_quad_1D_3pt(_)[source]
optimism.QuadratureRule._gauss_quad_1D_4pt(_)[source]
optimism.QuadratureRule._gauss_quad_1D_5pt(_)[source]
optimism.QuadratureRule.create_padded_quadrature_rule_1D(degree)[source]

Creates 1D Gauss quadrature rule data that are padded to maintain a uniform size, which makes this function jit-able.

This function is inteded to be used only when jit compilation of calls to the quadrature rules are needed. Otherwise, prefer to use the standard quadrature rules. The standard rules do not contain extra 0s for padding, which makes them more efficient when used repeatedly (such as in the global energy).

Parameters:

degree – degree of highest polynomial to be integrated exactly

optimism.QuadratureRule.create_quadrature_rule_1D(degree)[source]

Creates a Gauss-Legendre quadrature on the unit interval.

The rule can exactly integrate polynomials of degree up to degree.

Parameters:

degree (Highest degree polynomial to be exactly integrated by the quadrature rule)

Returns:

  • A QuadratureRule named tuple containing the quadrature point coordinates

  • and the weights.

optimism.QuadratureRule.create_quadrature_rule_on_triangle(degree)[source]

Creates a Gauss-Legendre quadrature on the unit triangle.

The rule can exactly integrate 2D polynomials up to the value of degree. The domain is the triangle between the vertices (0, 0)-(1, 0)-(0, 1). The rules here are guaranteed to be cyclically symmetric in triangular coordinates and to have strictly positive weights.

Parameters:

degree (Highest degree polynomial to be exactly integrated by the quadrature rule)

Returns:

  • A QuadratureRule named tuple containing the quadrature point coordinates

  • and the weights.

optimism.QuadratureRule.eval_at_iso_points(xigauss, field)[source]
optimism.QuadratureRule.len(quadRule)[source]

Gets the number of points in a quadrature rule.

optimism.ReadExodusMesh module

optimism.ReadExodusMesh._get_vertex_nodes_from_exodus_tri6_mesh(conns)[source]
optimism.ReadExodusMesh._read_block_conns(exodusDataset, blockOrdinal)[source]
optimism.ReadExodusMesh._read_block_variable_values(exodusDataset, blockOrdinal, variableName)[source]
optimism.ReadExodusMesh._read_blocks(exodusDataset)[source]
optimism.ReadExodusMesh._read_coordinates(exodusDataset)[source]
optimism.ReadExodusMesh._read_element_type(exodusDataset)[source]
optimism.ReadExodusMesh._read_names_list(exodusDataset, recordName)[source]
optimism.ReadExodusMesh._read_node_sets(exodusDataset)[source]
optimism.ReadExodusMesh._read_side_sets(exodusDataset)[source]
optimism.ReadExodusMesh.read_exodus_mesh(fileName)[source]
optimism.ReadExodusMesh.read_exodus_mesh_element_properties(fileName, varNames, blockNum=1)[source]

optimism.ReadMesh module

optimism.ReadMesh.read_json_mesh(meshFileName)[source]

optimism.ScalarRootFind module

class optimism.ScalarRootFind.Settings(max_iters, x_tol, r_tol)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('max_iters', 'x_tol', 'r_tol')
classmethod _make(iterable)

Make a new Settings object from a sequence or iterable

_replace(**kwds)

Return a new Settings object replacing specified fields with new values

max_iters

Alias for field number 0

r_tol

Alias for field number 2

x_tol

Alias for field number 1

class optimism.ScalarRootFind.SolutionInfo(converged, iterations, function_calls, residual_norm, correction_norm)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('converged', 'iterations', 'function_calls', 'residual_norm', 'correction_norm')
classmethod _make(iterable)

Make a new SolutionInfo object from a sequence or iterable

_replace(**kwds)

Return a new SolutionInfo object replacing specified fields with new values

converged

Alias for field number 0

correction_norm

Alias for field number 4

function_calls

Alias for field number 2

iterations

Alias for field number 1

residual_norm

Alias for field number 3

optimism.ScalarRootFind.bisection_step(x, xl, xh, df, f)[source]
optimism.ScalarRootFind.find_root(f, x0, bracket, settings)[source]

Find a root of a nonlinear scalar-valued equation.

Uses Newton’s method, safeguarded with bisection. See rtsafe(…) from Numerical Recipes. This function is differentiable using Jax transforms, and can be compsed with vmap and jit.

Parameters:
  • f (callable) – Scalar function of which to find a root.

  • x0 (real) – Initial guess for root. The value of x0 should be within the range defined by bracket. If not, the initial guess will be automatically clipped to the nearest bound.

  • bracket (sequence of 2 reals (list, tuple, numpy array, etc)) – Upper and lower bounds for the root search. The existence of a root is inferred by checking that the values of f at both brackets do not have the same sign. If this check fails, nan is returned.

  • settings (A settings object from this module) – Algorithmic settings.

Returns:

x – Argument of f such that f(x) = 0 (within provided tolerance). If the root is not bracketed, nan is returned.

Return type:

real (or nan)

optimism.ScalarRootFind.get_settings(max_iters=50, x_tol=1e-13, r_tol=0)[source]

Get numerical settings for the root finder.

Parameters:
  • max_iters (int) – Maximum number of iterations to use in search

  • x_tol (real) – Tolerance on independent variable for convergence. The root finder will terminate when the independent variable changes by less than x_tol in an iteration.

  • r_tol (real) – Tolerance on absolute value of residual for convergence.

Returns:

settings

Return type:

A Settings object, which can be used in find_root.

optimism.ScalarRootFind.newton_step(x, xl, xh, df, f)[source]
optimism.ScalarRootFind.rtsafe_(f, x0, bracket, settings)[source]

optimism.SmoothFunctions module

optimism.SmoothFunctions.abs(x, eps)[source]
optimism.SmoothFunctions.max(x, y, eps)[source]
optimism.SmoothFunctions.min(x, y, eps)[source]
optimism.SmoothFunctions.min_base(x, y, eps)[source]
optimism.SmoothFunctions.zmax(x, eps)[source]

optimism.SparseCholesky module

class optimism.SparseCholesky.SparseCholesky[source]

Bases: object

apply(b)[source]
apply_transpose(b)[source]
check_stability(x, p)[source]
factorize()[source]
get_diagonal_stiffness()[source]
multiply_by_approximate(x)[source]
multiply_by_transpose(x)[source]
update(new_stiffness_func)[source]

optimism.SparseMatrixAssembler module

optimism.SparseMatrixAssembler.assemble_sparse_stiffness_matrix(kValues, conns, dofManager)[source]

optimism.Surface module

optimism.Surface.compute_edge_vectors(edgeCoords)[source]
optimism.Surface.compute_normal(edgeCoords)[source]
optimism.Surface.create_edges(coords, conns, edge_is_potentially_in_contact)[source]
optimism.Surface.eval_field(field, fieldIndex)[source]
optimism.Surface.get_coords(mesh, side)[source]
optimism.Surface.get_field_index(edge, conns)[source]
optimism.Surface.integrate_function(quadratureRule, coords, field_func)[source]
optimism.Surface.integrate_function_on_edge(quadratureRule, edge, mesh, func)[source]
optimism.Surface.integrate_function_on_surface(quadratureRule, edges, mesh, func)[source]
optimism.Surface.integrate_values(quadratureRule, coords, gaussField)[source]

optimism.TensorMath module

Provide differentiable operations on 3x3 tensors.

optimism.TensorMath.I2(A)[source]
optimism.TensorMath._exp_relative_difference(lam1, lam2)[source]
optimism.TensorMath._exp_symm_jvp(primals, tangents)[source]
optimism.TensorMath._log_relative_difference(lam1, lam2)[source]
optimism.TensorMath._log_symm_jvp(primals, tangents)[source]
optimism.TensorMath._pow_relative_difference(lam1, lam2, m)[source]
optimism.TensorMath._pow_symm_jvp(primals, tangents)[source]
optimism.TensorMath._relative_log_difference(lam1, lam2)[source]
optimism.TensorMath._relative_log_difference_no_tolerance_check(lam1, lam2)[source]
optimism.TensorMath._relative_log_difference_taylor(lam1, lam2)[source]
optimism.TensorMath._sqrt_relative_difference(lam1, lam2)[source]
optimism.TensorMath._sqrt_symm_jvp(primals, tangents)[source]
optimism.TensorMath._symmetric_matrix_function_jvp_helper(func, relative_difference, primals, tangents)[source]
optimism.TensorMath.cos_of_acos_divided_by_3(x)[source]
optimism.TensorMath.det(A)[source]
optimism.TensorMath.detpIm1(A)[source]

Compute det(A + I) - 1 while preserving precision when A is small compared to the identity.

optimism.TensorMath.dev(strain)[source]
optimism.TensorMath.deviator(A)[source]
optimism.TensorMath.eigen_sym33_non_unit(tensor)[source]

Compute eigen values and vectors of a symmetric 3x3 tensor.

Note, returned eigen vectors may not be unit length Note, this routine involves high powers of the input tensor (~M^8). Thus results can start to denormalize when the infinity norm of the input tensor falls outside the range 1.0e-40 to 1.0e+40. Outside this range use eigen_sym33_unit

optimism.TensorMath.eigen_sym33_unit(tensor)[source]
optimism.TensorMath.gradient_2D_to_axisymmetric(dudX_2D, u, X)[source]
optimism.TensorMath.inv(A)[source]
optimism.TensorMath.log_sqrt_symm(A)[source]

Compute matrix logarithm of the square root of a symmetric positive definite matrix.

optimism.TensorMath.mises_invariant(S)[source]
optimism.TensorMath.norm(A)[source]
optimism.TensorMath.norm_of_deviator(tensor)[source]
optimism.TensorMath.norm_of_deviator_squared(tensor)[source]
optimism.TensorMath.right_polar_decomposition(F)[source]

Compute the right polar decomposition of a tensor.

Computes the factors R and U such that R@U = F, where R is an orthogonal matrix and U is symmetric positive semi-definite.

Parameters: F : 3x3 matrix

Returns: a tuple of the following arrays

R : orthogonal matrix U : right stretch matrix

optimism.TensorMath.skw(A)[source]
optimism.TensorMath.sym(A)[source]
optimism.TensorMath.symmetric_matrix_function(A, func)[source]

Create a function on symmetric matrices from a scalar function.

optimism.TensorMath.tensor_2D_to_3D(H)[source]
optimism.TensorMath.trace(A)[source]
optimism.TensorMath.triaxiality(A)[source]

optimism.Timer module

class optimism.Timer.Timer(name: str | None = None, text: str = 'Time in {name}: {:0.8f} seconds', logger: ~typing.Callable[[str], None] | None = <built-in function print>)[source]

Bases: ContextDecorator

Time your code using a class, context manager, or decorator

_start_time: float | None = None
logger()

print(value, …, sep=’ ‘, end=’n’, file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.

name: str | None = None
start() None[source]

Start a new timer

stop() float[source]

Stop the timer, and report the elapsed time

text: str = 'Time in {name}: {:0.8f} seconds'
timers: ClassVar[Dict[str, float]] = {}
exception optimism.Timer.TimerError[source]

Bases: Exception

A custom exception used to report errors in use of Timer class

optimism.TrustRegionSPG module

class optimism.TrustRegionSPG.Settings(t1, t2, eta1, eta2, eta3, max_trust_iters, tol, max_spg_iters, max_cumulative_spg_iters, spg_tol, spg_inexact_solve_ratio, tr_size, min_tr_size, check_stability, use_preconditioned_inner_product_for_spg, spg_use_nonmonotone, spg_nonmonotone_iter_limit_to_enforce_decrease, use_incremental_objective, cauchy_point_sufficient_decrease_factor, cauchy_point_decrease_tol, cauchy_point_max_line_search_iters, min_spectral_step_length, max_spectral_step_length, debug_info)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('t1', 't2', 'eta1', 'eta2', 'eta3', 'max_trust_iters', 'tol', 'max_spg_iters', 'max_cumulative_spg_iters', 'spg_tol', 'spg_inexact_solve_ratio', 'tr_size', 'min_tr_size', 'check_stability', 'use_preconditioned_inner_product_for_spg', 'spg_use_nonmonotone', 'spg_nonmonotone_iter_limit_to_enforce_decrease', 'use_incremental_objective', 'cauchy_point_sufficient_decrease_factor', 'cauchy_point_decrease_tol', 'cauchy_point_max_line_search_iters', 'min_spectral_step_length', 'max_spectral_step_length', 'debug_info')
classmethod _make(iterable)

Make a new Settings object from a sequence or iterable

_replace(**kwds)

Return a new Settings object replacing specified fields with new values

cauchy_point_decrease_tol

Alias for field number 19

cauchy_point_max_line_search_iters

Alias for field number 20

cauchy_point_sufficient_decrease_factor

Alias for field number 18

check_stability

Alias for field number 13

debug_info

Alias for field number 23

eta1

Alias for field number 2

eta2

Alias for field number 3

eta3

Alias for field number 4

max_cumulative_spg_iters

Alias for field number 8

max_spectral_step_length

Alias for field number 22

max_spg_iters

Alias for field number 7

max_trust_iters

Alias for field number 5

min_spectral_step_length

Alias for field number 21

min_tr_size

Alias for field number 12

spg_inexact_solve_ratio

Alias for field number 10

spg_nonmonotone_iter_limit_to_enforce_decrease

Alias for field number 16

spg_tol

Alias for field number 9

spg_use_nonmonotone

Alias for field number 15

t1

Alias for field number 0

t2

Alias for field number 1

tol

Alias for field number 6

tr_size

Alias for field number 11

use_incremental_objective

Alias for field number 17

use_preconditioned_inner_product_for_spg

Alias for field number 14

optimism.TrustRegionSPG.bound_constrained_trust_region_minimize(objective, x, bounds, settings, callback=None)[source]
optimism.TrustRegionSPG.find_generalized_cauchy_point(x, g, hess_vec_func, bounds, alpha, trSize, settings)[source]
optimism.TrustRegionSPG.get_settings(t1=0.25, t2=1.75, eta1=1e-10, eta2=0.1, eta3=0.5, max_trust_iters=100, tol=1e-08, max_spg_iters=25, max_cumulative_spg_iters=1000, spg_tol=None, spg_inexact_solve_ratio=0.0001, tr_size=2.0, min_tr_size=1e-08, check_stability=False, use_preconditioned_inner_product_for_spg=False, spg_use_nonmonotone=True, spg_nonmonotone_iter_limit_to_enforce_decrease=10, use_incremental_objective=False, cauchy_point_sufficient_decrease_factor=0.0001, cauchy_point_decrease_tol=1e-08, cauchy_point_max_line_search_iters=25, min_spectral_step_length=1e-12, max_spectral_step_length=1000000000000.0, debug_info=True)[source]

Must have spg_tol < tol to avoid inexactness of subproblem solves preventing convergence of trust region algorithm.

optimism.TrustRegionSPG.is_converged(objective, x, realO, modelO, realOptimality, modelOptimality, spgIters, trSize, settings)[source]
optimism.TrustRegionSPG.is_on_boundary(stepType)[source]
optimism.TrustRegionSPG.output_matrix(objective, x)[source]
optimism.TrustRegionSPG.print_min_banner(objective, modelObjective, res, modelRes, spgIters, trSize, onBoundary, willAccept, settings)[source]
optimism.TrustRegionSPG.project(x, bounds)[source]

Projects onto the feasible set.

optimism.TrustRegionSPG.project_onto_tr(x, xk, bounds, trSize)[source]

Projects onto intersection of feasible set and trust region boundary.

optimism.TrustRegionSPG.settings_with_new_tol(oldSettings, newTol)[source]
optimism.TrustRegionSPG.solve(objective, x0, p, lowerBounds, upperBounds, settings, callback=None, useWarmStart=True, updatePrecond=True)[source]
optimism.TrustRegionSPG.solve_spg_subproblem(x, cauchyStep, r, bounds, hess_vec_func, precond, trSize, settings)[source]
optimism.TrustRegionSPG.subproblem_optimality(xNew, x, d, bounds, trSize)[source]

optimism.VTKWriter module

class optimism.VTKWriter.VTKDataType(value)[source]

Bases: Enum

An enumeration.

BIT = 'bit'
CHAR = 'char'
DOUBLE = 'double'
FLOAT = 'float'
INT = 'int'
LONG = 'long'
SHORT = 'short'
UNSIGNED_CHAR = 'unsigned_char'
UNSIGNED_INT = 'unsigned_int'
UNSIGNED_LONG = 'unsigned_long'
UNSIGNED_SHORT = 'unsigned_short'
class optimism.VTKWriter.VTKFieldType(value)[source]

Bases: Enum

An enumeration.

SCALARS = 1
TENSORS = 3
VECTORS = 2
class optimism.VTKWriter.VTKWriter(mesh, baseFileName='output')[source]

Bases: object

class VTKFieldRecord(data, fieldType, dataType)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('data', 'fieldType', 'dataType')
classmethod _make(iterable)

Make a new VTKFieldRecord object from a sequence or iterable

_replace(**kwds)

Return a new VTKFieldRecord object replacing specified fields with new values

data

Alias for field number 0

dataType

Alias for field number 2

fieldType

Alias for field number 1

_check_and_format_data(field, fieldType)[source]
_write_cell_connectivity(vtkFile)[source]
_write_cell_fields(vtkFile)[source]
_write_cell_types(vtkFile)[source]
_write_contact_edges(vtkFile)[source]
_write_coordinate_data(vtkFile)[source]
_write_header(vtkFile)[source]
_write_nodal_fields(vtkFile)[source]
_write_out_all_fields_in_dict(fieldDict, vtkFile)[source]
add_cell_field(name, cellData, fieldType, dataType=VTKDataType.DOUBLE)[source]
add_contact_edges(edgeConns)[source]
add_nodal_field(name, nodalData, fieldType, dataType=VTKDataType.DOUBLE)[source]
add_sphere(x, radius)[source]
write()[source]
optimism.VTKWriter.default_values(fieldType, dataType)[source]
optimism.VTKWriter.write_matrix_as_table(A)[source]

optimism.WarmStart module

optimism.WarmStart.warm_start_increment(objective, x, pNew, index=0)[source]
optimism.WarmStart.warm_start_increment_jax_safe(objective, x, pNew)[source]

Module contents