48#include "hydrodynamics/HydroProp.hpp"
50#include "math/CholeskyDecomposition.hpp"
52#include "utils/simError.h"
56 HydroProp::HydroProp() : hasCOR_(false), hasXi_(false), hasS_(false) {}
58 HydroProp::HydroProp(Vector3d cor, Mat6x6d Xi) :
59 cor_(cor), Xi_(Xi), hasCOR_(true), hasXi_(true), hasS_(false) {}
61 void HydroProp::complete() {
63 CholeskyDecomposition(Xi_, S_);
67 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
68 "HydroProp was asked to complete without a Resistance Tensor.\n");
69 painCave.severity = OPENMD_ERROR;
75 Mat6x6d HydroProp::getS() {
76 if (!hasS_) { complete(); }
80 Mat3x3d HydroProp::getXitt() {
82 Xi_.getSubMatrix(0, 0, Xitt);
85 Mat3x3d HydroProp::getXirt() {
87 Xi_.getSubMatrix(0, 3, Xirt);
90 Mat3x3d HydroProp::getXitr() {
92 Xi_.getSubMatrix(3, 0, Xitr);
95 Mat3x3d HydroProp::getXirr() {
97 Xi_.getSubMatrix(3, 3, Xirr);
101 Mat6x6d HydroProp::getDiffusionTensor(RealType temperature) {
102 Mat6x6d XiCopy = Xi_;
105 RealType kt = Constants::kb * temperature;
110 Mat6x6d HydroProp::getResistanceTensorAtPos(Vector3d pos) {
114 Vector3d cp = pos - cor_;
118 Mat3x3d Xitt = getXitt();
119 Mat3x3d Xitr = getXitr();
120 Mat3x3d Xirr = getXirr();
128 Xipostr = (Xitr - U * Xitt);
129 Xiposrr = Xirr - U * Xitt * U + Xitr * U - U * Xitr.transpose();
132 Xipos.setSubMatrix(0, 0, Xipostt);
133 Xipos.setSubMatrix(0, 3, Xipostr.transpose());
134 Xipos.setSubMatrix(3, 0, Xipostr);
135 Xipos.setSubMatrix(3, 3, Xiposrr);
139 Mat6x6d HydroProp::getDiffusionTensorAtPos(Vector3d pos,
140 RealType temperature) {
145 Vector3d cp = pos - cor_;
149 Mat6x6d D = getDiffusionTensor(temperature);
155 D.getSubMatrix(0, 0, Dtt);
156 D.getSubMatrix(3, 0, Dtr);
157 D.getSubMatrix(3, 3, Drr);
165 Dpostt = Dtt - U * Drr * U + Dtr.transpose() * U - U * Dtr;
167 Dpostr = Dtr + Drr * U;
170 Dpos.setSubMatrix(0, 0, Dpostt);
171 Dpos.setSubMatrix(0, 3, Dpostr.transpose());
172 Dpos.setSubMatrix(3, 0, Dpostr);
173 Dpos.setSubMatrix(3, 3, Dposrr);
177 Vector3d HydroProp::getCenterOfDiffusion(RealType temperature) {
180 Vector3d origin(0.0);
181 Mat6x6d Do = getDiffusionTensorAtPos(origin, temperature);
186 Do.getSubMatrix(3, 0, Dotr);
187 Do.getSubMatrix(3, 3, Dorr);
193 tmp(0, 0) = Dorr(1, 1) + Dorr(2, 2);
194 tmp(0, 1) = -Dorr(0, 1);
195 tmp(0, 2) = -Dorr(0, 2);
196 tmp(1, 0) = -Dorr(0, 1);
197 tmp(1, 1) = Dorr(0, 0) + Dorr(2, 2);
198 tmp(1, 2) = -Dorr(1, 2);
199 tmp(2, 0) = -Dorr(0, 2);
200 tmp(2, 1) = -Dorr(1, 2);
201 tmp(2, 2) = Dorr(1, 1) + Dorr(0, 0);
204 tmpVec[0] = Dotr(1, 2) - Dotr(2, 1);
205 tmpVec[1] = Dotr(2, 0) - Dotr(0, 2);
206 tmpVec[2] = Dotr(0, 1) - Dotr(1, 0);
209 Vector3d cod = tmp.inverse() * tmpVec;
213 Mat3x3d HydroProp::getPitchMatrix() {
215 P = -getXitt().
inverse() * getXirt();
219 RealType HydroProp::getScalarPitch() {
220 Mat3x3d P = getPitchMatrix();
224 RealType pScalar(0.0);
226 for (
int i = 0; i < 3; i++) {
227 pScalar += pow(evals[i], 2);
231 return sqrt(pScalar);
234 void HydroProp::pitchAxes(Mat3x3d& pitchAxes, Vector3d& pitches,
235 RealType& pitchScalar) {
236 Mat3x3d P = getPitchMatrix();
241 for (
int i = 0; i < 3; i++) {
242 pitchScalar += pow(pitches[i], 2);
246 pitchScalar = sqrt(pitchScalar);
249 Vector3d HydroProp::getCenterOfPitch() {
250 Mat3x3d P = getPitchMatrix();
252 cop[0] = 0.5 * (P(1, 2) - P(2, 1));
253 cop[1] = 0.5 * (P(2, 0) - P(0, 2));
254 cop[2] = 0.5 * (P(0, 1) - P(1, 0));
SquareMatrix3< Real > inverse() const
Sets the value of this matrix to the inverse of itself.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
bool invertMatrix(MatrixType &A, MatrixType &AI)
Invert input square matrix A into matrix AI.