Skip to content
Snippets Groups Projects

[Minor - torchSCULatticeLaw] - HouseKeeping

Merged Mohib Mustafa requested to merge dev_mm_torchSCRU into master
2 files
+ 68
126
Compare changes
  • Side-by-side
  • Inline

Files

@@ -3072,11 +3072,11 @@ void torchANNBasedDG3DMaterialLaw::RNNstress_stiff(const fullMatrix<double>& E0,
#if defined(HAVE_TORCH)
// subroutine for computing stress and stiffness using extra inputs (other than Strain and internal variables) @Mohib TODO: Rename
//appended arguments with E0 and Extra0 to feature enable SCU @Mohib
void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>& E0, const fullMatrix<double>& E1, const fullMatrix<double>& Extra0, const fullMatrix<double>& Extra1, const torch::Tensor& h0, torch::Tensor& h1,
fullMatrix<double>& S, const bool stiff, fullMatrix<double>& DSDE)
{
// appended arguments with E0 and Extra0 to feature enable SCU @Mohib
void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>& E0, const fullMatrix<double>& E1,
const fullMatrix<double>& Extra0, const fullMatrix<double>& Extra1,
const torch::Tensor& h0, torch::Tensor& h1,
fullMatrix<double>& S, const bool stiff, fullMatrix<double>& DSDE){
// Containers for Strain and extra inputs @ Mohib
vector<float> E_vec(_numberOfInput - _numberOfExtraInput);
// Appended E0 to feature enable SCU @Mohib
@@ -3096,7 +3096,6 @@ void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>&
// Container for normalized combined input exteries(Extra + Input) @ Mohib
torch::Tensor Combine0_norm;
// @Mohib TODO: Remove b4 commit
torch::Tensor E_norm;
// Appended E0 and dE_norm to feature enable SCU
torch::Tensor E0_norm, dE_norm;
@@ -3118,41 +3117,18 @@ void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>&
Normalize_strain(E0, E0_vec);
// Normalize extra inputs at previous time step and store in Extra0_vec. Necessary for feature enabling SCU @Mohib
Normalize_geo(Extra0, Extra0_vec);
// Changes in SCU with Radius correction dont require this combine vector anymore TODO: Cleanup b4 commit
// // Populate the container "Combine_vec0" with the normalized quantities in the correct order.
// // Order is : Radius + E0 for SCU. Last entry in Extra0_vec contains time and isnt needed here @Mohib.
// Combine0_vec.insert(Combine0_vec.end(), Extra0_vec.begin(), Extra0_vec.end() - 1);
// Combine0_vec.insert(Combine0_vec.end(), E0_vec.begin(), E0_vec.end());
}
if(_NeedExtraNorm and _DoubleInput){
// Changes in SCU with Radius correction dont require this combine vector anymore TODO: Cleanup b4 commit
// // Populate the container "Combine_vec" with the normalized quantities in the correct order.
// // Order is : Radius + E for SCU . Last entry in Extra_vec contains time and isnt needed here @Mohib.
// Combine_vec.insert(Combine_vec.end(), Extra_vec.begin(), Extra_vec.end() - 1);
// Combine_vec.insert(Combine_vec.end(), E_vec.begin(), E_vec.end());
if(stiff){
E0_norm = torch::from_blob(E0_vec.data(), {1,1, _numberOfInput - _numberOfExtraInput}, torch::requires_grad());
// Changes in SCU with Radius correction dont require this combine vector anymore TODO: Cleanup b4 commit
// Combine0_norm = torch::from_blob(Combine0_vec.data(), {1,1, _numberOfInput - 1}, torch::requires_grad());
}
else{
E0_norm = torch::from_blob(E0_vec.data(), {1,1, _numberOfInput - _numberOfExtraInput}, torch::requires_grad(false));
// Changes in SCU with Radius correction dont require this combine vector anymore TODO: Cleanup b4 commit
// Combine0_norm = torch::from_blob(Combine0_vec.data(), {1,1, _numberOfInput - 1}, torch::requires_grad(false));
}
// Changes in SCU with Radius correction dont require pushing this combine vector into the input jit anymore TODO: Cleanup b4 commit
// inputs.push_back(Combine0_norm);
inputs.push_back(E0_norm);
}
else{
// Populate the container "Combine_vec" with the normalized quantities in the correct order.
// Order is : Radius, Size, TSTEP + E for GRU @Mohib.
Combine_vec.insert(Combine_vec.end(), Extra_vec.begin(), Extra_vec.end());
@@ -3168,10 +3144,7 @@ void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>&
}
inputs.push_back(Combine_norm);
}
// // @Mohib TODO: fix 3 and 6 cases
// E_norm = torch::from_blob(E_vec.data(), {1,1, _numberOfInput - _numOfExtra}, torch::requires_grad());
// added norm of E1 and delta E_vec to feature enable SCU @Mohib
vector<float> norm_E1(1);
// delta DE_vec doesnt include time and radius so decrementing by num of extea variables @Mohib.
@@ -3180,9 +3153,7 @@ void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>&
if(_kinematicInput == torchANNBasedDG3DMaterialLaw::EGLInc or _NeedExtraNorm){
if(_kinematicInput == torchANNBasedDG3DMaterialLaw::EGL and _NeedExtraNorm){
for (int i = 0; i <_numberOfInput - _numberOfExtraInput; i++) {
// Changes in SCU with Radius correction dont require this combine vector anymore TODO: Cleanup b4 commit
//DE_vec[i] = Combine_vec[i]- Combine0_vec[i];
for (int i = 0; i <_numberOfInput - _numberOfExtraInput; i++){
DE_vec[i] = E_vec[i]-E0_vec[i];
}
if(_DoubleInput){
@@ -3194,32 +3165,16 @@ void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>&
}
inputs.push_back(dE_norm);
}
// norm_E1[0] = sqrt(std::inner_product(DE_vec.begin(), DE_vec.end(), DE_vec.begin(), 0.0));
// norm_E1[0] = sqrt(std::inner_product(DE_vec.begin(), DE_vec.end(), DE_vec.begin(), 0.0));
norm_E1[0] = 0;
for (int i = 0; i <_numberOfInput - _numberOfExtraInput; i++ ) {
norm_E1[0] += DE_vec[i] * DE_vec[i];
norm_E1[0] += DE_vec[i] * DE_vec[i];
}
norm_E1[0] = sqrt(norm_E1[0]);
}
else{
// Changes in SCU with Radius correction dont require this combine vector anymore TODO: Cleanup b4 commit
// fullMatrix<double> CombineE1(1, _numberOfInput - 1);
//
//
// for (int i = 0; i < _numberOfExtraInput - 1; i++)
// {
// CombineE1(0, i) = Extra1(0, i);
// }
//
// for (int i = 0; i < _numberOfInput - _numberOfExtraInput; i++)
// {
// CombineE1(0, _numberOfExtraInput - 1 + i) = E1(0, i);
// }
// norm_E1[0] = CombineE1.norm();
norm_E1[0] = E1.norm();
}
}
else{
norm_E1[0] = E1.norm();
}
if(stiff){
norm = torch::from_blob(norm_E1.data(), {1,1,1}, torch::requires_grad());
@@ -3235,21 +3190,18 @@ void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>&
torch::Tensor dt_norm;
if(_kinematicInput == torchANNBasedDG3DMaterialLaw::EGLInc or _NeedExtraNorm){
if(_kinematicInput == torchANNBasedDG3DMaterialLaw::EGL and _NeedExtraNorm){
// For SCU dt needs to be seperately normalized. @Mohib
Normalize_dt(Extra1, Extra_vec);
Normalize_dt(Extra0, Extra0_vec);
dt_vec[0] = Extra_vec[_numberOfExtraInput - 1] - Extra0_vec[_numberOfExtraInput - 1];
if(stiff){
dt_norm = torch::from_blob(dt_vec.data(), {1,1,1}, torch::requires_grad());
}
else{
dt_norm = torch::from_blob(dt_vec.data(), {1,1,1}, torch::requires_grad(false));
}
inputs.push_back(dt_norm);
if(_kinematicInput == torchANNBasedDG3DMaterialLaw::EGL and _NeedExtraNorm){
// For SCU dt needs to be seperately normalized. @Mohib
Normalize_dt(Extra1, Extra_vec);
Normalize_dt(Extra0, Extra0_vec);
dt_vec[0] = Extra_vec[_numberOfExtraInput - 1] - Extra0_vec[_numberOfExtraInput - 1];
if(stiff){
dt_norm = torch::from_blob(dt_vec.data(), {1,1,1}, torch::requires_grad());
}
else{
dt_norm = torch::from_blob(dt_vec.data(), {1,1,1}, torch::requires_grad(false));
}
inputs.push_back(dt_norm);
}
}
@@ -3259,21 +3211,16 @@ void torchANNBasedDG3DMaterialLaw::RNNstressGeo_stiff(const fullMatrix<double>&
if(_kinematicInput == torchANNBasedDG3DMaterialLaw::EGLInc or _NeedExtraNorm){
if(_kinematicInput == torchANNBasedDG3DMaterialLaw::EGL and _NeedExtraNorm){
// // For SCU dt needs to be seperately normalized. @Mohib
// Normalize_dt(Extra1, Extra_vec);
// Normalize_dt(Extra0, Extra0_vec);
r_vec[0] = Extra_vec[0];
if(stiff){
r_norm = torch::from_blob(r_vec.data(), {1,1,1}, torch::requires_grad());
}
else{
r_norm = torch::from_blob(r_vec.data(), {1,1,1}, torch::requires_grad(false));
}
inputs.push_back(r_norm);
}
// Extra_vec already contains normalized value
r_vec[0] = Extra_vec[0];
if(stiff){
r_norm = torch::from_blob(r_vec.data(), {1,1,1}, torch::requires_grad());
}
else{
r_norm = torch::from_blob(r_vec.data(), {1,1,1}, torch::requires_grad(false));
}
inputs.push_back(r_norm);
}
}
inputs.push_back(h0);
@@ -3564,7 +3511,7 @@ void torchANNBasedDG3DMaterialLaw::Normalize_geo(const fullMatrix<double>& Extra
{
if(_NeedExtraNorm and _DoubleInput){
int j = 0;
// For SCU we only need to normalize radius dt will be done seperatly. @Mohib
// For SCU we only need to normalize radius, dt will be done seperatly. @Mohib
for(int i=0; i<_numberOfExtraInput - 1; i++){
if(_normParams_ExtraInput[j + 1] != 0.0){
Geo_norm[i] = (Extra1(0, i) - _normParams_ExtraInput[j]) / _normParams_ExtraInput[j + 1];
Loading