Hi all,
I'm trying to test some functionalities in DMPlex, specifically I want to do a 2d fem simulation using a mesh generated by GMSH.
At this point I am trying to understand how Dirichlet BC can be applied.

Can you explain to me what arguments I have to pass to:
DMPlexAddBoundary()?

I am attaching a little bit of c code and my mesh.geo and mesh.msh so that you understand the context.
The BCs I want to apply are displacement of 0.2 in the y direction if y==1.0
0.0 in the x direction if y==0.0

--
Best,
Luc

static char help[] = "We load a 2d mesh from msh file and create a corresponding DMPlex.\n\n\n";

#include <petscdmplex.h>
#include <petscksp.h>
#include <petscds.h>

void top_displacement(const PetscReal x[], PetscScalar *u, void *ctx)
{
  *u = x[1]==0.0? 0.0:0.2;
}

#undef __FUNCT__
#define __FUNCT__ "main"
int main(int argc, char **argv)
{
  MPI_Comm        comm;
  DM              dm;
  KSP             ksp;
  Vec             u,r;
  PetscErrorCode  ierr;

  const char *    filename = "/home/luc/research/simulations/Petsc_DMPlex/simple_test/square.msh";
  
  ierr = PetscInitialize(&argc, &argv, (char *)0, help);CHKERRQ(ierr);
  comm = PETSC_COMM_WORLD;
  
  //Create the DM using a gmsh file
  ierr = DMPlexCreateFromFile(comm, filename, PETSC_TRUE, &dm);CHKERRQ(ierr);
  ierr = DMPlexSetRefinementUniform(dm, PETSC_FALSE);CHKERRQ(ierr);
  ierr = DMPlexAddBoundary(dm, PETSC_TRUE,"wall","marker",(void (*)())top_displacement,1,&id,user)
  /* Must have boundary marker for Dirichlet conditions */
  ierr = DMViewFromOptions(dm, NULL, "-dm_view");CHKERRQ(ierr);
  
  ierr = KSPCreate(comm, &ksp);CHKERRQ(ierr);
  ierr = KSPSetDM(ksp, dm);CHKERRQ(ierr);
  
  ierr = PetscFinalize();
  return(0);
}
// Gmsh project created on Wed May 29 23:30:10 2013
// Light Options
General.Light0X = -0.70;
General.Light0Y = -0.70;
General.Light0Z = 0;

// Mesh Options
Mesh.RecombineAll=1; 
Mesh.Algorithm=8; 
Mesh.SubdivisionAlgorithm=1;
Mesh.ColorCarousel=0;
Mesh.Smoothing = 10; // Elliptic smoother

// Parameters
pw  = 1.0E-5; // Plate width
xx  = 100;
nn  = xx/2+1; // Number of nodes on each side of the square
pr  = 1.0;    // Progression of element sizes 
cl1 = 0.2;   // Mesh size - Not used in structured

// Nodes
//   4---3
//   |   |
//   1---2
Point(1) = {0, 0, 0, cl1};
Point(2) = {1, 0, 0, cl1};
Point(3) = {1, 1, 0, cl1};
Point(4) = {0, 1, 0, cl1};

// Exterior sides of the Square
//  4--iii--3
//  |       |
//  iv      ii
//  |       |
//  1-- i --2
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};

// Surface
Line Loop(6) = { 1, 2, 3, 4};
Ruled Surface(7) = {6};

// Physical Surface
Physical Surface(1) = {7};
Physical Line(10) = {1};
Physical Line(11) = {2};
Physical Line(12) = {3};
Physical Line(13) = {4};
#Physical Line("bottom") = {1};
#Physical Line("right") = {2};
#Physical Line("left") = {3};
#Physical Line("top") = {4};

Attachment: square.msh
Description: Mesh model

Reply via email to