Struct libceed::operator::CompositeOperator[][src]

pub struct CompositeOperator<'a> { /* fields omitted */ }

Implementations

impl<'a> CompositeOperator<'a>[src]

pub fn create(ceed: &'a Ceed) -> Result<Self, CeedError>[src]

pub fn apply(
    &self,
    input: &Vector<'_>,
    output: &mut Vector<'_>
) -> Result<i32, CeedError>
[src]

Apply Operator to a vector

  • input - Input Vector
  • output - Output Vector
let ne = 4;
let p = 3;
let q = 4;
let ndofs = p * ne - ne + 1;

// Vectors
let x = ceed.vector_from_slice(&[-1., -0.5, 0.0, 0.5, 1.0]).unwrap();
let mut qdata_mass = ceed.vector(ne * q).unwrap();
qdata_mass.set_value(0.0);
let mut qdata_diff = ceed.vector(ne * q).unwrap();
qdata_diff.set_value(0.0);
let mut u = ceed.vector(ndofs).unwrap();
u.set_value(1.0);
let mut v = ceed.vector(ndofs).unwrap();
v.set_value(0.0);

// Restrictions
let mut indx: Vec<i32> = vec![0; 2 * ne];
for i in 0..ne {
    indx[2 * i + 0] = i as i32;
    indx[2 * i + 1] = (i + 1) as i32;
}
let rx = ceed
    .elem_restriction(ne, 2, 1, 1, ne + 1, MemType::Host, &indx)
    .unwrap();
let mut indu: Vec<i32> = vec![0; p * ne];
for i in 0..ne {
    indu[p * i + 0] = i as i32;
    indu[p * i + 1] = (i + 1) as i32;
    indu[p * i + 2] = (i + 2) as i32;
}
let ru = ceed
    .elem_restriction(ne, 3, 1, 1, ndofs, MemType::Host, &indu)
    .unwrap();
let strides: [i32; 3] = [1, q as i32, q as i32];
let rq = ceed
    .strided_elem_restriction(ne, q, 1, q * ne, strides)
    .unwrap();

// Bases
let bx = ceed
    .basis_tensor_H1_Lagrange(1, 1, 2, q, QuadMode::Gauss)
    .unwrap();
let bu = ceed
    .basis_tensor_H1_Lagrange(1, 1, p, q, QuadMode::Gauss)
    .unwrap();

// Build quadrature data
let qf_build_mass = ceed.q_function_interior_by_name("Mass1DBuild").unwrap();
ceed.operator(&qf_build_mass, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("dx", &rx, &bx, VectorOpt::Active)
    .unwrap()
    .field("weights", ElemRestrictionOpt::None, &bx, VectorOpt::None)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, VectorOpt::Active)
    .unwrap()
    .apply(&x, &mut qdata_mass)
    .unwrap();

let qf_build_diff = ceed.q_function_interior_by_name("Poisson1DBuild").unwrap();
ceed.operator(&qf_build_diff, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("dx", &rx, &bx, VectorOpt::Active)
    .unwrap()
    .field("weights", ElemRestrictionOpt::None, &bx, VectorOpt::None)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, VectorOpt::Active)
    .unwrap()
    .apply(&x, &mut qdata_diff)
    .unwrap();

// Application operator
let qf_mass = ceed.q_function_interior_by_name("MassApply").unwrap();
let op_mass = ceed
    .operator(&qf_mass, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("u", &ru, &bu, VectorOpt::Active)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, &qdata_mass)
    .unwrap()
    .field("v", &ru, &bu, VectorOpt::Active)
    .unwrap();

let qf_diff = ceed.q_function_interior_by_name("Poisson1DApply").unwrap();
let op_diff = ceed
    .operator(&qf_diff, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("du", &ru, &bu, VectorOpt::Active)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, &qdata_diff)
    .unwrap()
    .field("dv", &ru, &bu, VectorOpt::Active)
    .unwrap();

let op_composite = ceed
    .composite_operator()
    .unwrap()
    .sub_operator(&op_mass)
    .unwrap()
    .sub_operator(&op_diff)
    .unwrap();

v.set_value(0.0);
op_composite.apply(&u, &mut v).unwrap();

// Check
let sum: f64 = v.view().iter().sum();
assert!(
    (sum - 2.0).abs() < 1e-15,
    "Incorrect interval length computed"
);

pub fn apply_add(
    &self,
    input: &Vector<'_>,
    output: &mut Vector<'_>
) -> Result<i32, CeedError>
[src]

Apply Operator to a vector and add result to output vector

  • input - Input Vector
  • output - Output Vector
let ne = 4;
let p = 3;
let q = 4;
let ndofs = p * ne - ne + 1;

// Vectors
let x = ceed.vector_from_slice(&[-1., -0.5, 0.0, 0.5, 1.0]).unwrap();
let mut qdata_mass = ceed.vector(ne * q).unwrap();
qdata_mass.set_value(0.0);
let mut qdata_diff = ceed.vector(ne * q).unwrap();
qdata_diff.set_value(0.0);
let mut u = ceed.vector(ndofs).unwrap();
u.set_value(1.0);
let mut v = ceed.vector(ndofs).unwrap();
v.set_value(0.0);

// Restrictions
let mut indx: Vec<i32> = vec![0; 2 * ne];
for i in 0..ne {
    indx[2 * i + 0] = i as i32;
    indx[2 * i + 1] = (i + 1) as i32;
}
let rx = ceed
    .elem_restriction(ne, 2, 1, 1, ne + 1, MemType::Host, &indx)
    .unwrap();
let mut indu: Vec<i32> = vec![0; p * ne];
for i in 0..ne {
    indu[p * i + 0] = i as i32;
    indu[p * i + 1] = (i + 1) as i32;
    indu[p * i + 2] = (i + 2) as i32;
}
let ru = ceed
    .elem_restriction(ne, 3, 1, 1, ndofs, MemType::Host, &indu)
    .unwrap();
let strides: [i32; 3] = [1, q as i32, q as i32];
let rq = ceed
    .strided_elem_restriction(ne, q, 1, q * ne, strides)
    .unwrap();

// Bases
let bx = ceed
    .basis_tensor_H1_Lagrange(1, 1, 2, q, QuadMode::Gauss)
    .unwrap();
let bu = ceed
    .basis_tensor_H1_Lagrange(1, 1, p, q, QuadMode::Gauss)
    .unwrap();

// Build quadrature data
let qf_build_mass = ceed.q_function_interior_by_name("Mass1DBuild").unwrap();
ceed.operator(&qf_build_mass, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("dx", &rx, &bx, VectorOpt::Active)
    .unwrap()
    .field("weights", ElemRestrictionOpt::None, &bx, VectorOpt::None)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, VectorOpt::Active)
    .unwrap()
    .apply(&x, &mut qdata_mass)
    .unwrap();

let qf_build_diff = ceed.q_function_interior_by_name("Poisson1DBuild").unwrap();
ceed.operator(&qf_build_diff, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("dx", &rx, &bx, VectorOpt::Active)
    .unwrap()
    .field("weights", ElemRestrictionOpt::None, &bx, VectorOpt::None)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, VectorOpt::Active)
    .unwrap()
    .apply(&x, &mut qdata_diff)
    .unwrap();

// Application operator
let qf_mass = ceed.q_function_interior_by_name("MassApply").unwrap();
let op_mass = ceed
    .operator(&qf_mass, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("u", &ru, &bu, VectorOpt::Active)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, &qdata_mass)
    .unwrap()
    .field("v", &ru, &bu, VectorOpt::Active)
    .unwrap();

let qf_diff = ceed.q_function_interior_by_name("Poisson1DApply").unwrap();
let op_diff = ceed
    .operator(&qf_diff, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("du", &ru, &bu, VectorOpt::Active)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, &qdata_diff)
    .unwrap()
    .field("dv", &ru, &bu, VectorOpt::Active)
    .unwrap();

let op_composite = ceed
    .composite_operator()
    .unwrap()
    .sub_operator(&op_mass)
    .unwrap()
    .sub_operator(&op_diff)
    .unwrap();

v.set_value(1.0);
op_composite.apply_add(&u, &mut v).unwrap();

// Check
let sum: f64 = v.view().iter().sum();
assert!(
    (sum - (2.0 + ndofs as f64)).abs() < 1e-15,
    "Incorrect interval length computed"
);

pub fn sub_operator(self, subop: &Operator<'_>) -> Result<Self, CeedError>[src]

Add a sub-Operator to a Composite Operator

  • subop - Sub-Operator
let mut op = ceed.composite_operator().unwrap();

let qf_mass = ceed.q_function_interior_by_name("MassApply").unwrap();
let op_mass = ceed
    .operator(&qf_mass, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap();
op = op.sub_operator(&op_mass).unwrap();

let qf_diff = ceed.q_function_interior_by_name("Poisson1DApply").unwrap();
let op_diff = ceed
    .operator(&qf_diff, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap();
op = op.sub_operator(&op_diff).unwrap();

pub fn linear_asssemble_diagonal(
    &self,
    assembled: &mut Vector<'_>
) -> Result<i32, CeedError>
[src]

Assemble the diagonal of a square linear Operator

This overwrites a Vector with the diagonal of a linear Operator.

Note: Currently only non-composite Operators with a single field and composite Operators with single field sub-operators are supported.

  • op - Operator to assemble QFunction
  • assembled - Vector to store assembled Operator diagonal

pub fn linear_assemble_add_diagonal(
    &self,
    assembled: &mut Vector<'_>
) -> Result<i32, CeedError>
[src]

Assemble the point block diagonal of a square linear Operator

This overwrites a Vector with the point block diagonal of a linear Operator.

Note: Currently only non-composite Operators with a single field and composite Operators with single field sub-operators are supported.

  • op - Operator to assemble QFunction
  • assembled - Vector to store assembled Operator diagonal

pub fn linear_assemble_point_block_diagonal(
    &self,
    assembled: &mut Vector<'_>
) -> Result<i32, CeedError>
[src]

Assemble the diagonal of a square linear Operator

This overwrites a Vector with the diagonal of a linear Operator.

Note: Currently only non-composite Operators with a single field and composite Operators with single field sub-operators are supported.

  • op - Operator to assemble QFunction
  • assembled - Vector to store assembled CeedOperator point block diagonal, provided in row-major form with an ncomp * ncomp block at each node. The dimensions of this vector are derived from the active vector for the CeedOperator. The array has shape [nodes, component out, component in].

pub fn linear_assemble_add_point_block_diagonal(
    &self,
    assembled: &mut Vector<'_>
) -> Result<i32, CeedError>
[src]

Assemble the diagonal of a square linear Operator

This sums into a Vector with the diagonal of a linear Operator.

Note: Currently only non-composite Operators with a single field and composite Operators with single field sub-operators are supported.

  • op - Operator to assemble QFunction
  • assembled - Vector to store assembled CeedOperator point block diagonal, provided in row-major form with an ncomp * ncomp block at each node. The dimensions of this vector are derived from the active vector for the CeedOperator. The array has shape [nodes, component out, component in].

Trait Implementations

impl<'a> Display for CompositeOperator<'a>[src]

View a composite Operator


// Sub operator field arguments
let ne = 3;
let q = 4 as usize;
let mut ind: Vec<i32> = vec![0; 2 * ne];
for i in 0..ne {
    ind[2 * i + 0] = i as i32;
    ind[2 * i + 1] = (i + 1) as i32;
}
let r = ceed
    .elem_restriction(ne, 2, 1, 1, ne + 1, MemType::Host, &ind)
    .unwrap();
let strides: [i32; 3] = [1, q as i32, q as i32];
let rq = ceed
    .strided_elem_restriction(ne, 2, 1, q * ne, strides)
    .unwrap();

let b = ceed
    .basis_tensor_H1_Lagrange(1, 1, 2, q, QuadMode::Gauss)
    .unwrap();

let qdata_mass = ceed.vector(q * ne).unwrap();
let qdata_diff = ceed.vector(q * ne).unwrap();

let qf_mass = ceed.q_function_interior_by_name("MassApply").unwrap();
let op_mass = ceed
    .operator(&qf_mass, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("u", &r, &b, VectorOpt::Active)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, &qdata_mass)
    .unwrap()
    .field("v", &r, &b, VectorOpt::Active)
    .unwrap();

let qf_diff = ceed.q_function_interior_by_name("Poisson1DApply").unwrap();
let op_diff = ceed
    .operator(&qf_diff, QFunctionOpt::None, QFunctionOpt::None)
    .unwrap()
    .field("du", &r, &b, VectorOpt::Active)
    .unwrap()
    .field("qdata", &rq, BasisOpt::Collocated, &qdata_diff)
    .unwrap()
    .field("dv", &r, &b, VectorOpt::Active)
    .unwrap();

let op = ceed
    .composite_operator()
    .unwrap()
    .sub_operator(&op_mass)
    .unwrap()
    .sub_operator(&op_diff)
    .unwrap();

println!("{}", op);

Auto Trait Implementations

impl<'a> RefUnwindSafe for CompositeOperator<'a>

impl<'a> !Send for CompositeOperator<'a>

impl<'a> !Sync for CompositeOperator<'a>

impl<'a> Unpin for CompositeOperator<'a>

impl<'a> UnwindSafe for CompositeOperator<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.