Run Calculix without GUI and read results

Need help, or want to share a macro? Post here!
User avatar
bernd
Posts: 8488
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Run Calculix without GUI and read results

Postby bernd » Mon Sep 24, 2018 6:53 pm

You could try to set your own inp file for the fea and than run the fea. I have never tried to be honest.
EkaitzEsteban
Posts: 101
Joined: Wed Sep 12, 2018 1:31 pm

Re: Run Calculix without GUI and read results

Postby EkaitzEsteban » Mon Sep 24, 2018 8:00 pm

bernd wrote:
Mon Sep 24, 2018 6:40 pm
no because with fea.run() you can not run a spcific inp file
Thanks for clarifying this.

Best regards,
Ekaitz.
EkaitzEsteban
Posts: 101
Joined: Wed Sep 12, 2018 1:31 pm

Re: Run Calculix without GUI and read results

Postby EkaitzEsteban » Mon Sep 24, 2018 8:03 pm

bernd wrote:
Mon Sep 24, 2018 6:53 pm
You could try to set your own inp file for the fea and than run the fea. I have never tried to be honest.
Thank you bernd. I will try this and I will tell you if it works.
EkaitzEsteban
Posts: 101
Joined: Wed Sep 12, 2018 1:31 pm

Re: Run Calculix without GUI and read results

Postby EkaitzEsteban » Mon Sep 24, 2018 8:13 pm

bernd wrote:
Mon Sep 24, 2018 6:43 pm
Check this module https://github.com/FreeCAD/FreeCAD/blob ... cxtools.py
Ok I will check the module cxxtools.py. It is this module a parent from fea? I think that this one is fea

https://github.com/FreeCAD/FreeCAD/blob ... olsCcx.py

fea.run() is line 170 to 190 am I right?

best regards,

Ekaitz.
User avatar
bernd
Posts: 8488
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Run Calculix without GUI and read results

Postby bernd » Tue Sep 25, 2018 7:18 am

EkaitzEsteban wrote:
Mon Sep 24, 2018 8:13 pm
Ok I will check the module cxxtools.py. It is this module a parent from fea? I think that this one is fea
https://github.com/FreeCAD/FreeCAD/blob ... olsCcx.py
Be careful with links. your one links to the tree from a commit from 3rd of June 2016

My link links to up to date master commit ... https://github.com/FreeCAD/FreeCAD/blob ... cxtools.py You could use this instead too ... https://github.com/FreeCAD/FreeCAD/blob ... cxtools.py this link points to latest master in any case ...
User avatar
bernd
Posts: 8488
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Run Calculix without GUI and read results

Postby bernd » Tue Sep 25, 2018 7:19 am

the ccxtools module defines the fea class. I my give your problem a try and report back.

bernd
EkaitzEsteban
Posts: 101
Joined: Wed Sep 12, 2018 1:31 pm

[SOLVED] Run Calculix without GUI and read results

Postby EkaitzEsteban » Tue Sep 25, 2018 7:43 am

bernd wrote:
Tue Sep 25, 2018 7:19 am
the ccxtools module defines the fea class. I my give your problem a try and report back.

bernd
Hi bernd,

I solved it, thank you a lot for your help!

I modify the ccxtools.py file by adding the following code:

Code: Select all

#------------------------------------------------------------------------------
#  ----------------------------------- My mod (take care)-------------------------------------------
#------------------------------------------------------------------------------

# define a new function which takes your previously defined .inp file       
    def myinp_file(self):
        import femsolver.calculix.writer as iw
        import sys
        self.inp_file_name = ""
        try:
            inp_writer = iw.FemInputWriterCcx(
                self.analysis, self.solver,
                self.mesh, self.materials_linear, self.materials_nonlinear,
                self.fixed_constraints, self.displacement_constraints,
                self.contact_constraints, self.planerotation_constraints, self.transform_constraints,
                self.selfweight_constraints, self.force_constraints, self.pressure_constraints,
                self.temperature_constraints, self.heatflux_constraints, self.initialtemperature_constraints,
                self.beam_sections, self.beam_rotations, self.shell_thicknesses, self.fluid_sections,
                self.working_dir)
            self.inp_file_name = "C:\Users\mypath\myinpfile.inp"
        except:
            FreeCAD.Console.PrintError("Unexpected error when writing CalculiX input file: {}\n".format(sys.exc_info()[0]))
            raise

# Define a new run taking into account the def myinp_file(self) function.
    def myrun(self):
        ret_code = 0
        message = self.check_prerequisites()
        if not message:
            self.myinp_file()
            from FreeCAD import Base
            progress_bar = Base.ProgressIndicator()
            progress_bar.start("Running CalculiX ccx...", 0)
            ret_code = self.start_ccx()
            self.finished.emit(ret_code)
            progress_bar.stop()
            if ret_code or self.ccx_stderr:
                FreeCAD.Console.PrintError("CalculiX failed with exit code {}\n".format(ret_code))
                FreeCAD.Console.PrintMessage("--------start of stderr-------\n")
                FreeCAD.Console.PrintMessage(self.ccx_stderr)
                FreeCAD.Console.PrintMessage("--------end of stderr---------\n")
                FreeCAD.Console.PrintMessage("--------start of stdout-------\n")
                FreeCAD.Console.PrintMessage(self.ccx_stdout)
                self.has_for_nonpositive_jacobians()
                FreeCAD.Console.PrintMessage("--------end of stdout---------\n")
            else:
                FreeCAD.Console.PrintMessage("CalculiX finished without error\n")
        else:
            FreeCAD.Console.PrintError("CalculiX was not started due to missing prerequisites:\n{}\n".format(message))
            # ATM it is not possible to start CalculiX if prerequisites are not fulfilled
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------ 
Then, by typing in python API console

Code: Select all

FemGui.setActiveAnalysis(FreeCAD.getDocument("SimpleBox").Analysis)
fea = ccxtools.FemToolsCcx()
fea.update_objects()
message = fea.check_prerequisites()
if not message:
    fea.reset_all()
    fea.myrun() # this calls ccxtools.py def myrun(self) function where my custom inp file is defined.
    fea.load_results()
else:
    FreeCAD.Console.PrintError("Houston, we have a problem! {}\n".format(message))  # in report view
Results are then obtained in the same manner and works correctly.

best regards,

Ekaitz

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13528 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Spanish/Spain (es_ES)