Skip to content

Instantly share code, notes, and snippets.

@andrewseidl
Last active April 10, 2024 04:10
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save andrewseidl/8066c18e97c40086c183 to your computer and use it in GitHub Desktop.
Save andrewseidl/8066c18e97c40086c183 to your computer and use it in GitHub Desktop.
Clang-format style comparison

This is a comparison of the different formatting styles including with clang-format.

Generated via:

styles=( LLVM Google Chromium Mozilla WebKit )
for style in $styles
do
  clang-format -style=$style ChLcpIterativeAPGD.h > ChLcpIterativeAPGD.$style.h
done
//
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2013 Project Chrono
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file at the top level of the distribution
// and at http://projectchrono.org/license-chrono.txt.
//
#ifndef CHITERATIVEAPGD_H
#define CHITERATIVEAPGD_H
//////////////////////////////////////////////////
//
// ChLcpIterativeAPGD.h
//
// An iterative solver based on Nesterov's
// Projected Gradient Descent
//
// HEADER file for CHRONO HYPEROCTANT LCP solver
//
// ------------------------------------------------
// www.deltaknowledge.com
// ------------------------------------------------
///////////////////////////////////////////////////
#include "ChLcpIterativeSolver.h"
namespace chrono {
/// An iterative solver based on Nesterov's
/// Projected Gradient Descent.
/// The problem is described by an LCP of type
///
/// | M -Cq'|*|q|- | f|= |0| , c>=0, l>=0, l*c=0;
/// | Cq 0 | |l| |-b| |c|
///
/// or similar CCP problem.
class ChApi ChIterativeAPGD : public ChLcpIterativeSolver {
protected:
//
// DATA
//
double residual;
int nc;
ChMatrixDynamic<> gamma_hat, gammaNew, g, y, gamma, yNew, r, tmp;
public:
//
// CONSTRUCTORS
//
ChIterativeAPGD(int mmax_iters = 1000, ///< max.number of iterations
bool mwarm_start = false, ///< uses warm start?
double mtolerance =
0.0 ///< tolerance for termination criterion
)
: ChLcpIterativeSolver(mmax_iters, mwarm_start, mtolerance, 0.0001) {};
virtual ~ChIterativeAPGD() {};
//
// FUNCTIONS
//
// Performs the solution of the LCP.
virtual double Solve(ChLcpSystemDescriptor& sysd);
void ShurBvectorCompute(ChLcpSystemDescriptor& sysd);
double Res4(ChLcpSystemDescriptor& sysd);
double GetResidual() { return residual; }
void Dump_Rhs(std::vector<double>& temp) {
for (int i = 0; i < r.GetRows(); i++) {
temp.push_back(r(i, 0));
}
}
void Dump_Lambda(std::vector<double>& temp) {
for (int i = 0; i < gamma_hat.GetRows(); i++) {
temp.push_back(gamma_hat(i, 0));
}
}
};
} // END_OF_NAMESPACE____
#endif // END of ChLcpIterativeAPGD.h
//
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2013 Project Chrono
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file at the top level of the distribution
// and at http://projectchrono.org/license-chrono.txt.
//
#ifndef CHITERATIVEAPGD_H
#define CHITERATIVEAPGD_H
//////////////////////////////////////////////////
//
// ChLcpIterativeAPGD.h
//
// An iterative solver based on Nesterov's
// Projected Gradient Descent
//
// HEADER file for CHRONO HYPEROCTANT LCP solver
//
// ------------------------------------------------
// www.deltaknowledge.com
// ------------------------------------------------
///////////////////////////////////////////////////
#include "ChLcpIterativeSolver.h"
namespace chrono {
/// An iterative solver based on Nesterov's
/// Projected Gradient Descent.
/// The problem is described by an LCP of type
///
/// | M -Cq'|*|q|- | f|= |0| , c>=0, l>=0, l*c=0;
/// | Cq 0 | |l| |-b| |c|
///
/// or similar CCP problem.
class ChApi ChIterativeAPGD : public ChLcpIterativeSolver {
protected:
//
// DATA
//
double residual;
int nc;
ChMatrixDynamic<> gamma_hat, gammaNew, g, y, gamma, yNew, r, tmp;
public:
//
// CONSTRUCTORS
//
ChIterativeAPGD(int mmax_iters = 1000, ///< max.number of iterations
bool mwarm_start = false, ///< uses warm start?
double mtolerance =
0.0 ///< tolerance for termination criterion
)
: ChLcpIterativeSolver(mmax_iters, mwarm_start, mtolerance, 0.0001) {};
virtual ~ChIterativeAPGD() {};
//
// FUNCTIONS
//
// Performs the solution of the LCP.
virtual double Solve(ChLcpSystemDescriptor& sysd);
void ShurBvectorCompute(ChLcpSystemDescriptor& sysd);
double Res4(ChLcpSystemDescriptor& sysd);
double GetResidual() { return residual; }
void Dump_Rhs(std::vector<double>& temp) {
for (int i = 0; i < r.GetRows(); i++) {
temp.push_back(r(i, 0));
}
}
void Dump_Lambda(std::vector<double>& temp) {
for (int i = 0; i < gamma_hat.GetRows(); i++) {
temp.push_back(gamma_hat(i, 0));
}
}
};
} // END_OF_NAMESPACE____
#endif // END of ChLcpIterativeAPGD.h
//
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2013 Project Chrono
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file at the top level of the distribution
// and at http://projectchrono.org/license-chrono.txt.
//
#ifndef CHITERATIVEAPGD_H
#define CHITERATIVEAPGD_H
//////////////////////////////////////////////////
//
// ChLcpIterativeAPGD.h
//
// An iterative solver based on Nesterov's
// Projected Gradient Descent
//
// HEADER file for CHRONO HYPEROCTANT LCP solver
//
// ------------------------------------------------
// www.deltaknowledge.com
// ------------------------------------------------
///////////////////////////////////////////////////
#include "ChLcpIterativeSolver.h"
namespace chrono
{
/// An iterative solver based on Nesterov's
/// Projected Gradient Descent.
/// The problem is described by an LCP of type
///
/// | M -Cq'|*|q|- | f|= |0| , c>=0, l>=0, l*c=0;
/// | Cq 0 | |l| |-b| |c|
///
/// or similar CCP problem.
class ChApi ChIterativeAPGD : public ChLcpIterativeSolver
{
protected:
//
// DATA
//
double residual;
int nc;
ChMatrixDynamic<> gamma_hat, gammaNew, g, y, gamma, yNew, r, tmp;
public:
//
// CONSTRUCTORS
//
ChIterativeAPGD(
int mmax_iters=1000, ///< max.number of iterations
bool mwarm_start=false, ///< uses warm start?
double mtolerance=0.0 ///< tolerance for termination criterion
)
: ChLcpIterativeSolver(mmax_iters,mwarm_start, mtolerance,0.0001)
{
};
virtual ~ChIterativeAPGD() {};
//
// FUNCTIONS
//
// Performs the solution of the LCP.
virtual double Solve(ChLcpSystemDescriptor& sysd);
void ShurBvectorCompute(ChLcpSystemDescriptor& sysd);
double Res4(ChLcpSystemDescriptor& sysd);
double GetResidual(){
return residual;
}
void Dump_Rhs(std::vector<double> &temp){
for (int i=0; i<r.GetRows(); i++){
temp.push_back(r(i,0));
}
}
void Dump_Lambda(std::vector<double> &temp){
for (int i=0; i<gamma_hat.GetRows(); i++){
temp.push_back(gamma_hat(i,0));
}
}
};
} // END_OF_NAMESPACE____
#endif // END of ChLcpIterativeAPGD.h
//
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2013 Project Chrono
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file at the top level of the distribution
// and at http://projectchrono.org/license-chrono.txt.
//
#ifndef CHITERATIVEAPGD_H
#define CHITERATIVEAPGD_H
//////////////////////////////////////////////////
//
// ChLcpIterativeAPGD.h
//
// An iterative solver based on Nesterov's
// Projected Gradient Descent
//
// HEADER file for CHRONO HYPEROCTANT LCP solver
//
// ------------------------------------------------
// www.deltaknowledge.com
// ------------------------------------------------
///////////////////////////////////////////////////
#include "ChLcpIterativeSolver.h"
namespace chrono {
/// An iterative solver based on Nesterov's
/// Projected Gradient Descent.
/// The problem is described by an LCP of type
///
/// | M -Cq'|*|q|- | f|= |0| , c>=0, l>=0, l*c=0;
/// | Cq 0 | |l| |-b| |c|
///
/// or similar CCP problem.
class ChApi ChIterativeAPGD : public ChLcpIterativeSolver {
protected:
//
// DATA
//
double residual;
int nc;
ChMatrixDynamic<> gamma_hat, gammaNew, g, y, gamma, yNew, r, tmp;
public:
//
// CONSTRUCTORS
//
ChIterativeAPGD(int mmax_iters = 1000, ///< max.number of iterations
bool mwarm_start = false, ///< uses warm start?
double mtolerance =
0.0 ///< tolerance for termination criterion
)
: ChLcpIterativeSolver(mmax_iters, mwarm_start, mtolerance, 0.0001) {};
virtual ~ChIterativeAPGD() {};
//
// FUNCTIONS
//
// Performs the solution of the LCP.
virtual double Solve(ChLcpSystemDescriptor &sysd);
void ShurBvectorCompute(ChLcpSystemDescriptor &sysd);
double Res4(ChLcpSystemDescriptor &sysd);
double GetResidual() { return residual; }
void Dump_Rhs(std::vector<double> &temp) {
for (int i = 0; i < r.GetRows(); i++) {
temp.push_back(r(i, 0));
}
}
void Dump_Lambda(std::vector<double> &temp) {
for (int i = 0; i < gamma_hat.GetRows(); i++) {
temp.push_back(gamma_hat(i, 0));
}
}
};
} // END_OF_NAMESPACE____
#endif // END of ChLcpIterativeAPGD.h
//
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2013 Project Chrono
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file at the top level of the distribution
// and at http://projectchrono.org/license-chrono.txt.
//
#ifndef CHITERATIVEAPGD_H
#define CHITERATIVEAPGD_H
//////////////////////////////////////////////////
//
// ChLcpIterativeAPGD.h
//
// An iterative solver based on Nesterov's
// Projected Gradient Descent
//
// HEADER file for CHRONO HYPEROCTANT LCP solver
//
// ------------------------------------------------
// www.deltaknowledge.com
// ------------------------------------------------
///////////////////////////////////////////////////
#include "ChLcpIterativeSolver.h"
namespace chrono {
/// An iterative solver based on Nesterov's
/// Projected Gradient Descent.
/// The problem is described by an LCP of type
///
/// | M -Cq'|*|q|- | f|= |0| , c>=0, l>=0, l*c=0;
/// | Cq 0 | |l| |-b| |c|
///
/// or similar CCP problem.
class ChApi ChIterativeAPGD : public ChLcpIterativeSolver {
protected:
//
// DATA
//
double residual;
int nc;
ChMatrixDynamic<> gamma_hat, gammaNew, g, y, gamma, yNew, r, tmp;
public:
//
// CONSTRUCTORS
//
ChIterativeAPGD(int mmax_iters = 1000, ///< max.number of iterations
bool mwarm_start = false, ///< uses warm start?
double mtolerance =
0.0 ///< tolerance for termination criterion
)
: ChLcpIterativeSolver(mmax_iters, mwarm_start, mtolerance, 0.0001) {};
virtual ~ChIterativeAPGD() {};
//
// FUNCTIONS
//
// Performs the solution of the LCP.
virtual double Solve(ChLcpSystemDescriptor& sysd);
void ShurBvectorCompute(ChLcpSystemDescriptor& sysd);
double Res4(ChLcpSystemDescriptor& sysd);
double GetResidual() { return residual; }
void Dump_Rhs(std::vector<double>& temp) {
for (int i = 0; i < r.GetRows(); i++) {
temp.push_back(r(i, 0));
}
}
void Dump_Lambda(std::vector<double>& temp) {
for (int i = 0; i < gamma_hat.GetRows(); i++) {
temp.push_back(gamma_hat(i, 0));
}
}
};
} // END_OF_NAMESPACE____
#endif // END of ChLcpIterativeAPGD.h
//
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2013 Project Chrono
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file at the top level of the distribution
// and at http://projectchrono.org/license-chrono.txt.
//
#ifndef CHITERATIVEAPGD_H
#define CHITERATIVEAPGD_H
//////////////////////////////////////////////////
//
// ChLcpIterativeAPGD.h
//
// An iterative solver based on Nesterov's
// Projected Gradient Descent
//
// HEADER file for CHRONO HYPEROCTANT LCP solver
//
// ------------------------------------------------
// www.deltaknowledge.com
// ------------------------------------------------
///////////////////////////////////////////////////
#include "ChLcpIterativeSolver.h"
namespace chrono {
/// An iterative solver based on Nesterov's
/// Projected Gradient Descent.
/// The problem is described by an LCP of type
///
/// | M -Cq'|*|q|- | f|= |0| , c>=0, l>=0, l*c=0;
/// | Cq 0 | |l| |-b| |c|
///
/// or similar CCP problem.
class ChApi ChIterativeAPGD : public ChLcpIterativeSolver {
protected:
//
// DATA
//
double residual;
int nc;
ChMatrixDynamic<> gamma_hat, gammaNew, g, y, gamma, yNew, r, tmp;
public:
//
// CONSTRUCTORS
//
ChIterativeAPGD(
int mmax_iters = 1000, ///< max.number of iterations
bool mwarm_start = false, ///< uses warm start?
double mtolerance = 0.0 ///< tolerance for termination criterion
)
: ChLcpIterativeSolver(mmax_iters, mwarm_start, mtolerance, 0.0001) {};
virtual ~ChIterativeAPGD() {};
//
// FUNCTIONS
//
// Performs the solution of the LCP.
virtual double Solve(ChLcpSystemDescriptor& sysd);
void ShurBvectorCompute(ChLcpSystemDescriptor& sysd);
double Res4(ChLcpSystemDescriptor& sysd);
double GetResidual()
{
return residual;
}
void Dump_Rhs(std::vector<double>& temp)
{
for (int i = 0; i < r.GetRows(); i++) {
temp.push_back(r(i, 0));
}
}
void Dump_Lambda(std::vector<double>& temp)
{
for (int i = 0; i < gamma_hat.GetRows(); i++) {
temp.push_back(gamma_hat(i, 0));
}
}
};
} // END_OF_NAMESPACE____
#endif // END of ChLcpIterativeAPGD.h
// Chromium
void function_addForces(int& index,
bool* active,
real* mass,
real3* inertia,
real3* forces,
real3* torques,
real3* vel,
real3* omega) {
if (active[index] != 0) {
// v += m_inv * h * f
vel[index] += forces[index] * mass[index];
// w += J_inv * h * c
omega[index] += torques[index] * inertia[index];
}
}
// Google
void function_addForces(int& index, bool* active, real* mass, real3* inertia,
real3* forces, real3* torques, real3* vel,
real3* omega) {
if (active[index] != 0) {
// v += m_inv * h * f
vel[index] += forces[index] * mass[index];
// w += J_inv * h * c
omega[index] += torques[index] * inertia[index];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment