Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • develop protected
  • ITAFFT_v2024a
  • VA_v2023b
  • VA_v2023a
  • VA_v2022a
  • before_cmake_rework
  • v2021.a
  • v2020.a
  • v2019.a
  • v2018.b
  • v2018.a
  • v2017.d
  • v2017.c
  • v2017.b
  • v2017.a
  • v2016.a
17 results

FFTW3Backend.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    01_GenerateMicrostructures.py 5.30 KiB
    import numpy as np
    # import scipy.optimize as scopt
    import splinepy as sp
    import pandas as pd
    import os
    import shutil
    
    from gismo.gismo_export import AdditionalBlocks, export
    from gismo.GenerateMicrostructures_fun import generate
    
    EPS = 1e-8
    BOX_LENGTH = 0.14
    BOX_HEIGHT = 0.041
    SHOW_MICROSTRUCTURE = False
    FILENAME = "microstructure.xml"
    N_THREADS = 1
    sp.settings.NTHREADS = N_THREADS
    
    # Simulation parameters
    TILING = [5,3]#[5, 3]
    N_REFINEMENTS = 0
    DEGREE_ELEVATIONS = 1
    INLET_BOUNDARY_ID = 2
    OUTLET_BOUNDARY_ID = 3
    INLET_PEAK_VELOCITY = 1.4336534897721067
    CLOSING_FACE = "x"
    # OBJECTIVE_FUNCTION = [1, 3]
    # OBJECTIVE_FUNCTION_WEIGHTS = [49927, 10.027]
    OBJECTIVE_FUNCTION = [2, 3]
    # OBJECTIVE_FUNCTION_WEIGHTS = [6.673e13, 5.700225]
    OBJECTIVE_FUNCTION_WEIGHTS = [7e5, 2e-3]
    
    microtile_string = 'HollowOctagon'
    MICROTILE = sp.microstructure.tiles.HollowOctagon()
    # ! Use random sizes
    SIZES_lower_bound = 0.04
    SIZES_upper_bound = 0.36
    SIZES_TRAIN = [0.04, 0.12, 0.20, 0.28, 0.36]
    SIZES_TEST = [0.08, 0.16, 0.24, 0.32]
    
    
    # Dictionary to store the setup
    data_setup = {
        'EPS': EPS,
        'BOX_LENGTH': BOX_LENGTH,
        'BOX_HEIGHT': BOX_HEIGHT,
        'SHOW_MICROSTRUCTURE': SHOW_MICROSTRUCTURE,
        'FILENAME': FILENAME,
        'N_THREADS': N_THREADS,
    
        # Simulation parameters
        'TILING': TILING,
        'N_REFINEMENTS': N_REFINEMENTS,
        'DEGREE_ELEVATIONS': DEGREE_ELEVATIONS,
        'INLET_BOUNDARY_ID': INLET_BOUNDARY_ID,
        'OUTLET_BOUNDARY_ID': OUTLET_BOUNDARY_ID,
        'INLET_PEAK_VELOCITY': INLET_PEAK_VELOCITY,
        'CLOSING_FACE': CLOSING_FACE,
        'OBJECTIVE_FUNCTION': OBJECTIVE_FUNCTION,
        'OBJECTIVE_FUNCTION_WEIGHTS': OBJECTIVE_FUNCTION_WEIGHTS,
    
        'MICROTILE': microtile_string,
        'N_SIZES_TRAIN': len(SIZES_TRAIN)**TILING[1],
        'N_SIZES_TEST': len(SIZES_TEST)**TILING[1],
    }
    
    data_sizes = {
        'size_1': [],
        'size_2': [],
        'size_3': [],
    }
    
    
    
    if __name__ == "__main__":
        # Define microstructure deformation function
        initial_macro_spline = sp.helpme.create.box(BOX_LENGTH, BOX_HEIGHT)
        # x0_max, x1_max = initial_macro_spline.cps.max(axis=0)
        # print(f'x0_max: {x0_max}, x1_max: {x1_max}')
        
        # Define identifier functions for microstructure boundaries
        def identifier_inlet(points):
            return points[:, 0] < EPS
    
        def identifier_outlet(points):
            return points[:, 0] > BOX_LENGTH - EPS
    
        boundary_identifier_dict = {
            identifier_inlet: INLET_BOUNDARY_ID,
            identifier_outlet: OUTLET_BOUNDARY_ID,
        }
    
        knots_y = np.linspace(0, 1, TILING[1] * 2 + 1)[1:-1:2]
        # print(f'knots_y: {knots_y}')
        train_index = 0
        # Train models
        if not os.path.exists('Data'): os.mkdir('Data')
        if os.path.exists('Data/train'): shutil.rmtree('Data/train')
        os.mkdir('Data/train')
        if os.path.exists('Data/train/microstructure'): shutil.rmtree('Data/train/microstructure/')
        os.mkdir('Data/train/microstructure')
        if os.path.exists('Data/test'): shutil.rmtree('Data/test')
        os.mkdir('Data/test')
        if os.path.exists('Data/test/microstructure'): shutil.rmtree('Data/test/microstructure/')
        os.mkdir('Data/test/microstructure')
        for size_1 in SIZES_TRAIN:
            for size_2 in SIZES_TRAIN:
                for size_3 in SIZES_TRAIN:
                    data_sizes['size_1'].append(size_1)
                    data_sizes['size_2'].append(size_2)
                    data_sizes['size_3'].append(size_3)
                    
                    microstructure, gismo_export_options = generate(
                        size_1, size_2, size_3, BOX_LENGTH, BOX_HEIGHT, EPS, INLET_BOUNDARY_ID, OUTLET_BOUNDARY_ID, knots_y, TILING, CLOSING_FACE, MICROTILE
                    )
                    export(
                        fname=f'Data/train/microstructure/index_{train_index}.xml', multipatch=microstructure,
                        indent=True,
                        additional_blocks=gismo_export_options,
                        as_base64=False
                    )
    
    
                    train_index+=1
        data_setup['N_SIZES_TRAIN'] = train_index
        df_sizes = pd.DataFrame(data_sizes)
        df_sizes.to_excel('Data/train/parameter_input.xlsx', index=True)
    
        # Test models
        test_index = 0
        for size_1 in SIZES_TEST:
            for size_2 in SIZES_TEST:
                for size_3 in SIZES_TEST:
                    data_sizes['size_1'].append(size_1)
                    data_sizes['size_2'].append(size_2)
                    data_sizes['size_3'].append(size_3)
                    
                    microstructure, gismo_export_options = generate(
                        size_1, size_2, size_3, BOX_LENGTH, BOX_HEIGHT, EPS, INLET_BOUNDARY_ID, OUTLET_BOUNDARY_ID, knots_y, TILING, CLOSING_FACE, MICROTILE
                    )
                    export(
                        fname=f'Data/test/microstructure/index_{test_index}.xml', multipatch=microstructure,
                        indent=True,
                        additional_blocks=gismo_export_options,
                        as_base64=False
                    )
    
                    test_index+=1
    
        data_setup['N_SIZES_TEST'] = test_index
        df_sizes = pd.DataFrame(data_sizes).iloc[train_index:]
        df_sizes.to_excel('Data/test/parameter_input.xlsx', index=True)
    
    
    # df = pd.DataFrame(data)
    df_setup = pd.DataFrame.from_dict(data_setup, orient='index')
    df_setup = df_setup.transpose()
    df_setup.to_excel('Data/HollowOctagon_Setup.xlsx', index=False)
    
    # df_sizes = pd.DataFrame(data_sizes)
    # df_sizes.to_excel('Data/Parameter/HollowOctagon_Sizes.xlsx', index=True)