Beispiel #1
0
int main(int argc, char *argv[])
{
  Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); // initialize MPI
  int rank = Teuchos::GlobalMPISession::getRank();
  
  Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
  
  string meshFileName;
  bool readInParallel = true;
  
  cmdp.setOption("meshFile", &meshFileName );
  cmdp.setOption("readDistributed", "readReplicated", &readInParallel );
  
  if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
  {
#ifdef HAVE_MPI
    MPI_Finalize();
#endif
    return -1;
  }
  
  MeshTopologyPtr meshTopo = MeshFactory::importMOABMesh(meshFileName, readInParallel);
  
  int spaceDim = meshTopo->getDimension();
  int cellCount = meshTopo->activeCellCount();
  if (rank==0) cout << spaceDim << "D mesh topology has " << cellCount << " cells.\n";
  
  return 0;
}
Beispiel #2
0
MeshTopologyPtr MeshTopologyTests::makeHexMesh(double x0, double y0, double z0, double width, double height, double depth,
    unsigned horizontalCells, unsigned verticalCells, unsigned depthCells)
{
  unsigned spaceDim = 3;
  MeshTopologyPtr mesh = Teuchos::rcp( new MeshTopology(spaceDim) );
  double dx = width / horizontalCells;
  double dy = height / verticalCells;
  double dz = depth / depthCells;
  CellTopoPtrLegacy hexTopo = Teuchos::rcp( new shards::CellTopology(shards::getCellTopologyData<shards::Hexahedron<8> >() ) );
  for (unsigned i=0; i<horizontalCells; i++)
  {
    double x = x0 + dx * i;
    for (unsigned j=0; j<verticalCells; j++)
    {
      double y = y0 + dy * j;
      for (unsigned k=0; k<depthCells; k++)
      {
        double z = z0 + dz * k;
        vector< vector<double> > vertices = hexPoints(x, y, z, dx, dy, dz);
        mesh->addCell(hexTopo, vertices);
      }
    }
  }
  return mesh;
}
Beispiel #3
0
CellTopoPtrLegacy getBottomTopology(MeshTopologyPtr meshTopo, IndexType cellID) {
  int spaceDim = meshTopo->getSpaceDim() - 1;
  // determine cell topology:
  vector<IndexType> cellVertexIndices = meshTopo->getCell(cellID)->vertices();
  set<IndexType> bottomVertexIndices;
  int bottomNodeCount = cellVertexIndices.size() / 2;
  for (int i=0; i<bottomNodeCount; i++) {
    bottomVertexIndices.insert(cellVertexIndices[i]);
  }
  IndexType bottomEntityIndex = meshTopo->getEntityIndex(spaceDim, bottomVertexIndices);
  unsigned bottomCellTopoKey = meshTopo->getEntityTopology(spaceDim, bottomEntityIndex).getKey();
  CellTopoPtrLegacy cellTopo = CamelliaCellTools::cellTopoForKey(bottomCellTopoKey);
  return cellTopo;
}
Beispiel #4
0
void printMeshInfo(MeshTopologyPtr mesh)
{
  unsigned spaceDim = mesh->getDimension();
  unsigned vertexCount = mesh->getEntityCount(0);
  unsigned edgeCount = (spaceDim > 1) ? mesh->getEntityCount(1) : 0;
  unsigned faceCount = (spaceDim > 2) ? mesh->getEntityCount(2) : 0;
  if (vertexCount > 0)
  {
    cout << "Vertices:\n";
    for (int vertexIndex=0; vertexIndex < vertexCount; vertexIndex++)
    {
      mesh->printEntityVertices(0, vertexIndex);
    }
  }
  if (edgeCount > 0)
  {
    cout << "Edges:\n";
    for (int edgeIndex=0; edgeIndex < edgeCount; edgeIndex++)
    {
      cout << "Edge " << edgeIndex << ":\n";
      mesh->printEntityVertices(1, edgeIndex);
    }
  }
  if (faceCount > 0)
  {
    cout << "Faces:\n";
    for (int faceIndex=0; faceIndex < faceCount; faceIndex++)
    {
      cout << "Face " << faceIndex << ":\n";
      mesh->printEntityVertices(2, faceIndex);
    }
  }
}
Beispiel #5
0
MeshPtr MeshTools::timeSliceMesh(MeshPtr spaceTimeMesh, double t,
                                 map<GlobalIndexType, GlobalIndexType> &sliceCellIDToSpaceTimeCellID, int H1OrderForSlice) {
  MeshTopologyPtr meshTopo = spaceTimeMesh->getTopology();
  set<IndexType> cellIDsToCheck = meshTopo->getRootCellIndices();
  set<IndexType> activeCellIDsForTime;
  
  set<IndexType> allActiveCellIDs = meshTopo->getActiveCellIndices();
  
  int spaceDim = meshTopo->getSpaceDim() - 1;  // # of true spatial dimensions
  
  MeshTopologyPtr sliceTopo = Teuchos::rcp( new MeshTopology(spaceDim) );
  set<IndexType> rootCellIDs = meshTopo->getRootCellIndices();
  for (set<IndexType>::iterator rootCellIt = rootCellIDs.begin(); rootCellIt != rootCellIDs.end(); rootCellIt++) {
    IndexType rootCellID = *rootCellIt;
    FieldContainer<double> physicalNodes = spaceTimeMesh->physicalCellNodesForCell(rootCellID);
    if (cellMatches(physicalNodes, t)) { // cell and some subset of its descendents should be included in slice mesh
      vector< vector< double > > sliceNodes = timeSliceForCell(physicalNodes, t);
      CellTopoPtrLegacy cellTopo = getBottomTopology(meshTopo, rootCellID);
      CellPtr sliceCell = sliceTopo->addCell(cellTopo, sliceNodes);
      sliceCellIDToSpaceTimeCellID[sliceCell->cellIndex()] = rootCellID;
    }
  }
  
  MeshPtr sliceMesh = Teuchos::rcp( new Mesh(sliceTopo, spaceTimeMesh->bilinearForm(), H1OrderForSlice, spaceDim) );
  
  // process refinements.  For now, we assume isotropic refinements, which means that each refinement in spacetime induces a refinement in the spatial slice
  set<IndexType> sliceCellIDsToCheckForRefinement = sliceTopo->getActiveCellIndices();
  while (sliceCellIDsToCheckForRefinement.size() > 0) {
    set<IndexType>::iterator cellIt = sliceCellIDsToCheckForRefinement.begin();
    IndexType sliceCellID = *cellIt;
    sliceCellIDsToCheckForRefinement.erase(cellIt);
    
    CellPtr sliceCell = sliceTopo->getCell(sliceCellID);
    CellPtr spaceTimeCell = meshTopo->getCell(sliceCellIDToSpaceTimeCellID[sliceCellID]);
    if (spaceTimeCell->isParent()) {
      set<GlobalIndexType> cellsToRefine;
      cellsToRefine.insert(sliceCellID);
      sliceMesh->hRefine(cellsToRefine, RefinementPattern::regularRefinementPattern(sliceCell->topology()->getKey()));
      vector<IndexType> spaceTimeChildren = spaceTimeCell->getChildIndices();
      for (int childOrdinal=0; childOrdinal<spaceTimeChildren.size(); childOrdinal++) {
        IndexType childID = spaceTimeChildren[childOrdinal];
        FieldContainer<double> childNodes = meshTopo->physicalCellNodesForCell(childID);
        if (cellMatches(childNodes, t)) {
          vector< vector<double> > childSlice = timeSliceForCell(childNodes, t);
          CellPtr childSliceCell = sliceTopo->findCellWithVertices(childSlice);
          sliceCellIDToSpaceTimeCellID[childSliceCell->cellIndex()] = childID;
          sliceCellIDsToCheckForRefinement.insert(childSliceCell->cellIndex());
        }
      }
    }
  }
  
  return sliceMesh;
}
Beispiel #6
0
MeshPtr MeshTools::timeSliceMesh(MeshPtr spaceTimeMesh, double t,
                                 map<GlobalIndexType, GlobalIndexType> &sliceCellIDToSpaceTimeCellID, int H1OrderForSlice)
{
  MeshTopology* meshTopo = dynamic_cast<MeshTopology*>(spaceTimeMesh->getTopology().get());
  TEUCHOS_TEST_FOR_EXCEPTION(!meshTopo, std::invalid_argument, "timeSliceMesh() called with spaceTimeMesh that appears to be pure MeshTopologyView.  This is not supported.");
  set<IndexType> cellIDsToCheck = meshTopo->getRootCellIndices();
  set<IndexType> activeCellIDsForTime;

  set<IndexType> allActiveCellIDs = meshTopo->getActiveCellIndices();

  int spaceDim = meshTopo->getDimension() - 1;  // # of true spatial dimensions

  MeshTopologyPtr sliceTopo = Teuchos::rcp( new MeshTopology(spaceDim) );
  set<IndexType> rootCellIDs = meshTopo->getRootCellIndices();
  for (set<IndexType>::iterator rootCellIt = rootCellIDs.begin(); rootCellIt != rootCellIDs.end(); rootCellIt++)
  {
    IndexType rootCellID = *rootCellIt;
    FieldContainer<double> physicalNodes = spaceTimeMesh->physicalCellNodesForCell(rootCellID);
    if (cellMatches(physicalNodes, t))   // cell and some subset of its descendents should be included in slice mesh
    {
      vector< vector< double > > sliceNodes = timeSliceForCell(physicalNodes, t);
      CellTopoPtr cellTopo = getBottomTopology(meshTopo, rootCellID);
      GlobalIndexType newCellID = sliceTopo->cellCount();
      CellPtr sliceCell = sliceTopo->addCell(newCellID, cellTopo, sliceNodes); // for consistency, this is only valid if run on every MPI rank.
      sliceCellIDToSpaceTimeCellID[sliceCell->cellIndex()] = rootCellID;
    }
  }

  MeshPtr sliceMesh = Teuchos::rcp( new Mesh(sliceTopo, spaceTimeMesh->bilinearForm(), H1OrderForSlice, spaceDim) );

  // process refinements.  For now, we assume isotropic refinements, which means that each refinement in spacetime induces a refinement in the spatial slice
  set<IndexType> sliceCellIDsToCheckForRefinement = sliceTopo->getActiveCellIndices();
  while (sliceCellIDsToCheckForRefinement.size() > 0)
  {
    set<IndexType>::iterator cellIt = sliceCellIDsToCheckForRefinement.begin();
    IndexType sliceCellID = *cellIt;
    sliceCellIDsToCheckForRefinement.erase(cellIt);

    CellPtr sliceCell = sliceTopo->getCell(sliceCellID);
    CellPtr spaceTimeCell = meshTopo->getCell(sliceCellIDToSpaceTimeCellID[sliceCellID]);
    if (spaceTimeCell->isParent(spaceTimeMesh->getTopology()))
    {
      set<GlobalIndexType> cellsToRefine;
      cellsToRefine.insert(sliceCellID);
      sliceMesh->hRefine(cellsToRefine, RefinementPattern::regularRefinementPattern(sliceCell->topology()));
      vector<IndexType> spaceTimeChildren = spaceTimeCell->getChildIndices(spaceTimeMesh->getTopology());
      for (int childOrdinal=0; childOrdinal<spaceTimeChildren.size(); childOrdinal++)
      {
        IndexType childID = spaceTimeChildren[childOrdinal];
        FieldContainer<double> childNodes = meshTopo->physicalCellNodesForCell(childID);
        if (cellMatches(childNodes, t))
        {
          vector< vector<double> > childSlice = timeSliceForCell(childNodes, t);
          CellPtr childSliceCell = sliceTopo->findCellWithVertices(childSlice);
          sliceCellIDToSpaceTimeCellID[childSliceCell->cellIndex()] = childID;
          sliceCellIDsToCheckForRefinement.insert(childSliceCell->cellIndex());
        }
      }
    }
  }

  MeshPartitionPolicyPtr partitionPolicy = MeshPartitionPolicy::inducedPartitionPolicy(sliceMesh, spaceTimeMesh, sliceCellIDToSpaceTimeCellID);

  sliceMesh->setPartitionPolicy(partitionPolicy);

  return sliceMesh;
}
SpaceTimeIncompressibleFormulation::SpaceTimeIncompressibleFormulation(Teuchos::RCP<IncompressibleProblem> problem, Teuchos::ParameterList &parameters)
{
  int spaceDim = parameters.get<int>("spaceDim", 2);
  bool steady = parameters.get<bool>("steady", true);
  double mu = parameters.get<double>("mu", 1e-2);
  bool useConformingTraces = parameters.get<bool>("useConformingTraces", false);
  int fieldPolyOrder = parameters.get<int>("fieldPolyOrder", 2);
  int delta_p = parameters.get<int>("delta_p", 2);
  int numTElems = parameters.get<int>("numTElems", 2);
  string norm = parameters.get<string>("norm", "Graph");
  string savedSolutionAndMeshPrefix = parameters.get<string>("savedSolutionAndMeshPrefix", "");

  _spaceDim = spaceDim;
  _steady = steady;
  _mu = mu;
  _useConformingTraces = useConformingTraces;
  MeshTopologyPtr meshTopo = problem->meshTopology(numTElems);
  MeshGeometryPtr meshGeometry = problem->meshGeometry();

  if (!steady)
  {
    TEUCHOS_TEST_FOR_EXCEPTION(meshTopo->getDimension() != _spaceDim + 1, std::invalid_argument, "MeshTopo must be space-time mesh for transient");
  }
  else
  {
    TEUCHOS_TEST_FOR_EXCEPTION(meshTopo->getDimension() != _spaceDim, std::invalid_argument, "MeshTopo must be spatial mesh for steady");
  }
  TEUCHOS_TEST_FOR_EXCEPTION(mu==0, std::invalid_argument, "mu may not be 0!");
  TEUCHOS_TEST_FOR_EXCEPTION(spaceDim==1, std::invalid_argument, "Incompressible Navier-Stokes is trivial for spaceDim=1");
  TEUCHOS_TEST_FOR_EXCEPTION((spaceDim != 2) && (spaceDim != 3), std::invalid_argument, "spaceDim must be 2 or 3");


  Space uHatSpace = useConformingTraces ? HGRAD : L2;

  FunctionPtr zero = Function::constant(1);
  FunctionPtr one = Function::constant(1);
  FunctionPtr n_x = TFunction<double>::normal(); // spatial normal
  // FunctionPtr n_x_parity = n_x * TFunction<double>::sideParity();
  FunctionPtr n_xt = TFunction<double>::normalSpaceTime();
  // FunctionPtr n_xt_parity = n_xt * TFunction<double>::sideParity();

  // declare all possible variables -- will only create the ones we need for spaceDim
  // fields
  VarPtr u1, u2, u3;
  VarPtr sigma11, sigma12, sigma13;
  VarPtr sigma21, sigma22, sigma23;
  VarPtr sigma31, sigma32, sigma33;
  VarPtr p;

  // traces
  VarPtr u1hat, u2hat, u3hat;
  VarPtr tm1hat, tm2hat, tm3hat;

  // tests
  VarPtr v1, v2, v3;
  VarPtr tau1, tau2, tau3;
  VarPtr q;

  _vf = VarFactory::varFactory();


  if (spaceDim == 1)
  {
    u1 = _vf->fieldVar(s_u1);
    sigma11 = _vf->fieldVar(s_sigma11);
    p = _vf->fieldVar(s_p);
    u1hat = _vf->traceVarSpaceOnly(s_u1hat, 1.0 * u1, uHatSpace);
    tm1hat = _vf->fluxVar(s_tm1hat);
    v1 = _vf->testVar(s_v1, HGRAD);
    tau1 = _vf->testVar(s_tau1, HGRAD); // scalar
    q = _vf->testVar(s_q, HGRAD);
  }
  if (spaceDim == 2)
  {
    u1 = _vf->fieldVar(s_u1);
    u2 = _vf->fieldVar(s_u2);
    sigma11 = _vf->fieldVar(s_sigma11);
    sigma12 = _vf->fieldVar(s_sigma12);
    sigma21 = _vf->fieldVar(s_sigma21);
    sigma22 = _vf->fieldVar(s_sigma22);
    p = _vf->fieldVar(s_p);
    u1hat = _vf->traceVarSpaceOnly(s_u1hat, 1.0 * u1, uHatSpace);
    u2hat = _vf->traceVarSpaceOnly(s_u2hat, 1.0 * u2, uHatSpace);

    // LinearTermPtr tm1_lt, tm2_lt;
    // tm1_lt = p * n_x->x() - sigma11 * n_x->x() - sigma12 * n_x->y();
    // tm2_lt = p * n_x->y() - sigma21 * n_x->x() - sigma22 * n_x->y();
    // tm1hat = _vf->fluxVar(s_tm1hat, tm1_lt);
    // tm2hat = _vf->fluxVar(s_tm2hat, tm2_lt);
    tm1hat = _vf->fluxVar(s_tm1hat);
    tm2hat = _vf->fluxVar(s_tm2hat);

    v1 = _vf->testVar(s_v1, HGRAD);
    v2 = _vf->testVar(s_v2, HGRAD);
    tau1 = _vf->testVar(s_tau1, HDIV); // vector
    tau2 = _vf->testVar(s_tau2, HDIV); // vector
    q = _vf->testVar(s_q, HGRAD);
  }
  if (spaceDim == 3)
  {
    u1 = _vf->fieldVar(s_u1);
    u2 = _vf->fieldVar(s_u2);
    u3 = _vf->fieldVar(s_u3);
    sigma11 = _vf->fieldVar(s_sigma11);
    sigma12 = _vf->fieldVar(s_sigma12);
    sigma13 = _vf->fieldVar(s_sigma13);
    sigma21 = _vf->fieldVar(s_sigma21);
    sigma22 = _vf->fieldVar(s_sigma22);
    sigma23 = _vf->fieldVar(s_sigma23);
    sigma31 = _vf->fieldVar(s_sigma31);
    sigma32 = _vf->fieldVar(s_sigma32);
    sigma33 = _vf->fieldVar(s_sigma33);
    p = _vf->fieldVar(s_p);
    u1hat = _vf->traceVarSpaceOnly(s_u1hat, 1.0 * u1, uHatSpace);
    u2hat = _vf->traceVarSpaceOnly(s_u2hat, 1.0 * u2, uHatSpace);
    u3hat = _vf->traceVarSpaceOnly(s_u3hat, 1.0 * u3, uHatSpace);
    tm1hat = _vf->fluxVar(s_tm1hat);
    tm2hat = _vf->fluxVar(s_tm2hat);
    tm3hat = _vf->fluxVar(s_tm3hat);
    v1 = _vf->testVar(s_v1, HGRAD);
    v2 = _vf->testVar(s_v2, HGRAD);
    v3 = _vf->testVar(s_v3, HGRAD);
    tau1 = _vf->testVar(s_tau1, HDIV); // vector
    tau2 = _vf->testVar(s_tau2, HDIV); // vector
    tau3 = _vf->testVar(s_tau3, HDIV); // vector
    q = _vf->testVar(s_q, HGRAD);
  }

  // LinearTermPtr tc_lt;
  // if (spaceDim == 1)
  // {
  //   tc_lt = beta->x()*n_x_parity->x()*u
  //     -sigma1 * n_x_parity->x()
  //     + u*n_xt_parity->t();
  // }
  // else if (spaceDim == 2)
  // {
  //   tc_lt = beta->x()*n_x_parity->x()*u
  //     + beta->y()*n_x_parity->y()*u
  //     - sigma1 * n_x_parity->x()
  //     - sigma2 * n_x_parity->y()
  //     + u*n_xt_parity->t();
  // }
  // else if (spaceDim == 3)
  // {
  //   tc_lt = beta->x()*n_x_parity->x()*u
  //     + beta->y()*n_x_parity->y()*u
  //     + beta->z()*n_x_parity->z()*u
  //     - sigma1 * n_x_parity->x()
  //     - sigma2 * n_x_parity->y()
  //     - sigma3 * n_x_parity->z()
  //     + u*n_xt_parity->t();
  // }
  // tc = _vf->fluxVar(s_tc, tc_lt);

  _bf = Teuchos::rcp( new BF(_vf) );




  // Define mesh
  BCPtr bc = BC::bc();

  vector<int> H1Order(2);
  H1Order[0] = fieldPolyOrder + 1;
  H1Order[1] = fieldPolyOrder + 1; // for now, use same poly. degree for temporal bases...
  if (savedSolutionAndMeshPrefix == "")
  {
    map<int,int> trialOrderEnhancements;
    // trialOrderEnhancements[tm1hat->ID()] = fieldPolyOrder;
    // trialOrderEnhancements[tm2hat->ID()] = fieldPolyOrder;
    // trialOrderEnhancements[u1hat->ID()] = fieldPolyOrder;
    // trialOrderEnhancements[u2hat->ID()] = fieldPolyOrder;
    // MeshPtr proxyMesh = Teuchos::rcp( new Mesh(meshTopo->deepCopy(), _bf, H1Order, delta_p) ) ;
    _mesh = Teuchos::rcp( new Mesh(meshTopo, _bf, H1Order, delta_p, trialOrderEnhancements) ) ;
    if (meshGeometry != Teuchos::null)
      _mesh->setEdgeToCurveMap(meshGeometry->edgeToCurveMap());
    // problem->preprocessMesh(_mesh);
    // proxyMesh->registerObserver(_mesh);
    // problem->preprocessMesh(proxyMesh);
    // _mesh->enforceOneIrregularity();

    _solutionUpdate = Solution::solution(_bf, _mesh, bc);
    _solutionBackground = Solution::solution(_bf, _mesh, bc);
    map<int, FunctionPtr> initialGuess;
    initialGuess[u(1)->ID()] = problem->u1_exact();
    initialGuess[u(2)->ID()] = problem->u2_exact();
    initialGuess[sigma(1,1)->ID()] = problem->sigma1_exact()->x();
    initialGuess[sigma(1,2)->ID()] = problem->sigma1_exact()->y();
    initialGuess[sigma(2,1)->ID()] = problem->sigma2_exact()->x();
    initialGuess[sigma(2,2)->ID()] = problem->sigma2_exact()->y();
    // initialGuess[p()->ID()] = problem->p_exact();
    initialGuess[uhat(1)->ID()] = problem->u1_exact();
    initialGuess[uhat(2)->ID()] = problem->u2_exact();
    // initialGuess[tmhat(1)->ID()] =
    //   (problem->u1_exact()*problem->u1_exact()-problem->sigma1_exact()->x()+problem->p_exact())*n_x->x()
    //   + (problem->u1_exact()*problem->u2_exact()-problem->sigma1_exact()->y())*n_x->y();
    // initialGuess[tmhat(2)->ID()] =
    //   (problem->u1_exact()*problem->u2_exact()-problem->sigma2_exact()->x())*n_x->x()
    //   + (problem->u2_exact()*problem->u2_exact()-problem->sigma2_exact()->y()+problem->p_exact())*n_x->y();

    _solutionBackground->projectOntoMesh(initialGuess);
  }
  else
  {
    // // BFPTR version should be deprecated
    _mesh = MeshFactory::loadFromHDF5(_bf, savedSolutionAndMeshPrefix+".mesh");
    _solutionBackground = Solution::solution(_bf, _mesh, bc);
    _solutionBackground->loadFromHDF5(savedSolutionAndMeshPrefix+".soln");
    _solutionUpdate = Solution::solution(_bf, _mesh, bc);
    // _solutionUpdate->loadFromHDF5(savedSolutionAndMeshPrefix+"_update.soln");
  }
  // _solutionUpdate->setFilter(problem->pc());
  // _solutionBackground->setFilter(problem->pc());

  FunctionPtr u1_prev = Function::solution(u1, _solutionBackground);
  FunctionPtr u2_prev = Function::solution(u2, _solutionBackground);
  FunctionPtr u_prev = Function::vectorize(u1_prev, u2_prev);


  if (spaceDim == 2)
  {
    // stress equation
    _bf->addTerm((1.0 / _mu) * sigma11, tau1->x());
    _bf->addTerm((1.0 / _mu) * sigma12, tau1->y());
    _bf->addTerm((1.0 / _mu) * sigma21, tau2->x());
    _bf->addTerm((1.0 / _mu) * sigma22, tau2->y());
    _bf->addTerm(u1, tau1->div());
    _bf->addTerm(u2, tau2->div());
    _bf->addTerm(-u1hat, tau1 * n_x);
    _bf->addTerm(-u2hat, tau2 * n_x);

    // momentum equation
    if (!steady)
    {
      _bf->addTerm(-u1, v1->dt());
      _bf->addTerm(-u2, v2->dt());
    }
    _bf->addTerm(-u1_prev*u1, v1->dx());
    _bf->addTerm(-u1_prev*u1, v1->dx());
    _bf->addTerm(-u2_prev*u1, v1->dy());
    _bf->addTerm(-u1_prev*u2, v1->dy());
    _bf->addTerm(-u2_prev*u1, v2->dx());
    _bf->addTerm(-u1_prev*u2, v2->dx());
    _bf->addTerm(-u2_prev*u2, v2->dy());
    _bf->addTerm(-u2_prev*u2, v2->dy());

    _bf->addTerm(sigma11, v1->dx());
    _bf->addTerm(sigma12, v1->dy());
    _bf->addTerm(sigma21, v2->dx());
    _bf->addTerm(sigma22, v2->dy());

    _bf->addTerm(-p, v1->dx());
    _bf->addTerm(-p, v2->dy());

    _bf->addTerm(tm1hat, v1);
    _bf->addTerm(tm2hat, v2);
    // _bf->addTerm(2*u1_prev*u1hat*n_x->x(), v1);
    // _bf->addTerm((u2_prev*u1hat+u1_prev*u2hat)*n_x->y(), v1);
    // _bf->addTerm((u2_prev*u1hat+u1_prev*u2hat)*n_x->x(), v2);
    // _bf->addTerm(2*u2_prev*u2hat*n_x->y(), v2);

    // continuity equation
    _bf->addTerm(-u1, q->dx());
    _bf->addTerm(-u2, q->dy());

    // _bf->addTerm(u1hat, q->times_normal_x());
    // _bf->addTerm(u2hat, q->times_normal_y());
    _bf->addTerm(u1hat*n_x->x(), q);
    _bf->addTerm(u2hat*n_x->y(), q);
  }

  // Add residual to RHS
  _rhs = RHS::rhs();
  // stress equation
  _rhs->addTerm( -u1_prev * tau1->div() );
  _rhs->addTerm( -u2_prev * tau2->div() );

  // momentum equation
  if (!steady)
  {
    _rhs->addTerm( u1_prev * v1->dt());
    _rhs->addTerm( u2_prev * v2->dt());
  }
  _rhs->addTerm( u1_prev * u1_prev*v1->dx() );
  _rhs->addTerm( u1_prev * u2_prev*v1->dy() );
  _rhs->addTerm( u2_prev * u1_prev*v2->dx() );
  _rhs->addTerm( u2_prev * u2_prev*v2->dy() );

  // _rhs->addTerm( -u1_prev*u1_prev*n_x->x() * v1 );
  // _rhs->addTerm( -u2_prev*u1_prev*n_x->y() * v1 );
  // _rhs->addTerm( -u2_prev*u1_prev*n_x->x() * v2 );
  // _rhs->addTerm( -u2_prev*u2_prev*n_x->y() * v2 );

  // continuity equation
  _rhs->addTerm( u1_prev*q->dx());
  _rhs->addTerm( u2_prev*q->dy());

  _ips["Graph"] = _bf->graphNorm();

  _ips["CoupledRobust"] = Teuchos::rcp(new IP);
  // _ips["CoupledRobust"]->addTerm(_beta*v->grad());
  _ips["CoupledRobust"]->addTerm(u_prev*v1->grad());
  _ips["CoupledRobust"]->addTerm(u_prev*v2->grad());
  _ips["CoupledRobust"]->addTerm(u1_prev*v1->dx() + u2_prev*v2->dx());
  _ips["CoupledRobust"]->addTerm(u1_prev*v1->dy() + u2_prev*v2->dy());
  // _ips["CoupledRobust"]->addTerm(Function::min(one/Function::h(),Function::constant(1./sqrt(_mu)))*tau);
  _ips["CoupledRobust"]->addTerm(Function::min(one/Function::h(),Function::constant(1./sqrt(_mu)))*tau1);
  _ips["CoupledRobust"]->addTerm(Function::min(one/Function::h(),Function::constant(1./sqrt(_mu)))*tau2);
  // _ips["CoupledRobust"]->addTerm(sqrt(_mu)*v->grad());
  _ips["CoupledRobust"]->addTerm(sqrt(_mu)*v1->grad());
  _ips["CoupledRobust"]->addTerm(sqrt(_mu)*v2->grad());
  // _ips["CoupledRobust"]->addTerm(Function::min(sqrt(_mu)*one/Function::h(),one)*v);
  _ips["CoupledRobust"]->addTerm(Function::min(sqrt(_mu)*one/Function::h(),one)*v1);
  _ips["CoupledRobust"]->addTerm(Function::min(sqrt(_mu)*one/Function::h(),one)*v2);
  // _ips["CoupledRobust"]->addTerm(tau->div() - v->dt() - beta*v->grad());
  if (!steady)
  {
    _ips["CoupledRobust"]->addTerm(tau1->div() -v1->dt() - u_prev*v1->grad() - u1_prev*v1->dx() - u2_prev*v2->dx());
    _ips["CoupledRobust"]->addTerm(tau2->div() -v2->dt() - u_prev*v2->grad() - u1_prev*v1->dy() - u2_prev*v2->dy());
  }
  else
  {
    _ips["CoupledRobust"]->addTerm(tau1->div() - u_prev*v1->grad() - u1_prev*v1->dx() - u2_prev*v2->dx());
    _ips["CoupledRobust"]->addTerm(tau2->div() - u_prev*v2->grad() - u1_prev*v1->dy() - u2_prev*v2->dy());
  }
  // _ips["CoupledRobust"]->addTerm(v1->dx() + v2->dy());
  _ips["CoupledRobust"]->addTerm(q->grad());
  _ips["CoupledRobust"]->addTerm(q);


  _ips["NSDecoupledH1"] = Teuchos::rcp(new IP);
  // _ips["NSDecoupledH1"]->addTerm(one/Function::h()*tau);
  _ips["NSDecoupledH1"]->addTerm(one/Function::h()*tau1);
  _ips["NSDecoupledH1"]->addTerm(one/Function::h()*tau2);
  // _ips["NSDecoupledH1"]->addTerm(v->grad());
  _ips["NSDecoupledH1"]->addTerm(v1->grad());
  _ips["NSDecoupledH1"]->addTerm(v2->grad());
  // _ips["NSDecoupledH1"]->addTerm(_beta*v->grad()+v->dt());
  if (!steady)
  {
    _ips["NSDecoupledH1"]->addTerm(v1->dt() + u_prev*v1->grad() + u1_prev*v1->dx() + u2_prev*v2->dx());
    _ips["NSDecoupledH1"]->addTerm(v2->dt() + u_prev*v2->grad() + u1_prev*v1->dy() + u2_prev*v2->dy());
  }
  else
  {
    _ips["NSDecoupledH1"]->addTerm(u_prev*v1->grad() + u1_prev*v1->dx() + u2_prev*v2->dx());
    _ips["NSDecoupledH1"]->addTerm(u_prev*v2->grad() + u1_prev*v1->dy() + u2_prev*v2->dy());
  }
  // _ips["NSDecoupledH1"]->addTerm(tau->div());
  _ips["NSDecoupledH1"]->addTerm(tau1->div());
  _ips["NSDecoupledH1"]->addTerm(tau2->div());
  // _ips["NSDecoupledH1"]->addTerm(v);
  _ips["NSDecoupledH1"]->addTerm(v1);
  _ips["NSDecoupledH1"]->addTerm(v2);
  // _ips["CoupledRobust"]->addTerm(v1->dx() + v2->dy());
  _ips["NSDecoupledH1"]->addTerm(q->grad());
  _ips["NSDecoupledH1"]->addTerm(q);

  IPPtr ip = _ips.at(norm);
  if (problem->forcingFunction != Teuchos::null)
  {
    _rhs->addTerm(problem->forcingFunction->x() * v1);
    _rhs->addTerm(problem->forcingFunction->y() * v2);
  }

  _solutionUpdate->setRHS(_rhs);
  _solutionUpdate->setIP(ip);

  // impose zero mean constraint
  // if (problem->imposeZeroMeanPressure())
  //   _solutionUpdate->bc()->shouldImposeZeroMeanConstraint(p->ID());
  // _solutionUpdate->bc()->singlePointBC(p->ID());

  _mesh->registerSolution(_solutionBackground);
  _mesh->registerSolution(_solutionUpdate);

  LinearTermPtr residual = _rhs->linearTerm() - _bf->testFunctional(_solutionUpdate, false); // false: don't exclude boundary terms

  // double energyThreshold = 0.2;
  double energyThreshold = 0;
  _refinementStrategy = Teuchos::rcp( new RefinementStrategy( _mesh, residual, ip, energyThreshold ) );
}
Beispiel #8
0
bool checkConstraints( MeshTopologyPtr mesh, unsigned entityDim, map<unsigned,pair<IndexType,unsigned> > &expectedConstraints, string meshName = "mesh")
{
  bool success = true;

  // check constraints for entities belonging to active cells
  set<IndexType> myActiveCells = mesh->getMyActiveCellIndices();

  for (IndexType cellIndex : myActiveCells)
  {
    CellPtr cell = mesh->getCell(cellIndex);
    vector<unsigned> entitiesForCell = cell->getEntityIndices(entityDim);
    for (vector<unsigned>::iterator entityIt = entitiesForCell.begin(); entityIt != entitiesForCell.end(); entityIt++)
    {
      unsigned entityIndex = *entityIt;

      pair<IndexType,unsigned> constrainingEntity = mesh->getConstrainingEntity(entityDim, entityIndex);

      unsigned constrainingEntityIndex = constrainingEntity.first;
      unsigned constrainingEntityDim = constrainingEntity.second;
      if ((constrainingEntityIndex==entityIndex) && (constrainingEntityDim == entityDim))
      {
        // then we should expect not to have an entry in expectedConstraints:
        if (expectedConstraints.find(entityIndex) != expectedConstraints.end())
        {
          cout << "Expected entity constraint is not imposed in " << meshName << ".\n";
          cout << "Expected " << typeString(entityDim) << " " << entityIndex << " to be constrained by ";
          cout << typeString(expectedConstraints[entityIndex].second) << " " << expectedConstraints[entityIndex].first << endl;
          cout << typeString(entityDim) << " " << entityIndex << " vertices:\n";
          mesh->printEntityVertices(entityDim, entityIndex);
          cout << typeString(expectedConstraints[entityIndex].second) << " " << expectedConstraints[entityIndex].first << " vertices:\n";
          mesh->printEntityVertices(entityDim, expectedConstraints[entityIndex].first);
          success = false;
        }
      }
      else
      {
        if (expectedConstraints.find(entityIndex) == expectedConstraints.end())
        {
          cout << "Unexpected entity constraint is imposed in " << meshName << ".\n";

          string entityType;
          if (entityDim==0)
          {
            entityType = "Vertex ";
          }
          else if (entityDim==1)
          {
            entityType = "Edge ";
          }
          else if (entityDim==2)
          {
            entityType = "Face ";
          }
          else if (entityDim==3)
          {
            entityType = "Volume ";
          }
          string constrainingEntityType;
          if (constrainingEntityDim==0)
          {
            constrainingEntityType = "Vertex ";
          }
          else if (constrainingEntityDim==1)
          {
            constrainingEntityType = "Edge ";
          }
          else if (constrainingEntityDim==2)
          {
            constrainingEntityType = "Face ";
          }
          else if (constrainingEntityDim==3)
          {
            constrainingEntityType = "Volume ";
          }

          cout << entityType << entityIndex << " unexpectedly constrained by " << constrainingEntityType << constrainingEntityIndex << endl;
          cout << entityType << entityIndex << " vertices:\n";
          mesh->printEntityVertices(entityDim, entityIndex);
          cout << constrainingEntityType << constrainingEntityIndex << " vertices:\n";
          mesh->printEntityVertices(constrainingEntityDim, constrainingEntityIndex);
          success = false;
        }
        else
        {
          unsigned expectedConstrainingEntity = expectedConstraints[entityIndex].first;
          if (expectedConstrainingEntity != constrainingEntityIndex)
          {
            cout << "The constraining entity is not the expected one in " << meshName << ".\n";
            cout << "Expected " << typeString(entityDim) << " " << entityIndex << " to be constrained by ";
            cout << typeString(expectedConstraints[entityIndex].second) << " " << expectedConstrainingEntity;
            cout << "; was constrained by " << constrainingEntityIndex << endl;
            cout << typeString(entityDim) << " " << entityIndex << " vertices:\n";
            mesh->printEntityVertices(entityDim, entityIndex);
            cout << typeString(expectedConstraints[entityIndex].second) << " " << expectedConstrainingEntity << " vertices:\n";
            mesh->printEntityVertices(entityDim, expectedConstrainingEntity);
            cout << typeString(constrainingEntityDim) << " " << constrainingEntityIndex << " vertices:\n";
            mesh->printEntityVertices(constrainingEntityDim, constrainingEntityIndex);
            success = false;
          }
        }
      }
    }
  }
  return success;
}