0% found this document useful (0 votes)
14 views

Assignment 3

Uploaded by

ankithcs3328
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Assignment 3

Uploaded by

ankithcs3328
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ID2090: Introduction to Scientific Computing Jan-May 24

Introduction to Scientific Computing


Indian Institute of Technology, Madras
Assignment 3
Maximum Marks: 100 Assigned: March 18, 2024
Deadline: March 31, 2024
General Instructions
• You are expected to use the VM for this assignment. Create a directory in your home directory called
assignment_3. Use this directory to work on the assignment.
• For each question (for question i), create a bash file called question_i.sh in the assignment_3 directory.
This bash file should contain the necessary code or commands to solve the respective question.
• We will be using an evaluation script to assess and evaluate your submission. Therefore, kindly ensure
that the naming convention (as mentioned in usage section of each question) is strictly adhered to, and
that the output which you get from running a script, matches the structure of the sample output.
• For submission, upload the MD5 checksum of the assignment_3 directory on Moodle. You can use the
following command. Make sure that you are in assignment_3 directory for this command to work as
intended.
find ./assignment_3/* -exec md5sum {} \; | cut -f 1 -d " " | md5sum
• After submitting the MD5 checksum on Moodle, do not update any file(s). Doing so will change your
checksum, and your submission will not be evaluated.
• You are free to read through various resources. However, please ensure that you cite your sources to avoid
plagiarism. Any detected instances of plagiarism will result in penalties.
• Please contact your assigned TA for any doubts or queries regarding this assignment.
• The soft deadline for this assignment is 11:59 PM on March 31, 2024. Submissions after this deadline
will face a linearly increasing penalty of 10 marks per late day.
• The hard deadline for this assignment is 11:59 PM on April 7, 2024. Submissions after this deadline
will not be evaluated.

[100 marks] 1. The most common use of Makefile is to manage dependencies of source files of programs during com-
pilation while the programs are being compiled.
In large C/C++ projects, rebuilding the program can take significant time and effort during the compi-
lation and linking of source files. Manually performing this task is error-prone and tedious. Make tracks
dependencies, compiles, and links the source files automatically during the “build phase”, and keeps
track of changes, thereby recompiling programs only when necessary during the “test phase”.

In this assignment, you are provided a C++ library and are tasked with
[40 marks] (a) completing functions in the library,
[60 marks] (b) creating a Makefile to compile and return an executable.
Note: This assignment does not require you to possess prior knowledge about C++, about Meshing, or
any numerical technique.

1
ID2090: Introduction to Scientific Computing Jan-May 24

Meshing is a technique commonly used in numerical methods like Finite Element Analysis (FEA) or in
Computational Fluid Dynamics (CFD). Meshing involves discretizing a continuous domain Ω over which
a function f needs to be computed.
For example, consider a simple 2-dimensional domain Ω = [0, 1]2 (Fig. 1a) over which the function
f (x, y) = sin (πx) sin (πy) has to be evaluated. The first step is to mesh the domain Ω into smaller
regions (Fig. 1c, 1b), followed by computing f as a piece-wise linear approximation over the domain.
Figure 1d is the Analytical f over the domain Ω. Figures 1f and 1e are Numerical forms of f computed
over the domain Ω for mesh sizes 0.1 and 0.05 respectively. It is easy to verify that a finer mesh yields
a more accurate solution.

1.0 1.0

1.0

0.8 0.8

0.8

0.6 0.6

0.6
y

y
0.4 0.4
y

0.4

0.2 0.2

0.2

0.0 0.0

0.0 0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0
x x
0.0 0.2 0.4 0.6 0.8 1.0
x

(b) Meshed Domain (c) Meshed Domain


(a) Domain Ω = [0, 1]2 (mesh size = 0.1) (mesh size = 0.05)

0.8 0.8
f (x, y)

f (x, y)
0.8 0.6 0.6
f (x, y)

0.4 0.4
0.6
0.2 0.2
0.4
0.0 0.0
0.2

0.0 1.0 1.0


0.8 0.8
1.0 0.6 0.6
0.8 0.0 0.0
0.2 0.4 y 0.2 0.4 y
0.6 0.4 0.4
0.0 0.6 0.2 0.6 0.2
0.2 0.4 y x 0.8 x 0.8
0.4 0.0 0.0
0.2 1.0 1.0
0.6
x 0.8 0.0
1.0

(e) Numerical Solution (f) Numerical Solution


(d) Analytical Solution (mesh size = 0.1) (mesh size = 0.05)

Meshing is an effective strategy for computing f , especially for complex geometries for which analytical
expression for the boundaries cannot be established. It is trivial that for f = 1, the method returns the
area of the domain.
This strategy can also be extended to solving differential equations over domains Ω. For instance, solving
the Navier-Stoke’s Equation in Fluid Mechanics or the Constitutive Equation in Solid Mechanics employ
this strategy.

2
ID2090: Introduction to Scientific Computing Jan-May 24

In this assignment, you are tasked to find the area of IIT Madras1 using a custom library written in
C++ (Program files are available in /var/home/Jan24/assignments/assignment_3).
[40 marks] (a) The majority of the implementation has already been done. However, a few functions are not
fully implemented. The first part of the assignment requires you to locate partially implemented
functions and complete them. (These functions are explicitly marked with comments that start
with “TO DO”. You may use a combination of find, cat and grep to locate them).
The library is structured as
assignment 3
geometry
point.h & point.cpp
line.h & line.cpp
triangle.h & triangle.cpp
main.cpp
map.txt
– point file contains the necessary constructs to represent a Point(x, y),
– line file contains the necessary constructs to represent a line segment that connects Point p1
and Point p2,
– triangle file contains the necessary constructs to represent a triangle formed by line segments
Line(p1, p2), Line(p2, p3) and Line(p3, p1),
– main.cpp file contains the scripts to read the mesh data from a .txt file and also to compute
the area enclosed by a triangle,
– map.txt2 is a space separated file containing the coordinates of the vertices of the triangulated
mesh (Fig. 2b).
Note: This assignment does not require you to possess prior knowledge about C++ (or its syntax).
The sub-part (a) requires you to use only the complete logic of the code and not syntax.

Hint: Given any domain, its mesh (triangulated), the area enclosed by the domain can be computed
as X
Area of Domain = Area of Triangle t.
t ∈ Mesh

The Area of Triangle t can be computed using Heron’s Formula from its vertices (xj , yj ), j ∈
{1, 2, 3}.
[60 marks] (b) Since the library is made of multiple C++ files, compiling them requires more than one terminal
command. Create a Makefile in the directory that identifies all .cpp files, compiles and links them,
and creates an executable for main.cpp as main. The Makefile should have the following functions
– make: Compile and create the executables,
– make clean: Remove the executables.

1 Inspired from ME5204: Finite Element Analysis (Jul-Nov 23)


2 Obtained using AutoCad and meshed using GMSH

3
ID2090: Introduction to Scientific Computing Jan-May 24

A B C D E F G H I J K L M N O

1 INDEX 1
N
ACADEMIC ZONE HOSTEL ZONE RESIDENTIAL ZONE
W E
DEPARTMENTS HOSTELS 1. BOSE EINSTIEN GUEST HOUSE H-13&I-13
2 2
1. AEROSPACE ENGINEERING D-13 1. ALAKANANDA K-18&L-18 2. K.V SANGATHAN OFFICE H-11&H-12
2. BIO-TECHNOLOGY
3. CHEMICAL ENGINEERING
D-15
E-14
2. BRAHMAPUTRA
3. CAUVERY
H-19&I-19
H-18
3. KENDRIYA VIDYALAYA SCHOOL
4. COMMUNITY HALL & LADIES CLUB
G-12,13&H-12,13
L-9&M-9
S
4. APPLIED CHEMISTRY BLOCK G-16 4. GANGA K-17&L-17 5. CRECHE L-8
5. BUILDING SCIENCES BLOCK E-15 5. GODAVARI J-17&J-18 6. DIRECTOR'S QUARTERS I-13
6. COMPUTER SCIENCE & ENGINEERING E-15
3 6. YAMUNA K-17&L-17 7. POST OFFICE H-12 SARDAR PATEL ROAD
EXIT ENTRY
3
7. ELECTRICAL ENGINEERING F-16 TNEB

7. KRISHNA G-19&H-19,H-20 8. PUMP HOUSE M-4 13


OLD OUT GATE

8. ENGINEERING DESIGN C-15 SECURITY


CABIN
SECURITY

8. MAHANADI L-16 9. SBI (STATE BANK OF INDIA) H-12&H-13 CABIN

BUS STOP
9. HUMANITIES & SCIENCES G-14&G-15 YOU ARE
9. MANDAKINI L-17&M-17 10. CANARA BANK M-10 8 HERE
MAIN UG SUMP
10. DEPARTMENT OF MANAGEMENT STUDIES I-14 PUMP HOUSE

10. NARMADA I-18 11. TELEPHONE EXCHANGE & SUMP


11. MATHEMATICS G-15 WATER SUPPLY SUB-DIVISION

11. PAMBA K-16 MAINTENANCE OFFICE M-10 SS1


12. MECHANICAL ENGINEERING F-14&F-15
4 12. SARASWATHI J-18 12. TEMPLES N-6&M-6 OHT 4
13. METALLURGICAL & MATERIALS ENGINEERING E-14
13. SARAYU I-14 13. TNEB M-3
14. OCEAN ENGINEERING C-14
15. PHYSICS G-16 14. SHARAVATHI H-15&I-15 14. VANAVANI SCHOOL K-8,K-9&L-8,L-9
15. SINDHU K-16 15. NEW C2 TYPE QTRS M-9&M-10

CENTRES 16. TAMIRAPARANI K-16 16. STAFF CLUB L-9


16. NEW ACADEMIC COMPLEX F-12&F-13 17. TAPTI I-18&I-19 17. SHOPPING CENTRE M-10
5 UE 5
17. CENTRAL ELECTRONIC CENTRE F-15&F-16 18. TUNGA, BHADRA G-17&G-18 18. G1 TYPE QTRS H-11 N AVEN
N UE BON
S A VE
18. CENTRAL WORKSHOP F-13&F-14 19. SABARMATI HOSTEL H-15&I-15 D RA

E
MA

AVENU
19. CENTRE FOR CONTINUING EDUCATION G-13 D - 16 (1-6)

MOH 1-24 D - 17 (7-12)


20. CENTRAL PHOTOGRAPHIC SECTION G-15 COMMON FACILITIES

BONN
D1 25 - 48
D - 18 (13-18)
21. CENTRAL GLASS BLOWING SECTION G-15 20. MAINTENANCE OFFICE I - 17 D - 32 (1-12)
D1 49 - 72
D - 19 (19-24)

6 22. CENTRE FOR COMPOSITE TECHNOLOGY D-13 21. HIMALAYA (MEGA MESS II) I-17&J-17 D1 73 - 96
6
23. DR.DESHPANDE CENTRE F-15&F-16 22. HOSTEL MANAGEMENT (CCW) K-17 C2-03 (1-12)
D - 20 (25-30)
D - 31 (1-12)

Bus Stop
(CENTRE FOR SYSTEM & DEVICE / FOSAPP) D - 21 (31-36) JALAKANDEESWARAR TEMPLE
23. QUARK J-18 D - 30 (1-12)
12
24. DR.SENAPATHY CENTRE (COMPUTER CENTRE) E-15 D - 22 (37-42)
24. OAT (OPEN AIR THEATRE) H-15&H-16

UE
25. MATERIAL SCIENCE RESEARCH CENTRE (MSRC) F-15 D - 23 (42-48) C - 12 (32-37)

AVEN
25. SAC (STUDENT ACTIVITY CENTRE) K-15 OZONE SHED
26. NCCRD D-13 D - 24 (49-54)

AS
26. SFC (STUDENT FACILITY CENTRE) I-17 C - 11(26-31)
27. R & AC E-13 D - 25 (55-60)

MADR
7 27. SKATING TRACK (SANGAM GROUND) J-18&K-18 15TH CROSS ROAD
7
28. SOPHISTICATED ANALYTICAL INSTRUMENTS FACILITY G-15
28. STP (SEWAGE TREATMENT PLANT) M-15 D - 27 (67-72)D
C 1 - 8 (20-25)

(SAIF) - 26 (61-66)

14TH CROSS ROAD C 1&2


29. MRI / MRS F-12 29. SWIMMING POOL J-15&J-16 E1-25 (1-12) D - 28 (73-78)
C11 & 12
C31 & 32

C91&2 C 29&30
D - 29 (79-84)
30. THARAMANI GUEST HOUSE H-17&I-17

ROAD
C3&4

AV ENUE
SSQ2 E1-24 (1-12) ROAD C 14A&14B
CROSS C 27&28
13TH
COMMON FACILITIES 31. TEMPLE H-17
MSQ-3

ROAD
C1 - 9 (3-8)
E1-23 (1-12) C5&6

LOOP
C15 & C16
C 25&26
29. ADMINISTRATIVE BLOCK G-14&H-14 32. VINDHYA MESS I-14
C1 - 7 (13-18)

8 8

Y AR

2ND LOOP
C7&8
C 18 & 17 C 24 & 23

3RD
C 1 - 6 (7-12)
30. CAFÉ COFFEE DAY / 33. NCC BUILDING I-16 VANA VANI SCHOOL
14

AD
C 21 & 22

5 C 9 & 10

HIGGINBOTHAMS BOOK HOUSE H-14 34. GFRG BUILDING H-17 14 CRECHE


C1 - 5 (1-6)
C 19 & 20

Bus Stop
35. SFC 2 H-15
31. BATTERY RESEARCH CENTRE G-14 G-7
COMMUNITY HALL
14
36. NILGIRI MESS G-19 4 C2-1 (1-12)
C2-2 (1-12)
32. CAMPUS CAFE & FOOD COURT F-13 G-5
G-6

BANY
Bus Stop OHT
H CROSS ROAD
12 T 16
33. CENTRAL LIBRARY H-14 ABBREVIATION STAFF CLUB

AN
D-14 (55-60) 4 15
9 F1(1-12)D-13 (49-54) D - 7 (7-12) LADIES CLUB KURINJI (C2-7)
9

AVEN
15
34. HOSPITAL G-12&G-13 SFC STUDENT FACILITY CENTRE MSQ1
E1-12 (25-30)
E1-13 (31-36) MARUTHAM (C2-6)

UE
F2 13-24

ROAD
D - 6 (1-6)
SSQ1 (1-12) SCHOOL GROUND
35. INDUSTRIAL CONSULTANCY & SPONSORED OHT OVERHEAD WATER TANK

AD
MSQ2 (13-24)E1-11 (19-24)
F4 C1- 01(1-6) 15
F3 25-36
N UE

RY RO
NEITHAL (C2-4)

6TH CROSS
15
RESEARCH CENTRE (IC&SR) G-13&G-14 ZIGZAG ROAD B9-9&8

SS ELECTRICAL SUBSTATION F5
AVE MAINTENANCE OFFICE/ MULLAI (C2-5)

ZIGZAG ROAD
NN
TELEPHONE EXCHANGE
G-3 B8 6 & & CANARA BANK
G-4
36. JEE / GATE OFFICE C-15 E1-1 (61-66) G-2
BO 10
A
SPH SEWAGE PUMP HOUSE E1-3 (6-12) G-1 1ST
C1 - 3 (9-14)

LOOP
C1 - 2 (15-20)
17
UND
BO
SHOPPING CENTRE
37. NEW SPORTS COMPLEX G-17&H-17 11TH CROSS E1-2 (1-6) ROAD
SS2
C1 - 4 (3-9)
ROAD
10 STP SEWAGE TREATMENT PLANT E1-5 (7-12)
10TH CROSS SS3 LPG
10
38. CFD HTML ANNEX D-13 ROAD
E1-4 (1-6)

C7 3 & 4
C8 1&2
B7 1 & 2
E1-7 (7-12
E1-6 (1-6) 5TH
39. NEW ACADEMIC COMPLEX - II D-14 9TH CROSS CROSS
ROAD ROAD
B TYPE
E1-9 (7-12)E1-8 (1-6)

40. CFI LAB F-13 E1-10 (13-18)


8TH CROSS ROAD
PANDIYA
LAKE
E1-14 (19-24)
Bus Stop OHT

LA
E1-16 (7-12) B- 3 & 4
C-06- 13&14 CHILDREN’S PARK B-1 & 2

KE
E1-15 (1-6)
E1-17 (13-18 O.H.S.R B5&6
IEW

V
E1-18 (19-24)
E1-20 (31-36) C-05-4&5 B 17 & 18
B TYPE SUMP B7&8
D-12 (7-12)
E1-19 (25-30)
Z2 (13-24) 4TH
11

R
Z-1 (1-12)
CROS
B TYPE
B TYPE
11

OA
B 9 & 10
Z3 (24-36)
D10 (16-210D-11 (1-6) CHOLA SS B 15 & 16
S ROAD

D
E - 11 (13-18)
18 C-04-4&5
B TYPE
B 13 & 14
G1 TYPE B 21 & 22
B TYPE B 11 & 12
QTRS
D - 8 (18-23)D - 9 (6-110 B 19 & 20
E - 6 (7-12)
E - 5 (13-18) CHERA
E - 10 (1-6)
2 7TH CROSS ROAD 3RD CROSS ROAD
B-4- 2 & 3
K.V. SANGATHAN OFFICE
E - 4 (19-24)E - 13 (31-36) BW - 25
E - 9 (19-24)
Bus Stop BE- 24
B-3- 2 & 3
E - 12 (25-30) D-05 (14-19)
E - 3 (7-12)
E - 8 (13-18)
C-03-4&5
C-1 1&2
2ND
E1-21 22-27)C1- 10 (16-21) OHT D-15 (25-30)
CROSS
12
E1-22 (28-33)
1ST CROSS E - 2 (1-6)
E - 7 (7-12)
Bus Stop
D-04 (8-13)
B2- 2&3
ROAD
LAKE 12
ROAD E - 1 (10-15)POST OFFICE
D-01 (1-6)
B-10-3&7

7 D-03 (1-6)
D-02 (4-9)

1ST B1-1&2

NEW ACADEMIC COMPLEX


29 KENDRIYA VIDYALAYA SCHOOL CROSS
SS4 MRI / MRS 34 STATE BANK OF INDIA
9 ROAD
16 HOSPITAL PEELIAMMAN TEMPLE
R & AC

E
EN U
38
CFD HTML
ROCKET &
6
ANNEX
MISSILE LAB GD LAB 27 DIRECTOR'S QUARTERS
PROPELLANT COMBUSTION

BON N AV
CAMPUS CAFE /
BOSE EINSTIEN GUEST HOUSE
IMPACT TESTING LAB FOOD COURT
1
13 32
METAL FORMING

SCHOOL GROUND
13
22 AEROSPACE ENGINEERING

NCCRD SS17 SS16 Bus Stop


COMPOSITES TECHNOLOGY CENTRE FOR CONTINUING EDUCATION 19

STADIUM
HTTP & IC ENGINE IC & SR
MEMH
SS13 SS14 1 CFI LAB

18 40 35
SS5 CENTRAL WORKSHOP
31 10 SPH
BATTERY DEPARTMENT OF
RESEARCH GC

MANAGEMENT STUDIES
13 CENTRE 30
3 CAFÉ COFFEE DAY / HIGGINBOTHAMS BOOK HOUSE
NEW ACADEMIC HTML CHEMICAL ENGINEERING RANGANATHAN BUILDINGS - MES
COMPLEX - II FLUID MECH
TTML 33 13
13 L
39 METALLURGY
14 14
29
U
HOSTE
SARAYU HOSTEL 14
DEPARTMENT OF OCEAN ENGINEERING SARAY
ADMINSTRATIVE BLOCK CENTRAL LIBRARY POND

NUE
Bus Stop MECHANICAL SCIENCE BLOCK

32
OHT

AVE
VINDHYA MESS
SS22
12 9

EL
AC PLANT SHARAVATHI HOSTEL
SUMP 35 14

HOST
STRUCTURAL ENGINEERING SFC 2
36 BIO TECH 5 WAY TO
8 GATE/JEE OFFICE BLOCK 2 20
BUILDING SCIENCES BLOCK IITM RESEARCH PARK

RAMP
SS7 25
15 ENGINEERING DESIGN
2
BIO TECH
MSRC HUMANITIES & SCIENCES
SABARMATI HOSTEL 15
19
OZONE SHED

RP
SAC
24 21
3D PRINTED ESB 25
HOUSE SS8 PG SENAPATHY CENTRE EXTENSION
6 23
24 STP
EWRE HYDRAULIC LAB
COMPUTER
SCIENCE OPEN AIR THEATRE NURSERY POND
17 28
ELECTRICAL SCIENCE
15 SWIMMING POOL
DR.DESHPANDE CENTRE
7 SS11 29
IOC DIESEL BUNK
SS9
P LA
YF
SECURITY CABIN IEL
TOILET DA
Bus Stop
CHEMPLAST CRICKET GROUND VEN SS12 16
16 AUTO SHOP
FOOT BALL GROUND HOCKEY GROUND UE
4
TAMIRAPARANI HOSTEL
MAHANADI HOSTEL
16
BALL BADMINTON COURT WARDEN QUARTERS
SINDHU HOSTEL
APPLIED CHEMISTRY BLOCK
33 8
NCC BUILDING
15
PAMBA HOSTEL
SS22

BASKET BALL & TENNIS COURT 31


TEMPLE GANGA HOSTEL
MAINTENANCE OFFICE 22 COCONUT PLANTATION
20 HIMALAYA HOSTEL MANAGEMENT
SS15 34 4
VOLLEY BALL COURT GFRG BUILDING 21
OHT
26 MANDAKINI HOSTEL
37 THARAMANI GUEST HOUSE SFC
SPORTS COMPLEX SS20 9
17 30 17
BHADRA HOSTEL
Bus Stop SS19
18 Bus Stop
Bus Stop GODAVARI HOSTEL 6
UG SUMP

NARMADA HOSTEL
5 OHT YAMUNA HOSTEL
SS23
10
23
TUNGA HOSTEL
3 QUARK 27 RO - 1
18 CAUVERY HOSTEL
SANGAM GROUND
18 1 ALAKANANDA HOSTEL
18
SKATING TRACK
SARASWATHI HOSTEL

SS21 TAPTI HOSTEL 12

PARKING
17
SECURITY
36

CYCLE
CABIN
NILGIRI
MESS
7
KRISHNA HOSTEL

19 2 19
0 100 200 400 600 800
BRAHMAPUTRA HOSTEL

Meters

20 20

Y
A B C D E F G H I J K L M N O

Z X
LAYOUT OF BUILDINGS - INDIAN INSTITUTE OF TECHNOLOGY MADRAS
AS ON 07-07-2021

(a) Scale: 800 m = 1.7094 units (b) Meshed Map (mesh size = 0.5)

Figure 2: Map of IIT Madras

Input:
map.txt
n
x_11 y_11 x_12 y_12 x_13 y_13
x_21 y_21 x_22 y_22 x_23 y_23
and so on . . . where (x_ij, y_ij) represents the x-coordinate and the y-coordinate of the j th vertex
(j ∈ {1, 2, 3}) of the ith triangle in the mesh and n is the total number of points.

Usage:
make && ./main map.txt

Output: (in m2 )
2479646.4320

Note: Actual reported area of IIT Madras around 2500000 m2 .

You might also like