Re: [daetools-users] Howto: discrete signal?
Object-oriented equation-based modelling and optimisation software
Brought to you by:
ciroki
|
From: Dragan N. <dra...@gm...> - 2018-03-09 11:04:24
|
Hi Henk,
It is just a matter of sequence of calls in daetools: first the
daeModel-derived classes __init__ is called, then
SetUpParametersAndDomains, SetUpVariables and finally DeclareEquations.
Thus, you need to set a value of tau_jump parameter in
SetUpParametersAndDomains function, i.e.:
self.m.tau_jump.SetValue(2.0*s)
Also, you forgot self.tau.dt for Time equation (you set an initial
condition so I suppose you wanted it to be a differential variable):
eq = self.CreateEquation("Time", "Differential equation to
calculate the time elapsed in the process.")
eq.Residual = self.tau.dt() - 1
Have a look on the attached file with the changes I made.
So, I guess you try to test the functionality to have discrete events
triggered and variables updated with constants and parameter values.
That will work with no problems I think.
Perhaps it would be a good idea to create an API (functions and classes)
to wrap the functionality required for system dynamics. That API can
internally use the basic modelling concepts (parameters, variables,
discontinuous equations and OnCondition handlers etc.). I could check
the documentation for some of the popular software.
Cheers
Dragan
On 09/03/18 10:51, StUstD wrote:
> Hi Dragan:
>
> Thanks, that works! 'itau' is discretely incremented event with
> ON_CONDITION( Time()==itau, ..., eventTolerance=0.0 ).
>
> However,
>
> 1) I've not been able to eliminate a second equation: DAETools wants
> (understandably) an equal number of equations as variables...
>
> 2) Expanding the problem, I have no success in trying to discretely
> update 'tau' at the condition with a daeParameter. See file attached.
>
> Regards,
> Henk
>
>
>
> On Thu, Mar 8, 2018 at 5:19 PM, Dragan Nikolic <dra...@gm...
> <mailto:dra...@gm...>> wrote:
>
> Hi Henk,
>
> It's just a typo, the argument of ON_CONDITION function should be
> switchToStates not switchToState. It works well.then.
>
> Also, you do not need to add a separate differential equation. You
> can just set:
>
> def SetUpVariables(self):
> self.m.itau.AssignValue(0.0)
> as it is in the attached file. But, it depends what do you need
> itau for.
>
> Cheers
> Dragan
>
>
> On 08/03/18 14:34, StUstD wrote:
>
> Hi Dragan:
>
> Please find attached the modified "whats_the_time.py" example
> that includes and tests the discrete-time conditional you
> suggested.
>
> Find below the simulation error message I obtain. Anything
> wrong in my specification?
>
> Regards,
> -- Henk
>
> ***********************************************************************
>
> Version: 1.8.0
>
> Copyright: Dragan Nikolic, 2017
>
> Homepage: http://www.daetools.com
>
> @ @
>
> @ @@@@@ @@@@@ @@@@@ @@@@@ @@@@@ @ @@@@@
>
> @@@@@@ @ @ @ @ @ @ @ @ @ @
>
> @ @ @@@@@@ @@@@@@ @ @ @ @ @ @ @@@@@
>
> @ @ @ @ @ @ @ @ @ @ @ @
>
> @@@@@@ @@@@@@ @@@@@ @@@ @@@@@ @@@@@ @@@@ @@@@@
>
> ***********************************************************************
>
> DAE Tools is free software: you can redistribute it and/or modify
>
> it under the terms of the GNU General Public License version 3
>
> as published by the Free Software Foundation.
>
> DAE Tools is distributed in the hope that it will be useful,
>
> but WITHOUT ANY WARRANTY; without even the implied warranty of
>
> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>
> General Public License for more details.
>
> You should have received a copy of the GNU General Public License
>
> along with this program. If not, see
> <http://www.gnu.org/licenses>.
>
> ***********************************************************************
>
> Creating the system...
>
> File
> "/home/hjansen/workspace/gitspace/Contryx/projects/enterprise/CxSim/inst/python/3/lib/python3.6/site-packages/daetools-1.8.0-py3.6-linux-x86_64.egg/daetools/dae_simulator/simulator.py",
> line 276, in run
>
> self.simulation.Initialize(self.daesolver, self.datareporter,
> self.log)
>
> File
> "/home/hjansen/workspace/gitspace/Contryx/projects/exploration/00-TaE-Python/src/simulation/daetools/discrete_signal_trial/discrete_signal_01.py",
> line 146, in DeclareEquations
>
> eventTolerance = 0.00001)
>
> Python argument types in
>
> daeModel.ON_CONDITION(modTutorial, daeCondition)
>
> did not match C++ signature:
>
> ON_CONDITION(dae::core::daeModel {lvalue} self,
> dae::core::daeCondition condition, boost::python::list
> switchToStates=[], boost::python::list setVariableValues=[],
> boost::python::list triggerEvents=[], boost::python::list
> userDefinedActions=[], double eventTolerance=0.0)
>
>
>
> On Wed, Mar 7, 2018 at 2:49 PM, Dragan Nikolic
> <dra...@gm... <mailto:dra...@gm...>
> <mailto:dra...@gm... <mailto:dra...@gm...>>>
> wrote:
>
> Hi,
>
> Well, it is a bit difficult because of the way the
> equation-based
> systems are solved numerically but it might work.
>
> If you wish to change a model variable you can use
> daeModel.ON_CONDITION function (have a look on tutorials
> 5, 14).
> If iT is a model variable, you can put the following in the
> function DeclareEquations:
>
> self.ON_CONDITION(Time() > iT, switchToStates = [],
> setVariableValues = [iT,
> iT+1], #
> here you may need to use self.iT()
> triggerEvents = [],
> userDefinedActions = [])
>
> But, you need to be careful here: your condition Time() >
> iT will
> be triggered EVERY time step once the simulation time becomes
> greater than iT. However, you change it each time the
> condition is
> satisfied, so it might work. Please check and let me know,
> I am
> curious if it works or not.
>
> Cheers
> Dragan
>
>
>
> On 07/03/18 11:45, StUstD wrote:
>
> How is it possible to create a discrete-time signal,
> e.g. a
> counter (in pseudo code):
>
> initial Time = 0
> iT = 1 # counter
>
> if Time() > iT:
> iT += 1
> endif
>
> Thanks.
>
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the
> world's most
> engaging tech sites, Slashdot.org!
> http://sdm.link/slashdot
>
>
> _______________________________________________
> daetools-users mailing list
> dae...@li...
> <mailto:dae...@li...>
> <mailto:dae...@li...
> <mailto:dae...@li...>>
> https://lists.sourceforge.net/lists/listinfo/daetools-users
> <https://lists.sourceforge.net/lists/listinfo/daetools-users>
>
> <https://lists.sourceforge.net/lists/listinfo/daetools-users
> <https://lists.sourceforge.net/lists/listinfo/daetools-users>>
>
>
>
>
>
|