Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88835581
common.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Oct 20, 22:22
Size
3 KB
Mime Type
text/x-c++
Expires
Tue, Oct 22, 22:22 (2 d)
Engine
blob
Format
Raw Data
Handle
21783249
Attached To
rCADDMESH CADD_mesher
common.hh
View Options
/**
* @file common.hh
* @author Till Junge <junge@lsmspc42.epfl.ch>
* @date Wed Apr 4 15:59:37 2012
*
* @brief common parts for the cadd_mesher
*
* @section LICENSE
*
* <insert lisence here>
*
*/
/* -------------------------------------------------------------------------- */
#ifndef __cadd_mesh_COMMON_HH__
#define __cadd_mesh_COMMON_HH__
#include <iostream>
#include <string>
#include <vector>
typedef double Real;
typedef unsigned int Uint;
const static Uint twoD = 2;
const static Uint threeD = 3;
const static Uint indent_incr = 2;
void indent_space(std::ostream & stream, int indent = 0);
template <typename numeric>
inline void keep_max(numeric & value, const numeric & comparison) {
if (comparison > value) {
value = comparison;
}
}
template <typename numeric>
inline void keep_min(numeric & value, const numeric & comparison) {
if (comparison < value) {
value = comparison;
}
}
template <typename numeric>
inline numeric square(numeric val) {return val*val;}
template <typename el_typo>
void print_vector(const std::vector<el_typo> & vec, const std::string & name,
Uint stride = 1, int indent = 0, std::ostream & stream = std::cout){
indent_space(stream, indent);
stream << "Vector '" << name << "': " <<std::endl;
const Uint max_size = 12;
Uint size = vec.size()/stride;
Uint i;
for (i = 0; i < size && i < max_size; ++i) {
stream.width(7);
indent_space(stream, indent+indent_incr);
stream << i << " : " ;
for (Uint j = 0; j < stride-1 ; ++j) {
stream.width(4);
stream << std::showpos << vec.at(stride*i +j) << ",\t" ;
}
stream.width(4);
stream << vec.at(stride*i+stride-1) << std::endl;
}
if (size > max_size) {
stream.width(7);
indent_space(stream, indent+indent_incr);
stream << i << " : ";
for (Uint j = 0; j < stride-1; ++j) {
stream.width(4);
stream << std::showpos << "..." << ",\t";
}
stream.width(4);
stream << "..." << std::endl;
}
}
template <typename el_typo>
void print_array(el_typo * array, Uint length, const std::string & name, std::ostream & stream=std::cout) {
stream << "Array '" << name << "': (" ;
for (Uint i = 0; i < length-1 ; ++i) {
stream << array[i] << ", ";
}
stream << array[length-1] << ")" << std::endl;
}
//This function sets a vec1's components to vec2's components
template <Uint DIM>
inline void vector_set(Real * vec1, const Real * vec2) {
for (Uint i = 0; i < DIM ; ++i) {
vec1[i] = vec2[i];
}
}
template<Uint DIM>
inline Real dot_prod(const Real vec1[DIM], const Real vec2[DIM]) {
Real prod = 0;
for (Uint i = 0 ; i < DIM ; ++i) {
prod += vec1[i]*vec2[i];
}
return prod;
}
// stretches a vector
template<Uint DIM>
inline void vector_stretch(Real * vector, const Real * factors) {
for (Uint i = 0; i < DIM ; ++i) {
vector[i] *= factors[i];
}
}
template<Uint DIM>
inline void vector_scale(Real * vector, const Real & factor) {
for (Uint i = 0; i < DIM ; ++i) {
vector[i] *= factor;
}
}
//This function adds factor times addition to vec1
template <Uint DIM>
inline void vector_incr(Real * vec1, const Real * addition, const Real & factor=1) {
for (Uint i = 0; i < DIM ; ++i) {
vec1[i] += factor * addition[i];
}
}
// vector from point 1 to point 2
template<Uint DIM>
inline void vector_difference(Real * vec, const Real * from, const Real * to,
const Real & factor = 1) {
vector_set<DIM>(vec, to);
vector_incr<DIM>(vec, from, -1);
vector_scale<DIM>(vec, factor);
}
#endif /* __cadd_mesh_COMMON_HH__ */
Event Timeline
Log In to Comment