Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ochubar/Radia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: hidecode221b/Radia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Oct 28, 2021

  1. Add files via upload

    hidecode221b authored Oct 28, 2021

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    8f7f661 View commit details
  2. Create gnu

    hidecode221b authored Oct 28, 2021
    Copy the full SHA
    b81fb39 View commit details
  3. Delete gnu

    hidecode221b authored Oct 28, 2021
    Copy the full SHA
    77f4303 View commit details
  4. Create readme

    hidecode221b authored Oct 28, 2021
    Copy the full SHA
    0910ea2 View commit details
  5. Add files via upload

    hidecode221b authored Oct 28, 2021
    Copy the full SHA
    42f5268 View commit details
  6. Add files via upload

    hidecode221b authored Oct 28, 2021
    Copy the full SHA
    e4b7545 View commit details
  7. Copy the full SHA
    6914c6f View commit details
  8. Copy the full SHA
    43055fc View commit details
  9. Copy the full SHA
    549f276 View commit details
  10. Copy the full SHA
    722aaa4 View commit details

Commits on Nov 5, 2021

  1. Copy the full SHA
    08bd1fa View commit details
  2. Copy the full SHA
    e163842 View commit details
  3. Copy the full SHA
    691acf6 View commit details
  4. Copy the full SHA
    78b58fd View commit details

Commits on Dec 26, 2021

  1. Copy the full SHA
    be8bc6a View commit details
  2. Add files via upload

    hidecode221b authored Dec 26, 2021
    Copy the full SHA
    327fd5f View commit details
  3. Copy the full SHA
    19a77c4 View commit details
  4. Copy the full SHA
    aef453e View commit details

Commits on Dec 27, 2021

  1. Add files via upload

    hidecode221b authored Dec 27, 2021
    Copy the full SHA
    9ac9267 View commit details

Commits on Dec 28, 2021

  1. Copy the full SHA
    f2779a7 View commit details

Commits on Jan 27, 2022

  1. Copy the full SHA
    60d6bc1 View commit details

Commits on Feb 6, 2024

  1. Update README.md

    hidecode221b authored Feb 6, 2024
    Copy the full SHA
    8e48ddb View commit details
  2. Update README.md

    hidecode221b authored Feb 6, 2024
    Copy the full SHA
    d702565 View commit details

Commits on Jun 19, 2024

  1. Copy the full SHA
    67286f9 View commit details
  2. Copy the full SHA
    5c7ca3c View commit details
  3. Copy the full SHA
    cf34ce6 View commit details
  4. Copy the full SHA
    df3df28 View commit details
  5. Copy the full SHA
    1c661fd View commit details
  6. Copy the full SHA
    e9d9902 View commit details
  7. Copy the full SHA
    4fa9b54 View commit details

Commits on Jun 20, 2024

  1. Add files via upload

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    4cdc5aa View commit details
  2. Copy the full SHA
    2606f7f View commit details
  3. Create readme.md

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    044afc3 View commit details
  4. Add files via upload

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    0bbe5b6 View commit details
  5. Update readme.md

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    e9a39f4 View commit details
  6. Copy the full SHA
    742bb96 View commit details
  7. Copy the full SHA
    f0681bb View commit details
  8. Copy the full SHA
    2cefede View commit details
  9. Copy the full SHA
    55e3a92 View commit details
  10. Copy the full SHA
    3f49824 View commit details
  11. Add files via upload

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    a7af510 View commit details
  12. Add files via upload

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    3a42089 View commit details
  13. Copy the full SHA
    1bcd68e View commit details
  14. Add files via upload

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    06bf023 View commit details
  15. Create readme.md

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    ccc638e View commit details
  16. Copy the full SHA
    9d14c2b View commit details
  17. Add files via upload

    hidecode221b authored Jun 20, 2024
    Copy the full SHA
    4883854 View commit details
  18. Copy the full SHA
    612d4c3 View commit details
  19. Copy the full SHA
    8a73297 View commit details
  20. Copy the full SHA
    e1493f8 View commit details
25 changes: 11 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ ext_dir = $(root_dir)/ext_lib
gcc_dir = $(root_dir)/cpp/gcc
py_dir = $(root_dir)/cpp/py
fftw_version = fftw-2.1.5
fftw_dir = $(fftw_version)
fftw_file = $(fftw_version).tar.gz
fftw_dir = $(ext_dir)/$(fftw_version)
fftw_file = $(ext_dir)/fftw
log_fftw = /dev/null
examples_dir = $(env_dir)/radia_python
export MODE ?= 0
@@ -29,20 +29,17 @@ fftw:
if [ ! -d "$(ext_dir)" ]; then \
mkdir $(ext_dir); \
fi; \
cd $(ext_dir); \
if [ ! -f "$(fftw_file)" ]; then \
wget https://raw.githubusercontent.com/ochubar/SRW/master/ext_lib/$(fftw_file); \
if [ ! -d "$(fftw_dir)" ]; then \
mkdir $(fftw_dir); \
fi; \
if [ -d "$(fftw_dir)" ]; then \
rm -rf $(fftw_dir); \
fi; \
tar -zxf $(fftw_file); \
cd $(fftw_file); \
cp $(fftw_file)/CMakeLists.txt $(fftw_dir); \
cd $(fftw_dir); \
./configure --enable-float --with-pic; \
sed 's/^CFLAGS = /CFLAGS = -fPIC /' -i Makefile; \
make -j8 && cp fftw/.libs/libfftw.a $(ext_dir); \
cmake .; \
make -j8
cp $(fftw_dir)/stage/lib/libfftw.a $(ext_dir); \
cd $(root_dir); \
rm -rf $(ext_dir)/$(fftw_dir);
rm -rf $(fftw_dir);

core:
#cd $(gcc_dir); make -j8 clean lib
@@ -53,7 +50,7 @@ pylib:

clean:
rm -f $(ext_dir)/libfftw.a $(gcc_dir)/libradia.a $(gcc_dir)/radia*.so; \
rm -rf $(ext_dir)/$(fftw_dir)/py/build/;
rm -rf $(fftw_dir)/py/build/;
if [ -d $(root_dir)/.git ]; then rm -f $(examples_dir)/radia*.so && (git checkout $(examples_dir)/radia*.so 2>/dev/null || :); fi;

.PHONY: all clean core fftw nofftw pylib
22 changes: 20 additions & 2 deletions cpp/gcc/Makefile
Original file line number Diff line number Diff line change
@@ -33,9 +33,27 @@ ML_INCLUDE= -I$(ML_ORIG_DIR) -I$(RAD_SRC_ML_DIR)
#MLMPREP= $(ML_ORIG_DIR)/mprep

#CC = gcc
CC = cc
#CC = cc
#CC = mpicxx
CXX = c++
#CXX = c++

ifeq ($(OS),Windows_NT)
CC ?= cc
CXX ?= c++
OSFLAG += -DWIN32
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CC ?= cc
CXX ?= c++
OSFLAG += -DLINUX
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG += -D__MAC__
CC ?= gcc
CXX ?= g++ -stdlib=libc++ -mmacosx-version-min=10.9
endif
endif

#RAD_SRC_DEF= -D__GCC__ -D__MATHEMATICA__ -DFFTW_ENABLE_FLOAT -DNO_TIMER -DANSI_DECLARATORS -DTRILIBRARY -DLINUX -D_GM_WITHOUT_BASE -DMLINTERFACE=4
#RAD_SRC_DEF= -D__GCC__ -DFFTW_ENABLE_FLOAT -DNO_TIMER -DANSI_DECLARATORS -DTRILIBRARY -DLINUX -D_GM_WITHOUT_BASE -D_WITH_MPI
2 changes: 1 addition & 1 deletion cpp/py/Makefile
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ MODE ?= 0
python: radia.so

radia.so:
MODE=$(MODE) python setup.py build_ext --build-lib='../gcc'
MODE=$(MODE) python3 setup.py build_ext --build-lib='../gcc'
cp ../gcc/radia*.so ../../env/radia_python/radia.so
rm -rf build

4 changes: 4 additions & 0 deletions cpp/py/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Change `python` to `python3`
```
MODE=$(MODE) python3 setup.py build_ext --build-lib='../gcc'
```
6 changes: 6 additions & 0 deletions cpp/src/ext/triangle/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Comment out lines below to build in macos

```
/* #include <fpu_control.h> */
/*_FPU_SETCW(cword); */
```
5 changes: 3 additions & 2 deletions cpp/src/ext/triangle/triangle.c
Original file line number Diff line number Diff line change
@@ -358,7 +358,7 @@ extern int gErrorTRIANGLE; //OC
#include <float.h>
#endif /* CPU86 */
#ifdef LINUX
#include <fpu_control.h>
/* #include <fpu_control.h> */
#endif /* LINUX */
#ifdef TRILIBRARY
#include "triangle.h"
@@ -5035,7 +5035,8 @@ void exactinit()
/* cword = 4735; */
cword = 4722; /* set FPU control word for double precision */
#endif /* not SINGLE */
_FPU_SETCW(cword);
/* _FPU_SETCW(cword); */
cword = 4722;
#endif /* LINUX */

every_other = 1;
4 changes: 3 additions & 1 deletion env/radia_python/RADIA_Example02.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
from __future__ import print_function #Py 2.*/3.* compatibility
import radia as rad
from uti_plot import *
import radia_vtk as rad_vtk

print('RADIA Python Example #2:')
print('This example consists in the creation of a set of racetrack and circular coils,')
@@ -81,7 +82,8 @@ def CalcField(g):
print('SCW Geometry Index:', g)

#Display the Geometry in 3D Viewer
rad.ObjDrwOpenGL(g)
#rad.ObjDrwOpenGL(g)
rad_vtk.plot_vtk(g)

#Calculate Magnetic Field
BzVsY, MeshY, IBzVsX, MeshX = CalcField(g)
4 changes: 3 additions & 1 deletion env/radia_python/RADIA_Example03.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import radia as rad
from uti_plot import *
import time
import radia_vtk as rad_vtk

print('RADIA Python Example #3:')
print('This example creates and solves a simple U46 Hybrid Undulator made with rectangular magnet blocks.')
@@ -124,7 +125,8 @@ def CalcField(g, per, numPer):
#Build the Structure
und, pole, magnet = Und(lp, mp, np, cp, lm, mm, nm, cm, gap, gapOffset, numPer)
#Show the Structure in 3D Viewer
rad.ObjDrwOpenGL(und)
#rad.ObjDrwOpenGL(und)
rad_vtk.plot_vtk(und)

#Solve the Magnetization Problem
t0 = time.time()
4 changes: 3 additions & 1 deletion env/radia_python/RADIA_Example04.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import radia as rad
from math import *
from uti_plot import *
import radia_vtk as rad_vtk

print('RADIA Python Example #4:')
print('This example illustrates the use of a polyhedron shape by means of the "radObjMltExtPgn" function.')
@@ -48,7 +49,8 @@ def SphericalVolume(_r, _n_phi, _nz, _M):
rad.ObjDrwAtr(aSpherMag, [0,0.5,0.8])

#Display the Geometry in 3D Viewer
rad.ObjDrwOpenGL(aSpherMag)
#rad.ObjDrwOpenGL(aSpherMag)
rad_vtk.plot_vtk(aSpherMag)

#Calculate Magnetic Field
print('Field in the Center = ', rad.Fld(aSpherMag, 'b', [0,0,0]))
7 changes: 5 additions & 2 deletions env/radia_python/RADIA_Example05.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
from time import *
from math import *
from array import *
import radia_vtk as rad_vtk

print('RADIA Python Example #5:')
print('This example concerns geometries dominated by iron.')
@@ -145,7 +146,8 @@ def Geom(circ):
size=rad.ObjDegFre(t)

#Display the Geometry
rad.ObjDrwOpenGL(t)
#rad.ObjDrwOpenGL(t)
rad_vtk.plot_vtk(t)

#Solve the Geometry
t1=time()
@@ -185,7 +187,8 @@ def Geom(circ):

#Creating the Model and Solving with Rectangular Segmentation in the Corners
t = Geom(0)
rad.ObjDrwOpenGL(t)
#rad.ObjDrwOpenGL(t)
rad_vtk.plot_vtk(t)

t1=time()
res=rad.Solve(t,0.0001,1500)
4 changes: 3 additions & 1 deletion env/radia_python/RADIA_Example06.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
from time import *
from math import *
from array import *
import radia_vtk as rad_vtk

print('RADIA Python Example #6:')
print('')
@@ -195,7 +196,8 @@ def multipole(w, q):
print('Delta Int. Quad. @ 10 mm = ', round(100*(Iz1/Iz-1),2), '%')

#Display the Geometry
rad.ObjDrwOpenGL(g)
#rad.ObjDrwOpenGL(g)
rad_vtk.plot_vtk(g)

#Magnetic Field Plots
z = 0; x1 = 0; x2 = 30; ymax = 40; np = 20
2,135 changes: 2,135 additions & 0 deletions env/radia_python/log_radia_build_py27_macos_make_all.sh

Large diffs are not rendered by default.

1,784 changes: 1,784 additions & 0 deletions env/radia_python/log_radia_build_py27_macos_make_fftw.sh

Large diffs are not rendered by default.

939 changes: 939 additions & 0 deletions env/radia_python/log_radia_build_py312_macos_make_all.sh

Large diffs are not rendered by default.

632 changes: 632 additions & 0 deletions env/radia_python/log_radia_build_py39_macos_make.sh

Large diffs are not rendered by default.

2,748 changes: 2,748 additions & 0 deletions env/radia_python/log_radia_build_py39_macos_make_all.sh

Large diffs are not rendered by default.

2,268 changes: 2,268 additions & 0 deletions env/radia_python/log_radia_build_py39_macos_make_fftw.sh

Large diffs are not rendered by default.

Binary file added env/radia_python/radia.cpython-27m-darwin.so
Binary file not shown.
Binary file added env/radia_python/radia.cpython-310-darwin.so
Binary file not shown.
Binary file added env/radia_python/radia.cpython-312-darwin.so
Binary file not shown.
Binary file added env/radia_python/radia.cpython-37m-darwin.so
Binary file not shown.
Binary file added env/radia_python/radia.cpython-38-darwin.so
Binary file not shown.
Binary file added env/radia_python/radia.cpython-39-darwin.so
Binary file not shown.
Binary file modified env/radia_python/radia.so
Binary file not shown.
78 changes: 78 additions & 0 deletions env/radia_python/radia_vtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ----------------------------------------------------------
# Modified for Hybrid wiggler and 3D vector field
# VTK preview by PyVISTA
#
# Hideki Nakajima, SLRI, 2022
# ----------------------------------------------------------
# --- Imports
import radia as rad
from itertools import accumulate
import numpy as np
import csv
import pyvista as pv


def plot_vtk(obj):
"""
export und_frc in vtk to check geometry
"""
exportGeometryToVTK(obj, 'radia_Geometry')
grid = pv.read('radia_Geometry.vtk')
grid.plot(cmap='terrain',show_scalar_bar=False,show_axes=False,show_edges=True,window_size = [1000, 580],lighting=True,component=1)
#viridis, terrain

# https://github.com/ochubar/Radia/issues/17
def chunks(lst, n):
"""Yield successive n-sized chunks from a list called 'lst'."""
for i in range(0, len(lst), n):
yield lst[i:i + n]

def exportGeometryToVTK(obj, fileName='radia_Geometry'):
'''
Writes the geometry of RADIA object "obj" to file fileName.vtk for use in Paraview. The format is VTK legacy, because it's simple. The file consists of polygons only (no cells).
'''

vtkData = rad.ObjDrwVTK(obj, 'Axes->False')

lengths = vtkData['polygons']['lengths']
nPoly = len(lengths)
offsets = list(accumulate(lengths))
offsets.insert(0, 0) # prepend list with a zero
points = vtkData['polygons']['vertices']
nPnts = int(len(points)/3)

# format the points array to be floats rather than double
points = [round(num, 8) for num in points]

# define the connectivity list
conn = list(range(nPnts))

# define colours array
colors = vtkData['polygons']['colors']

# pre-process the output lists to have chunkLength items per line
chunkLength = 9 # this writes 9 numbers per line (9 is the number used in Paraview if data is saved as the VTK Legacy format)
offsets = list(chunks(offsets, chunkLength))
points = list(chunks(points, chunkLength))
conn = list(chunks(conn, chunkLength))
colors = list(chunks(colors, chunkLength))

# write the data to file
with open(fileName + ".vtk", "w", newline="") as f:
f.write('# vtk DataFile Version 5.1\n')
f.write('vtk output\nASCII\nDATASET POLYDATA\n')
f.write('POINTS ' + str(nPnts) + ' float\n')

writer = csv.writer(f, delimiter=" ")
writer.writerows(points)
f.write('\n')
f.write('POLYGONS ' + str(nPoly+1) + ' ' + str(nPnts) + '\n')
f.write('OFFSETS vtktypeint64\n')
writer.writerows(offsets)
f.write('CONNECTIVITY vtktypeint64\n')
writer.writerows(conn)
f.write('\n')
f.write('CELL_DATA ' + str(nPoly) + '\n')
f.write('COLOR_SCALARS Radia_colours 3\n')
writer.writerows(colors)

Binary file modified ext_lib/fftw-2.1.5.tar.gz
Binary file not shown.
73 changes: 73 additions & 0 deletions ext_lib/fftw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Minimum cmake version
# Picked 3.12 as this one introduces a proper FindOpenMP
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

# Project name
project(Radia_fftw2)

cmake_policy(SET CMP0074 NEW)

# Temporary path for FFTW in case we need to build it
set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage)
message(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}")

include(ExternalProject)

if(UNIX)
# https://cmake.org/cmake/help/latest/module/ExternalProject.html
ExternalProject_Add(fftw_external
URL
http://www.fftw.org/fftw-2.1.5.tar.gz
URL_HASH
MD5=8d16a84f3ca02a785ef9eb36249ba433
CMAKE_ARGS "${CMAKE_ARGS};-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
PREFIX ${CMAKE_CURRENT_BINARY_DIR}
DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
# This cp line is important. FFTW 2 must be build inplace otherwise
# the make part will generate invalid library...
COMMAND cp -r ${CMAKE_CURRENT_BINARY_DIR}/src/fftw_external/. .
# Update config.sub and config.guess so fftw can be compiled with new target osx-arm64
# Note (2021-10-22): the git.savannah.gnu.org website is not
# accessible intermittently, so vendoring those two files:
COMMAND wget -O ${CMAKE_CURRENT_SOURCE_DIR}/config.sub https://git.savannah.gnu.org/gitweb/?p=config.git&a=blob_plain&f=config.sub&hb=HEAD
COMMAND wget -O ${CMAKE_CURRENT_SOURCE_DIR}/config.guess https://git.savannah.gnu.org/gitweb/?p=config.git&a=blob_plain&f=config.guess&hb=HEAD
COMMAND cp -v ${CMAKE_CURRENT_SOURCE_DIR}/config.sub .
COMMAND cp -v ${CMAKE_CURRENT_SOURCE_DIR}/config.guess .
COMMAND ./configure --enable-float --with-pic
COMMAND sed -i.bak -e "s/^CFLAGS = /CFLAGS = -fPIC /" Makefile
COMMAND make -j8
COMMAND mkdir -p ${STAGED_INSTALL_PREFIX}/lib
COMMAND cp fftw/.libs/libfftw.a ${STAGED_INSTALL_PREFIX}/lib
INSTALL_COMMAND ""
)

include(GNUInstallDirs)

set(
FFTW_ROOT ${STAGED_INSTALL_PREFIX}
CACHE PATH "Path to internally built FFTWConfig.cmake"
FORCE
)

set(
FFTW_DOUBLE_LIB ${STAGED_INSTALL_PREFIX}/lib/libfftw.a
CACHE PATH "Path to FFTW"
FORCE
)

set(
FFTW_FLOAT_LIB
CACHE PATH "Path to FFTWF"
FORCE
)


# Libraries
add_library(fftw STATIC IMPORTED)
set_property(TARGET fftw PROPERTY IMPORTED_LOCATION ${STAGED_INSTALL_PREFIX}/lib/libfftw.a)
endif()

add_dependencies(fftw fftw_external)

1,812 changes: 1,812 additions & 0 deletions ext_lib/fftw/config.guess

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions ext_lib/fftw/config.sub

Large diffs are not rendered by default.

Binary file added ext_lib/fftw/fftw-2.1.5.tar.gz
Binary file not shown.
Binary file modified ext_lib/libfftw.a
Binary file not shown.
255 changes: 255 additions & 0 deletions readme_mac_python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
# How to make/build the radia on python/macOS

This is a note to build radia on python/macOS. When python is updated, you can make a new shared object (so) in the following procedure. I tested radia.so with python version [2.7](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/radia.cpython-27m-darwin.so), [3.7](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/radia.cpython-37m-darwin.so), [3.8](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/radia.cpython-38-darwin.so), [3.9](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/radia.cpython-39-darwin.so), and [3.12](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/radia.cpython-312-darwin.so) but you can build it on your environment in the same way. You can also see [YouTube Video](https://youtu.be/mbbfCD5LF5c).

Note that you can try `python3 radia_example01.py` in **/env/radia_python** prior to this build. If it works, you do not have to make this proceudre. This repository is modified to build radia python on macOS. The Jupyter notebooks are also available [link](https://github.com/radiasoft/Radia-Examples), and cloud based Radia python is [here](https://www.sirepo.com/en/apps/magnets/).

- You should install the command line developer tools in the terminal (see details below).
```
xcode-select --install
```
- You may need python modules at least.
```
pip3 install numpy
pip3 install matplotlib
pip3 install setuptools
```
- You may also need [brew](https://brew.sh/) to install wget and cmake .
```
brew install wget
brew install cmake
```
- Download the Radia code in zip from this repository and unzip it.
- Open terminal and build radia.so in the radia-master directory (see details below).
```
cd ~/Downloads/radia-master/
make all
```
<!--
- Change the directory to **/cpp/py/** and run setup.py (if permission denied, add `sudo` in front of `python3`).
```
cd cpp/py
python3 setup.py install
```
- Make a copy of **/cpp/py/build/** *lib.macosx-10.9-x86_64-X.X/radia.cpython-XX-darwin.so* (names depend on your environment), and paste it in the directory **/env/radia_python/**.
```
cd build
ls
cd build/lib.macosx-12.9-x86_64-3.9/
cp radia.cpython-39-darwin.so ~/Downloads/radia-master/env/radia_python/radia.cpython-39-darwin.so
```
- Duplicate `radia.cpython-XX-darwin.so` and rename it to **radia.so** which works for Radia in python (you can overwrite or rename the original radia.so).
```
cd ~/Downloads/radia-master/env/radia_python/
cp radia.cpython-39-darwin.so radia.so
```
-->
- Test a Radia python code from an example to verify the first app run as below.
```
cd ~/Downloads/radia-master/env/radia_python/
python3 radia_example01.py
```
- The first message appears in the first radia run `"radia.cpython-XX-darwin.so" cannot be opened because the developer cannot be verified. Do you want to move to trash?`, then click `Cancel`.
- The second message may appear after the first `"radia.cpython-XX-darwin.so" cannot be opened because the developer cannot be verified. Do you want to move to trash?`, then click `Cancel`.
- Open system settings (in Apple menu) - security & privacy - security - `allow anyway` to allow opening `radia.cpython-XX-darwin.so` blocked from use because it is not from an identified developer.
- The last message appears in the second radia run `macOS cannot verify the developer of "radia.cpython-XX-darwin.so". Are you sure you want to open it?`, then click `Open`, and eventually radia runs without further verification.
- To display the geometry of objects in macOS, you need additonal modules.
```
pip3 install pyvista
pip3 install accumulate
```
- You can test the following examples.
```
python3 radia_example02.py
python3 radia_example03.py
python3 radia_example04.py
python3 radia_example05.py
python3 radia_example06.py
```

## Troubleshooting

### Error: `ImportError: not valid for use in process: library load disallowed by system policy`

Open system settings (in :apple: menu) - security & privacy - security - `allow anyway` to allow opening `radia.cpython-XX-darwin.so` blocked from use because it is not from an identified developer.

### Error: `fatal error: 'fpu_control.h' file not found`

Download the Radia from this repository and try `make all` again. In this repository, `triangle.c` file is modified as below.

Comment out in `fpu-control.h` in `triangle.c` because it is not needed in macos [link1](https://github.com/YosysHQ/yosys/issues/334), [link2](https://stackoverflow.com/questions/4271881/newbie-problem-with-gcc-4-2-compiler-mac-osx-fpu-control-h-no-such-file-or-d).

```
/* #include <fpu_control.h> */
/* _FPU_SETCW(cword); */
```

You can also download [original radia](https://github.com/ochubar/Radia) and modify `trinagle.c`.

### Error: `/bin/sh: line 0: [: /Users/.... : binary operator expected`

When you make radia, you may see this error because the folder name includes a space such as "radia test". You can use underscore "radia_test" for example, which is an issue in linux.

### Error: `xcode-select: Failed to locate 'python', requesting installation of command line developer tools.`

Install the command line developer tools in the terminal [link1](https://mac.install.guide/commandlinetools/), [likn2](https://www.intel.com/content/www/us/en/developer/articles/troubleshooting/error-ld-library-not-found-with-macos-big-sur.html).

```
xcode-select --install
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license
```

### Error: `/bin/sh: python: command not found`

In this repository, `python3` is used to build radia.so. If you want to run `python` instead of `python3`, follow the procedures below.

#### Use `python3` to setup.py install

In this repository, `Makefile` in **cpp/py** is modified for `python3`, so you can use `python3`.
```
python3 setup.py install
```

#### Create a symbolic link for `python` (but not recommended)

This is an important issue on macos, because the default python was version 2 on macos. Now, `python` does not exist on maxOS, and `python3` is a default python. However, the original Radia python is built on `python` not `python3`. We can create the symbolic link of `python3` for `python`.

Open the terminal and run below [link](https://developer.apple.com/forums/thread/704099).

```
sudo ln -s /Library/Developer/CommandLineTools/usr/bin/python3 /Library/Developer/CommandLineTools/usr/bin/python
```

You can check the version of python in terminal, and it should be `Python 3.X.X`.

```
python -V
```

If **permission denied** error appears, add `sudo` in front of `python setup.py install` or delete all folders previously created under **cpp/py/** with password.

In this method, I found an issue on the module installation in python environment such as numpy, matplotlib, etc. Even though the module can be installed in pip, radia code does not recognize these modules.


#### Virtual environment

[conda](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) or [pyenv](https://www.janmeppe.com/blog/how-to-set-python3-as-default-mac/) virtual environment might also help to configure python version 2, 3, and it derivatives. For example, `pyenv` works in both `python` and `python3` seamlessly without change in system default python environment.

```
brew install pyenv
pyenv install 3.9
```

Open your shell to run pyenv
```
nano ~/.zshrc
```
Copy and paste below into .zshrc, then `ctrl + o` for overwrite, `ctrl + x` for exit
```
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
```
Now you can check available python environment other than system python, and switch any python version.
```
pyenv versions
pyenv global 3.9
python -V
```

### Error: `error: could not create 'build/temp.macosx-10.9-x86_64-3.7': Permission denied`

Delete `build`, `dist`, `Radia_Python_Interface.egg-info ` folders in **cpp/py/**.

### Error: `ld: library not found for -lfftw`

This error is based on build error in `make fftw`. Check `make fftw` if `make all` does not work.

```
# - `make all` - will compile FFTW, C++ core and Python lib;
# - `make fftw` - will compile FFTW only;
# - `make` - will compile C++ core and Python lib;
# - `make clean` - will clean temporary files.
```

Previously I had a problem on a g77 symbolic link in **/user/local/bin/**, and solved with `rm g77`. You may check the difference from the successful terminal log as attached at the end of this report.

```
g77
-bash: /usr/local/bin/g77: Bad CPU type in executable
rm g77
```

Pre-compiled `libfftw.a` on Intel mac is added in this repository that makes `make` possible without `make all` including `make fftw`. If you use Apple silicon, you should `make all` (see details in the next paragraph for M1 mac).

```
Hidekis-Air-13:radia_python hidekinakajima$ python radia_example01.py
Traceback (most recent call last):
File "/Users/hidekinakajima/Downloads/Radia-master/env/radia_python/radia_example01.py", line 8, in <module>
import radia as rad
ImportError: dlopen(/Users/hidekinakajima/Downloads/Radia-master/env/radia_python/radia.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace (_fftw)
```

### Error: `configure: error: /bin/sh ./config.sub -apple-darwinXX.X.0 failed` or `an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')`

`make fftw` as well as `make all` might be an issue on mac with [Apple silicon](https://support.apple.com/en-us/116943) M series. To solve this issue, we have to `cmake` based on CMakeLists.txt as described in [SRW](https://github.com/ochubar/SRW) for `arm64` cpu archtecture. In this repository, `makefile` and `CMakeLists.txt` are modified in **root**, **cpp/gcc/**, and **ext_lib/fftw/** accordingly. The following files are downloaded via `wget` during the `cmake`, so your PC should be online.

```
http://www.fftw.org/fftw-2.1.5.tar.gz
https://git.savannah.gnu.org/gitweb/?p=config.git&a=blob_plain&f=config.sub
https://git.savannah.gnu.org/gitweb/?p=config.git&a=blob_plain&f=config.guess
```
<!--
I have no test on Apple silicon, but some suggestion is found in [link](https://stackoverflow.com/questions/73030706/how-to-install-fftw-2-1-5-on-an-m1-macbook-pro) or find the other solution from [SRW](https://github.com/ochubar/SRW).
-->

### Error: `ModuleNotFoundError: No module named 'numpy' or 'matplotlib', 'setuptools'`

Install [pip](https://pip.pypa.io/en/stable/installation/), and run the following commands.

```
pip3 install numpy
pip3 install matplotlib
pip3 install setuptools
```

### Error: `/bash/sh:'wget' or 'cmake': command not found`

Install [Homebrew](https://brew.sh/), and run the following commands.

```
brew install wget
brew install cmake
```

### Error: `RuntimeError: This function is not implemented on that platform.`

Radia in macos does not support `rad.ObjDrwOpenGL` for 3D viewer of the geometry. Instead, we can save and plot vtk file by using [pyvista](https://pyvista.org/) or [paraview](https://www.paraview.org/). `radia_vtk.py` in this repository coded by [quorx](https://github.com/ochubar/Radia/issues/17) is added.

```
import radia_vtk as rad_vtk
rad_vtk.plot_vtk(g)
```
`g` is an object file and changed to name of your object. `radia_geometry.vtk` is a name of vtk file exported. For pyvista, you need additional modules.
```
pip3 install pyvista
pip3 install accumulate
```

### Error: `macOS 12 (1207) or later required, have instead 12 (1206) !`

Python 3.10 and 3.11 have an issue on Tcl/Tk that makes plot on X11 [link](https://www.python.org/download/mac/tcltk/). Python 3.9 is still safe to open plots in X11.

## Build log files

[log_radia_build_py312_macos_make_all.sh](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/log_radia_build_py312_macos_make_all.sh)

[log_radia_build_py39_macos_make_all.sh](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/log_radia_build_py39_macos_make_all.sh)

[log_radia_build_py39_macos_make_fftw.sh](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/log_radia_build_py39_macos_make_fftw.sh)

[log_radia_build_py27_macos_make_all.sh](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/log_radia_build_py27_macos_make_all.sh)

[log_radia_build_py27_macos_make_fftw.sh](https://github.com/hidecode221b/Radia/blob/master/env/radia_python/log_radia_build_py27_macos_make_fftw.sh)