solve.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from coefficients import coefficients
  2. from discretization import HDPG1d
  3. from postprocess import convHistory
  4. import sys
  5. def queryYesNo(question, default="yes"):
  6. valid = {"yes": True, "y": True, "ye": True,
  7. "no": False, "n": False}
  8. if default is None:
  9. prompt = " [y/n] "
  10. elif default == "yes":
  11. prompt = " [Y/n] "
  12. elif default == "no":
  13. prompt = " [y/N] "
  14. else:
  15. raise ValueError("invalid default answer: '%s'" % default)
  16. while True:
  17. sys.stdout.write(question + prompt)
  18. choice = input().lower()
  19. if default is not None and choice == '':
  20. return valid[default]
  21. elif choice in valid:
  22. return valid[choice]
  23. else:
  24. sys.stdout.write("Please respond with 'yes' or 'no' "
  25. "(or 'y' or 'n').\n")
  26. def getCoefficients():
  27. question = 'Do you want to use the default parameters?'
  28. isDefault = queryYesNo(question, "yes")
  29. if (isDefault):
  30. Coeff = coefficients(1, 1, 0, 2, 2)
  31. else:
  32. Coeff = coefficients.from_input()
  33. return Coeff
  34. menu = {}
  35. menu['1.'] = "Solve with HDG."
  36. menu['2.'] = "Solve with HDPG."
  37. menu['3.'] = "Exit."
  38. options = menu.keys()
  39. for entry in options:
  40. print(entry, menu[entry])
  41. selection = input("Please Select:")
  42. if selection == '1':
  43. hdgCoeff = getCoefficients()
  44. hdgSolution = HDPG1d(hdgCoeff.nele, hdgCoeff.porder)
  45. trueError, estError = hdgSolution.adaptive()
  46. convHistory(trueError, estError)
  47. elif selection == '2':
  48. print("In development...")
  49. elif selection == '3':
  50. print("Bye.")
  51. else:
  52. print("Unknown Option Selected!")