Getting Started

Welcome to the getting started guide for MOLE (Mimetic Operators Library Enhanced). This guide will help you set up and run your first MOLE project.

Prerequisites

To install the MOLE library, you’ll need the following packages:

  • CMake (Minimum version 3.10)

  • OpenBLAS (Minimum version 0.3.10)

  • Eigen3

  • LAPACK (Mac only)

  • libomp (Mac only)

For documentation build requirements, please refer to the [Documentation Guide][doc-guide].

Package Installation by OS

Ubuntu/Debian Systems

# Install all required packages
sudo apt install cmake libopenblas-dev libeigen3-dev

macOS Systems

Install [Homebrew][homebrew] if you don’t have it already, then run:

# Install all required packages
brew install cmake openblas eigen libomp lapack

Troubleshooting Homebrew: If you encounter installation errors, try these steps:

# Fix permissions issues
sudo chown -R $(whoami) /usr/local/Cellar
# Fix shallow clone issues
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
# Remove Java dependencies if they cause conflicts
brew uninstall --ignore-dependencies java
brew update

RHEL/CentOS/Fedora Systems

# Install all required packages
sudo yum install cmake openblas-devel eigen3-devel

Building and Installing

  1. Clone the repository:

    git clone https://github.com/csrc-sdsu/mole.git
    cd mole
    
  2. Build the library:

    mkdir build && cd build
    cmake ..
    make
    
  3. Install the library:

    • For a custom location:

      cmake --install . --prefix /path/to/location
      
    • For a system location (requires privileges):

      sudo cmake --install .
      

      Or

      sudo cmake --install . --prefix /path/to/privileged/location
      

Note: Armadillo and SuperLU will be automatically installed in the build directory during the build process.

Testing

Run from the build directory:

C++

A suite of four automatic tests that verify MOLE’s installation and dependencies. These tests run automatically during the C++ library construction.

make run_tests

MATLAB/Octave

MATLAB/Octave equivalent of the C++ test suite. We recommend running these tests before using MOLE to ensure proper setup.

make run_matlab_tests

Examples

C++

Four self-contained, well-documented examples demonstrating typical PDE solutions. These are automatically built with make and serve as an excellent starting point for C++ users.

MATLAB/Octave Examples

A collection of over 30 examples showcasing various PDE solutions, from simple linear one-dimensional problems to complex nonlinear multidimensional scenarios.

Quick Start Examples

Here are some simple examples to help you get started with MOLE:

C++ Example

transport1D example (examples/cpp/transport1D.cpp)
 1/**
 2 * This example uses MOLE to solve the 1D advection-reaction-dispersion
 3 * equation:
 4 * https://wwwbrr.cr.usgs.gov/projects/GWC_coupled/phreeqc/html/final-22.html
 5 */
 6
 7#include "mole.h"
 8#include <iostream>
 9
10int main() {
11
12  int k = 2;             // Operators' order of accuracy
13  Real a = 0;            // Left boundary
14  Real b = 130;          // Right boundary
15  int m = 26;            // Number of cells
16  Real dx = (b - a) / m; // Cell's width [m]
17  Real t = 4;            // Simulation time [years]
18  int iter = 208;        // Number of iterations
19  Real dt = t / iter;    // Time step
20  Real dis = 5;          // Dispersivity [m]
21  Real vel = 15;         // Pore-water flow velocity [m/year]
22  Real R = 2.5;          // Retardation (Cl^- = 1, Na^+ = 2.5)
23  Real C0 = 1;           // Displacing solution concentration [mmol/kgw]
24
25  // Get 1D mimetic operators
26  Gradient G(k, m, dx);
27  Divergence D(k, m, dx);
28  Interpol I(m, 0.5);
29
30  // Allocate fields
31  vec C(m + 2); // Scalar field (concentrations)
32  vec V(m + 1); // Vector field (velocities)
33
34  // Impose initial conditions
35  C(0) = C0;
36  V.fill(vel);
37
38  // Hydrodynamic dispersion coefficient [m^2/year]
39  dis *= vel; // 75
40
41  // dt = dt/R (retardation)
42  dt /= R;
43
44  // Time integration loop
45  for (int i = 0; i <= iter; i++) {
46
47    // First-order forward-time scheme
48    C += dt * (D * (dis * (G * C)) - D * (V % (I * C)));
49
50    // Right boundary condition (reflection)
51    C(m + 1) = C(m);
52  }
53
54  // Spit out the new concentrations!
55  cout << C;
56
57  return 0;
58}

MATLAB/Octave Example

elliptic 1D example (examples/matlab/elliptic1D.m)
 1% Solves the 1D Poisson's equation with Robin boundary conditions
 2
 3clc
 4close all
 5
 6addpath('../../src/matlab')
 7
 8west = 0;  % Domain's limits
 9east = 1;
10
11k = 6;  % Operator's order of accuracy
12m = 2*k+1;  % Minimum number of cells to attain the desired accuracy
13dx = (east-west)/m;  % Step length
14
15L = lap(k, m, dx);  % 1D Mimetic laplacian operator
16
17% Impose Robin BC on laplacian operator
18a = 1;
19b = 1;
20L = L + robinBC(k, m, dx, a, b);
21
22% 1D Staggered grid
23grid = [west west+dx/2 : dx : east-dx/2 east];
24
25% RHS
26U = exp(grid)';
27U(1) = 0;  % West BC
28U(end) = 2*exp(1);  % East BC
29
30U = L\U;  % Solve a linear system of equations
31
32% Plot result
33plot(grid, U, 'o')
34hold on
35plot(grid, exp(grid))
36legend('Approximated', 'Analytical', 'Location', 'NorthWest')
37title('Poisson''s equation with Robin BC')
38xlabel('x')
39ylabel('u(x)')

Next Steps

  • Check out more C++ examples in the examples/cpp/ directory

  • Explore the MATLAB/Octave examples in the examples/matlab/ directory

  • Join our community and contribute

Performing non-unary operations involving operands constructed over different grids may lead to unexpected results. While MOLE allows such operations without throwing errors, users must exercise caution when manipulating operators across different grids.

Licensing

MOLE is distributed under a GNU General Public License; please refer to the LICENSE file for more details.