void NOX::Epetra::DebugTools::readMatrix( std::string baseName, Epetra_CrsMatrix* & p_crsMat ) { TEUCHOS_TEST_FOR_EXCEPT_MSG( p_crsMat != NULL, "Incoming Epetra_CrsMatrix pointer is not NULL. This could cause a memory leak." ); std::string mapFileName = baseName + "_map"; Epetra_Map * tmpMap = NULL; int ierr = EpetraExt::MatrixMarketFileToMap( mapFileName.c_str(), p_crsMat->Comm(), tmpMap ); TEUCHOS_TEST_FOR_EXCEPT_MSG( ierr != 0 || tmpMap == NULL, "Could not get Epetra_Map from file." // \"" + mapFileName + "\"." ); std::string matrixFileName = baseName + "_matrix"; ierr = EpetraExt::MatrixMarketFileToCrsMatrix( matrixFileName.c_str(), *tmpMap, p_crsMat ); TEUCHOS_TEST_FOR_EXCEPT_MSG( ierr != 0 || p_crsMat == NULL, "Could not get Epetra_CrsMatrix from file." // \"" + matrixFileName + "\"." ); delete tmpMap; return; }
void SetField<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { unsigned int numDimensions = evaluatedFieldDimensions.size(); TEUCHOS_TEST_FOR_EXCEPT_MSG(numDimensions < 1, "SetField::evaluateFields(), unsupported field type."); int dim1 = evaluatedFieldDimensions[0]; if(numDimensions == 1){ for (int i=0; i<dim1; ++i) { evaluatedField(i) = fieldValues[i]; } } else if(numDimensions == 2){ int dim2 = evaluatedFieldDimensions[1]; TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2, "SetField::evaluateFields(), inconsistent data sizes."); for(int i=0 ; i<dim1 ; ++i){ for(int j=0 ; j<dim2 ; ++j){ evaluatedField(i,j) = fieldValues[i*dim2 + j]; } } } else if(numDimensions == 3){ int dim2 = evaluatedFieldDimensions[1]; int dim3 = evaluatedFieldDimensions[2]; TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2*dim3, "SetField::evaluateFields(), inconsistent data sizes."); for(int i=0 ; i<dim1 ; ++i){ for(int j=0 ; j<dim2 ; ++j){ for(int m=0 ; m<dim3 ; ++m){ evaluatedField(i,j,m) = fieldValues[i*dim2*dim3 + j*dim3 + m]; } } } } else if(numDimensions == 4){ int dim2 = evaluatedFieldDimensions[1]; int dim3 = evaluatedFieldDimensions[2]; int dim4 = evaluatedFieldDimensions[3]; TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2*dim3*dim4, "SetField::evaluateFields(), inconsistent data sizes."); for(int i=0 ; i<dim1 ; ++i){ for(int j=0 ; j<dim2 ; ++j){ for(int m=0 ; m<dim3 ; ++m){ for(int n=0 ; n<dim4 ; ++n){ evaluatedField(i,j,m,n) = fieldValues[i*dim2*dim3*dim4 + j*dim3*dim4 + m*dim4 + n]; } } } } } else{ TEUCHOS_TEST_FOR_EXCEPT_MSG(numDimensions > 4, "SetField::evaluateFields(), unsupported data type."); } }
//! Returns material property value for a given key // Only implemented for multiphysics elastic material virtual double lookupMaterialProperty(const std::string keyname) const { std::string errorMsg = "**Error, Material::lookupMaterialProperty() called for "; errorMsg += Name(); errorMsg += " but this function is not implemented.\n"; TEUCHOS_TEST_FOR_EXCEPT_MSG(true, errorMsg); return 0.0; }
//! Set user-defined convergence status test. virtual void setUserConvStatusTest( const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &userConvStatusTest ) { TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setUserConvStatusTest() has not been" << " overridden for the class" << this->description() << " yet!"); }
virtual Thyra::ModelEvaluatorBase::InArgs<double> getUpperBounds() const { TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Not implemented."); return this->createInArgs(); }
virtual Teuchos::RCP<Thyra::PreconditionerBase<double>> create_W_prec() const { TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Not implemented."); return Teuchos::null; }
Teuchos::RCP<const Epetra_Operator> ReducedSpaceFactory::getSamplingOperator( const Teuchos::RCP<Teuchos::ParameterList> ¶ms, const Epetra_Map &stateMap) { Teuchos::RCP<const Epetra_Operator> result; { const Teuchos::RCP<Teuchos::ParameterList> hyperreductionParams = Teuchos::sublist(params, "Hyper Reduction"); const bool useHyperreduction = hyperreductionParams->get("Activate", false); if (useHyperreduction) { const Teuchos::Tuple<std::string, 1> allowedHyperreductionTypes = Teuchos::tuple<std::string>("Collocation"); const std::string hyperreductionType = hyperreductionParams->get("Type", allowedHyperreductionTypes[0]); TEUCHOS_TEST_FOR_EXCEPTION(!contains(allowedHyperreductionTypes, hyperreductionType), std::out_of_range, hyperreductionType + " not in " + allowedHyperreductionTypes.toString()); if (hyperreductionType == allowedHyperreductionTypes[0]) { const Teuchos::RCP<Teuchos::ParameterList> collocationParams = Teuchos::sublist(hyperreductionParams, "Collocation Data"); const Teuchos::Array<int> sampleLocalEntries = samplingFactory_->create(collocationParams); result = Teuchos::rcp(new EpetraSamplingOperator(stateMap, sampleLocalEntries)); } else { TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Should not happen"); } } } return result; }
Input (int argc, char** argv, const Teuchos::RCP<const Teuchos::Comm<int> >& icomm) { init(icomm); Teuchos::CommandLineProcessor clp(false); clp.setDocString("Unit and performance tester for BlockTriDiContainer. The performance test\n" "constructs a 3D 7-point stencil in a block domain of arbitrary size. The\n" "block is distributed by splitting it in each axis. The index space is\n" "denoted (I,J,K) in the documentation. The lines are in the K dimension."); clp.setOption("ni", &ni, "Number of cells in the I dimension."); clp.setOption("nj", &nj, "Number of cells in the J dimension."); clp.setOption("nk", &nk, "Number of cells in the K dimension."); clp.setOption("isplit", &isplit, "Cut the I dimension into this many pieces for MPI distribution. " "isplit*jsplit must equal the number of ranks."); clp.setOption("jsplit", &jsplit, "Cut the J dimension into this many pieces for MPI distribution. " "isplit*jsplit must equal the number of ranks."); clp.setOption("bs", &bs, "Block size. This might be the number of degrees of freedom in a system of PDEs, " "for example."); clp.setOption("nrhs", &nrhs, "Number of right hand sides to solve for."); clp.setOption("repeat", &repeat, "Number of times to run the performance test for timing. " "To run the performance test, set it to a number > 0."); clp.setOption("iterations", &iterations, "Max number of fixed-point iterations."); clp.setOption("tol", &tol, "Tolerance for norm-based termination. Set to <= 0 to turn off norm-based termination."); clp.setOption("check-tol-every", &check_tol_every, "Check norm every CE iterations."); clp.setOption("verbose", "quiet", &verbose, "Verbose output."); clp.setOption("test", "notest", &teuchos_test, "Run unit tests."); clp.setOption("jacobi", "tridiag", &jacobi, "Run with little-block Jacobi instead of block tridagional."); clp.setOption("contiguous", "noncontiguous", &contiguous, "Use contiguous GIDs."); clp.setOption("seq-method", "non-seq-method", &use_seq_method, "Developer option."); clp.setOption("overlap-comm", "non-overlap-comm", &use_overlap_comm, "Developer option."); auto out = clp.parse(argc, argv, icomm->getRank() == 0 ? &std::cerr : nullptr); TEUCHOS_TEST_FOR_EXCEPT_MSG(out > Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED, "Parse error."); check(); }
virtual Teuchos::RCP<const Thyra::VectorSpaceBase<double>> get_g_space(int l) const { (void) l; TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Not implemented."); return Teuchos::null; }
virtual Teuchos::ArrayView<const std::string> get_g_names(int j) const { (void) j; TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Not implemented."); return Teuchos::null; }
//! wipe clean a already initialized preconditioner object void PreconditionerFactory::uninitializePrec(PreconditionerBase<double> * prec, RCP<const LinearOpSourceBase<double> > * fwdOpSrc, ESupportSolveUse *supportSolveUse) const { // Preconditioner * blkPrec = dynamic_cast<Preconditioner *>(prec); // what do I do here? TEUCHOS_TEST_FOR_EXCEPT_MSG(true,"\"PreconditionerFactory::uninitializePrec not implemented\""); }
virtual Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const { TEUCHOS_TEST_FOR_EXCEPT_MSG( l != 0, "Mikado can only deal with one parameter vector." ); return p_names_; }
void check () { TEUCHOS_ASSERT( ! comm.is_null()); TEUCHOS_ASSERT(ni >= 1 && nj >= 1); TEUCHOS_ASSERT(isplit >= 1 && jsplit >= 1); TEUCHOS_ASSERT(bs >= 1); TEUCHOS_ASSERT(nrhs >= 1); TEUCHOS_ASSERT(repeat >= 0); TEUCHOS_ASSERT(iterations >= 1); TEUCHOS_ASSERT(check_tol_every >= 1); TEUCHOS_TEST_FOR_EXCEPT_MSG(nk <= 1, "k dimension is <= 1; must be >= 2."); TEUCHOS_TEST_FOR_EXCEPT_MSG( isplit*jsplit != comm->getSize(), "isplit*jsplit must be == to #ranks; isplit = " << isplit << " jsplit = " << jsplit << " but #ranks = " << comm->getSize() << "."); TEUCHOS_TEST_FOR_EXCEPT_MSG(std::max(isplit, jsplit) > comm->getSize(), "i,jsplit must be <= #ranks; isplit = " << isplit << " jsplit = " << jsplit); if (comm->getRank() == 0) print(std::cout); }
virtual Teuchos::RCP<const Thyra::VectorSpaceBase<double>> get_p_space(int l) const { TEUCHOS_TEST_FOR_EXCEPT_MSG( l != 0, "Mikado can only deal with one parameter vector." ); return Thyra::createVectorSpace<double>(p_map_); }
virtual void reportFinalPoint( const Thyra::ModelEvaluatorBase::InArgs<double> &finalPoint, const bool wasSolved ) { (void) finalPoint; (void) wasSolved; TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Not implemented."); }
void SaveStateField<PHAL::AlbanyTraits::Residual, Traits>:: evaluateFields(typename Traits::EvalData workset) { // Get shards Array (from STK) for this state // Need to check if we can just copy full size -- can assume same ordering? Albany::StateArray::const_iterator it; it = workset.stateArrayPtr->find(stateName); TEUCHOS_TEST_FOR_EXCEPTION((it == workset.stateArrayPtr->end()), std::logic_error, std::endl << "Error: cannot locate " << stateName << " in PHAL_SaveStateField_Def" << std::endl); Albany::MDArray sta = it->second; std::vector<PHX::DataLayout::size_type> dims; sta.dimensions(dims); int size = dims.size(); switch (size) { case 1: for (int cell = 0; cell < dims[0]; ++cell) sta(cell) = field(cell); break; case 2: for (int cell = 0; cell < dims[0]; ++cell) for (int qp = 0; qp < dims[1]; ++qp) sta(cell, qp) = field(cell,qp);; break; case 3: for (int cell = 0; cell < dims[0]; ++cell) for (int qp = 0; qp < dims[1]; ++qp) for (int i = 0; i < dims[2]; ++i) sta(cell, qp, i) = field(cell,qp,i); break; case 4: for (int cell = 0; cell < dims[0]; ++cell) for (int qp = 0; qp < dims[1]; ++qp) for (int i = 0; i < dims[2]; ++i) for (int j = 0; j < dims[3]; ++j) sta(cell, qp, i, j) = field(cell,qp,i,j); break; case 5: for (int cell = 0; cell < dims[0]; ++cell) for (int qp = 0; qp < dims[1]; ++qp) for (int i = 0; i < dims[2]; ++i) for (int j = 0; j < dims[3]; ++j) for (int k = 0; k < dims[4]; ++k) sta(cell, qp, i, j, k) = field(cell,qp,i,j,k); break; default: TEUCHOS_TEST_FOR_EXCEPT_MSG(size<1||size>5, "Unexpected Array dimensions in SaveStateField: " << size); } }
Teuchos::RCP<Albany::AbstractNodeFieldContainer> Albany::buildSTKNodeField(const std::string& name, const std::vector<int>& dim, stk::mesh::MetaData* metaData, const bool output){ switch(dim.size()){ case 1: // scalar return Teuchos::rcp(new STKNodeField<double, 1>(name, dim, metaData, output)); break; case 2: // vector return Teuchos::rcp(new STKNodeField<double, 2>(name, dim, metaData, output)); break; case 3: // tensor return Teuchos::rcp(new STKNodeField<double, 3>(name, dim, metaData, output)); break; default: TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error: unexpected argument for dimension"); } }
void SaveCellStateField<PHAL::AlbanyTraits::Residual, Traits>:: evaluateFields(typename Traits::EvalData workset) { // Get shards Array (from STK) for this state // Need to check if we can just copy full size -- can assume same ordering? Albany::StateArray::const_iterator it; it = workset.stateArrayPtr->find(stateName); TEUCHOS_TEST_FOR_EXCEPTION((it == workset.stateArrayPtr->end()), std::logic_error, std::endl << "Error: cannot locate " << stateName << " in PHAL_SaveCellStateField_Def" << std::endl); Albany::MDArray sta = it->second; std::vector<int> dims; field.dimensions(dims); int size = dims.size(); double el_weight; switch (size) { case 1: for (int cell = 0; cell < dims[0]; ++cell) sta(cell) = field(cell); break; case 2: for (int cell = 0; cell < dims[0]; ++cell) { sta(cell, 0) = 0.0; el_weight = 0.0; for (int qp = 0; qp < dims[1]; ++qp) { sta(cell, 0) += weights(cell,qp)*field(cell,qp); el_weight += weights(cell,qp); } sta(cell, 0) /= el_weight; } break; case 3: for (int cell = 0; cell < dims[0]; ++cell) { sta(cell, 0) = 0.0; el_weight = 0.0; for (int qp = 0; qp < dims[1]; ++qp) { sta(cell, 0) += weights(cell,qp)*field(cell,qp,i_index); el_weight += weights(cell,qp); } sta(cell, 0) /= el_weight; } break; case 4: for (int cell = 0; cell < dims[0]; ++cell) { sta(cell, 0) = 0.0; el_weight = 0.0; for (int qp = 0; qp < dims[1]; ++qp) { sta(cell, 0) += weights(cell,qp)*field(cell,qp,i_index,j_index); el_weight += weights(cell,qp); } sta(cell, 0) /= el_weight; } break; case 5: for (int cell = 0; cell < dims[0]; ++cell) { sta(cell, 0) = 0.0; el_weight = 0.0; for (int qp = 0; qp < dims[1]; ++qp) { sta(cell, 0) += weights(cell,qp)*field(cell,qp,i_index,j_index,k_index); el_weight += weights(cell,qp); } sta(cell, 0) /= el_weight; } break; default: TEUCHOS_TEST_FOR_EXCEPT_MSG(size<1||size>5, "Unexpected Array dimensions in SaveCellStateField: " << size); } }
Teuchos::RCP<PeridigmNS::Material> PeridigmNS::MaterialFactory::create(const Teuchos::ParameterList& materialParams) { std::string materialModelName = materialParams.get<std::string>("Material Model"); Teuchos::RCP<PeridigmNS::Material> materialModel; if (materialModelName == "Elastic") materialModel = Teuchos::rcp( new ElasticMaterial(materialParams) ); else if (materialModelName == "Multiphysics Elastic") materialModel = Teuchos::rcp( new MultiphysicsElasticMaterial(materialParams) ); else if (materialModelName == "Elastic Plastic") materialModel = Teuchos::rcp( new ElasticPlasticMaterial(materialParams) ); else if (materialModelName == "Elastic Plastic Hardening") materialModel = Teuchos::rcp( new ElasticPlasticHardeningMaterial(materialParams) ); else if (materialModelName == "Viscoelastic") materialModel = Teuchos::rcp( new ViscoelasticMaterial(materialParams) ); else if (materialModelName == "Elastic Plastic Correspondence") materialModel = Teuchos::rcp( new ElasticPlasticCorrespondenceMaterial(materialParams) ); else if (materialModelName == "Elastic Correspondence") materialModel = Teuchos::rcp( new ElasticCorrespondenceMaterial(materialParams) ); else if (materialModelName == "Viscoplastic Needleman Correspondence") materialModel = Teuchos::rcp( new ViscoplasticNeedlemanCorrespondenceMaterial(materialParams) ); else if (materialModelName == "Drucker-Prager Correspondence") materialModel = Teuchos::rcp( new DruckerPragerCorrespondenceMaterial(materialParams) ); else if (materialModelName == "Isotropic Hardening Correspondence") materialModel = Teuchos::rcp( new IsotropicHardeningPlasticCorrespondenceMaterial(materialParams) ); else if (materialModelName == "LCM") materialModel = Teuchos::rcp( new LCMMaterial(materialParams) ); else if (materialModelName == "Elastic Bond Based") materialModel = Teuchos::rcp( new ElasticBondBasedMaterial(materialParams) ); else if (materialModelName == "Vector Poisson") materialModel = Teuchos::rcp( new VectorPoissonMaterial(materialParams) ); else if (materialModelName == "Pals") materialModel = Teuchos::rcp( new Pals_Model(materialParams) ); else if (materialModelName == "Elastic Partial Volume"){ #ifdef PERIDIGM_PV materialModel = Teuchos::rcp( new ElasticPVMaterial(materialParams) ); #else TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "\n**** Elastic Partial Volume material model unavailable, recompile with -DUSE_PV.\n"); #endif } else if (materialModelName == "Linear LPS Partial Volume"){ #ifdef PERIDIGM_PV materialModel = Teuchos::rcp( new LinearLPSPVMaterial(materialParams) ); #else TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "\n**** Linear LPS Partial Volume material model unavailable, recompile with -DUSE_PV.\n"); #endif } else if (materialModelName == "Elastic Correspondence Partial Stress"){ #ifdef PERIDIGM_SANDIA_INTERNAL materialModel = Teuchos::rcp( new ElasticCorrespondencePartialStressMaterial(materialParams) ); #else TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "\n**** Elastic Correspondence Partial Stress material model unavailable, recompile with -DUSE_SANDIA_INTERNAL.\n"); #endif } else if (materialModelName == "Pressure Dependent Elastic Plastic"){ #ifdef PERIDIGM_CJL materialModel = Teuchos::rcp( new LammiConcreteModel(materialParams) ); #else TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "\n**** Pressure Dependent Elastic Plastic material model unavailable, recompile with -DUSE_CJL.\n"); #endif } else { std::string invalidMaterial("\n**** Unrecognized material model: "); invalidMaterial += materialModelName; invalidMaterial += ", must be \"Elastic\" or \"Elastic Plastic\" or \"Elastic Plastic Hardening\" or \"Viscoelastic\" or \"Elastic Correspondence\" or \"LCM\" or \"Vector Poisson\".\n"; TEUCHOS_TEST_FOR_EXCEPT_MSG(true, invalidMaterial); } return materialModel; }
void ParallelSetField<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { unsigned int numDimensions = evaluatedFieldDimensions.size(); TEUCHOS_TEST_FOR_EXCEPT_MSG(numDimensions < 1, "SetField::evaluateFields(), unsupported field type."); int dim1 = evaluatedFieldDimensions[0]; if(numDimensions == 1){ auto view = evaluatedField.get_kokkos_view1(); auto hostMirror = Kokkos::create_mirror_view(view); for (int i=0; i<dim1; ++i) { hostMirror(i) = fieldValues[i]; } Kokkos::deep_copy (view, hostMirror); } else if(numDimensions == 2){ auto view = evaluatedField.get_kokkos_view2(); auto hostMirror = Kokkos::create_mirror_view(view); int dim2 = evaluatedFieldDimensions[1]; TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2, "SetField::evaluateFields(), inconsistent data sizes."); for(int i=0 ; i<dim1 ; ++i){ for(int j=0 ; j<dim2 ; ++j){ hostMirror(i,j) = fieldValues[i*dim2 + j]; } } Kokkos::deep_copy (view, hostMirror); } else if(numDimensions == 3){ auto view = evaluatedField.get_kokkos_view3(); auto hostMirror = Kokkos::create_mirror_view(view); int dim2 = evaluatedFieldDimensions[1]; int dim3 = evaluatedFieldDimensions[2]; TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2*dim3, "SetField::evaluateFields(), inconsistent data sizes."); for(int i=0 ; i<dim1 ; ++i){ for(int j=0 ; j<dim2 ; ++j){ for(int m=0 ; m<dim3 ; ++m){ hostMirror(i,j,m) = fieldValues[i*dim2*dim3 + j*dim3 + m]; } } } Kokkos::deep_copy (view, hostMirror); } else if(numDimensions == 4){ auto view = evaluatedField.get_kokkos_view4(); auto hostMirror = Kokkos::create_mirror_view(view); int dim3 = evaluatedFieldDimensions[2]; int dim2 = evaluatedFieldDimensions[1]; int dim4 = evaluatedFieldDimensions[3]; TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2*dim3*dim4, "SetField::evaluateFields(), inconsistent data sizes."); for(int i=0 ; i<dim1 ; ++i){ for(int j=0 ; j<dim2 ; ++j){ for(int m=0 ; m<dim3 ; ++m){ for(int n=0 ; n<dim4 ; ++n){ hostMirror(i,j,m,n) = fieldValues[i*dim2*dim3*dim4 + j*dim3*dim4 + m*dim4 + n]; } } } } Kokkos::deep_copy (view, hostMirror); } else{ TEUCHOS_TEST_FOR_EXCEPT_MSG(numDimensions > 4, "SetField::evaluateFields(), unsupported data type."); } }
void Stresses<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // ScalarT C11,C33,C12,C23,C44,C66; //Irina TOFIX pointers TEUCHOS_TEST_FOR_EXCEPT_MSG(0== 0, "Stress:: evaluator has to be fixed for Kokkos data types"); /* switch (numDims) { case 1: // Compute Stress (uniaxial strain) for (std::size_t cell=0; cell < workset.numCells; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp) stress(cell,qp,0,0) = C11 * strain(cell,qp,0,0); break; case 2: // Compute Stress (plane strain) for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { ScalarT &e1 = strain(cell,qp,0,0), &e2 = strain(cell,qp,1,1), &e3 = strain(cell,qp,0,1); stress(cell,qp,0,0) = C11*e1 + C12*e2; stress(cell,qp,1,1) = C12*e1 + C11*e2; stress(cell,qp,0,1) = C44*e3; stress(cell,qp,1,0) = stress(cell,qp,0,1); } } // Compute Micro Stress for(int i=0; i<numMicroScales; i++){ HMC2Tensor &sd = *(strainDifference[i]); HMC2Tensor &ms = *(microStress[i]); ScalarT beta = betaParameter[i]; for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { ScalarT& e1 = sd(cell,qp,0,0), e2 = sd(cell,qp,1,1), e3 = sd(cell,qp,0,1), e4 = sd(cell,qp,1,0); ms(cell,qp,0,0) = beta*(C11*e1 + C12*e2); ms(cell,qp,1,1) = beta*(C12*e1 + C11*e2); ms(cell,qp,0,1) = beta*(C44*e3); ms(cell,qp,1,0) = beta*(C44*e4); } } } // Compute Double Stress for(int i=0; i<numMicroScales; i++){ HMC3Tensor &msg = *(microStrainGradient[i]); HMC3Tensor &ds = *(doubleStress[i]); ScalarT beta = lengthScale[i]*lengthScale[i]*betaParameter[i]; for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { for (std::size_t k=0; k < numDims; ++k) { ScalarT& e1 = msg(cell,qp,0,0,k), e2 = msg(cell,qp,1,1,k), e3 = msg(cell,qp,0,1,k), e4 = msg(cell,qp,1,0,k); ds(cell,qp,0,0,k) = beta*(C11*e1 + C12*e2); ds(cell,qp,1,1,k) = beta*(C12*e1 + C11*e2); ds(cell,qp,0,1,k) = beta*(C44*e3); ds(cell,qp,1,0,k) = beta*(C44*e4); } } } } break; case 3: // Compute Stress for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { ScalarT &e1 = strain(cell,qp,0,0), &e2 = strain(cell,qp,1,1), &e3 = strain(cell,qp,2,2); ScalarT &e4 = strain(cell,qp,1,2), &e5 = strain(cell,qp,0,2), &e6 = strain(cell,qp,0,1); stress(cell,qp,0,0) = C11*e1 + C12*e2 + C23*e3; stress(cell,qp,1,1) = C12*e1 + C11*e2 + C23*e3; stress(cell,qp,2,2) = C23*e1 + C23*e2 + C33*e3; stress(cell,qp,1,2) = C44*e4; stress(cell,qp,0,2) = C44*e5; stress(cell,qp,0,1) = C66*e6; stress(cell,qp,1,0) = stress(cell,qp,0,1); stress(cell,qp,2,0) = stress(cell,qp,0,2); stress(cell,qp,2,1) = stress(cell,qp,1,2); } } // Compute Micro Stress for(int i=0; i<numMicroScales; i++){ HMC2Tensor &sd = *(strainDifference[i]); HMC2Tensor &ms = *(microStress[i]); ScalarT beta = betaParameter[i]; for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { ScalarT& e1 = sd(cell,qp,0,0), e2 = sd(cell,qp,1,1), e3 = sd(cell,qp,2,2); ScalarT& e4 = sd(cell,qp,1,2), e5 = sd(cell,qp,0,2), e6 = sd(cell,qp,0,1); ScalarT& e7 = sd(cell,qp,2,1), e8 = sd(cell,qp,2,0), e9 = sd(cell,qp,1,0); ms(cell,qp,0,0) = beta*(C11*e1 + C12*e2 + C23*e3); ms(cell,qp,1,1) = beta*(C12*e1 + C11*e2 + C23*e3); ms(cell,qp,2,2) = beta*(C23*e1 + C23*e2 + C33*e3); ms(cell,qp,1,2) = beta*(C44*e4); ms(cell,qp,0,2) = beta*(C44*e5); ms(cell,qp,0,1) = beta*(C66*e6); ms(cell,qp,1,0) = beta*(C44*e9); ms(cell,qp,2,0) = beta*(C44*e8); ms(cell,qp,2,1) = beta*(C66*e7); } } } // Compute Double Stress for(int i=0; i<numMicroScales; i++){ HMC3Tensor &msg = *(microStrainGradient[i]); HMC3Tensor &ds = *(doubleStress[i]); ScalarT beta = lengthScale[i]*lengthScale[i]*betaParameter[i]; for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { for (std::size_t k=0; k < numDims; ++k) { ScalarT& e1 = msg(cell,qp,0,0,k), e2 = msg(cell,qp,1,1,k), e3 = msg(cell,qp,2,2,k); ScalarT& e4 = msg(cell,qp,1,2,k), e5 = msg(cell,qp,0,2,k), e6 = msg(cell,qp,0,1,k); ScalarT& e7 = msg(cell,qp,2,1,k), e8 = msg(cell,qp,2,0,k), e9 = msg(cell,qp,1,0,k); ds(cell,qp,0,0,k) = beta*(C11*e1 + C12*e2 + C23*e3); ds(cell,qp,1,1,k) = beta*(C12*e1 + C11*e2 + C23*e3); ds(cell,qp,2,2,k) = beta*(C23*e1 + C23*e2 + C33*e3); ds(cell,qp,1,2,k) = beta*(C44*e4); ds(cell,qp,0,2,k) = beta*(C44*e5); ds(cell,qp,0,1,k) = beta*(C66*e6); ds(cell,qp,1,0,k) = beta*(C44*e9); ds(cell,qp,2,0,k) = beta*(C44*e8); ds(cell,qp,2,1,k) = beta*(C66*e7); } } } } break; } */ }
void dft_PolyA22_Tpetra_Operator<Scalar,MatrixType>:: insertMatrixValue (GlobalOrdinal rowGID, GlobalOrdinal colGID, MatScalar value, GlobalOrdinal blockColFlag ) { // if poisson then blockColFlag = 0 // if density then blockColFlag = 1 // if cms then blockColFlag = 2 if (cmsMap_->isNodeGlobalElement(rowGID)) { // Insert into cmsOnCmsMatrix or cmsOnDensityMatrix switch (blockColFlag) { case 2: // Insert into cmsOnCmsMatrix if (firstTime_) { if (rowGID!=curRow_) { // Dump the current contents of curRowValues_ into matrix and clear map this->insertRow(); curRow_=rowGID; } curRowValuesCmsOnCms_[colGID] += value; } else cmsOnCmsMatrixStatic_->sumIntoGlobalValues(rowGID, Array<GlobalOrdinal>(1,colGID), Array<MatScalar>(1,value)); break; case 1: // Insert into cmsOnDensityMatrix ("F matrix") if (firstTime_) { if (rowGID!=curRow_) { // Dump the current contents of curRowValues_ into matrix and clear map this->insertRow(); curRow_=rowGID; } curRowValuesCmsOnDensity_[colGID] += value; } else if (!isFLinear_) { cmsOnDensityMatrix_->sumIntoGlobalValues(rowGID, Array<GlobalOrdinal>(1,colGID), Array<MatScalar>(1,value)); } break; default: char err_msg[200]; sprintf(err_msg,"PolyA22_Epetra_Operator::insertMatrixValue(): Invalid argument -- row in cmsMap, but blockColFlag not set for cms or density equations."); TEUCHOS_TEST_FOR_EXCEPT_MSG(1, err_msg); break; } } // end Insert into cmsOnCmsMatrix or cmsOnDensityMatrix else if (densityMap_->isNodeGlobalElement(rowGID)) { // Insert into densityOnDensityMatrix or densityOnCmsMatrix switch (blockColFlag) { case 1: // Insert into densityOnDensityMatrix TEUCHOS_TEST_FOR_EXCEPT(rowGID!=colGID); // Confirm that this is a diagonal value densityOnDensityMatrix_->sumIntoLocalValue(densityMap_->getLocalElement(rowGID), value); break; case 2: // Insert into densityOnCmsMatrix // The density-on-cms matrix is diagonal for most but not all use cases. if (firstTime_) { if (rowGID!=curRow_) { // Dump the current contents of curRowValues maps into matrix and clear map insertRow(); curRow_=rowGID; } curRowValuesDensityOnCms_[colGID] += value; } else densityOnCmsMatrix_->sumIntoGlobalValues(rowGID, Array<GlobalOrdinal>(1,colGID), Array<MatScalar>(1,value)); break; default: char err_msg[200]; sprintf(err_msg,"PolyA22_Epetra_Operator::insertMatrixValue(): Invalid argument -- row in densityMap, but blockColFlag not set for cms or density equations."); TEUCHOS_TEST_FOR_EXCEPT_MSG(1, err_msg); break; } } // end Insert into densityOnDensityMatrix or densityOnCmsMatrix else { // Problem! rowGID not in cmsMap or densityMap char err_msg[200]; sprintf(err_msg,"PolyA22_Epetra_Operator::insertMatrixValue(): rowGID=%i not in cmsMap or densityMap.",rowGID); TEUCHOS_TEST_FOR_EXCEPT_MSG(1, err_msg); } } //end insertMatrixValue
PeridigmNS::ZoltanSearchTree::ZoltanSearchTree(int numPoints, double* coordinates) : SearchTree(numPoints, coordinates), callbackdata(numPoints,coordinates),zoltan(0), partToCoordIdx(new int[numPoints]), searchParts(new int[numPoints]) { zoltan = Zoltan_Create(MPI_COMM_SELF); Zoltan_Set_Param(zoltan, "debug_level", "0"); Zoltan_Set_Param(zoltan, "rcb_output_level", "0"); /* * query function returns the number of objects that are currently assigned to the processor */ Zoltan_Set_Num_Obj_Fn(zoltan, &get_num_points, &callbackdata); /* * query function fills two (three if weights are used) arrays with information about the objects * currently assigned to the processor. Both arrays are allocated (and subsequently freed) by Zoltan; * their size is determined by a call to a ZOLTAN_NUM_OBJ_FN query function to get the array size. */ Zoltan_Set_Obj_List_Fn(zoltan, &get_point_ids, &callbackdata); /* * query function returns the number of values needed to express the geometry of an object. * For example, for a two-dimensional mesh-based application, (x,y) coordinates are needed * to describe an object's geometry; thus the ZOLTAN_NUM_GEOM_FN query function should return * the value of two. For a similar three-dimensional application, the return value should be three. */ Zoltan_Set_Num_Geom_Fn(zoltan, &get_dimension, NULL); /* * query function returns a vector of geometry values for a list of given objects. The geometry * vector is allocated by Zoltan to be of size num_obj * num_dim. */ Zoltan_Set_Geom_Multi_Fn(zoltan, &get_point_coordinates, &callbackdata); /* * setting method */ Zoltan_Set_Param(zoltan,"lb_method","rcb"); /* * keep cuts */ Zoltan_Set_Param(zoltan,"keep_cuts","1"); Zoltan_Set_Param(zoltan,"return_lists","part"); Zoltan_Set_Param(zoltan, "num_lid_entries", "0"); char s[11]; sprintf(s,"%d",numPoints); Zoltan_Set_Param(zoltan, "num_global_parts", s); int numimp = -1, numexp = -1; int numgid = 1, numlid = 0; ZOLTAN_ID_PTR impgid=NULL, implid=NULL; ZOLTAN_ID_PTR gid=NULL, lid=NULL; int *imppart = NULL, *impproc = NULL; int *procs = NULL, *parts=NULL; int changes; int ierr = Zoltan_LB_Partition(zoltan, &changes, &numgid, &numlid, &numimp, &impgid, &implid, &imppart, &impproc, &numexp, &gid, &lid, &procs, &parts); TEUCHOS_TEST_FOR_EXCEPT_MSG(ierr != 0, "Error in ZoltanSearchTree::ZoltanSearchTree(), call to Zoltan_LB_Partition() returned a nonzero error code."); for (int I = 0; I < numPoints; I++) partToCoordIdx[parts[I]] = I; Zoltan_LB_Free_Part(&impgid, &implid, &impproc, &imppart); Zoltan_LB_Free_Part(&gid, &lid, &procs, &parts); }
int main(int argc, char *argv[]) { // Create output stream. (Handy for multicore output.) auto out = Teuchos::VerboseObjectBase::getDefaultOStream(); Teuchos::GlobalMPISession session(&argc, &argv, NULL); auto comm = Teuchos::DefaultComm<int>::getComm(); // Wrap the whole code in a big try-catch-statement. bool success = true; try { // ========================================================================= // Handle command line arguments. // Boost::program_options is somewhat more complete here (e.g. you can // specify options without the "--" syntax), but it isn't less complicated // to use. Stick with Teuchos for now. Teuchos::CommandLineProcessor myClp; myClp.setDocString( "Numerical parameter continuation for nonlinear Schr\"odinger equations.\n" ); std::string xmlInputPath = ""; myClp.setOption("xml-input-file", &xmlInputPath, "XML file containing the parameter list", true ); // Print warning for unrecognized arguments and make sure to throw an // exception if something went wrong. //myClp.throwExceptions(false); //myClp.recogniseAllOptions ( true ); // Finally, parse the command line. myClp.parse(argc, argv); // Retrieve Piro parameter list from given file. std::shared_ptr<Teuchos::ParameterList> piroParams( new Teuchos::ParameterList() ); Teuchos::updateParametersFromXmlFile( xmlInputPath, Teuchos::rcp(piroParams).ptr() ); // ======================================================================= // Extract the location of input and output files. const Teuchos::ParameterList outputList = piroParams->sublist("Output", true); // Set default directory to be the directory of the XML file itself const std::string xmlDirectory = xmlInputPath.substr(0, xmlInputPath.find_last_of( "/" ) + 1); // By default, take the current directory. std::string prefix = "./"; if (!xmlDirectory.empty()) prefix = xmlDirectory + "/"; const std::string outputDirectory = prefix; const std::string contFilePath = prefix + outputList.get<std::string>("Continuation data file name"); Teuchos::ParameterList & inputDataList = piroParams->sublist("Input", true); const std::string inputExodusFile = prefix + inputDataList.get<std::string>("File"); const int step = inputDataList.get<int>("Initial Psi Step"); //const bool useBordering = piroParams->get<bool>("Bordering"); // ======================================================================= // Read the data from the file. auto mesh = std::make_shared<Nosh::StkMesh>( Teuchos::get_shared_ptr(comm), inputExodusFile, step ); // Cast the data into something more accessible. auto psi = mesh->getComplexVector("psi"); //psi->Random(); // Set the output directory for later plotting with this. std::stringstream outputFile; outputFile << outputDirectory << "/solution.e"; mesh->openOutputChannel(outputFile.str()); // Create a parameter map from the initial parameter values. Teuchos::ParameterList initialParameterValues = piroParams->sublist("Initial parameter values", true); // Check if we need to interpret the time value stored in the file // as a parameter. const std::string & timeName = piroParams->get<std::string>("Interpret time as", ""); if (!timeName.empty()) { initialParameterValues.set(timeName, mesh->getTime()); } // Explicitly set the initial parameter value for this list. const std::string & paramName = piroParams->sublist( "LOCA" ) .sublist( "Stepper" ) .get<std::string>("Continuation Parameter"); *out << "Setting the initial parameter value of \"" << paramName << "\" to " << initialParameterValues.get<double>(paramName) << "." << std::endl; piroParams->sublist( "LOCA" ) .sublist( "Stepper" ) .set("Initial Value", initialParameterValues.get<double>(paramName)); // Set the thickness field. auto thickness = std::make_shared<Nosh::ScalarField::Constant>(*mesh, 1.0); // Some alternatives for the positive-definite operator. // (a) -\Delta (Laplace operator with Neumann boundary) //const std::shared_ptr<Nosh::ParameterMatrix::Virtual> matrixBuilder = // rcp(new Nosh::ParameterMatrix::Laplace(mesh, thickness)); // (b) (-i\nabla-A)^2 (Kinetic energy of a particle in magnetic field) // (b1) 'A' explicitly given in file. const double mu = initialParameterValues.get<double>("mu"); auto mvp = std::make_shared<Nosh::VectorField::ExplicitValues>(*mesh, "A", mu); //const std::shared_ptr<Nosh::ParameterMatrix::Virtual> keoBuilder( // new Nosh::ParameterMatrix::Keo(mesh, thickness, mvp) // ); //const std::shared_ptr<Nosh::ParameterMatrix::Virtual> DKeoDPBuilder( // new Nosh::ParameterMatrix::DKeoDP(mesh, thickness, mvp, "mu") // ); // (b2) 'A' analytically given (here with constant curl). // Optionally add a rotation axis u. This is important // if continuation happens as a rotation of the vector // field around an axis. //const std::shared_ptr<DoubleVector> b = rcp(new DoubleVector(3)); //std::shared_ptr<Teuchos::SerialDenseVector<int,double> > u = Teuchos::null; //if ( piroParams->isSublist("Rotation vector") ) //{ // u = rcp(new Teuchos::SerialDenseVector<int,double>(3)); // Teuchos::ParameterList & rotationVectorList = // piroParams->sublist( "Rotation vector", false ); // (*u)[0] = rotationVectorList.get<double>("x"); // (*u)[1] = rotationVectorList.get<double>("y"); // (*u)[2] = rotationVectorList.get<double>("z"); //} //std::shared_ptr<Nosh::VectorField::Virtual> mvp = // rcp(new Nosh::VectorField::ConstantCurl(mesh, b, u)); //const std::shared_ptr<Nosh::ParameterMatrix::Virtual> matrixBuilder = // rcp(new Nosh::ParameterMatrix::Keo(mesh, thickness, mvp)); // (b3) 'A' analytically given in a class you write yourself, derived // from Nosh::ParameterMatrix::Virtual. // [...] // // Setup the scalar potential V. // (a) A constant potential. //std::shared_ptr<Nosh::ScalarField::Virtual> sp = //rcp(new Nosh::ScalarField::Constant(*mesh, -1.0)); //const double T = initialParameterValues.get<double>("T"); // (b) With explicit values. //std::shared_ptr<Nosh::ScalarField::Virtual> sp = //rcp(new Nosh::ScalarField::ExplicitValues(*mesh, "V")); // (c) One you built yourself by deriving from Nosh::ScalarField::Virtual. auto sp = std::make_shared<MyScalarField>(mesh); const double g = initialParameterValues.get<double>("g"); // Finally, create the model evaluator. // This is the most important object in the whole stack. auto modelEvaluator = std::make_shared<Nosh::ModelEvaluator::Nls>( mesh, mvp, sp, g, thickness, psi, "mu" ); // Build the Piro model evaluator. It's used to hook up with // several different backends (NOX, LOCA, Rhythmos,...). std::shared_ptr<Thyra::ModelEvaluator<double>> piro; // Declare the eigensaver; it will be used only for LOCA solvers, though. std::shared_ptr<Nosh::SaveEigenData> glEigenSaver; // Switch by solver type. std::string & solver = piroParams->get<std::string>("Piro Solver"); if (solver == "NOX") { auto observer = std::make_shared<Nosh::Observer>(modelEvaluator); piro = std::make_shared<Piro::NOXSolver<double>>( Teuchos::rcp(piroParams), Teuchos::rcp(modelEvaluator), Teuchos::rcp(observer) ); } else if (solver == "LOCA") { auto observer = std::make_shared<Nosh::Observer>( modelEvaluator, contFilePath, piroParams->sublist("LOCA") .sublist("Stepper") .get<std::string>("Continuation Parameter") ); // Setup eigen saver. #ifdef HAVE_LOCA_ANASAZI bool computeEigenvalues = piroParams->sublist( "LOCA" ) .sublist( "Stepper" ) .get<bool>("Compute Eigenvalues"); if (computeEigenvalues) { Teuchos::ParameterList & eigenList = piroParams->sublist("LOCA") .sublist("Stepper") .sublist("Eigensolver"); std::string eigenvaluesFilePath = xmlDirectory + "/" + outputList.get<std::string> ( "Eigenvalues file name" ); glEigenSaver = std::make_shared<Nosh::SaveEigenData>( eigenList, modelEvaluator, eigenvaluesFilePath ); std::shared_ptr<LOCA::SaveEigenData::AbstractStrategy> glSaveEigenDataStrategy = glEigenSaver; eigenList.set("Save Eigen Data Method", "User-Defined"); eigenList.set("User-Defined Save Eigen Data Name", "glSaveEigenDataStrategy"); eigenList.set("glSaveEigenDataStrategy", glSaveEigenDataStrategy); } #endif // Get the solver. std::shared_ptr<Piro::LOCASolver<double>> piroLOCASolver( new Piro::LOCASolver<double>( Teuchos::rcp(piroParams), Teuchos::rcp(modelEvaluator), Teuchos::null //Teuchos::rcp(observer) ) ); // // Get stepper and inject it into the eigensaver. // std::shared_ptr<LOCA::Stepper> stepper = Teuchos::get_shared_ptr( // piroLOCASolver->getLOCAStepperNonConst() // ); //#ifdef HAVE_LOCA_ANASAZI // if (computeEigenvalues) // glEigenSaver->setLocaStepper(stepper); //#endif piro = piroLOCASolver; } #if 0 else if ( solver == "Turning Point" ) { std::shared_ptr<Nosh::Observer> observer; Teuchos::ParameterList & bifList = piroParams->sublist("LOCA").sublist("Bifurcation"); // Fetch the (approximate) null state. auto nullstateZ = mesh->getVector("null"); // Set the length normalization vector to be the initial null vector. TEUCHOS_ASSERT(nullstateZ); auto lengthNormVec = Teuchos::rcp(new NOX::Thyra::Vector(*nullstateZ)); //lengthNormVec->init(1.0); bifList.set("Length Normalization Vector", lengthNormVec); // Set the initial null vector. auto initialNullAbstractVec = Teuchos::rcp(new NOX::Thyra::Vector(*nullstateZ)); // initialNullAbstractVec->init(1.0); bifList.set("Initial Null Vector", initialNullAbstractVec); piro = std::make_shared<Piro::LOCASolver<double>>( Teuchos::rcp(piroParams), Teuchos::rcp(modelEvaluator), Teuchos::null //Teuchos::rcp(observer) ); } #endif else { TEUCHOS_TEST_FOR_EXCEPT_MSG( true, "Unknown solver type \"" << solver << "\"." ); } // ---------------------------------------------------------------------- // Now the setting of inputs and outputs. Thyra::ModelEvaluatorBase::InArgs<double> inArgs = piro->createInArgs(); inArgs.set_p( 0, piro->getNominalValues().get_p(0) ); // Set output arguments to evalModel call. Thyra::ModelEvaluatorBase::OutArgs<double> outArgs = piro->createOutArgs(); // Now solve the problem and return the responses. const Teuchos::RCP<Teuchos::Time> piroSolveTime = Teuchos::TimeMonitor::getNewTimer("Piro total solve time");; { Teuchos::TimeMonitor tm(*piroSolveTime); piro->evalModel(inArgs, outArgs); } // Manually release LOCA stepper. #ifdef HAVE_LOCA_ANASAZI if (glEigenSaver) glEigenSaver->releaseLocaStepper(); #endif // Print timing data. Teuchos::TimeMonitor::summarize(); } catch (Teuchos::CommandLineProcessor::HelpPrinted) { } catch (Teuchos::CommandLineProcessor::ParseError) { } TEUCHOS_STANDARD_CATCH_STATEMENTS(true, *out, success); return success ? EXIT_SUCCESS : EXIT_FAILURE; }
PeridigmForceBase<EvalT, Traits>::PeridigmForceBase( Teuchos::ParameterList& p, const Teuchos::RCP<Albany::Layouts>& dataLayout) : supportsTransient(false), referenceCoordinates( p.get<std::string>("Reference Coordinates Name"), dataLayout->vertices_vector), currentCoordinates( p.get<std::string>("Current Coordinates Name"), dataLayout->node_vector), velocity(p.get<std::string>("Velocity Name"), dataLayout->node_vector), acceleration( p.get<std::string>("Acceleration Name"), dataLayout->node_vector), force(p.get<std::string>("Force Name"), dataLayout->node_vector), residual(p.get<std::string>("Residual Name"), dataLayout->node_vector), density(0.0), sphereVolume( p.get<std::string>("Sphere Volume Name"), dataLayout->node_scalar) { peridigmParams = p.sublist("Peridigm Parameters", true); supportsTransient = p.get<bool>("Supports Transient", false); // Hard code numQPs and numDims for sphere elements. numQPs = 1; numDims = 3; if (supportsTransient) { density = p.get<RealType>("Density"); this->addDependentField(sphereVolume); this->addDependentField(velocity); this->addDependentField(acceleration); } this->addDependentField(referenceCoordinates); this->addDependentField(currentCoordinates); this->addEvaluatedField(force); this->addEvaluatedField(residual); outputFieldInfo = LCM::PeridigmManager::self()->getOutputFields(); for (unsigned int i = 0; i < outputFieldInfo.size(); ++i) { std::string albanyName = outputFieldInfo[i].albanyName; std::string relation = outputFieldInfo[i].relation; int length = outputFieldInfo[i].length; Teuchos::RCP<PHX::DataLayout> layout; if (relation == "node" && length == 1) layout = dataLayout->node_scalar; else if (relation == "node" && length == 3) layout = dataLayout->node_vector; else if (relation == "node" && length == 9) layout = dataLayout->node_tensor; else if (relation == "element" && length == 1) layout = dataLayout->qp_scalar; else if (relation == "element" && length == 3) layout = dataLayout->qp_vector; else if (relation == "element" && length == 9) layout = dataLayout->qp_tensor; else TEUCHOS_TEST_FOR_EXCEPT_MSG( true, "\n\n**** PeridigmForceBase::PeridigmForceBase() invalid output " "variable type."); this->outputFields[albanyName] = PHX::MDField<ScalarT>(albanyName, layout); this->addEvaluatedField(this->outputFields[albanyName]); } this->setName("Peridigm" + PHX::typeAsString<EvalT>()); }
void dft_PolyLinProbMgr<Scalar,MatrixType>:: insertMatrixValue (LocalOrdinal ownedPhysicsID, LocalOrdinal ownedNode, LocalOrdinal boxPhysicsID, LocalOrdinal boxNode, MatScalar value) { LocalOrdinal schurBlockRow = physicsIdToSchurBlockId_[ownedPhysicsID]; LocalOrdinal schurBlockCol = physicsIdToSchurBlockId_[boxPhysicsID]; GlobalOrdinal rowGID = BLPM::ownedToSolverGID(ownedPhysicsID, ownedNode); // Get solver Row GID GlobalOrdinal colGID = BLPM::boxToSolverGID(boxPhysicsID, boxNode); LocalOrdinal schurBlockNumber = 10 * schurBlockRow + schurBlockCol; switch (schurBlockNumber) { case 11: // A11 block A11_->insertMatrixValue(solverOrdering_[ownedPhysicsID], ownedMap_->getGlobalElement(ownedNode), rowGID, colGID, value); break; case 22: // A22 block // if poisson then blockColFlag = 0 // if density then blockColFlag = 1 // if cms then blockColFlag = 2 if (isCmsEquation_[boxPhysicsID]) { A22_->insertMatrixValue(rowGID, colGID, value, 2); }else if (isDensityEquation_[boxPhysicsID]) { A22_->insertMatrixValue(rowGID, colGID, value, 1); }else if (isPoissonEquation_[boxPhysicsID]) { A22_->insertMatrixValue(rowGID, colGID, value, 0); }else{ TEUCHOS_TEST_FOR_EXCEPT_MSG(1, "Unknown box physics ID in A22."); } break; case 21: // A12 block if (firstTime_) { if (rowGID!=curRowA21_) { // Insert the current row values into the matrix and move on to the next row this->insertRowA21(); curRowA21_=rowGID; } curRowValuesA21_[colGID] += value; } else A21Static_->sumIntoGlobalValues(rowGID, Array<GlobalOrdinal>(1,colGID), Array<MatScalar>(1,value)); break; case 12: // A12 block if (firstTime_) { if (rowGID!=curRowA12_) { // Insert the current row values into the matrix and move on to the next row this->insertRowA12(); curRowA12_=rowGID; } curRowValuesA12_[colGID] += value; } else A12Static_->sumIntoGlobalValues(rowGID, Array<GlobalOrdinal>(1,colGID), Array<MatScalar>(1,value)); break; } if (debug_) { BLPM::insertMatrixValue(ownedPhysicsID, ownedNode, boxPhysicsID, boxNode, value); } } //insertMatrixValue
void PeridigmNS::ShortRangeForceContactModel::computeForce(const double dt, const int numOwnedPoints, const int* ownedIDs, const int* contactNeighborhoodList, PeridigmNS::DataManager& dataManager) const { // Zero out the forces dataManager.getData(m_contactForceDensityFieldId, PeridigmField::STEP_NP1)->PutScalar(0.0); double *cellVolume, *y, *contactForce, *velocity; dataManager.getData(m_volumeFieldId, PeridigmField::STEP_NONE)->ExtractView(&cellVolume); dataManager.getData(m_coordinatesFieldId, PeridigmField::STEP_NP1)->ExtractView(&y); dataManager.getData(m_velocityFieldId, PeridigmField::STEP_NP1)->ExtractView(&velocity); dataManager.getData(m_contactForceDensityFieldId, PeridigmField::STEP_NP1)->ExtractView(&contactForce); int neighborhoodListIndex(0), numNeighbors, nodeID, neighborID, iID, iNID; double nodeCurrentX[3], nodeCurrentV[3], nodeVolume, currentDistance, c, temp, neighborVolume; double normal[3], currentDotNormal, currentDotNeighbor, nodeCurrentVperp[3], nodeNeighborVperp[3], Vcm[3], nodeCurrentVrel[3], nodeNeighborVrel[3]; double normCurrentVrel, normNeighborVrel, currentNormalForce[3], neighborNormalForce[3], normCurrentNormalForce, normNeighborNormalForce, currentFrictionForce[3], neighborFrictionForce[3]; double currentDistanceSquared; double contactRadiusSquared = m_contactRadius*m_contactRadius; const double pi = boost::math::constants::pi<double>(); for(iID=0 ; iID<numOwnedPoints ; ++iID){ numNeighbors = contactNeighborhoodList[neighborhoodListIndex++]; if(numNeighbors > 0){ nodeID = ownedIDs[iID]; nodeCurrentX[0] = y[nodeID*3]; nodeCurrentX[1] = y[nodeID*3+1]; nodeCurrentX[2] = y[nodeID*3+2]; nodeCurrentV[0] = velocity[nodeID*3]; nodeCurrentV[1] = velocity[nodeID*3+1]; nodeCurrentV[2] = velocity[nodeID*3+2]; nodeVolume = cellVolume[nodeID]; for(iNID=0 ; iNID<numNeighbors ; ++iNID){ neighborID = contactNeighborhoodList[neighborhoodListIndex++]; TEUCHOS_TEST_FOR_EXCEPT_MSG(neighborID < 0, "Invalid neighbor list\n"); currentDistanceSquared = distanceSquared(nodeCurrentX[0], nodeCurrentX[1], nodeCurrentX[2], y[neighborID*3], y[neighborID*3+1], y[neighborID*3+2]); if(currentDistanceSquared < contactRadiusSquared){ currentDistance = distance(nodeCurrentX[0], nodeCurrentX[1], nodeCurrentX[2], y[neighborID*3], y[neighborID*3+1], y[neighborID*3+2]); c = 9.0*m_springConstant/(pi*m_horizon*m_horizon*m_horizon*m_horizon); // half value (of 18) due to force being applied to both nodes temp = c*(m_contactRadius - currentDistance)/m_horizon; neighborVolume = cellVolume[neighborID]; if (m_frictionCoefficient != 0.0){ // calculate the perpendicular velocity of the current node wrt the vector between the nodes normal[0] = (y[neighborID*3] - nodeCurrentX[0])/currentDistance; normal[1] = (y[neighborID*3+1] - nodeCurrentX[1])/currentDistance; normal[2] = (y[neighborID*3+2] - nodeCurrentX[2])/currentDistance; currentDotNormal = nodeCurrentV[0]*normal[0] + nodeCurrentV[1]*normal[1] + nodeCurrentV[2]*normal[2]; currentDotNeighbor = velocity[neighborID*3]*normal[0] + velocity[neighborID*3+1]*normal[1] + velocity[neighborID*3+2]*normal[2]; nodeCurrentVperp[0] = nodeCurrentV[0] - currentDotNormal*normal[0]; nodeCurrentVperp[1] = nodeCurrentV[1] - currentDotNormal*normal[1]; nodeCurrentVperp[2] = nodeCurrentV[2] - currentDotNormal*normal[2]; nodeNeighborVperp[0] = velocity[neighborID*3] - currentDotNeighbor*normal[0]; nodeNeighborVperp[1] = velocity[neighborID*3+1] - currentDotNeighbor*normal[1]; nodeNeighborVperp[2] = velocity[neighborID*3+2] - currentDotNeighbor*normal[2]; // calculate frame of reference for the perpendicular velocities Vcm[0] = 0.5*(nodeCurrentVperp[0] + nodeNeighborVperp[0]); Vcm[1] = 0.5*(nodeCurrentVperp[1] + nodeNeighborVperp[1]); Vcm[2] = 0.5*(nodeCurrentVperp[2] + nodeNeighborVperp[2]); // calculate the relative velocity of the current node wrt the neighboring node and vice versa nodeCurrentVrel[0] = nodeCurrentVperp[0] - Vcm[0]; nodeCurrentVrel[1] = nodeCurrentVperp[1] - Vcm[1]; nodeCurrentVrel[2] = nodeCurrentVperp[2] - Vcm[2]; nodeNeighborVrel[0] = nodeNeighborVperp[0] - Vcm[0]; nodeNeighborVrel[1] = nodeNeighborVperp[1] - Vcm[1]; nodeNeighborVrel[2] = nodeNeighborVperp[2] - Vcm[2]; normCurrentVrel = sqrt(nodeCurrentVrel[0]*nodeCurrentVrel[0] + nodeCurrentVrel[1]*nodeCurrentVrel[1] + nodeCurrentVrel[2]*nodeCurrentVrel[2]); normNeighborVrel = sqrt(nodeNeighborVrel[0]*nodeNeighborVrel[0] + nodeNeighborVrel[1]*nodeNeighborVrel[1] + nodeNeighborVrel[2]*nodeNeighborVrel[2]); // calculate the normal forces currentNormalForce[0] = -(temp*neighborVolume*(y[neighborID*3] - nodeCurrentX[0])/currentDistance); currentNormalForce[1] = -(temp*neighborVolume*(y[neighborID*3+1] - nodeCurrentX[1])/currentDistance); currentNormalForce[2] = -(temp*neighborVolume*(y[neighborID*3+2] - nodeCurrentX[2])/currentDistance); neighborNormalForce[0] = (temp*nodeVolume*(y[neighborID*3] - nodeCurrentX[0])/currentDistance); neighborNormalForce[1] = (temp*nodeVolume*(y[neighborID*3+1] - nodeCurrentX[1])/currentDistance); neighborNormalForce[2] = (temp*nodeVolume*(y[neighborID*3+2] - nodeCurrentX[2])/currentDistance); normCurrentNormalForce = sqrt(currentNormalForce[0]*currentNormalForce[0] + currentNormalForce[1]*currentNormalForce[1] + currentNormalForce[2]*currentNormalForce[2]); normNeighborNormalForce = sqrt(neighborNormalForce[0]*neighborNormalForce[0] + neighborNormalForce[1]*neighborNormalForce[1] + neighborNormalForce[2]*neighborNormalForce[2]); // calculate the friction forces if (normCurrentVrel != 0.0) { currentFrictionForce[0] = -m_frictionCoefficient*normCurrentNormalForce*nodeCurrentVrel[0]/normCurrentVrel; currentFrictionForce[1] = -m_frictionCoefficient*normCurrentNormalForce*nodeCurrentVrel[1]/normCurrentVrel; currentFrictionForce[2] = -m_frictionCoefficient*normCurrentNormalForce*nodeCurrentVrel[2]/normCurrentVrel; } else { currentFrictionForce[0] = 0.0; currentFrictionForce[1] = 0.0; currentFrictionForce[2] = 0.0; } if (normNeighborVrel != 0.0) { neighborFrictionForce[0] = -m_frictionCoefficient*normNeighborNormalForce*nodeNeighborVrel[0]/normNeighborVrel; neighborFrictionForce[1] = -m_frictionCoefficient*normNeighborNormalForce*nodeNeighborVrel[1]/normNeighborVrel; neighborFrictionForce[2] = -m_frictionCoefficient*normNeighborNormalForce*nodeNeighborVrel[2]/normNeighborVrel; } else { neighborFrictionForce[0] = 0.0; neighborFrictionForce[1] = 0.0; neighborFrictionForce[2] = 0.0; } // compute total contributions to force density contactForce[nodeID*3] += currentNormalForce[0] + currentFrictionForce[0]; contactForce[nodeID*3+1] += currentNormalForce[1] + currentFrictionForce[1]; contactForce[nodeID*3+2] += currentNormalForce[2] + currentFrictionForce[2]; contactForce[neighborID*3] += neighborNormalForce[0] + neighborFrictionForce[0]; contactForce[neighborID*3+1] += neighborNormalForce[1] + neighborFrictionForce[1]; contactForce[neighborID*3+2] += neighborNormalForce[2] + neighborFrictionForce[2]; } else { // compute contributions to force density (Normal Force Only) contactForce[nodeID*3] -= temp*neighborVolume*(y[neighborID*3] - nodeCurrentX[0])/currentDistance; contactForce[nodeID*3+1] -= temp*neighborVolume*(y[neighborID*3+1] - nodeCurrentX[1])/currentDistance; contactForce[nodeID*3+2] -= temp*neighborVolume*(y[neighborID*3+2] - nodeCurrentX[2])/currentDistance; contactForce[neighborID*3] += temp*nodeVolume*(y[neighborID*3] - nodeCurrentX[0])/currentDistance; contactForce[neighborID*3+1] += temp*nodeVolume*(y[neighborID*3+1] - nodeCurrentX[1])/currentDistance; contactForce[neighborID*3+2] += temp*nodeVolume*(y[neighborID*3+2] - nodeCurrentX[2])/currentDistance; } } } } } }