| qfunction.rs (e03682af89f4c0f5e8c281990d44146e81dbdd46) | qfunction.rs (1142270cb02df4484c0ba89e11097db6aa2d5cef) |
|---|---|
| 1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3// reserved. See files LICENSE and NOTICE for details. 4// 5// This file is part of CEED, a collection of benchmarks, miniapps, software 6// libraries and APIs for efficient high-order finite element and spectral 7// element discretizations for exascale applications. For more information and 8// source code availability see http://github.com/ceed. --- 224 unchanged lines hidden (view full) --- 233 } 234} 235 236// ----------------------------------------------------------------------------- 237// CeedQFunction context wrapper 238// ----------------------------------------------------------------------------- 239#[derive(Debug)] 240pub(crate) struct QFunctionCore<'a> { | 1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3// reserved. See files LICENSE and NOTICE for details. 4// 5// This file is part of CEED, a collection of benchmarks, miniapps, software 6// libraries and APIs for efficient high-order finite element and spectral 7// element discretizations for exascale applications. For more information and 8// source code availability see http://github.com/ceed. --- 224 unchanged lines hidden (view full) --- 233 } 234} 235 236// ----------------------------------------------------------------------------- 237// CeedQFunction context wrapper 238// ----------------------------------------------------------------------------- 239#[derive(Debug)] 240pub(crate) struct QFunctionCore<'a> { |
| 241 ceed: &'a crate::Ceed, | |
| 242 ptr: bind_ceed::CeedQFunction, | 241 ptr: bind_ceed::CeedQFunction, |
| 242 _lifeline: PhantomData<&'a ()>, |
|
| 243} 244 245struct QFunctionTrampolineData { 246 number_inputs: usize, 247 number_outputs: usize, 248 input_sizes: [usize; MAX_QFUNCTION_FIELDS], 249 output_sizes: [usize; MAX_QFUNCTION_FIELDS], 250 user_f: Box<QFunctionUserClosure>, --- 95 unchanged lines hidden (view full) --- 346 self.qf_core.fmt(f) 347 } 348} 349 350// ----------------------------------------------------------------------------- 351// Core functionality 352// ----------------------------------------------------------------------------- 353impl<'a> QFunctionCore<'a> { | 243} 244 245struct QFunctionTrampolineData { 246 number_inputs: usize, 247 number_outputs: usize, 248 input_sizes: [usize; MAX_QFUNCTION_FIELDS], 249 output_sizes: [usize; MAX_QFUNCTION_FIELDS], 250 user_f: Box<QFunctionUserClosure>, --- 95 unchanged lines hidden (view full) --- 346 self.qf_core.fmt(f) 347 } 348} 349 350// ----------------------------------------------------------------------------- 351// Core functionality 352// ----------------------------------------------------------------------------- 353impl<'a> QFunctionCore<'a> { |
| 354 // Error handling 355 #[doc(hidden)] 356 fn check_error(&self, ierr: i32) -> crate::Result<i32> { 357 let mut ptr = std::ptr::null_mut(); 358 unsafe { 359 bind_ceed::CeedQFunctionGetCeed(self.ptr, &mut ptr); 360 } 361 crate::check_error(ptr, ierr) 362 } 363 |
|
| 354 // Common implementation 355 pub fn apply(&self, Q: usize, u: &[Vector], v: &[Vector]) -> crate::Result<i32> { 356 let mut u_c = [std::ptr::null_mut(); MAX_QFUNCTION_FIELDS]; 357 for i in 0..std::cmp::min(MAX_QFUNCTION_FIELDS, u.len()) { 358 u_c[i] = u[i].ptr; 359 } 360 let mut v_c = [std::ptr::null_mut(); MAX_QFUNCTION_FIELDS]; 361 for i in 0..std::cmp::min(MAX_QFUNCTION_FIELDS, v.len()) { 362 v_c[i] = v[i].ptr; 363 } 364 let Q = i32::try_from(Q).unwrap(); 365 let ierr = unsafe { 366 bind_ceed::CeedQFunctionApply(self.ptr, Q, u_c.as_mut_ptr(), v_c.as_mut_ptr()) 367 }; | 364 // Common implementation 365 pub fn apply(&self, Q: usize, u: &[Vector], v: &[Vector]) -> crate::Result<i32> { 366 let mut u_c = [std::ptr::null_mut(); MAX_QFUNCTION_FIELDS]; 367 for i in 0..std::cmp::min(MAX_QFUNCTION_FIELDS, u.len()) { 368 u_c[i] = u[i].ptr; 369 } 370 let mut v_c = [std::ptr::null_mut(); MAX_QFUNCTION_FIELDS]; 371 for i in 0..std::cmp::min(MAX_QFUNCTION_FIELDS, v.len()) { 372 v_c[i] = v[i].ptr; 373 } 374 let Q = i32::try_from(Q).unwrap(); 375 let ierr = unsafe { 376 bind_ceed::CeedQFunctionApply(self.ptr, Q, u_c.as_mut_ptr(), v_c.as_mut_ptr()) 377 }; |
| 368 self.ceed.check_error(ierr) | 378 self.check_error(ierr) |
| 369 } 370} 371 372// ----------------------------------------------------------------------------- 373// User QFunction Closure 374// ----------------------------------------------------------------------------- 375pub type QFunctionUserClosure = dyn FnMut( 376 [&[crate::Scalar]; MAX_QFUNCTION_FIELDS], --- 101 unchanged lines hidden (view full) --- 478 std::mem::size_of::<QFunctionTrampolineData>() as u64, 479 std::mem::transmute(trampoline_data.as_ref()), 480 ) 481 }; 482 ceed.check_error(ierr)?; 483 ierr = unsafe { bind_ceed::CeedQFunctionSetContext(ptr, qf_ctx_ptr) }; 484 ceed.check_error(ierr)?; 485 Ok(Self { | 379 } 380} 381 382// ----------------------------------------------------------------------------- 383// User QFunction Closure 384// ----------------------------------------------------------------------------- 385pub type QFunctionUserClosure = dyn FnMut( 386 [&[crate::Scalar]; MAX_QFUNCTION_FIELDS], --- 101 unchanged lines hidden (view full) --- 488 std::mem::size_of::<QFunctionTrampolineData>() as u64, 489 std::mem::transmute(trampoline_data.as_ref()), 490 ) 491 }; 492 ceed.check_error(ierr)?; 493 ierr = unsafe { bind_ceed::CeedQFunctionSetContext(ptr, qf_ctx_ptr) }; 494 ceed.check_error(ierr)?; 495 Ok(Self { |
| 486 qf_core: QFunctionCore { ceed, ptr }, | 496 qf_core: QFunctionCore { 497 ptr, 498 _lifeline: PhantomData, 499 }, |
| 487 qf_ctx_ptr, 488 trampoline_data, 489 }) 490 } 491 492 /// Apply the action of a QFunction 493 /// 494 /// * `Q` - The number of quadrature points --- 101 unchanged lines hidden (view full) --- 596 self.trampoline_data.number_inputs += 1; 597 let (size, emode) = ( 598 i32::try_from(size).unwrap(), 599 emode as bind_ceed::CeedEvalMode, 600 ); 601 let ierr = unsafe { 602 bind_ceed::CeedQFunctionAddInput(self.qf_core.ptr, name_c.as_ptr(), size, emode) 603 }; | 500 qf_ctx_ptr, 501 trampoline_data, 502 }) 503 } 504 505 /// Apply the action of a QFunction 506 /// 507 /// * `Q` - The number of quadrature points --- 101 unchanged lines hidden (view full) --- 609 self.trampoline_data.number_inputs += 1; 610 let (size, emode) = ( 611 i32::try_from(size).unwrap(), 612 emode as bind_ceed::CeedEvalMode, 613 ); 614 let ierr = unsafe { 615 bind_ceed::CeedQFunctionAddInput(self.qf_core.ptr, name_c.as_ptr(), size, emode) 616 }; |
| 604 self.qf_core.ceed.check_error(ierr)?; | 617 self.qf_core.check_error(ierr)?; |
| 605 Ok(self) 606 } 607 608 /// Add a QFunction output 609 /// 610 /// * `fieldname` - Name of QFunction field 611 /// * `size` - Size of QFunction field, `(ncomp * dim)` for `Grad` or 612 /// `(ncomp * 1)` for `None` and `Interp` --- 33 unchanged lines hidden (view full) --- 646 self.trampoline_data.number_outputs += 1; 647 let (size, emode) = ( 648 i32::try_from(size).unwrap(), 649 emode as bind_ceed::CeedEvalMode, 650 ); 651 let ierr = unsafe { 652 bind_ceed::CeedQFunctionAddOutput(self.qf_core.ptr, name_c.as_ptr(), size, emode) 653 }; | 618 Ok(self) 619 } 620 621 /// Add a QFunction output 622 /// 623 /// * `fieldname` - Name of QFunction field 624 /// * `size` - Size of QFunction field, `(ncomp * dim)` for `Grad` or 625 /// `(ncomp * 1)` for `None` and `Interp` --- 33 unchanged lines hidden (view full) --- 659 self.trampoline_data.number_outputs += 1; 660 let (size, emode) = ( 661 i32::try_from(size).unwrap(), 662 emode as bind_ceed::CeedEvalMode, 663 ); 664 let ierr = unsafe { 665 bind_ceed::CeedQFunctionAddOutput(self.qf_core.ptr, name_c.as_ptr(), size, emode) 666 }; |
| 654 self.qf_core.ceed.check_error(ierr)?; | 667 self.qf_core.check_error(ierr)?; |
| 655 Ok(self) 656 } 657} 658 659// ----------------------------------------------------------------------------- 660// QFunction 661// ----------------------------------------------------------------------------- 662impl<'a> QFunctionByName<'a> { 663 // Constructor 664 pub fn create(ceed: &'a crate::Ceed, name: &str) -> crate::Result<Self> { 665 let name_c = CString::new(name).expect("CString::new failed"); 666 let mut ptr = std::ptr::null_mut(); 667 let ierr = unsafe { 668 bind_ceed::CeedQFunctionCreateInteriorByName(ceed.ptr, name_c.as_ptr(), &mut ptr) 669 }; 670 ceed.check_error(ierr)?; 671 Ok(Self { | 668 Ok(self) 669 } 670} 671 672// ----------------------------------------------------------------------------- 673// QFunction 674// ----------------------------------------------------------------------------- 675impl<'a> QFunctionByName<'a> { 676 // Constructor 677 pub fn create(ceed: &'a crate::Ceed, name: &str) -> crate::Result<Self> { 678 let name_c = CString::new(name).expect("CString::new failed"); 679 let mut ptr = std::ptr::null_mut(); 680 let ierr = unsafe { 681 bind_ceed::CeedQFunctionCreateInteriorByName(ceed.ptr, name_c.as_ptr(), &mut ptr) 682 }; 683 ceed.check_error(ierr)?; 684 Ok(Self { |
| 672 qf_core: QFunctionCore { ceed, ptr }, | 685 qf_core: QFunctionCore { 686 ptr, 687 _lifeline: PhantomData, 688 }, |
| 673 }) 674 } 675 676 /// Apply the action of a QFunction 677 /// 678 /// * `Q` - The number of quadrature points 679 /// * `input` - Array of input Vectors 680 /// * `output` - Array of output Vectors --- 62 unchanged lines hidden --- | 689 }) 690 } 691 692 /// Apply the action of a QFunction 693 /// 694 /// * `Q` - The number of quadrature points 695 /// * `input` - Array of input Vectors 696 /// * `output` - Array of output Vectors --- 62 unchanged lines hidden --- |