MacPorts users: CalculiX port test request

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: MacPorts users: CalculiX port test request

Post by ian.rees »

Hi Lorenzo,

Sorry, I'm not clear on what state your computer is in, so this might not quite answer what you're asking.
Lorenzo Ramirez wrote:I tried your recipe and I was not able to compile ccx ( I beleive the issue is related to where MacPorts is installed in my Machine). So I am very happy to report you that I was able to compile ccx ; through the instructions provided for ccx and cgx.
Just to confirm - you could not build ccx using the MacPorts Portfile that was on my github account (it's updated now), but did get it to work with the one from the MacPorts ticket 50810? I want to check because you used the word "recipe", which is Homebrew terminology and ccx can also be installed with Homebrew.

Further, if the your different MacPorts path actually did break the install, then that is a bug I'd like to understand and fix*. The Portfile that was on my github account turned in to the one in that MacPorts ticket.
Lorenzo Ramirez wrote:Do you have a suggestion how I can get NETGEN loaded?
NETGEN (more precisely nglib) needs to be compiled in to FreeCAD, it's not something you can load later (unlike GMSH if I understand correctly). If you build FreeCAD yourself, then you'll need to install nglib (see separate MacPorts ticket https://trac.macports.org/ticket/50687 ), then turn on the FreeCAD cmake option BUILD_FEM_NETGEN. Alternatively, the 0.16 Mac release binaries are built with nglib.

Hope this helps! -Ian-

*All that said, I've just about decided to switch over to Homebrew and stop putting effort in to MacPorts. I find the MacPorts infrastructure to be a lot harder to work with than Homebrew, and then after putting effort in to make MacPorts Portfiles/patches, they seem to take forever to get merged in.
Lorenzo Ramirez
Posts: 18
Joined: Tue Mar 22, 2016 4:15 am

Re: MacPorts users: CalculiX port test request

Post by Lorenzo Ramirez »

Ian
As mentioend in my last post, I had been trying to mesh within FreeCAD though the GMSHMacro.FCMacro that you recommended . The error ath ti got is the following:

<unknown exception traceback><type 'exceptions.SyntaxError'>: ('invalid syntax', ('/Users/JCarrington 1/Library/Preferences/FreeCAD/Macros_FreeCAD/Macros/GMSHMesh.FCMacro', 22, 18, 'gmsh_bin_other = \xe2\x80\x9c/Applications/Gmsh.app/Contents/MacOS/gmsh\xe2\x80\x9d\n'))

I do not know what is the source of the backslashes and appended fields (highlighted in red color above in the error message) at the beginning path ( \xe2\x80\x9c /Applications/…) and appended at the end of the path …/gmsh\ xe2\x80\x9d\n'. The appended field and baclashes are not part of the path to gmsh.


Had you seen this error before?
Do you have any suggestions on how can overcome the error and be able to mesh using gmsh?
Any help will be appreciated.
I searched and found this link which reports the same issue but I am not sure if thsi will fix the issue or will casue soem trroubleto my computer. http://stackoverflow.com/questions/1728 ... after-upda

Thanks for the help.

My computer is a MAC OS X, Version 10.9.5.
I am running FreeCAD version 16.
I am using TextEdit as editor.

The path to where gmsh is in my computer is the one already mentioned in some post in this thread: /Applications/Gmsh.app/Contents/MacOS/gmsh

The Macro file that I edited to include the path where gmsh ( gmsh_bin_other = "/Applications/Gmsh.app/Contents/MacOS/gmsh") is the following:

Code: Select all

# -*- coding: utf-8 -*-
# Mesh with GMSH inside of FreeCAD
# Author: Gomez Lucio
# Modified by: PrzemoF
# Modified by: Bernd Hahnebach (bernd@bimstatik.org)
# License: LGPL v 2.1
# Version: 04/07/2015

# CONFIGURATION - EDIT THE FOLLOWING LINE TO MATCH YOUR GMSH BINARY


gmsh_bin_linux = "/usr/bin/gmsh"


gmsh_bin_windwos = "C:\\Daten\\gmsh-2.10.0-Windows\\gmsh.exe"


#gmsh_bin_other = "/usr/bin/gmsh"

#Lorenzo changes

gmsh_bin_other = “/Applications/Gmsh.app/Contents/MacOS/gmsh”


# END CONFIGURATION

# START OF MACRO
from PySide import QtGui, QtCore
import Fem
import FemGui
import FemAnalysis
import FreeCAD
import FreeCADGui
import ImportGui
import Mesh
import subprocess
import sys
import tempfile
from platform import system
if system() == "Linux":
    gmsh_bin = gmsh_bin_linux
    path_sep = "/"
elif system() == "Windows":
    gmsh_bin = gmsh_bin_windwos
    path_sep = "\\"


else:

    gmsh_bin = gmsh_bin_other
    path_sep = "/"

class MeshGmsh(QtGui.QWidget):
    def __init__(self):
        super(MeshGmsh, self).__init__()
        self.initUI()

    def __del__(self):
        return

    def initUI(self):
        # Mesh dimension
        self.rb_1D = QtGui.QRadioButton("   1D", self)
        self.rb_2D = QtGui.QRadioButton("   2D", self)
        self.rb_3D = QtGui.QRadioButton("   3D", self)
        self.rb_3D.setChecked(QtCore.Qt.Checked)
        # Optimized:
        self.cb_optimized = QtGui.QCheckBox("    Optimized", self)
        self.cb_optimized.setChecked(QtCore.Qt.Checked)
        # Create Mechanical Analysis from mesh
        self.cb_mec_anal = QtGui.QCheckBox("    Create Mechanical Analysis from mesh",self)
        #self.cb_mec_anal.setChecked(QtCore.Qt.Checked)
        # Algorithm:
        self.l_algorithm = QtGui.QLabel("Algorithm ", self)
        self.cmb_algorithm = QtGui.QComboBox(self)
        self.algorithm_list = [self.tr('iso'), self.tr('netgen'), self.tr('tetgen'), self.tr('meshadapt'), ]
        self.cmb_algorithm.addItems(self.algorithm_list)
        self.cmb_algorithm.setCurrentIndex(1)
        # Format:
        self.l_format = QtGui.QLabel("Format ", self)
        self.cmb_format = QtGui.QComboBox(self)
        self.format_list = [self.tr('unv'), self.tr('stl'), self.tr('med')]
        self.cmb_format.addItems(self.format_list)
        self.cmb_format.setCurrentIndex(0)
        self.stored_cmb_format_index = 0
        # Element max size:
        self.cb_max_elme_size = QtGui.QCheckBox("  Set maximum mesh element size",self)
        self.cb_max_elme_size.setChecked(QtCore.Qt.Checked)
        self.sb_max_element_size = QtGui.QDoubleSpinBox(self)
        self.sb_max_element_size.setValue(5.0)
        self.sb_max_element_size.setMaximum(10000000.0)
        self.sb_max_element_size.setMinimum(0.00000001)
        # Element min size:
        self.cb_min_elme_size = QtGui.QCheckBox("  Set minimum mesh element size",self)
        self.sb_min_element_size = QtGui.QDoubleSpinBox(self)
        self.sb_min_element_size.setValue(1.0)
        self.sb_min_element_size.setMaximum(10000000.0)
        self.sb_min_element_size.setMinimum(0.00000001)
        self.sb_min_element_size.setEnabled(False)
        # Set Mesh Order:
        self.cb_mesh_order = QtGui.QCheckBox("  mesh order",self)
        self.cb_mesh_order.setChecked(QtCore.Qt.Checked)
        self.sb_mesh_order = QtGui.QSpinBox(self)
        self.sb_mesh_order.setValue(2)
        self.sb_mesh_order.setMaximum(5)
        self.sb_mesh_order.setMinimum(1)
        # Other gmsh commands:
        self.l_cmd_line_opt = QtGui.QLabel("Custom gmsh options ", self)
        self.le_cmd_line_opt = QtGui.QLineEdit(self)
        self.le_cmd_line_opt.setToolTip("Those option will be appended to gmsh command line call")
        # Ok buttons:
        self.okbox = QtGui.QDialogButtonBox(self)
        self.okbox.setOrientation(QtCore.Qt.Horizontal)
        self.okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
        # Web button
        self.pb_web = QtGui.QPushButton(self)
        self.pb_web.setText("gmsh options (web)")
        # Layout:
        layout = QtGui.QGridLayout()
        layout.addWidget(self.rb_1D, 1, 0)
        layout.addWidget(self.rb_2D, 1, 1)
        layout.addWidget(self.rb_3D, 2, 0)
        layout.addWidget(self.cb_optimized, 2, 1)
        layout.addWidget(self.l_algorithm, 3, 0)
        layout.addWidget(self.cmb_algorithm, 3, 1)
        layout.addWidget(self.l_format, 4, 0)
        layout.addWidget(self.cmb_format, 4, 1)
        layout.addWidget(self.cb_max_elme_size, 5, 0)
        layout.addWidget(self.sb_max_element_size, 5, 1)
        layout.addWidget(self.cb_min_elme_size, 6, 0)
        layout.addWidget(self.sb_min_element_size, 6, 1)
        layout.addWidget(self.cb_mesh_order, 7, 0)
        layout.addWidget(self.sb_mesh_order, 7, 1)
        layout.addWidget(self.cb_mec_anal, 8, 0)
        layout.addWidget(self.l_cmd_line_opt, 9, 0)
        layout.addWidget(self.le_cmd_line_opt, 9, 1)
        layout.addWidget(self.pb_web, 10, 0)
        layout.addWidget(self.okbox, 10, 1)
        self.setLayout(layout)
        # Connectors:
        QtCore.QObject.connect(self.okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(self.okbox, QtCore.SIGNAL("rejected()"), self.cancel)
        self.pb_web.clicked.connect(self.open_gmsh_options)
        self.cb_max_elme_size.stateChanged.connect(self.max_size_state)
        self.cb_min_elme_size.stateChanged.connect(self.min_size_state)
        self.cb_mesh_order.stateChanged.connect(self.mesh_order_state)
        
    def max_size_state(self, state):   
        if state == QtCore.Qt.Checked:
            self.sb_max_element_size.setEnabled(True)
        else:
            self.sb_max_element_size.setEnabled(False)

    def min_size_state(self, state):   
        if state == QtCore.Qt.Checked:
            self.sb_min_element_size.setEnabled(True)
        else:
            self.sb_min_element_size.setEnabled(False)
            
    def mesh_order_state(self, state):   
        if state == QtCore.Qt.Checked:
            self.sb_mesh_order.setEnabled(True)
        else:
            self.sb_mesh_order.setEnabled(False)

    def open_gmsh_options(self):
        import webbrowser
        webbrowser.open('http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#Command_002dline-options')

    def cancel(self):
        self.close()
        d.close()

    def proceed(self):
        temp_file = tempfile.mkstemp(suffix='.step')[1]
        selection = FreeCADGui.Selection.getSelection()
        if not selection:
            QtGui.QMessageBox.critical(None, "GMSHMesh macro", "An object has to be selected to run gmsh!")
            return
        # Export a part in step format
        ImportGui.export(selection, temp_file)
        selection_name = selection[0].Name
        # Mesh temporaly file
        file_format = self.cmb_format.currentText()
        temp_mesh_file = tempfile.tempdir + path_sep + selection_name + '_Mesh.' + file_format
        # OPTIONS GMSH:
        clmax = self.sb_max_element_size.text()
        clmin = self.sb_min_element_size.text()
        cmd_line_opt = self.le_cmd_line_opt.text()
        algo = self.cmb_algorithm.currentText()
        mesh_order = self.sb_mesh_order.text()

        if self.cb_optimized.isChecked():
            cmd_optimize = ' -optimize'
        else:
            cmd_optimize = ''

        if self.rb_3D.isChecked():
            dim = ' -3 '
        if self.rb_2D.isChecked():
            dim = ' -2 '
        if self.rb_1D.isChecked():
            dim = ' -1 '
        if self.cb_max_elme_size.isChecked():
            max_size = ' -clmax ' + clmax
        else:
            max_size = ''
        if self.cb_min_elme_size.isChecked():
            min_size = ' -clmin ' + clmin
        else:
            min_size = ''
        if self.cb_mesh_order.isChecked():
            order = ' -order ' + mesh_order
        else:
            order = ''

        options = ' -algo ' + algo + max_size + min_size + cmd_optimize + order + cmd_line_opt
        # RUN GMSH
        command = gmsh_bin + ' ' + temp_file + dim + '-format ' + file_format + ' -o ' + temp_mesh_file  + '' + options
        
        FreeCAD.Console.PrintMessage("Running: {}".format(command))
        try:
            if system() == "Linux":
                output = subprocess.check_output([command, '-1'], shell=True, stderr=subprocess.STDOUT,)
            elif system() == "Windows":
                output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT,)
            else:
                output = subprocess.check_output([command, '-1'], shell=True, stderr=subprocess.STDOUT,)
            FreeCAD.Console.PrintMessage(output)
            if file_format in ('unv', 'med'):
                Fem.insert(temp_mesh_file, FreeCAD.ActiveDocument.Name)
            if file_format == 'stl':
                Mesh.insert(temp_mesh_file, FreeCAD.ActiveDocument.Name)
            if self.cb_mec_anal.isChecked():
              FMesh = App.activeDocument().ActiveObject
              FemAnalysis.makeFemAnalysis('MechanicalAnalysis')
              FemGui.setActiveAnalysis(App.activeDocument().ActiveObject)
              App.activeDocument().ActiveObject.Member = App.activeDocument().ActiveObject.Member + [FMesh]
            if self.rb_1D.isChecked():
              FMeshG = Gui.ActiveDocument.ActiveObject
              FMeshG.DisplayMode = "Elements & Nodes"
        except:
            FreeCAD.Console.PrintError("Unexpected error in GMSHMesh macro: {}".format(sys.exc_info()[0]))
        finally:
            try:
                del temp_file
            except:
                pass
            try:
                del temp_mesh_file
            except:
                pass


mw = FreeCADGui.getMainWindow()
d = QtGui.QDockWidget()
d.setWidget(MeshGmsh())
d.toggleViewAction().setText("Gmsh")
d.setAttribute(QtCore.Qt.WA_DeleteOnClose)
d.setWindowTitle(" GMSH Mesh Generator ")
mw.addDockWidget(QtCore. Qt.RightDockWidgetArea, d)

# END OF MACRO
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: MacPorts users: CalculiX port test request

Post by ian.rees »

The red highlighted parts are UTF-8 unicode characters for left and right double quote. In the code snippet you posted, you can see them as the different-looking quotes after gmsh_bin_other. Python supports unicode in source code, but I believe only the ASCII type single and double quotes are acceptable for marking string literals. -Ian-
Lorenzo Ramirez
Posts: 18
Joined: Tue Mar 22, 2016 4:15 am

Re: MacPorts users: CalculiX port test request

Post by Lorenzo Ramirez »

Ian
I am reporting that I had been able to sucesfully prepare the geometry, mesh the model, stup constrains, assign forces and material, run and inspect the results of my first ever FEM analysis in FreeCAD!!!
Thank you very much from all your help and pointing that the quotes that I had in the Macro were incorrect ( I need to study and learn about the difference between them).

Have a great day!

Lorenzo Ramirez
Brucesc2
Posts: 11
Joined: Tue May 17, 2016 8:38 pm

Re: MacPorts users: CalculiX port test request

Post by Brucesc2 »

Hi Ian,

I reported the issue on github but thought this might be the appropriate forum for trying to troubleshoot the can not execute the portfile issue, and thanks for you answer (link in the bottom)

I have followed the steps to make a local portfile repository and updated all sources.conf, run the script. Do I need to change the portfile or something?
When running the portindex command I get the following output:

Creating port index in /Users/markusenberg/Downloads/macports

Total number of ports parsed: 0
Ports successfully parsed: 0
Ports failed: 0
Up-to-date ports skipped: 4


when running search, the following appears:

test:calculix markusenberg$ port search calculix
calculix @2.10 (math)
A three-dimensional finite element solver

calculix-ccx @2.10 (math)
A three-dimensional finite element solver

calculix-cgx @2.10 (math)
A three-dimensional finite element solver

calculix-html @2.10 (math)
A three-dimensional finite element solver


Indicating that the calculix is available: The problem seems to be the portfile as the erro msg say:
Error: Unable to execute port: Could not open file: /Users/markusenberg/Downloads/macports/math/calculix/Portfile
But i can open and edit the portfile in textmate


Link to the original question:
https://github.com/ianrrees/macports/issues/1
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: MacPorts users: CalculiX port test request

Post by ian.rees »

Permissions issue maybe? When I was working on this, I probably would've cd'ed to the top level of my local port development tree (so your /Users/markusenberg/Downloads/macports ). I vaguely recall seeing some behaviour where the portindex tool gave results that seemed confusing - not sure how tightly coupled it is with the script that handles installing packages. Beyond that, your best bet is probably to ask on one of the MacPorts mailing lists.

FWIW - My plan is to switch over to just using Homebrew sometime soon; have found that it does what I want, with less effort, and seems to have a much more active community. As an example, the port that this thread was started for has been waiting for a review/merge for several weeks with no movement despite a couple pokes on the MacPorts development list. Contrast that with changes to the Homebrew recipe for netgen, which took a couple days start-to-finish.
Brucesc2
Posts: 11
Joined: Tue May 17, 2016 8:38 pm

Re: MacPorts users: CalculiX port test request

Post by Brucesc2 »

Hi, sorry for late reply, I solved it by using brew, there is a formula calculix-ccx in the homebrew/science tap you can install with brew. This post is just to guide people that are searching for this topic.
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: MacPorts users: CalculiX port test request

Post by ian.rees »

No worries, glad to hear you got it going! I have switched to using homebrew as well. Those requests are still sitting untouched in the MacPorts tracker :/. -Ian-
Post Reply