VERB_code_2.3
Main.cpp File Reference

This is the main program file. More...

#include <valarray>
#include <math.h>
#include <ctime>
#include <time.h>
#include "../Logging/Output.h"
#include "../VariousFunctions/variousFunctions.h"
#include "../Diffusion/PSD.h"
#include "../Grid/Grid.h"
#include "../Grid/BoundaryConditions.h"
#include "../Grid/AdditionalSourcesAndLosses.h"
#include "../Parameters/Parameters.h"

Go to the source code of this file.

Macros

#define _CRT_SECURE_NO_DEPRECATE
 No "depreciated" warnings.
 
#define __VERB_VERSION_NUMBER__   "2.3.0.0"
 Number of current VERB code version.
 

Functions

int main (int argc, char *argv[])
 Main code. More...
 

Variables

Parameters_structure parameters
 Parameters structure, with all parameters from the parameters.ini file. The default parameters defined in the constructor.
 

Detailed Description

This is the main program file.

Author
Developed by Dmitry Subbotin under supervision of the PI Yuri Shprits.

Code below corresponds to the commented part. It works only in uncommented state.

// \def DEBUG
// \brief Reserved for debug purposes if defined
// #define DEBUG
// \def DEBUG_MODE
// \brief define DEBUG_MODE value. Checks if memory was alocated for a matrix at each use.
// \warning Additional checks and outputs for debbugging if defined. MUCH SLOWER, FOR DEBUG ONLY!
// #define DEBUG_MODE

Definition in file Main.cpp.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Main code.

NOTE: The code bodies displayed below are abbreviations of the functions and variable names for simplicity's sake. To see the full code, look at source code.

Parameters
[in]argv[]The name of the parameter file
argcNumber of arguments, mandatory automatic parameter (does not need to be specified).

Step 1: Creating Grids

Create the radial and local diffusions grids from the given parameters specified by Parameters.ini

radialDiffusionGrid.Create_Grid(...);
localDiffusionsGrid.Create_Grid(...);

Output the grids to plt files for MATLAB to read

localDiffusionsGrid.Output("./perp_grid.plt");
radialDiffusionGrid.Output("./rad_grid.plt");

Step 2: Set Boundary Conditions

Loading the boundaries that should be loaded from a file
Check the parameters, if the type of boundary is defined we can load the boundary.
Else the default value for boundary type is BCT_CONSTANT_PSD
The boundary defined only on the slice of the grid
See Matrix3D::xSlice and Matrix3D::ySlice

if (parameters.L_UpperBoundaryCondition.type == "BCT_FILE" || "BCT_FILE_GRID" || "BCT_MULTIPLE_FILES") {
L.UpperBoundaryCondition.LoadBoundaryCondition(
parameters.L_UpperBoundaryCondition,
radialDiffusionGrid.epc.arr.xSlice(radialDiffusionGrid.L.size-1),
radialDiffusionGrid.alpha.arr.xSlice(radialDiffusionGrid.L.size-1));
}
if (parameters.pc_LowerBoundaryCondition.type == "BCT_FILE" || "BCT_FILE_GRID" || "BCT_MULTIPLE_FILES") {
pc_LowerBoundaryCondition.LoadBoundaryCondition(
parameters.pc_LowerBoundaryCondition,
localDiffusionsGrid.L.arr.ySlice(0),
localDiffusionsGrid.alpha.arr.ySlice(0));
}

create initial radial diffusion PSD

psdRadialDiffusion.Create_Initial_PSD();

making boundary conditions using corresponding slice method for L, pc, and alpha where GridElement represents L, pc, or alpha, and GridElementSlice represents xSlice, ySlice, and zSlice respectively

GridElement_LowerBoundaryCondition.MakeBoundaryCondition(..., GridElementSlice(0));
GridElement_UpperBoundaryCondition.MakeBoundaryCondition(..., GridElementSlice(size-1));

create local diffusions PSD, and interpolate them with radial PSD

psdLocalDiffusions.Create_Initial_PSD();
psdLocalDiffusions.Interpolate();

create and obtain all diffusion coefficients, stored into function arguments

CreateAllDiffusionCoefficients(DLL, Daa, Dpcpc, Dpca, DaaLpp, DpcpcLpp, DpcaLpp, parameters, radialDiffusionGrid, localDiffusionsGrid);

Update the boundary conditions for L if need be

L_LowerBoundaryCondition.Update();
L_UpperBoundaryCondition.Update();

Update radial diffusion coefficients if using radial diffusion

DLL.MakeDLL(L, pc, alpha, Kp, DLLType);
}

Step 3: Calculate Radial Diffusion PSD

Calculate diffusion for radial distance, given diffusion coefficients, grid elements, and boundary conditions (including boundary flux)
check PSD::Diffusion_L for implementation

psdRadialDiffusion.Diffusion_L(timeStep, Lpp[iteration], DLL, L, pc, alpha, Jacobian, LowerBoundaryCondition.arr, UpperBoundaryCondition.arr * Bf[iteration], LowerBoundaryCondition.calculationType, UpperBoundaryCondition.calculationType, tau[iteration], tauLpp[iteration]);

How to calculate BF - it is a boundary condition file

μ = μ(L_boundary)

\( Bf = \frac{Flux-data(L\_boundary, μ)}{ pc(L\_boundary, μ) } / [ \frac{J\_L7}{pc(L=7, μ)} * \frac{steady\_state(L\_boundary)}{steady\_state(L=7)} ] \)

Interpolate from radial to local diffusion grids so that captures upper boundary condition with ySlice max size

psdLocalDiffusions.Interpolate(..., psdRadialDiffusion.arr.ySlice(radialDiffusionGrid.pc.size-1));

Update everything: pc-boundaries, alpha-boundaries, diffusion coefficients

if (localDiffusionsGrid.pc.size > 1) {
pc_LowerBoundaryCondition.Update(iteration, psdLocalDiffusions.arr.ySlice(0));
pc_UpperBoundaryCondition.Update(iteration, psdLocalDiffusions.arr.ySlice(radialDiffusionGrid.pc.size-1));
}
if (localDiffusionsGrid.alpha.size > 1) {
alphaLower...Update(zSlice(0));
alphaUpper...Update(zSlice(...);
}
Dpcpc.ActivateAndScale(simulation_time, parameters.Kp[iteration]);
DpcpcLpp.ActivateAndScale(...);
}
Daa...;
DaaLpp...;
}
Dpca...;
DpcaLpp...;
}

Step 4: Calculate Local Diffusion PSD

calculate Diffusion for pc and alpha if approximating with Block method
checks to see that grid is 3D by checking pc and alpha size
see PSD::Diffusion_pc_alpha for details on matrix calculations

if (parameters.psdLocalDiffusions.approximationMethod == "AM_Block_C" || "AM_Block_LR") {
if (localDiffusionsGrid.pc.size > 1 && localDiffusionsGrid.alpha.size > 1) {
psdLocalDiffusions.Diffusion_pc_alpha(...);
}
}

calculate Diffusion for pc, alpha, or MixedTerms if approximating with Split method checks to see that grid has dimension in respective element see PSD::Diffusion_pc, PSD::Diffusion_alpha, and PSD::DiffusionMixTermExplicit for details on matrix calculations

if (parameters.psdLocalDiffusions.approximationMethod == "AM_Split_C" || "AM_Split_LR" || "AM_Split_C_oldway" || "AM_Split_LR_oldway") {
if (parameters.useEnergyDiffusion && localDiffusionsGrid.pc.size > 1) {
psdLocalDiffusions.Diffusion_pc(...);
}
if (useAlphaDiffusion && alpha.size > 1) {
Diffusion_alpha(...);
}
if (useEnergyAlphaMixedTerms && pc.size > 1 && alpha.size > 1) {
DiffusionMixTermExplicit(...);
}
}

calculate and update sources and losses

SL.Update(iteration, parameters.SL, localDiffusionsGrid);
psdLocalDiffusions.SourcesAndLosses(...);

checks for negative PSD values, and sets them to floating point zero

if (psdLocalDiffusions.arr[il][im][ia] < VC::zero_f) {
psdLocalDiffusions.arr[il][im][ia] = VC::zero_f;
}

interpolate from local diffusions to radial diffusion grid

psdRadialDiffusion.Interpolate();

Definition at line 195 of file Main.cpp.