def u_exact(self, t): """ Routine to compute the exact/initial trajectory at time t Args: t (float): current time Returns: dtype_u: exact/initial position and velocity """ assert t == 0.0, 'error, u_exact only works for the initial time t0=0' me = particles(self.init) me.pos.values[:, 0] = [0.0, 0.0, 0.0] me.pos.values[:, 1] = [-3.5025653, -3.8169847, -1.5507963] me.pos.values[:, 2] = [9.0755314, -3.0458353, -1.6483708] me.pos.values[:, 3] = [8.3101420, -16.2901086, -7.2521278] me.pos.values[:, 4] = [11.4707666, -25.7294829, -10.8169456] me.pos.values[:, 5] = [-15.5387357, -25.2225594, -3.1902382] me.vel.values[:, 0] = [0.0, 0.0, 0.0] me.vel.values[:, 1] = [0.00565429, -0.00412490, -0.00190589] me.vel.values[:, 2] = [0.00168318, 0.00483525, 0.00192462] me.vel.values[:, 3] = [0.00354178, 0.00137102, 0.00055029] me.vel.values[:, 4] = [0.00288930, 0.00114527, 0.00039677] me.vel.values[:, 5] = [0.00276725, -0.0017072, -0.00136504] me.m[0] = 1.00000597682 # Sun me.m[1] = 0.000954786104043 # Jupiter me.m[2] = 0.000285583733151 # Saturn me.m[3] = 0.0000437273164546 # Uranus me.m[4] = 0.0000517759138449 # Neptune me.m[5] = 1.0 / 130000000.0 # Pluto return me
def u_init(self): """ Routine to compute the starting values for the particles Returns: dtype_u: particle set filled with initial data """ u0 = self.params.u0 N = self.params.nparts u = particles((3, N)) if u0[2][0] is not 1 or u0[3][0] is not 1: raise ProblemError('so far only q = m = 1 is implemented') # set first particle to u0 u.pos.values[0, 0] = u0[0][0] u.pos.values[1, 0] = u0[0][1] u.pos.values[2, 0] = u0[0][2] u.vel.values[0, 0] = u0[1][0] u.vel.values[1, 0] = u0[1][1] u.vel.values[2, 0] = u0[1][2] u.q[0] = u0[2][0] u.m[0] = u0[3][0] # initialize random seed np.random.seed(N) comx = u.pos.values[0, 0] comy = u.pos.values[1, 0] comz = u.pos.values[2, 0] for n in range(1, N): # draw 3 random variables in [-1,1] to shift positions r = np.random.random_sample(3) - 1 u.pos.values[0, n] = r[0] + u0[0][0] u.pos.values[1, n] = r[1] + u0[0][1] u.pos.values[2, n] = r[2] + u0[0][2] # draw 3 random variables in [-5,5] to shift velocities r = np.random.random_sample(3) - 5 u.vel.values[0, n] = r[0] + u0[1][0] u.vel.values[1, n] = r[1] + u0[1][1] u.vel.values[2, n] = r[2] + u0[1][2] u.q[n] = u0[2][0] u.m[n] = u0[3][0] # gather positions to check center comx += u.pos.values[0, n] comy += u.pos.values[1, n] comz += u.pos.values[2, n] # print('Center of positions:',comx/N,comy/N,comz/N) return u
def u_exact(self, t): """ Routine to compute the exact trajectory at time t (only for single-particle setup) Args: t (float): current time Returns: dtype_u: particle type containing the exact position and velocity """ # some abbreviations wE = self.params.omega_E wB = self.params.omega_B N = self.params.nparts u0 = self.params.u0 if N != 1: raise ProblemError('u_exact is only valid for a single particle') u = particles((3, 1)) wbar = np.sqrt(2) * wE # position and velocity in z direction is easy to compute u.pos.values[2, 0] = u0[0][2] * np.cos( wbar * t) + u0[1][2] / wbar * np.sin(wbar * t) u.vel.values[2, 0] = -u0[0][2] * wbar * np.sin( wbar * t) + u0[1][2] * np.cos(wbar * t) # define temp. variables to compute complex position Op = 1 / 2 * (wB + np.sqrt(wB**2 - 4 * wE**2)) Om = 1 / 2 * (wB - np.sqrt(wB**2 - 4 * wE**2)) Rm = (Op * u0[0][0] + u0[1][1]) / (Op - Om) Rp = u0[0][0] - Rm Im = (Op * u0[0][1] - u0[1][0]) / (Op - Om) Ip = u0[0][1] - Im # compute position in complex notation w = np.complex(Rp, Ip) * np.exp(-np.complex(0, Op * t)) + np.complex( Rm, Im) * np.exp(-np.complex(0, Om * t)) # compute velocity as time derivative of the position dw = -1j * Op * np.complex(Rp, Ip) * \ np.exp(-np.complex(0, Op * t)) - 1j * Om * np.complex(Rm, Im) * np.exp(-np.complex(0, Om * t)) # get the appropriate real and imaginary parts u.pos.values[0, 0] = w.real u.vel.values[0, 0] = dw.real u.pos.values[1, 0] = w.imag u.vel.values[1, 0] = dw.imag return u
def u_exact(self, t): """ Routine to compute the exact/initial trajectory at time t Args: t (float): current time Returns: dtype_u: exact/initial position and velocity """ assert t == 0.0, 'error, u_exact only works for the initial time t0=0' me = particles(self.init) # initial positions and velocities taken from # https://www.aanda.org/articles/aa/full/2002/08/aa1405/aa1405.right.html me.pos.values[:, 0] = [0.0, 0.0, 0.0] me.pos.values[:, 1] = [-2.503321047836E-01, +1.873217481656E-01, +1.260230112145E-01] me.pos.values[:, 2] = [+1.747780055994E-02, -6.624210296743E-01, -2.991203277122E-01] me.pos.values[:, 3] = [-9.091916173950E-01, +3.592925969244E-01, +1.557729610506E-01] me.pos.values[:, 4] = [+1.203018828754E+00, +7.270712989688E-01, +3.009561427569E-01] me.pos.values[:, 5] = [+3.733076999471E+00, +3.052424824299E+00, +1.217426663570E+00] me.pos.values[:, 6] = [+6.164433062913E+00, +6.366775402981E+00, +2.364531109847E+00] me.pos.values[:, 7] = [+1.457964661868E+01, -1.236891078519E+01, -5.623617280033E+00] me.pos.values[:, 8] = [+1.695491139909E+01, -2.288713988623E+01, -9.789921035251E+00] me.pos.values[:, 9] = [-9.707098450131E+00, -2.804098175319E+01, -5.823808919246E+00] me.vel.values[:, 0] = [0.0, 0.0, 0.0] me.vel.values[:, 1] = [-2.438808424736E-02, -1.850224608274E-02, -7.353811537540E-03] me.vel.values[:, 2] = [+2.008547034175E-02, +8.365454832702E-04, -8.947888514893E-04] me.vel.values[:, 3] = [-7.085843239142E-03, -1.455634327653E-02, -6.310912842359E-03] me.vel.values[:, 4] = [-7.124453943885E-03, +1.166307407692E-02, +5.542098698449E-03] me.vel.values[:, 5] = [-5.086540617947E-03, +5.493643783389E-03, +2.478685100749E-03] me.vel.values[:, 6] = [-4.426823593779E-03, +3.394060157503E-03, +1.592261423092E-03] me.vel.values[:, 7] = [+2.647505630327E-03, +2.487457379099E-03, +1.052000252243E-03] me.vel.values[:, 8] = [+2.568651772461E-03, +1.681832388267E-03, +6.245613982833E-04] me.vel.values[:, 9] = [+3.034112963576E-03, -1.111317562971E-03, -1.261841468083E-03] # masses relative to the sun taken from # https://en.wikipedia.org/wiki/Planetary_mass#Values_from_the_DE405_ephemeris me.m[0] = 1.0 # Sun me.m[1] = 0.1660100 * 1E-06 # Mercury me.m[2] = 2.4478383 * 1E-06 # Venus me.m[3] = 3.0404326 * 1E-06 # Earth+Moon me.m[4] = 0.3227151 * 1E-06 # Mars me.m[5] = 954.79194 * 1E-06 # Jupiter me.m[6] = 285.88600 * 1E-06 # Saturn me.m[7] = 43.662440 * 1E-06 # Uranus me.m[8] = 51.513890 * 1E-06 # Neptune me.m[9] = 0.0073960 * 1E-06 # Pluto return me
def u_exact(self, t): """ Routine to compute the exact trajectory at time t Args: t (float): current time Returns: dtype_u: exact position and velocity """ me = particles(1) me.pos.values[:] = self.params.amp * np.cos(np.sqrt(self.params.k) * t + self.params.phase) me.vel.values[:] = -self.params.amp * np.sqrt(self.params.k) * np.sin(np.sqrt(self.params.k) * t + self.params.phase) return me
def restrict(self, F): """ Dummy restriction routine Args: F: the fine level data """ if isinstance(F, particles): G = particles(F) elif isinstance(F, fields): G = fields(F) else: raise TransferError("Unknown type of fine data, got %s" % type(F)) return G
def prolong(self, G): """ Dummy prolongation routine Args: G: the coarse level data """ if isinstance(G, particles): F = particles(G) elif isinstance(G, fields): F = fields(G) else: raise TransferError("Unknown type of coarse data, got %s" % type(G)) return F
def u_exact(self, t): """ Routine to compute the exact/initial trajectory at time t Args: t (float): current time Returns: dtype_u: exact/initial position and velocity """ assert t == 0.0, 'error, u_exact only works for the initial time t0=0' me = particles(self.init) for n in range(self.params.npart): me.pos.values[n] = np.sin(self.params.k * np.pi * n / (self.params.npart - 1)) me.vel.values[n] = 0.0 return me
def u_exact(self, t): """ Routine to compute the exact/initial trajectory at time t Args: t (float): current time Returns: dtype_u: exact/initial position and velocity """ assert t == 0.0, 'error, u_exact only works for the initial time t0=0' me = particles(2) q1 = 0.0 q2 = 0.2 p2 = 0.2 U0 = 0.5 * (q1 * q1 + q2 * q2) + q1 * q1 * q2 - q2 * q2 * q2 / 3.0 H0 = 0.125 me.pos.values[0] = q1 me.pos.values[1] = q2 me.vel.values[0] = np.sqrt(2.0 * (H0 - U0) - p2 * p2) me.vel.values[1] = p2 return me
def u_init(self): """ Initialization routine for the single particle Returns: particle type """ u0 = self.params.u0 # some abbreviations u = particles((3, 1)) u.pos.values[0, 0] = u0[0][0] u.pos.values[1, 0] = u0[0][1] u.pos.values[2, 0] = u0[0][2] u.vel.values[0, 0] = u0[1][0] u.vel.values[1, 0] = u0[1][1] u.vel.values[2, 0] = u0[1][2] u.q[:] = u0[2][0] u.m[:] = u0[3][0] return u
def check_datatypes_particles(init): from pySDC.implementations.datatype_classes.particles import particles from pySDC.implementations.datatype_classes.particles import acceleration p1 = particles(init) p2 = particles(p1) p5 = particles(init) p1.pos.values[:] = 1.0 p2.pos.values[:] = 2.0 p1.vel.values[:] = 10.0 p2.vel.values[:] = 20.0 p3 = p1 + p2 p4 = p1 - p2 p5.pos = 0.1 * p1.vel p6 = p1 p7 = abs(p1) a1 = acceleration(init) a2 = acceleration(a1) p8 = particles(p1) a1.values[:] = 100.0 a2.values[:] = 200.0 a3 = a1 + a2 p8.vel = 0.1 * a1 p8.pos = 0.1 * (0.1 * a1) assert isinstance(p3, type(p1)) assert isinstance(p4, type(p1)) assert isinstance(p5.pos, type(p1.pos)) assert isinstance(p6, type(p1)) assert isinstance(p7, float) assert isinstance(a2, type(a1)) assert isinstance(p8.pos, type(p1.pos)) assert isinstance(p8.vel, type(p1.vel)) assert isinstance(0.1 * 0.1 * a1, type(p1.vel)) assert p2 is not p1 assert p3 is not p1 assert p4 is not p1 assert p5 is not p1 assert p6 is p1 assert a2 is not a1 assert a3 is not a1 assert np.shape(p3.pos.values) == np.shape(p1.pos.values) assert np.shape(p4.pos.values) == np.shape(p1.pos.values) assert np.shape(p3.vel.values) == np.shape(p1.vel.values) assert np.shape(p4.vel.values) == np.shape(p1.vel.values) assert np.shape(a2.values) == np.shape(a1.values) assert np.all(p3.pos.values == 3.0) assert np.all(p4.pos.values == -1.0) assert np.all(p3.vel.values == 30.0) assert np.all(p4.vel.values == -10.0) assert np.all(p5.pos.values == 1.0) assert p7 >= 0 assert np.all(p8.pos.values == 1.0) assert np.all(p8.vel.values == 10.0) assert np.all(a3.values == 300.0)