H Ondrej,

Le dimanche 25 avril 2010 à 16:10 -0700, Ondrej Certik a écrit :
> Hi Harold,
> 
> On Sun, Apr 25, 2010 at 3:52 AM, Harold E. <[email protected]> wrote:
> > Hi,
> >
> > I saw that a new modules for physics began to be implemented, and the
> > part which interested me was on the physical units: for a project I
> > tried to write my own classes, inspired by those in ScientificPython,
> > but evidently it was not compatible with sympy, and so I thought and
> > tried to inspired from the classes in sympycore, without successes.
> > But yet, with a better understanding of sympy, I read the recent
> > implementation and had few questions and observations: the actual way
> > is useful to make symbolic computations with units, but it is
> > convenient when we want to work with units, e.g. to convert a quantity
> > in one unit into another, or to take into account the dimension of
> > units.
> > So I was wondering me if it was not possible to merge actual and
> > ScientificPython approaches. For my project I tried several ways, the
> > latest was to create classes for the dimension (a tuple), the unit
> > symbol (like actual unit) and for the unit; the latest having a
> > symbol, a factor and a dimension — something like that (I still search
> > the best way to arrange).
> 
> Is this how ScientificPython does it?
> 
> http://dirac.cnrs-orleans.fr/ScientificPython/ScientificPythonManual/Scientific.Physics.PhysicalQuantities-module.html

Yes, ScientificPython has two classes: one which handles units and
another for quantities. The Unit class has some properties like a
dimension: e.g. for the meter has [1,0,0,0,0,0,0,0,0] and the joule
[2,1,-2,0,0,0,0,0,0], and so on. They have also a factor (1 for meter,
1000 for km…) and of course a name. They can also have an offset (to
symbolize degree Celsius for example). A quantity has a value and an
unit.
Several methods tests if units are compatible, converts them into
another… When operations are made between units, a new unit is created
from dimensions and factors.

> Our units are very simple, see sympy/physics/units.py, so anything
> more advanced is welcomed. If you get something working, let us know
> and we can review the code and merge it in, or help you improve it.
> 
> Ondrej
> 

I will try to make something good to submit it to you.

The first approach I had was to directly make operations when two units
where together, but it gave strange comportment (even if, written on
paper its more logic, it's not convenient for computing use, I think)
like
>>> m + m
m
>>> 1*m + 1*m
2*m
so I try another way.

I created a class Unit which have almost the same attributs as those in
ScientificPython, but also a base symbol (like m for all distances),
which is used when computations are made. It will have the methods to
convert units. This class does not inherit from another class, but the
class for the symbol is the same as those defined in the actual units.py
from sympy. I made also a short class for the Dimension.
The main problems after is how transform an object like Mul, Add…
(passed in argument) into a Quantity (I did not already read the
documentation for that), which have methods to change its units…

How can I show you the code? Should I create a new issue on tracker and
attach the code?

I had a problem with the code in sympy/physics/units.py (0.6.7 version
or svn): when I use the class Unit like it is defined, it works fine:
>>> m = Unit('meter', 'm')
>>> m
m
but if I rename it into UnitSymbol, I have:
>>> m = UnitSymbol('meter', 'm')
>>> m
UnitSymbol()

Do you know how I can fit that? I try to search into the code, but I did
not see anything which can help me.

Harold

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to