Some new convenience functions and types.

Former-commit-id: 7701cd8ee779e06ba18d6e19bfe650bd9465487f
This commit is contained in:
Marek Nečada 2020-01-08 14:39:29 +02:00
parent d31d8737b8
commit e1a6389232
4 changed files with 36 additions and 2 deletions

View File

@ -24,6 +24,12 @@ typedef struct qpms_epsmu_generator_t {
const void *params;
} qpms_epsmu_generator_t;
/// Convenience function for generating material properties at given frequency.
static inline qpms_epsmu_t qpms_epsmu_generator_eval(
qpms_epsmu_generator_t gen, complex double omega) {
return gen.function(omega, gen.params);
}
/// Constant optical property "generator" for qpms_epsmu_generator_t.
qpms_epsmu_t qpms_epsmu_const_g(complex double omega, ///< Frequency ignored.
const void *epsmu ///< Points to the qpms_epsmu_t to be returned.

View File

@ -410,6 +410,7 @@ typedef struct qpms_epsmu_t {
complex double mu; ///< Relative permeability.
} qpms_epsmu_t;
struct qpms_tolerance_spec_t; // See tolerances.c
#define lmcheck(l,m) assert((l) >= 1 && abs(m) <= (l))
#endif // QPMS_TYPES

View File

@ -19,8 +19,11 @@ static inline complex double *qpms_tmatrix_row(qpms_tmatrix_t *t, size_t rowno){
}
/// Initialises a zero T-matrix.
/** \sa qpms_tmatrix_init_from_generator()
* \sa qpms_tmatrix_init_from_function() */
qpms_tmatrix_t *qpms_tmatrix_init(const qpms_vswf_set_spec_t *bspec);
/// Copies a T-matrix, allocating new array for the T-matrix data.
qpms_tmatrix_t *qpms_tmatrix_copy(const qpms_tmatrix_t *T);
@ -253,6 +256,16 @@ typedef struct qpms_tmatrix_generator_t {
const void *params; ///< Parameter pointer passed to the function.
} qpms_tmatrix_generator_t;
/// Initialises and evaluates a new T-matrix using a generator.
static inline qpms_tmatrix_t *qpms_tmatrix_init_from_generator(
const qpms_vswf_set_spec_t *bspec,
qpms_tmatrix_generator_t gen,
complex double omega) {
qpms_tmatrix_t *t = qpms_tmatrix_init(bspec);
QPMS_ENSURE_SUCCESS(gen.function(t, omega, gen.params));
return t;
}
/// Implementation of qpms_matrix_generator_t that just copies a constant matrix.
/** N.B. this does almost no checks at all, so use it only for t-matrices with
* the same base spec.
@ -518,6 +531,12 @@ typedef struct qpms_tmatrix_function_t {
const qpms_tmatrix_generator_t *gen; ///< A T-matrix generator function.
} qpms_tmatrix_function_t;
/// Convenience function to create a new T-matrix from qpms_tmatrix_function_t.
// FIXME the name is not very intuitive.
static inline qpms_tmatrix_t *qpms_tmatrix_init_from_function(qpms_tmatrix_function_t f, complex double omega) {
return qpms_tmatrix_init_from_generator(f.spec, omega, f.gen);
}
/// Specifies different kinds of operations done on T-matrices
typedef enum {
QPMS_TMATRIX_OPERATION_NOOP, ///< Identity operation.
@ -596,11 +615,9 @@ typedef struct qpms_tmatrix_operation_t {
} qpms_tmatrix_operation_t;
/// Apply an operation on a T-matrix, returning a newly allocated result.
// TODO IMPLEMENT
qpms_tmatrix_t *qpms_tmatrix_apply_operation(const qpms_tmatrix_operation_t *op, const qpms_tmatrix_t *orig);
/// Apply an operation on a T-matrix and replace it with the result.
// TODO IMPLEMENT
qpms_tmatrix_t *qpms_tmatrix_apply_operation_inplace(const qpms_tmatrix_operation_t *op, qpms_tmatrix_t *orig);
/// (Recursively) deallocates internal data of qpms_tmatrix_operation_t.

10
qpms/tolerances.h Normal file
View File

@ -0,0 +1,10 @@
/*! \file tolerances.h */
#ifndef QPMS_TOLERANCES_H
#define QPMS_TOLERANCES_H
typedef struct qpms_tolerance_spec_t {
double atol;
double rtol;
} qpms_tolerance_spec_t;
#endif // QPMS_TOLERANCES_H