Skip to content

Instantly share code, notes, and snippets.

View Kenneth-T-Moore's full-sized avatar

Kenneth Moore Kenneth-T-Moore

View GitHub Profile
@Kenneth-T-Moore
Kenneth-T-Moore / gist:3090492
Created July 11, 2012 13:53
Testing username
Testing username
@Kenneth-T-Moore
Kenneth-T-Moore / variable_in_slot
Created November 30, 2012 20:13
Playing around with an OpenMDAO slot containing a custom object
>> z = Component()
>> z.add_trait('x', Slot(TransientScalar, iotype='in'))
>> print z.x
None
>> # Type-checking is now enforced (only Trasientscalars allowed)
>> z.x="Hello"
Traceback (most recent call last):
...
TypeError: : x must be an instance of class 'TransientScalar'
from __future__ import print_function, division, absolute_import
from openmdao.api import Problem, Group, IndepVarComp, ExplicitComponent
from openmdao.api import view_model
from openmdao.devtools.xdsm_viewer.xdsm_writer import write_xdsm
class TimeComp(ExplicitComponent):
def setup(self):
import numpy as np
import openmdao.api as om
class DistParab(om.ExplicitComponent):
def initialize(self):
self.options.declare('arr_size', types=int, default=10,
@Kenneth-T-Moore
Kenneth-T-Moore / gist:23ec1b571c314fdb42a9b87d1d0c9c19
Created May 12, 2020 14:21
Two Parallel Subsystems in Series
import openmdao.api as om
prob = om.Problem()
model = prob.model
model.add_subsystem('p1', om.IndepVarComp('x', 1.0))
parallel = model.add_subsystem('parallel', om.ParallelGroup())
parallel.add_subsystem('c1', om.ExecComp(['y=-2.0*x']))
@Kenneth-T-Moore
Kenneth-T-Moore / gist:08674a0c0f41dd380978ba72f2f72efb
Created June 24, 2020 13:47
This should raise an exception.
import numpy as np
import openmdao.api as om
class ControlInterpComp(om.ExplicitComponent):
def setup(self):
self.add_output('x', shape=(3, 1))
@Kenneth-T-Moore
Kenneth-T-Moore / z1.py
Created August 21, 2020 12:53
Exception when promoting on a subgroup during configure.
import numpy as np
import openmdao.api as om
class Burn1(om.Group):
def setup(self):
self.add_subsystem('comp1', om.ExecComp(['y1=x*2'], y1=np.ones(4), x=np.ones(4)),
promotes_outputs=['*'])
import numpy as np
import openmdao.api as om
class Burn1(om.Group):
def setup(self):
self.add_subsystem('comp1', om.ExecComp(['y1=x*2'], y1=np.ones(4), x=np.ones(4)),
promotes_outputs=['*'])
@Kenneth-T-Moore
Kenneth-T-Moore / gist:1b420c28c7561f35079b8955fcbe60f4
Created August 21, 2020 19:37
Problem with src_indices dissapearing from _var_abs2meta.
import numpy as np
import openmdao.api as om
class RHS(om.Group):
def initialize(self):
self.options.declare('size', 1)
@Kenneth-T-Moore
Kenneth-T-Moore / gist:a4df46c7e5491bf6e1b5ab8d9e4c2006
Created November 13, 2020 22:26
Example: complex step to compute derivs around euler integration of openmdao problem.
import numpy as np
from scipy.optimize import minimize
import openmdao.api as om
class DynamicPressureComp(om.ExplicitComponent):
def setup(self):
self.add_input(name='rho', val=1.0, units='kg/m**3',