Integration
Here we show how to perform integration.
This is a very simple example that simply used the attributes of the coef object
Import general modules
[1]:
# Import required modules
from mpi4py import MPI #equivalent to the use of MPI_init() in C
import matplotlib.pyplot as plt
import numpy as np
# Get mpi info
comm = MPI.COMM_WORLD
Import modules from pynek
[2]:
from pysemtools.io.ppymech.neksuite import pynekread
from pysemtools.datatypes.msh import Mesh
from pysemtools.datatypes.coef import Coef
from pysemtools.datatypes.field import FieldRegistry
Read the data and build objects
In this instance, we create connectivity for the mesh object, given that we wish to use direct stiffness summation to reduce discontinuities.
[3]:
msh = Mesh(comm, create_connectivity=True)
fld = FieldRegistry(comm)
pynekread('../data/rbc0.f00001', comm, data_dtype=np.double, msh=msh, fld=fld)
coef = Coef(msh, comm, get_area=False)
2024-08-25 21:02:37,603 - Mesh - INFO - Initializing empty Mesh object.
2024-08-25 21:02:37,604 - Field - INFO - Initializing empty Field object
2024-08-25 21:02:37,605 - pynekread - INFO - Reading file: ../data/rbc0.f00001
2024-08-25 21:02:37,611 - Mesh - INFO - Initializing Mesh object from x,y,z ndarrays.
2024-08-25 21:02:37,612 - Mesh - INFO - Initializing common attributes.
2024-08-25 21:02:37,613 - Mesh - INFO - Creating connectivity
2024-08-25 21:02:37,845 - Mesh - INFO - Mesh object initialized.
2024-08-25 21:02:37,846 - Mesh - INFO - Mesh data is of type: float64
2024-08-25 21:02:37,847 - Mesh - INFO - Elapsed time: 0.23524014099999999s
2024-08-25 21:02:37,847 - pynekread - INFO - Reading field data
2024-08-25 21:02:37,852 - pynekread - INFO - File read
2024-08-25 21:02:37,853 - pynekread - INFO - Elapsed time: 0.248190697s
2024-08-25 21:02:37,853 - Coef - INFO - Initializing Coef object
2024-08-25 21:02:37,854 - Coef - INFO - Getting derivative matrices
2024-08-25 21:02:37,856 - Coef - INFO - Calculating the components of the jacobian
2024-08-25 21:02:37,919 - Coef - INFO - Calculating the jacobian determinant and inverse of the jacobian matrix
2024-08-25 21:02:37,934 - Coef - INFO - Calculating the mass matrix
2024-08-25 21:02:37,935 - Coef - INFO - Coef object initialized
2024-08-25 21:02:37,936 - Coef - INFO - Coef data is of type: float64
2024-08-25 21:02:37,936 - Coef - INFO - Elapsed time: 0.08297883800000005s
Integration in physical space
In physical space, to integrate we must simply perform a weighted sum of a variable with the mass matrix. In this case, since we average, we divide by the mass matrix as well.
[4]:
w_avrg = coef.glsum(fld.registry['w']*coef.B, comm, dtype=np.double)/coef.glsum(coef.B, comm, dtype=np.double)
print('Average w =', w_avrg)
Average w = -1.4410692531281081e-08
The average of the z velocity in this case should be around 0