###
# cMesh.py (C) of thesis research "Modeling and Simulating Three Phases of Steel: Austenite, Feritte and Cementite" 2018 by Thijs Verbeek
# is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
#
# You should have received a copy of the license along with this
# work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
###

import numpy as np
import matplotlib.pyplot as plt


### Lot of other properties of the mesh is added in the cGrid code. Not so nice programming, but it works. ;)
class cMesh:
    def __init__(self, n, dimension, name):
        self.d = dimension
        self.n = n
        self.n_tri = -1
        self.n_edges = -1
        self.points = np.zeros((0,self.d))
        self.points_index = np.zeros((0,self.d),dtype=np.int)
        self.edges = np.zeros((0,2))
        self.edges_index = np.zeros((0,2),dtype=np.int)
        self.triangles = np.zeros((0,3))
        self.triangles_index = np.zeros((0,3),dtype=np.int)
        self.name = name

    def plot(self, point = None, corner=None, edge=None, triangle=None, triangle_mid = None):
        from set_layout_plot import plot_settings
        plot_settings()
        x0 = np.min(self.points[:,0])
        xN = np.max(self.points[:,0])
        y0 = np.min(self.points[:,1])
        yN = np.max(self.points[:,1])
        hx = (xN - x0)/self.n
        hy = (yN - y0)/self.n

        # Plot triangulation
        f, (ax1) = plt.subplots(1,1, sharex = True, sharey = True)

        # Plot 1
        ## Plot triangles in tri_domain
        ax1.triplot(self.points[:,0], self.points[:,1], self.triangles_index)


#        ## plot border of domain
#        ax1.plot(np.array([ 0.,  0.]),np.array([ 0.,  1.]),color='black',linewidth = 3)
#        ax1.plot(np.array([ 0.,  1.]),np.array([ 0.,  0.]),color='black',linewidth = 3)
#        ax1.plot(np.array([ 1.,  1.]),np.array([ 0.,  1.]),color='black',linewidth = 3)
#        ax1.plot(np.array([ 0.,  1.]),np.array([ 1.,  1.]),color='black',linewidth = 3)
        ax1.set_title(self.name)
        ax1.axis([x0 - 5*hx , xN + 5*hx, y0 - 5*hy, yN + 5*hy])




        plt.show()

