Assignment 3
Assignment 3
[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
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
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.
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
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
E
MA
AVENU
19. CENTRE FOR CONTINUING EDUCATION G-13 D - 16 (1-6)
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)
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
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)
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
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
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
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
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)
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