Python Wrapper

This section describes the functionality exposed to Python in HypOptLib.

Note that all parameter types here are shown as C++ variables. The Python wrapper auto-translates these from Python types. For example, a Python list of ints will be translated into a C++ std::vector<uint32_t>* automatically.

Contents

Structs and Enums

These objects are used to define the physical characteristics of the problem: the mesh and the boundary conditions.

enum BoundaryConditionType

Types of boundary conditions currently supported.

Values:

enumerator FIXED_POINT

Cells are fixed at one. Future support may allow for arbitrary fixed point values and voids.

enumerator LOAD

Cells have a load applied at this ponit.

enum verbosity

Debug log verbosity levels.

Values:

enumerator QUIET

Most logs are muted.

enumerator INFO

Default log level.

enumerator DEBUG

Higher level logs are printed.

struct BoundaryCondition

Boundary condition set by user. The types supported are fixed points and loads.

The range in each dimension are defined as (min, max), where max >= min. If max = min, then the range is singular in that axis. If all ranges are singular, the boundary condition describes a single piont.

Public Members

BoundaryConditionType type

fixed point or laod.

std::vector<PetscScalar> xRange

Range at which the boundary condition applies in the x direction.

std::vector<PetscScalar> yRange

Range at which the boundary condition applies in the y direction.

std::vector<PetscScalar> zRange

Range at which the boundary condition applies in the z direction.

std::set<PetscInt> degreesOfFreedom

set of desired degrees of freedom. Must one or multiple of 0, 1, or 2, corresponding to x, y, and z respectively.

PetscScalar value

Only used for load types currently, typically around -0.001. If there is more than one degree of freedom, the value is applies to each one respectively.

struct DomainCoordinates

Domain definition. These coordinates define the size of the problem.

This allows for varying grid sizes without modifying the boundary conditions. The domain is used in all boundary condition calculations.

Public Members

PetscScalar xMinimum
PetscScalar xMaximum
PetscScalar yMinimum
PetscScalar yMaximum
PetscScalar zMinimum
PetscScalar zMaximum

HypOptLib

class HypOptLib

Main HypOptLib class.

This is the equivalent to a “main” function, and provides access to the Python wrapper to the essential functions to run Hyperoptimization.

Basic Functionality

The following functions are used to initialize and start the hyperoptimization algorithm.

inline HypOptLib::HypOptLib()

An empty constructor is used to make Pybind11 translation easier.

uint32_t HypOptLib::newRun(std::vector<uint32_t> *iterationSaveRange)

Starts a fresh run with the provided parameters.

Parameters:

iterationSaveRange – Range of iterations to save. Does not need to include the final iteration to support restarting, this is saved regardless.

Throws:

HypOptException –

Returns:

0 on success, or error. Only used to align with Petsc exception handling.

uint32_t HypOptLib::restartRun(std::string restartPath, std::vector<uint32_t> *iterationSaveRange)

Restarts a simualtion from the provided file path. All options are parsed from the metadata in the restart file.

Parameters:
  • restartPath – Location of the restart file.

  • iterationSaveRange – Range of iterations to save. Does not need to include the final iteration to support restarting, this is saved regardless.

Throws:

HypOptException –

Returns:

0 on success, or error. Only used to align with Petsc exception handling.

Advanced Functionality

For more advanced hyperoptimization usage or debugging.

void HypOptLib::generateRandomInitialConditionsFile(std::vector<uint32_t> *gridDimensions, std::string filePath)

Generates a file with randomized initial velocities and positions. This file can then be passed as an optional parameter to ensure the same initial conditions are used accross multiple runs.

Parameters:
  • gridDimensions – Dimensions of the cells in the grid. The final mesh will have be one higher in each dimension. The dimenions should each be divisible by 2 three times.

  • filePath – Name and path to save the output to.

Throws:

HypOptException –

Required Settings

These functions are required in order to define the topology optimization problem.

void HypOptLib::setGridProperties(std::vector<uint32_t> *gridDimensions, DomainCoordinates domain)

Sets the provided dimensions for any future simulations.

Parameters:
  • gridDimensions – x, y, and z coordinate dimensions for the grid. The mesh will be 1 larger in each direction.

  • domain – domain coordinates for the grid. This defines the actual unit lengths of each dimension. For example, a mesh with grid dimensions [32, 32, 32] and domain [(0, 1), (0, 1), (-1, 1)] means that each cell in the grid will be a rectangle, with the z axis twice the width of other two dimensions.

void HypOptLib::setBoundaryConditions(std::vector<BoundaryCondition> *boundaryConditions)

Sets the provided list of boundary conditions.

Each boundary condition is defined by its:

  • Type: FIXED_POINT or LOAD.

  • <x,y,z>Range: range in each dimension over which the condition applies. This can either be a range, ie x coordinates from [0, 4] or a single value, ie [4, 4]. Only points with x coordinate 4 will apply this BC.

  • degreesOfFreedom: a set of either 0, 1, or 2, where 0 is the x axis, 1 is the y axis, and 2 is the z axis.

  • value: for LOAD types, the scalar value for the load.

Parameters:

boundaryConditions – list of boundary conditions to apply. If an empty or invalid list is supplied, this will throw an error.

Recommneded Settings

These functions are recommended for basic usage. Each will use default values if not set, but are commonly set to custom values.

inline void HypOptLib::setSavePath(std::string filePath)

Optional setting. Sets the save path and file name of the simulation result.

Note

Defaults to ‘hypopt_output.h5’

inline void HypOptLib::setTargetTemperature(double targetTemperature)

Recommended setting. Sets the target system temperature for the simulation on new runs. Must be greater than 0.

Note

defaults to 0.

inline void HypOptLib::setTimestep(double timestep)

Recommended setting. Sets the timestep between each iteration.

Note

defaults to 0.001.

inline void HypOptLib::setNoseHooverChainOrder(uint32_t noseHooverChainOrder)

Recommended setting. Sets the number of Nose Hoover particles in the chain.

Note

defaults to 10.

inline void HypOptLib::setMaximumIterations(uint32_t maximumIterations)

Recommended setting. Sets the number of Nose Hoover particles in the chain.

Note

defaults to 100.

Optional Settings

These functions help specify specific parameters for hyperoptimization runs. If not specified, each parameter will be set to a default value.

inline void HypOptLib::setPenalty(double penalty)

Optional setting. Sets optimization penalty power.

Note

defaults to 3.

inline void HypOptLib::setMinimumFilterRadius(double minimumFilterRadius)

Optional setting. Sets the minimum filter radius. Must be greater than 0.

Note

defaults to 0.08.

inline void HypOptLib::setVolumeFraction(double volumeFraction)

Optional setting. Sets the volume fraction.

Note

defaults to 0.12.

inline void HypOptLib::setRandomStartingValues(bool randomStartingValues)

Debugging setting. If false, all positions be initialized to the volume fraction.

Note

Defaults to true.

inline void HypOptLib::setSaveHamiltonian(bool saveHamiltonian)

Debugging parameter. Enabling will double run time, but save the compliance and Hamiltonian.

Note

Defaults to false.

inline void HypOptLib::setMaxSimulationTime(double simTime)

Sets the maximum amount of time the simulation can run for.

This is calculated as timestep*iteration. Useful for variable timestep runs when the number of iterations might not be predictable.

Note

If this is set, the lower of simulation time and setMaximumIterations will be used.

Parameters:

simTime – Maxmimum allowed simulation time.

inline void HypOptLib::enableVariableTimestep(double timestepConstantAlpha, double timestepConstantBeta, double diffusionConstant)

Enables variable timestepping with the provided parameters.

Parameters:
  • timestepConstantAlpha – Growth parameter. Should be close to but greater than 1.

  • timestepConstantBeta – Decay parameter. Should be close to but less than 1.

  • diffusionConstant – Conditional error parameter.

inline void HypOptLib::loadInitialConditionsFromFile(std::string filePath)

Loads the starting positions and velocities from the provided file.

Parameters:

filePath – HDF5 file containing a valid initial conditions given the temperature and grid dimensions provided.

inline void HypOptLib::restartDoesntSupportCustomMesh()

Compatibility flag. Call this function if the restart file provided was generated before the custom mesh and boundary conditions were implemented.

Warning

if this flag is set, the grid properties and boundary conditions supplied must match the restart file.

inline void HypOptLib::setMaximumFeaSolverIterations(uint32_t maxIterations)

Optional setting to restrict number of iterations on the Krylov Method iterative solver.

The default value is 200, and is recommended for low temperature simulations. At high temperatures, the compliance of the system can become very large, and the number of iterations (and hence compute time) to solve the Finite Element Analysis (FEA) becomes quite high. In these situations, it is recomended to lower the maximum number of iterations. However, lowering the iteration count effectively truncates the solution, so the accuracy will become much reduced. This should not be an issue for high temperature simulations, where the solution space is less suceptible to lower FEA accuracy.

Parameters:

maxIterations – maximum number of iterations for the Kylov method iterative solver.