Skip to Search
Skip to Navigation
Skip to Content

University of Connecticut School of Engineering Cellular Mechanics Laboratory

IMPETUS – Interactive MultiPhysics Simulation Environment

Tutorials

Full PDF tutorial is also available.

Download IMPETUS and Tutorials.

Tutorial 2 : Solving the Diffusion equation using Interactive Field

2.1 Introduction

This tutorial will guide users to create a simple simulation to solve the diffusion equation  using the “InteractiveField” MID. Where  is the concentration and  is the constant diffusion coefficient, by using the continuum field component of the program.

·         The tutorial is located in:

Tutorials/tutorialHeat/

·         For a diffusion simulation, insert the line below in the main.cpp:

            #include "../Tutorials/tutorialHeat/heat.h"

 

2.2. The “InteractiveField” Object

The “InteractiveField” object is the discretized physical space defined by a grid of nodes. Field equations can be solved numerically at the nodes. Here, we follow the explicit finite difference method. The “Parameters” object is required to create the “InteractiveField” object. The following example shows how to create the object using an input file:

      vamde::InteractiveField * c0;

      vamde::InteractiveField::Cinit continit;

      continit.readinput("Tutorials/tutorialHeat/input/cont0.input");

      c0 = new vamde::InteractiveField(continit,param);

The required parameters for constructing the “InteractiveField” are

·         Minimum number of total nodes on each axis: nx, ny, nz. The simulation engine will divide the continuum to the processors and rounding up so that the number of nodes is the same in every processor. Therefore the resulting number of nx, ny and nz may be slightly higher than the assigned value.

      int nx, ny, nz;

·         Ghost layer is the size of the shell layer used in processor communication

      int ghost_layer;

 

·         A printing path is required for the generated .cfg configuration files but it is not required to construct the field:

      char *output_directory_name;

An example for an input file cell0.input is shown below:

Text Box: [IN] nx ny nz
120 120 120

[IN] ghost_layer
1

[IN] output directory name
Tutorials/tutorialHeat/output/Cont_outputs/cont0/

 

Common InteractiveField Functions:

·         The diffusivity can be adjusted:

            c0->diffusivity = 0.05;

·         Several boundary conditions can be used. Examples on how to use sink/source  and insulators  as boundary conditions are as follows:

            c0->setAllGlobalBoundarySink();

            c0->setAllGlobalBoundaryInsulated()

·         Users can set a concentration value “concentration_val”  to a certain location x0, y0, z0 as follow:

            c0->setConcentration( x , y , z , concentration_val);

·         To print configuration .cfg files to a provided output directory name, we use the function:

            c0->cfgwriter->print();

·         To copy the nodes of the border of one processor to the shell layer of its adjacent processor as pseudo nodes, we use the function:

            c0->copyParticles();

·         This function will specifically integrate the parabolic equation.

            c0->IterateParabolicPDE();

Creating a Simulation

The following example shows how to use the functions defined above along with what we discussed in (Supplementary Software 2) to build a simple diffusion simulation.

Text Box: void runSimulation(vamde::Parameters * param)  {
	
	vamde::TimeKeeper * tk;
	tk = new vamde::TimeKeeper(param);
	
	/// parameters: 
	double delta_t = param-> delta_t;
	double end_step = param-> end_step;
	double & t = param->clock->t;
	int & step = param->clock->step;
	/// Initiate clock
	param->clock->set_step(0);
	
	vamde::InteractiveField * c0;
	vamde::InteractiveField::Cinit continit;
	continit.readinput("Tutorials/tutorialHeat/input/cont0.input");
	c0 = new vamde::InteractiveField(continit,param);
	c0->diffusivity = 0.05;

	double x_mid = (param->gridinfo->world.lo[0] + param->gridinfo->world.hi[0]) /2;
	double y_mid = (param->gridinfo->world.lo[1] + param->gridinfo->world.hi[1]) /2;
	double z_mid = (param->gridinfo->world.lo[2] + param->gridinfo->world.hi[2]) /2;

	c0->setConcentration(x_mid,y_mid,z_mid,10 );
	c0->setAllGlobalBoundarySink();
	c0->cfgwriter->print();
	
	while (step < end_step) {
		
		/// Print Runtime progress
		tk->print_progress(10);
		/// Advace the clock by one step
		param->clock->advance();

		c0->copyParticles();
		c0->IterateParabolicPDE();
		c0->cfgwriter->print();
		
	}
}

 

Results are shown in EXAMPLES.