Created
November 30, 2012 20:13
-
-
Save Kenneth-T-Moore/4178285 to your computer and use it in GitHub Desktop.
Playing around with an OpenMDAO slot containing a custom object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> 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' | |
>> z.x = TransientScalar(points=np.sin(np.linspace(0,2*np.pi,20)), | |
t=np.linspace(0,1,20)) | |
>> print z.x # Note, behavior determined by __repr__ function I added | |
Now Printing... | |
>> print z.x.points | |
[ 0.00000000e+00 3.24699469e-01 6.14212713e-01 8.37166478e-01 | |
9.69400266e-01 9.96584493e-01 9.15773327e-01 7.35723911e-01 | |
4.75947393e-01 1.64594590e-01 -1.64594590e-01 -4.75947393e-01 | |
-7.35723911e-01 -9.15773327e-01 -9.96584493e-01 -9.69400266e-01 | |
-8.37166478e-01 -6.14212713e-01 -3.24699469e-01 -2.44929360e-16] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment