void Structure0815:: timestep(double dt) { STRUCTURE_DEBUG("Adding value changes to values."); _oldVelocities = _velocities; _oldDisplacements = _displacements; _time += dt; _timesteps++; DynVector centerOfGravity(_dim, 0.0); double totalMass = 0.0; double totalVolume = 0.0; if (not _fixedCharacteristics){ computeCharacteristics(centerOfGravity, totalMass, totalVolume); STRUCTURE_INFO("Center of gravity delta: " << _centerOfGravity - centerOfGravity); STRUCTURE_INFO("Total mass delta: " << _totalMass - totalMass); STRUCTURE_INFO("Total volume delta: " << _totalMass/_density - totalVolume); } _statisticsWriter.writeData(TIMESTEPS, _timesteps); _statisticsWriter.writeData(TIME, _time); if (_dim == 2){ precice::utils::Vector2D centerOfGravity2D(centerOfGravity); _statisticsWriter.writeData(CENTEROFGRAVITY, centerOfGravity2D); } else { assertion1(_dim == 3, _dim); precice::utils::Vector3D centerOfGravity3D(centerOfGravity); _statisticsWriter.writeData(CENTEROFGRAVITY, centerOfGravity3D); } _statisticsWriter.writeData(TOTALMASS, totalMass); _statisticsWriter.writeData(TOTALVOLUME, totalVolume); }
UtilityMath::S_Vector2<T> UtilityMath::S_Vector2<T>::s_CenterOfGravityWith3Points(const UtilityMath::S_Vector2<T>& rA, const UtilityMath::S_Vector2<T>& rB, const UtilityMath::S_Vector2<T>& rC) { S_Vector2 centerOfGravity(rA + rB + rC); centerOfGravity /= static_cast<T>(3); return centerOfGravity; }
Structure0815:: Structure0815 ( int dim, double density, const DynVector& gravity, const DynVector& vertices, const tarch::la::DynamicVector<int> faces ) : TIMESTEPS("Timesteps"), TIME("Time"), CENTEROFGRAVITY("Center-of-gravity"), TOTALMASS("Total mass"), TOTALVOLUME("Total volume"), _dim(dim), _density(density), _gravity(gravity), _centerOfGravity(dim, 0.0), _totalMass(0.0), _time(0.0), _timesteps(0), _vertices(vertices), _faces(faces), _forces(vertices.size(), 0.0), _velocities(vertices.size(), 0.0), _oldVelocities(vertices.size(), 0.0), _velocityDeltas(vertices.size(), 0.0), _displacements(vertices.size(), 0.0), _oldDisplacements(vertices.size(), 0.0), _displacementDeltas(vertices.size(), 0.0), _fixedTranslationDirections(dim, false), _fixed(false), _fixture(dim, 0.0), _fixedCharacteristics(false), _statisticsWriter("structure0815-statistics.txt") { double totalVolume = 0.0; computeCharacteristics(_centerOfGravity, _totalMass, totalVolume); STRUCTURE_INFO("Center of gravity: " << _centerOfGravity); STRUCTURE_INFO("Total mass: " << _totalMass); STRUCTURE_INFO("Total volume: " << totalVolume); _statisticsWriter.addData(TIMESTEPS, precice::io::TXTTableWriter::INT ); _statisticsWriter.addData(TIME, precice::io::TXTTableWriter::DOUBLE ); if (dim == 2){ _statisticsWriter.addData(CENTEROFGRAVITY, precice::io::TXTTableWriter::VECTOR2D); } else { _statisticsWriter.addData(CENTEROFGRAVITY, precice::io::TXTTableWriter::VECTOR3D); } _statisticsWriter.addData(TOTALMASS, precice::io::TXTTableWriter::DOUBLE); _statisticsWriter.addData(TOTALVOLUME, precice::io::TXTTableWriter::DOUBLE); _statisticsWriter.writeData(TIMESTEPS, _timesteps); _statisticsWriter.writeData(TIME, _time); if (dim == 2){ precice::utils::Vector2D centerOfGravity(_centerOfGravity); _statisticsWriter.writeData(CENTEROFGRAVITY, centerOfGravity); } else { assertion1(_dim == 3, _dim); precice::utils::Vector3D centerOfGravity(_centerOfGravity); _statisticsWriter.writeData(CENTEROFGRAVITY, centerOfGravity); } _statisticsWriter.writeData(TOTALMASS, _totalMass); _statisticsWriter.writeData(TOTALVOLUME, totalVolume); }