solve.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from .coefficients import coefficients
  2. from .discretization import hdpg1d
  3. from .postprocess import utils
  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. def menu():
  35. menu = {}
  36. menu['1.'] = "Solve with HDG."
  37. menu['2.'] = "Solve with HDPG."
  38. menu['3.'] = "Exit."
  39. for key, value in sorted(menu.items()):
  40. print(key, value)
  41. selection = input("Please Select: ")
  42. if selection == '1':
  43. hdgCoeff = getCoefficients()
  44. hdgSolution = hdpg1d(hdgCoeff.nele, hdgCoeff.porder)
  45. # solve the problem adaptively and plot convergence history
  46. hdgSolution.adaptive()
  47. post = utils(hdgSolution)
  48. post.convHistory()
  49. elif selection == '2':
  50. print("In development...")
  51. elif selection == '3':
  52. print("Bye.")
  53. else:
  54. print("Unknown Option Selected!")