diff --git a/src/Mod/Fem/femsolver/calculix/write_femelement_geometry.py b/src/Mod/Fem/femsolver/calculix/write_femelement_geometry.py index 64c0d6a925..559dd9cb85 100644 --- a/src/Mod/Fem/femsolver/calculix/write_femelement_geometry.py +++ b/src/Mod/Fem/femsolver/calculix/write_femelement_geometry.py @@ -27,39 +27,43 @@ __url__ = "https://www.freecadweb.org" def write_femelement_geometry(f, ccxwriter): + + # floats read from ccx should use {:.13G}, see comment in writer module + f.write("\n{}\n".format(59 * "*")) f.write("** Sections\n") for ccx_elset in ccxwriter.ccx_elsets: if ccx_elset["ccx_elset"]: + elsetdef = "ELSET={}, ".format(ccx_elset["ccx_elset_name"]) + material = "MATERIAL={}".format(ccx_elset["mat_obj_name"]) + if "beamsection_obj"in ccx_elset: # beam mesh beamsec_obj = ccx_elset["beamsection_obj"] - elsetdef = "ELSET=" + ccx_elset["ccx_elset_name"] + ", " - material = "MATERIAL=" + ccx_elset["mat_obj_name"] normal = ccx_elset["beam_normal"] if beamsec_obj.SectionType == "Rectangular": - height = beamsec_obj.RectHeight.getValueAs("mm") - width = beamsec_obj.RectWidth.getValueAs("mm") + height = beamsec_obj.RectHeight.getValueAs("mm").Value + width = beamsec_obj.RectWidth.getValueAs("mm").Value section_type = ", SECTION=RECT" - section_geo = str(height) + ", " + str(width) + "\n" + section_geo = "{:.13G},{:.13G}\n".format(height, width) section_def = "*BEAM SECTION, {}{}{}\n".format( elsetdef, material, section_type ) elif beamsec_obj.SectionType == "Circular": - radius = 0.5 * beamsec_obj.CircDiameter.getValueAs("mm") + radius = 0.5 * beamsec_obj.CircDiameter.getValueAs("mm").Value section_type = ", SECTION=CIRC" - section_geo = str(radius) + "\n" + section_geo = "{:.13G}\n".format(radius) section_def = "*BEAM SECTION, {}{}{}\n".format( elsetdef, material, section_type ) elif beamsec_obj.SectionType == "Pipe": - radius = 0.5 * beamsec_obj.PipeDiameter.getValueAs("mm") - thickness = beamsec_obj.PipeThickness.getValueAs("mm") + radius = 0.5 * beamsec_obj.PipeDiameter.getValueAs("mm").Value + thickness = beamsec_obj.PipeThickness.getValueAs("mm").Value section_type = ", SECTION=PIPE" - section_geo = str(radius) + ", " + str(thickness) + "\n" + section_geo = "{:.13G},{:.13G}\n".format(radius, thickness) section_def = "*BEAM GENERAL SECTION, {}{}{}\n".format( elsetdef, material, @@ -67,7 +71,7 @@ def write_femelement_geometry(f, ccxwriter): ) # see forum topic for output formatting of rotation # https://forum.freecadweb.org/viewtopic.php?f=18&t=46133&p=405142#p405142 - section_nor = "{:f}, {:f}, {:f}\n".format( + section_nor = "{:.13G}, {:.13G}, {:.13G}\n".format( normal[0], normal[1], normal[2] @@ -77,8 +81,6 @@ def write_femelement_geometry(f, ccxwriter): f.write(section_nor) elif "fluidsection_obj"in ccx_elset: # fluid mesh fluidsec_obj = ccx_elset["fluidsection_obj"] - elsetdef = "ELSET=" + ccx_elset["ccx_elset_name"] + ", " - material = "MATERIAL=" + ccx_elset["mat_obj_name"] if fluidsec_obj.SectionType == "Liquid": section_type = fluidsec_obj.LiquidSectionType if (section_type == "PIPE INLET") or (section_type == "PIPE OUTLET"): @@ -101,16 +103,13 @@ def write_femelement_geometry(f, ccxwriter): f.write(section_geo) elif "shellthickness_obj"in ccx_elset: # shell mesh shellth_obj = ccx_elset["shellthickness_obj"] - elsetdef = "ELSET=" + ccx_elset["ccx_elset_name"] + ", " - material = "MATERIAL=" + ccx_elset["mat_obj_name"] - section_def = "*SHELL SECTION, " + elsetdef + material + "\n" - section_geo = str(shellth_obj.Thickness.getValueAs("mm")) + "\n" + section_def = "*SHELL SECTION, {}{}\n".format(elsetdef, material) + thickness = shellth_obj.Thickness.getValueAs("mm").Value + section_geo = "{:.13G}\n".format(thickness) f.write(section_def) f.write(section_geo) else: # solid mesh - elsetdef = "ELSET=" + ccx_elset["ccx_elset_name"] + ", " - material = "MATERIAL=" + ccx_elset["mat_obj_name"] - section_def = "*SOLID SECTION, " + elsetdef + material + "\n" + section_def = "*SOLID SECTION, {}{}\n".format(elsetdef, material) f.write(section_def) @@ -118,37 +117,41 @@ def write_femelement_geometry(f, ccxwriter): # Helpers def liquid_section_def(obj, section_type): if section_type == "PIPE MANNING": - manning_area = str(obj.ManningArea.getValueAs("mm^2").Value) - manning_radius = str(obj.ManningRadius.getValueAs("mm")) - manning_coefficient = str(obj.ManningCoefficient) - section_geo = manning_area + "," + manning_radius + "," + manning_coefficient + "\n" + manning_area = obj.ManningArea.getValueAs("mm^2").Value + manning_radius = obj.ManningRadius.getValueAs("mm").Value + manning_coefficient = obj.ManningCoefficient + section_geo = "{:.13G},{:.13G},{:.13G}\n".format( + manning_area, + manning_radius, + manning_coefficient + ) return section_geo elif section_type == "PIPE ENLARGEMENT": - enlarge_area1 = str(obj.EnlargeArea1.getValueAs("mm^2").Value) - enlarge_area2 = str(obj.EnlargeArea2.getValueAs("mm^2").Value) - section_geo = enlarge_area1 + "," + enlarge_area2 + "\n" + enlarge_area1 = obj.EnlargeArea1.getValueAs("mm^2").Value + enlarge_area2 = obj.EnlargeArea2.getValueAs("mm^2").Value + section_geo = "{:.13G},{:.13G}\n".format(enlarge_area1, enlarge_area2) return section_geo elif section_type == "PIPE CONTRACTION": - contract_area1 = str(obj.ContractArea1.getValueAs("mm^2").Value) - contract_area2 = str(obj.ContractArea2.getValueAs("mm^2").Value) - section_geo = contract_area1 + "," + contract_area2 + "\n" + contract_area1 = obj.ContractArea1.getValueAs("mm^2").Value + contract_area2 = obj.ContractArea2.getValueAs("mm^2").Value + section_geo = "{:.13G},{:.13G}\n".format(contract_area1, contract_area2) return section_geo elif section_type == "PIPE ENTRANCE": - entrance_pipe_area = str(obj.EntrancePipeArea.getValueAs("mm^2").Value) - entrance_area = str(obj.EntranceArea.getValueAs("mm^2").Value) - section_geo = entrance_pipe_area + "," + entrance_area + "\n" + entrance_pipe_area = obj.EntrancePipeArea.getValueAs("mm^2").Value + entrance_area = obj.EntranceArea.getValueAs("mm^2").Value + section_geo = "{:.13G},{:.13G}\n".format(entrance_pipe_area, entrance_area) return section_geo elif section_type == "PIPE DIAPHRAGM": - diaphragm_pipe_area = str(obj.DiaphragmPipeArea.getValueAs("mm^2").Value) - diaphragm_area = str(obj.DiaphragmArea.getValueAs("mm^2").Value) - section_geo = diaphragm_pipe_area + "," + diaphragm_area + "\n" + diaphragm_pipe_area = obj.DiaphragmPipeArea.getValueAs("mm^2").Value + diaphragm_area = obj.DiaphragmArea.getValueAs("mm^2").Value + section_geo = "{:.13G},{:.13G}\n".format(diaphragm_pipe_area, diaphragm_area) return section_geo elif section_type == "PIPE BEND": - bend_pipe_area = str(obj.BendPipeArea.getValueAs("mm^2").Value) - bend_radius_diameter = str(obj.BendRadiusDiameter) - bend_angle = str(obj.BendAngle) - bend_loss_coefficient = str(obj.BendLossCoefficient) - section_geo = ("{},{},{},{}\n".format( + bend_pipe_area = obj.BendPipeArea.getValueAs("mm^2").Value + bend_radius_diameter = obj.BendRadiusDiameter + bend_angle = obj.BendAngle + bend_loss_coefficient = obj.BendLossCoefficient + section_geo = ("{:.13G},{:.13G},{:.13G},{:.13G}\n".format( bend_pipe_area, bend_radius_diameter, bend_angle, @@ -156,16 +159,16 @@ def liquid_section_def(obj, section_type): )) return section_geo elif section_type == "PIPE GATE VALVE": - gatevalve_pipe_area = str(obj.GateValvePipeArea.getValueAs("mm^2").Value) - gatevalve_closing_coeff = str(obj.GateValveClosingCoeff) - section_geo = gatevalve_pipe_area + "," + gatevalve_closing_coeff + "\n" + gatevalve_pipe_area = obj.GateValvePipeArea.getValueAs("mm^2").Value + gatevalve_closing_coeff = obj.GateValveClosingCoeff + section_geo = "{:.13G},{:.13G}\n".format(gatevalve_pipe_area, gatevalve_closing_coeff) return section_geo elif section_type == "PIPE WHITE-COLEBROOK": - colebrooke_area = str(obj.ColebrookeArea.getValueAs("mm^2").Value) - colebrooke_diameter = str(2 * obj.ColebrookeRadius.getValueAs("mm")) - colebrooke_grain_diameter = str(obj.ColebrookeGrainDiameter.getValueAs("mm")) - colebrooke_form_factor = str(obj.ColebrookeFormFactor) - section_geo = ("{},{},{},{},{}\n".format( + colebrooke_area = obj.ColebrookeArea.getValueAs("mm^2").Value + colebrooke_diameter = 2 * obj.ColebrookeRadius.getValueAs("mm") + colebrooke_grain_diameter = obj.ColebrookeGrainDiameter.getValueAs("mm") + colebrooke_form_factor = obj.ColebrookeFormFactor + section_geo = ("{:.13G},{:.13G},{},{:.13G},{:.13G}\n".format( colebrooke_area, colebrooke_diameter, "-1", @@ -176,10 +179,10 @@ def liquid_section_def(obj, section_type): elif section_type == "LIQUID PUMP": section_geo = "" for i in range(len(obj.PumpFlowRate)): - flow_rate = str(obj.PumpFlowRate[i]) - top = str(obj.PumpHeadLoss[i]) - section_geo = section_geo + flow_rate + "," + top + "," - section_geo = section_geo + "\n" + flow_rate = obj.PumpFlowRate[i] + top = obj.PumpHeadLoss[i] + section_geo = "{:.13G},{:.13G},\n".format(section_geo + flow_rate, top) + section_geo = "{}\n".format(section_geo) return section_geo else: return "" diff --git a/src/Mod/Fem/femtest/data/calculix/material_multiple_bendingbeam_fivefaces.inp b/src/Mod/Fem/femtest/data/calculix/material_multiple_bendingbeam_fivefaces.inp index 4531ad8190..6c4af8aba7 100644 --- a/src/Mod/Fem/femtest/data/calculix/material_multiple_bendingbeam_fivefaces.inp +++ b/src/Mod/Fem/femtest/data/calculix/material_multiple_bendingbeam_fivefaces.inp @@ -2540,11 +2540,11 @@ Efaces *********************************************************** ** Sections *SHELL SECTION, ELSET=FemMaterial1ShellThickness, MATERIAL=FemMaterial1 -10.0 +10 *SHELL SECTION, ELSET=FemMaterial2ShellThickness, MATERIAL=FemMaterial2 -10.0 +10 *SHELL SECTION, ELSET=FemMaterial3ShellThickness, MATERIAL=FemMaterial3 -10.0 +10 *********************************************************** ** At least one step is needed to run an CalculiX analysis of FreeCAD diff --git a/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_edgeforces.inp b/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_edgeforces.inp index d681a77175..f83795031d 100644 --- a/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_edgeforces.inp +++ b/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_edgeforces.inp @@ -2556,7 +2556,7 @@ Efaces *********************************************************** ** Sections *SHELL SECTION, ELSET=FemMaterialShellThickness, MATERIAL=FemMaterial -15.0 +15 *********************************************************** ** At least one step is needed to run an CalculiX analysis of FreeCAD diff --git a/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_nodeforces.inp b/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_nodeforces.inp index 9b6f00e217..8d47883ac8 100644 --- a/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_nodeforces.inp +++ b/src/Mod/Fem/femtest/data/calculix/square_pipe_end_twisted_nodeforces.inp @@ -2556,7 +2556,7 @@ Efaces *********************************************************** ** Sections *SHELL SECTION, ELSET=FemMaterialShellThickness, MATERIAL=FemMaterial -15.0 +15 *********************************************************** ** At least one step is needed to run an CalculiX analysis of FreeCAD diff --git a/src/Mod/Fem/femtest/data/calculix/thermomech_flow1D.inp b/src/Mod/Fem/femtest/data/calculix/thermomech_flow1D.inp index ac1eed5f4c..38a0011566 100644 --- a/src/Mod/Fem/femtest/data/calculix/thermomech_flow1D.inp +++ b/src/Mod/Fem/femtest/data/calculix/thermomech_flow1D.inp @@ -100,23 +100,23 @@ Eedges ** Sections *FLUID SECTION, ELSET=M0F0, TYPE=PIPE INOUT, MATERIAL=FluidMaterial *FLUID SECTION, ELSET=M0F1, TYPE=PIPE ENTRANCE, MATERIAL=FluidMaterial -31416.0,25133.0 +31416,25133 *FLUID SECTION, ELSET=M0F2, TYPE=PIPE MANNING, MATERIAL=FluidMaterial -31416.0,50.0,0.002 +31416,50,0.002 *FLUID SECTION, ELSET=M0F3, TYPE=PIPE BEND, MATERIAL=FluidMaterial -31416.0,1.5,45.0,0.4 +31416,1.5,45,0.4 *FLUID SECTION, ELSET=M0F4, TYPE=PIPE ENLARGEMENT, MATERIAL=FluidMaterial -31416.0,70686.0 +31416,70686 *FLUID SECTION, ELSET=M0F5, TYPE=PIPE MANNING, MATERIAL=FluidMaterial -70686.0,75.0,0.002 +70686,75,0.002 *FLUID SECTION, ELSET=M0F6, TYPE=PIPE CONTRACTION, MATERIAL=FluidMaterial -70686.0,17671.0 +70686,17671 *FLUID SECTION, ELSET=M0F7, TYPE=PIPE MANNING, MATERIAL=FluidMaterial -17671.0,37.5,0.002 +17671,37.5,0.002 *FLUID SECTION, ELSET=M0F8, TYPE=PIPE GATE VALVE, MATERIAL=FluidMaterial -17671.0,0.5 +17671,0.5 *FLUID SECTION, ELSET=M0F9, TYPE=PIPE ENLARGEMENT, MATERIAL=FluidMaterial -17671.0,1e+12 +17671,1000000000000 *FLUID SECTION, ELSET=M0F10, TYPE=PIPE INOUT, MATERIAL=FluidMaterial ***********************************************************