Computational Physics - Department of Physics

(Axel Boer) #1

86 3 Numerical differentiation and interpolation


doublevi = fabs(vec[i]);
if(norm < 100 && vi < 100){
norm = sqrt(normnorm + vivi);
}else if(norm > vi){
norm= sqrt(1.0 + pow(vi/norm,2));
}else{
norm = vi
sqrt(1.0 + pow(norm/vi,2));
}
}
returnnorm;
}


// dump the components of a vector to screen
std::ostream&operator<<(std::ostream& s,constVector& v){// output operator
v.print(s);
returns;
}


3.4 Modules in Fortran


In the previous section we discussed classes and templates in C++. Classes offer several
advantages, such as



  • Allows us to place classes into structures

  • Pass arguments to methods

  • Allocate storage for objects

  • Implement associations

  • Encapsulate internal details into classes

  • Implement inheritance in data structures


Classes contain a new data type and the procedures that can beperformed by the class. The
elements (or components) of the data type are the class data members, and the procedures
are the class member functions. In Fortran a class is defined as aMODULEwhich contains an
abstract dataTYPEdefinition. The example we elaborate on here is a Fortran class for defining
operations on single-particle quantum numbers such as the total angular momentum, the
orbital momentum, the energy, spin etc.
We present theMODULE single_particle_orbitshere and discuss several of its feature
with links to C++ programming.


! Definition of single particle data


MODULE single_particle_orbits
TYPE, PUBLIC :: single_particle_descript
INTEGER :: total_orbits
INTEGER, DIMENSION(:), POINTER :: nn, ll, jj, spin
CHARACTER*10, DIMENSION(:), POINTER :: orbit_status, &
model_space
REAL(KIND=8), DIMENSION(:), POINTER :: e
END TYPE single_particle_descript
TYPE (single_particle_descript), PUBLIC :: all_orbit, &
neutron_data, proton_data
CONTAINS


! various member functions here

Free download pdf