Home | Trees | Indices | Help |
|
---|
|
1 """ 2 Provides various integration schemes and an abstract gradient class. 3 """ 4 5 from abc import ABCMeta, abstractmethod 6 7 from csb.statistics.samplers.mc import State, TrajectoryBuilder11 """ 12 Abstract integrator class. Subclasses implement different integration 13 schemes for solving deterministic equations of motion. 14 15 @param timestep: Integration timestep 16 @type timestep: float 17 18 @param gradient: Gradient of potential energy 19 @type gradient: L{AbstractGradient} 20 """ 21 22 __metaclass__ = ABCMeta 23 287930 """ 31 Integrates equations of motion starting from an initial state a certain 32 number of steps. 33 34 @param init_state: Initial state from which to start integration 35 @type init_state: L{State} 36 37 @param length: Nubmer of integration steps to be performed 38 @type length: int 39 40 @param return_trajectory: Return complete L{Trajectory} instead of the initial 41 and final states only (L{PropagationResult}). This reduces 42 performance. 43 @type return_trajectory: boolean 44 45 @rtype: L{AbstractPropagationResult} 46 """ 47 48 builder = TrajectoryBuilder.create(full=return_trajectory) 49 50 builder.add_initial_state(init_state) 51 state = init_state.clone() 52 53 for i in range(length - 1): 54 state = self.integrate_once(state, i) 55 builder.add_intermediate_state(state) 56 57 state = self.integrate_once(state, length - 1) 58 builder.add_final_state(state) 59 60 return builder.product61 62 @abstractmethod64 """ 65 Integrates one step starting from an initial state and an initial time 66 given by the product of the timestep and the current_step parameter. 67 The input C{state} is changed in place. 68 69 @param state: State which to evolve one integration step 70 @type state: L{State} 71 72 @param current_step: Current integration step 73 @type current_step: int 74 75 @return: the altered state 76 @rtype: L{State} 77 """ 78 pass81 """ 82 Leap Frog integration scheme implementation that calculates position and 83 momenta at equal times. Slower than FastLeapFrog, but intermediate points 84 in trajectories obtained using 85 LeapFrog.integrate(init_state, length, return_trajectoy=True) are physical. 86 """ 8710189 90 i = current_step 91 92 if i == 0: 93 self._oldgrad = self._gradient(state.position, 0.) 94 95 momentumhalf = state.momentum - 0.5 * self._timestep * self._oldgrad 96 state.position = state.position + self._timestep * momentumhalf 97 self._oldgrad = self._gradient(state.position, (i + 1) * self._timestep) 98 state.momentum = momentumhalf - 0.5 * self._timestep * self._oldgrad 99 100 return state103 """ 104 Leap Frog integration scheme implementation that calculates position and 105 momenta at unequal times by concatenating the momentum updates of two 106 successive integration steps. 107 WARNING: intermediate points in trajectories obtained by 108 FastLeapFrog.integrate(init_state, length, return_trajectories=True) 109 are NOT to be interpreted as phase-space trajectories, because 110 position and momenta are not given at equal times! In the initial and the 111 final state, positions and momenta are given at equal times. 112 """ 113152115 """ 116 Integrates equations of motion starting from an initial state a certain 117 number of steps. 118 119 @param init_state: Initial state from which to start integration 120 @type init_state: L{State} 121 122 @param length: Nubmer of integration steps to be performed 123 @type length: int 124 125 @param return_trajectory: Return complete L{Trajectory} instead of the initial 126 and final states only (L{PropagationResult}). This reduces 127 performance. 128 @type return_trajectory: boolean 129 130 @rtype: L{AbstractPropagationResult} 131 """ 132 133 builder = TrajectoryBuilder.create(full=return_trajectory) 134 135 builder.add_initial_state(init_state) 136 state = init_state.clone() 137 138 state.momentum = state.momentum - 0.5 * self._timestep * self._gradient(state.position, 0.) 139 140 for i in range(length): 141 state.position = state.position + self._timestep * state.momentum 142 if i != length - 1: 143 state.momentum = state.momentum - self._timestep * \ 144 self._gradient(state.position, (i + 1) * self._timestep) 145 builder.add_intermediate_state(state) 146 147 state.momentum = state.momentum - 0.5 * self._timestep * \ 148 self._gradient(state.position, length * self._timestep) 149 builder.add_final_state(state) 150 151 return builder.product154 """ 155 Velocity Verlet integration scheme implementation. 156 """ 157172159 160 i = current_step 161 162 if i == 0: 163 self._oldgrad = self._gradient(state.position, 0.) 164 165 state.position = state.position + self._timestep * state.momentum \ 166 - 0.5 * self._timestep ** 2 * self._oldgrad 167 newgrad = self._gradient(state.position, (i + 1) * self._timestep) 168 state.momentum = state.momentum - 0.5 * self._timestep * (self._oldgrad + newgrad) 169 self._oldgrad = newgrad 170 171 return state174 """ 175 Abstract gradient class. Implementations evaluate the gradient of an energy 176 function. 177 """ 178 179 __metaclass__ = ABCMeta 180 181 @abstractmethod210183 """ 184 Evaluates the gradient at position q and time t. 185 186 @param q: Position array 187 @type q: One-dimensional numpy array 188 189 @param t: Time 190 @type t: float 191 192 @rtype: numpy array 193 """ 194 pass195
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Jul 2 23:48:48 2012 | http://epydoc.sourceforge.net |