With pre rendering (FreeCAD STL) - adamfrees/comsol-builder GitHub Wiki

This method involves more moving pieces but more accurately captures the geometry of overlapping electrodes. It relies on FreeCAD to reformat the 2D .dxf file into a 2D .FCStd file, and the QMT Repository to render the 2D .FCStd file into a 3D .stl file. The comsol-builder application then imports this .stl file into COMSOL.

An example of this last process (.stl->.mph) can be found in examples/from_stl/test_device.java. To build this example on Linux/MacOS, after set-up run:

./generate_mph examples/from_stl/test_device.java

from the comsol-builder directory.

Set-up

The steps required to set up comsol-builder without pre-rendering are required for comsol-builder with pre-rendering as well. Here, we describe the steps required to set up the pre-rendering steps.

First, install Microsoft's QMT Repository. The easiest method to do this is to use Anaconda/Miniconda; instructions on how to install using this method can be found here.

Installing QMT also installs the application FreeCAD. After installing, copy the FreeCAD Macro in this repository utilities/dxf2Sketch.FCMacro into the FreeCAD Macro folder. To find the active folder, in FreeCAD go to the menu option Macro->Macros.... The default folder on MacOS is ~/Library/Preferences/FreeCAD/Macro.

Building COMSOL file

Creating a .mph file from a .dxf file using this method consists of three steps: .dxf->.FCStd, .FCStd->.stl, and .stl->.mph.

.dxf -> .FCStd

Both of these file types describe 2D electrode geometries. While .dxf files are a commonly-used 2D CAD format, QMT requires FreeCAD files (.FCStd) as input.

To perform this transformation, modify the values of dxfFilename and saveFilename in the dxf2Sketch.FCMacro file located in the FreeCAD Macro folder. These values should reflect the desired input and output filenames.

Next, in FreeCAD go to the menu option Macro->Macros..., select dxf2Sketch.FCMacro and click "Execute".

.FCStd -> .stl

While a .FCStd file describes a 2D geometry, a .stl file is a simple 3D mesh. To find the correct 3D geometry of the electrodes, we use the QMT repository. An example of how to perform this transformation can be found in the repository. If this example is no longer working, please contact Adam Frees.

.stl -> .mph

The final step of constructing a COMSOL file can be performed using the comsol-builder application. Just as in the "without pre-processing" case, a COMSOL file can be generated by running ./generate_mph /path/to/file/javaFile.java, where javaFile.java is a Java file with some information about the device's materials and heterostructure. An example Java file can be found at examples/from_stl/test_device.java in this repository.