def dirichlet(pair):
    """ Calculate dirichlet between 2D and 3D triangle pair.


    Arguments:
        pair: This is a numpy array with pairs of 3d and 2d triangles

    Returns:
        dirichlet: returns the dirichlet energy between pair of tris
    """

    # Assign values in triangle to vertices
    fv1 = np.array(pair["2D"][0])
    fv2 = np.array(pair["2D"][1])
    fv3 = np.array(pair["2D"][2])
    v1 = pair["3D"][0]
    v2 = pair["3D"][1]
    v3 = pair["3D"][2]

    # Calc theta1, theta2, theta3
    theta1 = calc_theta(v3 - v1, v3 - v2)
    theta2 = calc_theta(v2 - v1, v2 - v3)
    theta3 = calc_theta(v1 - v3, v1 - v2)

    # Calc normalized euclidian vectors from points
    dpart1 = magnitude(fv1 - fv2)**2
    dpart2 = magnitude(fv1 - fv3)**2
    dpart3 = magnitude(fv2 - fv3)**2

    # Calc dirichlet
    dirichlet = mpmath.cot(theta3) * dpart1 + \
                mpmath.cot(theta2) * dpart2 + \
                mpmath.cot(theta1) * dpart3

    return (dirichlet)
Пример #2
0
    def calculateInverseProblem(self):
        try :
            phi1 = math.radians(ast.literal_eval(self.ui.lineEdit_389.text()) + ast.literal_eval(
            self.ui.lineEdit_390.text()) / 60 + ast.literal_eval(self.ui.lineEdit_387.text()) / 3600)
            lambda1 = math.radians(ast.literal_eval(self.ui.lineEdit_391.text()) + ast.literal_eval(
            self.ui.lineEdit_386.text()) / 60 + ast.literal_eval(self.ui.lineEdit_388.text()) / 3600)
            phi2 = math.radians(ast.literal_eval(self.ui.lineEdit_402.text()) + ast.literal_eval(
            self.ui.lineEdit_400.text()) / 60 + ast.literal_eval(self.ui.lineEdit_403.text()) / 3600)
            lambda2 = math.radians(ast.literal_eval(self.ui.lineEdit_399.text()) + ast.literal_eval(
            self.ui.lineEdit_404.text()) / 60 + ast.literal_eval(self.ui.lineEdit_401.text()) / 3600)

            a = 6378249.2
            b= 6356515
            R = (2*a+b)/3

            deltaLambda = lambda2 - lambda1
            distanceD12 = math.acos( (math.sin(phi1)) * (math.sin(phi2)) + (math.cos(phi1)) * (math.cos(phi2)) * (math.cos(deltaLambda) ) )
            distanceD12 = R * distanceD12
            azimutDepart = math.degrees( mpmath.acot(
                ( ( (math.tan(phi2)) * math.cos(phi1) ) / math.sin(deltaLambda)) -
            ((math.sin(phi1)) * (mpmath.cot(deltaLambda))) ) )
            azimutArrive = math.degrees(  mpmath.acot( - ( ( (math.tan(phi1)) * math.cos(phi2) ) / (math.sin(deltaLambda)) -
            ( (math.sin(phi2)) * (mpmath.cot(deltaLambda) ) ) ) ) )
            azimutDepart = UIFunctions.degdecimal2dms(azimutDepart)
            azimutArrive = UIFunctions.degdecimal2dms(azimutArrive)
            self.ui.lineEdit_393.setText(str("%.4f" % distanceD12))
            self.ui.lineEdit_395.setText(str("%.f" % azimutDepart[0]))
            self.ui.lineEdit_392.setText(str("%.f" % azimutDepart[1]))
            self.ui.lineEdit_394.setText(str("%.4f" % azimutDepart[2]))
            self.ui.lineEdit_398.setText(str("%.f" % azimutArrive[0]))
            self.ui.lineEdit_396.setText(str("%.f" % azimutArrive[1]))
            self.ui.lineEdit_397.setText(str("%.4f" % azimutArrive[2]))
        except Exception :
            UIFunctions.errorMsg(self,"Erreur\nressayer une autre fois ")
Пример #3
0
def Der_Phi_Phi_Basis_Fn(M_Coef,N_Coef, Theta, Phi): # M_Coef < 0 Corresonds to Z^|M|_N

	Der_Phi_Phi_Val = 0	
	
	if(M_Coef < 0):

		m_sph = -1*M_Coef 
		Der_Phi_Phi_Val += m_sph*(m_sph*(mpmath.cot(Phi)**2) - (mpmath.csc(Phi)**2))*sph_harm(m_sph, N_Coef, Theta, Phi).imag

		if(m_sph < N_Coef):
			Der_Phi_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef+m_sph+1))*(2*m_sph + 1)*mpmath.cot(Phi)*(((e**(-1j*Theta))*sph_harm(m_sph+1, N_Coef, Theta, Phi))).imag

		if(m_sph < (N_Coef -1) ):
			Der_Phi_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef-m_sph-1)*(N_Coef+m_sph+1)*(N_Coef+m_sph+2))*(((e**(-2j*Theta))*sph_harm(m_sph+2, N_Coef, Theta, Phi))).imag

	else: # M_Coef >= 0	

		m_sph = M_Coef
		Der_Phi_Phi_Val +=  m_sph*(m_sph*(mpmath.cot(Phi)**2) - (mpmath.csc(Phi)**2))*sph_harm(m_sph, N_Coef, Theta, Phi).real

		if(m_sph < N_Coef):
			Der_Phi_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef+m_sph+1))*(2*m_sph + 1)*mpmath.cot(Phi)*(((e**(-1j*Theta))*sph_harm(m_sph+1, N_Coef, Theta, Phi))).real
		if(m_sph < (N_Coef -1) ):
			Der_Phi_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef-m_sph-1)*(N_Coef+m_sph+1)*(N_Coef+m_sph+2))*(((e**(-2j*Theta))*sph_harm(m_sph+2, N_Coef, Theta, Phi))).real

	return Der_Phi_Phi_Val
Пример #4
0
def Der_Phi_Basis_Fn(M_Coef,N_Coef, Theta, Phi): # M_Coef < 0 Corresonds to Z^|M|_N

	Der_Phi_Val = []

        # For Scalar Case, we use usual vectorization:
	if(isscalar(Theta)):
		#COPIED FROM SPH_DER_PHI_FN
		Der_Phi_Val = 0	

		if(M_Coef == 0): #No Cotangent terms:
			if(N_Coef > 0):
				return sqrt((N_Coef)*(N_Coef+1))*(((e**(-1j*Theta))*sph_harm(1, N_Coef, Theta, Phi))).real
			else: 
				return 0 #d_phi Y^0_0 = 0

		elif(M_Coef < 0):

			m_sph = -1*M_Coef 
			Der_Phi_Val += (m_sph*mpmath.cot(Phi))*sph_harm(m_sph, N_Coef, Theta, Phi).imag

			if(m_sph < N_Coef):
				Der_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef+m_sph+1))*(((e**(-1j*Theta))*sph_harm(m_sph+1, N_Coef, Theta, Phi))).imag

		else: # M_Coef >= 0	

			m_sph = M_Coef
			Der_Phi_Val += (m_sph*mpmath.cot(Phi))*sph_harm(m_sph, N_Coef, Theta, Phi).real	

			if(m_sph < N_Coef):		
				Der_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef+m_sph+1))*(((e**(-1j*Theta))*sph_harm(m_sph+1, N_Coef, Theta, Phi))).real
	
	else: # array input case:

		#COPIED FROM SPH_DER_PHI_FN
		Der_Phi_Val = np.zeros_like(Theta)

		if(M_Coef == 0): #No Cotangent terms:
			if(N_Coef > 0):
				return sqrt((N_Coef)*(N_Coef+1))*(((np.exp(-1j*Theta))*sph_harm(1, N_Coef, Theta, Phi))).real
			else: 
				return 0 #d_phi Y^0_0 = 0

		elif(M_Coef < 0):

			m_sph = -1*M_Coef 
			Der_Phi_Val += (m_sph*(1./np.tan(Phi)))*sph_harm(m_sph, N_Coef, Theta, Phi).imag

			if(m_sph < N_Coef):
				Der_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef+m_sph+1))*(((np.exp(-1j*Theta))*sph_harm(m_sph+1, N_Coef, Theta, Phi))).imag

		else: # M_Coef >= 0	

			m_sph = M_Coef
			Der_Phi_Val += (m_sph*(1./np.tan(Phi)))*sph_harm(m_sph, N_Coef, Theta, Phi).real	

			if(m_sph < N_Coef):		
				Der_Phi_Val += sqrt((N_Coef-m_sph)*(N_Coef+m_sph+1))*(((np.exp(-1j*Theta))*sph_harm(m_sph+1, N_Coef, Theta, Phi))).real				

	return Der_Phi_Val
Пример #5
0
def CurvePoints(xt, yt, xc, yc, Bte, Yle, Ate, dzte, zte, rle, b8, b0, b2, b15,
                b17):
    # Calculation of bezier control points 3434 parametrization
    # Leading edge thickness curve [LET]
    # LET : Matrix 4 columns [points] by 2 rows [x, y] of bezier points
    LET = np.zeros((2, 4))
    LET[0, 2] = -3 * b8**2 / (2 * rle)
    LET[0, 3] = xt
    LET[1, 1] = b8
    LET[1, 2] = yt
    LET[1, 3] = yt

    # Leading edge camber curve [LEC]
    # LEC: Matrix 4 columns [points] by 2 rows [x, y] of bezier points
    LEC = np.zeros((2, 4))
    LEC[0, 1] = b0
    LEC[0, 2] = b2
    LEC[0, 3] = xc
    LEC[1, 1] = b0 * m.tan(Yle)
    LEC[1, 2] = yc
    LEC[1, 3] = yc

    # Trailing edge thickness curve [TET]
    # TET: Matrix 5 columns [points] by 2 rows [x, y] of bezier points
    TET = np.zeros((2, 5))
    TET[0, 0] = xt
    TET[0, 1] = (7 * xt + 9 * b8**2 / (2 * rle)) / 4
    TET[0, 2] = 3 * xt - 5 * LET[0, 2] / 2
    TET[0, 3] = b15
    TET[0, 4] = 1
    TET[1, 0] = yt
    TET[1, 1] = yt
    TET[1, 2] = (yt + b8) / 2
    TET[1, 3] = dzte + (1 - b15) * m.tan(Bte)
    TET[1, 4] = dzte

    # Trailing edge camber curve [TEC]
    # TEC: Matrix 5 columns [points] by 2 rows [x, y] of bezier points
    TEC = np.zeros((2, 5))
    TEC[0, 0] = xc
    TEC[0, 1] = (3 * xc - yc * mp.cot(Yle)) / 2
    TEC[0, 2] = (-8 * yc * mp.cot(Yle) + 13 * xc) / 6
    TEC[0, 3] = b17
    TEC[0, 4] = 1
    TEC[1, 0] = yc
    TEC[1, 1] = yc
    TEC[1, 2] = 5 * yc / 6
    TEC[1, 3] = zte + (1 - b17) * m.tan(Ate)
    TEC[1, 4] = zte

    return LET, LEC, TET, TEC
Пример #6
0
def fuckin_freud(l, w, R, beta, dims):

    a, b, c, d = dims

    theta_input = float(atan(l / (R - w / 2)))
    theta_output_ackerman = float(acot(cot(theta_input) + w / l))

    def freudenstein_eq(theta_input):

        theta_input_freud = (pi / 2) - beta - theta_input

        J1 = d / a
        J2 = d / c
        J3 = (a**2 - b**2 + c**2 + d**2) / (2 * a * c)

        A = J3 - J1 + (1 - J2) * cos(theta_input_freud)
        B = -2 * sin(theta_input_freud)
        C = J1 + J3 - (1 + J2) * cos(theta_input_freud)

        theta_output_freud = float(2 * atan(
            (-B - sqrt(B**2 - 4 * A * C)) / (2 * A)))

        return (pi / 2) + beta - theta_output_freud

    theta_output_freud = freudenstein_eq(theta_input)
    error = (theta_output_freud - theta_output_ackerman)

    return error, theta_input, theta_output_ackerman, theta_output_freud
Пример #7
0
def cos_gamma(_a: float, incl: float, tol=10e-5) -> float:
    """Calculate the cos of the angle gamma"""
    if abs(incl) < tol:
        return 0
    else:
        return mpmath.cos(_a) / mpmath.sqrt(
            mpmath.cos(_a)**2 + mpmath.cot(incl)**2)  # real
def BMEquation(gamma, mach_1, beta):
    bm_equation = ""
    if beta > 0:
        bm_equation = (
            2 * cot(beta) * ((pow(mach_1, 2) * pow(sin(beta), 2) - 1) / (pow(mach_1, 2) * (gamma + cos(2 * beta)) + 2))
        )
    return bm_equation
Пример #9
0
def test_gauss_digamma_theorem():
    pi = mpmath.pi
    r = 3
    m = 5
    y = (
        -mpmath.euler - mpmath.log(2 * m) - pi / 2 * mpmath.cot(r * pi / m) +
        2 * sum(
            mpmath.cos(2 * pi * n * r / m) * mpmath.log(mpmath.sin(pi * n / m))
            for n in range(1, (m - 1) // 2 + 1)))
    x = digammainv(y)
    assert mpmath.almosteq(x, mpmath.mpf(r) / m)
Пример #10
0
def getAntiprismSurfaceArea( n, k ):
    if real( n ) < 3:
        raise ValueError( 'the number of sides of the prism cannot be less than 3,' )

    if not isinstance( k, RPNMeasurement ):
        return getAntiprismSurfaceArea( n, RPNMeasurement( real( k ), 'meter' ) )

    if k.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'antiprism_area\' argument 2 must be a length' )

    result = getProduct( [ fdiv( n, 2 ), fadd( cot( fdiv( pi, n ) ), sqrt( 3 ) ), getPower( k, 2 ) ] )
    return result.convert( 'meter^2' )
Пример #11
0
	def get_coords(self, x, y):
		
		val = math.pi/4 + y/2

		if round(val,4) == 0.0000:
			val = 0.00001
		elif round(val, 4) >= 1.5708:
			val = 1.5707
		elif round(val, 4) < 0:
			return (-10000, -10000)
		
		r = self.F * math.pow( mpmath.cot(val) , self.n)
		new_x = r * math.sin(self.n*x)	
		new_y = - r * math.cos(self.n * x)					
		
		return 80*new_x, 80*new_y
Пример #12
0
def getPrismVolume( n, k, h ):
    if real( n ) < 3:
        raise ValueError( 'the number of sides of the prism cannot be less than 3,' )

    if not isinstance( k, RPNMeasurement ):
        return getPrismVolume( n, RPNMeasurement( real( k ), 'meter' ), h )

    if not isinstance( h, RPNMeasurement ):
        return getPrismVolume( n, k, RPNMeasurement( real( h ), 'meter' ) )

    if k.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'prism_volume\' argument 2 must be a length' )

    if h.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'prism_volume\' argument 3 must be a length' )

    return getProduct( [ fdiv( n, 4 ), h, getPower( k, 2 ), cot( fdiv( pi, n ) ) ] ).convert( 'meter^3' )
Пример #13
0
 def zeta(self, z):
     # A+S 18.10.
     from mpmath import pi, jtheta, exp, mpc, cot, sqrt
     Delta = self.Delta
     e1, _, _ = self.__roots
     om = self.__periods[0] / 2
     omp = self.__periods[1] / 2
     if self.__ng3:
         z = mpc(0, 1) * z
     if Delta > 0:
         tau = omp / om
         # NOTE: here q has to be real.
         q = (exp(mpc(0, 1) * pi() * tau)).real
         eta = -(pi()**2 * jtheta(n=1, z=0, q=q, derivative=3)) / (
             12 * om * jtheta(n=1, z=0, q=q, derivative=1))
         v = (pi() * z) / (2 * om)
         retval = (eta * z) / om + (pi() *
                                    jtheta(n=1, z=v, q=q, derivative=1)) / (
                                        2 * om * jtheta(n=1, z=v, q=q))
     elif Delta < 0:
         om2 = om + omp
         om2p = omp - om
         tau2 = om2p / (2 * om2)
         # NOTE: here q will be pure imaginary.
         q = mpc(0, (mpc(0, 1) * exp(mpc(0, 1) * pi() * tau2)).imag)
         eta2 = -(pi()**2 * jtheta(n=1, z=0, q=q, derivative=3)) / (
             12 * om2 * jtheta(n=1, z=0, q=q, derivative=1))
         v = (pi() * z) / (2 * om2)
         retval = (eta2 * z) / om2 + (pi() * jtheta(
             n=1, z=v, q=q, derivative=1)) / (2 * om2 *
                                              jtheta(n=1, z=v, q=q))
     else:
         g2, g3 = self.__invariants
         if g2 == 0 and g3 == 0:
             retval = 1 / z
         else:
             c = e1 / 2
             A = sqrt(3 * c)
             retval = c * z + A * cot(A * z)
     if self.__ng3:
         return mpc(0, 1) * retval
     else:
         return retval
Пример #14
0
    def CTG(self, a):
        x = Argument(int32_t)
        y = Argument(int32_t)

        try:
            with Function("Cotangent", (x, y), int32_t) as asm_ctg:
                reg_x = GeneralPurposeRegister32()

                LOAD.ARGUMENT(reg_x, x)

                CTG(reg_x)

                RETURN(reg_x)

            code_ctg = asm_ctg.finalize(abi.detect()).encode().load()
        except:
            code_ctg = round(mpmath.cot(a), 4)
            return (code_ctg)

        return (code_ctg(a))
Пример #15
0
def move(headX, faceWidth):

    #Rotate robot
    moveTime = abs(6000 - headX) / ANGULAR_VELOCITY

    if headX < 6000:
        moveRight(moveTime)
    elif headX > 6000:
        moveLeft(moveTime)

    #Move robot
    dist = mpmath.cot(mpmath.radians(62.2 * (w / 640) / 2))
    moveTime = abs(dist - faceDistTarget) * VELOCITY

    if dist < faceDistTarget:
        moveBack(moveTime)
    elif dist > faceDistTarget:
        moveForward(moveTime)

    client.sendData("Are you Sarah Connor?")
Пример #16
0
    def calculateDirecteProblem(self):
        try:
            a = 6378249.2
            b = 6356515
            R = (2 * a + b) / 3

            phi1 = math.radians(ast.literal_eval(self.ui.lineEdit_184.text()) + ast.literal_eval(
                self.ui.lineEdit_185.text()) / 60 + ast.literal_eval(self.ui.lineEdit_182.text()) / 3600)
            lambda1 = math.radians(ast.literal_eval(self.ui.lineEdit_186.text()) + ast.literal_eval(
                self.ui.lineEdit_181.text()) / 60 + ast.literal_eval(self.ui.lineEdit_183.text()) / 3600)
            azimut = math.radians(ast.literal_eval(self.ui.lineEdit_190.text()) + ast.literal_eval(
                self.ui.lineEdit_187.text()) / 60 + ast.literal_eval(self.ui.lineEdit_189.text()) / 3600)
            distanceD12 = (ast.literal_eval(self.ui.lineEdit_188.text()))/R

            phi2 = math.degrees(math.asin(
                (math.sin(phi1)) * (math.cos(distanceD12)) + (math.cos(phi1)) * (math.sin(distanceD12)) * (
                    math.cos(azimut))))
            lambda2 =(math.degrees(lambda1)) + (math.degrees(mpmath.acot(((mpmath.cot(distanceD12)) * math.sin(
                ((math.pi / 2) - phi1)) - (math.cos((math.pi / 2) - phi1)) * math.cos(azimut)) * (1 / (math.sin(azimut))))))
            azimutRetour = math.degrees(mpmath.acot(
                ( (math.cos(distanceD12)) * (math.cos(azimut)) - (math.tan(phi1)) * (math.sin(distanceD12)) ) * (1 / (math.sin(azimut))) ))
            phi2 = UIFunctions.degdecimal2dms(phi2)
            lambda2 = UIFunctions.degdecimal2dms(lambda2)
            azimutRetour = UIFunctions.degdecimal2dms(azimutRetour)
            self.ui.lineEdit_192.setText(str("%.f" % phi2[0]))
            self.ui.lineEdit_198.setText(str("%.f" % phi2[1]))
            self.ui.lineEdit_191.setText(str("%.4f" % phi2[2]))

            self.ui.lineEdit_197.setText(str("%.f" % lambda2[0]))
            self.ui.lineEdit_199.setText(str("%.f" % lambda2[1]))
            self.ui.lineEdit_194.setText(str("%.4f" % lambda2[2]))

            self.ui.lineEdit_195.setText(str("%.f" % azimutRetour[0]))
            self.ui.lineEdit_196.setText(str("%.f" % azimutRetour[1]))
            self.ui.lineEdit_193.setText(str("%.4f" % azimutRetour[2]))
        except Exception :
            UIFunctions.errorMsg(self,"Erreur\nressayer une autre fois ")
	def zeta(self,z):
		# A+S 18.10.
		from mpmath import pi, jtheta, exp, mpc, cot, sqrt
		Delta = self.Delta
		e1, _, _ = self.__roots
		om = self.__periods[0] / 2
		omp = self.__periods[1] / 2
		if self.__ng3:
			z = mpc(0,1) * z
		if Delta > 0:
			tau = omp / om
			# NOTE: here q has to be real.
			q = (exp(mpc(0,1) * pi() * tau)).real
			eta = -(pi()**2 * jtheta(n=1,z=0,q=q,derivative=3)) / (12 * om * jtheta(n=1,z=0,q=q,derivative=1))
			v = (pi() * z) / (2 * om)
			retval = (eta * z) / om + (pi() * jtheta(n=1,z=v,q=q,derivative=1)) / (2 * om * jtheta(n=1,z=v,q=q))
		elif Delta < 0:
			om2 = om + omp
			om2p = omp - om
			tau2 = om2p / (2 * om2)
			# NOTE: here q will be pure imaginary.
			q = mpc(0,(mpc(0,1) * exp(mpc(0,1) * pi() * tau2)).imag)
			eta2 = -(pi()**2 * jtheta(n=1,z=0,q=q,derivative=3)) / (12 * om2 * jtheta(n=1,z=0,q=q,derivative=1))
			v = (pi() * z) / (2 * om2)
			retval = (eta2 * z) / om2 + (pi() * jtheta(n=1,z=v,q=q,derivative=1)) / (2 * om2 * jtheta(n=1,z=v,q=q))
		else:
			g2, g3 = self.__invariants
			if g2 == 0 and g3 == 0:
				retval = 1 / z
			else:
				c = e1 / 2
				A = sqrt(3 * c)
				retval = c*z + A * cot(A*z)
		if self.__ng3:
			return mpc(0,1) * retval
		else:
			return retval
Пример #18
0
def getAntiprismSurfaceAreaOperator(n, k):
    result = getProduct(
        [fdiv(n, 2),
         fadd(cot(fdiv(pi, n)), sqrt(3)),
         getPower(k, 2)])
    return result.convert('meter^2')
Пример #19
0
def getPrismSurfaceAreaOperator(n, k, h):
    result = add(getProduct([fdiv(n, 2),
                             getPower(k, 2),
                             cot(fdiv(pi, n))]), getProduct([n, k, h]))
    return result.convert('meter^2')
Пример #20
0
def calc_buff(faces, num_vert, coordinates, d, wDX):
    """
    Calculates buffer distance between edge of DX tile and center of vertex.

    Parameters
    ----------
    faces : list
        Fx2 cell matrix, where F is the number of faces.
        The first column details how many vertices the face has
        The second column details the vertex IDs of the face
    num_vert : int
        number of vertices, V
    coordinates : numpy.ndarray
        Vx3 matrix of spatial coordinates of vertices,
        V = number of vertices
    d : float
        distance between two nucleotides, in angstroms
    wDX : int
        width of DX tile, in angstroms

    Returns
    -------
    buff_nt
        distance, in nucleotides, between edge of DX arm and vertex coordinate
    """

    vert_angles = [[] for i in range(num_vert)]

    # For each face
    for curr_face in faces:
        face_coords = coordinates[curr_face]

        # for each vert
        for face_vert_ID in range(len(curr_face)):

            center_vert = curr_face[face_vert_ID]
            center_coords = face_coords[face_vert_ID]

            if face_vert_ID == 0:  # if first
                prev_coords = face_coords[-1]
            else:
                prev_coords = face_coords[face_vert_ID - 1]

            if face_vert_ID == len(curr_face) - 1:  # if last
                next_coords = face_coords[0]
            else:
                next_coords = face_coords[face_vert_ID + 1]

            a_vec = np.array(prev_coords - center_coords)
            b_vec = np.array(next_coords - center_coords)

            angle = math.atan2(np.linalg.norm(np.cross(a_vec, b_vec)),
                               np.dot(a_vec, b_vec))

            vert_angles[center_vert] += [angle]

    buff_nt = [0] * num_vert

    # For creating no discontinuities
    for vert_ID in range(num_vert):
        sum_of_angles = sum(vert_angles[vert_ID])
        theta_max = max(vert_angles[vert_ID])
        theta_P_max = theta_max * (2. * np.pi / sum_of_angles)
        r = float(wDX / 2. * mpmath.cot(theta_P_max / 2.))

        if sum_of_angles <= 2. * np.pi:
            s = r * (2. * np.pi / sum_of_angles)
        else:
            s = r

        buff_nt[vert_ID] = int(np.ceil(s / d))

    return buff_nt
Пример #21
0
def multiscale_X(fr, sig1, L1, sig2, L2, sig3, L3, thi, er):

    er = er.conjugate()

    sig1 = sig1 * 100  # change from m to cm scale
    L1 = L1 * 100

    sig2 = sig2 * 100  # change from m to cm scale
    L2 = L2 * 100

    sig3 = sig3 * 100  # change from m to cm scale
    L3 = L3 * 100

    sig12 = sig1**2
    sig22 = sig2**2
    sig32 = sig3**2

    sigs2 = sig12 + sig22 + sig32

    # - fr: frequency in GHz
    # - sig: rms height of surface in cm
    # - L: correlation length of surface in cm
    # - theta_d: incidence angle in degrees
    # - er: relative permittivity
    # - sp: type of surface correlation function

    error = 1.0e8

    k = 2 * math.pi * fr / 30  # wavenumber in free space.Speed of light is in cm / sec
    theta = thi * math.pi / 180  # transform to radian

    ks = k * math.sqrt(sigs2)  # roughness parameter
    kl = k * L

    ks2 = ks * ks
    kl2 = kl**2

    cs = math.cos(theta)
    s = math.sin(theta + 0.001)

    s2 = s**2

    # -- calculation of reflection coefficints
    rt = sqrt(er - s2)

    rv = (er * cs - rt) / (er * cs + rt)

    rh = (cs - rt) / (cs + rt)

    rvh = (rv - rh) / 2

    # print(rt, rv, rh, rvh)
    # exit()

    # -- rms slope values
    sig_l = sig / L

    wn = multi_roughness_spectrum(sig12, sig22, sig32, sigs2, L1, L2, L3, k, s,
                                  Ts)

    rss = sqrt(2) / sigs2 * (sig12 * sig1 / L1 + sig22 * sig2 / L2 +
                             sig32 * sig3 / L3)

    # --- Selecting number of spectral components of the surface roughness
    # if auto == 0:

    n_spec = 15  # numberofterms to include in the surface roughness spectra

    #
    #
    # if auto == 1:
    #     n_spec = 1
    #     while error > 1.0e-8:
    #         n_spec = n_spec + 1
    #         error = (ks2 * (2 * cs) ** 2) ** n_spec / math.factorial(n_spec)

    # -- calculating shadow consideration in single scat(Smith, 1967)

    ct = mpmath.cot(theta + 0.001)
    farg = (ct / sqrt(2) / rss).real

    gamma = 0.5 * (math.exp(-float(farg.real)**2) / 1.772 / float(farg.real) -
                   erfc(float(farg.real)))

    Shdw = 1 / (1 + gamma)

    # -- calculating multiple scattering contribution
    # ------ a double integration function

    math.factorials = {}
    for number in np.arange(1, n_spec + 1):
        math.factorials[number] = math.factorial(number)

    svh = dblquad(
        lambda phi, r: xpol_integralfunc_vec(
            r, phi, sp, xx, ks2, cs, s, kl2, L, er, rss, rvh, n_spec, math.
            factorials), 0.1, 1, lambda x: 0, lambda x: math.pi)[0]

    svh = svh * 1.e-5  # # un - scale after rescalingin the integrand function.
    sigvh = 10 * math.log10(svh * Shdw)

    return (sigvh)
Пример #22
0
# -*- coding: utf-8 -*-
"""

Created by libsedmlscript v0.0.1
"""

from sed_roadrunner import model, task, plot

from mpmath import cot
#----------------------------------------------

cot(0.5)
Пример #23
0
 'sqrt': ['primitive', [lambda x, y: mp.sqrt(x), None]],
 'cbrt': ['primitive', [lambda x, y: mp.cbrt(x), None]],
 'root': ['primitive', [lambda x, y: mp.root(x, y[0]), None]],  # y's root 
 'unitroots': ['primitive', [lambda x, y: Vector(mp.unitroots(x)),
                             None]],  #  
 'hypot': ['primitive', [lambda x, y: mp.hypot(x, y[0]),
                         None]],  # sqrt(x**2+y**2) 
 #
 'sin': ['primitive', [lambda x, y: mp.sin(x), None]],
 'cos': ['primitive', [lambda x, y: mp.cos(x), None]],
 'tan': ['primitive', [lambda x, y: mp.tan(x), None]],
 'sinpi': ['primitive', [lambda x, y: mp.sinpi(x), None]],  #sin(x * pi) 
 'cospi': ['primitive', [lambda x, y: mp.cospi(x), None]],
 'sec': ['primitive', [lambda x, y: mp.sec(x), None]],
 'csc': ['primitive', [lambda x, y: mp.csc(x), None]],
 'cot': ['primitive', [lambda x, y: mp.cot(x), None]],
 'asin': ['primitive', [lambda x, y: mp.asin(x), None]],
 'acos': ['primitive', [lambda x, y: mp.acos(x), None]],
 'atan': ['primitive', [lambda x, y: mp.atan(x), None]],
 'atan2': ['primitive', [lambda x, y: mp.atan2(y[0], x), None]],
 'asec': ['primitive', [lambda x, y: mp.asec(x), None]],
 'acsc': ['primitive', [lambda x, y: mp.acsc(x), None]],
 'acot': ['primitive', [lambda x, y: mp.acot(x), None]],
 'sinc': ['primitive', [lambda x, y: mp.sinc(x), None]],
 'sincpi': ['primitive', [lambda x, y: mp.sincpi(x), None]],
 'degrees': ['primitive', [lambda x, y: mp.degrees(x),
                           None]],  #radian - >degree 
 'radians': ['primitive', [lambda x, y: mp.radians(x),
                           None]],  #degree - >radian 
 #
 'exp': ['primitive', [lambda x, y: mp.exp(x), None]],
Пример #24
0
 def eval(self, z):
     return mpmath.cot(z)
Пример #25
0
async def find_cot(event):
    input_str = float(event.pattern_match.group(1))
    output = mpmath.cot(input_str)
    await event.edit(f"**Value of Cot {input_str}\n==>>**`{output}`") 
Пример #26
0
    def calculateShadow(self, ntimes):
        shadow_length_tower = np.zeros((ntimes))
        shadow_length_rotor_top = np.zeros((ntimes))
        shadow_length_rotor_bot = np.zeros((ntimes))

        for tt in range(0, ntimes):
            shadow_length_tower[tt] = self.tower_height * cot(
                np.radians(self.elevation_angle[tt]))
            shadow_length_rotor_top[tt] = (
                self.tower_height + self.rotor_radius) * cot(
                    np.radians(self.elevation_angle[tt]))
            shadow_length_rotor_bot[tt] = (
                self.tower_height - self.rotor_radius) * cot(
                    np.radians(self.elevation_angle[tt]))
        shadow_length_tower[self.elevation_angle <= 0.0] = np.nan
        shadow_length_rotor_top[self.elevation_angle <= 0.0] = np.nan
        shadow_length_rotor_bot[self.elevation_angle <= 0.0] = np.nan
        shadow_ang = self.azimuth_angle - 180.0
        shadow_ang[self.elevation_angle <= 0.0] = np.nan
        shadow_ang[shadow_ang < 0.0] += 360.0

        shadow = np.ones(
            (np.shape(self.xyc)[0], np.shape(self.xyc)[1], ntimes))

        distance = np.sqrt(self.xyc**2 + self.yxc**2)
        angle = np.degrees(np.arctan(self.xyc / self.yxc))
        angle[self.yxc < 0.0] = angle[self.yxc < 0.0] + 180.0
        angle[angle < 0.0] = angle[angle < 0.0] + 360.0

        for toi in range(0, ntimes):
            D = shadow_length_tower[toi]
            theta = np.radians(shadow_ang[toi])
            mask = np.ones(np.shape(self.xyc))

            htw = self.tower_width / 2.0
            # find the left and right edges of the tower shadow by adding/subtracting 90 degrees from the shadow angle
            tower_left_xs, tower_left_ys = htw * np.sin(
                np.radians(shadow_ang[toi] - 90.0)), htw * np.cos(
                    np.radians(shadow_ang[toi] - 90.0))
            tower_rght_xs, tower_rght_ys = htw * np.sin(
                np.radians(shadow_ang[toi] + 90.0)), htw * np.cos(
                    np.radians(shadow_ang[toi] + 90.0))
            tower_left_xe, tower_left_ye = D * np.sin(
                theta) + tower_left_xs, D * np.cos(theta) + tower_left_ys
            tower_rght_xe, tower_rght_ye = D * np.sin(
                theta) + tower_rght_xs, D * np.cos(theta) + tower_rght_ys
            # Find the slopes & intercepts of these lines to find the cells that are between the two
            tower_left_slope = (tower_left_ys - tower_left_ye) / (
                tower_left_xs - tower_left_xe)
            tower_rght_slope = (tower_rght_ys - tower_rght_ye) / (
                tower_rght_xs - tower_rght_xe)
            tower_left_int = tower_left_ys - tower_left_slope * tower_left_xs
            tower_rght_int = tower_rght_ys - tower_rght_slope * tower_rght_xs
            tower_axis_slope = (tower_left_ys - tower_rght_ys) / (
                tower_left_xs - tower_rght_xs)
            # Make is so that the angle is 0 in the direction of the shadow... remove 180 > A > 270
            shadow_angle = angle - shadow_ang[toi]
            shadow_angle[shadow_angle < 0.0] += 360.0
            # Find points between the two lines...
            mask[((self.yxc >= tower_left_slope * self.xyc + tower_left_int) &
                  (self.yxc <= tower_rght_slope * self.xyc + tower_rght_int)) |
                 ((self.yxc <= tower_left_slope * self.xyc + tower_left_int) &
                  (self.yxc >= tower_rght_slope * self.xyc + tower_rght_int)
                  )] = (1.0 - self.tower_shadow_weight)
            # Find points that are less than the shadow distance
            mask[distance > shadow_length_tower[toi]] = 1.0
            # Find points in the direction of the shadow
            mask[(shadow_angle > 90.0) & (shadow_angle < 270.0)] = 1.0

            # Define the ellipse!
            g_ell_center = (D * np.sin(theta), D * np.cos(theta))
            g_ell_height = self.rotor_radius
            g_ell_width = shadow_length_rotor_top[
                toi] - shadow_length_rotor_bot[toi]
            ell_angle = np.degrees(
                np.arctan2(D * np.cos(theta), D * np.sin(theta)))
            # Get the angles of the axes
            cos_angle = np.cos(np.radians(180. - ell_angle))
            sin_angle = np.sin(np.radians(180. - ell_angle))
            # Find the distance of each gridpoint from the ellipse
            exc = self.xyc - g_ell_center[0]
            eyc = self.yxc - g_ell_center[1]
            exct = exc * cos_angle - eyc * sin_angle
            eyct = exc * sin_angle + eyc * cos_angle
            # Get the radial distance away from ellipse: cutoff at r = 1
            rad_cc = (exct**2 /
                      (g_ell_width / 2.)**2) + (eyct**2 /
                                                (g_ell_height / 2.)**2)

            g_ellipse = patches.Ellipse(g_ell_center,
                                        g_ell_width,
                                        g_ell_height,
                                        angle=ell_angle)
            mask[rad_cc <= 1.0] = mask[rad_cc <= 1.0] * (
                1.0 - self.rotor_shadow_weight)

            shadow[:, :, toi] = mask
        self.shadow = shadow
Пример #27
0
 def run(self, context):
     return mpmath.cot(self.body.run(context))
Пример #28
0
def I2EM_Bistat_model(
        frequency,
        sigma_h,
        CL,
        theta_i,
        theta_scat,
        phi_scat,
        er,  # Dielectric constant
        sp,
        xx):

    error = 1.0e8

    sigma_h = sigma_h * 100  # change from m to cm scale
    CL = CL * 100

    mu_r = 1  # relative permeability

    k = 2 * math.pi * frequency / 30  # wavenumber in free space.\
    # Speed of light is in cm / sec
    theta = theta_i * math.pi / 180  # transform to radian
    phi = 0
    thetas = theta_scat * math.pi / 180
    phis = phi_scat * math.pi / 180

    ks = k * sigma_h  # roughness parameter
    kl = k * CL

    ks2 = ks * ks

    cs = math.cos(theta + 0.01)
    s = math.sin(theta + 0.01)

    sf = math.sin(phi)
    cf = math.cos(phi)

    ss = math.sin(thetas)
    css = math.cos(thetas)

    cfs = math.cos(phis)
    sfs = math.sin(phis)

    s2 = s**2

    kx = k * s * cf
    ky = k * s * sf
    kz = k * cs

    ksx = k * ss * cfs
    ksy = k * ss * sfs
    ksz = k * css

    # -- reflection coefficients
    rt = sqrt(er - s2)
    Rvi = (er * cs - rt) / (er * cs + rt)
    Rhi = (cs - rt) / (cs + rt)

    wvnb = k * math.sqrt((ss * cfs - s * cf)**2 + (ss * sfs - s * sf)**2)

    Ts = 1

    while error > 1.0e-8:
        Ts = Ts + 1
        error = (ks2 * (cs + css)**2)**Ts / math.factorial(Ts)

    # ---------------- calculating roughness spectrum - ----------

    (wn, rss) = roughness_spectrum(sp, xx, wvnb, sigma_h, CL, Ts)

    # ----------- compute R - transition - -----------

    Rv0 = (sqrt(er) - 1) / (sqrt(er) + 1)
    Rh0 = -Rv0

    Ft = 8 * Rv0**2 * ss * (cs + sqrt(er - s2)) / (cs * sqrt(er - s2))
    a1 = 0
    b1 = 0

    for n in np.arange(1, Ts + 1):
        a0 = (ks * cs)**(2 * n) / math.factorial(n)
        a1 = a1 + a0 * wn[n - 1]
        b1 = b1 + a0 * (abs(Ft / 2 + 2**(n + 1) * Rv0 / cs *
                            math.exp(-(ks * cs)**2)))**2 * wn[n - 1]

    St = 0.25 * (abs(Ft))**2 * a1 / b1

    St0 = 1 / (abs(1 + 8 * Rv0 / (cs * Ft)))**2

    Tf = 1 - St / St0

    # ----------- compute average reflection coefficients - -----------
    # -- these coefficients account for slope effects, especially near the
    # brewster angle.They are not important if the slope is small.

    sigx = 1.1 * sigma_h / CL
    sigy = sigx
    xxx = 3 * sigx

    # print( cs, s, er, s2, sigx, sigy)

    #######################

    def complex_dblquad(func, a, b, c, d):
        def real_func(x, y):
            return np.real(func(x, y))

        def imag_func(x, y):
            return np.imag(func(x, y))

        real_integral = dblquad(real_func, a, b, c, d)
        imag_integral = dblquad(imag_func, a, b, c, d)

        return (real_integral[0] + 1j * imag_integral[0])

    #####################

    Rav = complex_dblquad(lambda Zx, Zy: utils.Rav_integration(
        Zx, Zy, cs, s, er, s2, sigx, sigy), -xxx, xxx, -xxx,
                          xxx)  # Integrate over Zx, Zy

    Rah = complex_dblquad(lambda Zx, Zy: utils.Rah_integration(
        Zx, Zy, cs, s, er, s2, sigx, sigy), -xxx, xxx, -xxx,
                          xxx)  # Integrate over Zx, Zy

    Rav = Rav / (2 * math.pi * sigx * sigy)
    Rah = Rah / (2 * math.pi * sigx * sigy)

    # -- select proper reflection coefficients

    if (theta_i == theta_scat) & (phi_scat
                                  == 180):  # i.e.operating in backscatter mode
        Rvt = Rvi + (Rv0 - Rvi) * Tf
        Rht = Rhi + (Rh0 - Rhi) * Tf

    else:  # in this case, it is the bistatic configuration and average R is used
        # Rvt = Rav + (Rv0 - Rav) * Tf
        # Rht = Rah + (Rh0 - Rah) * Tf
        Rvt = Rav
        Rht = Rah

    fvv = 2 * Rvt * (s * ss - (1 + cs * css) * cfs) / (cs + css)
    fhh = -2 * Rht * (s * ss - (1 + cs * css) * cfs) / (cs + css)

    # ------- Calculate the Fppup(dn) i(s) coefficients - ---
    (Fvvupi, Fhhupi) = utils.Fppupdn_is_calculations(+1, 1, Rvi, Rhi, er, k,
                                                     kz, ksz, s, cs, ss, css,
                                                     cf, cfs, sfs)
    (Fvvups, Fhhups) = utils.Fppupdn_is_calculations(+1, 2, Rvi, Rhi, er, k,
                                                     kz, ksz, s, cs, ss, css,
                                                     cf, cfs, sfs)
    (Fvvdni, Fhhdni) = utils.Fppupdn_is_calculations(-1, 1, Rvi, Rhi, er, k,
                                                     kz, ksz, s, cs, ss, css,
                                                     cf, cfs, sfs)
    (Fvvdns, Fhhdns) = utils.Fppupdn_is_calculations(-1, 2, Rvi, Rhi, er, k,
                                                     kz, ksz, s, cs, ss, css,
                                                     cf, cfs, sfs)

    qi = k * cs
    qs = k * css

    # ----- calculating Ivv and Ihh - ---

    fvv = fvv.conjugate()
    fhh = fhh.conjugate()

    Fvvupi = Fvvupi.conjugate()
    Fvvups = Fvvups.conjugate()
    Fvvdni = Fvvdni.conjugate()
    Fvvdns = Fvvdns.conjugate()

    Fhhupi = Fhhupi.conjugate()
    Fhhups = Fhhups.conjugate()
    Fhhdni = Fhhdni.conjugate()
    Fhhdns = Fhhdns.conjugate()

    Ivv = np.zeros(Ts, dtype=np.complex_)
    Ihh = Ivv.copy()

    for n in np.arange(1, Ts + 1):

        Ivv[n-1] = (kz + ksz) ** n * fvv *math.exp(-sigma_h ** 2 * kz * ksz) + \
        0.25 * (Fvvupi * (ksz - qi) ** (n - 1) *math.exp(-sigma_h ** 2 * (qi ** 2 - qi * (ksz - kz))) +
        Fvvdni* (ksz+qi) ** (n - 1) *math.exp(-sigma_h ** 2 * (qi ** 2 + qi * (ksz - kz))) +
        Fvvups * (kz + qs) ** (n - 1) *math.exp(-sigma_h ** 2 * (qs ** 2 - qs * (ksz - kz))) +
        Fvvdns * (kz - qs) ** (n - 1) *math.exp(-sigma_h ** 2 * (qs ** 2 + qs * (ksz - kz))))


        Ihh[n-1] = (kz + ksz) ** n * fhh *math.exp(-sigma_h ** 2 * kz * ksz) + \
        0.25 * (Fhhupi * (ksz - qi) ** (n - 1) *math.exp(-sigma_h ** 2 * (qi ** 2 - qi * (ksz - kz))) +
        Fhhdni* (ksz+qi) ** (n - 1) *math.exp(-sigma_h ** 2 * (qi ** 2 + qi * (ksz - kz))) +
        Fhhups * (kz + qs) ** (n - 1) *math.exp(-sigma_h ** 2 * (qs ** 2 - qs * (ksz - kz))) +
        Fhhdns * (kz - qs) ** (n - 1) *math.exp(-sigma_h ** 2 * (qs ** 2 + qs * (ksz - kz))))

    # -- Shadowing function calculations

    if (theta_i == theta_scat) & (phi_scat
                                  == 180):  # i.e.working in backscatter mode
        ct = mpmath.cot(theta)
        cts = mpmath.cot(thetas)
        rslp = rss
        ctorslp = float((ct / sqrt(2) / rslp).real)
        ctsorslp = float((cts / sqrt(2) / rslp).real)

        shadf = 0.5 * (math.exp(-ctorslp**2) / sqrt(math.pi) / ctorslp -
                       erfc(ctorslp))
        shadfs = 0.5 * (math.exp(-ctsorslp**2) / sqrt(math.pi) / ctsorslp -
                        erfc(ctsorslp))
        ShdwS = 1 / (1 + shadf + shadfs)
    else:
        ShdwS = 1

    # ------- calculate the values of sigma_note - -------------

    sigmavv = 0
    sigmahh = 0

    for n in np.arange(1, Ts + 1):

        a0 = wn[n - 1] / math.factorial(n) * sigma_h**(2 * n)

        sigmavv = sigmavv + abs(Ivv[n - 1])**2 * a0
        sigmahh = sigmahh + abs(Ihh[n - 1])**2 * a0

    sigmavv = sigmavv * ShdwS * k**2 / 2 * math.exp(-sigma_h**2 *
                                                    (kz**2 + ksz**2))
    sigmahh = sigmahh * ShdwS * k**2 / 2 * math.exp(-sigma_h**2 *
                                                    (kz**2 + ksz**2))

    ssv = 10 * math.log10(sigmavv.real)
    ssh = 10 * math.log10(sigmahh.real)

    sigma_0_vv = ssv
    sigma_0_hh = ssh

    return sigma_0_vv, sigma_0_hh
Пример #29
0
def IEMX_model(fr, sig, L, theta_d, er, sp, xx, auto):
    er = er.conjugate()
    sig = sig * 100  # change to cm scale
    L = L * 100  # change to cm scale

    # - fr: frequency in GHz
    # - sig: rms height of surface in cm
    # - L: correlation length of surface in cm
    # - theta_d: incidence angle in degrees
    # - er: relative permittivity
    # - sp: type of surface correlation function

    error = 1.0e8

    k = 2 * math.pi * fr / 30  # wavenumber in free space.Speed of light is in cm / sec
    theta = theta_d * math.pi / 180  # transform to radian

    ks = k * sig  # roughness parameter
    kl = k * L

    ks2 = ks * ks
    kl2 = kl**2

    cs = math.cos(theta)
    s = math.sin(theta + 0.001)

    s2 = s**2

    # -- calculation of reflection coefficints
    rt = sqrt(er - s2)

    rv = (er * cs - rt) / (er * cs + rt)

    rh = (cs - rt) / (cs + rt)

    rvh = (rv - rh) / 2

    # print(rt, rv, rh, rvh)
    # exit()

    # -- rms slope values
    sig_l = sig / L
    if sp.lower() == 'math.exponential':  # -- math.exponential correl func
        rss = sig_l

    if sp.lower() == 'gaussian':  # -- Gaussian correl func
        rss = sig_l * sqrt(2)

    if sp.lower() == 'power_spec':  # -- 1.5 - power spectra correl func
        rss = sig_l * sqrt(2 * xx)

    # --- Selecting number of spectral components of the surface roughness
    if auto == 0:
        n_spec = 15  # numberofterms to include in the surface roughness spectra

    if auto == 1:
        n_spec = 1
        while error > 1.0e-8:
            n_spec = n_spec + 1
            error = (ks2 * (2 * cs)**2)**n_spec / math.factorial(n_spec)

    # -- calculating shadow consideration in single scat(Smith, 1967)

    ct = mpmath.cot(theta + 0.001)
    farg = (ct / sqrt(2) / rss).real

    gamma = 0.5 * (math.exp(-float(farg.real)**2) / 1.772 / float(farg.real) -
                   erfc(float(farg.real)))

    Shdw = 1 / (1 + gamma)

    # -- calculating multiple scattering contribution
    # ------ a double integration function

    math.factorials = {}
    for number in np.arange(1, n_spec + 1):
        math.factorials[number] = math.factorial(number)

    svh = dblquad(
        lambda phi, r: xpol_integralfunc_vec(
            r, phi, sp, xx, ks2, cs, s, kl2, L, er, rss, rvh, n_spec, math.
            factorials), 0.1, 1, lambda x: 0, lambda x: math.pi)[0]

    svh = svh * 1.e-5  # # un - scale after rescalingin the integrand function.
    sigvh = 10 * math.log10(svh * Shdw)

    return (sigvh)
Пример #30
0
    def phi_quadratic_exact(self, start_phi=0, final_phi=pi):

        # Calculate 'temp' delta
        delta = (final_phi - start_phi) / self.outer_points

        # Increase starting point if start_phi = 0
        if start_phi == 0:
            start_phi = delta

        # Decrease end point if final_phi = pi
        if final_phi == pi:
            final_phi = final_phi - delta

        # Discretise the interval from start_phi to final_phi
        discr_pi = linspace(start_phi, final_phi, self.outer_points)

        # Solve Eq. 24 (Kager et al. 2004) on the range start_phi to final_phi
        self.phi_exact_quadratic_forward = array(
            [2 - 2 * phi * cot(phi) + 2 * 1j * phi for phi in discr_pi],
            dtype=complex128)

        # Create a properties string specifically for the phi exact solution
        properties_string = "-".join([
            str(prop) for prop in [
                self.index, "PHI",
                self.number_to_string(start_phi),
                self.number_to_string(final_phi), self.outer_points
            ]
        ])

        if self.save_data:

            # Create a filename for the dat file
            filename = EXACT_FORWARD_DATA_OUTPUT + properties_string + DATA_EXT

            # Create a 2D array from the real and imaginary values of the results
            results_array = column_stack(
                (self.phi_exact_quadratic_forward.real,
                 self.phi_exact_quadratic_forward.imag))

            # Save the array to the filesystem
            self.save_to_dat(filename, results_array)

        if self.save_plot:

            # Clear any preexisting plots to be safe
            plt.cla()

            # Set the plot title
            self.set_plot_title()

            # Plo the values
            plt.plot(self.phi_exact_quadratic_forward.real,
                     self.phi_exact_quadratic_forward.imag,
                     color='crimson')

            # Set the axes labels
            plt.xlabel(FOR_PLOT_XL)
            plt.ylabel(FOR_PLOT_YL)

            # Set the lower limit of the y-axis
            plt.ylim(bottom=0)

            # Save the plot to the filesystem
            plt.savefig(EXACT_FORWARD_PLOT_OUTPUT + properties_string +
                        PLOT_EXT,
                        bbox_inches='tight')
Пример #31
0
def getPrismVolumeOperator(n, k, h):
    return getProduct([fdiv(n, 4), h,
                       getPower(k, 2),
                       cot(fdiv(pi, n))]).convert('meter^3')
Пример #32
0
	def precompute_values(self):
		self.n = (math.log(math.cos(self.phi1) * mpmath.sec(self.phi2)))/	math.log(math.tan(math.pi/4 + self.phi2/2) * mpmath.cot(math.pi/4 + self.phi1/2))
		if self.n == 0.0000:
			self.n = 0.00001
		self.F = (math.cos(self.phi1) * math.pow(math.tan(math.pi / 4 + self.phi1 / 2), self.n))/ self.n
Пример #33
0
def Multiscale_I2EM_Backscatter(fr, sig1, L1, sig2, L2, sig3, L3, thi, er):

    ths = thi

    phs = 180

    error = 1.0e8

    sig1 = sig1 * 100  # change from m to cm scale
    L1 = L1 * 100

    sig2 = sig2 * 100  # change from m to cm scale
    L2 = L2 * 100

    sig3 = sig3 * 100  # change from m to cm scale
    L3 = L3 * 100

    sig12 = sig1**2
    sig22 = sig2**2
    sig32 = sig3**2

    sigs2 = sig12 + sig22 + sig32

    mu_r = 1  # relative permeability

    # Speed of light is in cm / sec

    theta = thi * math.pi / 180  # transform to radian

    k = 2 * math.pi * fr / 30  # wavenumber in free space.

    phi = 0
    thetas = ths * math.pi / 180
    phis = phs * math.pi / 180

    ks = k * math.sqrt(sigs2)  # roughness parameter
    kl1 = k * L1

    ks2 = ks * ks

    cs = math.cos(theta + 0.01)
    s = math.sin(theta + 0.01)

    sf = math.sin(phi)
    cf = math.cos(phi)

    ss = math.sin(thetas)
    css = math.cos(thetas)

    cfs = math.cos(phis)
    sfs = math.sin(phis)

    s2 = s * s
    # sq = sqrt(er - s2)

    kx = k * s * cf
    ky = k * s * sf
    kz = k * cs

    ksx = k * ss * cfs
    ksy = k * ss * sfs
    ksz = k * css

    # -- reflection coefficients
    rt = sqrt(er - s2)
    Rvi = (er * cs - rt) / (er * cs + rt)
    Rhi = (cs - rt) / (cs + rt)

    wvnb = k * sqrt((ss * cfs - s * cf)**2 + (ss * sfs - s * sf)**2)

    Ts = 1

    while error > 1.0e-8:
        Ts = Ts + 1

        error = (ks2.real * (cs + css)**2)**Ts / math.factorial(Ts)

    # ---------------- calculating roughness spectrum - ----------

    wn = utils.multi_roughness_spectrum(sig12, sig22, sig32, sigs2, L1, L2, L3,
                                        k, s, Ts)

    rss = sqrt(2) / sigs2 * (sig12 * sig1 / L1 + sig22 * sig2 / L2 +
                             sig32 * sig3 / L3)

    # ----------- compute R - transition - -----------

    Rv0 = (sqrt(er) - 1) / (sqrt(er) + 1)
    Rh0 = -Rv0

    Ft = 8 * Rv0**2 * ss * (cs + sqrt(er - s2)) / (cs * sqrt(er - s2))
    a1 = 0
    b1 = 0
    for n in np.arange(1, Ts + 1):
        a0 = (ks.real * cs)**(2 * n) / math.factorial(n)
        a1 = a1 + a0 * wn[n - 1]

        b1 = b1 + a0 * (abs(Ft / 2 + 2**(n + 1) * Rv0 / cs *
                            math.exp(-(ks * cs)**2)))**2 * wn[n - 1]

    St = 0.25 * (abs(Ft))**2 * a1 / b1

    St0 = 1 / (abs(1 + 8 * Rv0 / (cs * Ft)))**2

    Tf = 1 - St / St0

    # # ----------- compute average reflection coefficients - -----------
    # # -- these coefficients account for slope effects
    # # especially near the  brewster angle.
    # # They are not important if the slope is small.
    #
    # sigx = 1.1 * sig / L
    # sigy = sigx
    # xxx = 3 * sigx
    #
    # Rav = dblquad( @ (Zx, Zy)
    # Rav_integration(Zx, Zy, cs, s, er, s2, sigx, sigy), -xxx, xxx, -xxx, xxx )
    #
    # Rah = dblquad( @ (Zx, Zy)
    # Rah_integration(Zx, Zy, cs, s, er, s2, sigx, sigy), -xxx, xxx, -xxx, xxx )
    #
    # Rav = Rav / (2 *math.pi * sigx * sigy)
    # Rah = Rah / (2 *math.pi * sigx * sigy)
    #

    # -- select proper reflection coefficients

    # if thi == ths & & phs == 180, # i.e.operating in backscatter mode
    Rvt = Rvi + (Rv0 - Rvi) * Tf
    Rht = Rhi + (Rh0 - Rhi) * Tf

    # else # in this case, it is the bistatic configuration and average R is used
    # # Rvt = Rav + (Rv0 - Rav) * Tf
    # # Rht = Rah + (Rh0 - Rah) * Tf
    # Rvt = Rav
    # Rht = Rah
    # end

    fvv = 2 * Rvt * (s * ss - (1 + cs * css) * cfs) / (cs + css)
    fhh = -2 * Rht * (s * ss - (1 + cs * css) * cfs) / (cs + css)

    # ------- Calculate the Fppup(dn) i(s) coefficients - ---

    (Fvvupi, Fhhupi) = Fppupdn_is_calculations(+1, 1, Rvi, Rhi, er, k, kz, ksz,
                                               s, cs, ss, css, cf, cfs, sfs)
    (Fvvups, Fhhups) = Fppupdn_is_calculations(+1, 2, Rvi, Rhi, er, k, kz, ksz,
                                               s, cs, ss, css, cf, cfs, sfs)
    (Fvvdni, Fhhdni) = Fppupdn_is_calculations(-1, 1, Rvi, Rhi, er, k, kz, ksz,
                                               s, cs, ss, css, cf, cfs, sfs)
    (Fvvdns, Fhhdns) = Fppupdn_is_calculations(-1, 2, Rvi, Rhi, er, k, kz, ksz,
                                               s, cs, ss, css, cf, cfs, sfs)

    qi = k * cs
    qs = k * css

    # ----- calculating Ivv and Ihh - ---

    Ivv = np.zeros(Ts, dtype=np.complex_)
    Ihh = Ivv.copy()

    for n in np.arange(1, Ts + 1):
        Ivv[n-1] = (kz + ksz) ** n * fvv * math.exp(-sigs2 * kz * ksz) + \
        0.25 * (Fvvupi * (ksz - qi) ** (n - 1) * math.exp(-sigs2 * (qi ** 2 - qi * (ksz - kz))) +
                Fvvdni * (ksz+qi) ** (n - 1) * math.exp(-sigs2 * (qi ** 2 + qi * (ksz - kz))) +
        Fvvups * (kz + qs) ** (n - 1) * math.exp(-sigs2 * (qs ** 2 - qs * (ksz - kz))) +
        Fvvdns * (kz - qs) ** (n - 1) * math.exp(-sigs2 * (qs ** 2 + qs * (ksz - kz))))


        Ihh[n-1] = (kz + ksz) ** n * fhh * math.exp(-sigs2 * kz * ksz) + \
        0.25 * (Fhhupi * (ksz - qi) ** (n - 1) * math.exp(-sigs2 * (qi ** 2 - qi * (ksz - kz))) +
                Fhhdni * (ksz+qi) ** (n - 1) * math.exp(-sigs2 * (qi ** 2 + qi * (ksz - kz))) +
        Fhhups * (kz + qs) ** (n - 1) * math.exp(-sigs2 * (qs ** 2 - qs * (ksz - kz))) +
        Fhhdns * (kz - qs) ** (n - 1) * math.exp(-sigs2 * (qs ** 2 + qs * (ksz - kz))))

    # -- Shadowing function calculations

    # if thi == ths & & phs == 180 # i.e.working in backscatter mode
    ct = mpmath.cot(theta)
    cts = mpmath.cot(thetas)
    rslp = rss
    ctorslp = float(ct / math.sqrt(2) / rslp)
    ctsorslp = float(cts / math.sqrt(2) / rslp)

    shadf = 0.5 * (math.exp(-ctorslp**2) / sqrt(math.pi) / ctorslp -
                   erfc(ctorslp))
    shadfs = 0.5 * (math.exp(-ctsorslp**2) / sqrt(math.pi) / ctsorslp -
                    erfc(ctsorslp))
    ShdwS = 1 / (1 + shadf + shadfs)

    # ------- calculate the values of sigma_note - -------------

    sigmavv = 0
    sigmahh = 0

    for n in np.arange(1, Ts + 1):

        a0 = wn[n - 1] / math.factorial(n) * sigs2**(n)

        sigmavv = sigmavv + abs(Ivv[n - 1])**2 * a0
        sigmahh = sigmahh + abs(Ihh[n - 1])**2 * a0

    sigmavv = sigmavv * ShdwS * k**2 / 2 * math.exp(-sigs2 * (kz**2 + ksz**2))
    sigmahh = sigmahh * ShdwS * k**2 / 2 * math.exp(-sigs2 * (kz**2 + ksz**2))

    if (abs(sigmavv.imag) + abs(sigmahh.imag)) > 0:
        raise Exception('backscatter coeff must be real')

    ssv = 10 * math.log10(sigmavv.real)
    ssh = 10 * math.log10(sigmahh.real)

    sigma_0_vv = ssv
    sigma_0_hh = ssh

    return (sigma_0_vv, sigma_0_hh)
Пример #34
0
from __future__ import division
import mpmath as math
from units import *
from copy import copy

def sqrt(x):
  if hasattr(x,'unit'):
    return math.sqrt(x.number) | x.unit**0.5 
  return math.sqrt(x)  

#trigonometric convenience functions which are "unit aware"
sin=lambda x: math.sin(1.*x)
cos=lambda x: math.cos(1.*x)
tan=lambda x: math.tan(1.*x)
cot=lambda x: math.cot(1.*x)

asin=lambda x: math.asin(x) | rad
acos=lambda x: math.acos(x) | rad
atan=lambda x: math.atan(x) | rad
atan2=lambda x,y: math.atan2(x,y) | rad

#~ cos=math.cos
#~ sin=math.sin
#~ tan=math.tan
#~ cosh=math.cosh
#~ sinh=math.sinh
#~ tanh=math.tanh
#~ acos=math.acos
#~ asin=math.asin
#~ atan=math.atan
acosh=math.acosh
Пример #35
0
 def eval(self, z):
     return mpmath.cot(z)
Пример #36
0
    def move(self, alpha, v, t):
        if alpha == 0:
            self.x1 += v * t
            self.x2 += v * t
            return
        reverse_alpha = False
        reverse_v = False
        alpha = mpmath.radians(alpha)
        if alpha < 0:
            alpha = -alpha
            reverse_alpha = True

        if v < 0:
            v = -v
            reverse_v = True

        R = self.l * mpmath.cot(alpha) + 0.5 * self.d  # outer radius
        r = self.l * mpmath.cot(alpha) - 0.5 * self.d  # inner radius
        w = v / R  # angular velocity
        beta = w * t  # angle that has been turned after the move viewed from the center of the circle
        assert (beta < mpmath.pi)  # make sure it still forms a triangle
        theta = 0.5 * beta  # the angle of deviation from the original orientation
        m = 2 * R * mpmath.sin(theta)  # displacement of outer rear wheel
        n = 2 * r * mpmath.sin(theta)  # displacement of inner rear wheel
        if not reverse_alpha and not reverse_v:
            delta_x1, delta_y1 = mpmath.cos(theta) * m, mpmath.sin(theta) * m
            delta_x2, delta_y2 = mpmath.cos(theta) * n, mpmath.sin(theta) * n
        elif reverse_alpha and not reverse_v:
            delta_x2, delta_y2 = mpmath.cos(theta) * m, -mpmath.sin(theta) * m
            delta_x1, delta_y1 = mpmath.cos(theta) * n, -mpmath.sin(theta) * n
        elif not reverse_alpha and reverse_v:
            delta_x1, delta_y1 = -mpmath.cos(theta) * m, mpmath.sin(theta) * m
            delta_x2, delta_y2 = -mpmath.cos(theta) * n, mpmath.sin(theta) * n
        else:
            delta_x2, delta_y2 = -mpmath.cos(theta) * m, -mpmath.sin(theta) * m
            delta_x1, delta_y1 = -mpmath.cos(theta) * n, -mpmath.sin(theta) * n

        delta_x1 = float(delta_x1)
        delta_y1 = float(delta_y1)
        delta_x2 = float(delta_x2)
        delta_y2 = float(delta_y2)

        # the current calculation is based on this relative reference system
        # we need to map this coordinate in the relative reference system back to the absolute system

        # use the dot product of the rear wheel line to find the rotation from the relative reference system to the absolute system
        if self.y1 != 0 or self.y2 != 10:  # no rotation is needed
            bottom = np.sqrt(((self.x2 - self.x1) * (self.x2 - self.x1) +
                              (self.y2 - self.y1) * (self.y2 - self.y1))) * 10
            top = (self.y2 - self.y1) * 10
            cosine_value = float(top / bottom)
            rotation = mpmath.acos(cosine_value)
            # print(rotation)
            if self.x1 < self.x2:  # since arccos does not give direction, we need to do a check here
                rotation = -rotation
            # let A be the linear transformation that maps a relative referenced coordinate to an absolute referenced coordinate
            A = np.asarray(
                [[float(mpmath.cos(rotation)),
                  float(-mpmath.sin(rotation))],
                 [float(mpmath.sin(rotation)),
                  float(mpmath.cos(rotation))]])
            # then we map delta_1 and delta_2 to the absolute reference system
            relative_delta_1 = np.asarray([delta_x1, delta_y1])
            relative_delta_2 = np.asarray([delta_x2, delta_y2])
            absolute_delta_1 = np.matmul(A, relative_delta_1)
            absolute_delta_2 = np.matmul(A, relative_delta_2)
            delta_x1 = absolute_delta_1[0]
            delta_y1 = absolute_delta_1[1]
            delta_x2 = absolute_delta_2[0]
            delta_y2 = absolute_delta_2[1]
        # make vector addition in the absolute reference system
        self.x1 += delta_x1
        self.x2 += delta_x2
        self.y1 += delta_y1
        self.y2 += delta_y2
        dist = mpmath.sqrt((self.x1 - self.x2) * (self.x1 - self.x2) +
                           (self.y2 - self.y1) * (self.y2 - self.y1))
        assert abs(dist - self.d) <= self.d * 1e-4