WELSIM - Quantify the Uncertain
WELSIM is the #1 engineering simulation software for the open-source community.
Thursday, January 15, 2026
生成CalculiX求解器的接触与边界条件
CalculiX 是一款著名的开源有限元分析(FEA)软件,主打结构力学(静力、动力、非线性)与热分析,适用于科研、教学和中小型工程场景。CalculiX的核心优势有:开源免费。个人、企业、科研机构均可自由使用、修改和分发代码,遵循 GNU GPL 许可证。兼容支持 Abaqus 的 INP 输入文件格式,多数 Abaqus 模型也可直接导入 CalculiX 求解,减少学习曲线。求解器代码精简,对硬件资源要求低于商业软件,适合中小型模型的快速计算。对第三方前后端软件支持也非常好,易于前后处理器与求解器的整合。
Image
笔者曾在《使用WELSIM生成CalculiX求解器文件》一文中,介绍了如何快速地生成CalculiX输入文件。目前,WELSIM已经可以很好的作为CalculiX的前处理器生成输入文本,极大的方便用户使用CalculiX进行有限元分析。本文以更详细的方式介绍生成接触与边界条件的命令。
接触
在多体有限元结构分析中,接触是必要的设置之一。本章节描述生成两种常见的接触类型:绑定接触和可分离接触。
绑定接触
绑定接触是一种用于模拟多体之间完全刚性连接的接触条件,适用于部件间无相对滑移、无分离、无间隙的工况(如焊接、胶粘、过盈配合后固化、螺栓紧固的刚性连接)。绑定接触会强制接触界面的节点位移完全一致,等同于将多个独立部件 “融合” 为一个整体结构。
绑定接触设置如下图所示,
Image
转换成CalculiX命令时,使用*TIE 命令。生成的输入命令如下
*Tie, Name=ID_15, Position tolerance=0.01, Adjust=No
Target_Surface_15, Master_Surface_15
在网格文件中,定义的表面单元如下:
** Box_to_Box_1
*SURFACE, TYPE=ELEMENT, NAME=Master_Surface_15
70, S2
63, S2
74, S2
61, S2
66, S1
69, S2
** Box_to_Box_1
*SURFACE, TYPE=ELEMENT, NAME=Target_Surface_15
166, S3
185, S2
160, S3
173, S2
171, S4
169, S3
可分离接触
可分离接触是一种用于模拟多体接触界面允许接触、滑移、分离三种状态的非线性接触条件,核心特点是接触界面仅传递法向压力,无拉力作用,且切向可自由滑移或黏着,适用于部件间存在动态接触与分离的工况(如齿轮啮合、冲压成型、轴承滚动、机械碰撞)。根据摩擦力假设,又分为无摩擦接触和有摩擦接触。
WELSIM设置接触如下图所示,
Image
转换成CalculiX命令时,使用CONTACT命令。这里值得注意的是,CalculiX规定,主接触面又称作独立接触面,必须是以单元定义的表面。被动接触面又称作是依赖接触面,可以是单元定义的表面,也可以是节点定义的表面。
生成对应的CalculiX命令为
** Box_to_Box 1
*Surface interaction, Name=SurfaceInteraction_15
*Surface behavior, Pressure-overclosure=Hard
*Friction
0.15
*Contact Pair, Interaction=SurfaceInteraction_15, Type=Surface to surface
Target_Surface_15, Master_Surface_15
结构分析中的边界条件
设置边界条件是有限元分析中重要的步骤,也是前处理软件生成求解器命令的重要部分。WELSIM支持大量CalculiX的边界条件。本章节演示前处理器生成结构分析中的边界条件,并显示对应的求解器命令。
1. 固定边界或位移
位移边界条件是用于约束模型节点位移自由度的本质边界条件,其作用是限制结构的刚体运动、模拟实际支撑约束(如固定支座、铰支座),是结构静力、动力分析的基础条件。 3维模型中,对于实体单元,可以施加X/Y/Z方向的平移(Ux/Uy/Uz),对于壳单元,可以施加额外的绕 X/Y/Z 轴转动的转动(Rx/Ry/Rz)。
Image
对应生成的CalculiX求解器命令是,
** BC Name: Displacement
*Boundary
ID_22, 1, 1, 1
*Boundary
ID_22, 2, 2, 2
*Boundary
ID_22, 3, 3, 3
*Boundary
ID_22, 6, 6, 0.523599
2. 压力
压力边界条件是一种作用于结构表面的面载荷,属于分布载荷,其本质是通过指定单位面积上的法向力来模拟流体压力、接触压力、气体载荷等工程场景(如压力容器内壁压力、风载荷、土壤侧压力)。
压力是结构有限元分析中常见的边界条件之一。压力的符号规则决定载荷方向:正压力:载荷方向指向表面内侧,对结构产生压缩效应(如压力容器内壁压力);负压力:载荷方向背离表面外侧,对结构产生拉伸效应(如真空容器外壁的大气压力)。压力边界条件如图所示,
Image
对应生成的求解器命令是,
** BC Name: Pressure
*DLOAD
ID_20, P, 123
3. 力
力边界条件是作用于几何关键点、线、或者面的载荷,用于模拟工程中局部位置的受力工况(如螺栓预紧力、吊环拉力、销钉作用力)。 力是结构力学中最常见的边界条件,然而, 对于有限元数值方法中,几何面上的力边界条件的施加并不简单,通常是将多个节点的自由度耦合到一个参考节点,常用于将集中载荷分散到节点组(如把力加在参考节点,自动分配到耦合组)。
如图所示,在前处理器的力设置中,用户可以选定几何体的面,线,或点,并给定三个方向上的力大小。
Image
得到力的求解器命令如下,
*COUPLING, REF NODE=46, SURFACE=ID_17, CONSTRAINT NAME=c17
*KINEMATIC
1
3
** BC Name: Force
*CLOAD, OP=NEW
46, 1, 100
*CLOAD, OP=NEW
46, 2, 200
*CLOAD, OP=NEW
46, 3, 300
4. 节点力
节点力边界条件是直接作用于单个或多个节点的集中力载荷,是有限元离散化后最基础的载荷施加形式,与之前提到的集中力边界条件高度关联,但更偏向于网格离散后的直接操作,常用于精细化载荷控制或特殊工况模拟。
节点力是直接施加在网格节点上的力,根据节点数量大小,综合施加的力会叠加。
Image
生成的求解器命令也非常简单明了,根据所选的节点,施加CLOAD载荷。
** BC Name: Nodal Force
*CLOAD
ID_18, 1, 10
*CLOAD
ID_18, 2, 20
*CLOAD
ID_18, 3, 30
** Nodal_Force
*NSET, NSET=ID_18
82, 84, 86, 88, 95, 96, 103, 104, 107, 108,
111, 112, 145, 146, 147, 148, 149, 150
5. 重力
重力边界条件属于体积力(Body Force) 范畴,用于模拟地球引力场对结构的作用,是通过给模型的每个单元分配与质量成正比的惯性力,适用于几乎所有包含自重影响的结构分析(如建筑梁板、机械部件、航天器地面工况)。
重力的本质是加速度场作用下的体积力,其大小与单元的质量直接相关。前处理器设置如下,
Image
生成的求解器命令如下图所示。
** DC Name: Earth Gravity
*Dload
Eall, Grav, 9.807, 0, 0, -1
6. 旋转角速度
旋转角速度边界条件用于模拟结构绕某一轴做匀速转动的工况,会在结构内部产生离心力和科里奥利力(高速转动时需考虑),属于惯性载荷范畴,广泛应用于旋转机械分析(如飞轮、叶轮、离心机、涡轮转子)。
输入的参数有旋转轴,旋转原点,和角速度的大小。输入界面如下图所示。
Image
生成的求解器命令如下所示。
** DC Name: Rotational Velocity
*Dload
ID_21, CENTRIF, 100, 5, 5, 0, 0, 0, 1
热分析中的常见边界与初始条件
1. 温度
在有限元热分析中,温度边界条件是直接定义模型特定区域温度值的约束条件,属于本质边界条件(Dirichlet 边界条件),适用于已知表面或节点温度的场景(如恒温水箱壁面、与大热源接触的部件、温控设备的设定温度面)。
在热传导控制方程中,温度边界条件是强制约束,会直接固定边界节点的温度自由度,求解时优先满足该约束,再计算内部温度场分布。 前处理器设置如下,
Image
生成的CalculiX求解器命令如下,
** BC Name: Temperature
*Boundary, op=New
ID_23, 11, 11, 0
2. 热流密度
热流密度(Heat Flux)边界条件是直接定义单位面积上通过固体表面的热流量的边界设置,属于热载荷的一种,适用于已知表面热流输入 / 输出的场景(如电加热器表面、太阳能集热板、高温燃气冲刷壁面)。
热流密度是核心参数,正方向为热量流入固体,负方向为热量流出。输入界面如下:
Image
生成的CalculiX求解器命令如下:
** BC Name: Heat Flux
*Dflux
ID_24, S, 0.5
3. 体热流密度
体积热流是一种体载荷,用于模拟物体内部热源产生或消耗热量的过程,区别于作用在表面的热流密度边界条件,它直接作用于模型的体单元,适用于内热源驱动的温度场分析。
体积热流密度,SI单位为 W/m3(正号表示生成热量,负号表示消耗热量),用户输入界面如下:
Image
生成的CalculiX求解器命令如下,
*DFLUX
ID_31,BF,10.
4. 对流
对流(Convection)边界条件又称膜(Film)边界条件。是用于模拟固体表面与相邻流体(气体或液体)之间对流换热的边界设置,是工程热分析中最常用的边界条件之一,广泛应用于电子设备散热、管道换热、汽车发动机冷却等场景。
对流换热系数是表征对流换热强度的核心参数,环境温度参数是远离固体表面的主流流体温度。前处理器中的输入界面如下,
Image
生成的CalculiX求解器命令如下:
** BC Name: Convection
*Film, op=New
ID_29_S1, F1, 80, 123
ID_29_S2, F2, 80, 123
ID_29_S3, F3, 80, 123
ID_29_S4, F4, 80, 123
5. 热辐射边界条件
辐射边界条件是用于模拟物体表面与周围环境(或其他物体表面)之间通过热辐射方式传递热量的边界设置,其核心遵循斯蒂芬–玻尔兹曼定律,适用于真空、气体等介质的热交换场景(如航天器热控、高温设备散热)。辐射边界条件,是一种非线性边界条件,热流与温度的四次方成正比,求解时需要迭代计算。
用户需要输入的参数为发射率(Emissivity),介于0-1之间的数值,和环境温度。输入界面如下,
Image
生成的热辐射边界条件命令如下,
** BC Name: Radiation
*Radiate, op=New
ID_30_S1, R1, 30, 0.9
ID_30_S2, R2, 30, 0.9
ID_30_S3, R3, 30, 0.9
ID_30_S4, R4, 30, 0.9
总结
有限元分析中,边界条件的类型较多,涉及了条件的参数本身,也涉及到所选择的单元,或节点。对于前处理器来说,生成各种边界条件的命令,是一项复杂的工程。
WELSIM已经可以很好的设置各种边界条件,能够快速生成CalculiX求解器所需要的输入文件,并可以直接用于计算。用户可以使用WELSIM作为CalculiX的前处理器。
CalculiX还有少量边界条件,如Constraint和Equation等, 由于常规分析中较少使用,本文未作讨论。
CalculiX与Abaqus的输入文件格式有着很大的相似性,因此,本文所描述的内容,也可以用于Abaqus求解器。
WelSim与作者不隶属于CalculiX, Abaqus。和CalculiX与Abaqus开发团队与机构没有直接关系。这里引用开源软件的名称和图片仅用作技术博客文章与软件使用的参考。
Monday, January 12, 2026
WELSIM 2026R1 Releases to Support Particle Generation and Enhance Electromagnetic Simulation
WELSIM, the general-purpose engineering simulation and analysis software, has released its latest version 2026R1 (Internal Version: 3.2). Compared to the previous version, 2026R1 comes with a host of new features and enhancements, enabling WELSIM to better support various types of engineering simulation CAE analyses, with notable improvements in particle and electromagnetic simulation capabilities.
Support for Particle Generation
The new version introduces particle generation from geometric models, along with the ability to adjust particle generation methods and particle density. This feature simplifies the setup of smoothed particle and molecular dynamics simulations in WELSIM.
Press enter or click to view image in full size
WELSIM is committed to supporting open data exchange, so users can also export particle data to VTK-format files for visualization or further analysis in other software tools.
Enhanced Support for the OpenRadioss Solver
Become a member
The latest version improves compatibility with the OpenRadioss solver, allowing WELSIM to generate more types of OpenRadioss input files. The newly added input cards include: Fabric Geometric Property /PROP/TYPE16, Self-contact /INTER/TYPE24, and the SPH Cell Command SPHCEL. Meanwhile, a wide range of new material properties have been incorporated, such as LAW6 (HYD_VISC), LAW24 (CONC), LAW25 (COMPSH), LAW58 (FABR_A), LAW73, and LAW74. MatEditor, the standalone material editing software, has been updated with the same features accordingly.
Press enter or click to view image in full size
Enhanced Support for Palace
The new version strengthens compatibility with Palace, the open-source electromagnetic solver. WELSIM now supports more Palace solver types and fully upgrades Palace and its dependent libraries to their latest versions. On the post-processing model, the Poynting Vector result type has been added.
Press enter or click to view image in full size
Other Enhancements and Upgrades
With this release, WELSIM is more stable and user-friendly through optimizations to existing features.
Disclaimer: WELSIM and its authors are not affiliated with OpenRadioss or Palace, nor do they have any connection with the respective development teams and organizations. The references to OpenRadioss and Palace herein are solely for informational purposes in technical blog posts and software usage guidance.
Monday, January 5, 2026
WELSIM发布2026R1版本,支持粒子生成,增强电磁计算
通用工程仿真分析软件WELSIM发布了最新的2026R1版本(内部版本号3.2)。相对于上一个版本,2026R1版本含有许多新的功能与增强,能够更好地支持各种类型的工程仿真CAE分析,尤其是更好的支持粒子与电磁计算。
Image
增强对粒子生成的支持
新版本增加了从几何体生成粒子的功能,同时可以调整粒子生成的方式和粒子密度。这个功能使得WELSIM在光滑粒子和分子动力学仿真上更加简单。
Image
WELSIM一贯支持数据的交换与开放。用户还可以将粒子数据导出为VTK格式的文件,在其他软件上进行显示或分析。
增强对OpenRadioss求解器的支持
新版本支持增加对OpenRadioss的支持,使用WELSIM能生成更多类型的Radioss的输入文件。新增的Radioss输入卡片有:织物几何属性 /PROP/TYPE16,自接触 /INTER/TYPE24,SPH单元命令 SPHCEL。同时,新增了众多材料属性如:LAW6(HYD_VISC) ,LAW24 (CONC), LAW25 (COMPSH) ,LAW58 (FABR_A),LAW73, LAW74等。独立材料编辑软件MatEditor,也同步增加了相同功能。
Image
增强对Palace的支持
新版本增强了对开源电磁求解器Palace的支持。支持了更多的Palace 求解类型。同时全面升级了Palace及其依赖库到最新的版本。在后处理上,增加了坡印廷矢量计算结果的显示。
Image
其他增强与升级
此外,新版本还对已有功能进行了优化与升级,使得WELSIM更稳定更加易于使用。
WelSim与作者不隶属于OpenRadioss和Palace, 和以上开发团队与机构没有关系。这里引用OpenRadioss, Palace 仅用作技术博客文章与软件使用的参考。
Sunday, December 28, 2025
Compile the open-source electromagnetic simulation solver Palace
Palace is a parallel finite element solver developed by AWS Labs for full-wave 3D electromagnetic simulation, released under the Apache 2.0 open-source license. This solver supports full-wave frequency/time-domain simulation, eigenmode analysis, and parameter extraction for electrostatics/magnetostatics. It is compatible with platforms ranging from laptops to supercomputers and supports GPU acceleration, enabling the modeling of quantum computing hardware, RF/microwave devices, antennas, and other systems.
The author previously published a brief article introducing how to compile Palace on Windows, titled Compile the electromagnetic simulation solver Palace in Windows. . Expanding upon that earlier work, this article details the compilation process more in-depth, with a particular focus on the compilation of dependent libraries. The dependent libraries discussed in this article are as follows:
Hypre: A large-scale linear algebra matrix computation library, using version 2.30.
MUMPS: An open-source software library for solving large-scale sparse linear systems of equations.
ARPACK-NG: A library that supports complex linear matrix computations and is used for eigenvalue computation. Primarily written in Fortran, it can be compiled independently without relying on PETSc.
GSLib: Used for interpolation computations in high-order spectral elements.
libCEED: A linear algebra computation management framework that supports parallel computing across various CPUs, GPUs, and clusters.
MFEM: A flexible, efficient, and scalable finite element discretization framework used as the core solving dependency library for Palace.
System Environment and Compilers
Operating System: Windows 11, 64-bit
Compilers: Visual Studio 2022 Community (C++17), Intel Fortran Compiler 2022, and Intel MKL 2024.
Palace Version: 0.15
Compiling Hypre
Hypre is an open-source high-performance parallel linear solver library developed by Lawrence Livermore National Laboratory (LLNL) designed specifically for large-scale scientific computing and engineering simulation. Its core objective is to solve large-scale sparse linear systems of equations (in the form of Ax=b) efficiently, particularly strong at handling ultra-large-scale problems in distributed memory parallel environments. Hypre natively supports MPI parallelism, enabling it to utilize the full computing power of distributed memory architectures, such as supercomputers and clusters, and easily handle linear systems with millions or even billions of degrees of freedom. This stark advantage distinguishes Hypre from smaller solvers (e.g., Eigen).
Compiling Hypre on Windows is simple. You can directly use the built-in CMake configuration file to generate Visual Studio project files, which will in turn produce the static library file.
When configuring CMake, set the parameters as follows:
HYPRE_WITH_MPI = ON
HYPRE_USING_OPENMP = ON
HYPRE_WITH_CUDA = OFF
HYPRE_ENABLE_SYCL = OFF
HYPRE_INSTALL_PREFIX=D:/WelSimLLC/CodeDV/3rdParty/hypre/myInstall
CMAKE_INSTALL_PREFIX=D:/WelSimLLC/CodeDV/3rdParty/hypre/myInstall
If the compilation proceeds smoothly, then the hypre.lib static library file will be generated.
Compiling MUMPS
To solve Wave Port problems, the Palace solver requires one of three direct linear algebra solvers: SuperLU, STRUMPACK, or MUMPS. MUMPS is selected as the dependent library given that the author is relatively familiar with it.
MUMPS is an open-source parallel sparse direct solver library co-developed by French institutions including INRIA and CNRS. Its core objective is to solve large-scale sparse linear systems of equations (Ax=b) using the direct method. Unlike Hypre, which primarily relies on iterative methods, MUMPS computes without iteration by leveraging matrix decomposition (LU/Cholesky) via direct methods. This approach delivers higher precision and more robustness, making it particularly well-suited for solving sparse matrix problems involving asymmetric, symmetric positive definite, or indefinite matrices.
MUMPS depends on BLAS/LAPACK (basic linear algebra libraries) and SCALAPACK (parallel linear algebra library). In this case, the dependency is the Intel MKL Library.
The original version of MUMPS does not provide a compilation method for Windows. Instead, you can opt for the scivision/mumps version available on GitHub, which offers a CMake-based compilation approach for seamless implementation. The latest version 5.8.1 was downloaded for this example.
First ensure that the environment variable contains the following configuration: MKLTOOL= C:\Program Files (x86)\Intel\oneAPI\mkl\latest
Under CMake configuration, set the following parameters:
MUMPS_openmp = ON
MUMPS_parallel = OFF
Once the Visual Studio project files are generated, compile the project to produce all static libraries of MUMPS. The generated static libraries are illustrated in the figure below.
Press enter or click to view image in full size
Compiling ARPACK
For eigenvalue-related computations (e.g., eigenmode calculations), Palace requires a complex-number eigenvalue solver such as SLEPc or ARPACK. Since SLEPc depends on PETSc, which has a rather complex compilation on Windows, ARPACK is selected as the complex-number solver for Palace.
ARPACK is an open-source library for large-scale eigenvalue and eigenvector computations, co-developed by institutions including Rice University and Sandia National Laboratories. Its core objective is to efficiently compute a subset of eigenvalues and their corresponding eigenvectors for large sparse matrices. Unlike libraries such as Hypre and MUMPS, which are designed to solve linear systems of equations (Ax=b), ARPACK focuses specifically on tackling eigenvalue problems (Ax=λx or Ax=λBx).
Press enter or click to view image in full size
Download ARPACK-NG from GitHub and use its built-in CMake build configuration. Set the following parameters in CMake:
ICE = ON
Eigen = ON
Build_SHARED_LIBS = OFF
Meanwhile, ensure that the environment variable contains the entry MKLTOOL= C:\Program Files (x86)\Intel\oneAPI\mkl\latest; this allows CMake to automatically locate the BLAS and LAPACK libraries within MKL.
After generating the Visual Studio project files, you can directly compile the project to obtain the ARPACK static library.
Compiling GSLib
GSLIB is an open-source parallel sparse communication library designed to efficiently support sparse data gather/scatter communication and operators in parallel numerical simulation scenarios, such as the finite element method, spectral element method, and finite difference method. It greatly simplifies the development of parallel sparse communication and lowers the barrier to distributed memory programming. Its adaptive algorithms ensure efficient communication in large-scale parallel computing, satisfying ultra-large-scale simulation requirements.
Press enter or click to view image in full size
Since GSLIB does not come with CMake configuration files, it is unable to automatically generate Visual Studio project files on Windows, requiring you to create the Visual Studio project files manually. Create a new static library project named gslib-palace, and add all the source files and header files to this project.
In the preprocessor definitions of the Visual Studio project, add GSLIB_USE_CBLAS and GSLIB_USE_MKL.
During compilation, when the following error messages appear:
unary minus operator applied to unsigned type, result still unsigned
You will need to modify the code, for example, changing
p[map->n].el = -(uint)1;
to
p[map->n].el = 0-(uint)1;
This allows the compilation to succeed.
Become a member
When the following error message appears:
potentially uninitialized local pointer variable 'h' used
You will need to modify the code and initialize the pointer with a NULL value.
If you receive a prompt indicating that the fgs_free function has already been defined redundantly, simply comment out the fgs_setup, fgs_free, and fgs_unique functions.
Compiling libCEEM
libCEED is an efficient and scalable discretization library that focuses on high-performance computational discretization based on finite element and spectral element methods. It provides a lightweight algebraic interface for linear and nonlinear operators as well as preconditioners; it supports runtime selection and optimized implementations across a variety of computing devices such as CPUs and GPUs.
Compiling libCEED is the most challenging part of the entire task because libCEED does not provide CMake configuration files and contains numerous options. Coupled with the fact that Visual Studio does not support C99 syntax, extensive manual modifications to the source files are required, especially modifications related to dynamic arrays. For example, change the following dynamic array:
CeedInt num_points[num_elem];
to:
CeedInt *num_points = (CeedInt *)malloc(num_elem * sizeof(CeedInt));
After usage, you also need to free the array from memory at the end using the free function: free(num_points);.
Certain strings containing file paths also require modification. For instance, change:
*(relative_file_path) = strstr(absolute_file_path, "ceed/jit-source");
to:
#ifdef
_WIN32
*(relative_file_path) = strstr(absolute_file_path, "ceed\\jit-source");
#else
*(relative_file_path) = strstr(absolute_file_path, "ceed/jit-source");
#endif
Since Visual Studio’s support for weak functions differs from that of Linux, the weak functions in the source code need to be modified as follows:
Original code:
#define
CEED_BACKEND(name, num_prefixes, ...) \
CEED_INTERN int name(void) __attribute__((weak)); \
int name(void) { return CeedRegister_Weak(__func__, num_prefixes, __VA_ARGS__); }
#include
"ceed-backend-list.h"
Modified code:
#ifdef _WIN32
#define CEED_BACKEND(name, num_prefixes, ...) \
CEED_INTERN int name(void) __declspec(selectany); \
int name(void) { return CeedRegister_Weak(__func__, num_prefixes, __VA_ARGS__); }
#else
#define CEED_BACKEND(name, num_prefixes, ...) \
CEED_INTERN int name(void) __attribute__((weak)); \
int name(void) { return CeedRegister_Weak(__func__, num_prefixes, __VA_ARGS__); }
#include "ceed-backend-list.h"
#endif
Visual Studio does not support the __restrict__ keyword and requires it to be changed to __restrict.
Other minor modifications need to be made, such as replacing popen with _popen and pclose with _pclose. Additionally, there is an environment variable setting: setenv("RUST_TOOLCHAIN", "nightly", 0), which needs to be modified as follows:
char env_str[1024];
snprintf(env_str, sizeof(env_str), "%s=%s", "nightly", 0);
_putenv(env_str);
To reduce complexity, this compilation supports only CPU parallel computing and does not require GPU parallel support. Therefore, in the ceed-backend-list.h file, only the following functionalities need to be enabled:
CEED_BACKEND(CeedRegister_Opt_Blocked, 1, "/cpu/self/opt/blocked")
CEED_BACKEND(CeedRegister_Opt_Serial, 1, "/cpu/self/opt/serial")
CEED_BACKEND(CeedRegister_Ref, 1, "/cpu/self/ref/serial")
CEED_BACKEND(CeedRegister_Ref_Blocked, 1, "/cpu/self/ref/blocked")
CEED_BACKEND(CeedRegister_Xsmm_Blocked, 1, "/cpu/self/xsmm/blocked")
CEED_BACKEND(CeedRegister_Xsmm_Serial, 1, "/cpu/self/xsmm/serial")
All other computing functionalities can be commented out. Upon successful compilation, the static library for libCEED will be generated.
Compiling MFEM
MFEM is the core solver of Palace, an open-source high-order finite element library led by the Lawrence Livermore National Laboratory (LLNL). Designed specifically for large-scale scientific computing and engineering simulation, its core objective is to provide a flexible, efficient, and scalable finite element discretization framework. MFEM also serves as a mainstream open-source finite element tool for computational fluid dynamics, electromagnetic simulation, structural mechanics, nuclear physics, and other fields.
Press enter or click to view image in full size
Compiling MFEM is relatively straightforward. You can generate Visual Studio project files via CMake for compilation. Set the following options to ON in CMake:
MFEM_USE_MPI = ON
MFEM_USE_ZLIB = ON
MFEM_USE_METIS = ON
MFEM_USE_LAPACK = ON
MFEM_USE_LEGACY_OPENMP = ON
MFEM_THREAD_SAFE = ON
MFEM_USE_MUMPS = ON
Generate the Visual Studio project files and compile them directly to obtain the MFEM static library.
Compiling Palace
At this point, all complex dependent libraries have been successfully compiled. Proceed to the final step of this project: use the built-in CMake configuration file to generate Visual Studio project files and compile Palace. Note that you should select the CMakeLists.txt file located in the palace subdirectory instead of the one in the root directory, as the latter is used for generating the SuperBuild.
Set the following parameters in CMake:
PALACE_WITH_ARPACK = ON
PALACE_WITH_OPENMP = ON
PALACE_WITH_SLEPC = OFF
MPI_Fortran_WORKS = C:/Program Files (x86)/Microsoft SDKs/MPI/Include/x64
Configure the following paths:
nlohmann_json_DIR = D:/WelSimLLC/CodeDV/3rdParty/nlohmann_json/json-3.12.0/myInstall/share/cmake/nlohmann_json
fmt_DIR = D:\WelSimLLC\CodeDV\3rdParty\fmt\fmt-11.0.2\myInstall\lib\cmake\fmt
scn_DIR = D:\WelSimLLC\CodeDV\libPack\lib\scn\cmake\scn
MFEM_DIR = D:/WelSimLLC/CodeDV/libPack/lib/palace/mfem-cmake
arpackng_DIR = D:\WelSimLLC\CodeDV\libPack\lib\palace\arpack-cmake\arpackng
Open the generated Visual Studio project, and you will see a static library project named libpalace and an executable project named palace. If the compiler reports missing header files or the linker indicates unresolved functions during compilation, you can directly add the relevant paths and static libraries to the projects.
After completing the compilation, you can run a test on palace.exe. Note that you need to place all dynamic dependent libraries (such as the MKL dynamic libraries) in the same directory as palace.exe before running it.
Run a simple test case. The output shown below indicates that the compilation has been successful basically.
Press enter or click to view image in full size
Conclusion
As open-source electromagnetic field simulation solvers are presently scarce, Palace stands out as the most feature-rich one available. As a result, Palace relies on a large number of dependent libraries, and its version is still under continuous iterations. Some of these dependencies only support Linux builds, which adds to the complexity of compiling Palace on Windows. This article documents the complete compilation process of Palace and provides a resource for the open-source community on how to build Palace for Windows.
There are also other dependent libraries that are relatively easy to compile, such as Eigen, fmt, Metis, and nlohmann/json. Experienced developers can often independently build these libraries on Windows, so it is not discussed in this article.
The author has included the compiled palace.exe executable file in the WELSIM installation package, so you are able to directly obtain the Windows version of palace.exe from the WELSIM installer without having to compile it yourself.
This article describes the configuration of Palace for CPU multi-core parallel computing. The compilation methods for GPU-accelerated versions, such as CUDA, HIP, or SYCL, will be discussed in future articles.
WelSim and the author are not affiliated with Palace, Hypre, MUMPS, ARPACK, GSLIB, libCEED, or MFEM, nor do they have any direct connections with the development teams or institutions behind these projects. The references to the names and images of these open-source software in this article are solely for the purpose of technical blog documentation and software usage guidance.
Saturday, December 27, 2025
编译开源电磁仿真求解器Palace
Palace 是AWS Labs推出的一款用于全波 3D 电磁仿真的并行有限元求解器,开源许可证为Apache 2.0,求解器支持频域/时域全波、特征模、静电/静磁集总参数提取,适配笔记本到超算的多平台与 GPU 加速,可以用于量子计算硬件、射频 / 微波器件、天线等建模。
Image
笔者曾经简要介绍了如何在Windows下编译Palace的文章,参见《Windows环境下编译电磁仿真求解器Palace》一文。本文是在前文的基础上,更为详细的介绍编译过程,尤其着重介绍依赖库的编译。本文讨论的依赖库有:
Hypre:大型线性代数矩阵计算包。本例使用2.33.0版本。
MUMPS:来自法国的求解大规模稀疏线性方程组的开源软件库。本例使用5.8.1版本。
ARPACK-NG:支持复数线性矩阵计算,用于特征值计算。以Fortran程序为主,无需依赖PETSc,可以独立编译。需要通过Palace提供的diff文件手动修改部分源代码。
GSLIB:用于高阶谱单元的插值计算。
libCEED:是一款线性代数计算管理终端,支持对各种CPU,GPU和集群的并行计算。本例使用0.12版本。需要手动修改源代码以通过Windows Visual Studio的编译。
MFEM:提供灵活、高效、可扩展的有限元离散化框架。本例使用4.8.1版本。是Palace的核心求解依赖库。需要通过Palace提供的diff文件手动修改部分源代码。
系统环境与依赖库
操作系统:Windows 11, 64-bit
编译器:Visual Studio 2022 Community, C++17。Inter Fortran Compiler 2022,Intel MKL 2024。
Palace版本:0.15
编译Hypre
Hypre是劳伦斯利弗莫尔国家实验室 LLNL 开发的开源高性能并行线性求解器库,专为大规模科学计算和工程模拟设计。核心目标是高效求解大规模稀疏线性方程组(形如 Ax=b),尤其擅长处理超大规模、分布式内存并行环境下的问题。hypre 原生支持 MPI并行,能充分利用超级计算机、集群等分布式内存架构的算力,轻松处理数百万甚至数十亿自由度的线性系统,这是它区别于小型求解器(如 Eigen)的核心优势。
Image
Windows下编译hypre并不复杂,可以直接使用自带的CMakeFile文件,生成Visual Studio的项目文件,生成静态库文件。在配置CMake时,参数如下设置:
HYPRE_WITH_MPI = ON
HYPRE_USING_OPENMP = ON
HYPRE_WITH_CUDA = OFF
HYPRE_ENABLE_SYCL = OFF
HYPRE_INSTALL_PREFIX=D:/WelSimLLC/CodeDV/3rdParty/hypre/myInstall
CMAKE_INSTALL_PREFIX=D:/WelSimLLC/CodeDV/3rdParty/hypre/myInstall
如果编译顺利,会生成hyper.lib静态库文件。
编译 MUMPS
Palace求解器需要SuperLU, StrumPack,或者MUMPS三个直接线代求解器中的一个,才能求解Wave Port问题。由于笔者比较熟悉MUMPS,因此就选择的MUMPS求解器作为依赖库。
MUMPS是由法国 INRIA、CNRS 等机构联合开发的开源并行稀疏直接求解器库。它的核心目标是用 “直接法” 求解大规模稀疏线性方程组(Ax=b),区别于 hypre 以 “迭代法” 为主,MUMPS 用直接法通过矩阵分解(LU/Cholesky)计算出解,无需迭代,精度更高、鲁棒性更强,尤其适合求解非对称、对称正定 / 不定的稀疏矩阵问题。
MUMPS 依赖 BLAS/LAPACK(基础线性代数库)、SCALAPACK(并行线性代数库)。这里我们使用Intel的MKL库作为依赖库。
原始版本的MUMPS不提供Windows的编译方式,可以选择GitHub上的scivision/mumps版本,提供了基于CMake的编译方式,可以轻易实现编译。本例下载的是最新的5.8.1版本。
确保环境变量中含有MKLTOOL= C:\Program Files (x86)\Intel\oneAPI\mkl\latest
在CMake编译下,设置
MUMPS_openmp = ON
MUMP_parallel = OFF
生成Visual Studio的项目文件后,直接编译即可生成MUMPS的所有静态库。生成的静态库如下图所示。
Image
编译ARPACK
Palace在计算特征值相关的功能时,如计算Eigenmode,需要有SLEPc或者ARPACK复数求解器。由于SLEPc依赖PETSc,而PETSc在Windows下的编译较为复杂,因此就不选用SLEPc,这里选择ARPACK作为Palace的复数求解器。
ARPACK是由莱斯大学、桑迪亚国家实验室等机构,联合开发的开源大规模特征值/特征向量求解库。它的核心目标是高效计算大型稀疏矩阵的少数特征值与对应特征向量,和 hypre、MUMPS 这类求解线性方程组(Ax=b)的库不同,ARPACK 专注于处理特征值问题(Ax=λx 或 Ax=λBx)。
Image
从GitHub上下载ARPACK-ng,使用自带的CMake编译方式。确保环境变量中含有MKLTOOL= C:\Program Files (x86)\Intel\oneAPI\mkl\latest,这样CMake会自动找到MKL里的BLAS和Lapack。在CMake中设置如下
ICE = ON
Eigen = ON
Build_SHARED_LIBS = OFF
同时,确保环境变量中含有MKLTOOL= C:\Program Files (x86)\Intel\oneAPI\mkl\latest,这样CMake会自动找到MKL里的BLAS和Lapack。
同时,需要根据palace目录中extern/patch/arpack-ng文件夹下的diff文件,对源文件做相应修改。生成Visual Studio项目文件后,既可以直接编译得到Arpack的静态库。
编译GSLib
GSLIB是一个开源的并行稀疏通信库,它专为有限元、谱元、有限差分等并行数值模拟场景,提供高效的稀疏数据聚合 – 分发(Gather/Scatter)通信与算子支持。大幅简化并行稀疏通信开发,降低分布式内存编程门槛;自适应算法保证大规模并行下的通信效率,适配超大规模仿真需求。
Image
由于GSLib并没有CMake文件,无法在Windows下自动生成Visual Studio的项目文件,需要用户自己建立Visual Studio的项目文件。新建一个静态库项目,取名为gslib-palace,并将所有的源文件和头文件添加到此项目中。
在Visual Studio的项目预处理定义中,添加GSLIB_USE_CBLAS, GSLIB_USE_MKL。
编译时,当遇到以下错误提示时:
unary minus operator applied to unsigned type, result still unsigned
需要修改代码,如将
p[map->n].el = -(uint)1;
改为
p[map->n].el = 0-(uint)1;
以通过编译。
当遇到以下错误提示时:
potentially uninitialized local pointer variable 'h' used
需要修改代码,给指针添加NULL初始值。
如果提示fgs_free函数已经有重复的定义。将fgs_setup, fgs_free与fgs_unique函数注释掉即可。
编译libCEEM
libCEED 是一个高效可扩展的离散化库,专注于基于有限元和谱元方法的高效计算离散化。它提供轻量级代数接口,用于线性和非线性算子及预条件子,支持基于 CPU、GPU 等多种计算设备的运行时选择优化实现。
Image
编译libCEEM是整个工作的难点,由于libCEED不提供CMakeFile文件,同时含有较多的选项,同时Visual Studio不支持C99的语法,需要大量手动修改源文件,尤其是对于动态数组的修改。如将以下动态数组
CeedInt num_points[num_elem];
修改成为
CeedInt *num_points = (CeedInt *)malloc(num_elem * sizeof(CeedInt));
使用完成后,还需在结尾处,使用free函数,从内存中删除此数组,free(num_points)。
一些含有路径的字符串,也需要做修改。如
*(relative_file_path) = strstr(absolute_file_path, "ceed/jit-source");
改为
#ifdef
_WIN32
*(relative_file_path) = strstr(absolute_file_path, "ceed\\jit-source");
#else
*(relative_file_path) = strstr(absolute_file_path, "ceed/jit-source");
#endif
由于Visual Studio对weak的函数支持方式与Linux不一样,需要对源码中的weak函数做如下修改:
#define
CEED_BACKEND(name, num_prefixes, ...) \
CEED_INTERN int name(void) __attribute__((weak)); \
int name(void) { return CeedRegister_Weak(__func__, num_prefixes, __VA_ARGS__); }
#include
"ceed-backend-list.h"
改为
#ifdef
_WIN32
#define
CEED_BACKEND(name, num_prefixes, ...) \
CEED_INTERN int name(void) __declspec(selectany); \
int name(void) { return CeedRegister_Weak(__func__, num_prefixes, __VA_ARGS__); }
#else
#define
CEED_BACKEND(name, num_prefixes, ...) \
CEED_INTERN int name(void) __attribute__((weak)); \
int name(void) { return CeedRegister_Weak(__func__, num_prefixes, __VA_ARGS__); }
#include
"ceed-backend-list.h"
#endif
Visual Studio不支持__restrict__关键字,需要改成__restrict。
还有一些小范围的修改,如将popen改成_popen,将pclose改成 _pclose。有一处环境变量设定setenv("RUST_TOOLCHAIN", "nightly", 0),需要做如下修改:
char env_str[1024];
snprintf(env_str, sizeof(env_str), "%s=%s", "nightly", 0);
_putenv(env_str);
为了减少不必要的复杂度,本次编译只支持CPU并行计算的内容,GPU并行无需支持,因此在ceed-backend-list.h文件中,只需要支持以下功能:
CEED_BACKEND(CeedRegister_Opt_Blocked, 1, "/cpu/self/opt/blocked")
CEED_BACKEND(CeedRegister_Opt_Serial, 1, "/cpu/self/opt/serial")
CEED_BACKEND(CeedRegister_Ref, 1, "/cpu/self/ref/serial")
CEED_BACKEND(CeedRegister_Ref_Blocked, 1, "/cpu/self/ref/blocked")
CEED_BACKEND(CeedRegister_Xsmm_Blocked, 1, "/cpu/self/xsmm/blocked")
CEED_BACKEND(CeedRegister_Xsmm_Serial, 1, "/cpu/self/xsmm/serial")
其余的计算功能可以注释掉。编译成功后会生成libCEEM的静态库。
编译MFEM
MFEM是Palace的核心求解器,由劳伦斯利弗莫尔国家实验室(LLNL)主导开发的开源高阶有限元库,专为大规模科学计算和工程仿真设计,核心目标是提供灵活、高效、可扩展的有限元离散化框架。MFEM 也是计算流体力学、电磁仿真、结构力学、核物理模拟等领域的主流开源有限元工具。
Image
编译MFEM相对简单,可以通过CMake的方式生成Visual Studio项目文件来编译。在CMake的选项中,选择激活的选项如下:
MFEM_USE_MPI = ON
MFEM_USE_ZLIB = ON
MFEM_USE_METIS = ON
MFEM_USE_LAPACK = ON
MFEM_USE_LEGACY_OPENMP = ON
MFEM_THREAD_SAFE = ON
MFEM_USE_MUMPS = ON
同时,需要根据palace目录中extern/patch/mfem文件夹下的diff文件,对源文件做相应修改。由于需要修改的源文件较多,需要耐心仔细,或者在Linux下先编译一遍,将自动修改好的mfem拷贝覆盖至Windows下需要编译的mfem文件夹。整个生成Visual Studio的项目文件后,直接编译,即可得到mfem的静态库。
编译Palace
至此,复杂的依赖库都已经编译完成。开始整个项目的最后一步,使用自带的CMakeFile文件,生成Visual Studio的项目文件,编译Palace。这里要注意的是,应该选择在palace子目录中的CMakeFile.txt文件,而不是根目录下的CMakeFile.txt,因为后者是用于生成Superbuild的。
CMake下设置:
PALACE_WITH_ARPACK = ON
PALACE_WITH_OPENMP = ON
PALACE_WITH_SLEPC = OFF
MPI_Fortran_WORKS = C:/Program Files (x86)/Microsoft SDKs/MPI/Include/x64
设置路径
nlohmann_json_DIR = D:/WelSimLLC/CodeDV/3rdParty/nlohmann_json/json-3.12.0/myInstall/share/cmake/nlohmann_json
fmt_DIR = D:\WelSimLLC\CodeDV\3rdParty\fmt\fmt-11.0.2\myInstall\lib\cmake\fmt
scn_DIR = D:\WelSimLLC\CodeDV\libPack\lib\scn\cmake\scn
MFEM_DIR = D:/WelSimLLC/CodeDV/libPack/lib/palace/mfem-cmake
arpackng_DIR = D:\WelSimLLC\CodeDV\libPack\lib\palace\arpack-cmake\arpackng
打开生成的Visual Studio项目,可以看到名为libpalace的静态库项目,和名为palace的可执行文件项目。如果在编译时提示找不到头文件,或者连接时缺少相关函数,可以直接在项目中添加相关路径和静态库。
Image
完成编译后,可以试运行一下palace.exe。注意使用时,需要将动态依赖库放置与palace.exe同一个文件夹下,如MKL系列的相关动态库文件。
计算一个简单算例,得到如下显示。表明编译基本成功。
Image
总结
目前可用的开源电磁场仿真求解器不多,Palace是目前功能最多的开源电磁求解器。Palace的依赖库较多,版本还在不断更新迭代,一些依赖库只支持Linux版本,增加了Windows下编译的难度。本文记录编译整个Palace的过程,同时给开源社区提供一些Windows下编译Palace的参考。
还有一些其他依赖库编译相对容易,如Eigen, fmt, Metis,nlhmann/json等。有经验的开发者可以自行在Windows下成功编译,就不在本文中赘述了。
笔者已将编译好的palace.exe可执行文件收录在WELSIM安装包中,用户也可以直接从WELSIM安装包中获得Windows版本的palace.exe,无需自己编译。
本文介绍的是CPU多核并行计算下的Palace,GPU版本的编译方法,如CUDA, HIP,或SYCL版本,会在以后的文章中讨论。
WelSim与作者不隶属于Palace, Hypre, MUMPS, Arpack, GSLib, libCEEM, 和MFEM。和Palace, Hypre, MUMPS, Arpack, GSLib, libCEEM, 和MFEM开发团队与机构没有直接关系。这里引用这些开源软件的名称和图片仅用作技术博客文章与软件使用的参考。
Tuesday, September 30, 2025
Generating Particles for Complex Geometries Using WELSIM
With the development of modern engineering simulation, particle-based simulation has been increasingly adopted by the industrial community. Particle-related computations and software have emerged in various fields of engineering and science. In addition to pure particle simulations, such as molecular dynamics, there are also coupled methods with continuum approaches like the finite element method, enabling more sophisticated simulations. An example is the SPH (Smoothed Particle Hydrodynamics) method, which simulates the motion of fluids and granular materials.
As a result, the demands on particle simulations are also rising. Particle generation is the first and most critical step in all such simulations. Therefore, algorithms and processes for generating particles are particularly important. The author has previously discussed numerical methods for generating particles in the article titled “Automatic Generation of Simulation Particles.”
Press enter or click to view image in full size
Generating particles for simple geometric models, such as cubes, is not difficult. However, when the geometry becomes more complex, particle generation becomes challenging. Currently, there are not many software solutions on the market that can generate particles for arbitrary shapes. WELSIM is already capable of handling this well and can export particles as external files for use in other software. This article provides a brief introduction on how to generate particles in WELSIM.
1. Open WELSIM and Import a STEP Geometry Model
In this example, a cylindrical model with a circular hole is imported. Set the geometry’s Create Particles property to True.
Press enter or click to view image in full size
2. Click the Meshing Button to Automatically Generate Particles
In this setup, 441 particles are generated.
Press enter or click to view image in full size
3. To Increase Particle Density
Modify the Maximum Size value in the mesh settings. When set to 0.01, the particle density increases.
4. Adjust Particle Display Size for Clarity
When the number of particles increases, it helps to reduce their display size for better visibility. In the 3D View of the mesh object, set the Particle Size value. Here, it is set to 0.001.
Now, a larger number of particles can be seen — 16,060 in total. WELSIM thus allows for easy and efficient generation of particles at any desired density.
Press enter or click to view image in full size
5. Export the Particles
Once particle generation is complete, export the particle file. Right-click the Mesh objectand select Export Particles from the context menu.
Press enter or click to view image in full size
6. In the Export Dialog
Enter the filename and choose the export format. The current version supports the VTK PolyData format. More formats will be supported in future versions.
Press enter or click to view image in full size
The exported file can be loaded and used by other software. For example, ParaView can be used to visualize the exported particles, as shown in the image.
Press enter or click to view image in full size
Conclusion
This article outlines the steps for generating particles using WELSIM. Users only need to import a geometry in STEP format and, through an automatic mesh-like method, can quickly generate particles at various densities. Although a simple geometry was used here, the same process can be applied to complex models. The software also supports exporting particle data for use in other applications. The particle generation feature is already available in version 2025R3 and will continue to be improved in future releases.
WELSIM has no direct affiliation with the author or the developers of ParaView. ParaView is referenced here purely as a technical example for demonstration purposes.
Monday, September 29, 2025
使用WELSIM生成复杂几何模型的粒子
随着现代工程仿真的发展,粒子仿真也越来越多的被工业届接受。粒子相关的计算和软件在各个工程和科学领域都有出现。除了单纯的粒子计算,如分子动力学计算,还有与有限元等连续介质计算方法耦合,实现更为精巧的计算。如SPH方法计算流体和沙石颗粒的运动。随之,人们对粒子计算的要求也不断提高。而生成粒子是所有计算的第一步,也是整个计算的关键一环。因此,生成粒子的算法和实现过程,就显得尤为重要了。作者曾讨论过生成粒子的数值方法,参见《自动化生成仿真粒子的方法》一文。
Image
生成简单几何模型,如立方体,的粒子并不难,但是当粒子区域轮廓变得复杂时,生成粒子就变得困难了。目前市场可以生成任意轮廓粒子的软件并不多,WELSIM已经可以很好的实现这点,并输出为外部文件,用于其他软件的计算。本文就如何在WELSIM下生成粒子,做一个简要介绍。
1. 打开WELSIM软件,并导入一个STEP几何模型。这里导入一个带有圆孔的圆柱体。并将几何体的创建粒子(Create Particles)属性设为真。
Image
2. 点击网格划分按钮,便可自动生成粒子。此设置下,生成了441个粒子。
Image
3. 如果想得到密度更高的粒子,可以修改网格设置属性中的最大单元尺寸(Maximum Size)值。当把值改为0.01时,粒子的密度会增加。
Image
4. 粒子数量增加后,为了显示更为清楚,可以调整粒子显示大小。点击网格节点的三维视图(3D View),设置粒子尺寸(Particle Size)值即可,这里设为0.001。
Image
此时,可以看到生成了更多的粒子,数量达到16,060。因此,使用WELSIM可以方便快捷地生成任意密度的粒子。
Image
5. 粒子生成工作已经完成。下一步来导出粒子文件。右键点击Mesh节点,从弹出菜单中选择导出粒子(Export Particles)。
Image
6. 在导出对话框中,输入文件名称和类型。目前已经支持了VTK PolyData格式,以后版本中,会增加更多的导出格式。
Image
导出文件可以被其他软件读取并使用。如图所示,使用ParaView读取此文件的显示结果。
Image
总结
本文介绍了如何使用WELSIM生成粒子的方法步骤。用户只需导入STEP格式的几何体,通过类似自动化网格划分的方式,快速得到各种不同密度的粒子。本文中使用的几何模型较为简单,复杂的几何体也可以同样的方式得到粒子。同时,提供了粒子数据导出功能,用户可以将生成的粒子用于其他软件的计算。粒子生成功能已经存在2025R3版中,会在后续的版本中不断增强和改进。
WelSim与作者和ParaView开发者没有直接关系。这里引用ParaView仅用作技术博客文章与软件使用的参考。
Subscribe to:
Comments (Atom)