The gradient of a scalar field is a vector field.

Scalar Field Gradient

The Scalar Field Gradient model displays the gradient by overlaying a vector field on scalar field U(x,y). The gradient of a scalar field U(x,y) is a vector field that points in the direction of the greatest rate of change of the scalar field.  The Scalar Field Gradient Model computes the gradient using a numerical approximation to the partial derivatives.

Computational Model

In Cartesian coordinates, the gradient is computed using the del or nabla (del) operator.

 

The Scalar Field Gradient model computes these derivatives in a fixed relation code page using the central difference approximation.

// compute the gradient using the central difference approximation
double h2=2*(_view.scalarField.indexToX(1)-_view.scalarField.indexToX(0));
for(int i=1; i<m-1; i++) {                             // loop over grid x
  for(int j=1; j<m-1; j++) {                           // loop over grid y
    xGradData[i][j]=(scalarData[i+1][j]-scalarData[i-1][j])/h2;
    yGradData[i][j]=(scalarData[i][j+1]-scalarData[i][j-1])/h2;
  } // end of y loop
} // end of x loop

The scalar field is stored in the scalarData 2D array and the vector field components are stored in the xGradData and yGradData arrays.

Related Models

The following EJS models are described in Chapter 10 of the EJS adaptation of An Introduction to Computer Simulation Methods.

Additional models to be written.

Credits:

The Laplace Equation model was created by Wolfgang Christian using the Easy Java Simulations (EJS) modeling tool version 4.2.  You can examine and modify the model for this simulation if you have EJS installed by right-clicking within the program and selecting "Open Ejs Model" from the pop-up menu. 

 

Information about EJS is available at: <http://www.um.es/fem/Ejs/> and in the OSP ComPADRE collection <http://www.compadre.org/OSP/>.