|
| 1 | +# *************************************************************************** |
| 2 | +# * Copyright (c) 2020 Sudhanshu Dubey <sudhanshu.thethunder@gmail.com> * |
| 3 | +# * * |
| 4 | +# * This file is part of the FreeCAD CAx development system. * |
| 5 | +# * * |
| 6 | +# * This program is free software; you can redistribute it and/or modify * |
| 7 | +# * it under the terms of the GNU Lesser General Public License (LGPL) * |
| 8 | +# * as published by the Free Software Foundation; either version 2 of * |
| 9 | +# * the License, or (at your option) any later version. * |
| 10 | +# * for detail see the LICENCE text file. * |
| 11 | +# * * |
| 12 | +# * This program is distributed in the hope that it will be useful, * |
| 13 | +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 | +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 | +# * GNU Library General Public License for more details. * |
| 16 | +# * * |
| 17 | +# * You should have received a copy of the GNU Library General Public * |
| 18 | +# * License along with this program; if not, write to the Free Software * |
| 19 | +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * |
| 20 | +# * USA * |
| 21 | +# * * |
| 22 | +# *************************************************************************** |
| 23 | + |
| 24 | +# to run the example use: |
| 25 | +""" |
| 26 | +from femexamples.equation_electrostatics_cube_capacitor import setup |
| 27 | +setup() |
| 28 | +""" |
| 29 | +# Electrostatics Cube Capacitor |
| 30 | +# https://forum.freecadweb.org/viewtopic.php?f=18&t=41488&start=60#p401652 |
| 31 | + |
| 32 | +import FreeCAD |
| 33 | + |
| 34 | +import Fem |
| 35 | +import ObjectsFem |
| 36 | + |
| 37 | +mesh_name = "Mesh" # needs to be Mesh to work with unit tests |
| 38 | + |
| 39 | + |
| 40 | +def init_doc(doc=None): |
| 41 | + if doc is None: |
| 42 | + doc = FreeCAD.newDocument() |
| 43 | + return doc |
| 44 | + |
| 45 | + |
| 46 | +def get_information(): |
| 47 | + info = {"name": "Electrostatics Cube Capacitor", |
| 48 | + "meshtype": "solid", |
| 49 | + "meshelement": "Tet10", |
| 50 | + "constraints": ["electrostatic potential"], |
| 51 | + "solvers": ["elmer"], |
| 52 | + "material": "fluid", |
| 53 | + "equation": "electrostatic" |
| 54 | + } |
| 55 | + return info |
| 56 | + |
| 57 | + |
| 58 | +def setup(doc=None, solvertype="elmer"): |
| 59 | + # setup base model |
| 60 | + |
| 61 | + if doc is None: |
| 62 | + doc = init_doc() |
| 63 | + |
| 64 | + # geometry object |
| 65 | + # name is important because the other method in this module use obj name |
| 66 | + geom_obj = doc.addObject("Part::Box", "Box") |
| 67 | + geom_obj.Height = geom_obj.Width = geom_obj.Length = 1000 |
| 68 | + doc.recompute() |
| 69 | + |
| 70 | + if FreeCAD.GuiUp: |
| 71 | + geom_obj.ViewObject.Document.activeView().viewAxonometric() |
| 72 | + geom_obj.ViewObject.Document.activeView().fitAll() |
| 73 | + |
| 74 | + # analysis |
| 75 | + analysis = ObjectsFem.makeAnalysis(doc, "Analysis") |
| 76 | + |
| 77 | + # solver |
| 78 | + if solvertype == "elmer": |
| 79 | + solver_object = analysis.addObject(ObjectsFem.makeSolverElmer(doc, "SolverElmer"))[0] |
| 80 | + eq_electrostatic = ObjectsFem.makeEquationElectrostatic(doc, solver_object) |
| 81 | + eq_electrostatic.CalculateCapacitanceMatrix = True |
| 82 | + else: |
| 83 | + FreeCAD.Console.PrintWarning( |
| 84 | + "Not known or not supported solver type: {}. " |
| 85 | + "No solver object was created.\n".format(solvertype) |
| 86 | + ) |
| 87 | + |
| 88 | + # material |
| 89 | + material_object = analysis.addObject( |
| 90 | + ObjectsFem.makeMaterialFluid(doc, "FemMaterial") |
| 91 | + )[0] |
| 92 | + mat = material_object.Material |
| 93 | + mat["Name"] = "Air-Generic" |
| 94 | + mat["Density"] = "1.20 kg/m^3" |
| 95 | + mat["KinematicViscosity"] = "15.11 mm^2/s" |
| 96 | + mat["VolumetricThermalExpansionCoefficient"] = "0.00 µm/m/K" |
| 97 | + mat["ThermalConductivity"] = "0.03 W/m/K" |
| 98 | + mat["ThermalExpansionCoefficient"] = "0.0034/K" |
| 99 | + mat["SpecificHeat"] = "1.00 J/kg/K" |
| 100 | + mat["RelativePermittivity"] = "1.00" |
| 101 | + material_object.Material = mat |
| 102 | + |
| 103 | + # 1st potential_constraint |
| 104 | + constraint_elect_pot0 = analysis.addObject( |
| 105 | + ObjectsFem.makeConstraintElectrostaticPotential(doc))[0] |
| 106 | + constraint_elect_pot0.References = [(geom_obj, "Face6")] |
| 107 | + constraint_elect_pot0.PotentialEnabled = True |
| 108 | + constraint_elect_pot0.Potential = 2.00 |
| 109 | + constraint_elect_pot0.CapacitanceBodyEnabled = True |
| 110 | + constraint_elect_pot0.CapacitanceBody = 1 |
| 111 | + |
| 112 | + # 2nd potential_constraint |
| 113 | + constraint_elect_pot1 = analysis.addObject( |
| 114 | + ObjectsFem.makeConstraintElectrostaticPotential(doc))[0] |
| 115 | + constraint_elect_pot1.References = [(geom_obj, "Face5")] |
| 116 | + constraint_elect_pot1.PotentialEnabled = True |
| 117 | + constraint_elect_pot1.Potential = -1.00 |
| 118 | + constraint_elect_pot1.CapacitanceBodyEnabled = True |
| 119 | + constraint_elect_pot1.CapacitanceBody = 2 |
| 120 | + |
| 121 | + # mesh |
| 122 | + from .meshes.mesh_cube_capacitor_tetra10 import create_nodes, create_elements |
| 123 | + fem_mesh = Fem.FemMesh() |
| 124 | + control = create_nodes(fem_mesh) |
| 125 | + if not control: |
| 126 | + FreeCAD.Console.PrintError("Error on creating nodes.\n") |
| 127 | + control = create_elements(fem_mesh) |
| 128 | + if not control: |
| 129 | + FreeCAD.Console.PrintError("Error on creating elements.\n") |
| 130 | + femmesh_obj = analysis.addObject( |
| 131 | + ObjectsFem.makeMeshGmsh(doc, mesh_name) |
| 132 | + )[0] |
| 133 | + femmesh_obj.FemMesh = fem_mesh |
| 134 | + femmesh_obj.Part = geom_obj |
| 135 | + femmesh_obj.SecondOrderLinear = False |
| 136 | + |
| 137 | + doc.recompute() |
| 138 | + return doc |
0 commit comments