[ae3ce4e] | 1 | #!/usr/bin/env python |
---|
| 2 | """ Provide base functionality for all model components |
---|
| 3 | @author: Mathieu Doucet / UTK |
---|
| 4 | @contact: mathieu.doucet@nist.gov |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | # info |
---|
| 8 | __author__ = "Mathieu Doucet / UTK" |
---|
| 9 | __id__ = "$Id: BaseComponent.py,v 1.2 2007/03/14 21:04:40 doucet Exp $" |
---|
| 10 | |
---|
| 11 | # imports |
---|
| 12 | from sans.models.BaseComponent import BaseComponent |
---|
| 13 | |
---|
| 14 | class MulComponent(BaseComponent): |
---|
| 15 | """ Basic model component for Multiply |
---|
| 16 | Provides basic arithmetics |
---|
| 17 | """ |
---|
| 18 | |
---|
| 19 | def __init__(self, base=None, other=None): |
---|
| 20 | """ |
---|
| 21 | @param base: component to multiply |
---|
| 22 | @param other: component to multiply by |
---|
| 23 | """ |
---|
| 24 | BaseComponent.__init__(self) |
---|
| 25 | # Component to multiply |
---|
| 26 | self.operateOn = base |
---|
| 27 | # Component to multiply by |
---|
| 28 | self.other = other |
---|
| 29 | # name |
---|
| 30 | self.name = 'MulComponent' |
---|
| 31 | |
---|
| 32 | def run(self, x=0): |
---|
| 33 | """ |
---|
| 34 | Evaluate each part of the component and sum the results |
---|
| 35 | @param x: input parameter |
---|
| 36 | @return: value of the model at x |
---|
| 37 | """ |
---|
| 38 | return self.operateOn.run(x) * self.other.run(x) |
---|
| 39 | |
---|
[3db3895] | 40 | def runXY(self, x=0): |
---|
| 41 | """ |
---|
| 42 | Evaluate each part of the component and sum the results |
---|
| 43 | @param x: input parameter |
---|
| 44 | @return: value of the model at x |
---|
| 45 | """ |
---|
| 46 | return self.operateOn.runXY(x) * self.other.runXY(x) |
---|
| 47 | |
---|
[ae3ce4e] | 48 | def setParam(self, name, value): |
---|
| 49 | """ |
---|
| 50 | Set the value of a model parameter |
---|
| 51 | @param name: name of parameter to set |
---|
| 52 | @param value: value to give the paramter |
---|
| 53 | """ |
---|
| 54 | return BaseComponent.setParamWithToken(self, name, |
---|
| 55 | value, 'mul', self.other) |
---|
| 56 | |
---|
| 57 | def getParam(self, name): |
---|
| 58 | """ |
---|
| 59 | Set the value of a model parameter |
---|
| 60 | @param name: name of the parameter |
---|
| 61 | @return: value of the parameter |
---|
| 62 | """ |
---|
| 63 | return BaseComponent.getParamWithToken(self, name, 'mul', self.other) |
---|
| 64 | |
---|
| 65 | def getParamList(self): |
---|
| 66 | """ Return a list of all available parameters for the model |
---|
| 67 | """ |
---|
| 68 | return BaseComponent.getParamListWithToken(self, 'mul', self.other) |
---|
| 69 | |
---|
| 70 | # End of file |
---|