Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Suggestions for Maintaining "Object" State?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78399] Re: Suggestions for Maintaining "Object" State?
  • From: "Carey Sublette" <careysub at earthling.net>
  • Date: Sat, 30 Jun 2007 06:08:47 -0400 (EDT)
  • References: <f5vsk1$l46$1@smc.vnet.net> <f62kka$bv1$1@smc.vnet.net>

Thanks to all for replying!

I have combined the replies so that I can take care of responding with one 
go.

"dh" <dh at metrohm.ch> wrote in message news:f602rb$sh9$1 at smc.vnet.net...
>
>
> Hi Carey,
>
> you could try to put all the states into a function. E.g.:
>
> assume 2 objects a and b:
>
> a={1,2};
>
> b={4,3,2,1};
>
> states[a]=a;
>
> states[b]=b;
>
> states[x] will then return the state of x.
>
> hope this helps, Daniel

Thanks Daniel, this got me part of the way there. Hannes, below, gave built 
on this idea for a more complete solution approach.


> In version 6 there is a very interesting tutorial that you can see by 
> typing
> tutorial/AdvancedDynamicFunctionality into the Documentation Center 
> window.
> Local variables defined within DynamicModule have their states preserved,
> because they are stored (in a hidden way) in the output cell created by
> DynamicModule. Although I haven't yet used this behaviour to do 
> simulations
> of the sort that you describe, it looks to me as if DynamicModule may well
> give you the functionality you want.
>
> Steve Luttrell
> West Malvern, UK

Hi Steve: I looked into this, but it only seems designed to support UI 
functions. It holds evaluations, permanently it seems, if there is no UI 
component present, and since the state is kept in the front end, not the 
kernel, it suggests performance would be not so great. I fiddled with it 
awhile, but could not get it to do anything useful.



"Hannes Kessler" <HannesKessler at hushmail.com> wrote in message 
news:f62kka$bv1$1 at smc.vnet.net...
> Hello Carey,
>
> one possibility you could use is an object-oriented approach what you
> perhaps have in mind with "using UpValues or Tags to assign object
> state to symbols". Here are two links where you can download packages
> and examples:
>
> http://library.wolfram.com/infocenter/Conferences/5773/
> http://library.wolfram.com/infocenter/Articles/3243/
>


Thanks Hannes:!

You fleshed out the ideas I was working towards! The techniques you showed 
work great!

Roman Maeder's package looks impressive. It is a bit much to bit off right 
now, but I'll have to study it.

For what it worth, here is the toy problem I implemented using this 
approach. It has an "ice" object that keeps track of its enthalpy, and can 
be examined for its temperature and fraction that is melted.
In[142]:= ice[mP] = 273;
ice[CpL] = 4.18;
ice[CpS] = 2.114;
ice[heatOfFusion] = 334;
ice[hMelt] = ice[mP]*ice[CpS];
ice[hAllMelt] = ice[hMelt] + ice[heatOfFusion];
ice[initialTemp_, initialMass_] := Module[{thisIce},
mass[thisIce] = initialMass;
H[thisIce] = (initialTemp + ice[mP])*ice[CpS]*initialMass // N;
thisIce
]
In[149]:=
changeEnergy[i_, heatJ_] := H[i] = H[i] + heatJ;
getState[i_] := (h = H[i]/mass[i];
If[h <= ice[hMelt], {(h/ice[CpS]) - ice[mP], 0},
If[h >= ice[hAllMelt], {ice[mP] + (h - ice[hAllMelt] )/ice[CpL],
1}, {ice[mP], (h - ice[hMelt])/ice[heatOfFusion]}]]);

In[151]:= iceCube = ice[-50, 1]
H[iceCube]
mass[iceCube]
getState[iceCube]
changeEnergy[iceCube, 200];
H[iceCube]
getState[iceCube]
Out[151]= thisIce$4308
Out[152]= 471.422
Out[153]= 1
Out[154]= {-50., 0}
Out[156]= 671.422
Out[157]= {273, 0.282335}



  • Prev by Date: Re: Solving a Integral
  • Next by Date: Re: Solving a Integral
  • Previous by thread: Re: Suggestions for Maintaining "Object" State?
  • Next by thread: Re: Suggestions for Maintaining "Object" State?