diff --git a/CMakeLists.txt b/CMakeLists.txt index ab3237e..a905337 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ include(${BLT_SOURCE_DIR}/SetupBLT.cmake) # set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries") if(ENABLE_CUDA) - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -restrict -arch ${CUDA_ARCH} --expt-extended-lambda --expt-relaxed-constexpr") + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -restrict --extended-lambda --expt-relaxed-constexpr") endif() ################################ diff --git a/scripts/meshing/CMakeLists.txt b/scripts/meshing/CMakeLists.txt index 7f3ddb2..fd5ff26 100644 --- a/scripts/meshing/CMakeLists.txt +++ b/scripts/meshing/CMakeLists.txt @@ -11,7 +11,7 @@ if(ENABLE_OPENMP) endif() if(ENABLE_CUDA) - list(APPEND MESHING_DEPENDS cuda) + list(APPEND MESHING_DEPENDS cuda CUDA::cublas CUDA::cusparse) endif() if(ENABLE_HIP) diff --git a/scripts/meshing/mesh_generator.cpp b/scripts/meshing/mesh_generator.cpp index 65d42f2..52ab16d 100644 --- a/scripts/meshing/mesh_generator.cpp +++ b/scripts/meshing/mesh_generator.cpp @@ -50,7 +50,6 @@ int main(int argc, char *argv[]) lenx = leny = lenz = 1.0; int order; - Mesh *mesh = nullptr; OptionsParser args(argc, argv); // All the arguments to automatically generate a mesh args.AddOption(&auto_mesh, "-auto_mesh", "--automatic-mesh-generator" , @@ -93,30 +92,30 @@ int main(int argc, char *argv[]) Vector g_map; - *mesh = mfem::Mesh::MakeCartesian3D(nx, ny, nz, Element::HEXAHEDRON, lenx, leny, lenz, false); + auto mesh = mfem::Mesh::MakeCartesian3D(nx, ny, nz, Element::HEXAHEDRON, lenx, leny, lenz, false); ifstream igmap(grain_file); if (!igmap) { cerr << "\nCannot open grain map file: " << grain_file << '\n' << endl; } - int gmapSize = mesh->GetNE(); + int gmapSize = mesh.GetNE(); g_map.Load(igmap, gmapSize); igmap.close(); // reset boundary conditions from - setBdrConditions(mesh); + setBdrConditions(&mesh); // set grain ids as element attributes on the mesh // The offset of where the grain index is located is // location - 1. - setElementGrainIDs(mesh, g_map, 1, 0); + setElementGrainIDs(&mesh, g_map, 1, 0); - mesh->SetCurvature(order); + mesh.SetCurvature(order); ofstream omesh(output_file); omesh.precision(14); - mesh->Print(omesh); + mesh.Print(omesh); } @@ -126,26 +125,24 @@ int main(int argc, char *argv[]) cerr << "\nCan not open mesh file: " << vtk_file << endl; return 2; } - mesh = new Mesh(imesh, 1, 1, true); + auto mesh = Mesh(imesh, 1, 1, true); imesh.close(); - const FiniteElementSpace *nodal_fes = mesh->GetNodalFESpace(); + const FiniteElementSpace *nodal_fes = mesh.GetNodalFESpace(); if (nodal_fes != NULL) { if(order > nodal_fes->GetOrder(0)) { printf("Increasing order of the FE Space to %d\n", order); - mesh->SetCurvature(order); + mesh.SetCurvature(order); } } - vtkFixBdrElements(mesh); + vtkFixBdrElements(&mesh); ofstream omesh(output_file); omesh.precision(14); - mesh->Print(omesh); + mesh.Print(omesh); } - delete mesh; - return 0; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c586bb1..e2217a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,9 +35,15 @@ set(EXACONSTIT_SOURCES system_driver.cpp option_parser.cpp ./umat_tests/userumat.cxx - ./umat_tests/umat.f ) +if (ENABLE_FORTRAN) + list(APPEND EXACONSTIT_SOURCES ./umat_tests/umat.f) +else() + list(APPEND EXACONSTIT_SOURCES ./umat_tests/umat.cxx) +endif() + + #------------------------------------------------------------------------------ # Dependencies #------------------------------------------------------------------------------ diff --git a/src/umat_tests/umat.cxx b/src/umat_tests/umat.cxx new file mode 100644 index 0000000..36fc688 --- /dev/null +++ b/src/umat_tests/umat.cxx @@ -0,0 +1,45 @@ +#include +#include +#include + +#include +#include +#include +#include + +#define real8 double + +#ifdef WIN32 +#define UMAT_API __declspec(dllexport) +#elif defined(__clang__) +#define UMAT_API extern "C" +#define UMAT umat +#else +#define UMAT_API extern "C" +#define UMAT umat_ +#endif + +UMAT_API +void UMAT(real8 *stress, real8 *statev, real8 *ddsdde, + real8 *sse, real8 *spd, real8 *scd, real8 *rpl, + real8 *ddsdt, real8 *drplde, real8 *drpldt, + real8 *stran, real8 *dstran, real8 *time, + real8 *deltaTime, real8 *tempk, real8 *dtemp, real8 *predef, + real8 *dpred, real8 *cmname, int *ndi, int *nshr, int *ntens, + int *nstatv, real8 *props, int *nprops, real8 *coords, + real8 *drot, real8 *pnewdt, real8 *celent, + real8 *dfgrd0, real8 *dfgrd1, int *noel, int *npt, + int *layer, int *kspt, int *kstep, int *kinc) +{ + sse[0] += 1.0; + spd[0] += 1.0; + scd[0] += 1.0; + rpl[0] += 1.0; + drpldt[0] += 1.0; + for (int i = 0; i < ntens[0]; i++){ + drplde[i] += 1.0; + for (int j = 0; j < ntens[0]; j++) { + ddsdde[j * ntens[0] + i] += 1; + } + } +} diff --git a/workflows/Stage3/pre_main_post_script/voxel_coarsen/Cargo.toml b/workflows/Stage3/pre_main_post_script/voxel_coarsen/Cargo.toml index 71efa52..679f01a 100644 --- a/workflows/Stage3/pre_main_post_script/voxel_coarsen/Cargo.toml +++ b/workflows/Stage3/pre_main_post_script/voxel_coarsen/Cargo.toml @@ -6,14 +6,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -data_reader = {git="https://github.com/rcarson3/rust_data_reader.git", features=["mmap"]} -anyhow = "1.0" +data_reader = {git="https://github.com/rcarson3/rust_data_reader.git"} +anyhow = {version="1.0"} rand = {version = "0.8"} -polars = {version = "0.24.3", optional=true} -numpy = "0.17" -pyo3 = { version = "0.17", features = ["abi3-py37", "extension-module", "multiple-pymethods", "anyhow"] } +polars = {version = "0.30.0", optional=true, features = ["csv"]} +numpy = {version = "0.21", optional=true} +pyo3 = { version = "0.21", optional=true, features = ["abi3-py37", "extension-module", "multiple-pymethods", "anyhow"] } [features] +python = ["numpy", "pyo3"] polar = ["polars"] [lib] @@ -21,5 +22,13 @@ name = "voxel_coarsen" crate-type = ["cdylib", "rlib"] [profile.release] +opt-level = 3 codegen-units = 1 -lto = true \ No newline at end of file +lto = true + +[profile.test] +opt-level = 3 +debug = false +lto = true +incremental = false +codegen-units = 1 \ No newline at end of file diff --git a/workflows/Stage3/pre_main_post_script/voxel_coarsen/setup.py b/workflows/Stage3/pre_main_post_script/voxel_coarsen/setup.py index f81edf5..d1a3e5f 100644 --- a/workflows/Stage3/pre_main_post_script/voxel_coarsen/setup.py +++ b/workflows/Stage3/pre_main_post_script/voxel_coarsen/setup.py @@ -4,8 +4,8 @@ setup( name="rust_voxel_coarsen", version="0.1", - rust_extensions=[RustExtension("rust_voxel_coarsen.rust_voxel_coarsen", binding=Binding.PyO3, debug=False,)], + rust_extensions=[RustExtension("rust_voxel_coarsen.rust_voxel_coarsen", binding=Binding.PyO3, debug=False,features=["python"])], packages=["rust_voxel_coarsen"], # rust extensions are not zip safe, just like C-extensions. zip_safe=False, -) \ No newline at end of file +) diff --git a/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/coarsen/mod.rs b/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/coarsen/mod.rs index 93be750..a479515 100644 --- a/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/coarsen/mod.rs +++ b/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/coarsen/mod.rs @@ -10,7 +10,7 @@ use std::cmp::Ordering; use std::convert::TryFrom; #[cfg(not(feature = "polars"))] -fn read_data(f: &str) -> Result, Error> { +fn read_data(f: &str) -> Result>, Error> { let params = reader::ReaderParams { comments: Some(b'%'), delimiter: reader::Delimiter::Any(b','), @@ -18,23 +18,17 @@ fn read_data(f: &str) -> Result, Error> { skip_footer: None, usecols: None, max_rows: None, + row_format: false, + ..Default::default() }; reader::load_txt_i32(f, ¶ms) } #[cfg(feature = "polars")] -fn read_data(f: &str) -> Result, Error> { - let params = reader::ReaderParams { - comments: Some(b'%'), - delimiter: reader::Delimiter::Any(b','), - skip_header: Some(2), - skip_footer: None, - usecols: None, - max_rows: None, - }; - - reader::load_txt_i32(f, ¶ms); +fn read_data(f: &str) -> PolarsResult { + CsvReader::from_path(f)?.has_header(false).with_skip_rows(2) + .with_delimiter(b'%').with_comment_char(Some(b',')).finish() } fn sort_data(chunk_size: usize, data: &mut [i32]) { @@ -124,13 +118,10 @@ pub fn voxel_coarsen(file: &str, coarsen_size: usize) -> Result<((usize, usize, let read_results = read_data(file)?; // Find the box size of things - let cols = vec![0, 1, 2, 3]; - let col_results = read_results.get_cols(cols); - let box_size = { - let x = &col_results[0]; - let y = &col_results[1]; - let z = &col_results[2]; + let x = read_results.get_inner_lanes(0); + let y = read_results.get_inner_lanes(1); + let z = read_results.get_inner_lanes(2); let mut min = (0, 0, 0); let mut max = (0, 0, 0); min.0 = *x.iter().min().unwrap(); @@ -157,9 +148,10 @@ pub fn voxel_coarsen(file: &str, coarsen_size: usize) -> Result<((usize, usize, )); } - let mut data = col_results[3].clone(); + let mut data = read_results.get_col(3); + let col_result = read_results.get_inner_lanes(3); + rearrange_data(col_result, &box_size, coarsen_size, &mut data); - rearrange_data(&col_results[3], &box_size, coarsen_size, &mut data); sort_data(coarsen_size, &mut data); let block_size = coarsen_size.pow(3); diff --git a/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/pycoarsen/mod.rs b/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/pycoarsen/mod.rs index cf7fca1..1cb286d 100644 --- a/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/pycoarsen/mod.rs +++ b/workflows/Stage3/pre_main_post_script/voxel_coarsen/src/pycoarsen/mod.rs @@ -1,19 +1,19 @@ use numpy::PyArray1; -use pyo3::{pymodule, types::PyModule, PyResult, Python}; +use pyo3::{pymodule, Bound, types::PyModule, PyResult, Python}; use crate::coarsen::voxel_coarsen; #[pymodule] -fn rust_voxel_coarsen(_py: Python<'_>, m: &PyModule) -> PyResult<()> { +fn rust_voxel_coarsen(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { #[pyfn(m)] #[pyo3(name = "voxel_coarsen")] fn voxel_coarsen_py<'py>( py: Python<'py>, file: &str, coarsen_size: usize, - ) -> anyhow::Result<((usize, usize, usize), &'py PyArray1)> { + ) -> anyhow::Result<((usize, usize, usize), Bound<'py, PyArray1>)> { let result = voxel_coarsen(file, coarsen_size)?; - Ok((result.0, PyArray1::from_vec(py, result.1))) + Ok((result.0, PyArray1::from_vec_bound(py, result.1))) } Ok(())