Skip to content

Commit

Permalink
Various bug fixes + allow non-fortran builds
Browse files Browse the repository at this point in the history
Found a couple bugs in the current dev branch of ExaConstit
Also turned off the Fortran build requirements as its a pain to get working on most macs...
  • Loading branch information
rcarson3 committed Jul 8, 2024
1 parent 49d4045 commit 2d49b6f
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

################################
Expand Down
2 changes: 1 addition & 1 deletion scripts/meshing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 11 additions & 14 deletions scripts/meshing/mesh_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ,
Expand Down Expand Up @@ -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);

}

Expand All @@ -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;

}
Expand Down
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#------------------------------------------------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions src/umat_tests/umat.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>

#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;
}
}
}
21 changes: 15 additions & 6 deletions workflows/Stage3/pre_main_post_script/voxel_coarsen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ 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]
name = "voxel_coarsen"
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = 3
codegen-units = 1
lto = true
lto = true

[profile.test]
opt-level = 3
debug = false
lto = true
incremental = false
codegen-units = 1
4 changes: 2 additions & 2 deletions workflows/Stage3/pre_main_post_script/voxel_coarsen/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,25 @@ use std::cmp::Ordering;
use std::convert::TryFrom;

#[cfg(not(feature = "polars"))]
fn read_data(f: &str) -> Result<reader::ReaderResults<i32>, Error> {
fn read_data(f: &str) -> Result<Box<dyn reader::ReaderResults<i32>>, 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,
row_format: false,
..Default::default()
};

reader::load_txt_i32(f, &params)
}

#[cfg(feature = "polars")]
fn read_data(f: &str) -> Result<reader::ReaderResults<i32>, 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, &params);
fn read_data(f: &str) -> PolarsResult<DataFrame> {
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]) {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<i32>)> {
) -> anyhow::Result<((usize, usize, usize), Bound<'py, PyArray1<i32>>)> {
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(())
Expand Down

0 comments on commit 2d49b6f

Please sign in to comment.