コード例 #1
0
//Wedge
Albany::MpasSTKMeshStruct::MpasSTKMeshStruct(const Teuchos::RCP<Teuchos::ParameterList>& params,
                                             const Teuchos::RCP<const Epetra_Comm>& comm,
                                             const std::vector<int>& indexToTriangleID, const std::vector<int>& verticesOnTria, int nGlobalTriangles, int numLayers, int Ordering) :
  GenericSTKMeshStruct(params,Teuchos::null,3),
  out(Teuchos::VerboseObjectBase::getDefaultOStream()),
  periodic(false),
  NumEles(indexToTriangleID.size()),
  hasRestartSol(false),
  restartTime(0.)
{
  std::vector<int> indexToPrismID(indexToTriangleID.size()*numLayers);

  //Int ElemColumnShift = (ordering == ColumnWise) ? 1 : indexToTriangleID.size();
  int elemColumnShift = (Ordering == 1) ? 1 : nGlobalTriangles;
  int lElemColumnShift = (Ordering == 1) ? 1 : indexToTriangleID.size();
  int elemLayerShift = (Ordering == 0) ? 1 : numLayers;

  for(int il=0; il< numLayers; il++)
  {
	  int shift = il*elemColumnShift;
	  int lShift = il*lElemColumnShift;
	  for(int j=0; j< indexToTriangleID.size(); j++)
	  {
		  int lid = lShift + j*elemLayerShift;
		  indexToPrismID[lid] = shift+elemLayerShift * indexToTriangleID[j];
	  }
  }

  elem_map = Teuchos::rcp(new Epetra_Map(nGlobalTriangles*numLayers, indexToPrismID.size(), &indexToPrismID[0], 0, *comm)); // Distribute the elems equally

  params->validateParameters(*getValidDiscretizationParameters(),0);


  std::string ebn="Element Block 0";
  partVec[0] = & metaData->declare_part(ebn, stk::topology::ELEMENT_RANK );
  ebNameToIndex[ebn] = 0;

#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*partVec[0]);
#endif


  std::vector<std::string> nsNames;
  std::string nsn="Lateral";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, stk::topology::NODE_RANK );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="Internal";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, stk::topology::NODE_RANK );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="Bottom";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, stk::topology::NODE_RANK );
#ifdef ALBANY_SEACAS
	stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif


  std::vector<std::string> ssNames;
  std::string ssnLat="lateralside";
  std::string ssnBottom="basalside";
  std::string ssnTop="upperside";

  ssNames.push_back(ssnLat);
  ssNames.push_back(ssnBottom);
  ssNames.push_back(ssnTop);
  ssPartVec[ssnLat] = & metaData->declare_part(ssnLat, metaData->side_rank() );
  ssPartVec[ssnBottom] = & metaData->declare_part(ssnBottom, metaData->side_rank() );
  ssPartVec[ssnTop] = & metaData->declare_part(ssnTop, metaData->side_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*ssPartVec[ssnLat]);
    stk::io::put_io_part_attribute(*ssPartVec[ssnBottom]);
    stk::io::put_io_part_attribute(*ssPartVec[ssnTop]);
#endif

  stk::mesh::set_cell_topology<shards::Wedge<6> >(*partVec[0]);
  stk::mesh::set_cell_topology<shards::Triangle<3> >(*ssPartVec[ssnBottom]);
  stk::mesh::set_cell_topology<shards::Triangle<3> >(*ssPartVec[ssnTop]);
  stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnLat]);

  numDim = 3;
  int cub = params->get("Cubature Degree",3);
  int worksetSizeMax = params->get("Workset Size",50);
  int worksetSize = this->computeWorksetSize(worksetSizeMax, elem_map->NumMyElements());

  const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[0]).getCellTopologyData();

  this->meshSpecs[0] = Teuchos::rcp(new Albany::MeshSpecsStruct(ctd, numDim, cub,
                             nsNames, ssNames, worksetSize, partVec[0]->name(),
                             ebNameToIndex, this->interleavedOrdering));


}
コード例 #2
0
Albany::ExtrudedSTKMeshStruct::ExtrudedSTKMeshStruct(const Teuchos::RCP<Teuchos::ParameterList>& params, const Teuchos::RCP<const Teuchos_Comm>& comm) :
    GenericSTKMeshStruct(params, Teuchos::null, 3), out(Teuchos::VerboseObjectBase::getDefaultOStream()), periodic(false) {
  params->validateParameters(*getValidDiscretizationParameters(), 0);

  std::string ebn = "Element Block 0";
  partVec[0] = &metaData->declare_part(ebn, stk::topology::ELEMENT_RANK);
  ebNameToIndex[ebn] = 0;

#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*partVec[0]);
#endif

  std::vector<std::string> nsNames;
  std::string nsn = "lateral";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = &metaData->declare_part(nsn, stk::topology::NODE_RANK);
#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn = "internal";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = &metaData->declare_part(nsn, stk::topology::NODE_RANK);
#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn = "bottom";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = &metaData->declare_part(nsn, stk::topology::NODE_RANK);
#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif

  std::vector<std::string> ssNames;
  std::string ssnLat = "lateralside";
  std::string ssnBottom = "basalside";
  std::string ssnTop = "upperside";

  ssNames.push_back(ssnLat);
  ssNames.push_back(ssnBottom);
  ssNames.push_back(ssnTop);
  ssPartVec[ssnLat] = &metaData->declare_part(ssnLat, metaData->side_rank());
  ssPartVec[ssnBottom] = &metaData->declare_part(ssnBottom, metaData->side_rank());
  ssPartVec[ssnTop] = &metaData->declare_part(ssnTop, metaData->side_rank());
#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*ssPartVec[ssnLat]);
  stk::io::put_io_part_attribute(*ssPartVec[ssnBottom]);
  stk::io::put_io_part_attribute(*ssPartVec[ssnTop]);
#endif

  Teuchos::RCP<Teuchos::ParameterList> params2D(new Teuchos::ParameterList());
  params2D->set("Use Serial Mesh", params->get("Use Serial Mesh", false));
  params2D->set<int>("Number Of Time Derivatives", params->get<int>("Number Of Time Derivatives"));
#ifdef ALBANY_SEACAS
  params2D->set("Exodus Input File Name", params->get("Exodus Input File Name", "IceSheet.exo"));

  basalMeshStruct = Teuchos::rcp(new Albany::IossSTKMeshStruct(params2D, adaptParams, comm));
#else
    // Above block of code could allow for 2D mesh to come from other sources instead of Ioss
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
              std::endl << "Error in ExtrudedSTKMeshStruct: Currently Requires 2D mesh to come from exodus");
#endif

  Teuchos::RCP<Albany::StateInfoStruct> sis = Teuchos::rcp(new Albany::StateInfoStruct);
  Albany::AbstractFieldContainer::FieldContainerRequirements req;

  int ws_size = basalMeshStruct->getMeshSpecs()[0]->worksetSize;
  basalMeshStruct->setFieldAndBulkData(comm, params, 1, req, sis, ws_size);

  stk::mesh::Selector select_owned_in_part = stk::mesh::Selector(basalMeshStruct->metaData->universal_part()) & stk::mesh::Selector(basalMeshStruct->metaData->locally_owned_part());
  int numCells = stk::mesh::count_selected_entities(select_owned_in_part, basalMeshStruct->bulkData->buckets(stk::topology::ELEMENT_RANK));

  std::string shape = params->get("Element Shape", "Hexahedron");
  std::string basalside_name;
  if(shape == "Tetrahedron")  {
    ElemShape = Tetrahedron;
    basalside_name = shards::getCellTopologyData<shards::Triangle<3> >()->name;
  }
  else if (shape == "Wedge")  {
    ElemShape = Wedge;
    basalside_name = shards::getCellTopologyData<shards::Triangle<3> >()->name;
  }
  else if (shape == "Hexahedron") {
    ElemShape = Hexahedron;
    basalside_name = shards::getCellTopologyData<shards::Quadrilateral<4> >()->name;
  }
  else
    TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameterValue,
              std::endl << "Error in ExtrudedSTKMeshStruct: Element Shape " << shape << " not recognized. Possible values: Tetrahedron, Wedge, Hexahedron");

  std::string elem2d_name(basalMeshStruct->getMeshSpecs()[0]->ctd.base->name);
  TEUCHOS_TEST_FOR_EXCEPTION(basalside_name != elem2d_name, Teuchos::Exceptions::InvalidParameterValue,
                std::endl << "Error in ExtrudedSTKMeshStruct: Expecting topology name of elements of 2d mesh to be " <<  basalside_name << " but it is " << elem2d_name);


  switch (ElemShape) {
  case Tetrahedron:
    stk::mesh::set_cell_topology<shards::Tetrahedron<4> >(*partVec[0]);
    stk::mesh::set_cell_topology<shards::Triangle<3> >(*ssPartVec[ssnBottom]);
    stk::mesh::set_cell_topology<shards::Triangle<3> >(*ssPartVec[ssnTop]);
    stk::mesh::set_cell_topology<shards::Triangle<3> >(*ssPartVec[ssnLat]);
    NumBaseElemeNodes = 3;
    break;
  case Wedge:
    stk::mesh::set_cell_topology<shards::Wedge<6> >(*partVec[0]);
    stk::mesh::set_cell_topology<shards::Triangle<3> >(*ssPartVec[ssnBottom]);
    stk::mesh::set_cell_topology<shards::Triangle<3> >(*ssPartVec[ssnTop]);
    stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnLat]);
    NumBaseElemeNodes = 3;
    break;
  case Hexahedron:
    stk::mesh::set_cell_topology<shards::Hexahedron<8> >(*partVec[0]);
    stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnBottom]);
    stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnTop]);
    stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnLat]);
    NumBaseElemeNodes = 4;
    break;
  }



  numDim = 3;
  int cub = params->get("Cubature Degree", 3);
  int worksetSizeMax = params->get("Workset Size", 50);
  int worksetSize = this->computeWorksetSize(worksetSizeMax, numCells);

  const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[0]).getCellTopologyData();

  this->meshSpecs[0] = Teuchos::rcp(new Albany::MeshSpecsStruct(ctd, numDim, cub, nsNames, ssNames, worksetSize, partVec[0]->name(), ebNameToIndex, this->interleavedOrdering));

}
コード例 #3
0
Albany::MpasSTKMeshStruct::MpasSTKMeshStruct(const Teuchos::RCP<Teuchos::ParameterList>& params,
                                             const Teuchos::RCP<const Epetra_Comm>& comm,
                                             const std::vector<int>& indexToTriangleID, const std::vector<int>& verticesOnTria, int nGlobalTriangles) :
  GenericSTKMeshStruct(params,Teuchos::null, 2),
  out(Teuchos::VerboseObjectBase::getDefaultOStream()),
  periodic(false),
  NumEles(indexToTriangleID.size()),
  hasRestartSol(false),
  restartTime(0.)
{
  elem_map = Teuchos::rcp(new Epetra_Map(nGlobalTriangles, indexToTriangleID.size(), &indexToTriangleID[0], 0, *comm)); // Distribute the elems equally
  
  params->validateParameters(*getValidDiscretizationParameters(),0);


  std::string ebn="Element Block 0";
  partVec[0] = & metaData->declare_part(ebn, stk::topology::ELEMENT_RANK );
  ebNameToIndex[ebn] = 0;

#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*partVec[0]);
#endif


  std::vector<std::string> nsNames;
  std::string nsn="Lateral";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, stk::topology::NODE_RANK );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="Internal";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, stk::topology::NODE_RANK );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif


  std::vector<std::string> ssNames;
  std::string ssn="LateralSide";
  ssNames.push_back(ssn);
    ssPartVec[ssn] = & metaData->declare_part(ssn, metaData->side_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*ssPartVec[ssn]);
#endif

  stk::mesh::set_cell_topology<shards::Triangle<3> >(*partVec[0]);
  stk::mesh::set_cell_topology<shards::Line<2> >(*ssPartVec[ssn]);

  numDim = 2;
  int cub = params->get("Cubature Degree",3);
  int worksetSizeMax = params->get("Workset Size",50);
  int worksetSize = this->computeWorksetSize(worksetSizeMax, elem_map->NumMyElements());

  const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[0]).getCellTopologyData();

  this->meshSpecs[0] = Teuchos::rcp(new Albany::MeshSpecsStruct(ctd, numDim, cub,
                             nsNames, ssNames, worksetSize, partVec[0]->name(),
                             ebNameToIndex, this->interleavedOrdering));


}
コード例 #4
0
Albany::IossSTKMeshStruct::IossSTKMeshStruct(
                                             const Teuchos::RCP<Teuchos::ParameterList>& params, 
                                             const Teuchos::RCP<Teuchos::ParameterList>& adaptParams_, 
                                             const Teuchos::RCP<const Epetra_Comm>& comm) :
  GenericSTKMeshStruct(params, adaptParams_),
  out(Teuchos::VerboseObjectBase::getDefaultOStream()),
  useSerialMesh(false),
  periodic(params->get("Periodic BC", false)),
  m_hasRestartSolution(false),
  m_restartDataTime(-1.0),
  m_solutionFieldHistoryDepth(0)
{
  params->validateParameters(*getValidDiscretizationParameters(),0);

  mesh_data = new stk::io::MeshData();

  usePamgen = (params->get("Method","Exodus") == "Pamgen");

  std::vector<std::string> entity_rank_names;

  // eMesh needs "FAMILY_TREE" entity
  if(buildEMesh)
    entity_rank_names.push_back("FAMILY_TREE");

#ifdef ALBANY_ZOLTAN  // rebalance requires Zoltan

  if (params->get<bool>("Use Serial Mesh", false) && comm->NumProc() > 1){ 
    // We are parallel but reading a single exodus file

    useSerialMesh = true;

    readSerialMesh(comm, entity_rank_names);

  }
  else 
#endif
    if (!usePamgen) {
      *out << "Albany_IOSS: Loading STKMesh from Exodus file  " 
           << params->get<std::string>("Exodus Input File Name") << std::endl;

      stk::io::create_input_mesh("exodusii",
//      create_input_mesh("exodusii",
                                 params->get<std::string>("Exodus Input File Name"),
                                 Albany::getMpiCommFromEpetraComm(*comm), 
                                 *metaData, *mesh_data,
                                 entity_rank_names); 
    }
    else {
      *out << "Albany_IOSS: Loading STKMesh from Pamgen file  " 
           << params->get<std::string>("Pamgen Input File Name") << std::endl;

      stk::io::create_input_mesh("pamgen",
//      create_input_mesh("pamgen",
                                 params->get<std::string>("Pamgen Input File Name"),
                                 Albany::getMpiCommFromEpetraComm(*comm), 
                                 *metaData, *mesh_data,
                                 entity_rank_names); 

    }

  typedef Teuchos::Array<std::string> StringArray;
  const StringArray additionalNodeSets = params->get("Additional Node Sets", StringArray());
  for (StringArray::const_iterator it = additionalNodeSets.begin(), it_end = additionalNodeSets.end(); it != it_end; ++it) {
    stk::mesh::Part &newNodeSet = metaData->declare_part(*it, metaData->node_rank());
    if (!stk::io::is_part_io_part(newNodeSet)) {
      stk::mesh::Field<double> * const distrFactorfield = metaData->get_field<stk::mesh::Field<double> >("distribution_factors");
      stk::mesh::put_field(*distrFactorfield, metaData->node_rank(), newNodeSet);
      stk::io::put_io_part_attribute(newNodeSet);
    }
  }

  numDim = metaData->spatial_dimension();

  stk::io::put_io_part_attribute(metaData->universal_part());

  // Set element blocks, side sets and node sets
  const stk::mesh::PartVector & all_parts = metaData->get_parts();
  std::vector<std::string> ssNames;
  std::vector<std::string> nsNames;
  int numEB = 0;

  for (stk::mesh::PartVector::const_iterator i = all_parts.begin();
       i != all_parts.end(); ++i) {

    stk::mesh::Part * const part = *i ;

    if ( part->primary_entity_rank() == metaData->element_rank()) {
      if (part->name()[0] != '{') {
        //*out << "IOSS-STK: Element part \"" << part->name() << "\" found " << std::endl;
        partVec[numEB] = part;
        numEB++;
      }
    }
    else if ( part->primary_entity_rank() == metaData->node_rank()) {
      if (part->name()[0] != '{') {
        //*out << "Mesh has Node Set ID: " << part->name() << std::endl;
        nsPartVec[part->name()]=part;
        nsNames.push_back(part->name());
      }
    }
    else if ( part->primary_entity_rank() == metaData->side_rank()) {
      if (part->name()[0] != '{') {
//        print(*out, "Found side_rank entity:\n", *part);
        ssPartVec[part->name()]=part;
      }
    }
  }

  cullSubsetParts(ssNames, ssPartVec); // Eliminate sidesets that are subsets of other sidesets

#if 0
  // for debugging, print out the parts now
  std::map<std::string, stk::mesh::Part*>::iterator it;

  for(it = ssPartVec.begin(); it != ssPartVec.end(); ++it){ // loop over the parts in the map

    // for each part in turn, get the name of parts that are a subset of it

    print(*out, "Found \n", *it->second);
  }
  // end debugging
#endif

  int cub = params->get("Cubature Degree",3);
  int worksetSizeMax = params->get("Workset Size",50);

  // Get number of elements per element block using Ioss for use
  // in calculating an upper bound on the worksetSize.
  std::vector<int> el_blocks;
  stk::io::get_element_block_sizes(*mesh_data, el_blocks);
  TEUCHOS_TEST_FOR_EXCEPT(el_blocks.size() != partVec.size());

  int ebSizeMax =  *std::max_element(el_blocks.begin(), el_blocks.end());
  int worksetSize = this->computeWorksetSize(worksetSizeMax, ebSizeMax);

  // Build a map to get the EB name given the index

  for (int eb=0; eb<numEB; eb++) 

    this->ebNameToIndex[partVec[eb]->name()] = eb;

  // Construct MeshSpecsStruct
  if (!params->get("Separate Evaluators by Element Block",false)) {

    const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[0]).getCellTopologyData();
    this->meshSpecs[0] = Teuchos::rcp(new Albany::MeshSpecsStruct(ctd, numDim, cub,
                                                                  nsNames, ssNames, worksetSize, partVec[0]->name(), 
                                                                  this->ebNameToIndex, this->interleavedOrdering));

  }
  else {

    *out << "MULTIPLE Elem Block in Ioss: DO worksetSize[eb] max?? " << std::endl; 
    this->allElementBlocksHaveSamePhysics=false;
    this->meshSpecs.resize(numEB);
    for (int eb=0; eb<numEB; eb++) {
      const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[eb]).getCellTopologyData();
      this->meshSpecs[eb] = Teuchos::rcp(new Albany::MeshSpecsStruct(ctd, numDim, cub,
                                                                     nsNames, ssNames, worksetSize, partVec[eb]->name(), 
                                                                     this->ebNameToIndex, this->interleavedOrdering));
      std::cout << "el_block_size[" << eb << "] = " << el_blocks[eb] << "   name  " << partVec[eb]->name() << std::endl; 
    }

  }

  {
    const Ioss::Region *inputRegion = mesh_data->m_input_region;
    m_solutionFieldHistoryDepth = inputRegion->get_property("state_count").get_int();
  }
}
コード例 #5
0
Albany::AsciiSTKMeshStruct::AsciiSTKMeshStruct(
                                             const Teuchos::RCP<Teuchos::ParameterList>& params, 
                                             const Teuchos::RCP<const Epetra_Comm>& comm) :
  GenericSTKMeshStruct(params,Teuchos::null,3),
  out(Teuchos::VerboseObjectBase::getDefaultOStream()),
  periodic(false)
{
   int numProc = comm->NumProc(); //total number of processors
   contigIDs = params->get("Contiguous IDs", true); 
   std::cout << "Number of processors: " << numProc << std::endl; 
   //names of files giving the mesh
   char meshfilename[100]; 
   char shfilename[100];
   char confilename[100];
   char bffilename[100];
   char geIDsfilename[100];
   char gnIDsfilename[100];
   char bfIDsfilename[100];
   char flwafilename[100]; //flow factor file
   char tempfilename[100]; //temperature file
   char betafilename[100]; //basal friction coefficient file
   if ((numProc == 1) & (contigIDs == true)) { //serial run with contiguous global IDs
     std::cout << "Ascii mesh has contiguous IDs; no bfIDs, geIDs, gnIDs files required." << std::endl;
     sprintf(meshfilename, "%s", "xyz");
     sprintf(shfilename, "%s", "sh");
     sprintf(confilename, "%s", "eles");
     sprintf(bffilename, "%s", "bf");
     sprintf(flwafilename, "%s", "flwa");
     sprintf(tempfilename, "%s", "temp");
     sprintf(betafilename, "%s", "beta");
   }
   else { //parallel run or serial run with non-contiguous global IDs - proc # is appended to file name to indicate what processor the mesh piece is on 
     if ((numProc == 1) & (contigIDs == false))
        std::cout << "1 processor run with non-contiguous IDs; bfIDs0, geIDs0, gnIDs0 files required." << std::endl;
     int suffix = comm->MyPID(); //current processor number 
     sprintf(meshfilename, "%s%i", "xyz", suffix);
     sprintf(shfilename, "%s%i", "sh", suffix);
     sprintf(confilename, "%s%i", "eles", suffix);
     sprintf(bffilename, "%s%i", "bf", suffix);
     sprintf(geIDsfilename, "%s%i", "geIDs", suffix);
     sprintf(gnIDsfilename, "%s%i", "gnIDs", suffix);
     sprintf(bfIDsfilename, "%s%i", "bfIDs", suffix);
     sprintf(flwafilename, "%s%i", "flwa", suffix);
     sprintf(tempfilename, "%s%i", "temp", suffix);
     sprintf(betafilename, "%s%i", "beta", suffix);
   }

    //read in coordinates of mesh -- right now hard coded for 3D
    //assumes mesh file is called "xyz" and its first row is the number of nodes  
    FILE *meshfile = fopen(meshfilename,"r");
    if (meshfile == NULL) { //check if coordinates file exists
      *out << "Error in AsciiSTKMeshStruct: coordinates file " << meshfilename <<" not found!"<< std::endl;
      TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
          std::endl << "Error in AsciiSTKMeshStruct: coordinates file " << meshfilename << " not found!"<< std::endl);
    }
    double temp; 
    fseek(meshfile, 0, SEEK_SET); 
    fscanf(meshfile, "%lf", &temp); 
    NumNodes = int(temp); 
    std::cout << "numNodes: " << NumNodes << std::endl;  
    xyz = new double[NumNodes][3]; 
    char buffer[100];
    fgets(buffer, 100, meshfile); 
    for (int i=0; i<NumNodes; i++){
      fgets(buffer, 100, meshfile); 
      sscanf(buffer, "%lf %lf %lf", &xyz[i][0], &xyz[i][1], &xyz[i][2]); 
      //*out << "i: " << i << ", x: " << xyz[i][0] << ", y: " << xyz[i][1] << ", z: " << xyz[i][2] << std::endl; 
     }
    //read in surface height data from mesh 
    //assumes surface height file is called "sh" and its first row is the number of nodes  
    FILE *shfile = fopen(shfilename,"r");
    have_sh = false;
    if (shfile != NULL) have_sh = true;
    if (have_sh) {
      fseek(shfile, 0, SEEK_SET); 
      fscanf(shfile, "%lf", &temp); 
      int NumNodesSh = int(temp);
      std::cout << "NumNodesSh: " << NumNodesSh<< std::endl; 
      if (NumNodesSh != NumNodes) { 
           *out << "Error in AsciiSTKMeshStruct: sh file must have same number nodes as xyz file!  numNodes in xyz = " << NumNodes <<", numNodes in sh = "<< NumNodesSh  << std::endl;
          TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
            std::endl << "Error in AsciiSTKMeshStruct: sh file must have same number nodes as xyz file!  numNodes in xyz = " << NumNodes << ", numNodes in sh = "<< NumNodesSh << std::endl);
      }
      sh = new double[NumNodes]; 
      fgets(buffer, 100, shfile); 
      for (int i=0; i<NumNodes; i++){
        fgets(buffer, 100, shfile); 
        sscanf(buffer, "%lf", &sh[i]); 
        //*out << "i: " << i << ", sh: " << sh[i] << std::endl; 
       }
     }
     //read in connectivity file -- right now hard coded for 3D hexes
     //assumes mesh file is called "eles" and its first row is the number of elements  
     FILE *confile = fopen(confilename,"r"); 
     if (confile == NULL) { //check if element connectivity file exists
      *out << "Error in AsciiSTKMeshStruct: element connectivity file " << confilename <<" not found!"<< std::endl;
      TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
          std::endl << "Error in AsciiSTKMeshStruct: element connectivity file " << confilename << " not found!"<< std::endl);
     }
     fseek(confile, 0, SEEK_SET); 
     fscanf(confile, "%lf", &temp); 
     NumEles = int(temp); 
     std::cout << "numEles: " << NumEles << std::endl; 
     eles = new int[NumEles][8]; 
     fgets(buffer, 100, confile); 
     for (int i=0; i<NumEles; i++){
        fgets(buffer, 100, confile); 
        sscanf(buffer, "%i %i %i %i %i %i %i %i", &eles[i][0], &eles[i][1], &eles[i][2], &eles[i][3], &eles[i][4], &eles[i][5], &eles[i][6], &eles[i][7]);
        //*out << "elt # " << i << ": " << eles[i][0] << " " << eles[i][1] << " " << eles[i][2] << " " << eles[i][3] << " " << eles[i][4] << " "
        //                  << eles[i][5] << " " << eles[i][6] << " " << eles[i][7] << std::endl; 
     }
    //read in basal face connectivity file from ascii file
    //assumes basal face connectivity file is called "bf" and its first row is the number of faces on basal boundary
    FILE *bffile = fopen(bffilename,"r");
    have_bf = false;
    if (bffile != NULL) have_bf = true;
    if (have_bf) {
      fseek(bffile, 0, SEEK_SET); 
      fscanf(bffile, "%lf", &temp); 
      NumBasalFaces = int(temp); 
      std::cout << "numBasalFaces: " << NumBasalFaces << std::endl;  
      bf = new int[NumBasalFaces][5]; //1st column of bf: element # that face belongs to, 2rd-5th columns of bf: connectivity (hard-coded for quad faces) 
      fgets(buffer, 100, bffile); 
      for (int i=0; i<NumBasalFaces; i++){
        fgets(buffer, 100, bffile); 
        sscanf(buffer, "%i %i %i %i %i", &bf[i][0], &bf[i][1], &bf[i][2], &bf[i][3], &bf[i][4]); 
        //*out << "face #:" << bf[i][0] << ", face conn:" << bf[i][1] << " " << bf[i][2] << " " << bf[i][3] << " " << bf[i][4] << std::endl; 
       }
     }
     //Create array w/ global element IDs 
     globalElesID = new int[NumEles];
     if ((numProc == 1) & (contigIDs == true)) { //serial run with contiguous global IDs: element IDs are just 0->NumEles-1
       for (int i=0; i<NumEles; i++) {
          globalElesID[i] = i; 
          //*out << "local element ID #:" << i << ", global element ID #:" << globalElesID[i] << std::endl;
       }
     }
     else {//parallel run: read global element IDs from file.  
           //This file should have a header like the other files, and length NumEles.
       FILE *geIDsfile = fopen(geIDsfilename,"r");
       if (geIDsfile == NULL) { //check if global element IDs file exists
         *out << "Error in AsciiSTKMeshStruct: global element IDs file " << geIDsfilename <<" not found!"<< std::endl;
         TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
            std::endl << "Error in AsciiSTKMeshStruct: global element IDs file " << geIDsfilename << " not found!"<< std::endl);
       }
       fseek(geIDsfile, 0, SEEK_SET);
       fgets(buffer, 100, geIDsfile);
       for (int i=0; i<NumEles; i++){
         fgets(buffer, 100, geIDsfile);
         sscanf(buffer, "%i ", &globalElesID[i]);
         globalElesID[i] = globalElesID[i]-1; //subtract 1 b/c global element IDs file assumed to be 1-based not 0-based
         //*out << "local element ID #:" << i << ", global element ID #:" << globalElesID[i] << std::endl;
       }
     }
     //Create array w/ global node IDs 
     globalNodesID = new int[NumNodes];
     if ((numProc == 1) & (contigIDs == true)) { //serial run with contiguous global IDs: element IDs are just 0->NumEles-1
       for (int i=0; i<NumNodes; i++) { 
          globalNodesID[i] = i; 
          //*out << "local node ID #:" << i << ", global node ID #:" << globalNodesID[i] << std::endl;
       }
     }
     else {//parallel run: read global node IDs from file.  
           //This file should have a header like the other files, and length NumNodes
       FILE *gnIDsfile = fopen(gnIDsfilename,"r");
       if (gnIDsfile == NULL) { //check if global node IDs file exists
         *out << "Error in AsciiSTKMeshStruct: global node IDs file " << gnIDsfilename <<" not found!"<< std::endl;
         TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
            std::endl << "Error in AsciiSTKMeshStruct: global node IDs file " << gnIDsfilename << " not found!"<< std::endl);
       }
       fseek(gnIDsfile, 0, SEEK_SET);
       fgets(buffer, 100, gnIDsfile);
       for (int i=0; i<NumNodes; i++){
         fgets(buffer, 100, gnIDsfile);
         sscanf(buffer, "%i ", &globalNodesID[i]);
         globalNodesID[i] = globalNodesID[i]-1; //subtract 1 b/c global node IDs file assumed to be 1-based not 0-based 
         //*out << "local node ID #:" << i << ", global node ID #:" << globalNodesID[i] << std::endl;
       }
     }
     basalFacesID = new int[NumBasalFaces];
     if ((numProc == 1) & (contigIDs == true)) { //serial run with contiguous global IDs: element IDs are just 0->NumEles-1
       for (int i=0; i<NumBasalFaces; i++) { 
          basalFacesID[i] = i; 
          //*out << "local face ID #:" << i << ", global face ID #:" << basalFacesID[i] << std::endl;
       }
     }
     else {//parallel run: read basal face IDs from file.  
           //This file should have a header like the other files, and length NumBasalFaces
       FILE *bfIDsfile = fopen(bfIDsfilename,"r");
       fseek(bfIDsfile, 0, SEEK_SET);
       fgets(buffer, 100, bfIDsfile);
       for (int i=0; i<NumBasalFaces; i++){
         fgets(buffer, 100, bfIDsfile);
         sscanf(buffer, "%i ", &basalFacesID[i]);
         basalFacesID[i] = basalFacesID[i]-1; //subtract 1 b/c basal face IDs file assumed to be 1-based not 0-based
         //*out << "local face ID #:" << i << ", global face ID #:" << basalFacesID[i] << std::endl;
       }
     }
    //read in flow factor (flwa) data from mesh 
    //assumes flow factor file is called "flwa" and its first row is the number of elements in the mesh
    FILE *flwafile = fopen(flwafilename,"r");
    have_flwa = false;
    if (flwafile != NULL) have_flwa = true;
    if (have_flwa) {
      fseek(flwafile, 0, SEEK_SET); 
      fscanf(flwafile, "%lf", &temp); 
      flwa = new double[NumEles]; 
      fgets(buffer, 100, flwafile); 
      for (int i=0; i<NumEles; i++){
        fgets(buffer, 100, flwafile); 
        sscanf(buffer, "%lf", &flwa[i]); 
        //*out << "i: " << i << ", flwa: " << flwa[i] << std::endl; 
       }
     }
    //read in temperature data from mesh 
    //assumes temperature file is called "temp" and its first row is the number of elements in the mesh
    FILE *tempfile = fopen(tempfilename,"r");
    have_temp = false;
    if (tempfile != NULL) have_temp = true;
    if (have_temp) {
      fseek(tempfile, 0, SEEK_SET); 
      fscanf(tempfile, "%lf", &temp); 
      temper = new double[NumEles]; 
      fgets(buffer, 100, tempfile); 
      for (int i=0; i<NumEles; i++){
        fgets(buffer, 100, tempfile); 
        sscanf(buffer, "%lf", &temper[i]); 
        //*out << "i: " << i << ", temp: " << temper[i] << std::endl; 
       }
     }
    //read in basal friction (beta) data from mesh 
    //assumes basal friction file is called "beta" and its first row is the number of nodes  
    FILE *betafile = fopen(betafilename,"r");
    have_beta = false;
    if (betafile != NULL) have_beta = true;
    if (have_beta) {
      fseek(betafile, 0, SEEK_SET); 
      fscanf(betafile, "%lf", &temp); 
      beta = new double[NumNodes]; 
      fgets(buffer, 100, betafile); 
      for (int i=0; i<NumNodes; i++){
        fgets(buffer, 100, betafile); 
        sscanf(buffer, "%lf", &beta[i]); 
        //*out << "i: " << i << ", beta: " << beta[i] << std::endl; 
       }
     }
 
  elem_map = Teuchos::rcp(new Epetra_Map(-1, NumEles, globalElesID, 0, *comm)); //Distribute the elements according to the global element IDs
  node_map = Teuchos::rcp(new Epetra_Map(-1, NumNodes, globalNodesID, 0, *comm)); //Distribute the nodes according to the global node IDs 
  basal_face_map = Teuchos::rcp(new Epetra_Map(-1, NumBasalFaces, basalFacesID, 0, *comm)); //Distribute the elements according to the basal face IDs

  
  params->validateParameters(*getValidDiscretizationParameters(),0);


  std::string ebn="Element Block 0";
  partVec[0] = & metaData->declare_part(ebn, metaData->element_rank() );
  ebNameToIndex[ebn] = 0;

#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*partVec[0]);
#endif


  std::vector<std::string> nsNames;
  std::string nsn="Bottom";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, metaData->node_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="NodeSet0";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, metaData->node_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="NodeSet1";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, metaData->node_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="NodeSet2";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, metaData->node_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="NodeSet3";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, metaData->node_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="NodeSet4";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, metaData->node_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif
  nsn="NodeSet5";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, metaData->node_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif


  std::vector<std::string> ssNames;
  std::string ssn="Basal";
  ssNames.push_back(ssn);
    ssPartVec[ssn] = & metaData->declare_part(ssn, metaData->side_rank() );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*ssPartVec[ssn]);
#endif

  stk::mesh::fem::set_cell_topology<shards::Hexahedron<8> >(*partVec[0]);
  stk::mesh::fem::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssn]);

  numDim = 3;
  int cub = params->get("Cubature Degree",3);
  int worksetSizeMax = params->get("Workset Size",50);
  int worksetSize = this->computeWorksetSize(worksetSizeMax, elem_map->NumMyElements());

  const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[0]).getCellTopologyData();

  this->meshSpecs[0] = Teuchos::rcp(new Albany::MeshSpecsStruct(ctd, numDim, cub,
                             nsNames, ssNames, worksetSize, partVec[0]->name(),
                             ebNameToIndex, this->interleavedOrdering));


}
コード例 #6
0
//Constructor for arrays passed from CISM through Albany-CISM interface
Albany::CismSTKMeshStruct::CismSTKMeshStruct(
                  const Teuchos::RCP<Teuchos::ParameterList>& params,
                  const Teuchos::RCP<const Teuchos_Comm>& commT,
                  const double * xyz_at_nodes_Ptr,
                  const int * global_node_id_owned_map_Ptr,
                  const int * global_element_id_active_owned_map_Ptr,
                  const int * global_element_conn_active_Ptr,
                  const int * global_basal_face_active_owned_map_Ptr,
                  const int * global_top_face_active_owned_map_Ptr,
                  const int * global_basal_face_conn_active_Ptr,
                  const int * global_top_face_conn_active_Ptr,
                  const int * global_west_face_active_owned_map_Ptr,
                  const int * global_west_face_conn_active_Ptr,
                  const int * global_east_face_active_owned_map_Ptr,
                  const int * global_east_face_conn_active_Ptr,
                  const int * global_south_face_active_owned_map_Ptr,
                  const int * global_south_face_conn_active_Ptr,
                  const int * global_north_face_active_owned_map_Ptr,
                  const int * global_north_face_conn_active_Ptr,
                  const int * dirichlet_node_mask_Ptr,
                  const double * uvel_at_nodes_Ptr,
                  const double * vvel_at_nodes_Ptr, 
                  const double * beta_at_nodes_Ptr,
                  const double * surf_height_at_nodes_Ptr,
                  const double * dsurf_height_at_nodes_dx_Ptr,
                  const double * dsurf_height_at_nodes_dy_Ptr,
                  const double * thick_at_nodes_Ptr,
                  const double * flwa_at_active_elements_Ptr,
                  const int nNodes, const int nElementsActive,
                  const int nCellsActive, const int nWestFacesActive, 
                  const int nEastFacesActive, const int nSouthFacesActive, 
                  const int nNorthFacesActive, 
                  const int verbosity) :
  GenericSTKMeshStruct(params,Teuchos::null,3),
  out(Teuchos::VerboseObjectBase::getDefaultOStream()),
  hasRestartSol(false),
  restartTime(0.0),
  periodic(false)
{
  if (verbosity == 1 & commT->getRank() == 0) std::cout <<"In Albany::CismSTKMeshStruct - double * array inputs!" << std::endl;
  NumNodes = nNodes;
  NumEles = nElementsActive;
  NumBasalFaces = nCellsActive;
  NumWestFaces =  nWestFacesActive; 
  NumEastFaces =  nEastFacesActive; 
  NumSouthFaces = nSouthFacesActive; 
  NumNorthFaces = nNorthFacesActive; 
  debug_output_verbosity = verbosity;
  if (verbosity == 2) {
    std::cout <<"Proc #" << commT->getRank() << ", NumNodes = " << NumNodes << ", NumEles = "<< NumEles << ", NumBasalFaces = " << NumBasalFaces 
               <<", NumWestFaces = " << NumWestFaces << ", NumEastFaces = "<< NumEastFaces 
              << ", NumSouthFaces = " << NumSouthFaces << ", NumNorthFaces = " << NumNorthFaces <<  std::endl;
  }
  xyz = new double[NumNodes][3];
  eles = new int[NumEles][8];
  dirichletNodeMask = new int[NumNodes];
  //1st column of bf: element # that face belongs to, 2rd-5th columns of bf: connectivity (hard-coded for quad faces)
  bf = new int[NumBasalFaces][5]; 
  tf = new int[NumBasalFaces][5]; 
  wf = new int[NumWestFaces][5]; 
  ef = new int[NumEastFaces][5]; 
  sf = new int[NumSouthFaces][5]; 
  nf = new int[NumNorthFaces][5]; 
  sh = new double[NumNodes];
  thck = new double[NumNodes];
  shGrad = new double[NumNodes][2];
  globalNodesID = new GO[NumNodes];
  globalElesID = new GO[NumEles];
  basalFacesID = new GO[NumBasalFaces];
  topFacesID = new GO[NumBasalFaces];
  westFacesID = new GO[NumWestFaces]; 
  eastFacesID = new GO[NumEastFaces]; 
  southFacesID = new GO[NumSouthFaces]; 
  northFacesID = new GO[NumNorthFaces]; 
  flwa = new double[NumEles];
  beta = new double[NumNodes];
  uvel = new double[NumNodes];
  vvel = new double[NumNodes];
  //TO DO? pass in temper?  for now, flwa is passed instead of temper
  //temper = new double[NumEles];

  //check if optional input fields exist
  if (surf_height_at_nodes_Ptr != NULL) have_sh = true;
  else have_sh = false;
  if (thick_at_nodes_Ptr != NULL) have_thck = true;
  else have_thck = false;
  if (dsurf_height_at_nodes_dx_Ptr != NULL && dsurf_height_at_nodes_dy_Ptr != NULL) have_shGrad = true;
  else have_shGrad = false;
  if (global_basal_face_active_owned_map_Ptr != NULL) have_bf = true; 
  else  have_bf = false;
  if (global_top_face_active_owned_map_Ptr != NULL) have_tf = true; 
  else  have_tf = false;
  if (flwa_at_active_elements_Ptr != NULL) have_flwa = true;
  else have_flwa = false;
  if (beta_at_nodes_Ptr != NULL) have_beta = true;
  else have_beta = false;
  if (global_west_face_active_owned_map_Ptr != NULL && NumWestFaces > 0) have_wf = true; 
  else have_wf = false; 
  if (global_east_face_active_owned_map_Ptr != NULL && NumEastFaces > 0) have_ef = true;
  else have_ef = false;
  if (global_south_face_active_owned_map_Ptr != NULL && NumSouthFaces > 0) have_sf = true;
  else have_sf = false;
  if (global_north_face_active_owned_map_Ptr != NULL && NumNorthFaces > 0) have_nf = true;
  else have_nf = false;
  have_temp = false; //for now temperature field is not passed; flwa is passed instead
  if (dirichlet_node_mask_Ptr != NULL) have_dirichlet = true; 
  else have_dirichlet = false; 

  for (int i=0; i<NumNodes; i++){
    globalNodesID[i] = global_node_id_owned_map_Ptr[i]-1;
    for (int j=0; j<3; j++)
      xyz[i][j] = xyz_at_nodes_Ptr[i + NumNodes*j];
    //*out << "i: " << i << ", x: " << xyz[i][0] 
         //<< ", y: " << xyz[i][1] << ", z: " << xyz[i][2] << std::endl;
  }
  if (have_sh) {
    for (int i=0; i<NumNodes; i++)
      sh[i] = surf_height_at_nodes_Ptr[i];
  }
  if (have_thck) {
    for (int i=0; i<NumNodes; i++)
      thck[i] = thick_at_nodes_Ptr[i];
  }
  if (have_shGrad) {
    for (int i=0; i<NumNodes; i++){
      shGrad[i][0] = dsurf_height_at_nodes_dx_Ptr[i];
      shGrad[i][1] = dsurf_height_at_nodes_dy_Ptr[i];
    }
  }
  if (have_beta) {
    for (int i=0; i<NumNodes; i++) {
      beta[i] = beta_at_nodes_Ptr[i];
      //*out << "beta[i] " << beta[i] << std::endl;
    }
  }

  for (int i=0; i<NumEles; i++) {
    globalElesID[i] = global_element_id_active_owned_map_Ptr[i]-1;
    for (int j = 0; j<8; j++)
      eles[i][j] = global_element_conn_active_Ptr[i + nElementsActive*j];
    //*out << "elt # " << globalElesID[i] << ": " << eles[i][0] 
    //     << " " << eles[i][1] << " " << eles[i][2] << " " 
    //     << eles[i][3] << " " << eles[i][4] << " "
    //     << eles[i][5] << " " << eles[i][6] << " " << eles[i][7] << std::endl;
  }
  if (have_dirichlet) {
    for (int i=0; i<NumNodes; i++) {
      dirichletNodeMask[i] = dirichlet_node_mask_Ptr[i];
      uvel[i] = uvel_at_nodes_Ptr[i]; 
      vvel[i] = vvel_at_nodes_Ptr[i]; 
      //*out << "i: " << i << ", x: " << xyz[i][0] 
      //     << ", y: " << xyz[i][1] << ", z: " << xyz[i][2] << ", dirichlet: " << dirichletNodeMask[i] << std::endl;
      /*if (abs(uvel[i]) > 0) {
      *out << "i: " << i << ", x: " << xyz[i][0] 
           << ", y: " << xyz[i][1] << ", z: " << xyz[i][2] << ", uvel: " << uvel[i] << ", vvel: " << vvel[i] << std::endl;
      }*/
    }
  }

  if (have_flwa) {
    for (int i=0; i<NumEles; i++)
      flwa[i] = flwa_at_active_elements_Ptr[i];
  }
  if (have_bf) {
    for (int i=0; i<NumBasalFaces; i++) {
      basalFacesID[i] = global_basal_face_active_owned_map_Ptr[i]-1;
      for (int j=0; j<5; j++)
        bf[i][j] = global_basal_face_conn_active_Ptr[i + nCellsActive*j];
        //*out << "bf # " << basalFacesID[i] << ": " << bf[i][0] << " " << bf[i][1] << " " << bf[i][2] << " " << bf[i][3] << " " << bf[i][4] << std::endl;
    }
  }
  if (have_tf) {
    for (int i=0; i<NumBasalFaces; i++) {
      topFacesID[i] = global_top_face_active_owned_map_Ptr[i]-1;
      for (int j=0; j<5; j++)
        tf[i][j] = global_top_face_conn_active_Ptr[i + nCellsActive*j];
    }
  }
  if (have_wf) {
    for (int i=0; i<NumWestFaces; i++) {
       westFacesID[i] = global_west_face_active_owned_map_Ptr[i]-1;    
       for (int j=0; j<5; j++) 
         wf[i][j] = global_west_face_conn_active_Ptr[i + NumWestFaces*j]; 
    }
  }
  if (have_ef) {
    for (int i=0; i<NumEastFaces; i++) {
       eastFacesID[i] = global_east_face_active_owned_map_Ptr[i]-1;    
       for (int j=0; j<5; j++) 
         ef[i][j] = global_east_face_conn_active_Ptr[i + NumEastFaces*j]; 
    }
  }
  if (have_sf) {
    for (int i=0; i<NumSouthFaces; i++) {
       southFacesID[i] = global_south_face_active_owned_map_Ptr[i]-1;    
       for (int j=0; j<5; j++)  
         sf[i][j] = global_south_face_conn_active_Ptr[i + NumSouthFaces*j];
        /*if (commT->getRank() == 0) { 
          *out << "proc 0, sf # " << southFacesID[i] << ": " << sf[i][0] << " " << sf[i][1] << " " << sf[i][2] << " " << sf[i][3] << " " << sf[i][4] << std::endl; }
        if (commT->getRank() == 1) { 
          *out << "proc 1, sf # " << southFacesID[i] << ": " << sf[i][0] << " " << sf[i][1] << " " << sf[i][2] << " " << sf[i][3] << " " << bf[i][4] << std::endl; }
        if (commT->getRank() == 2) { 
          *out << "proc 2, sf # " << southFacesID[i] << ": " << sf[i][0] << " " << sf[i][1] << " " << sf[i][2] << " " << sf[i][3] << " " << sf[i][4] << std::endl; }
        if (commT->getRank() == 3) { 
          *out << "proc 3, sf # " << southFacesID[i] << ": " << sf[i][0] << " " << sf[i][1] << " " << sf[i][2] << " " << sf[i][3] << " " << sf[i][4] << std::endl; } */
    }
  }
  if (have_nf) {
    for (int i=0; i<NumNorthFaces; i++) {
       northFacesID[i] = global_north_face_active_owned_map_Ptr[i]-1;    
       for (int j=0; j<5; j++) 
         nf[i][j] = global_north_face_conn_active_Ptr[i + NumNorthFaces*j]; 
    }
  }


  Teuchos::ArrayView<const GO> globalElesIDAV = Teuchos::arrayView(globalElesID, NumEles);
  Teuchos::ArrayView<const GO> globalNodesIDAV = Teuchos::arrayView(globalNodesID, NumNodes);
  Teuchos::ArrayView<const GO> basalFacesIDAV = Teuchos::arrayView(basalFacesID, NumBasalFaces);
  Teuchos::ArrayView<const GO> topFacesIDAV = Teuchos::arrayView(topFacesID, NumBasalFaces);
  Teuchos::ArrayView<const GO> westFacesIDAV = Teuchos::arrayView(westFacesID, NumWestFaces);
  Teuchos::ArrayView<const GO> eastFacesIDAV = Teuchos::arrayView(eastFacesID, NumEastFaces);
  Teuchos::ArrayView<const GO> southFacesIDAV = Teuchos::arrayView(southFacesID, NumSouthFaces);
  Teuchos::ArrayView<const GO> northFacesIDAV = Teuchos::arrayView(northFacesID, NumNorthFaces);
  //Distribute the elements according to the global element IDs
  elem_mapT = Teuchos::rcp(new Tpetra_Map(NumEles, globalElesIDAV, 0, commT)); 
  //Distribute the nodes according to the global node IDs
  node_mapT = Teuchos::rcp(new Tpetra_Map(NumNodes, globalNodesIDAV, 0, commT));
  //Distribute the elements according to the basal face IDs
  basal_face_mapT = Teuchos::rcp(new Tpetra_Map(NumBasalFaces, basalFacesIDAV, 0, commT));
  //Distribute the elements according to the top face IDs
  top_face_mapT = Teuchos::rcp(new Tpetra_Map(NumBasalFaces, topFacesIDAV, 0, commT));
  //Distribute the elements according to the lateral face IDs
  west_face_mapT = Teuchos::rcp(new Tpetra_Map(NumWestFaces, westFacesIDAV, 0, commT));
  east_face_mapT = Teuchos::rcp(new Tpetra_Map(NumEastFaces, eastFacesIDAV, 0, commT));
  south_face_mapT = Teuchos::rcp(new Tpetra_Map(NumSouthFaces, southFacesIDAV, 0, commT));
  north_face_mapT = Teuchos::rcp(new Tpetra_Map(NumNorthFaces, northFacesIDAV, 0, commT));


  params->validateParameters(*getValidDiscretizationParameters(),0);


  std::string ebn="Element Block 0";
  partVec[0] = & metaData->declare_part(ebn, stk::topology::ELEMENT_RANK );
  ebNameToIndex[ebn] = 0;

#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*partVec[0]);
#endif


  std::vector<std::string> nsNames;
  std::string nsn="NodeSetDirichlet";
  nsNames.push_back(nsn);
  nsPartVec[nsn] = & metaData->declare_part(nsn, stk::topology::NODE_RANK );
#ifdef ALBANY_SEACAS
    stk::io::put_io_part_attribute(*nsPartVec[nsn]);
#endif


  std::vector<std::string> ssNames;
  std::string ssnBasal="Basal";
  std::string ssnTop="Top";
  std::string ssnLateral="Lateral";

  ssNames.push_back(ssnBasal);
  ssNames.push_back(ssnTop);
  ssNames.push_back(ssnLateral);

  ssPartVec[ssnBasal] = & metaData->declare_part(ssnBasal, metaData->side_rank() );
  ssPartVec[ssnTop] = & metaData->declare_part(ssnTop, metaData->side_rank() );
  ssPartVec[ssnLateral] = & metaData->declare_part(ssnLateral, metaData->side_rank() );
#ifdef ALBANY_SEACAS
  stk::io::put_io_part_attribute(*ssPartVec[ssnBasal]);
  stk::io::put_io_part_attribute(*ssPartVec[ssnTop]);
  stk::io::put_io_part_attribute(*ssPartVec[ssnLateral]);
#endif
  stk::mesh::set_cell_topology<shards::Hexahedron<8> >(*partVec[0]);
  stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnBasal]);
  stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnTop]);
  stk::mesh::set_cell_topology<shards::Quadrilateral<4> >(*ssPartVec[ssnLateral]);

  numDim = 3;
  int cub = params->get("Cubature Degree",3);
  int worksetSizeMax = params->get("Workset Size",50);
  int worksetSize = this->computeWorksetSize(worksetSizeMax, elem_mapT->getNodeNumElements());

  const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[0]).getCellTopologyData();

  this->meshSpecs[0] = Teuchos::rcp(new Albany::MeshSpecsStruct(ctd, numDim, cub,
                             nsNames, ssNames, worksetSize, partVec[0]->name(),
                             ebNameToIndex, this->interleavedOrdering));

}
コード例 #7
0
Albany::IossSTKMeshStruct::IossSTKMeshStruct(
                                             const Teuchos::RCP<Teuchos::ParameterList>& params,
                                             const Teuchos::RCP<Teuchos::ParameterList>& adaptParams_,
                                             const Teuchos::RCP<const Teuchos_Comm>& commT) :
  GenericSTKMeshStruct(params, adaptParams_),
  out(Teuchos::VerboseObjectBase::getDefaultOStream()),
  useSerialMesh(false),
  periodic(params->get("Periodic BC", false)),
  m_hasRestartSolution(false),
  m_restartDataTime(-1.0),
  m_solutionFieldHistoryDepth(0)
{
  params->validateParameters(*getValidDiscretizationParameters(),0);

  usePamgen = (params->get("Method","Exodus") == "Pamgen");


  const Teuchos::MpiComm<int>* mpiComm = dynamic_cast<const Teuchos::MpiComm<int>* > (commT.get());
  std::vector<std::string> entity_rank_names = stk::mesh::entity_rank_names();

  // eMesh needs "FAMILY_TREE" entity
  if(buildEMesh) {
    entity_rank_names.push_back("FAMILY_TREE");
  }

  const Teuchos::MpiComm<int>* theComm = dynamic_cast<const Teuchos::MpiComm<int>* > (commT.get());
  if (params->get<bool>("Use Serial Mesh", false) && commT->getSize() > 1){
    // We are parallel but reading a single exodus file
    useSerialMesh = true;

    // Read a single exodus mesh on Proc 0 then rebalance it across the machine
    MPI_Group group_world;
    MPI_Group peZero;
    MPI_Comm peZeroComm;
    //MPI_Comm theComm = Albany::getMpiCommFromEpetraComm(*comm);
    int process_rank[1]; // the reader process
    process_rank[0] = 0;
    int my_rank = commT->getRank();

    //get the group under theComm
    MPI_Comm_group(*theComm->getRawMpiComm(), &group_world);
    // create the new group. This group includes only processor zero - that is the only processor that reads the file
    MPI_Group_incl(group_world, 1, process_rank, &peZero);
    // create the new communicator - it just contains processor zero
    MPI_Comm_create(*theComm->getRawMpiComm(), peZero, &peZeroComm);

    mesh_data = Teuchos::rcp(new stk::io::StkMeshIoBroker(peZeroComm));
  }
  else {
    mesh_data = Teuchos::rcp(new stk::io::StkMeshIoBroker(*theComm->getRawMpiComm()));
  }

  // Create input mesh

  mesh_data->set_rank_name_vector(entity_rank_names);
  mesh_data->set_sideset_face_creation_behavior(stk::io::StkMeshIoBroker::STK_IO_SIDESET_FACE_CREATION_CLASSIC);
  //StkMeshIoBroker::set_sideset_face_creation_behavior(stk::io::StkMeshIoBroker::STK_IO_SIDESET_FACE_CREATION_CLASSIC);
  std::string mesh_type;
  std::string file_name;
  if (!usePamgen) {
    *out << "Albany_IOSS: Loading STKMesh from Exodus file  "
         << params->get<std::string>("Exodus Input File Name") << std::endl;

    mesh_type = "exodusII";
    file_name = params->get<std::string>("Exodus Input File Name");
  }
  else {
    *out << "Albany_IOSS: Loading STKMesh from Pamgen file  "
         << params->get<std::string>("Pamgen Input File Name") << std::endl;

    mesh_type = "pamgen";
    file_name = params->get<std::string>("Pamgen Input File Name");
  }

  mesh_data->add_mesh_database(file_name, mesh_type, stk::io::READ_MESH);
  mesh_data->create_input_mesh();

  metaData = mesh_data->meta_data_rcp();

  // End of creating input mesh

  typedef Teuchos::Array<std::string> StringArray;
  const StringArray additionalNodeSets = params->get("Additional Node Sets", StringArray());
  for (StringArray::const_iterator it = additionalNodeSets.begin(), it_end = additionalNodeSets.end(); it != it_end; ++it) {
    stk::mesh::Part &newNodeSet = metaData->declare_part(*it, stk::topology::NODE_RANK);
    if (!stk::io::is_part_io_part(newNodeSet)) {
      stk::mesh::Field<double> * const distrFactorfield = metaData->get_field<stk::mesh::Field<double> >(stk::topology::NODE_RANK, "distribution_factors");
      stk::mesh::put_field(*distrFactorfield, newNodeSet);
      stk::io::put_io_part_attribute(newNodeSet);
    }
  }

  numDim = metaData->spatial_dimension();

  stk::io::put_io_part_attribute(metaData->universal_part());

  // Set element blocks, side sets and node sets
  const stk::mesh::PartVector & all_parts = metaData->get_parts();
  std::vector<std::string> ssNames;
  std::vector<std::string> nsNames;
  int numEB = 0;

  for (stk::mesh::PartVector::const_iterator i = all_parts.begin();
       i != all_parts.end(); ++i) {

    stk::mesh::Part * const part = *i ;

    if (!stk::mesh::is_auto_declared_part(*part)) {
      if ( part->primary_entity_rank() == stk::topology::ELEMENT_RANK) {

        //*out << "IOSS-STK: Element part \"" << part->name() << "\" found " << std::endl;
        partVec[numEB] = part;
        numEB++;
      }
      else if ( part->primary_entity_rank() == stk::topology::NODE_RANK) {
        //*out << "Mesh has Node Set ID: " << part->name() << std::endl;
        nsPartVec[part->name()]=part;
        nsNames.push_back(part->name());
      }
      else if ( part->primary_entity_rank() == metaData->side_rank()) {
        //print(*out, "Found side_rank entity:\n", *part);
        ssPartVec[part->name()]=part;
      }
    }
  }

  cullSubsetParts(ssNames, ssPartVec); // Eliminate sidesets that are subsets of other sidesets

#if 0
  // for debugging, print out the parts now
  std::map<std::string, stk::mesh::Part*>::iterator it;

  for(it = ssPartVec.begin(); it != ssPartVec.end(); ++it){ // loop over the parts in the map

    // for each part in turn, get the name of parts that are a subset of it

    print(*out, "Found \n", *it->second);
  }
  // end debugging
#endif

  const int cub      = params->get("Cubature Degree",3);
  
  //Get Cubature Rule
  const std::string cub_rule_string = params->get("Cubature Rule", "GAUSS");
  Intrepid2::EIntrepidPLPoly cub_rule;  
  if (cub_rule_string == "GAUSS")
    cub_rule = static_cast<Intrepid2::EIntrepidPLPoly>(Intrepid2::PL_GAUSS); 
  else if (cub_rule_string == "GAUSS_RADAU_LEFT") 
    cub_rule = static_cast<Intrepid2::EIntrepidPLPoly>(Intrepid2::PL_GAUSS_RADAU_LEFT); 
  else if (cub_rule_string == "GAUSS_RADAU_RIGHT") 
    cub_rule = static_cast<Intrepid2::EIntrepidPLPoly>(Intrepid2::PL_GAUSS_RADAU_RIGHT); 
  else if (cub_rule_string == "GAUSS_LOBATTO")
    cub_rule = static_cast<Intrepid2::EIntrepidPLPoly>(Intrepid2::PL_GAUSS_LOBATTO); 
  else
    TEUCHOS_TEST_FOR_EXCEPTION (true, Teuchos::Exceptions::InvalidParameterValue,
                                "Invalid Cubature Rule: " << cub_rule_string << "; valid options are GAUSS, GAUSS_RADAU_LEFT, GAUSS_RADAU_RIGHT, and GAUSS_LOBATTO");

  int worksetSizeMax = params->get("Workset Size",50);

  // Get number of elements per element block using Ioss for use
  // in calculating an upper bound on the worksetSize.
  std::vector<int> el_blocks;
  get_element_block_sizes(*mesh_data, el_blocks);
  TEUCHOS_TEST_FOR_EXCEPT(el_blocks.size() != partVec.size());

  int ebSizeMax =  *std::max_element(el_blocks.begin(), el_blocks.end());
  int worksetSize = this->computeWorksetSize(worksetSizeMax, ebSizeMax);

  // Build a map to get the EB name given the index

  for (int eb=0; eb<numEB; eb++)

    this->ebNameToIndex[partVec[eb]->name()] = eb;

  // Construct MeshSpecsStruct
  if (!params->get("Separate Evaluators by Element Block",false)) {

    const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[0]).getCellTopologyData();
    this->meshSpecs[0] = Teuchos::rcp(new Albany::MeshSpecsStruct(
        ctd, numDim, cub, nsNames, ssNames, worksetSize, partVec[0]->name(),
        this->ebNameToIndex, this->interleavedOrdering, false, cub_rule));

  }
  else {

    *out << "MULTIPLE Elem Block in Ioss: DO worksetSize[eb] max?? " << std::endl;
    this->allElementBlocksHaveSamePhysics=false;
    this->meshSpecs.resize(numEB);
    for (int eb=0; eb<numEB; eb++) {
      const CellTopologyData& ctd = *metaData->get_cell_topology(*partVec[eb]).getCellTopologyData();
      this->meshSpecs[eb] = Teuchos::rcp(new Albany::MeshSpecsStruct(
          ctd, numDim, cub, nsNames, ssNames, worksetSize, partVec[eb]->name(),
          this->ebNameToIndex, this->interleavedOrdering, true, cub_rule));
      //std::cout << "el_block_size[" << eb << "] = " << el_blocks[eb] << "   name  " << partVec[eb]->name() << std::endl;
    }

  }

  {
    const Ioss::Region& inputRegion = *(mesh_data->get_input_io_region());
    m_solutionFieldHistoryDepth = inputRegion.get_property("state_count").get_int();
  }
}
コード例 #8
0
#include <stk_mesh/fem/FEMHelpers.hpp>
#include <stk_mesh/fem/EntityRanks.hpp>
#include "Albany_Utils.hpp"

enum { field_data_chunk_size = 1001 };


Albany::FromCubitSTKMeshStruct::FromCubitSTKMeshStruct(
                  const Teuchos::RCP<CUTR::CubitMeshMover>& meshMover, 
                  const Teuchos::RCP<Teuchos::ParameterList>& params, 
                  const unsigned int neq_,
                  const Teuchos::RCP<Albany::StateInfoStruct>& sis,
) :
  periodic(params->get("Periodic BC", false))
{
  params->validateParameters(*getValidDiscretizationParameters(),0);
  neq=neq_;

  // Get singleton to STK info as loaded by Cubit MeshMover
  STKMeshData* stkMeshData = STKMeshData::instance();

  metaData = stkMeshData->get_meta_data();
  coordinates_field = stkMeshData->get_coords_field();

  solution_field = & metaData->declare_field< VectorFieldType >( "solution" );
  residual_field = & metaData->declare_field< VectorFieldType >( "residual" );
  stk::mesh::put_field( *solution_field , metaData->node_rank() , metaData->universal_part(), neq );
  stk::mesh::put_field( *residual_field , metaData->node_rank() , metaData->universal_part() , neq );

  // Construct nsPartVec from similar stkMeshData struct
  std::map<int, stk::mesh::Part*> nsList= stkMeshData->get_nodeset_list();