R7571/work/week12/starting_point3f64baf160e1master
starting_point
README.md
Homework week12 ReadMe
Exercise 1: Code discovery
See below in the readme or in the Doxyfile the descriptions of the newly implemented code and classes
Exercise 2: FFT library linking
See the Cmake list modifications, first, the path for the fft library is found and then, if the option UseFFTW in the CCMake is activated it will be linked with our library ae well as the test ones.
Exercise 3: Interface implementation
FFT interface
The idea here is to be able to use the FFTW with our specific implemented classes. A special wrapping interface is done there. It is done in the following order for the Fast Fourier Transform. First we shold get the size N of the squared matrix (N=number of column, N=number of line) The input signals are then defined as complex values by taking the real and imag parts of the initial matrix(of complexes). the fast fourier transfor plan is then created depending on forward or inverse FFT transform and then executed. The output matrix of complexe is then obtained from the computed 2d signals. Note that for the inverse transform a factor or 1/N^2 is needed for the real and imaginary output parts.
See below in the readme or the doxyfile the fft.hh file description
FFT testings
forward FFT testing:
A matrix is created with values such as we can know its fft transform. We then compare the analytical values to the ones computed with the FFT transfer function.
inverse FFT testing:
A matrix is created with values such as we can know its ifft transform. We then compare the analytical values to the ones computed with the backward FFT transfer function.
FFT compute frequencies:
Compute the wavenumbers with the given size of the signal. See test_fft.cc First, it populates reference frequency matrix, from numpy generated file (see test_fftfrq.py), then uses the FFT::computeFrequencies method and compares the different output. The test was done from several trials with different signal sizes N.
Exercise 4: Solver implementation
Input files
Run *generate_input.py* with a "-h" to obtain the help for the different output wanted.
The generate_input.py python file is used to generate or matrix of particule with the parameters desired for all the next questions and needs. It will return a CSV file consisting of the particles positions, velocities, forces, vectors and mass. Moreover is added to it, the particles' heat distribution, heat rate, and its temperature.
The particles positions will consist of a sqrt(N)xsqrt(N) matrix of points within a domain spans of [-1,1],[-1,1] The name file is at default step-00000.csv in the dumps folder (if not exisiting, it will be created) but it can be changed as wanted (-o). The Heat distribution can be (-H) null, line, or circular. The circular heat radius can be defined there too ( -R Value). The temperature of the particles can be set as randomn within a defined rang or to be homogeneous regarding of what we want to observe. (-T) It is possible to plot the corresponding HEat distribution and the temperature of the particles to verify what we generate as file input. (-p)
1/ ComputeTemperature subclass
Takes the system of particles and compute a time step of integration of temperatures
The temperature subclass is first creating the different temperature and heat distribution matrices. The FFT transform is applied to both of those matrices and the derivative of the Fourier's domain's temperature matrix of complexes is computed. Then the inverse Fourier's transform is applied to obtain the new temperatures regarding the Heat transfert equation after a time step. To that extent, the laplacian from the heat distribution's wavenumbers and the space dimension are computed.
2/ Validating test for homogeneous temperature and no heat flux
First the *generate_input.py* as to be run with the following paraneter: python generate_input.py <a square number of particles> -t -H null in the dumps folder The generate_input.py will provide a input file : " testnull.csv" in the dumps folder with zero heat source and a homogeneous temperature then run the test_heat_equation_fft.cc it will populate the system with the generated input's parameters and check for several time steps the stability in temperature. As the variation over a timestep of the temperature should be equal to zero in that case.
3/ Validating test for lined defined volumetric heat source
First the *generate_input.py* as to be run with the following paraneter: python generate_input.py <a square number of particles> -t -H null
The generate_input.py will provide a input file : " testline.csv" in the dumps folder with the defined heat source and initial temperature at equilibrium then run the test_heat_equation_fft.cc it will populate the system with the generated input's parameters and check for several time steps the stability in temperature. As the variation over a timestep of the temperature should be equal to zero in that case.
4/ Implementation of a python script to generate a heat distribution within a provided radius
To generate the radial heat distribution, run the *generate_input.py* with the following parameters: python generate_input.py <a square number of particles> -H circular -R <your desired radius> -T <random or homogeneous>
To set a zero degrees temperature condition on the boundaries and to be able to keep the different tests, the compute boudaries method would be added in the system evolution. So there would be not interaction in the computationnel process for each time step within the boundaries.
5/ Launching a simulation which will produce dumps observable with Paraview for a grid of 512 × 512 particles.
To launch such a simulation, first the inputs have to be created. In the starting point folder: run the command: <python generate_input.py -n 262144 -H circular -T random -R 0.3>
This will create a matrix of 512*512 material points with as parameters the Heat rate (by default set to 1, but can be modified with the --h option in the command line) the initial temperature and the heat source at each particles location. A default named step-00000.csv file is then created with all those values appended to the one from a simple particle class. The next step is to run the c code. There in the build folder, run the < ./particles 100 1 dumps/step-00000.csv material_point 0.1 >
This will produce 100 steps of a 0.1s timestep and 100 step-00XX.csv files in the dumps folder with the positions of the particles at fields 0,1,2 (spanning it the [-1,1]x[-1,1] space) and their temperatures at field 10 and their heat source location value at field 12. Knowing those elements, paraview can be run and loading all those files, will display (after setting the delimiter space, keeping the values and convertion from table to points with the coordinates defined) the position of all our particles. To view the value and temperature and heate source fields, it can be done from the the property tab, where the colouring of the point can be done with one selected field (if we want to display the temperature field 10 and heat source field 12). To Glyph feature can provide a better display of the points if the visibility is not good enough.
MaterialPoint class
This class is meant to be used as the fundamental entity (i.e. a grid point) to compute the spatio-temporal evolution of heat on a 2D grid. To this effect, the class inherits from the Particle class and defines three additional real number attributes: temperature, heat rate, and heat distribution at the space position where the particles is placed, to be used to solve the heat equation.
matrix.hh file
The *matrix.hh* file defines several 2D template grid classes to work with particles of any type. A particle is supposed to be a point in the grid.
MatrixIterator
This template is an abstract object allowing iteration over Matrix objects. It contains a pointer to a Matrix object as well as a size and an index field referring to the size of the matrix and the current index. It also contains several operators:
- the ++ operator handles iteration by just incrementing the index field
- the * operator (i.e. accessor) returns the content of the i-th element of the matrix (i.e. at the current index)
- the != operator checks for inequality of index fields between the current operator and another operator
Matrix
This template is an abstract data type representing a 2D square (NxN) matrix. Its underlying data container is a 1D std::vector. It also contains several methods and operators:
- the size(), rows() and cols() methods all return the size (N) of the matrix, which is the square root of the number of elements in the 1D vector (NxN)
- the resize() method resizes the matrix by resizing the underlying data vector
- the accessor operator returns, for a pair of indexes (i, j), the element of the 1D vector at the corresponding serialized index (j * N + i)
- the /= operator handles element-wise division of the matrix by a scalar
- the data() method returns the underlying data vector
- the begin() and end() methods return iterator objects that can point to the first and last elements of the matrix, which can then be used in range for loop to iterate over the matrix elements.
MatrixIndexIterator
This template defines a more complex type of abstract operator that inherits from MatrixIterator, but with overwritten accessor element that now returns a 3 elements (i, j, x) tuple, where x is the pointed element, i and j represent the indexes of the element along both matrix dimensions.
IndexedMatrix
This template defines a wrapper around the Matrix template in which the begin and end operators are of type *MatrixIndexIterator*, and can then be used in different types of range for loops. The index() method can be used to convert a "simple" Matrix object into an IndexedMatrix object.
Finally, the std::iterator_traits template is used to define the data type used by the MatrixIterator objects when they are then used in other parts of the code.
MaterialPointsFactory
This class is meant to be used as the interface through which the user can initialize a collection of MaterialPoint objects and then run a simulation to compute the spatio-temporal evolution of temperature across these points. To this effect, it inherits from the generic ParticlesFactoryInterface and redefines the createParticle and createSimulation methods in the specific context of material points (e.g. making sure that number of points is square at initialization).
fft.hh
This file defines an FFT structure that is a wrapper around the FFTW library. In particular, it defines 3 functions to work with signals of complex numbers:
- the transform() function to compute the forward FFT of a complex signal
- the itransform() function to compute the inverse FFT of a complex signal
- the computeFrequencies() function to compute the sample frequencies of the forward FFT of a complex signal (i.e. the coordinates of the signal in the Fourier space). The Laplacian of these frequencies is then used to sovle the heat equation in the Fourier space.
Boundary condition to the temperature field
The boudary condition on temperature is implemented in the code by setting the temperature of the material points at the borders equal to the pre-defined value (e.g. zero in this case). In the compute_temeprature Class, after processing the temperature evolution of the particles, we set the temperature of the particles at the borders equal to 0.