Skip to content
Snippets Groups Projects
Select Git revision
  • 4cc4b58d90556c85f48e602c7fe37506099be4eb
  • master default protected
  • dof-renumbering
  • test-dof-hash
  • gdemesy-master-patch-30528
  • eval-space-time
  • oscillating_multiharm
  • MH_movement
  • axisqu
  • write_vtu_and_ensight_formats
  • movingband
  • CP_1972_add_vtu_file_writing
  • mortar
  • fast_freq_sweep_Resolution
  • applyresolvent_again
  • marteaua-master-patch-54323
  • patch-1
  • binde-master-patch-08072
  • binde-master-patch-52461
  • BCGSL
  • resolvent
  • getdp_3_5_0
  • getdp_3_4_0
  • getdp_3_3_0
  • getdp_3_2_0
  • getdp_3_1_0
  • getdp_3_0_4
  • getdp_3_0_3
  • getdp_3_0_2
  • getdp_3_0_1
  • getdp_3_0_0
  • onelab_mobile_2.1.0
  • getdp_2_11_3 protected
  • getdp_2_11_2 protected
  • getdp_2_11_1 protected
  • getdp_2_11_0 protected
  • getdp_2_10_0 protected
  • getdp_2_9_2 protected
  • getdp_2_9_1 protected
  • getdp_2_9_0 protected
  • getdp_2_8_0 protected
41 results

OS.h

Blame
  • prepro.py 4.51 KiB
    import gmsh
    import math
    import sys
    
    # This example shows how to implement a simple interactive pre-processor for a
    # finite element solver, i.e. by interactively specifying boundary conditions
    # and material properties on parts of the model
    
    gmsh.initialize(sys.argv)
    if len(sys.argv) > 1:
        gmsh.open(sys.argv[1])
    
    # For Gmsh to know which types of boundary conditions/materials are available,
    # we define "template" ONELAB variables, whose names contains the following
    # substrings:
    #
    # - 'ONELAB Context/Point Template/'
    # - 'ONELAB Context/Curve Template/'
    # - 'ONELAB Context/Surface Template/'
    # - 'ONELAB Context/Volume Template/'
    #
    # Double- (or right-) clicking on an entity in the GUI will pop-up a window
    # where instances of these variables for the given entity can be edited. For
    # example, if the 'ONELAB Context/Curve Template/0Boundary condition' exists,
    # double-clicking on curve 123 in the model will create 'ONELAB Context/Curve
    # 123/0Boundary condition' (or 'ONELAB Context/Physical Curve 1000/0Boundary
    # condition' depending on the choice in the window, if Curve 123 belongs to the
    # Physical Curve 1000)
    #
    parameters = """
    [
      {
        "type":"number",
        "name":"ONELAB Context/Curve Template/0Boundary condition",
        "values":[0],
        "choices":[0, 1],
        "valueLabels":{"Temperature [℃]":0, "Flux [Wm⁻²]":1}
      },
      {
        "type":"number",
        "name":"ONELAB Context/Curve Template/1Value",
        "values":[20],
        "min":0,
        "max":100,
        "step":0.1
      },
      {
        "type":"number",
        "name":"ONELAB Context/Surface Template/0Material",
        "values":[1],
        "choices":[0, 1, 2],
        "valueLabels":{"User-defined":0, "Steel":1, "Concrete":2},
        "attributes":{"ServerActionHide":"ONELAB Context/Surface Template/1.*",
                      "ServerActionShow 0":"ONELAB Context/Surface Template/1.*"}
      },
      {
        "type":"number",
        "name":"ONELAB Context/Surface Template/10Conductivity [Wm⁻¹K⁻¹]",
        "values":[205],
        "min":0.1,
        "max":500,
        "step":0.1,
        "visible":false
      },
      {
        "type":"number",
        "name":"ONELAB Context/Surface Template/11Diffusivity [mm²s⁻¹]",
        "values":[97],
        "min":10,
        "max":1200,
        "step":0.1,
        "visible":false
      },
      {
        "type":"string",
        "name":"ONELAB/Button",
        "values":["Run", "run"],
        "visible":false
      },
      {
        "type":"number",
        "name":"My solver/1Some flag",
        "values":[0],
        "choices":[0, 1]
      },
      {
        "type":"number",
        "name":"My solver/2Some parameter",
        "values":[1.234],
        "min":0,
        "max":10,
        "step":0.1
      },
      {
        "type":"number",
        "name":"My solver/3Some choice",
        "values":[0],
        "choices":[0, 1],
        "valueLabels":{"Choice 1": 0, "Choice 2": 1}
      },
      {
        "type":"string",
        "name":"My solver/3Some input",
        "values":[""]
      },
      {
        "type":"string",
        "name":"My solver/5Some action",
        "values":["select entity"],
        "attributes":{"Macro":"Action"}
      }
    ]"""
    
    gmsh.onelab.set(parameters)
    
    def runSolver():
        print('parameters =', gmsh.onelab.get())
        print('running the solver with the given parameters...')
    
    def eventLoop():
        # terminate the event loop if the GUI was closed
        if gmsh.fltk.isAvailable() == 0: return 0
        # wait for an event
        gmsh.fltk.wait()
        # check if an action is requested
        action = gmsh.onelab.getString("ONELAB/Action")
        if len(action) < 1:
            # no action requested
            pass
        elif action[0] == "check":
            # database was changed: update/define new parameters depending on new
            # state
            gmsh.onelab.setString("ONELAB/Action", [""])
            # print('parameters = ', gmsh.onelab.get())
            gmsh.fltk.update()
        elif action[0] == "reset":
            # user clicked on "Reset database"
            gmsh.onelab.setString("ONELAB/Action", [""])
            gmsh.onelab.set(parameters)
            gmsh.fltk.update()
        elif action[0] == "run":
            # user clicked on "Run"
            gmsh.onelab.setString("ONELAB/Action", [""])
            runSolver()
        elif action[0] == "select entity":
            # user clicked on "My solver/Select an entity"
            gmsh.onelab.setString("ONELAB/Action", [""])
            gmsh.fltk.setStatusMessage(
                "Please select an entity (or press 'q' to quit)", True)
            r, ent = gmsh.fltk.selectEntities()
            if gmsh.fltk.isAvailable() == 0: return 0
            if r and len(ent):
                gmsh.fltk.showContextWindow(ent[0][0], ent[0][1])
            gmsh.fltk.setStatusMessage('', True)
        return 1
    
    if '-nopopup' not in sys.argv:
        gmsh.fltk.initialize()
        while eventLoop():
            pass
    else:
        runSolver()
    
    gmsh.finalize()