diff --git a/src/math_complex.h b/src/math_complex.h new file mode 100644 index 0000000000..4f53b45288 --- /dev/null +++ b/src/math_complex.h @@ -0,0 +1,72 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Pieter J. in 't Veld (SNL) +------------------------------------------------------------------------- */ + +#ifndef LMP_MATH_COMPLEX_H +#define LMP_MATH_COMPLEX_H + +#define COMPLEX_NULL {0, 0} + +namespace LAMMPS_NS { + +typedef struct complex { + double re, im; } complex; + +} + +#define C_MULT(d, x, y) { \ + d.re = x.re*y.re-x.im*y.im; \ + d.im = x.re*y.im+x.im*y.re; } + +#define C_RMULT(d, x, y) { \ + register complex t = x; \ + d.re = t.re*y.re-t.im*y.im; \ + d.im = t.re*y.im+t.im*y.re; } + +#define C_CRMULT(d, x, y) { \ + register complex t = x; \ + d.re = t.re*y.re-t.im*y.im; \ + d.im = -t.re*y.im-t.im*y.re; } + +#define C_SMULT(d, x, y) { \ + d.re = x.re*y; \ + d.im = x.im*y; } + +#define C_ADD(d, x, y) { \ + d.re = x.re+y.re; \ + d.im = x.im+y.im; } + +#define C_SUBTR(d, x, y) { \ + d.re = x.re-y.re; \ + d.im = x.im-y.im; } + +#define C_CONJ(d, x) { \ + d.re = x.re; \ + d.im = -x.im; } + +#define C_SET(d, x, y) { \ + d.re = x; \ + d.im = y; } + +#define C_ANGLE(d, angle) { \ + register double a = angle; \ + d.re = cos(a); \ + d.im = sin(a); } + +#define C_COPY(d, x) { \ + memcpy(&d, &x, sizeof(complex)); } + +#endif diff --git a/src/math_vector.h b/src/math_vector.h new file mode 100644 index 0000000000..da65e069bd --- /dev/null +++ b/src/math_vector.h @@ -0,0 +1,448 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Pieter J. in 't Veld (SNL) +------------------------------------------------------------------------- */ + +#ifndef LMP_MATH_VECTOR_H +#define LMP_MATH_VECTOR_H + +#include "math.h" +#include "string.h" + +#define VECTOR_NULL {0, 0, 0} +#define SHAPE_NULL {0, 0, 0, 0, 0, 0} +#define FORM_NULL {0, 0, 0, 0, 0, 0} +#define MATRIX_NULL {VECTOR_NULL, VECTOR_NULL, VECTOR_NULL} +#define VECTOR4_NULL {0, 0, 0, 0} +#define QUATERNION_NULL {0, 0, 0, 0} +#define FORM4_NULL {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + +#define FZERO 1e-15 +#define fzero(x) (((x)>-FZERO) && ((x)1) xtx[4] = xtx[2]; + if (!form_inv(xtx_inv, xtx)) return 0; + memcpy(eqn, xty, sizeof(vector)); + form_vec_dot(eqn, xtx_inv); + return 1; } + +// cubic regression: y = eqn[0] + eqn[1]*x + eqn[2]*x*x + eqn[3]*x*x*x + +inline int regress3(vector4 &eqn, int order, double *x, double *y, int n) { + form4 xtx = FORM4_NULL, xtx_inv; + vector4 xty = VECTOR4_NULL; + double xn, xi, yi; + int i; + + vec4_null(eqn); + xtx[0] = n; + if ((order = order%3)<0) order = -order; // max: cubic regress + if (order<1) xtx[1] = 1.0; + if (order<2) xtx[2] = 1.0; + if (order<3) xtx[3] = 1.0; + for (i=0; i1) xtx[8] = xtx[1]; + if (order>2) { xtx[6] = xtx[7]; xtx[5] = xtx[2]; } + if (!form4_inv(xtx_inv, xtx)) return 0; + memcpy(eqn, xty, sizeof(vector4)); + form4_vec4_dot(eqn, xtx_inv); + return 1; } + +} + +#endif