Skip to content

Instantly share code, notes, and snippets.

View jwpeterson's full-sized avatar

John W. Peterson jwpeterson

View GitHub Profile
#include "libmesh/node.h"
#include "libmesh/elem.h"
#include "libmesh/mesh.h"
#include "libmesh/face_tri3.h"
#include "libmesh/getpot.h"
using namespace libMesh;
// Commands to approximately generate the Bassi & Rebay meshes:
// In my opinion, the meshes look best when nodes_per_ring = 2 * num_rings
@jwpeterson
jwpeterson / default_destructor.C
Created June 6, 2018 20:04
Defaulted destructors inhibit move constructor generation
#include <iostream>
#include <vector>
struct S
{
S(const S&) { std::cout << "Copied an S\n"; }
S(S&&) { std::cout << "Moved an S\n"; }
S() = default;
// C++ include files that we need
#include <iostream>
// Basic include files needed for the mesh functionality.
#include "libmesh/libmesh.h"
#include "libmesh/mesh.h"
#include "libmesh/mesh_generation.h"
#include "libmesh/linear_implicit_system.h"
#include "libmesh/equation_systems.h"
#include "libmesh/exodusII_io.h"
@jwpeterson
jwpeterson / noncopyable.C
Last active February 15, 2023 15:35
Demonstrate usage of noncopyable class in std containers
// Compilation requires -std=c++17
// http://stackoverflow.com/questions/17603666/copy-move-requirements-for-the-key-value-types-in-a-stdmap
#include <map>
#include <vector>
struct foo
{
int i;
foo(int j) : i(j) {}
// An FEM formulation for solving the Jeffery-Hamel ODE:
// f''' + 2 * alpha * Re * f * f' + 4 * alpha^2 * f' = 0
// using C1 Hermite cubic and quartic finite elements.
// Libmesh includes
#include "libmesh/mesh.h"
#include "libmesh/elem.h"
#include "libmesh/mesh_generation.h"
#include "libmesh/equation_systems.h"
#include "libmesh/linear_implicit_system.h"
// MPI headers so we can make a parallel example
#include <mpi.h>
// Suppress warnings about missing overrides in VTK headers
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
#endif
#include "vtkVersionMacros.h"
// Originally got this code from http://www.vtk.org/Wiki/VTK_Autoconf
// 5.x
// #include "vtkConfigure.h"
// 7.x
// Suppress warnings about missing overrides in VTK headers
#ifdef __clang__
#pragma clang diagnostic push
"""
This script solves the 3rd-order Jeffery-Hamel ODE:
f''' + 2*Re*alpha*f*f' + 4*alpha*alpha*f' = 0
f(0) = 1
f(1) = 0
f'(0) = 0
as three ODEs:
#include "libmesh/libmesh.h"
#include "libmesh/mesh.h"
#include "libmesh/mesh_generation.h"
#include "libmesh/elem.h"
#include "libmesh/fe.h"
#include "libmesh/quadrature_gauss.h"
#include "libmesh/getpot.h"
#include "libmesh/mesh_modification.h"
#include "libmesh/cell_hex27.h"
#include <iostream>
#include <vector>
#include <chrono>
#include <stdlib.h> // RAND_MAX
// In this case, N is a compile time global constant.
const unsigned int N = 1000;
typedef double ** Matrix;