00001
00002
00003
00004
00005
00006 #ifndef BEAM_COUPLED_SOLVER2_H
00007 #define BEAM_COUPLED_SOLVER2_H
00008
00016 #include <cmath>
00017 #include "BeamSolver.h"
00018
00025 template <>
00026 class BeamCoupledSolver<2> : public BeamSolver {
00027 typedef BeamSolver base;
00028 public:
00029 BeamCoupledSolver() : base(), nodeids(0), connections(0), coordinates(0),
00030 velocities(0) {}
00031 virtual ~BeamCoupledSolver() {}
00032
00033
00034
00035
00036 virtual void sendBoundaryReceivePressure() = 0;
00037
00038
00039 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00040 base::register_at(Ctrl,prefix);
00041 char VariableName[32];
00042 for (int d=0; d<2; d++) {
00043 std::sprintf(VariableName,"Start(%d)",d+1);
00044 RegisterAt(base::LocCtrl,VariableName,start[d]);
00045 std::sprintf(VariableName,"Tangent(%d)",d+1);
00046 RegisterAt(base::LocCtrl,VariableName,tangent[d]);
00047 }
00048 }
00049 virtual void register_at(ControlDevice& Ctrl) {
00050 register_at(Ctrl, "");
00051 }
00052
00053 virtual bool setup() {
00054 bool ret=base::setup();
00055 if (ret) {
00056 nodeids = new int[NumNodes()];
00057 for (register int i=0; i<NumNodes(); i++)
00058 nodeids[i] = i;
00059 connections = new int[2*NumElements()];
00060 for (register int i=0; i<NumElements(); i++) {
00061 connections[2*i] = i; connections[2*i+1] = i+1;
00062 }
00063 coordinates = new double[2*NumNodes()];
00064 velocities = new double[2*NumNodes()];
00065 }
00066 return ret;
00067 }
00068
00069 virtual void finish() {
00070 base::finish();
00071 if (nodeids) delete [] nodeids;
00072 if (connections) delete [] connections;
00073 if (coordinates) delete [] coordinates;
00074 if (velocities) delete [] velocities;
00075 }
00076
00077 virtual void Initialize(double& t, double& dt) {
00078 base::Initialize(t,dt);
00079 sendBoundaryReceivePressure();
00080 }
00081
00082 virtual void Advance(double& t, double& dt) {
00083 sendBoundaryReceivePressure();
00084 base::Advance(t,dt);
00085 }
00086
00087 virtual void Restart(double& t, double& dt) {
00088 base::Restart(t,dt);
00089 sendBoundaryReceivePressure();
00090 }
00091
00092 virtual void UpdateBoundary() {
00093 double alpha=0;
00094 if (tangent[0]!=0.) alpha=std::atan(tangent[1]/tangent[0]);
00095 else {
00096 if (tangent[1]>0) alpha=2.*std::atan(1.0);
00097 else alpha=-2.*std::atan(1.0);
00098 }
00099 double ca = std::cos(alpha);
00100 double sa = std::sin(alpha);
00101 for (register int i=0; i<NumNodes(); i++) {
00102 coordinates[2*i] = start[0] + ca*i*base::StepSize() -
00103 sa*base::Deflection(i);
00104 coordinates[2*i+1] = start[1] + sa*i*base::StepSize() +
00105 ca*base::Deflection(i);
00106 velocities[2*i] = -sa*base::Velocity(i);
00107 velocities[2*i+1] = ca*base::Velocity(i);
00108 }
00109 }
00110
00111 inline int NumNodes() { return base::NumNodes(); }
00112 inline int NumElements() { return base::NumNodes()-1; }
00113 inline double* Pressures() { return base::CurLoad(); }
00114 inline const int* NodeIDs() const { return nodeids; }
00115 inline const int* Connections() const { return connections; }
00116 inline const double* Coordinates() const { return coordinates; }
00117 inline const double* Velocities() const { return velocities; }
00118
00119 protected:
00120 double start[2];
00121 double tangent[2];
00122 int* nodeids;
00123 int* connections;
00124 double* coordinates;
00125 double* velocities;
00126 };
00127
00128 #endif