Loading [MathJax]/extensions/tex2jax.js
libMesh
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Private Member Functions | List of all members
PeriodicBCTest Class Reference
Inheritance diagram for PeriodicBCTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (PeriodicBCTest)
 
 CPPUNIT_TEST (testPeriodicLagrange2)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void testPeriodicBC (FEType fe_type)
 
void testPeriodicLagrange2 ()
 

Detailed Description

Definition at line 161 of file periodic_bc_test.C.

Member Function Documentation

◆ CPPUNIT_TEST()

PeriodicBCTest::CPPUNIT_TEST ( testPeriodicLagrange2  )

◆ CPPUNIT_TEST_SUITE_END()

PeriodicBCTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

PeriodicBCTest::LIBMESH_CPPUNIT_TEST_SUITE ( PeriodicBCTest  )

◆ testPeriodicBC()

void PeriodicBCTest::testPeriodicBC ( FEType  fe_type)
inlineprivate

Definition at line 175 of file periodic_bc_test.C.

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::DofMap::add_periodic_boundary(), libMesh::BoundaryInfo::add_side(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_remote_element_removal(), libMesh::System::attach_assemble_function(), bottom_id, libMesh::MeshBase::delete_remote_elements(), libMesh::MeshBase::get_boundary_info(), libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::libmesh_real(), mesh, libMesh::PeriodicBoundaryBase::myboundary, libMesh::PeriodicBoundaryBase::pairedboundary, periodic_bc_test_poisson(), libMesh::System::point_value(), quadratic_solution(), libMesh::MeshBase::read(), libMesh::Real, side_id, libMesh::LinearImplicitSystem::solve(), TestCommWorld, libMesh::TOLERANCE, top_id, and libMesh::ExodusII_IO::write_equation_systems().

176  {
178  BoundaryInfo & boundary = mesh.get_boundary_info();
179 
180  EquationSystems es(mesh);
181  LinearImplicitSystem &sys =
182  es.add_system<LinearImplicitSystem> ("PBCSys");
183 
184  // We need to change around BCIDs and set up the periodic BC first
186 
187  mesh.read("meshes/shark_tooth_tri6.xda.gz");
188 
189  // Add some BCIDs on top and bottom for our periodic boundary
190  for (const Elem * elem : mesh.active_element_ptr_range())
191  {
192  for (unsigned int s=0; s != 3; ++s)
193  if (!elem->neighbor_ptr(s))
194  {
195  unsigned v2 = (s+1)%3;
196  // Left-running edges are on bottom, because this xda
197  // has a flipped mesh
198  if (elem->point(s)(0) - elem->point(v2)(0) < -.1)
199  boundary.add_side(elem, s, top_id);
200 
201  // Right-running edges are on top
202  else if (elem->point(s)(0) - elem->point(v2)(0) > .1)
203  boundary.add_side(elem, s, bottom_id);
204 
205  // Vertical edges are Dirichlet
206  else
207  boundary.add_side(elem, s, side_id);
208  }
209  }
210 
211  PeriodicBoundary vert(RealVectorValue(0., 4.0));
212  vert.myboundary = bottom_id;
213  vert.pairedboundary = top_id;
215 
216  // Okay, *now* the mesh knows to save periodic neighbors
219 
220  const unsigned int u_var = sys.add_variable("u", fe_type);
222 
223  std::set<boundary_id_type> side_bdy { side_id };
224  std::vector<unsigned int> all_vars (1, u_var);
226  DirichletBoundary exact_bc(side_bdy, all_vars, exact_val);
227  sys.get_dof_map().add_dirichlet_boundary(exact_bc);
228 
229  es.init();
230 
231  sys.solve();
232 
233  ExodusII_IO(mesh).write_equation_systems("periodic.e", es);
234 
235  Parameters params;
236 
237  for (Real x = 0.1; x < 10; x += 0.2)
238  for (Real ya = -2.9; ya < 1; ya += 0.2)
239  {
240  // Integrate the sharktooth shape
241  const Real offset = 1-std::abs(std::fmod(x,2)-1);
242  const Real y = ya + offset;
243  Point p{x,y};
244  const Number exact = quadratic_solution(p,params,"","");
245  const Number approx = sys.point_value(0,p);
246  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(exact),
247  libmesh_real(approx),
248  TOLERANCE*TOLERANCE*20);
249  }
250  }
T libmesh_real(T a)
Wrap a libMesh-style function pointer into a FunctionBase object.
This is the EquationSystems class.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
void add_periodic_boundary(const PeriodicBoundaryBase &periodic_boundary)
Adds a copy of the specified periodic boundary to the system.
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:67
VectorValue< Real > RealVectorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:52
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
const boundary_id_type side_id
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2399
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
The definition of a periodic boundary.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:160
virtual void solve() override
Assembles & solves the linear system A*x=b.
void allow_remote_element_removal(bool allow)
If false is passed in then this mesh will no longer have remote elements deleted when being prepared ...
Definition: mesh_base.h:1207
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
Definition: exodusII_io.C:2013
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
Definition: boundary_info.h:57
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1335
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
Definition: system.C:2139
const boundary_id_type top_id
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure...
void periodic_bc_test_poisson(EquationSystems &es, const std::string &)
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
virtual void delete_remote_elements()
When supported, deletes all nonlocal elements of the mesh except for "ghosts" which touch a local ele...
Definition: mesh_base.h:248
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
const DofMap & get_dof_map() const
Definition: system.h:2370
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
const boundary_id_type bottom_id
Number quadratic_solution(const Point &p, const Parameters &, const std::string &, const std::string &)

◆ testPeriodicLagrange2()

void PeriodicBCTest::testPeriodicLagrange2 ( )
inlineprivate

Definition at line 253 of file periodic_bc_test.C.

References libMesh::LAGRANGE, and libMesh::SECOND.

253 { LOG_UNIT_TEST; testPeriodicBC(FEType(SECOND, LAGRANGE)); }
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:196
void testPeriodicBC(FEType fe_type)

The documentation for this class was generated from the following file: