Skip to content

Instantly share code, notes, and snippets.

View jwpeterson's full-sized avatar

John W. Peterson jwpeterson

View GitHub Profile
@jwpeterson
jwpeterson / test_mixed_dimension_refinement.cc
Created August 10, 2022 21:09
Mixed-dimension refinement test that hits an assert in debug mode
// libMesh includes
#include "libmesh/libmesh.h"
#include "libmesh/elem.h"
#include "libmesh/mesh_generation.h"
#include "libmesh/replicated_mesh.h"
#include "libmesh/mesh_refinement.h"
using namespace libMesh;
int main (int argc, char** argv)
@jwpeterson
jwpeterson / unique_ptr_bind.C
Last active November 2, 2024 05:55
Use non-static member function for std::unique_ptr deleter
// Example of how a non-static member function can be used as the "deleter" for a std::unique_ptr via std::bind.
// Note: this approach incurs an additional overhead per unique_ptr object to store a pointer to the deleter
// function, so it may not be appropriate in cases where zero-overhead unique_pts are required.
// Source: https://stackoverflow.com/questions/29525370/how-to-pass-a-non-static-member-function-as-a-unique-ptr-deleter
#include <memory>
#include <iostream>
#include <functional>
#include <exception>
/**
@jwpeterson
jwpeterson / set_unique_ptr.C
Created April 19, 2022 20:35
Demonstration of C++14 is_transparent comparison object with std::set
#include <set>
#include <memory>
#include <iostream>
template <typename Container>
void print_address(const Container & c)
{
std::cout << "address of underlying" << std::endl;
for (const auto & ptr : c)
std::cout << ptr.get() << std::endl;
@jwpeterson
jwpeterson / stlsizeof.cpp
Last active November 2, 2024 05:56
stlsizeof.cpp
// clang++ -std=c++11 -o stlsizeof stlsizeof.cpp
#include <cstdint>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <cstdint>
#include <iostream>
@jwpeterson
jwpeterson / print_matlab_to_python.C
Created April 7, 2021 21:13
Convert the output of PetscMatrix::print_matlab() to a format which can be used in Python
// C++ header files
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdlib> // std::exit
#include <getopt.h> // getopt_long()
void usage(const char * progname)
// libmesh includes
#include "libmesh/libmesh.h"
#include "libmesh/mesh.h"
#include "libmesh/elem.h"
#include "libmesh/fe.h"
#include "libmesh/quadrature_gauss.h"
#include "libmesh/dense_vector.h"
#include "libmesh/dense_matrix.h"
using namespace libMesh;
@jwpeterson
jwpeterson / type_tensor_axpy_performance.cc
Created December 19, 2020 06:00
Comparison of A*x + y for RealTensorValue, DenseMatrix, and Eigen::Matrix3d
// Basic include file needed for the mesh functionality.
#include "libmesh/libmesh.h"
#include "libmesh/mesh.h"
#include "libmesh/dof_map.h"
#include "libmesh/elem.h"
#include "libmesh/fe_interface.h"
#include "libmesh/fe_map.h"
#include "libmesh/fe_base.h"
#include "libmesh/quadrature_gauss.h"
#include "libmesh/enum_to_string.h"
@jwpeterson
jwpeterson / type_tensor_ABC_performance.cc
Created December 19, 2020 05:59
Comparison of matrix-matrix-matrix product for RealTensorValue, DenseMatrix, and Eigen::Matrix3d
// Basic include file needed for the mesh functionality.
#include "libmesh/libmesh.h"
#include "libmesh/mesh.h"
#include "libmesh/dof_map.h"
#include "libmesh/elem.h"
#include "libmesh/fe_interface.h"
#include "libmesh/fe_map.h"
#include "libmesh/fe_base.h"
#include "libmesh/quadrature_gauss.h"
#include "libmesh/enum_to_string.h"
#!/usr/bin/env python
import sys
import os
name = ''
# Process command line args (0 is always the script name)
c = 1
while (c < len(sys.argv)):
#include "libmesh/mesh_generation.h"
#include "libmesh/mesh.h"
#include "libmesh/elem.h"
#include "libmesh/getpot.h"
#include "libmesh/string_to_enum.h"
#include "libmesh/elem_range.h"
// C++ includes
#include <chrono>