Atmospheric Modeling (5 ECTS) Lectures: Mon 10.15-12.00, Physicum - - PowerPoint PPT Presentation

atmospheric modeling 5 ects
SMART_READER_LITE
LIVE PREVIEW

Atmospheric Modeling (5 ECTS) Lectures: Mon 10.15-12.00, Physicum - - PowerPoint PPT Presentation

Atmospheric Modeling (5 ECTS) Lectures: Mon 10.15-12.00, Physicum D105 Tue 10.15-12.00, Physicum D104 Exercises: Mon 14.15-16.00, Physicum D105 Atmospheric Modeling (5 ECTS) Teachers Michael Boy, Dynamicum 1D01b


slide-1
SLIDE 1

Atmospheric Modeling (5 ECTS)

  • Lectures:

– Mon 10.15-12.00, Physicum D105 – Tue 10.15-12.00, Physicum D104

  • Exercises:

– Mon 14.15-16.00, Physicum D105

slide-2
SLIDE 2
  • Teachers

– Michael Boy, Dynamicum 1D01b – Sampo Smolander, Dynamicum 1D09a – Kenty Ortega, Dynamicum 1D16b – Risto Makkonen, Physicum B415

  • Course web page

– http://www.courses.physics.helsinki.fi/fys/atmodel/ – slides, links to Fortran-guides, timetable

Atmospheric Modeling (5 ECTS)

slide-3
SLIDE 3
  • Preceding studies:

A basic knowledge in one programming language (Fortran, MATLAB, C+, …) is

  • required. However, we will use the first two

lectures and exercises to give a short and comprehensive introduction and training to

  • Fortran. Each student should have access to
  • ne computer and we will help to install a

Fortran compiler if not already available.

slide-4
SLIDE 4

Course content

  • Introduction to Fortran
  • Introduction to boundary layer meteorology modeling
  • Including chemistry in the model
  • Implementing emissions
  • Modeling aerosol dynamical processes
  • Overview of atmospheric models and complex modeling

techniques

slide-5
SLIDE 5

Course structure

  • Lectures
  • Exercise

– Developing a chemical transport model including

biogenic emissions, chemistry and aerosol dynamics

– Bring your exercise material to the exercise session

  • n memory stick, paper, or your laptop
  • Exam

– Based on lecture content – Your model must be ready before the exam

slide-6
SLIDE 6

Timetable for first week

  • Mon 10.15-12.00

– introduction to course – starting Fortran introduction – 1st exercise given (small Fortran task)

  • Mon 14.15-16.00

– Checking that everyone has an environment for

editing, compiling and running Fortran

  • Tue 10.15-12.00

– Fortran introduction continues – Checking 1st exercise – Example of solving an equation in Fortran

slide-7
SLIDE 7

Atmospheric modeling

slide-8
SLIDE 8

Atmospheric modeling

slide-9
SLIDE 9

Atmospheric modeling

slide-10
SLIDE 10

Emissions

  • anthropogenic (SO2, black carbon, ...)
  • natural (organic compounds, dust, ...)

Meteorology

  • transport, radiative fluxes, ...

Chemistry & aerosols

  • OH, O3, photolysis, ...
  • aerosol formation, condensation, ...

Atmospheric modeling

slide-11
SLIDE 11

Emissions nucleation condensation

c h e m i s t r y chemistry

Atmospheric particle formation

slide-12
SLIDE 12

How to make the computer solve our equations?

slide-13
SLIDE 13

Modern programming languages

C, C++ Python Java Perl Actionscript Matlab OCaml

slide-14
SLIDE 14

Why would we use a programming language from the 50's?

slide-15
SLIDE 15

Fortran (FORmula TRANslation)

  • Simple to learn, less mistakes by beginners
  • Almost all current scientific computational code

is written in Fortran

– Availability of well tested libraries, especially for

mathematics

  • More space for compiler optimization, fast code
  • Portability of code
slide-16
SLIDE 16

#include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }

C++

program hello print *,"Hello World!" end program hello

Fortran

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }

Java

print "Hello, World!"

Python

The classic ”Hello World!” example.

slide-17
SLIDE 17

PROGRAM squarerootexample ! Comments start with an exclamation point. ! Some exponentiation and squareroot computations. ! You will find data type declarations, couple arithmetic operations ! and an interface that will ask values for these computations. IMPLICIT NONE !do not use implicit variable declarations REAL :: x, y ! Command line interface. Ask a number and read it in WRITE (*,*) 'Give a value (number) for x:' READ (*,*) x y=x**2+1 ! exponentiation and addition arithmetic WRITE (*,*) 'given value for x:', x WRITE (*,*) 'computed value of x**2 + 1:', y ! SQRT(y), Return the square root of the argument y WRITE (*,*) 'computed value of SQRT(x**2 + 1):', SQRT(y) END PROGRAM squarerootexample

slide-18
SLIDE 18

Data types

INTEGER An integer number REAL A real number COMPLEX A pair of real numbers used in complex arithmetic LOGICAL TRUE or FALSE CHARACTER A string consisting one or more characters

slide-19
SLIDE 19

!Variables can be initialized at their declaration IMPLICIT NONE ! After declaration and initialization the value of a variable can be ! changed whenever needed INTEGER :: n0 INTEGER :: n1=0 REAL :: a, b REAL :: r1=0.0 COMPLEX :: c COMPLEX :: imag_unit=(0.1, 1.0) CHARACTER(LEN=80) :: place CHARACTER(LEN=80) :: name='James Bond' LOGICAL :: test0 = .TRUE. LOGICAL :: test1 = .FALSE. ! How to define constants? After declaration it can not be changed REAL, PARAMETER :: pi=3.14159

slide-20
SLIDE 20

Precision

  • The precision of a variable may be declared using the KIND-statement

1) SELECTED_INT_KIND(r) 2) SELECTED_REAL_KIND(p) 3) SELECTED_REAL_KIND(p,r) Explanations: 1) integer, range between -10r < n < 10r 2) real, precision at least p decimals 3) real, range -10r < x < 10r and precision at least p decimals INTEGER, PARAMETER :: short=SELECTED_INT_KIND(4) INTEGER, PARAMETER :: double=SELECTED_REAL_KIND(12,100) INTEGER (KIND=short) :: index REAL (KIND=double) :: x,y,z COMPLEX (KIND=double) :: c x=1.0_double; y=2.0_double * ACOS(x)

slide-21
SLIDE 21

Operators

Arithmetic operators

REAL :: x,y INTEGER :: i = 10 x=2.0**(-i) !exponentiation and negation precedence: first x=x*REAL(i) !multiplication and type change precedence: second x=x/2.0 !division precedence: second i=i+1 !addition precedence: third i=i-1 !subtraction precedence: third

Relational operators

.LT. or < !less than .LE. or <= !less than or equal to .EQ. or == !equal to .NE. or /= !not equal to .GT. or > !greater than .GE. or >= !greater than or equal to

Logical operators

.NOT. !logical negation precedence: first .AND. !logical conjunction precedence: second .OR. !logical inclusive disjunction precedence: third .EQV. !logical equivalence precedence: fourth .NEQV. !logical nonequivalence precedence: fourth

slide-22
SLIDE 22

L1 L2 .AND. .OR. .EQV. .NEQV. F F F F T F F T F T F T T F F T F T T T T T T F LOGICAL :: L1, L2 ! How to determine the values of logical expressions ! F means .FALSE. T means .TRUE.

Logical operators

slide-23
SLIDE 23

Control structures

1) IF THEN ELSE (branching) 2) SELECT CASE (selecting) 3) DO (looping)

PROGRAM test_if IMPLICIT NONE REAL :: x,y,eps,t WRITE(*,*)' Give x and y :' READ(*,*)x, y eps = EPSILON(x) IF (ABS(x) > eps) THEN t=y/x ELSE WRITE(*,*)'division by zero' t=0.0 END IF WRITE(*,*)' y/x = ',t END PROGRAM

slide-24
SLIDE 24

Control structures: IF, ELSE, ELSE IF

PROGRAM test_if IMPLICIT NONE REAL :: x,y,eps,t WRITE(*,*)' Give x and y :' READ(*,*)x, y eps = EPSILON(x) IF (ABS(x) > eps) THEN IF (y > eps) THEN t=y/x ELSE IF (ABS(y) < eps) THEN t = 0.0 ELSE t = 1.0 END IF END IF END PROGRAM

slide-25
SLIDE 25

Control structures: SELECT CASE

  • SELECT CASE statements matches the entries of a list against

the case index. Only one found match is allowed.

  • Usually arguments are character strings or integers.
  • DEFAULT-branch if no match found.
  • If there is no CASE DEFAULT and no match found then the

statement following END SELECT is executed

... INTEGER :: i LOGICAL :: isprimenumber ... SELECT CASE (i) CASE (2,3,5,7) ! variables are not allowed on the list isprimenumber = .TRUE. CASE (1,4,6,8:10) ! case value range, form low:high isprimenumber = .FALSE. CASE DEFAULT ! DEFAULT-branch isprimenumber = testprinumber(i) ! function call END SELECT ...

slide-26
SLIDE 26

Control structures: DO, DO WHILE

1) DO-loop with an integer counter (count controlled)

INTEGER :: i, stepsize, NumberOfPoints INTEGER, PARAMETER :: max_points=100000 REAL :: x_coodinate(max_points), x, totalsum ... stepsize=2 DO i = 1, NumberOfPoints, stepsize x_coordinate(i) = i*stepsize*0.05 END DO

2) DO WHILE-construct (condition controlled loop)

totalsum = 0.0 READ(*,*) x DO WHILE (x > 0) totalsum = totalsum + x; READ(*,*) x END DO

slide-27
SLIDE 27

Control structures: DO, DO WHILE

3) DO-loop without loop control

REAL :: x, totalsum, eps totalsum = 0.0 DO READ(*,*) x IF (x < 0) THEN EXIT ! inside loop control, exit the loop END IF totalsum = totalsum + x END DO

4) DO-loop, “repeat until” style

eps = 1000.0*EPSILON(1.0) DO ... !Iterative loop body where ABS(x) is getting smaller and smaller IF (ABS(x) < eps) THEN EXIT ! inside loop control, exit the loop END IF END DO

slide-28
SLIDE 28

Control structures: example

PROGRAM gcd ! Computes the greatest common divisor, EUCLIDEAN ALGORITHM IMPLICIT NONE INTEGER, PARAMETER :: long = SELECTED_INT_KIND(9) INTEGER (KIND=long) :: m, n, t WRITE(*,*)' Give positive integers m and n :' READ(*,*) m, n WRITE(*,*)'m:', m,' n:', n positivecheck: IF (m > 0 .AND. n > 0) THEN main_algorithm: DO WHILE (n /= 0) t = MOD(m,n) m = n n = t END DO main_algorithm WRITE(*,*)'Greatest common divisor: ',m ELSE WRITE(*,*)'Negative value entered' END IF positivecheck END PROGRAM gcd

slide-29
SLIDE 29

Exercise #1

  • Create a Fortran program that

– reads a real number from a file – calls a subroutine, which multiplies the value with pi

  • (subroutine should be in a separate module-file)

– prints the multiplied value to screen

  • The whole program is about 15-20 lines