Commit 85c4bba0 authored by kraus's avatar kraus
Browse files

MSLang now includes action

parent 65147777
......@@ -2,7 +2,7 @@
/***************************************************************************
*
* The IPPL Framework
*
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
......@@ -12,7 +12,7 @@
#define DCOMPLEX_H
/***********************************************************************
*
*
* Work around the lack of draft standard complex<T> in all compilers.
* Correctly declare a dcomplex typedef based on the compiler capabilities
* and available C++ standard library. dcomplex is a complex number class
......@@ -27,7 +27,7 @@
// KAI and others have a templated complex class
#ifdef IPPL_USE_SINGLE_PRECISION
typedef complex<float> dcomplex;
typedef std::complex<float> dcomplex;
#else // USE_DOUBLE_PRECISION
typedef std::complex<double> dcomplex;
#endif
......@@ -38,7 +38,7 @@ typedef std::complex<float> fComplex;
// This assumes that all other compilers have the old non-templated
// complex type which is like complex<double> in the draft standard.
typedef complex dcomplex;
typedef std::complex dcomplex;
#endif // IPPL_HAS_TEMPLATED_COMPLEX
......@@ -47,5 +47,5 @@ typedef complex dcomplex;
/***************************************************************************
* $RCSfile: dcomplex.h,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:24 $
* IPPL_VERSION_ID: $Id: dcomplex.h,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $
***************************************************************************/
* IPPL_VERSION_ID: $Id: dcomplex.h,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $
***************************************************************************/
\ No newline at end of file
......@@ -3,10 +3,18 @@ PROJECT (MSLANG)
SET (MSLANG_VERSION_MAJOR 0)
SET (MSLANG_VERSION_MINOR 1)
SET (IPPL_CXX_FLAGS
"-DIPPL_LINUX -DIPPL_STRINGSTREAM -DIPPL_MPI -DMPICH_SKIP_MPICXX -DIPPL_DONT_POOL -DIPPL_USE_XDIV_RNG -DPETE_BITWISE_COPY -DIPPL_HAS_TEMPLATED_COMPLEX -DIPPL_USE_PARTIAL_SPECIALIZATION -Drestrict=__restrict__ -DNOCTAssert ${IPPL_CXX_FLAGS}"
)
SET (CMAKE_CXX_FLAGS
"${OTHER_CXX_FLAGS} ${IPPL_CXX_FLAGS} ${CMAKE_CXX_FLAGS} "
)
INCLUDE_DIRECTORIES (
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/Classic
${CMAKE_SOURCE_DIR}/ippl
${CMAKE_SOURCE_DIR}/ippl/src
)
LINK_DIRECTORIES (
......
#include "Algorithms/CoordinateSystemTrafo.h"
#include "Physics/Physics.h"
#include <boost/regex.hpp>
#include <iostream>
......@@ -9,25 +12,64 @@ std::string Double("(-?[0-9]+\\.?[0-9]*([Ee][+-]?[0-9]+)?)");
std::string UInt("([0-9]+)");
std::string FCall("([a-z]*)\\((.*)");
struct base;
struct function {
virtual ~function() {};
virtual void print(int indent) = 0;
virtual void apply(std::vector<base*> &bfuncs) = 0;
};
typedef std::string::iterator iterator;
bool parse(iterator &it, const iterator &end, function* &fun);
struct rectangle: public function {
struct base: public function {
CoordinateSystemTrafo trafo;
base():
trafo(Vector_t(0.0),
Quaternion(0.0, 0.0, 0.0, 1.0))
{ }
virtual base* clone() = 0;
};
struct rectangle: public base {
double width;
double height;
rectangle():
base(),
width(0.0),
height(0.0)
{ }
virtual ~rectangle() { }
virtual void print(int indentwidth) {
std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' ');
Vector_t origin = trafo.getOrigin();
double angle = trafo.getRotation()[0] * 2 * Physics::rad2deg;
std::cout << indent << "rectangle, \n"
<< indent2 << "w: " << width << ", \n"
<< indent2 << "h: " << height;
// << std::endl;
<< indent2 << "h: " << height << ", \n"
<< indent2 << "origin: " << origin[0] << ", " << origin[1] << ",\n"
<< indent2 << "angle: " << angle;
}
virtual void apply(std::vector<base*> &bfuncs) {
bfuncs.push_back(this->clone());
}
virtual base* clone() {
rectangle *rect = new rectangle;
rect->width = width;
rect->height = height;
rect->trafo = trafo;
return rect;
}
static
......@@ -51,17 +93,40 @@ struct rectangle: public function {
}
};
struct ellipse: public function {
struct ellipse: public base {
double width;
double height;
ellipse():
width(0.0),
height(0.0)
{ }
virtual ~ellipse() { }
virtual void print(int indentwidth) {
std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' ');
Vector_t origin = trafo.getOrigin();
double angle = trafo.getRotation()[0] * 2 * Physics::rad2deg;
std::cout << indent << "ellipse, \n"
<< indent2 << "w: " << width << ", \n"
<< indent2 << "h: " << height;
// << std::endl;
<< indent2 << "h: " << height << ", \n"
<< indent2 << "origin: " << origin[0] << ", " << origin[1] << ",\n"
<< indent2 << "angle: " << angle;
}
virtual void apply(std::vector<base*> &bfuncs) {
bfuncs.push_back(this->clone());
}
virtual base* clone() {
ellipse *elps = new ellipse;
elps->width = width;
elps->height = height;
elps->trafo = trafo;
return elps;
}
static
......@@ -91,6 +156,10 @@ struct repeat: public function {
double shiftx;
double shifty;
virtual ~repeat() {
delete func;
}
virtual void print(int indentwidth) {
std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' ');
......@@ -100,7 +169,24 @@ struct repeat: public function {
<< indent2 << "N: " << N << ", \n"
<< indent2 << "dx: " << shiftx << ", \n"
<< indent2 << "dy: " << shifty;
// << std::endl;
}
virtual void apply(std::vector<base*> &bfuncs) {
CoordinateSystemTrafo shift(Vector_t(shiftx, shifty, 0.0),
Quaternion(0.0, 0.0, 0.0, 1.0));
func->apply(bfuncs);
const unsigned int size = bfuncs.size();
CoordinateSystemTrafo current_shift = shift;
for (unsigned int i = 0; i < N; ++ i) {
for (unsigned int j = 0; j < size; ++ j) {
base *obj = bfuncs[j]->clone();
obj->trafo = current_shift * obj->trafo;
bfuncs.push_back(obj);
}
current_shift *= shift;
}
}
static
......@@ -132,6 +218,10 @@ struct translate: public function {
double shiftx;
double shifty;
virtual ~translate() {
delete func;
}
virtual void print(int indentwidth) {
std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' ');
......@@ -140,7 +230,18 @@ struct translate: public function {
std::cout << ",\n"
<< indent2 << "dx: " << shiftx << ", \n"
<< indent2 << "dy: " << shifty;
// << std::endl;
}
virtual void apply(std::vector<base*> &bfuncs) {
CoordinateSystemTrafo shift(Vector_t(shiftx, shifty, 0.0),
Quaternion(0.0, 0.0, 0.0, 1.0));
func->apply(bfuncs);
const unsigned int size = bfuncs.size();
for (unsigned int j = 0; j < size; ++ j) {
base *obj = bfuncs[j];
obj->trafo = shift * obj->trafo;
}
}
static
......@@ -171,6 +272,10 @@ struct rotate: public function {
function* func;
double angle;
virtual ~rotate() {
delete func;
}
virtual void print(int indentwidth) {
std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' ');
......@@ -178,7 +283,18 @@ struct rotate: public function {
func->print(indentwidth + 8);
std::cout << ",\n"
<< indent2 << "angle: " << angle;
// << std::endl;
}
virtual void apply(std::vector<base*> &bfuncs) {
CoordinateSystemTrafo rotation(Vector_t(0.0, 0.0, 0.0),
Quaternion(0.5 * angle, 0.0, 0.0, 1.0));
func->apply(bfuncs);
const unsigned int size = bfuncs.size();
for (unsigned int j = 0; j < size; ++ j) {
base *obj = bfuncs[j];
obj->trafo = rotation * obj->trafo;
}
}
static
......@@ -206,6 +322,12 @@ struct rotate: public function {
struct unionf: public function {
std::vector<function*> funcs;
virtual ~unionf () {
for (function* func: funcs) {
delete func;
}
}
virtual void print(int indentwidth) {
std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' ');
......@@ -214,11 +336,19 @@ struct unionf: public function {
std::cout << indent2 << "funcs: {\n";
funcs.front()->print(indentwidth + 16);
for (unsigned int i = 1; i < funcs.size(); ++ i) {
std::cout << indent3 << "," << std::endl;
std::cout << "\n"
<< indent3 << "," << std::endl;
funcs[i]->print(indentwidth + 16);
}
std::cout << "\n"
<< indent2 << "} ";// << std::endl;
<< indent2 << "} ";
}
virtual void apply(std::vector<base*> &bfuncs) {
for (unsigned int i = 0; i < funcs.size(); ++ i) {
function *func = funcs[i];
func->apply(bfuncs);
}
}
static
......@@ -339,7 +469,22 @@ main()
if (parse(str, fun)) {
fun->print(0);
std::cout << std::endl;
std::cout << "\n" << std::endl;
std::vector<base*> baseBlocks;
fun->apply(baseBlocks);
for (base* bfun: baseBlocks) {
bfun->print(0);
std::cout << std::endl;
}
for (base* func: baseBlocks) {
delete func;
}
}
delete fun;
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment