File size: 12,682 Bytes
10f2621 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | /**
* @defgroup Vec Vec class
* @brief an Nx1 vector class.
*/
/**
* @file vec.h
* @ingroup Vec
* @brief Class Vec: an Nx1 vector class.
* @version $Id: vec.h,v 1.22 2010/08/12 05:18:36 fetk Exp $
* @author Michael Holst
*
* @attention
* @verbatim
*
* MC = < Manifold Code >
* Copyright (C) 1994-- Michael Holst
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @endverbatim
*/
#ifndef _VEC_H_
#define _VEC_H_
#include <mc/mc_base.h>
#include <mc/mat.h>
/**
* @ingroup Vec
* @author Michael Holst
* @brief Contains public data memebers for Vec class
*/
struct sVec {
Vmem *vmem; /**< @brief the memory manager */
int iMadeVmem; /**< @brief did i make vmem or was it inherited */
char name[10]; /**< @brief character string name for this vector*/
int n; /**< @brief number of components in the vector */
double *u; /**< @brief the vector components */
int iMallocU; /**< @brief did i malloc u or was it passed in */
};
/**
* @brief Declaration of the Vec class as the Vec structure
* @ingroup Vec
* @author Michael Holst
* @return None
*/
typedef struct sVec Vec;
/*
* ***************************************************************************
* Class Vec: Inlineable methods (vec.c)
* ***************************************************************************
*/
#if !defined(VINLINE_BAM)
#else /* if defined(VINLINE_BAM) */
#endif /* if !defined(VINLINE_BAM) */
/**
* @ingroup Vec
* @brief The vector constructor (data array malloc'd by us).
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return Pointer to a newly allocated (empty) vector
* @param vmem Memory management object
* @param name character string name for this vector
* @param length the length of the vector
*/
VEXTERNC Vec* Vec_ctor(Vmem *vmem, const char *name, int length);
/**
* @ingroup Vec
* @brief The vector constructor (data array passed in).
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return Pointer to a newly allocated (empty) vector
* @param vmem Memory management object
* @param name character string name for this vector
* @param length the length of the vector
* @param data pointer to the initial value of the vector component
*/
VEXTERNC Vec* Vec_ctor2(Vmem *vmem, const char *name, int length, double *data);
/**
* @ingroup Vec
* @brief The vector destructor.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
*/
VEXTERNC void Vec_dtor(Vec **thee);
/**
* @ingroup Vec
* @brief Length of a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return Length of a vector
* @param thee Pointer to the vector
*/
VEXTERNC int Vec_len(Vec *thee);
/**
* @ingroup Vec
* @brief Address of a vector data.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return Address of a vector data
* @param thee Pointer to the vector
*/
VEXTERNC double *Vec_addr(Vec *thee);
/**
* @ingroup Vec
* @brief Return value of component of vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return value of component of vector.
* @param thee Pointer to the vector
* @param i index of the component of vector
*/
VEXTERNC double Vec_val(Vec *thee, int i);
/**
* @ingroup Vec
* @brief Set value of component of vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param i index of the component of vector
* @param val value of the component of vector
*/
VEXTERNC void Vec_set(Vec *thee, int i, double val);
/**
* @ingroup Vec
* @brief 1-norm of a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return 1-norm of a vector
* @param thee Pointer to the vector
*/
VEXTERNC double Vec_nrm1(Vec *thee);
/**
* @ingroup Vec
* @brief 2-norm of a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return 2-norm of a vector
* @param thee Pointer to the vector
*/
VEXTERNC double Vec_nrm2(Vec *thee);
/**
* @ingroup Vec
* @brief oo-norm of a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return oo-norm of a vector.
* @param thee Pointer to the vector
*/
VEXTERNC double Vec_nrm8(Vec *thee);
/**
* @ingroup Vec
* @brief 1-norm of a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return 1-norm of the difference of two vectors
* @param thee Pointer to the vector
* @param s the source vector
*/
VEXTERNC double Vec_dif1(Vec *thee, Vec *s);
/**
* @ingroup Vec
* @brief 2-norm of a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return 2-norm of the difference of two vectors
* @param thee Pointer to the vector
* @param s the source vector
*/
VEXTERNC double Vec_dif2(Vec *thee, Vec *s);
/**
* @ingroup Vec
* @brief oo-norm of a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return oo-norm of the difference of two vectors
* @param thee Pointer to the vector
* @param s the source vector
*/
VEXTERNC double Vec_dif8(Vec *thee, Vec *s);
/**
* @ingroup Vec
* @brief dot product of two vectors.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return dot product of two vectors
* @param thee Pointer to the vector
* @param s the source vector
*/
VEXTERNC double Vec_dot(Vec *thee, Vec *s);
/**
* @ingroup Vec
* @brief initialize a vector to be a constant.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param val value to be initialized for the vector
*/
VEXTERNC void Vec_init(Vec *thee, double val);
/**
* @ingroup Vec
* @brief vector scale.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param val value to be scaled to the vector
*/
VEXTERNC void Vec_scal(Vec *thee, double val);
/**
* @ingroup Vec
* @brief vector copy.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param s the source vector
*/
VEXTERNC void Vec_copy(Vec *thee, Vec *s);
/**
* @ingroup Vec
* @brief scalar times vector plus vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param s the source vector
* @param val coeficient for scaling the source vector
*/
VEXTERNC void Vec_axpy(Vec *thee, Vec *s, double val);
/**
* @ingroup Vec
* @brief print a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
*/
VEXTERNC void Vec_print(Vec *thee);
/**
* @ingroup Vec
* @brief print a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param fname the output file name
* @param pflag 0 ==> write, 1 ==> append
*/
VEXTERNC void Vec_printSp(Vec *thee, char *fname, int pflag);
/**
* @ingroup Vec
* @brief Apply inverse of diagonal to a vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param amat system matrix
* @param f source vector slot
*/
VEXTERNC void Vec_diagScale(Vec *thee, Mat *amat, Vec *f);
/**
* @ingroup Vec
* @brief Matrix times vector.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param amat system matrix
* @param v the source vector
* @param key which of A or A' to use for the matvec \n
* (0=A, 1=A', 2=A(accumulate), 3=A'(accumulate))\n
* (NOTE: 0=prolongate, 1=restrict, for PRO)
* @param part which part of matrix to use for the matvec \n
* (0=A=D+L+U, 1=D, 2=D+L, 3=D+U, 4=L+U) \n
* (NOTE: part!=0 only well-defined for DRC)
*/
VEXTERNC void Vec_matvec(Vec *thee, Mat *amat, Vec *v, int key, int part);
/**
* @ingroup Vec
* @brief Generic smoothing operator.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param amat system matrix
* @param f source vector slot
* @param w the work block vector
* @param key smooth with A or A' (0=A, 1=A')
* @param ioflag debug output level (0=normal, 1=none, 2=lots, ... )
* @param meth smoother choice (0=jac, 1=gs, ... )
* @param adj adjoint choice (0=normal, 1=adjoint)
* @param itmax number of iterations to do (the maximum allowed)
* @param etol error tolerance (currently ignored)
* @param omega SOR parameter (currently ignored)
*/
VEXTERNC void Vec_smooth(Vec *thee, Mat *amat, Vec *f, Vec *w,
int key, int ioflag, int meth, int adj, int itmax, double etol,
double omega);
/**
* @ingroup Vec
* @brief Jacobi iteration.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param amat system matrix
* @param f source vector slot
* @param w the work block vector
* @param key smooth with A or A' (0=A, 1=A')
* @param ioflag debug output level (0=normal, 1=none, 2=lots, ... )
* @param itmax number of iterations to do (the maximum allowed)
* @param etol error tolerance (currently ignored)
* @param omega iteration parameter
*/
VEXTERNC void Vec_jac(Vec *thee, Mat *amat, Vec *f, Vec *w,
int key, int ioflag, int itmax, double etol, double omega);
/**
* @ingroup Vec
* @brief Gauss-Seidel iteration.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param amat system matrix
* @param f source vector slot
* @param w the work block vector
* @param key smooth with A or A' (0=A, 1=A')
* @param ioflag debug output level (0=normal, 1=none, 2=lots, ... )
* @param adj adjoint choice (0=normal, 1=adjoint)
* @param itmax number of iterations to do (the maximum allowed)
* @param etol error tolerance (currently ignored)
*/
VEXTERNC void Vec_gs(Vec *thee, Mat *amat, Vec *f, Vec *w,
int key, int ioflag, int adj, int itmax, double etol);
/**
* @ingroup Vec
* @brief Apply boundary condition.
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param mat system matrix
* @param key index for setting zeroes in the row/column components
*/
VEXTERNC void Vec_bnd(Vec *thee, Mat *mat, int key);
/**
* @ingroup Vec
* @brief Log of abs value of entries of block vector, shifted by < val >
* @author Michael Holst
* @note Class Vec: Non-Inlineable methods (vec.c)
* @return None
* @param thee Pointer to the vector
* @param val value to be shifted to abs value of entries of block vector
*/
VEXTERNC void Vec_absLog(Vec *thee, double val);
#endif /* _VEC_H_ */
|