Parameter study in 2D parameter space

Problem description

This tutorial is an extension to ParameterStudy1DDemo, and thus also has very similar code structure. It shows how to do a parameter study by using the autonumber function in DPMBase. This tutorial treats the case in which a 2D parameter study has to be performed. The difference with ParameterStudy1DDemo is only the addition of the second dimension of the parameter study. Only the differences with respect to the 1D case are given here, as it is assumed that one looks at ParameterStudy1DDemo first. In this case ParameterStudy1D is extended to change both particle radii, and thus a parameter space can be created. This parameter space is also visualised in the image below.

Schematic overview of a 2D parameter study. Definitions of i, j, dim1 and dim2 will be given later.

Headers

The following headers are included:

These are the headers needed for this tutorial.

Before the main function

The main class inherits from Mercury3D.

This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:37
[PAR_SIM2D:headers]
Definition: ParameterStudy2DDemo.cpp:35

All steps needed in order to create this class have been explained below.
Step 1: (Private) Member variables.
Compared to ParameterStudy1DDemo a new variable is added, dim2_, that stores the information of the second dimension of the parameter study. Furthermore the size of studyNum is now also incremented by 1, as it stores information of both dimensions. studyNum is now build up as follows: The first entry is (still) storing an integer value giving information of the completeness of the study. The second and third entry store the current run in the first and second dimension respectively.

int dim1_ = 0;
int dim2_ = 0;
std::vector<int> studyNum;

Step 2: Set- and Get-functions for private member variables.
The set- and get-functions are extended to incorporate the second dimension with respect to ParameterStudy1DDemo.

void setStudyDimensions(int dim1, int dim2)
{
dim1_ = dim1;
dim2_ = dim2;
}
std::vector<int> getCurrentStudyNum()
{
}
std::vector< int > get2DParametersFromRunNumber(int size_x, int size_y) const
This turns a counter into 2 indices which is a very useful feature for performing a 2D study....
Definition: DPMBase.cc:698

Step 3: Create the particle species.
Nothing changed with respect to ParameterStudy1DDemo

Step 4: Setup the initial conditions.
The only change with respect to ParameterStudy2DDemo is that now the second particle is dependent on the second dimension of the parameter study.

void setupInitialConditions() override
{
studyNum = getCurrentStudyNum();
createSpecies();
P.setSpecies(speciesHandler.getObject(0));
// Create 2 particles
particleHandler.copyAndAddObject(P);
particleHandler.copyAndAddObject(P);
//Set up the stuff that is the same for all runs
particleHandler.getObject(0)->setPosition(Vec3D(0.006,0.005,0.0));
particleHandler.getObject(1)->setPosition(Vec3D(0.004,0.005,0.0));
particleHandler.getObject(0)->setVelocity(Vec3D(-0.1,0.0,0.0));
particleHandler.getObject(1)->setVelocity(Vec3D( 0.1,0.0,0.0));
// We have two different size particles for both left and right particles
// The value gets updated based on what studyNum is, these come from the automatic counter
particleHandler.getObject(0)->setRadius(0.0001*studyNum[1]);
particleHandler.getObject(1)->setRadius(0.0001*studyNum[2]);
}
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:37
Definition: Vector.h:51
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73

Step 5: Setting up the parameter study.
Nothing changed with respect to ParameterStudy1DDemo, both actionsBeforeTimeLoop() and actionsAfterSolve() are the same.

Step 6: Creating the main function.
The only difference with ParameterStudy2DDemo is that now both study dimensions have to be set.

problem.setStudyDimensions(2,2)

This line results in 4 simulations being run, in which all 4 combinations of particle sizes are solved.

int main(int argc UNUSED, char *argv[] UNUSED)
{
//Problem constructor, using class definition above
// Setup the study dimensions that you want to perform
problem.setStudyDimensions(2,2);
// Setup the automatic numbering system (create/read COUNTER_DO_NOT_DEL file)
problem.autoNumber();
// Setup output file name
problem.setName("ParameterStudy2DDemo");
// General simulation settings
problem.setTimeStep(1e-5);
problem.setTimeMax(0.1);
problem.setSaveCount(5000);
problem.setXMin(0.0);
problem.setXMax(1.0);
problem.setYMin(0.0);
problem.setYMax(1.0);
problem.setZMin(0.0);
problem.setZMax(1.0);
// Solve the problem
problem.solve();
// Give a successful exit code to the terminal
return 0;
}
#define UNUSED
Definition: GeneralDefine.h:39
int main(int argc, char *argv[])
Definition: T_protectiveWall.cpp:215
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:408
void setYMin(Mdouble newYMin)
Sets the value of YMin, the lower bound of the problem domain in the y-direction.
Definition: DPMBase.cc:1034
void autoNumber()
The autoNumber() function calls three functions: setRunNumber(), readRunNumberFromFile() and incremen...
Definition: DPMBase.cc:539
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:422
void setYMax(Mdouble newYMax)
Sets the value of YMax, the upper bound of the problem domain in the y-direction.
Definition: DPMBase.cc:1191
void setZMin(Mdouble newZMin)
Sets the value of ZMin, the lower bound of the problem domain in the z-direction.
Definition: DPMBase.cc:1058
void setXMax(Mdouble newXMax)
Sets the value of XMax, the upper bound of the problem domain in the x-direction.
Definition: DPMBase.cc:1165
void setZMax(Mdouble newZMax)
Sets the value of ZMax, the upper bound of the problem domain in the z-direction.
Definition: DPMBase.cc:1217
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1234
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:873
void solve()
The work horse of the code.
Definition: DPMBase.cc:4270
void setXMin(Mdouble newXMin)
Sets the value of XMin, the lower bound of the problem domain in the x-direction.
Definition: DPMBase.cc:1010
void setStudyDimensions(int dim1, int dim2)
[PAR_SIM2D:createSpecies]
Definition: ParameterStudy2DDemo.cpp:128

If you would like to look at the 1D or 3D parameter study demos:
ParameterStudy1DDemo
ParameterStudy3DDemo
Or return to Overview of advanced tutorials