def GaussianRandomInitializer(gridShape, sigma=0.2, seed=None, slipSystem=None, slipPlanes=None, slipDirections=None, vacancy=None, smectic=None): oldgrid = copy.copy(gridShape) if len(gridShape) == 1: gridShape = (128,) if len(gridShape) == 2: gridShape = (128,128) if len(gridShape) == 3: gridShape = (128,128,128) """ Returns a random initial set of fields of class type PlasticityState """ if slipSystem=='gamma': state = SlipSystemState.SlipSystemState(gridShape,slipPlanes=slipPlanes,slipDirections=slipDirections) elif slipSystem=='betaP': state = SlipSystemBetaPState.SlipSystemState(gridShape,slipPlanes=slipPlanes,slipDirections=slipDirections) else: if vacancy is not None: state = VacancyState.VacancyState(gridShape,alpha=vacancy) elif smectic is not None: state = SmecticState.SmecticState(gridShape) else: state = PlasticityState.PlasticityState(gridShape) field = state.GetOrderParameterField() Ksq_prime = FourierSpaceTools.FourierSpaceTools(gridShape).kSq * (-sigma**2/4.) if seed is None: seed = 0 n = 0 random.seed(seed) Ksq = FourierSpaceTools.FourierSpaceTools(gridShape).kSq.numpy_array() for component in field.components: temp = random.normal(scale=gridShape[0],size=gridShape) ktemp = fft.rfftn(temp)*(sqrt(pi)*sigma)**len(gridShape)*exp(-Ksq*sigma**2/4.) field[component] = numpy.real(fft.irfftn(ktemp)) #field[component] = GenerateGaussianRandomArray(gridShape, temp ,sigma) n += 1 """ t, s = LoadState("2dstate32.save", 0) for component in field.components: for j in range(0,32): field[component][:,:,j] = s.betaP[component].numpy_array() """ ## To make seed consistent across grid sizes and convergence comparison gridShape = copy.copy(oldgrid) if gridShape[0] != 128: state = ResizeState(state,gridShape[0],Dim=len(gridShape)) state = ReformatState(state) state.ktools = FourierSpaceTools.FourierSpaceTools(gridShape) return state
def SmecticInitializer(gridShape, sigma=0.2, seed=None): if seed is None: seed = 0 random.seed(seed) state = SmecticState.SmecticState(gridShape) field = state.GetOrderParameterField() Ksq = FourierSpaceTools.FourierSpaceTools(gridShape).kSq.numpy_array() for component in field.components: temp = random.normal(scale=gridShape[0],size=gridShape) ktemp = fft.rfftn(temp)*(sqrt(pi)*sigma)**len(gridShape)*exp(-Ksq*sigma**2/4.) field[component] = numpy.real(fft.irfftn(ktemp)) ## To make seed consistent across grid sizes and convergence comparison gridShape = copy.copy(oldgrid) if gridShape[0] != 128: state = ResizeState(state,gridShape[0],Dim=len(gridShape)) state = ReformatState(state) state.ktools = FourierSpaceTools.FourierSpaceTools(gridShape) return state