# GSoC 2019 Application Faisal Riyaz: Implementation of Vector Integration

Faisal Riyaz edited this page Apr 10, 2019 · 27 revisions

## Basic Information

Name Faisal Riyaz
University Aligarh Muslim University
Email faisalriyaz011@gmail.com
Github Handle FrackeR011
Time zone IST (UTC +5:30)

## Personal Background

I am Faisal Riyaz, a second year undergraduate student at Aligarh Muslim University, Aligarh. I am pursuing a degree in Computer Engineering. I am interested in computer science and math.

I enjoy watching video lectures on MIT OCW particularly related to Computer Science.

## Programming Background

I started programming about 5 years ago when i was introduced to C++ in high school. I code on Ubuntu 16.04 and use gedit as my text editor. I use gedit because it is simple and fast.

I have been programming in python since last year. Python help me focus more on the algorithms than its implementation.

I have been contributing to Sympy from past 4-5 months. Sympy has many wonderful features. My favourite feature in Sympy is its ability to solve indefinte integrals. Some integrals are very difficult to solve manually but can be easily solved using Sympy. For example:

>>> x = Symbol('x')

>>> integrate(x**5*log(x)**2, x)
x**6*log(x)**2/6 - x**6*log(x)/18 + x**6/108



I am fairly comfortable with Git and GitHub, having used these over the past months for contributing to SymPy.

## Contributions

I started contributing to Sympy in November 2018 by fixing Easy to Fix issues. SymPy is the first project I contributed to and the experience was incredible.

Here is the list of all my contributions so far in chronological order:

• (Merged) matrices: Improved speed of solve() #15341
• (Merged) trigsimp: changes order of TRmorrie and TR10i in trigsimp.py #15346
• (Open) py-dy license added #15372
• (Merged) Replaces _gcdcache wtih lru_cache#15453
• (Merged) Point: redefine distance() in Point to work for Line and other GeometryEntity #15542
• (Merged) numbers: changed behavior of Number.__divmod__ to builtin divmod#15567
• (Closed) Changed behaviour of __eq__() for Polygon #15747
• (Merged) Hash function of Polygon class changed #15754
• (Merged) heurisch : Fix AssertionError #16021
• (Merged) periodicity of e**(I*x) #16068
• (Merged) Replaced var[0] with v1[0] in diophantine.py #16117
• (Merged) Disallow circles with imaginary radius. 16158
• (Merged) Added class to represent unevaluated laplacian. #16158
• (Merged) core.relational.py: Eq without rhs now raises ValueError #16567

# The Project

## Overview and Motivation

My project aims at adding the functionality of vector integration over Curves, Surfaces and Volumes.

Prasoon Shukla had done a Google Summer of Code project on writing a vector calculus module for Sympy. The development of vector module began during Prasoon's GSoC. In his GSoC proposal,.

Currently sympy.vector package supports basic integration of vectors like we integrate expressions. **Example

>>> C = CoordSys3D('C')

>>> x = Symbol('x')

>>> v = 4*x**2*C.i + x**3*C.j + x*C.k

>>> integrate(v, x)



Some work on integration was done by Prasoon but it could not get merged.

Vector calculus has many applications in the field of physics and mathematics. Some of the applications are listed below:

• The work done on a point object when it is displaced under a force F along a curve C is equal to line integral of F along curve C.
• The net charge enclosed inside a surface is directly directly proportional to the flux across the surface. Flux across a surface due to a vector field is equal to the surface integral of the vector field.

## The Plan

The major components which i plan to implement will be the following classes:

1. Curve
2. Surface
3. Volume
4. lineIntegral
5. surfaceIntegral
6. volumeIntegral

To integrate over a curve, surface or volume, user will have to first initialise an object representing that region. This object will be passed as a parameter to methods responsible for integration over region. I will be explaining the workflow using examples. For these examples, we will assume the following code has been executed:

>>> from sympy import *
>>> from sympy.vector import *
>>> C = CoordSys3D('C')
>>> S = C.create_new('S', transformation="spherical")


Each of theses classes are explained in more detail below.

### Curve

This class represents a curve defined parametrically in space.

#### Method

curveLength Example

>>> Curve(C.x=2*t**2, C.y=4*t, (t, 0, pi/2) )
>>> Curve(S.r=4, S.theta=t, (t, 0, pi))


### Surface

This class represents a surface defined parametrically in space. To define a surface, we need two paramters

#### Method

surfaceArea Example

>>> Surface(C.x=r*cos(theta), C.y=r*sin(theta), C.z=r, (r, 0, 2), (theta, 0, 2*pi))

>>> Surface(S.r=4)


### Volume

This class represents a volume defined parametrically in space.

### Integration over Curve

Line integrals may appear in any one of these forms:

Note In case, image representing equations do not render, i list them in LaTeX below:

1. \int _{C}\boldsymbol{V} . d \boldsymbol{r}

2. \int _{C} \phi d \boldsymbol{r}

3. \int _{C}\boldsymbol{V} \times d \boldsymbol{r}

Most commonly encountered line integrals are of form 1 and form 2.

To integrate over a curve,user will have to first create an object of Curve class representing that curve. This object of Curve class will be passed as parameter to lineIntegrate function. lineIntegrate function will return an object of lineIntegral class representing unevaluated line integral.

To use integral of type 3, cross parameter has to bet set true. To evaluate the integral, evalf() method must be used.

Example

>>> vectorField = C.x**2*C.i + C.y**3*C.j + C.k

>>> lineIntegrate(vectorField, Cur)
lineIntegral(vectorField, Cur)

>>> lineIntegrate(vectorField, Cur, cross=True)
lineIntegral(vectorField, Cur, cross=True)

>>> scalarField = C.x**2*C.y*C.z

>>> lineIntegrate(scalarField, Cur)
lineIntegral(scalarField, Cur)


### Integration over Surface

Surface integrals may appear in any one of these forms:

LaTeX form of equations:

1. \int _{S} \boldsymbol{V} . d \boldsymbol{ \sigma }

2. \int _{S} \phi d \boldsymbol{ \sigma }

3. \int _{S} \boldsymbol{V} \times d \boldsymbol{ \sigma }

Differential area in general orthogonal curvilinear system is defined as

LaTeX form of equation:

d\boldsymbol{\sigma } = h_{2}h_{3}dq_{2}dq_{3} \mathbf{e_{1}} + h_{3}h_{1}dq_{3}dq_{1} \mathbf{h_{2}} + h_{1}h_{2}dq_{1}dq_{2} \mathbf{e_{3}}


Surface integrals of form 2 are most commonly encountered.

To integrate over a surface,user will have to first create an object of Surface class representing required Surface. This object of Surface class will be passed as parameter to surfaceIntegrate function. surfaceIntegrate function will return an object of surfaceIntegral class representing unevaluated line integral.

To use integral of type 3, cross parameter has to bet set true. To evaluate the integral, evalf() method must be used.

cross: cross will identify the type of integral which needs to be performed

Example

>>> vectorField = C.x**2*C.i + C.y**3*C.j + C.k

>>> surfaceIntegrate(vectorField, Cur)
surfaceIntegral(vectorField, Cur)

>>> scalarField = C.x**2*C.y*C.z

>>> surfaceIntegrate(scalarField, Cur)
surfaceIntegral(scalarField, Cur)

>>> surfaceIntegrate(vectorField, Cur, cross=True)
surfaceIntegral(vectorField, Cur, cross=True)



### Integration over Volume

LaTeX form of equations:

1. \int _{V} \boldsymbol{V} d \tau

2. \int _{V} \phi d \tau

Differential area in general orthogonal curvilinear system is defined as

LaTeX form of equation: d\tau = h_{1}h_{2}h_{3}dq_{1}dq_{2}dq_{3}

Example

>>> vectorField =

>>> volumeIntegrate(vectorField, Cur)

>>> scalarField =

>>> volumeIntegrate(scalarField, Cur)



Volume integrals are simpler and has one form as volume element is a scalar.

To integrate over a volume,user will have to first create an object of Volume class representing required Volume. This object of Volume class will be passed as parameter to volumeIntegrate function. volumeIntegrate function will return an object of volumeIntegral class representing unevaluated line integral.

#### Volume

This method will return volume bounded by the Surface.

Apart from the classes list above, classes to represent commonly used curves,surfaces and regions can be very helpful. I plan to add following classes:

• Circle
• Disk
• Sphere
• solidCylinder
• solidSphere These classes will inherit from Surface and Volume class.

Example

>>> d = Disk(center_x=0, center_y=0, radius=4)
>>> field = 10
>>> surfaceIntegrate(field, d)
160*pi
>>> V = solidSphere(center_x=0, center_y=2, radius=3)
360*pi


### Make express function work for different co-ordinate systems

Currently, express only works for conversion between cartesion coordinate systems. It gives wrong result when used to express a scalar field into different curvilinear system.

>>> field = C.x + C.y + C.z
>>> express(field, S, variables=True)
S.phi + S.r + S.theta


The correct answer should be:

r*sin(theta)*cos(phi) + r*sin(theta)*sin(phi) + r*cos(theta)

A pull request was made by Szymon to adapt express for transformation equations. Unfortunately, it is still unmerged.

I would like to start from the work done by Szymon and complete .

## How i fit in?

I have been contributing to Sympy for past 4-5 months and i am passionate about the project.

I have had a course on vector calculus. The implementation is within limits of my mathematical knowledge. Among the many projects listed in ideas page, i found this project most interesting and within my capability. Some relevant courses which i have opted at university are mentioned below:

• Introduction to Data Structures and Algorithms
• Design and Analysis of Algorithms
• Object Oriented Programming
• Software Engineering
• Discrete Mathematics
• Numerical Analysis

# Proposed Timeline

May 6 - 27, 2019: Community Bonding Period *The goal of community bonding period is to get acquainted with SymPy, my mentors and other students of the program. I will read more in detail on this topic and rectify any left out loopholes. I will discuss the proposed project with my mentors and will act further according to their advices.

*I will create a blog and start writing short summaries of conversations happening with the mentors and progress of the project every week.

Week 1, 2

Goal: In these two weeks, I plan to work on Curve and lineIntegral class.

Week 3, 4

Goal: Complete implementation of Surface class. This is probably the most difficult part of the project. I have not yet figured about the internals of 'Surface class.

Phase 1 evaluation

Week 5, 6

Goal: Complete implementation of volumeIntegral class.

Week 7, 8

Goal: Complete implementation of Volume class.

Phase 2 evaluation

Week 9

Goal: Complete implementation of volumeIntegral class.

Week 10, 11

Goal: Fix express function

Week 12, 13

Goal: Complete any pending work and write documentation

## Post GSoC

If there are parts of project that are left unimplemented I will try to complete them post GSoC.

Visualization is an important important aspect when it comes to problems involving surface and volume integration. Features for plotting Surface and Volume objects can be of great help to users using vector integration functions. I would like to help with this.

I am looking forward for a long term association with Sympy Community. I plan to actively maintain and review vector module. I am particularly interested in core` module.

I am looking to contribute to some other open source projects

## Time commitment

I will be able to devote 40 hours for Sympy per week on an average. I plan to devote around 5-6 hours on weekdays and 7-8 hours on weekends.

I will be doing a research internship at RISE-lab, IIT madras under Professor V. Kamakoti. The internship will last between June 8, 2019 to July 31, 2019. Although a large portion of GSoC coding period will overlap with research internship, I assure the community that it will not affect my work and commitment toward GSoC project. In fact, working in a research labratory might help me better appreciate Sympy. I have been contributing to Sympy from November.

I plan to start early and complete important and difficult part of project before first evaluation.

## References

##### Clone this wiki locally
You can’t perform that action at this time.