def make_fluid_store(): """ Make an example fluid case for reusing later """ fluid_store = Case(name="fluids_R_us", visible=False) fluida = CaseField(name="fluidA", parent_case=fluid_store) fluida_density = CaseField(name="density", parent_field=fluida) ParameterSpec(name="min", value="200", parent_casefield=fluida_density) ParameterSpec(name="max", value="4000", parent_casefield=fluida_density) ParameterSpec(name="default", value="1000", parent_casefield=fluida_density) ParameterSpec(name="units", value="kg/m³", parent_casefield=fluida_density) fluida_viscosity = CaseField(name="viscosity", parent_field=fluida) ParameterSpec(name="min", value="0.01", parent_casefield=fluida_viscosity) ParameterSpec(name="max", value="4.", parent_casefield=fluida_viscosity) ParameterSpec(name="default", value="1", parent_casefield=fluida_viscosity) ParameterSpec(name="units", value="Pa.s", parent_casefield=fluida_viscosity) return fluid_store
def make_dambreak(): """ The openfoam dambreak case. """ dambreak = Case(name="dambreak_test") Script(name="Allrun", url="testopenfoamapi", parent_case=dambreak) Script(name="Allclean", url="testopenfoamapi", parent_case=dambreak) return dambreak
def make_tank_store(): """ Make an example tank case containing a sample tank """ tank_store = Case(name="tanks_R_us", visible=False) tanka = CaseField(name="tankA", parent_case=tank_store) tanka_length = CaseField(name="length", parent_field=tanka) ParameterSpec(name="min", value="0.2", parent_casefield=tanka_length) ParameterSpec(name="max", value="40", parent_casefield=tanka_length) ParameterSpec(name="default", value="3", parent_casefield=tanka_length) ParameterSpec(name="units", value="m", parent_casefield=tanka_length) tanka_width = CaseField(name="width", parent_field=tanka) ParameterSpec(name="min", value="0.1", parent_casefield=tanka_width) ParameterSpec(name="max", value="40", parent_casefield=tanka_width) ParameterSpec(name="default", value="3", parent_casefield=tanka_width) ParameterSpec(name="units", value="m", parent_casefield=tanka_width) return tank_store
def set_up_cavity_testdata(): """ Make a cavity case and commit it to the database """ session = db.session exists = session.query(Case).filter(Case.name == "cavity").first() if exists: return f"Case already exists: cavity." repository = Repository( url="https://github.com/alan-turing-institute/simulate-cavity.git", branch=None, commit=None, ) # make cavity case cavity = Case( name="cavity", thumbnail="https://raw.githubusercontent.com/alan-turing-institute/" "simulate-cavity/master/thumbnail.png", description="icoFoam cavity tutorial", repository=repository, visible=True, ) fluid = CaseField(name="fluid", parent_case=cavity) kinematic_viscosity = CaseField(name="kinematic_viscosity", parent_field=fluid, component="slider") ParameterSpec(name="min", value="0.001", parent_casefield=kinematic_viscosity) ParameterSpec(name="max", value="1.0", parent_casefield=kinematic_viscosity) ParameterSpec(name="step", value="0.001", parent_casefield=kinematic_viscosity) ParameterSpec(name="default", value="0.01", parent_casefield=kinematic_viscosity) ParameterSpec(name="units", value="m²/s", parent_casefield=kinematic_viscosity) lid = CaseField(name="lid", parent_case=cavity) wall_velocity = CaseField(name="wall_velocity", parent_field=lid, component="slider") ParameterSpec(name="min", value="0.1", parent_casefield=wall_velocity) ParameterSpec(name="max", value="2.0", parent_casefield=wall_velocity) ParameterSpec(name="step", value="0.01", parent_casefield=wall_velocity) ParameterSpec(name="default", value="0.5", parent_casefield=wall_velocity) ParameterSpec(name="units", value="m/s", parent_casefield=wall_velocity) script = Script( parent_case=cavity, source="constants.template.yml", destination="constants.yml", action=None, patch=True, ) session.add(script) script = Script( parent_case=cavity, source="simulate/state/job_id", destination="simulate/state/job_id", action=None, patch=True, ) session.add(script) script = Script( parent_case=cavity, source="simulate/state/job_token", destination="simulate/state/job_token", action=None, patch=True, ) session.add(script) script = Script( parent_case=cavity, source="simulate/state/manager_url", destination="simulate/state/manager_url", action=None, patch=True, ) session.add(script) script = Script( parent_case=cavity, source=None, destination="simulate/run.sh", action="RUN", patch=False, ) session.add(script) Script( parent_case=cavity, source=None, destination="simulate/stop.sh", action="STOP", patch=False, ) session.add(script) session.add(cavity) session.commit() return "Added case: cavity."
def make_phases(): """ Make an example fluid case for reusing later """ phase_store = Case(name="phases", visible=False) # phase_A (e.g. water) phase_A = CaseField(name="phase_A", parent_case=phase_store, component="heading") phase_A_density = CaseField(name="density", parent_field=phase_A, component="slider") ParameterSpec(name="min", value="1", parent_casefield=phase_A_density) ParameterSpec(name="max", value="2000", parent_casefield=phase_A_density) ParameterSpec(name="default", value="1000", parent_casefield=phase_A_density) ParameterSpec(name="units", value="kg/m³", parent_casefield=phase_A_density) phase_A_viscosity = CaseField(name="viscosity", parent_field=phase_A, component="slider") ParameterSpec(name="min", value="0.000001", parent_casefield=phase_A_viscosity) ParameterSpec(name="max", value="0.0001", parent_casefield=phase_A_viscosity) ParameterSpec(name="step", value="0.000001", parent_casefield=phase_A_viscosity) ParameterSpec(name="default", value="0.00001", parent_casefield=phase_A_viscosity) ParameterSpec(name="units", value="m/s²", parent_casefield=phase_A_viscosity) phase_A_surface_tension = CaseField(name="surface_tension", parent_field=phase_A, component="slider") ParameterSpec(name="min", value="0.01", parent_casefield=phase_A_surface_tension) ParameterSpec(name="max", value="0.1", parent_casefield=phase_A_surface_tension) ParameterSpec(name="step", value="0.01", parent_casefield=phase_A_surface_tension) ParameterSpec(name="default", value="0.07", parent_casefield=phase_A_surface_tension) ParameterSpec(name="units", value="N/m", parent_casefield=phase_A_surface_tension) # phase_B (e.g. air) phase_B = CaseField(name="phase_B", parent_case=phase_store, component="heading") phase_B_density = CaseField(name="density", parent_field=phase_B, component="slider") ParameterSpec(name="min", value="1", parent_casefield=phase_B_density) ParameterSpec(name="max", value="2000", parent_casefield=phase_B_density) ParameterSpec(name="default", value="1000", parent_casefield=phase_B_density) ParameterSpec(name="units", value="kg/m³", parent_casefield=phase_B_density) phase_B_viscosity = CaseField(name="viscosity", parent_field=phase_B, component="slider") ParameterSpec(name="min", value="0.000001", parent_casefield=phase_B_viscosity) ParameterSpec(name="max", value="0.0001", parent_casefield=phase_B_viscosity) ParameterSpec(name="step", value="0.000001", parent_casefield=phase_B_viscosity) ParameterSpec(name="default", value="0.00001", parent_casefield=phase_B_viscosity) ParameterSpec(name="units", value="m/s²", parent_casefield=phase_B_viscosity) return phase_store
def set_up_dambreak_testdata(): """ Make a real case, using phases from the 'phase store', and commit it to the database """ phase_store_message = create_phase_store() session = db.session exists = session.query(Case).filter(Case.name == "damBreak").first() if exists: return f"{phase_store_message} Case already exists: damBreak." repository = Repository( url="https://github.com/alan-turing-institute/simulate-damBreak.git", branch=None, commit=None, ) # make damBreak case damBreak = Case( name="damBreak", thumbnail="https://raw.githubusercontent.com/alan-turing-institute/" "simulate-damBreak/master/thumbnail.png", description="interFoam damBreak tutorial", repository=repository, visible=True, ) # retrieve the phase store from the database new_phase_store = session.query(Case).filter(Case.name == "phases").first() # copy phases from the phase store, and name them Water and Air new_phaseA = new_phase_store.fields[0].deep_copy() new_phaseA.name = "Water" new_phaseA.prepend_prefix("Water_") new_phaseB = new_phase_store.fields[1].deep_copy() new_phaseB.name = "Air" new_phaseB.prepend_prefix("Air_") damBreak.fields.append(new_phaseA) damBreak.fields.append(new_phaseB) script = Script( parent_case=damBreak, source="constants.template.yml", destination="constants.yml", action=None, patch=True, ) session.add(script) script = Script( parent_case=damBreak, source="simulate/state/job_id", destination="simulate/state/job_id", action=None, patch=True, ) session.add(script) script = Script( parent_case=damBreak, source="simulate/state/job_token", destination="simulate/state/job_token", action=None, patch=True, ) session.add(script) script = Script( parent_case=damBreak, source="simulate/state/manager_url", destination="simulate/state/manager_url", action=None, patch=True, ) session.add(script) script = Script( parent_case=damBreak, source=None, destination="simulate/run.sh", action="RUN", patch=False, ) session.add(script) Script( parent_case=damBreak, source=None, destination="simulate/stop.sh", action="STOP", patch=False, ) session.add(script) session.add(damBreak) session.commit() return f"{phase_store_message} Added case: damBreak."
def set_up_test_database(): """ Set up a database with some stuff in it """ # preamble - pretend this bit is being done before hand ################# # add some cases to the Tank Store and the Fluid Store session = db.session tank = make_tank_store() fluid = make_fluid_store() done = False for _ in Case.query.all(): done = True if done: print("Data already there!") exit() session.add(tank) session.add(fluid) session.commit() # add milk and tankX (fixed values for Jobs) to the JobParameterTemplate make_mint_store(session) # end of preamble ################# # create a real case, using the tank from the tank store # and the fluid from the fluid store mycase = Case(name="MyCase", visible=True) new_tank_store = session.query(Case).filter( Case.name == "tanks_R_us").first() new_tankA = new_tank_store.fields[0].deep_copy() new_fluid_store = session.query(Case).filter( Case.name == "fluids_R_us").first() new_fluid1 = new_fluid_store.fields[0].deep_copy() new_fluid1.name = "fluid 1" new_fluid1.prepend_prefix("Fluid1_") new_fluid2 = new_fluid_store.fields[0].deep_copy() new_fluid2.name = "fluid 2" new_fluid2.prepend_prefix("Fluid2_") mycase.fields.append(new_tankA) mycase.fields.append(new_fluid1) mycase.fields.append(new_fluid2) start = Script( parent_case=mycase, action="start", source="http://the.internet/start", destination="start", patch=False, ) run = Script( parent_case=mycase, action="run", source="http://the.internet/run", destination="run", patch=False, ) gofish = Script( parent_case=mycase, action="gofish", source="http://the.internet/gofish", destination="gofish", patch=False, ) # save this to the DB session.add(mycase) session.add(start) session.add(run) session.add(gofish) session.commit() # test the prefix has been added # print('prefix to fluid2 viscosity ', # mycase.fields[2].child_field[1].specs[-1].property_value) ################################################################### # ########################try minting a case ######################## # create a dictionary with the mapping between # the case names and the mintstore names # => i guess the UI will have a better way of doing this in real life! mintstoremap = {"tankA": "TankX", "fluid 1": "Milk", "fluid 2": "Water"} minted_case = mint_case(session, "TESTMINT", mycase, "testuser", mintstoremap) session.add(minted_case) session.commit()