NuMRI/kalman/run_forward.py
2020-11-23 13:41:11 +01:00

43 lines
1.2 KiB
Python

''' Run a forward simulation.
Detects FractionalStep and Hyperelasticity from input files.
'''
from dolfin import parameters
import ruamel.yaml as yaml
import argparse
import logging
logging.getLogger().setLevel(logging.INFO)
parameters['form_compiler']['optimize'] = True
parameters['form_compiler']['cpp_optimize'] = True
parameters['form_compiler']['cpp_optimize_flags'] = ('-O3 -ffast-math '
'-march=native')
def get_forward_solver(inputfile):
''' Get forward solver from input file '''
with open(inputfile, 'r') as f:
options = yaml.load(f)
if 'fluid' in options:
from navierstokes import solver
elif 'material' in options:
parameters['form_compiler']['quadrature_degree'] = 6
from hyperelasticity import solver
return solver
def get_parser():
parser = argparse.ArgumentParser(
description='Run forward simulation',
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('inputfile', type=str, help='path to YAML input file')
return parser
if __name__ == '__main__':
inputfile = get_parser().parse_args().inputfile
solver = get_forward_solver(inputfile)
sol = solver.init(inputfile)
sol.solve()