Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AnalysisAction/PrincipalAxisSystemAction.cpp

    r0430e3 r6e5084  
    1010#include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
    1111#include "Actions/ActionRegistry.hpp"
     12#include "Helpers/Log.hpp"
     13#include "Helpers/Verbose.hpp"
     14#include "LinearAlgebra/Matrix.hpp"
     15#include "LinearAlgebra/Vector.hpp"
     16#include "element.hpp"
    1217#include "molecule.hpp"
    13 #include "log.hpp"
    14 #include "verbose.hpp"
    1518
    1619#include <iostream>
     
    2124#include "UIElements/UIFactory.hpp"
    2225#include "UIElements/Dialog.hpp"
    23 #include "UIElements/ValueStorage.hpp"
     26#include "Actions/ValueStorage.hpp"
    2427
    2528const char AnalysisPrincipalAxisSystemAction::NAME[] = "principal-axis-system";
     
    3639};
    3740
    38 Dialog* AnalysisPrincipalAxisSystemAction::createDialog() {
    39   Dialog *dialog = UIFactory::getInstance().makeDialog();
     41Dialog* AnalysisPrincipalAxisSystemAction::fillDialog(Dialog *dialog) {
     42  ASSERT(dialog,"No Dialog given when filling action dialog");
    4043
    4144  dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
     
    4649Action::state_ptr AnalysisPrincipalAxisSystemAction::performCall() {
    4750  molecule *mol = NULL;
     51  Matrix InertiaTensor;
    4852
    4953  ValueStorage::getInstance().queryCurrentValue(NAME, mol);
     
    5155  for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
    5256    molecule *mol = iter->second;
    53     mol->PrincipalAxisSystem(false);
     57    Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
     58
     59    // reset inertia tensor
     60    InertiaTensor.zero();
     61
     62    // sum up inertia tensor
     63    for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     64      Vector x = (*iter)->x;
     65      x -= *CenterOfGravity;
     66      InertiaTensor.at(0,0) += (*iter)->type->mass*(x[1]*x[1] + x[2]*x[2]);
     67      InertiaTensor.at(0,1) += (*iter)->type->mass*(-x[0]*x[1]);
     68      InertiaTensor.at(0,2) += (*iter)->type->mass*(-x[0]*x[2]);
     69      InertiaTensor.at(1,0) += (*iter)->type->mass*(-x[1]*x[0]);
     70      InertiaTensor.at(1,1) += (*iter)->type->mass*(x[0]*x[0] + x[2]*x[2]);
     71      InertiaTensor.at(1,2) += (*iter)->type->mass*(-x[1]*x[2]);
     72      InertiaTensor.at(2,0) += (*iter)->type->mass*(-x[2]*x[0]);
     73      InertiaTensor.at(2,1) += (*iter)->type->mass*(-x[2]*x[1]);
     74      InertiaTensor.at(2,2) += (*iter)->type->mass*(x[0]*x[0] + x[1]*x[1]);
     75    }
     76    // print InertiaTensor for debugging
     77    DoLog(0) && (Log() << Verbose(0) << "The inertia tensor is:" << InertiaTensor << endl);
    5478  }
    5579  return Action::success;
Note: See TracChangeset for help on using the changeset viewer.