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开发团队与机构没有直接关系。这里引用这些开源软件的名称和图片仅用作技术博客文章与软件使用的参考。