Making calls to adj_inc_timestep automatic when new time value is assigned to a special time constant

Registered by Martin Sandve Alnæs

A code with the pattern:

        # ... timesteps = list of time values

        t = Constant(timesteps[0], name="TIME")

        # ... initialization

        adj_inc_timestep(float(t))
        for timestep in xrange(1,len(timesteps)):
            t.assign(t, timesteps[timestep])

            # ... solve equations

            adj_start_timestep(float(t))

Could be written with less explicit annotation:

        # ... initialization, timesteps = list of time values

        t = Constant(timesteps[0], name="TIME")

        # ... initialization

        for timestep in xrange(1,len(timesteps)):
            t.assign(timesteps[timestep])

            # ... solve equations

If dolfin-adjoint gave special treatment to a Constant with a particular name,
e.g. "TIME", or subclassed Constant with TimeConstant class, following the
behavioural pattern of this code:

    def Time(t0=0.0):
        t = Constant(t0, name="TIME")
        t._assigned_to = False
        return t

    def assign_time(t, tvalue):
        t.assign(tvalue)
        if t._assigned_to:
                adj_inc_timestep(tvalue)
        else:
            t._assigned_to = True
            adj_start_timestep(tvalue)

        # ... initialization, timesteps = list of time values

        t = Time(t0=timesteps[0])

        # ... initialization

        for timestep in xrange(1,len(timesteps)):
            assign_time(t, timesteps[timestep])

            # ... solve equations

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.