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/mit-gfx/diff_stokes_flow
26 October 2025, 15:16:42 UTC
  • Code
  • Branches (2)
  • Releases (1)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/develop
    • refs/heads/master
    • v1.0
  • 1b30001
  • /
  • cpp
  • /
  • core
  • /
  • src
  • /
  • shape
  • /
  • shape_composition.cpp
Raw File Download
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 Iframe embedding
swh:1:cnt:9fb17d86b4ad16995e78767436c0c96db8b44f30
origin badgedirectory badge Iframe embedding
swh:1:dir:ba254e4a3e6ede3ec9819e506cadd1e9141eb296
origin badgerevision badge
swh:1:rev:55eb7c0f3a9d58a50c1a09c2231177b81e0da84e
origin badgesnapshot badge
swh:1:snp:844e2388a41ac424d434588931efb89dd8b339bf

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: 55eb7c0f3a9d58a50c1a09c2231177b81e0da84e authored by Tao Du on 11 December 2020, 03:55:44 UTC
Create LICENSE
Tip revision: 55eb7c0
shape_composition.cpp
#include "shape/shape_composition.h"
#include "common/common.h"
#include "shape/bezier.h"
#include "shape/plane.h"
#include "shape/sphere.h"
#include "shape/polar_bezier.h"

template<>
void ShapeComposition<2>::AddParametricShape(const std::string& name, const int param_num) {
    ParametricShapeInfo<2> info;
    info.name = name;
    info.param_begin_idx = 0;
    info.param_num = param_num;
    if (name == "bezier") {
        info.shape = std::make_shared<Bezier2d>();
    } else if (name == "plane") {
        info.shape = std::make_shared<Plane<2>>();
    } else if (name == "sphere") {
        info.shape = std::make_shared<Sphere<2>>();
    } else if (name == "polar_bezier") {
        // Do not flip in 2D.
        const bool flip = false;
        info.shape = std::make_shared<PolarBezier2d>(flip);
    } else {
        PrintError("Unsupported shape name: " + name);
    }
    shape_info_.push_back(info);
}

template<>
void ShapeComposition<3>::AddParametricShape(const std::string& name, const int param_num) {
    ParametricShapeInfo<3> info;
    info.name = name;
    info.param_begin_idx = 0;
    info.param_num = param_num;
    if (name == "bezier") {
        info.shape = std::make_shared<Bezier3d>();
    } else if (name == "plane") {
        info.shape = std::make_shared<Plane<3>>();
    } else if (name == "sphere") {
        info.shape = std::make_shared<Sphere<3>>();
    } else if (BeginsWith(name, "polar_bezier")) {
        // Fetch z_level_num.
        const int z_level_num_signed = std::stoi(name.substr(std::string("polar_bezier").size()));
        const bool flip = z_level_num_signed < 0;
        const int z_level_num = flip ? -z_level_num_signed : z_level_num_signed;
        info.shape = std::make_shared<PolarBezier3d>(flip, z_level_num);
    } else {
        PrintError("Unsupported shape name: " + name);
    }
    shape_info_.push_back(info);
}

template<int dim>
void ShapeComposition<dim>::InitializeCustomizedData() {
    int param_cur_idx = 0;
    for (auto& info : shape_info_) {
        info.param_begin_idx = param_cur_idx;
        const std::vector<real> shape_param(ParametricShape<dim>::params().begin() + param_cur_idx,
            ParametricShape<dim>::params().begin() + param_cur_idx + info.param_num);
        info.shape->Initialize(ParametricShape<dim>::cell_nums(), shape_param, true);
        param_cur_idx += info.param_num;
    }
}

template<int dim>
const real ShapeComposition<dim>::ComputeSignedDistanceAndGradients(const std::array<real, dim>& point,
    std::vector<real>& grad) const {
    real min_pos_dist = std::numeric_limits<real>::infinity();
    real min_neg_dist = std::numeric_limits<real>::infinity();
    std::vector<real> min_pos_dist_grad, min_neg_dist_grad;
    CheckError(!shape_info_.empty(), "You need to have at least one shape.");
    int min_pos_param_begin = 0, min_neg_param_begin = 0;
    int min_pos_param_num = 0, min_neg_param_num = 0;
    bool is_solid = false;
    for (const auto& info : shape_info_) {
        std::vector<real> shape_grad;
        const real shape_dist = info.shape->ComputeSignedDistanceAndGradients(point, shape_grad);
        if (shape_dist >= 0) {
            // This point is inside the solid phase.
            is_solid = true;
            if (shape_dist < min_pos_dist) {
                min_pos_dist = shape_dist;
                min_pos_dist_grad = shape_grad;
                min_pos_param_begin = info.param_begin_idx;
                min_pos_param_num = info.param_num;
            }
        } else {
            // This point is in the fluid phase.
            if (-shape_dist < min_neg_dist) {
                min_neg_dist = -shape_dist;
                min_neg_dist_grad = shape_grad;
                min_neg_param_begin = info.param_begin_idx;
                min_neg_param_num = info.param_num;
            }
        }
    }
    grad.clear();
    grad.resize(ParametricShape<dim>::param_num(), 0);
    if (is_solid) {
        for (int i = 0; i < min_pos_param_num; ++i)
            grad[min_pos_param_begin + i] = min_pos_dist_grad[i];
        return min_pos_dist;
    } else {
        for (int i = 0; i < min_neg_param_num; ++i)
            grad[min_neg_param_begin + i] = min_neg_dist_grad[i];
        return -min_neg_dist;
    }
}

template class ParametricShapeInfo<2>;
template class ParametricShapeInfo<3>;
template class ShapeComposition<2>;
template class ShapeComposition<3>;

back to top

Software Heritage — Copyright (C) 2015–2025, 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