heaviside
Module Contents
Classes
The |
- class heaviside.PiecewiseHeavisideModel(**kwargs)
Bases:
csdl.Model- define()
User defined method to define runtime behavior. Note: the user never _calls_ this method. Only the Simulator class constructor calls this method.
Example
- def define(self):
self.create_input(‘x’) m = 5 b = 3 y = m*x + b self.register_output(‘y’, y)
# compile using Simulator imported from back end… sim = Simulator(Example()) sim[‘x’] = -3/5 sim.run() print(sim[‘y’]) # expect 0 ```
- initialize()
User defined method to declare parameter values. Parameters are compile time constants (neither inputs nor outputs to the model) and cannot be updated at runtime. Parameters are intended to make a Model subclass definition generic, and therefore reusable. The example below shows how a Model subclass definition uses parameters and how the user can set parameters when constructing the example Model subclass.
Example
- def initialize(self):
self.parameters.declare(‘num_times’, types=int) self.parameters.declare(‘step_size’, types=float) self.parameters.declare(‘surface’, types=dict)
- def define(self):
num_times = self.parameters[‘num_times’] step_size = self.parameters[‘step_size’] surface = self.parameters[‘surface’] name = surface[‘name’] # str symmetry = surface[‘symmetry’] # bool mesh = surface[‘mesh’] # numpy array
# define runtime behavior…
- surface = {
‘name’: ‘wing’, ‘symmetry’: False, ‘mesh’: mesh,
}
# compile using Simulator imported from back end… sim = Simulator(
- Example(
num_times=100, step_size=0.1, surface=surface,
),
)
- class heaviside.PiecewiseHeavisideOperation(*args, **kwargs)
Bases:
csdl.CustomExplicitOperationThe
Nodeclass is a base type for nodes in a Directed Acyclic Graph (DAG) that represents the computation to be performed during model evaluation.- compute(inputs, outputs)
Define outputs as an explicit function of the inputs
Example
```py def compute(self, inputs, outputs):
outputs[‘L’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] outputs[‘D’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’]
- compute_derivatives(inputs, derivatives)
User defined method to compute partial derivatives for this operation
Example
```py def compute(self, inputs, outputs):
outputs[‘L’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] outputs[‘D’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’]
- def compute_derivatives(self, inputs, derivatives):
derivatives[‘L’, ‘Cl’] = 1/2 * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘L’, ‘rho’] = 1/2 * inputs[‘Cl’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘L’, ‘V’] = inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’] * inputs[‘S’] derivatives[‘L’, ‘S’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2
derivatives[‘D’, ‘Cd’] = 1/2 * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘D’, ‘rho’] = 1/2 * inputs[‘Cd’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘D’, ‘V’] = inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’] * inputs[‘S’] derivatives[‘D’, ‘S’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2
- define()
User defined method to define custom operation
Example
def define(self): self.add_input('Cl') self.add_input('Cd') self.add_input('rho') self.add_input('V') self.add_input('S') self.add_output('L') self.add_output('D') # declare derivatives of all outputs wrt all inputs self.declare_derivatives('*', '*'))
- initialize()
User defined method to declare parameter values. Parameters are compile time constants (neither inputs nor outputs to the model) and cannot be updated at runtime. Parameters are intended to make a
CustomOperationsubclass definition generic, and therefore reusable. The example below shows how aCustomOperationsubclass definition uses parameters and how the user can set parameters when constructing the exampleCustomOperationsubclass. Note that the user never instantiates nor inherits directly from theCustomOperationbase class.Example
```py # in this example, we inherit from ExplicitOperation, but # the user can also inherit from ImplicitOperation class Example(ExplicitOperation):
- def initialize(self):
self.parameters.declare(‘in_name’, types=str) self.parameters.declare(‘out_name’, types=str)
- def define(self):
# use parameters declared in
initializein_name = self.parameters[‘in_name’] out_name = self.parameters[‘out_name’]self.add_input(in_name) self.add_output(out_name) self.declare_derivatives(out_name, in_name)
# define run time behavior by defining other methods…
# compile using Simulator imported from back end… sim = Simulator(
- Example(
in_name=’x’, out_name=’y’,
),
)