Page MenuHomec4science

surface
No OneTemporary

File Metadata

Created
Sun, Dec 29, 08:11
#!/usr/bin/env python3
# -*- mode: python; coding: utf-8 -*-
# vim: set ft=python:
"""
Create a random self-affine rough surface from command line parameters.
"""
import argparse
import sys
import time
import tamaas as tm
import numpy as np
__author__ = "Lucas Frérot"
__copyright__ = (
"Copyright (©) 2019-2023, EPFL (École Polytechnique Fédérale de Lausanne),"
"\nLaboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)"
)
__license__ = "SPDX-License-Identifier: AGPL-3.0-or-later"
parser = argparse.ArgumentParser(
description="Generate a self-affine rough surface"
)
parser.add_argument("--cutoffs", "-K",
nargs=3,
type=int,
help="Long, rolloff and short wavelength cutoffs",
metavar=('k_l', 'k_r', 'k_s'),
required=True)
parser.add_argument("--sizes",
nargs=2,
type=int,
help="Number of points",
metavar=('nx', 'ny'),
required=True)
parser.add_argument("--hurst", "-H",
type=float,
help="Hurst exponent",
required=True)
parser.add_argument("--rms",
type=float,
help="Root-mean-square of slopes",
default=1.)
parser.add_argument("--seed",
type=int,
help="Random seed",
default=int(time.time()))
parser.add_argument("--generator",
help="Generation method",
choices=('random_phase', 'filter'),
default='random_phase')
parser.add_argument("--output", "-o",
help="Output file name (compressed if .gz)")
args = parser.parse_args()
if args.generator == 'random_phase':
generator = tm.SurfaceGeneratorRandomPhase2D(args.sizes)
elif args.generator == 'filter':
generator = tm.SurfaceGeneratorFilter2D(args.sizes)
else:
raise ValueError('Unknown generator method {}'.format(args.generator))
generator.spectrum = tm.Isopowerlaw2D()
generator.spectrum.q0 = args.cutoffs[0]
generator.spectrum.q1 = args.cutoffs[1]
generator.spectrum.q2 = args.cutoffs[2]
generator.spectrum.hurst = args.hurst
generator.random_seed = args.seed
surface = generator.buildSurface() / generator.spectrum.rmsSlopes() * args.rms
output = args.output if args.output is not None else sys.stdout
np.savetxt(output, surface)

Event Timeline