data={"desc": "P-01 gas pipeline."}) P01_1 = Premise("P-01 pipeline section 1, KP 0-0.3", parent=P01, parameters={ "KP": [0, 0.3], "h_l": -370, "LC": 2, "SC": "high", "D": 0.6172 + 2*0.0242, "t": 0.0242, }, data={"desc": "P-01 section 1, KP 0-0.3."}) rootnode.plugin_func("pipe_physical_props", "pdover2t", argmap={ "Do": "D", "WT": "t", }) rootnode.plugin_func("pressure_containment_all", "pdover2t.dnvgl_st_f101") rootnode.plugin_func("pipe_collapse_all", "pdover2t.dnvgl_st_f101") lc1_pprops = Calc("Calc: pipe properties", parent=P01_1, data={"desc": "pipe physical properties."}, funcname="pipe_physical_props") lc1_cont = Calc("Calc: pressure containment", parent=P01_1, parameters={ "h_l": -370, }, data={"desc": "pressure containment calcs."}, funcname="pressure_containment_all")
basecase = Premise("Base case", parameters=parameters, data={"desc": "This is the base-case loadcase."}, vnpkl_fpath=vnpkl_file) lc1 = Premise("Load case 1", parent=basecase, data={"desc": "This is the 1st child loadcase."}) gc1 = Premise("gchild lc1", parent=lc1, data={"desc": "This is the 1st child loadcase."}) lc2 = Premise("Load case 2", parent=basecase, data={"desc": "This is the 2nd child loadcase."}) basecase.plugin_func("pressure_containment_all", "pdover2t.dnvgl_st_f101") lc1.rho_cont = np.linspace(100, 1000, 10) print("lc1.rho_cont", lc1.rho_cont) resdict = lc1.pressure_containment_all() print(resdict["p_cont_uty"]) lc1_pcont = Premise("GROUP: lc1 press contain", parent=lc1, data={"desc": "Group lc1 pressure contain calcs."}) _uty = lc1_pcont.pressure_containment_all(rho_cont=100) print("lc1_pcont (rho_cont=100) ", _uty) lc2_pcont = Calc("CallNode: lc2 press contain", parent=lc2, data={"desc": "Group lc2 pressure contain calcs."},
params2 = { #"c": 100, "c": np.array([10,20,30,1001.]), "d": 100., } rootnode = Premise("Root Node", parameters={ **params1, }, data={"desc": "Top-level parameters."}, vnpkl_fpath="add_tests.vn3") base1 = Premise("Base 1", parent=rootnode) rootnode.plugin_func(addAB) rootnode.plugin_func(addCD, argmap={"return":"CplusD"}) if True: addab = Calc("Calc: addAB", parent=rootnode, data={"desc": "First calc."}, funcname="addAB") addcd = Calc("Calc: addCD", parent=addab, parameters={ **params2, }, data={"desc": "2nd calc."}, funcname="addCD") total = Calc("Calc: add results", parent=addcd,
https://github.com/benranderson/wall """ from pflacs import Premise import numpy import wall import seawater base = Premise("Basecase") base.add_param("water_depth", 110, "water depth (m)") base.add_param("rho_seawater", 1025, "assumed water density (kg/m3)") base.add_param("pressure", desc="pressure (Pa)") base.plugin_func(wall.pressure_head, argmap={ "h": "water_depth", "rho": "rho_seawater" }) base.pressure = base.pressure_head() print(f'{base.name} pressure = {base.pressure}') base.add_param("lat", 53.2, "geographical latitude") base.add_param("S", 35, "water salinity") base.add_param("T", 8, "water temperature (°C)") base.plugin_func(seawater.dens) base.add_param("rho_seawater_check", desc="calculated water density (kg/m3)") base.rho_seawater_check = base.dens() print( f'{base.get_param_desc("rho_seawater_check")} = {base.rho_seawater_check}') if base.rho_seawater != base.rho_seawater_check:
# SETUP_NEW_STUDY = False # OPEN_EXISTING_STUDY = True if SETUP_NEW_STUDY: print(f"Create a new study.") study_parameters = { "ys": 22.1 * 10**6, # pipe yield strength in Pa "D": 110 * 10**-3, # pipe outer diameter in m "P": 20 * 10**5, # pipe internal pressure in Pa (20 bar) "t": 5 * 10**-3, "design_factor": 0.8, } basecase = Premise("Pipe study base case.", parameters=study_parameters) basecase.plugin_func(pipe_hoop_stress) basecase.plugin_func(allowable_stress_unity_check) #basecase.plugin_func("pressure_containment_all", "pdover2t.dnvgl_st_f101") #basecase.plugin_func(pdover2t.dnvgl_st_f101.pressure_containment_all) lc1 = Premise( "LoadCase1, pressure 15 bar.", basecase, parameters={ "P": 15 * 10**5, # pipe internal pressure in Pa }) lc1_pstress = Calc( "Calc pipe stress", lc1, funcname="pipe_hoop_stress", ) lc1_unity = Calc("Stress unity check",
_funcname = _d.get("funcname", None) _argmap = _d.get("argmap", None) _n = Calc(_name, _parent, parameters=_paras, funcname=_funcname, argmap=_argmap) _parent = _n return _n._root calctree = make_calc_branch(pipemass_branch) P101 = Premise( "P101", parameters=P101_data, data={ "desc": "Top-level field details, environmental and universal parameters." }) P101.plugin_func("calc_pipe_Di", "pdover2t.pipe") P101.plugin_func("pipe_CSA", "pdover2t.pipe") P101_z1 = Premise("P101 zone1", parent=P101) P101_z2 = Premise("P101 zone2", parent=P101) #P101.plugin_func("calc_pipe_Di", "pdover2t.pipe") calc_joint_mass = Calc("calc Di", parent=P101_z1, funcname="calc_pipe_Di")
import unittest from pflacs import Premise def add_abc(a, b, c=0): return a + b + c def sub_xy(x, y): return x - y basecase = Premise("Base case", parameters={"a":10, "b":20, "c":30}, data={"description": "This is the base-case loadcase."}) basecase.plugin_func(add_abc) para1 = Premise("Parameter study 1", parent=basecase, data={"description": ("This is the 1st parameter study " "loadcase, it is effectively the same as the base-case." ) }) para1.plugin_func(sub_xy, argmap={"x": "a", "y":"b"}) para2 = Premise("Parameter study 2", parent=basecase, parameters={"a":-20.8}, data={"description": ("This is the 2nd parameter study " "loadcase." ) }) print(basecase.to_texttree())
area_hw = rectangle_area(h, w) if area_wb is None: area_wb = rectangle_area(w, b) if area_bh is None: area_bh = rectangle_area(b, h) area = 2.0 * (area_hw + area_wb + area_bh) return area basecase = Premise("Study base-case", parameters={ "w": 4, "b": 5, "h": 3.5, }) basecase.plugin_func(rectangle_area) basecase.plugin_func(box_volume) print(f"Base-case rectange area = {basecase.rectangle_area()}") print(f"Base-case cube volume = {basecase.box_volume()}") parastudy = Premise("Parameter study", parent=basecase, parameters={ "w": np.array([1.0, 1.35, 2.0, 4.5]), "b": np.linspace(2.2, 5.5, 4), "h": 10.0, }) rect = Calc("Study rectangle area", parent=parastudy,
parent=P01, parameters={ "KP": [0.3, 15.0], "h_l": -420, "LC": 1, "D": 0.6172 + 2*0.0242, "t": 0.0242, }, data={"desc": "P-01 section 2, KP 0.3-15."}) P01_3 = Premise("P-01 section 3, KP 15-79.7", parent=P01, parameters={ "KP": [15.0, 79.7], "LC": 1, "D": 0.6172 + 2*0.0214, "t": 0.0214, }, data={"desc": "P-01 section 3, KP 15-79.7."}) rootnode.plugin_func("pressure_containment_all", "pdover2t.dnvgl_st_f101") rootnode.plugin_func("pipe_collapse_all", "pdover2t.dnvgl_st_f101") lc1_cont = Calc("Calc: lc2 press contain", parent=P01_1, parameters={ "h_l": -370, }, data={"desc": "Group lc2 pressure contain calcs."}, funcname="pressure_containment_all") rootnode.savefile()