00001 /* ======================================================================== 00002 * 00003 * Catfish 00004 * 00005 * A Finite Element Schrodinger-Poisson Solver 00006 * 00007 * Copyright (C) 2008, Kevin Long, Texas Tech University. 00008 * 00009 * This library is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU Lesser General Public License as 00011 * published by the Free Software Foundation; either version 2.1 of the 00012 * License, or (at your option) any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, but 00015 * WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00022 * USA 00023 * 00024 * ======================================================================== */ 00025 00026 00027 #ifndef SUNDANCE_COORDINATESYSTEM_HPP 00028 #define SUNDANCE_COORDINATESYSTEM_HPP 00029 00030 #include "SundanceExpr.hpp" 00031 #include "SundanceCoordExpr.hpp" 00032 #include "PlayaExceptions.hpp" 00033 #include <cmath> 00034 00035 00036 namespace Sundance 00037 { 00038 using Sundance::Expr; 00039 using namespace Teuchos; 00040 00041 class CoordinateSystemBase : 00042 public Playa::Handleable<CoordinateSystemBase> 00043 { 00044 public: 00045 /** */ 00046 virtual ~CoordinateSystemBase(){} 00047 00048 /** */ 00049 virtual Expr jacobian() const = 0 ; 00050 00051 /** */ 00052 virtual bool supportsMeshDimension(int dim) const = 0 ; 00053 00054 /** */ 00055 virtual std::ostream& print(std::ostream& os) const = 0 ; 00056 00057 /** */ 00058 double pi() const {return 4.0*::atan(1.0);} 00059 }; 00060 00061 00062 class CoordinateSystem : public Playa::Handle<CoordinateSystemBase> 00063 { 00064 public: 00065 /* boilerplate handle ctors */ 00066 HANDLE_CTORS(CoordinateSystem, CoordinateSystemBase); 00067 00068 /** */ 00069 Expr jacobian() const {return ptr()->jacobian();} 00070 00071 /** */ 00072 bool supportsMeshDimension(int dim) const 00073 {return ptr()->supportsMeshDimension(dim);} 00074 00075 }; 00076 00077 00078 class CartesianCoordinateSystem : public CoordinateSystemBase 00079 { 00080 public: 00081 /** */ 00082 CartesianCoordinateSystem(){} 00083 00084 /** */ 00085 Expr jacobian() const {return Expr(1.0);} 00086 00087 /** */ 00088 bool supportsMeshDimension(int dim) const {return dim > 0;} 00089 00090 /** */ 00091 std::ostream& print(std::ostream& os) const 00092 { 00093 os << "Cartesian"; 00094 return os; 00095 }; 00096 00097 00098 /** */ 00099 virtual RCP<CoordinateSystemBase> getRcp() {return rcp(this);} 00100 }; 00101 00102 00103 class MeridionalCylindricalCoordinateSystem : public CoordinateSystemBase 00104 { 00105 public: 00106 /** */ 00107 MeridionalCylindricalCoordinateSystem() 00108 : r_(new CoordExpr(0)) {} 00109 00110 /** */ 00111 Expr jacobian() const {return pi()*r_;} 00112 00113 /** */ 00114 bool supportsMeshDimension(int dim) const {return dim > 0 && dim <= 2;} 00115 00116 /** */ 00117 std::ostream& print(std::ostream& os) const 00118 { 00119 os << "Meridional Cylindrical"; 00120 return os; 00121 }; 00122 00123 /** */ 00124 virtual RCP<CoordinateSystemBase> getRcp() {return rcp(this);} 00125 00126 private: 00127 Expr r_; 00128 }; 00129 00130 class RadialSphericalCoordinateSystem : public CoordinateSystemBase 00131 { 00132 public: 00133 /** */ 00134 RadialSphericalCoordinateSystem() 00135 : r_(new CoordExpr(0)) {} 00136 00137 /** */ 00138 Expr jacobian() const {return pi()*r_*r_;} 00139 00140 /** */ 00141 bool supportsMeshDimension(int dim) const {return dim == 1;} 00142 00143 /** */ 00144 std::ostream& print(std::ostream& os) const 00145 { 00146 os << "Radial Spherical"; 00147 return os; 00148 }; 00149 00150 00151 00152 00153 /** */ 00154 virtual RCP<CoordinateSystemBase> getRcp() {return rcp(this);} 00155 private: 00156 Expr r_; 00157 }; 00158 00159 00160 class CoordinateSystemBuilder 00161 { 00162 public: 00163 /** */ 00164 static CoordinateSystem makeCoordinateSystem(const std::string& name); 00165 }; 00166 00167 00168 inline std::ostream& operator<<(std::ostream& os, const CoordinateSystem& cs) 00169 { 00170 return cs.ptr()->print(os); 00171 } 00172 00173 } 00174 00175 00176 00177 00178 #endif