• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Albany_OrdinarySTKFieldContainer_Def.hpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 
00007 #include <iostream>
00008 
00009 #include "Albany_OrdinarySTKFieldContainer.hpp"
00010 
00011 #include "Albany_Utils.hpp"
00012 #include <stk_mesh/base/GetBuckets.hpp>
00013 
00014 #ifdef ALBANY_SEACAS
00015 #include <stk_io/IossBridge.hpp>
00016 #endif
00017 
00018 template<bool Interleaved>
00019 Albany::OrdinarySTKFieldContainer<Interleaved>::OrdinarySTKFieldContainer(
00020   const Teuchos::RCP<Teuchos::ParameterList>& params_,
00021   stk::mesh::fem::FEMMetaData* metaData_,
00022   stk::mesh::BulkData* bulkData_,
00023   const int neq_,
00024   const AbstractFieldContainer::FieldContainerRequirements& req,
00025   const int numDim_,
00026   const Teuchos::RCP<Albany::StateInfoStruct>& sis)
00027   : GenericSTKFieldContainer<Interleaved>(params_, metaData_, bulkData_, neq_, numDim_),
00028       buildSurfaceHeight(false),
00029       buildTemperature(false),
00030       buildBasalFriction(false),
00031       buildThickness(false),
00032       buildFlowFactor(false),
00033       buildSurfaceVelocity(false),
00034       buildVelocityRMS(false) {
00035 
00036   typedef typename AbstractSTKFieldContainer::VectorFieldType VFT;
00037   typedef typename AbstractSTKFieldContainer::ScalarFieldType SFT;
00038 
00039 #ifdef ALBANY_FELIX
00040   buildSurfaceHeight = (std::find(req.begin(), req.end(), "Surface Height") != req.end());
00041 
00042   buildTemperature =  (std::find(req.begin(), req.end(), "Temperature") != req.end());
00043 
00044   buildBasalFriction = (std::find(req.begin(), req.end(), "Basal Friction") != req.end());
00045 
00046   buildThickness = (std::find(req.begin(), req.end(), "Thickness") != req.end());
00047   
00048   buildFlowFactor =  (std::find(req.begin(), req.end(), "Flow Factor") != req.end());
00049 
00050   buildSurfaceVelocity = (std::find(req.begin(), req.end(), "Surface Velocity") != req.end());
00051 
00052   buildVelocityRMS = (std::find(req.begin(), req.end(), "Velocity RMS") != req.end());
00053 #endif
00054 
00055   //Start STK stuff
00056   this->coordinates_field = & metaData_->declare_field< VFT >("coordinates");
00057   solution_field = & metaData_->declare_field< VFT >(
00058                      params_->get<std::string>("Exodus Solution Name", "solution"));
00059 
00060 #ifdef ALBANY_LCM
00061   residual_field = & metaData_->declare_field< VFT >(
00062                      params_->get<std::string>("Exodus Residual Name", "residual"));
00063 #endif
00064 
00065 #ifdef ALBANY_FELIX
00066 
00067   if(buildSurfaceHeight)
00068     this->surfaceHeight_field = & metaData_->declare_field< SFT >("surface_height");
00069   if(buildTemperature)
00070     this->temperature_field = & metaData_->declare_field< SFT >("temperature");
00071   if(buildBasalFriction)
00072     this->basalFriction_field = & metaData_->declare_field< SFT >("basal_friction");
00073   if(buildThickness)
00074     this->thickness_field = & metaData_->declare_field< SFT >("thickness");
00075   if(buildFlowFactor)
00076     this->flowFactor_field = & metaData_->declare_field< SFT >("flow_factor");
00077   if(buildSurfaceVelocity)
00078     this->surfaceVelocity_field = & metaData_->declare_field< VFT >("surface_velocity");
00079   if(buildVelocityRMS)
00080     this->velocityRMS_field = & metaData_->declare_field< VFT >("velocity_RMS");
00081 #endif
00082 
00083   stk::mesh::put_field(*this->coordinates_field , metaData_->node_rank() , metaData_->universal_part(), numDim_);
00084   stk::mesh::put_field(*solution_field , metaData_->node_rank() , metaData_->universal_part(), neq_);
00085 
00086 #ifdef ALBANY_LCM
00087   stk::mesh::put_field(*residual_field , metaData_->node_rank() , metaData_->universal_part() , neq_);
00088 #endif
00089 
00090 #ifdef ALBANY_FELIX
00091 
00092   if(buildSurfaceHeight)
00093     stk::mesh::put_field( *this->surfaceHeight_field , metaData_->node_rank() , metaData_->universal_part());
00094   if(buildTemperature)
00095     stk::mesh::put_field( *this->temperature_field , metaData_->element_rank() , metaData_->universal_part());
00096   if(buildBasalFriction)
00097     stk::mesh::put_field( *this->basalFriction_field , metaData_->node_rank() , metaData_->universal_part());//*metaData_->get_part("basalside","Mpas Interface"));
00098   if(buildThickness)
00099     stk::mesh::put_field( *this->thickness_field , metaData_->node_rank() , metaData_->universal_part());
00100   if(buildFlowFactor)
00101     stk::mesh::put_field( *this->flowFactor_field , metaData_->element_rank() , metaData_->universal_part());
00102   if(buildSurfaceVelocity)
00103     stk::mesh::put_field( *this->surfaceVelocity_field , metaData_->node_rank() , metaData_->universal_part(), neq_);
00104   if(buildVelocityRMS)
00105     stk::mesh::put_field( *this->velocityRMS_field , metaData_->node_rank() , metaData_->universal_part(), neq_);
00106 #endif
00107 
00108 #ifdef ALBANY_SEACAS
00109   stk::io::set_field_role(*this->coordinates_field, Ioss::Field::MESH);
00110   stk::io::set_field_role(*solution_field, Ioss::Field::TRANSIENT);
00111 #ifdef ALBANY_LCM
00112   stk::io::set_field_role(*residual_field, Ioss::Field::TRANSIENT);
00113 #endif
00114 
00115 #ifdef ALBANY_FELIX
00116 
00117   // ATTRIBUTE writes only once per file, but somehow did not work on restart.
00118   //stk::io::set_field_role(*surfaceHeight_field, Ioss::Field::ATTRIBUTE);
00119   if(buildSurfaceHeight)
00120      stk::io::set_field_role(*this->surfaceHeight_field, Ioss::Field::TRANSIENT);
00121   if(buildTemperature)
00122      stk::io::set_field_role(*this->temperature_field, Ioss::Field::TRANSIENT);
00123   if(buildBasalFriction)
00124      stk::io::set_field_role(*this->basalFriction_field, Ioss::Field::TRANSIENT);
00125   if(buildThickness)
00126      stk::io::set_field_role(*this->thickness_field, Ioss::Field::TRANSIENT);
00127   if(buildFlowFactor)
00128      stk::io::set_field_role(*this->flowFactor_field, Ioss::Field::TRANSIENT);
00129   if(buildSurfaceVelocity)
00130      stk::io::set_field_role(*this->surfaceVelocity_field, Ioss::Field::TRANSIENT);
00131   if(buildVelocityRMS)
00132      stk::io::set_field_role(*this->velocityRMS_field, Ioss::Field::TRANSIENT);
00133 #endif
00134 #endif
00135 
00136 
00137   // If the problem requests that the initial guess at the solution equals the input node coordinates,
00138   // set that here
00139   /*
00140     if(std::find(req.begin(), req.end(), "Initial Guess Coords") != req.end()){
00141        this->copySTKField(this->coordinates_field, solution_field);
00142     }
00143   */
00144 
00145 
00146 
00147   this->buildStateStructs(sis);
00148 
00149   initializeSTKAdaptation();
00150 
00151 }
00152 
00153 template<bool Interleaved>
00154 Albany::OrdinarySTKFieldContainer<Interleaved>::~OrdinarySTKFieldContainer() {
00155 }
00156 
00157 template<bool Interleaved>
00158 void Albany::OrdinarySTKFieldContainer<Interleaved>::initializeSTKAdaptation() {
00159 
00160   typedef typename AbstractSTKFieldContainer::IntScalarFieldType ISFT;
00161 
00162   this->proc_rank_field =
00163       & this->metaData->template declare_field< ISFT >("proc_rank");
00164 
00165   this->refine_field =
00166       & this->metaData->template declare_field< ISFT >("refine_field");
00167 
00168   // Processor rank field, a scalar
00169   stk::mesh::put_field(
00170       *this->proc_rank_field,
00171       this->metaData->element_rank(),
00172       this->metaData->universal_part());
00173 
00174   stk::mesh::put_field(
00175       *this->refine_field,
00176       this->metaData->element_rank(),
00177       this->metaData->universal_part());
00178 
00179 #ifdef ALBANY_LCM
00180   // Fracture state used for adaptive insertion.
00181   // It exists for all entities except cells (elements).
00182   this->fracture_state =
00183       & this->metaData->template declare_field< ISFT >("fracture_state");
00184 
00185   stk::mesh::EntityRank const
00186   cell_rank = this->metaData->element_rank();
00187 
00188   for (stk::mesh::EntityRank rank = 0; rank < cell_rank; ++rank) {
00189     stk::mesh::put_field(
00190         *this->fracture_state,
00191         rank,
00192         this->metaData->universal_part());
00193 
00194   }
00195 #endif // ALBANY_LCM
00196 
00197 #ifdef ALBANY_SEACAS
00198   stk::io::set_field_role(*this->proc_rank_field, Ioss::Field::MESH);
00199   stk::io::set_field_role(*this->refine_field, Ioss::Field::MESH);
00200 #ifdef ALBANY_LCM
00201   stk::io::set_field_role(*this->fracture_state, Ioss::Field::MESH);
00202 #endif // ALBANY_LCM
00203 #endif
00204 
00205 }
00206 
00207 template<bool Interleaved>
00208 void Albany::OrdinarySTKFieldContainer<Interleaved>::fillSolnVector(Epetra_Vector& soln,
00209     stk::mesh::Selector& sel, const Teuchos::RCP<Epetra_Map>& node_map) {
00210 
00211   typedef typename AbstractSTKFieldContainer::VectorFieldType VFT;
00212 
00213   // Iterate over the on-processor nodes by getting node buckets and iterating over each bucket.
00214   stk::mesh::BucketVector all_elements;
00215   stk::mesh::get_buckets(sel, this->bulkData->buckets(this->metaData->node_rank()), all_elements);
00216   this->numNodes = node_map->NumMyElements(); // Needed for the getDOF function to work correctly
00217   // This is either numOwnedNodes or numOverlapNodes, depending on
00218   // which map is passed in
00219 
00220   for(stk::mesh::BucketVector::const_iterator it = all_elements.begin() ; it != all_elements.end() ; ++it) {
00221 
00222     const stk::mesh::Bucket& bucket = **it;
00223 
00224     this->fillVectorHelper(soln, solution_field, node_map, bucket, 0);
00225 
00226   }
00227 
00228 }
00229 
00230 template<bool Interleaved>
00231 void Albany::OrdinarySTKFieldContainer<Interleaved>::saveSolnVector(const Epetra_Vector& soln,
00232     stk::mesh::Selector& sel, const Teuchos::RCP<Epetra_Map>& node_map) {
00233 
00234   typedef typename AbstractSTKFieldContainer::VectorFieldType VFT;
00235 
00236   // Iterate over the on-processor nodes by getting node buckets and iterating over each bucket.
00237   stk::mesh::BucketVector all_elements;
00238   stk::mesh::get_buckets(sel, this->bulkData->buckets(this->metaData->node_rank()), all_elements);
00239   this->numNodes = node_map->NumMyElements(); // Needed for the getDOF function to work correctly
00240   // This is either numOwnedNodes or numOverlapNodes, depending on
00241   // which map is passed in
00242 
00243   for(stk::mesh::BucketVector::const_iterator it = all_elements.begin() ; it != all_elements.end() ; ++it) {
00244 
00245     const stk::mesh::Bucket& bucket = **it;
00246 
00247     this->saveVectorHelper(soln, solution_field, node_map, bucket, 0);
00248 
00249   }
00250 
00251 }
00252 
00253 template<bool Interleaved>
00254 void Albany::OrdinarySTKFieldContainer<Interleaved>::saveResVector(const Epetra_Vector& res,
00255     stk::mesh::Selector& sel, const Teuchos::RCP<Epetra_Map>& node_map) {
00256 
00257   typedef typename AbstractSTKFieldContainer::VectorFieldType VFT;
00258 
00259   // Iterate over the on-processor nodes by getting node buckets and iterating over each bucket.
00260   stk::mesh::BucketVector all_elements;
00261   stk::mesh::get_buckets(sel, this->bulkData->buckets(this->metaData->node_rank()), all_elements);
00262   this->numNodes = node_map->NumMyElements(); // Needed for the getDOF function to work correctly
00263   // This is either numOwnedNodes or numOverlapNodes, depending on
00264   // which map is passed in
00265 
00266   for(stk::mesh::BucketVector::const_iterator it = all_elements.begin() ; it != all_elements.end() ; ++it) {
00267 
00268     const stk::mesh::Bucket& bucket = **it;
00269 
00270     this->saveVectorHelper(res, residual_field, node_map, bucket, 0);
00271 
00272   }
00273 
00274 }
00275 
00276 template<bool Interleaved>
00277 void Albany::OrdinarySTKFieldContainer<Interleaved>::transferSolutionToCoords() {
00278 
00279   this->copySTKField(solution_field, this->coordinates_field);
00280 
00281 }

Generated on Wed Mar 26 2014 18:36:36 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1