Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/penn-graphics-research/ziran2019
23 July 2020, 12:09:27 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    No releases to show
  • 0bca774
  • /
  • Lib
  • /
  • Ziran
  • /
  • Physics
  • /
  • LagrangianForce
  • /
  • Inertia.cpp
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:90a328c91e0fae54cac19af1d48e443c2690e8b5
origin badgedirectory badge
swh:1:dir:ea55178cc494830ba91a72f11883ac1d673f9dc9
origin badgerevision badge
swh:1:rev:8d3d27cd17bbceab18c317820dbe595178f6312a
origin badgesnapshot badge
swh:1:snp:60d230fd23a15f9241785ee90478bf9722d99dac

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 8d3d27cd17bbceab18c317820dbe595178f6312a authored by fangy14 on 06 November 2019, 07:20:57 UTC
open source
Tip revision: 8d3d27c
Inertia.cpp
#include <Ziran/CS/Util/Logging.h>
#include <Ziran/Physics/LagrangianForce/Inertia.h>

namespace ZIRAN {

template <class T, int dim>
MassLumpedInertia<T, dim>::MassLumpedInertia(const Vec& mass_matrix, const TVStack& dv, const T& dt)
    : mass_matrix(mass_matrix)
    , dv(dv)
    , dt(dt)
{
}

// E
template <class T, int dim>
T MassLumpedInertia<T, dim>::totalEnergy() const
{
    T ke = tbb::parallel_reduce(tbb::blocked_range<int>(0, dv.cols(), 256), (T)0,
        [&](const tbb::blocked_range<int>& range, T ns) -> T {
            int start = range.begin();
            int length = (range.end() - range.begin());
            const auto& dv_block = dv.middleCols(start, length);
            const auto& mass_block = mass_matrix.segment(start, length).transpose();
            return ns + ((dv_block.colwise().squaredNorm()).array() * mass_block.array()).sum();
        },
        [](T a, T b) -> T { return a + b; });
    // ZIRAN_INFO("Inertia Called ", ke);
    return ke / 2;
}

// f= -dE/dx
template <class T, int dim>
void MassLumpedInertia<T, dim>::addScaledForces(T scale, TVStack& forces) const
{
    scale /= dt; // dE/dx = ddv/dx dE/ddv = 1/dt dE/ddv
    tbb::parallel_for(tbb::blocked_range<int>(0, forces.cols(), 256),
        [&](const tbb::blocked_range<int>& range) {
            for (int p = range.begin(), s = range.end(); p < s; p++)
                forces.col(p) -= scale * mass_matrix(p) * dv.col(p);
        });
}

// df
template <class T, int dim>
void MassLumpedInertia<T, dim>::addScaledForceDifferential(T scale, const TVStack& dx, TVStack& df) const
{
    scale /= dt * dt;
    tbb::parallel_for(tbb::blocked_range<int>(0, df.cols(), 256),
        [&](const tbb::blocked_range<int>& range) {
            for (int p = range.begin(), s = range.end(); p < s; p++)
                df.col(p) -= scale * mass_matrix(p) * dx.col(p);
        });
}

// -df/dx
template <class T, int dim>
void MassLumpedInertia<T, dim>::addScaledStiffnessEntries(T scale, Eigen::SparseMatrix<T, Eigen::RowMajor>& newton_matrix) const
{
    //mass matrix
    scale /= dt * dt;
    for (int p = 0; p < mass_matrix.rows(); p++) {
        for (int d = 0; d < dim; d++) {
            int index = p * dim + d;
            newton_matrix.coeffRef(index, index) += scale * mass_matrix(p);
        }
    }
}

template <class T, int dim>
void MassLumpedInertia<T, dim>::initializeStiffnessSparsityPattern(StdVector<Eigen::Triplet<T>>& tripletList) const
{
    tripletList.reserve(tripletList.size() + dim * mass_matrix.rows());
    for (int p = 0; p < dim * mass_matrix.rows(); p++)
        tripletList.emplace_back(p, p, (T)0);
}
template class MassLumpedInertia<double, 2>;
template class MassLumpedInertia<double, 3>;
template class MassLumpedInertia<float, 2>;
template class MassLumpedInertia<float, 3>;
} // namespace ZIRAN

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API