Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92197021
geometry.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
Mon, Nov 18, 05:33
Size
8 KB
Mime Type
text/x-c++
Expires
Wed, Nov 20, 05:33 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22391834
Attached To
rLIBMULTISCALE LibMultiScale
geometry.hh
View Options
/**
* @file geometry.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Fri Jan 10 20:47:45 2014
*
* @brief Common mother of all geometries
*
* @section LICENSE
*
* Copyright INRIA and CEA
*
* The LibMultiScale is a C++ parallel framework for the multiscale
* coupling methods dedicated to material simulations. This framework
* provides an API which makes it possible to program coupled simulations
* and integration of already existing codes.
*
* This Project was initiated in a collaboration between INRIA Futurs Bordeaux
* within ScAlApplix team and CEA/DPTA Ile de France.
* The project is now continued at the Ecole Polytechnique Fédérale de Lausanne
* within the LSMS/ENAC laboratory.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*
*/
#ifndef __LIBMULTISCALE_GEOMETRY_HH__
#define __LIBMULTISCALE_GEOMETRY_HH__
/* -------------------------------------------------------------------------- */
#include "lm_parsable.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
class Cube;
/* -------------------------------------------------------------------------- */
/**
* Class Geometry
*
*/
class Geometry : public Parsable {
/* ------------------------------------------------------------------------ */
/* Typedefs */
/* ------------------------------------------------------------------------ */
public:
enum GeomType {
BALL = 1,
CUBE = 2,
INTER = 3,
SUB = 4,
ELLIPSOID = 5,
UNION = 6,
CYLINDER = 7,
CHAUDRON = 8,
CUBE_SURFACE = 9
};
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public:
Geometry(UInt Dim,GeomType Type, GeomID id);
virtual ~Geometry();
/* ------------------------------------------------------------------------ */
/* Accessors */
/* ------------------------------------------------------------------------ */
//! return type of geometry
GeomType getType() const;
//! return dimention of geometry
UInt getDim() const;
//! return dimention of geometry
void setDim(UInt d);
//! set the center of the geometry
void setCenter(Real X,Real Y=0,Real Z=0);
//! set the rotation matrix from euler parameters
void setRotation(Real phi,Real theta,Real psi);
//! get the i-est coordinate of the center
Real getCenter(UInt i) const;
//! get the id of the geometry
GeomID getID(){return id;};
//! set the id of the geometry
void setID(GeomID & id){this->id = id;};
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
public:
/// function to print the contain of the class
virtual void printself(std::ostream & stream, UInt indent = 0) const;
//! init function
virtual void init() = 0;
//! function that return true if geometrie contaUInt poUInt x,y,z
virtual bool contains(Real x,Real y=0,Real z=0)=0;
//! generic function that call the contains from a pointer
template <UInt Dim>
inline bool contains(const Real * X) {
if (Dim == 1) {
return this->contains(X[0]);
} else if (Dim == 2) {
return this->contains(X[0], X[1]);
} else if (Dim == 3) {
return this->contains(X[0], X[1], X[2]);
} else {
LM_FATAL("Unknown dimension '" << Dim << "'");
return false;
}
}
//! apply rotation on a given poUInt to change coordinates system
void rotate(Real & x,Real & y, Real & z);
//! return the distance to the center
Real distToCenter(Real X,Real Y=0,Real Z=0);
//! return the distance to the center
Real distToCenter(Real *X);
//! return the unidimentional(X) vector to the center (see source code)
Real vecToCenter(UInt index,Real X);
//! return the normed vector coordinate to the center
Real normToCenter(UInt index,Real X,Real Y=0.0,Real Z=0.0);
//! return a bounding box of the current geometry
virtual Cube & getBoundingBox();
//! intersect with another geometry
virtual bool doIntersect(Geometry & geom) = 0;
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
protected:
friend class GeomTools;
//! type of geom
GeomType type;
//! id of geom
GeomID id;
//! dimention
UInt dim;
//! center coordinates
Quantity<Length,3> center;
//!center of rotation
Quantity<Length,3> rotCenter;
//! rotation matrix by euler theorem with phi,teta,psi notation
/** see http://mathworld.wolfram.com/EulerAngles.html for more details */
Real rotMatrix[9];
};
/* -------------------------------------------------------------------------- */
inline void Geometry::rotate(Real & x,Real & y, Real & z){
Real x2 = rotMatrix[0]*x + rotMatrix[3]*y + rotMatrix[6]*z;
Real y2 = rotMatrix[1]*x + rotMatrix[4]*y + rotMatrix[7]*z;
Real z2 = rotMatrix[2]*x + rotMatrix[5]*y + rotMatrix[8]*z;
x = x2;
y = y2;
z = z2;
}
/* -------------------------------------------------------------------------- */
inline Real Geometry::distToCenter(Real X,Real Y,Real Z){
Real x[3] = {X,Y,Z};
return distToCenter(x);
}
/* -------------------------------------------------------------------------- */
inline Real Geometry::distToCenter(Real *X){
Real res = 0.0;
for (UInt i = 0; i < 3; ++i) {
Real tmp = center[i] - X[i];
res += tmp*tmp;
}
return sqrt(res);
}
/* -------------------------------------------------------------------------- */
inline Real Geometry::vecToCenter(UInt index,Real X){
Real res = X - center[index];
// LOG("vec au centre = " << res << " sur axe " << index);
return res;
}
/* -------------------------------------------------------------------------- */
inline Real Geometry::normToCenter(UInt index,Real X,Real Y,Real Z){
Real res[3];
res[0] = X - center[0];
res[1] = Y - center[1];
res[2] = Z - center[2];
Real norm = sqrt(res[0]*res[0] + res[1]*res[1] + res[2]*res[2]);
if (!norm)
return 0.0;
DUMP("norm au centre = " << res[index]/norm << " sur axe " << index,DBG_ALL);
return res[index]/norm;
}
/* -------------------------------------------------------------------------- */
/// standard output stream operator
inline std::ostream & operator <<(std::ostream & stream, Geometry & _this)
{
_this.printself(stream);
return stream;
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#endif /* __LIBMULTISCALE_GEOMETRY_HH__ */
Event Timeline
Log In to Comment