-
Notifications
You must be signed in to change notification settings - Fork 10
/
LocalSystems.C
187 lines (168 loc) · 5 KB
/
LocalSystems.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// $Id$
//==============================================================================
//!
//! \file LocalSystems.C
//!
//! \date Apr 07 2015
//!
//! \author Knut Morten Okstad / SINTEF
//!
//! \brief Local coordinate systems for linear elasticity problems.
//!
//==============================================================================
#include "IFEM.h"
#include "Elasticity.h"
#include "Utilities.h"
#include "Tensor.h"
#include "tinyxml2.h"
#ifdef PRINT_CS
#include <fstream>
#endif
/*!
\brief Local coordinate system for a cylinder along global z-axis.
*/
class CylinderCS : public LocalSystem
{
public:
//! \brief The constructor prints a message making user aware of its presense.
CylinderCS()
{
IFEM::cout <<"\nLocal coordinate system: Cylindric"<< std::endl;
}
//! \brief Empty destructor.
virtual ~CylinderCS() {}
//! \brief Computes the global-to-local transformation at the point \a X.
virtual const Tensor& getTmat(const Vec3& X) const
{
static Tensor T(3);
double r = hypot(X.x,X.y);
T(1,1) = X.x/r;
T(1,2) = X.y/r;
T(2,1) = -T(1,2);
T(2,2) = T(1,1);
T(3,3) = 1.0;
return T;
}
};
/*!
\brief Local coordinate system for a cylinder along the global z-axis,
closed by a spherical cap.
*/
class CylinderSphereCS : public LocalSystem
{
public:
//! \brief The constructor prints a message making user aware of its presense.
explicit CylinderSphereCS(double H = 0.0) : h(H)
{
IFEM::cout <<"\nLocal coordinate system: Cylindric with Spherical cap, h="
<< h << std::endl;
#ifdef PRINT_CS
sn.open("nodes.dat");
se.open("elements.dat");
s1.open("v1.dat");
s2.open("v2.dat");
s3.open("v3.dat");
sn <<"\n*NODES 4\n";
se <<"\n*ELEMENTS 4\n%NODES #4\n"
<<"%NO_ID\n%MAP_NODE_INDICES\n%PART_ID 4\n%POINTS\n";
s1 <<"\n*RESULTS 31\n%NO_ID\n%DIMENSION 3\n%PER_NODE #4\n";
s2 <<"\n*RESULTS 32\n%NO_ID\n%DIMENSION 3\n%PER_NODE #4\n";
s3 <<"\n*RESULTS 33\n%NO_ID\n%DIMENSION 3\n%PER_NODE #4\n";
}
//! \brief The destructor finalizes the VTF files plotting the local axes.
virtual ~CylinderSphereCS()
{
s1 <<"\n*GLVIEWVECTOR 2\n%NAME \"v1\"\n%STEP 1\n31\n";
s2 <<"\n*GLVIEWVECTOR 3\n%NAME \"v2\"\n%STEP 1\n32\n";
s3 <<"\n*GLVIEWVECTOR 4\n%NAME \"v3\"\n%STEP 1\n33\n";
#endif
}
//! \brief Computes the global-to-local transformation at the point \a X.
virtual const Tensor& getTmat(const Vec3& X) const
{
static Tensor T(3);
#ifdef PRINT_CS
sn << X <<'\n';
static int iel = 0;
se << ++iel <<'\n';
#endif
if (patch == 1) // Cylindric system {-z,theta,r}
{
T.zero();
double r = hypot(X.x,X.y);
T(1,3) = -1.0;
T(2,1) = -X.y/r;
T(2,2) = X.x/r;
T(3,1) = T(2,2);
T(3,2) = -T(2,1);
#ifdef PRINT_CS
s1 <<"0 0 -1\n";
s2 << T(2,1) <<" "<< T(2,2) <<" 0\n";
s3 << T(3,1) <<" "<< T(3,2) <<" 0\n";
#endif
}
else // Spherical system {phi,theta,r}
{
Vec3 v3(X.x,X.y,X.z-h);
v3 /= v3.length();
double theta = atan2(X.y,X.x);
double phi = acos(v3.z);
Vec3 v1(cos(theta)*cos(phi),sin(theta)*cos(phi),-sin(phi));
Vec3 v2(v3,v1);
for (int i = 1; i <= 3; i++)
{
T(1,i) = v1[i-1];
T(2,i) = v2[i-1];
T(3,i) = v3[i-1];
}
#ifdef PRINT_CS
s1 << v1 <<'\n';
s2 << v2 <<'\n';
s3 << v3 <<'\n';
#endif
}
return T;
}
private:
double h; //!< Height above global origin of the centre of the sphere
#ifdef PRINT_CS
mutable std::ofstream sn; //!< VTF output stream for CS nodes
mutable std::ofstream se; //!< VTF output stream for CS point elements
mutable std::ofstream s1; //!< VTF output stream for vector v1 of local CS
mutable std::ofstream s2; //!< VTF output stream for vector v2 of local CS
mutable std::ofstream s3; //!< VTF output stream for vector v3 of local CS
#endif
};
bool Elasticity::parseLocalSystem (const char* cline)
{
if (!strncasecmp(cline,"CYLINDRICZ",10))
this->setLocalSystem(new CylinderCS);
else if (!strncasecmp(cline,"CYLINDER+SPHERE",15))
this->setLocalSystem(new CylinderSphereCS(atof(cline+15)));
else
{
std::cerr <<" ** Unsupported coordinate system: "
<< cline <<" (ignored)"<< std::endl;
return false;
}
return true;
}
bool Elasticity::parseLocalSystem (const tinyxml2::XMLElement* elem)
{
if (elem->FirstChild() == nullptr) return false;
// Caution: When running adaptively, the below will cause a small memory
// leak because the coordinate system objects are only deleted by the
// Elasticity destructor (and not in SIMbase::clearProperties).
if (!strcasecmp(elem->FirstChild()->Value(),"cylindricz"))
this->setLocalSystem(new CylinderCS);
else if (!strcasecmp(elem->FirstChild()->Value(),"cylinder+sphere"))
{
double H = 0.0;
utl::getAttribute(elem,"H",H);
this->setLocalSystem(new CylinderSphereCS(H));
}
else
std::cerr <<" ** Unsupported local coordinate system: "
<< elem->FirstChild()->Value() <<" (ignored)"<< std::endl;
return true;
}