Skip to content
Snippets Groups Projects
PhaseDiagram_CurvContourSubPlots_Jumps.py 26.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
    import numpy as np
    import matplotlib.pyplot as plt
    import sympy as sym
    import math
    import os
    import subprocess
    import fileinput
    import re
    import matlab.engine
    import sys
    from ClassifyMin import *
    from HelperFunctions import *
    # from CellScript import *
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.cm as cm
    from vtk.util import numpy_support
    from pyevtk.hl import gridToVTK
    from matplotlib.ticker import MultipleLocator,FormatStrFormatter,MaxNLocator
    
    from mpl_toolkits.axes_grid1.inset_locator import inset_axes
    
    import time
    
    from mpl_toolkits.axes_grid1.inset_locator import inset_axes
    
    import matplotlib as mpl
    import seaborn as sns
    import matplotlib.colors as mcolors
    import time
    
    from scipy.ndimage.filters import gaussian_filter
    
    
    class MidpointNormalize(mcolors.Normalize):
        def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
            self.midpoint = midpoint
            super().__init__(vmin, vmax, clip)
    
        def __call__(self, value, clip=None):
            # I'm ignoring masked values and all kinds of edge cases to make a
            # simple example...
            x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
            return np.ma.masked_array(np.interp(value, x, y))
    # print(sys.executable)
    
    # --------------------------------------------------------------------
    # START :
    # INPUT (Parameters):   alpha, beta, theta, gamma, mu1, rho1
    #
    # -Option 1 : (Case lambda = 0 => q12 = 0)
    #   compute q1,q2,b1,b2 from Formula
    #       Option 1.1 :
    #           set mu_gamma = 'q1' or 'q2' (extreme regimes: gamma \in {0,\infty})
    #       Option 1.2 :
    #           compute mu_gamma with 'Compute_MuGamma' (2D problem much faster then Cell-Problem)
    # -Option 2 :
    #   compute Q_hom & B_eff by running 'Cell-Problem'
    #
    # -> CLASSIFY ...
    #
    # OUTPUT: Minimizer G, angle , type, curvature
    # -----------------------------------------------------------------------
    #
    #
    # def GetMuGamma(beta,theta,gamma,mu1,rho1, InputFilePath = os.path.dirname(os.getcwd()) +"/inputs/computeMuGamma.parset",
    #                 OutputFilePath = os.path.dirname(os.getcwd()) + "/outputs/outputMuGamma.txt" ):
    #     # ------------------------------------ get mu_gamma ------------------------------
    #     # ---Scenario 1.1: extreme regimes
    #     if gamma == '0':
    #         print('extreme regime: gamma = 0')
    #         mu_gamma = (1.0/6.0)*arithmeticMean(mu1, beta, theta) # = q2
    #         print("mu_gamma:", mu_gamma)
    #     elif gamma == 'infinity':
    #         print('extreme regime: gamma = infinity')
    #         mu_gamma = (1.0/6.0)*harmonicMean(mu1, beta, theta)   # = q1
    #         print("mu_gamma:", mu_gamma)
    #     else:
    #         # --- Scenario 1.2:  compute mu_gamma with 'Compute_MuGamma' (much faster than running full Cell-Problem)
    #         # print("Run computeMuGamma for Gamma = ", gamma)
    #         with open(InputFilePath, 'r') as file:
    #             filedata = file.read()
    #         filedata = re.sub('(?m)^gamma=.*','gamma='+str(gamma),filedata)
    #         # filedata = re.sub('(?m)^alpha=.*','alpha='+str(alpha),filedata)
    #         filedata = re.sub('(?m)^beta=.*','beta='+str(beta),filedata)
    #         filedata = re.sub('(?m)^theta=.*','theta='+str(theta),filedata)
    #         filedata = re.sub('(?m)^mu1=.*','mu1='+str(mu1),filedata)
    #         filedata = re.sub('(?m)^rho1=.*','rho1='+str(rho1),filedata)
    #         f = open(InputFilePath,'w')
    #         f.write(filedata)
    #         f.close()
    #         # --- Run Cell-Problem
    #
    #         # Check Time
    #         # t = time.time()
    #         # subprocess.run(['./build-cmake/src/Cell-Problem', './inputs/cellsolver.parset'],
    #         #                                      capture_output=True, text=True)
    #         # --- Run Cell-Problem_muGama   -> faster
    #         # subprocess.run(['./build-cmake/src/Cell-Problem_muGamma', './inputs/cellsolver.parset'],
    #         #                                              capture_output=True, text=True)
    #         # --- Run Compute_muGamma (2D Problem much much faster)
    #
    #         subprocess.run(['./build-cmake/src/Compute_MuGamma', './inputs/computeMuGamma.parset'],
    #                                                              capture_output=True, text=True)
    #         # print('elapsed time:', time.time() - t)
    #
    #         #Extract mu_gamma from Output-File                                           TODO: GENERALIZED THIS FOR QUANTITIES OF INTEREST
    #         with open(OutputFilePath, 'r') as file:
    #             output = file.read()
    #         tmp = re.search(r'(?m)^mu_gamma=.*',output).group()                           # Not necessary for Intention of Program t output Minimizer etc.....
    #         s = re.findall(r"[-+]?\d*\.\d+|\d+", tmp)
    #         mu_gamma = float(s[0])
    #         # print("mu_gamma:", mu_gammaValue)
    #     # --------------------------------------------------------------------------------------
    #     return mu_gamma
    #
    
    
    
    # ----------- SETUP PATHS
    # InputFile  = "/inputs/cellsolver.parset"
    # OutputFile = "/outputs/output.txt"
    InputFile  = "/inputs/computeMuGamma.parset"
    OutputFile = "/outputs/outputMuGamma.txt"
    # --------- Run  from src folder:
    path_parent = os.path.dirname(os.getcwd())
    os.chdir(path_parent)
    path = os.getcwd()
    print(path)
    InputFilePath = os.getcwd()+InputFile
    OutputFilePath = os.getcwd()+OutputFile
    print("InputFilepath: ", InputFilePath)
    print("OutputFilepath: ", OutputFilePath)
    print("Path: ", path)
    
    
    # -------------------------- Input Parameters --------------------
    # mu1 = 10.0               # TODO : here must be the same values as in the Parset for computeMuGamma
    mu1 = 1.0
    rho1 = 1.0
    alpha = 2.0
    beta = 2.0
    # beta = 5.0
    theta = 1.0/4.0
    #set gamma either to 1. '0' 2. 'infinity' or 3. a numerical positive value
    gamma = '0'
    # gamma = 'infinity'
    # gamma = 0.5
    # gamma = 0.25
    # gamma = 1.0
    
    # gamma = 5.0
    
    #added
    # lambda1 = 10.0
    lambda1 = 0.0
    
    #Test:
    # rho1 = -1.0
    
    
    
    print('---- Input parameters: -----')
    print('mu1: ', mu1)
    print('rho1: ', rho1)
    print('alpha: ', alpha)
    print('beta: ', beta)
    print('theta: ', theta)
    print('gamma:', gamma)
    
    print('lambda1: ', lambda1)
    print('----------------------------')
    # ----------------------------------------------------------------
    
    #
    # gamma_min = 0.5
    # gamma_max = 1.0
    #
    # # gamma_min = 1
    # # gamma_max = 1
    # Gamma_Values = np.linspace(gamma_min, gamma_max, num=3)
    # # #
    # # # Gamma_Values = np.linspace(gamma_min, gamma_max, num=13)    # TODO variable Input Parameters...alpha,beta...
    # print('(Input) Gamma_Values:', Gamma_Values)
    
    print('type of gamma:', type(gamma))
    # # #
    Gamma_Values = ['0', 'infinity']
    # Gamma_Values = ['infinity']
    # Gamma_Values = ['0']
    print('(Input) Gamma_Values:', Gamma_Values)
    
    for gamma in Gamma_Values:
    
        print('Run for gamma = ', gamma)
        print('type of gamma:', type(gamma))
            # muGamma = GetMuGamma(beta,theta,gamma,mu1,rho1,InputFilePath)
            # # muGamma = GetMuGamma(beta,theta,gamma,mu1,rho1)
            # print('Test MuGamma:', muGamma)
    
            # ------- Options --------
            # print_Cases = True
            # print_Output = True
    
                                #TODO
        # generalCase = True #Read Output from Cell-Problem instead of using Lemma1.4 (special case)
        generalCase = False
    
        # make_3D_plot = True
        # make_3D_PhaseDiagram = True
        make_2D_plot = False
        make_2D_PhaseDiagram = False
        make_3D_plot = False
        make_3D_PhaseDiagram = False
        make_2D_plot = True
        make_2D_PhaseDiagram = True
        #
    
        # --- Define effective quantities: q1, q2 , q3 = mu_gamma, q12 ---
        # q1 = harmonicMean(mu1, beta, theta)
        # q2 = arithmeticMean(mu1, beta, theta)
        # --- Set q12
        # q12 = 0.0  # (analytical example)              # TEST / TODO read from Cell-Output
    
    
    
    
    
        # b1 = prestrain_b1(rho1, beta, alpha, theta)
        # b2 = prestrain_b2(rho1, beta, alpha, theta)
        #
        # print('---- Input parameters: -----')
        # print('mu1: ', mu1)
        # print('rho1: ', rho1)
        # print('alpha: ', alpha)
        # print('beta: ', beta)
        # print('theta: ', theta)
        # print("q1: ", q1)
        # print("q2: ", q2)
        # print("mu_gamma: ", mu_gamma)
        # print("q12: ", q12)
        # print("b1: ", b1)
        # print("b2: ", b2)
        # print('----------------------------')
        # print("machine epsilon", sys.float_info.epsilon)
    
        # G, angle, type, kappa = classifyMin(q1, q2, mu_gamma, q12,  b1, b2, print_Cases, print_Output)
        # Test = f(1,2 ,q1,q2,mu_gamma,q12,b1,b2)
        # print("Test", Test)
    
        # ---------------------- MAKE PLOT / Write to VTK------------------------------------------------------------------------------
    
        # SamplePoints_3D = 10 # Number of sample points in each direction
        # SamplePoints_2D = 10 # Number of sample points in each direction
        SamplePoints_3D = 300 # Number of sample points in each direction
        # SamplePoints_3D = 150 # Number of sample points in each direction
        # SamplePoints_3D = 100 # Number of sample points in each direction
        # SamplePoints_3D = 200 # Number of sample points in each direction
        # SamplePoints_3D = 400 # Number of sample points in each direction
        # SamplePoints_2D = 7500 # Number of sample points in each direction
        # SamplePoints_2D = 4000 # 4000 # Number of sample points in each direction
        SamplePoints_2D = 400 # 4000  # Number of sample points in each direction
        # SamplePoints_2D = 500 # 4000    # Number of sample points in each direction
        # SamplePoints_2D = 100 # 4000  # Number of sample points in each direction
        # SamplePoints_2D = 200 # 4000  # Number of sample points in each direction
        # SamplePoints_2D = 2000 # 4000 # Number of sample points in each direction
        # SamplePoints_2D = 1000   # 4000 # Number of sample points in each direction
    
        if make_3D_PhaseDiagram:
            alphas_ = np.linspace(-20, 20, SamplePoints_3D)
            # alphas_ = np.linspace(-10, 10, SamplePoints_3D)
    
            # betas_  = np.linspace(0.01,40.01,SamplePoints_3D) # Full Range
            # betas_  = np.linspace(0.01,20.01,SamplePoints_3D) # FULL Range
    
    
    
            # betas_  = np.linspace(0.01,0.99,SamplePoints_3D)  # weird part
            betas_  = np.linspace(1.01,40.01,SamplePoints_3D)     #TEST !!!!!  For Beta <1 weird tings happen...
            thetas_ = np.linspace(0.01,0.99,SamplePoints_3D)
    
    
            # TEST
            # alphas_ = np.linspace(-2, 2, SamplePoints_3D)
            # betas_  = np.linspace(1.01,10.01,SamplePoints_3D)
            # print('betas:', betas_)
    
            # TEST :
            # alphas_ = np.linspace(-40, 40, SamplePoints_3D)
            # betas_  = np.linspace(0.01,80.01,SamplePoints_3D) # Full Range
    
            # print('type of alphas', type(alphas_))
            # print('Test:', type(np.array([mu_gamma])) )
            alphas, betas, thetas = np.meshgrid(alphas_, betas_, thetas_, indexing='ij')
            classifyMin_anaVec = np.vectorize(classifyMin_ana)
    
            # Get MuGamma values ...
            GetMuGammaVec = np.vectorize(GetMuGamma)
            muGammas = GetMuGammaVec(betas, thetas, gamma, mu1, rho1)
            # Classify Minimizers....
            G, angles, Types, curvature = classifyMin_anaVec(alphas, betas, thetas, muGammas,  mu1, rho1)   # Sets q12 to zero!!!
    
            # G, angles, Types, curvature = classifyMin_anaVec(alphas, betas, thetas, muGammas,  mu1, rho1, True, True)
            # print('size of G:', G.shape)
            # print('G:', G)
    
            # Option to print angles
            # print('angles:', angles)
    
    
            # Out = classifyMin_anaVec(alphas,betas,thetas)
            # T = Out[2]
            # --- Write to VTK
    
            GammaString = str(gamma)
            VTKOutputName = "outputs/PhaseDiagram3D" + "Gamma" + GammaString
            gridToVTK(VTKOutputName , alphas, betas, thetas, pointData = {'Type': Types, 'angles': angles, 'curvature': curvature} )
            print('Written to VTK-File:', VTKOutputName )
    
        if make_2D_PhaseDiagram:
            # alphas_ = np.linspace(-20, 20, SamplePoints_2D)
            # alphas_ = np.linspace(0, 1, SamplePoints_2D)
            thetas_ = np.linspace(0.01,0.99,SamplePoints_2D)
            alphas_ = np.linspace(-5, 5, SamplePoints_2D)
            # alphas_ = np.linspace(-5, 15, SamplePoints_2D)
            # thetas_ = np.linspace(0.05,0.25,SamplePoints_2D)
    
    
            # good range:
            # alphas_ = np.linspace(9, 10, SamplePoints_2D)
            # thetas_ = np.linspace(0.075,0.14,SamplePoints_2D)
    
            # range used:
            # alphas_ = np.linspace(8, 10, SamplePoints_2D)
            # thetas_ = np.linspace(0.05,0.16,SamplePoints_2D)
    
                # alphas_ = np.linspace(8, 12, SamplePoints_2D)
                # thetas_ = np.linspace(0.05,0.2,SamplePoints_2D)
            # betas_  = np.linspace(0.01,40.01,1)
            #fix to one value:
            betas_ = 2.0;
            # betas_ = 10.0;
            # betas_ = 5.0;
            # betas_ = 0.5;
    
    
            #intermediate Values
            alphas_ = np.linspace(-2, 1, SamplePoints_2D)
            # thetas_ = np.linspace(0.4,0.6,SamplePoints_2D)
            # betas_ = 10.0;
    
            # TEST
            # alphas_ = np.linspace(-8, 8, SamplePoints_2D)
            # thetas_ = np.linspace(0.01,0.99,SamplePoints_2D)
            # betas_ = 1.0; #TEST Problem: disvison by zero if alpha = 9, theta = 0.1 !
            # betas_ = 0.9;
            # betas_ = 0.5;  #TEST!!!
            # alphas, betas, thetas = np.meshgrid(alphas_, betas_, thetas_, indexing='ij')
            betas = betas_
            alphas, thetas = np.meshgrid(alphas_, thetas_, indexing='ij')
    
            if generalCase:
                classifyMin_matVec = np.vectorize(classifyMin_mat)
                GetCellOutputVec = np.vectorize(GetCellOutput, otypes=[np.ndarray, np.ndarray])
                Q, B = GetCellOutputVec(alphas,betas,thetas,gamma,mu1,rho1,lambda1, InputFilePath ,OutputFilePath )
    
    
                # print('type of Q:', type(Q))
                # print('Q:', Q)
                G, angles, Types, curvature = classifyMin_matVec(Q,B)
    
            else:
                classifyMin_anaVec = np.vectorize(classifyMin_ana)
                GetMuGammaVec = np.vectorize(GetMuGamma)
                # muGammas = GetMuGammaVec(betas,thetas,gamma,mu1,rho1,InputFilePath ,OutputFilePath )
                # G, angles, Types, curvature = classifyMin_anaVec(alphas,betas,thetas, muGammas,  mu1, rho1)    # Sets q12 to zero!!!
                muGammas = GetMuGammaVec(betas,thetas,gamma,mu1,rho1,InputFilePath ,OutputFilePath )
    
                if gamma == '0':
                    G, curvature_0, Types, curvature_0 = classifyMin_anaVec(alphas,betas,thetas, muGammas,  mu1, rho1)    # Sets q12 to zero!!!
                if gamma == 'infinity':
                    G, curvature_inf, Types, curvature_inf = classifyMin_anaVec(alphas,betas,thetas, muGammas,  mu1, rho1)    # Sets q12 to zero!!!
    
                # print('size of G:', G.shape)
                # print('G:', G)
                # print('Types:', Types)
                # Out = classifyMin_anaVec(alphas,betas,thetas)
                # T = Out[2]
                # --- Write to VTK
                # VTKOutputName = + path + "./PhaseDiagram2DNEW"
    
            # print('angles:',angles)
            # GammaString = str(gamma)
            # VTKOutputName = "outputs/PhaseDiagram2D" + "Gamma_" + GammaString
            # gridToVTK(VTKOutputName , alphas, betas, thetas, pointData = {'Type': Types, 'angles': angles, 'curvature': curvature} )
            # print('Written to VTK-File:', VTKOutputName )
    
    
    # --- Make 3D Scatter plot
    if(make_3D_plot or make_2D_plot):
        # fig = plt.figure()
        # ax = fig.add_subplot(111, projection='3d')
        # colors = cm.plasma(Types)
        # Styling
        plt.style.use("seaborn-darkgrid")
        plt.style.use("seaborn-whitegrid")
        plt.style.use("seaborn")
        # plt.style.use("seaborn-paper")
        # plt.style.use('ggplot')
        # plt.rcParams["font.family"] = "Avenir"
        # plt.rcParams["font.size"] = 16
    
        # plt.style.use("seaborn-darkgrid")
        mpl.rcParams['text.usetex'] = True
        mpl.rcParams["font.family"] = "serif"
        mpl.rcParams["font.size"] = "10"
        # mpl.rcParams['xtick.labelsize'] = 16mpl.rcParams['xtick.major.size'] = 2.5
        # mpl.rcParams['xtick.bottom'] = True
        # mpl.rcParams['ticks'] = True
        mpl.rcParams['xtick.bottom'] = True
        mpl.rcParams['xtick.major.size'] = 3
        mpl.rcParams['xtick.minor.size'] = 1.5
        mpl.rcParams['xtick.major.width'] = 0.75
        mpl.rcParams['ytick.left'] = True
        mpl.rcParams['ytick.major.size'] = 3
        mpl.rcParams['ytick.minor.size'] = 1.5
        mpl.rcParams['ytick.major.width'] = 0.75
    
        mpl.rcParams.update({'font.size': 10})
    
        ### ADJUST GRID:
        mpl.rcParams['axes.labelpad'] = 5
        mpl.rcParams['grid.linewidth'] = 0.25
        mpl.rcParams['grid.alpha'] = 0.9 # 0.75
        mpl.rcParams['grid.linestyle'] = '-'
        mpl.rcParams['grid.color']   = 'gray'#'black'
    
        Label_size = 7
    
    
        colors = cm.coolwarm(curvature_inf)
    
        ### GET COLORS :
        deep_colors = sns.color_palette("pastel")
        print('deep_colors.as_hex():',deep_colors.as_hex())
    
    
        diverging_colors = sns.color_palette("RdBu", 10)
        print('diverging_colors.as_hex():',diverging_colors.as_hex())
    
        pal = sns.color_palette("Blues")
        pal = sns.color_palette()
        print(pal.as_hex())
    
        # flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]
        flatui = ["coral","white", "cornflowerblue"]
        flatui = ["cornflowerblue", "coral"]
        flatui = ['#4c72b0','white', '#c44e52']
        flatui = ['#4c72b0','white', '#8de5a1']
        flatui = ['#a1c9f4', '#ffb482','#ff9f9b'] #Test colors
        flatui = ['#4c72b0','white', '#ffb482']
        flatui = ['#4c72b0','white', '#ff9f9b']
        flatui = ['#4c72b0','white', '#ab162a']
    
        # flatui = ['#4c72b0','white', '#eb9172']
        # flatui = ['#4c72b0','white', '#64b5cd']
        cmap = mpl.colors.ListedColormap(sns.color_palette(flatui).as_hex())
        cmap = mpl.colors.ListedColormap(sns.color_palette(flatui).as_hex())
        cmap = mpl.colors.ListedColormap(sns.color_palette("RdBu_r", 10).as_hex())
        cmap = mpl.colors.ListedColormap(sns.color_palette("coolwarm", 10).as_hex())  #Discrete CMAP
        cmap = sns.color_palette("coolwarm", as_cmap=True)
        # cmap = sns.color_palette("vlag", as_cmap=True)
        cmap = sns.color_palette("icefire", as_cmap=True)   ## THIS !
        # cmap = sns.color_palette("Spectral_r", as_cmap=True)
        # cmap = sns.color_palette("cubehelix", as_cmap=True)
    
        # cmap = sns.color_palette("flare_r", as_cmap=True)
        # cmap = sns.diverging_palette(220, 20, as_cmap=True)
        # cmap = sns.diverging_palette(250, 30, l=65, center="dark", as_cmap=True)
        # cmap = mpl.colors.ListedColormap(sns.color_palette().as_hex())
        # cmap = mpl.colors.LinearSegmentedColormap.from_list("", sns.color_palette(flatui).as_hex())
    
    
    
        width = 6.28
        # height = width / 1.618
        height = width / 2.5
        # fig, ax = plt.subplots()
        fig,ax = plt.subplots(nrows=1,ncols=2,figsize=(width,height), sharey=True)
        # ax = plt.axes((0.15,0.21 ,0.8,0.75))
    
    
    
    
        # if make_2D_plot: pnt3d=ax.scatter(alphas,thetas,c=Types.flat)
        # if make_3D_plot: pnt3d=ax.scatter(alphas,betas,thetas,c=Types.flat)
        #
        # if make_2D_plot: pnt3d=ax.scatter(alphas,thetas,c=angles.flat)
        # if make_3D_plot: pnt3d=ax.scatter(alphas,betas,thetas,c=angles.flat)
    
    
        # pnt=ax.scatter(alphas,thetas,c=angles,cmap='coolwarm')
        # # ax.colorbar()
        # CS = ax.contourf(alphas, thetas, angles,6, cmap=plt.cm.coolwarm, linestyle=dashed)
        # # CS = ax.contour(alphas, thetas, angles,6, colors='k')
        # ax.clabel(CS, inline=True, fontsize=7.5)
        # # ax.set_title('Simplest default with labels')
    
    
        divnorm=mcolors.TwoSlopeNorm(vmin=curvature_0.min(), vcenter=(curvature_0.max()+curvature_0.min())/2, vmax=curvature_0.max())
        # divnorm=mcolors.LogNorm(vmin=curvature_0.min(), vmax=curvature_0.max())
        # divnorm = mcolors.PowerNorm(0.3)
        # divnorm = MidpointNormalize(midpoint=(curvature_0.max()+curvature_0.min())/2) # Custom Normalization
    
        ### BOUNDED NORM:
        # bounds = np.array([0,1.0, 1.1, 1.2,1.3,1.4,1.5,1.6,3])
        # print('bounds.shape',np.shape(bounds))
        # print('bounds:', bounds)
        # bounds = np.arange(curvature_0.min(),curvature_0.max(), 0.2)
        # print('bounds.shape',np.shape(bounds))
        # print('bounds:', bounds)
        # divnorm = mcolors.BoundaryNorm(boundaries=bounds, ncolors=256)
    
        # divnorm = mcolors.CenteredNorm()
    
    
        ax[0].imshow(curvature_0.T, extent=[-2, 1, 0, 1], origin='lower', norm = divnorm,
                          cmap=cmap, alpha=0.9, aspect=2.5)
    
        levels = np.arange(curvature_inf.min()+0.5, curvature_inf.max()-0.5, 0.3)
        levels = np.arange(1.1,1.5, 0.15)
        levels = np.arange(1.0,1.5, 0.10)
        CS =  ax[0].contour(alphas, thetas, curvature_0, levels,  colors='white',linewidths=(0.5), extent=(-2, 1, 0, 1), zorder=5)
    
        # levels_below = np.arange(curvature_inf.min(),1, 0.5)
        levels_below = np.arange(-1,1, 0.5)
        CS_below =  ax[0].contour(alphas, thetas, curvature_0, levels_below,  colors='white',linewidths=(0.5), extent=(-2, 1, 0, 1), zorder=5)
        levels_above = np.arange(1.5,curvature_inf.max(), 0.4)
        CS_above=  ax[0].contour(alphas, thetas, curvature_0, levels_above,  colors='white',linewidths=(0.5), extent=(-2, 1, 0, 1), zorder=5)
        # CS_0 = ax[0].contourf(alphas, thetas, curvature_0, 10, cmap=plt.cm.coolwarm)
        # CS_0 = ax[0].contourf(alphas, thetas, curvature_0, 10, cmap=plt.cm.gnuplot)
        # CS = ax.contourf(alphas, thetas, angles, 10, cmap='RdBu')
        # CS_02 = ax[0].contour(CS_0, levels=CS_0.levels[::2], colors='black',inline=True, linewidths=(0.5,))
        # ax.clabel(CS2, inline=True, fontsize=9, colors='black')
        # ax.clabel(CS2, inline=True, inline_spacing=3, rightside_up=True, colors='k', fontsize=8)
        # manual_lobcations = [
        #     (-0.5, 0.3), (-0.7, 0.4), (-0.8, 0.5), (-0.9, 0.6), (-1,0.7)]
        manual_locations = [
            (-0.4, 0.2),(-0.6, 0.3), (-0.7, 0.4), (-0.8, 0.5), (-0.9, 0.6), (-1,0.7)]
        # ax[0].clabel(CS_02, inline=True, fontsize=6, colors='black', manual=manual_locations)
        # ax[0].clabel(CS_02, inline=True, fontsize=10, colors='black')
        manual_location_below = [(-0.25,0.8), (0.25,0.8), (0.7,0.68) , (0.75,0.85)]
        manual_location_above = [(-1,0.15), (-1.5,0.35), ( -1.75,0.6), (-1.8,0.8)]
        manual_location = [(-0.5,0.15), (-0.45,0.2), (0,0.2), (0.25,0.2) , (0.75,0.2)]
    
        # ax[0].clabel(CS_below, inline=True, fontsize=Label_size, colors='white', manual=manual_location_below)
        # ax[0].clabel(CS, inline=True, fontsize=Label_size, colors='white', manual=manual_location)
        # ax[0].clabel(CS_above, inline=True, fontsize=Label_size, colors='white', manual= manual_location_above)
    
    
    
        # ax.clabel(CS2, CS2.levels, inline=True, fontsize=10)
        # ax.clabel(CS,  fontsize=5, colors='black')
        # cbar = fig.colorbar(CS,label=r'angle $\alpha$', ticks=[0, np.pi/8, np.pi/4, 3*np.pi/8 , np.pi/2 ])
        # cbar = fig.colorbar(CS_0, ticks=[0, np.pi/2 ])
        # cbar.ax.set_yticklabels(['$0$', r'$\pi/2$'])
        # cbar.ax.set_title(r'angle $\alpha$')
    
        # divnorm=mcolors.TwoSlopeNorm(vmin=curvature_inf.min(), vcenter=(curvature_inf.max()+curvature_inf.min())/2, vmax=curvature_inf.max())
        Im = ax[1].imshow(curvature_inf.T, extent=[-2, 1, 0, 1], origin='lower', norm = divnorm,
                          cmap=cmap, alpha=0.9, aspect=2.5)
    
        # levels = np.arange(curvature_inf.min(), curvature_inf.max(), 0.3)
        CS_1 =  ax[1].contour(alphas, thetas, curvature_inf, levels, colors='white',linewidths=(0.5), extent=(-2, 1, 0, 1), zorder=5)
        CS_1_below =  ax[1].contour(alphas, thetas, curvature_inf, levels_below, colors='white',linewidths=(0.5), extent=(-2, 1, 0, 1), zorder=5)
        CS_1_above =  ax[1].contour(alphas, thetas, curvature_inf, levels_above, colors='white',linewidths=(0.5), extent=(-2, 1, 0, 1), zorder=5)
        # CS_1 =  ax[1].contour(alphas, thetas, curvature_inf, levels=15, colors='white',linewidths=(0.5), extent=(-2, 1, 0, 1), zorder=5)
    
        # CS_1 = ax[1].contourf(alphas, thetas, curvature_inf, 10, cmap=plt.cm.gnuplot)
        # CS_1 = ax[1].contourf(alphas, thetas, curvature_inf, 10, cmap=plt.cm.jet)
        # CS = ax.contourf(alphas, thetas, angles, 10, cmap='RdBu')
        # CS_12 = ax[1].contour(CS_1, levels=CS_1.levels[::2], colors='black',inline=True, linewidths=(0.5,))
        # ax.clabel(CS2, inline=True, fontsize=9, colors='black')
        # ax.clabel(CS2, inline=True, inline_spacing=3, rightside_up=True, colors='k', fontsize=8)
        # manual_locations = [
        #     (-1.8,0.9), (-1.5,0.4), (-1,0.3), (0,0.15),(0,0.67) ,(0.5,0.75) , (0.5,0.8), (0.8,0.9)   ]
        # ax[1].clabel(CS_12, inline=True, fontsize=10, colors='black', manual=manual_locations)
        # ax[1].clabel(CS_12, inline=True, fontsize=10, colors='black')
        ax[1].clabel(CS_1_below, inline=True, fontsize=Label_size, colors='white', manual=manual_location_below)
    
        manual_location = [(-0.5,0.1), (0.25,0.2) ]
        ax[1].clabel(CS_1, levels[1::2], inline=True,fontsize=Label_size, colors='white', manual=manual_location)
        # ax[1].clabel(CS_1, levels[1::2], inline=True,fontsize=Label_size, colors='white')
        # manual_location_above = [(-1.5,0.35), ( -1.75,0.6), (-1.8,0.8)]
        ax[1].clabel(CS_1_above, inline=True, fontsize=Label_size, colors='white', manual = manual_location_above )
    
        # ADD COLORBAR :
        axins1 = inset_axes(ax[1],
                           width="5%",  # width = 5% of parent_bbox width
                           height="100%",  # height : 50%
                           loc='lower left',
                           bbox_to_anchor=(1.05, 0., 1, 1),
                           bbox_transform=ax[1].transAxes,
                           borderpad=0,
                           )
        #
        cbar = fig.colorbar(Im, cax=axins1)
        # cbar = fig.colorbar(CS_1, cax=axins1)
        # cbar.ax.tick_params(labelsize=8)
        cbar.ax.set_title(r'$\kappa$')
    
    
        # cbar.ax.set_yticklabels(['$0$',r'$\pi/8$', r'$\pi/4$' ,r'$3\pi/8$' , r'$\pi/2$'])
        # cbar.ax.set_title(r'angle $\alpha$')
        # cbar.ax.set_title(r'curvature $\kappa$')
    
        # cbar=plt.colorbar(pnt3d)
        # cbar.set_label("Values (units)")
        # plt.axvline(x = 8, color = 'b', linestyle = ':', label='$q_1$')
        # plt.axhline(y = 0.083333333, color = 'b', linestyle = ':', label='$q_1$')
    
        ax[0].set_xlabel(r'$\theta_\rho$',fontsize=10)
        # ax[0].yaxis.set_major_locator(MultipleLocator(0.1))
        # ax[0].xaxis.set_major_locator(MultipleLocator(1))
        ax[0].yaxis.set_major_locator(MultipleLocator(0.1))
        ax[0].xaxis.set_major_locator(MultipleLocator(0.5))
        ax[0].set_ylabel(r'$\theta$   ', rotation=0)
        ax[0].tick_params(axis='x' )
        ax[0].tick_params(axis='y')
    
        ax[1].set_xlabel(r'$\theta_\rho$')
        # ax.xaxis.set_minor_locator(MultipleLocator(0.5))
        # ax[1].yaxis.set_major_locator(MultipleLocator(0.1))
        # ax[1].xaxis.set_major_locator(MultipleLocator(1))
        ax[1].yaxis.set_major_locator(MultipleLocator(0.1))
        ax[1].xaxis.set_major_locator(MultipleLocator(0.5))
        ax[1].tick_params(axis='x')
        ax[1].tick_params(axis='y')
        # ax.set_ylabel('beta')
        # ax[1].set_ylabel(r'$\theta$   ',fontsize=10, rotation=0)
        # if make_3D_plot: ax.set_zlabel('theta')
        # plt.subplots_adjust(bottom=0.2)
        # plt.subplots_adjust(wspace=0.22, hspace=0.1)
        plt.subplots_adjust(hspace=0.15, wspace=0.1)
        # plt.subplots_adjust(hspace=0.15, wspace=0.0)
        plt.subplots_adjust(bottom=0.2)
        # plt.subplots_adjust(right=0.1)
        # fig.subplots_adjust(right=0.1)
    
    
        # ax[0].grid( linestyle = '--', linewidth = 0.25)
        # ax[1].grid( linestyle = '--', linewidth = 0.25)
    
    
    
        fig.set_size_inches(width, height)
        outputName = 'Plot-CurvContour.pdf'
        fig.savefig(outputName)
        # fig.savefig('Plot-Contour.pdf')
        plt.show()
        # plt.savefig('common_labels.png', dpi=300)
        # print('T:', T)
        # print('Type 1 occured here:', np.where(T == 1))
        # print('Type 2 occured here:', np.where(T == 2))