50#include "utils/simError.h"
54 VelocityField::VelocityField(
SimInfo* info) : info_(info) {
55 vfParams_ = info_->getSimParams()->getVelocityFieldParameters();
59 void VelocityField::initialize() {
60 if (initialized_)
return;
63 if (vfParams_ == NULL || !vfParams_->getUseVelocityField()) {
64 doVelocityField_ =
false;
69 bool haveSR = vfParams_->haveStrainRate();
70 bool haveSD1 = vfParams_->haveStrainDirection1();
71 bool haveSD2 = vfParams_->haveStrainDirection2();
72 bool haveVort = vfParams_->haveVorticity();
73 bool haveBG = vfParams_->haveBackgroundVelocity();
75 bool anyStrain = haveSR || haveSD1 || haveSD2;
76 bool fullStrain = haveSR && haveSD1 && haveSD2;
78 if (anyStrain && !fullStrain) {
79 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
80 "VelocityField: an incomplete rate-of-strain block was given.\n"
81 "\tThe constant-stress part requires all three of strainRate,\n"
82 "\tstrainDirection1, and strainDirection2 together (set\n"
83 "\tstrainDirection2 = strainDirection1 for uniaxial extension).\n");
88 if (!fullStrain && !haveVort && !haveBG) {
89 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
90 "VelocityField: nothing to do. Specify a rate-of-strain block\n"
91 "\t(strainRate, strainDirection1, strainDirection2), a vorticity\n"
92 "\tvector, a backgroundVelocity, or some combination of these.\n");
105 RealType sr = vfParams_->getStrainRate();
107 std::vector<RealType> d1 = vfParams_->getStrainDirection1();
108 std::vector<RealType> d2 = vfParams_->getStrainDirection2();
109 if (d1.size() != 3 || d2.size() != 3) {
110 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
111 "VelocityField: strainDirection1 and strainDirection2 must\n"
112 "\teach have 3 components (got %zu and %zu).\n",
113 d1.size(), d2.size());
114 painCave.isFatal = 1;
118 Vector3d a(d1[0], d1[1], d1[2]);
119 Vector3d b(d2[0], d2[1], d2[2]);
122 RealType cpsi =
dot(a, b);
124 E_(0, 0) = sr * (a.x() * b.x() - cpsi / 3.0);
125 E_(0, 1) = 0.5 * sr * (a.x() * b.y() + a.y() * b.x());
126 E_(0, 2) = 0.5 * sr * (a.x() * b.z() + a.z() * b.x());
128 E_(1, 1) = sr * (a.y() * b.y() - cpsi / 3.0);
129 E_(1, 2) = 0.5 * sr * (a.y() * b.z() + a.z() * b.y());
132 E_(2, 2) = sr * (a.z() * b.z() - cpsi / 3.0);
138 std::vector<RealType> w = vfParams_->getVorticity();
140 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
141 "VelocityField: vorticity must have 3 components (got %zu).\n",
143 painCave.isFatal = 1;
147 W_(0, 1) = -0.5 * w[2];
148 W_(0, 2) = 0.5 * w[1];
149 W_(1, 0) = 0.5 * w[2];
150 W_(1, 2) = -0.5 * w[0];
151 W_(2, 0) = -0.5 * w[1];
152 W_(2, 1) = 0.5 * w[0];
156 if (vfParams_->haveBackgroundVelocity()) {
157 std::vector<RealType> v0 = vfParams_->getBackgroundVelocity();
158 if (v0.size() != 3) {
159 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
160 "VelocityField: backgroundVelocity must have 3 components\n"
163 painCave.isFatal = 1;
166 v0_ = Vector3d(v0[0], v0[1], v0[2]);
173 E_ = 0.5 * (K_ + K_.transpose());
174 W_ = 0.5 * (K_ - K_.transpose());
175 omega_.x() = K_(2, 1) - K_(1, 2);
176 omega_.y() = K_(0, 2) - K_(2, 0);
177 omega_.z() = K_(1, 0) - K_(0, 1);
179 doVelocityField_ =
true;
Linear (homogeneous) ambient velocity field, queried at a location.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.