Skip to content

Commit

Permalink
update unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
hverhelst committed Dec 10, 2024
1 parent 9edf5fa commit 62fa7f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
25 changes: 11 additions & 14 deletions unittests/gsMaterialMatrixTFT_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class STFTfun : public gsFunction<T>

gsMatrix<T> C = m_mm->eval3D_matrix_C(Cmat,m_patch,m_u.col(0),m_z(0,0),MaterialOutput::Generic);
gsMatrix<T> S = m_mm->eval3D_vector_C(Cmat,m_patch,m_u.col(0),m_z(0,0),MaterialOutput::Generic);

gsMatrix<T> THETA = m_mmTFT->eval_theta(C,S,E);

T n1 = math::cos(THETA(0,0));
Expand All @@ -71,7 +71,7 @@ class STFTfun : public gsFunction<T>
const index_t m_patch;
const gsMatrix<T> m_u;
const gsMatrix<T> m_z;
};
};


template<class T>
Expand Down Expand Up @@ -111,7 +111,7 @@ class Sfun : public gsFunction<T>
const index_t m_patch;
const gsMatrix<T> m_u;
const gsMatrix<T> m_z;
};
};

template<class T>
class Cfun : public gsFunction<T>
Expand Down Expand Up @@ -153,7 +153,7 @@ class Cfun : public gsFunction<T>
const index_t m_patch;
const gsMatrix<T> m_u;
const gsMatrix<T> m_z;
};
};

SUITE(gsMaterialMatrixTFT_test) // The suite should have the same name as the file
{
Expand Down Expand Up @@ -359,23 +359,23 @@ SUITE(gsMaterialMatrixTFT_test) // The suite should have the sam
parameters[7] = &alpha3fun;
}

gsMaterialMatrixBase<real_t> * materialMatrix;
gsMaterialMatrixBase<real_t> * materialMatrixTFT;
gsMaterialMatrixBase<real_t>::uPtr materialMatrix;
gsMaterialMatrixBase<real_t>::uPtr materialMatrixTFT;
gsOptionList options;
if (material==0)
{
options.addInt("Material","Material model: (0): SvK | (1): NH | (2): NH_ext | (3): MR | (4): Ogden",0);
options.addInt("Implementation","Implementation: (0): Composites | (1): Analytical | (2): Generalized | (3): Spectral",1);
materialMatrix = getMaterialMatrix<2,real_t>(mp,t,parameters,options);
materialMatrixTFT = new gsMaterialMatrixTFT<2,real_t,true>(materialMatrix);
materialMatrixTFT = memory::make_unique(new gsMaterialMatrixTFT<2,real_t,true>(*materialMatrix));
}
else
{
options.addInt("Material","Material model: (0): SvK | (1): NH | (2): NH_ext | (3): MR | (4): Ogden",material);
options.addSwitch("Compressibility","Compressibility: (false): Imcompressible | (true): Compressible",Compressibility);
options.addInt("Implementation","Implementation: (0): Composites | (1): Analytical | (2): Generalized | (3): Spectral",impl);
materialMatrix = getMaterialMatrix<2,real_t>(mp,t,parameters,options);
materialMatrixTFT = new gsMaterialMatrixTFT<2,real_t,false>(materialMatrix);
materialMatrixTFT = memory::make_unique(new gsMaterialMatrixTFT<2,real_t,false>(*materialMatrix));
}

gsVector<> testpt(2);
Expand Down Expand Up @@ -436,22 +436,22 @@ SUITE(gsMaterialMatrixTFT_test) // The suite should have the sam
CHECK_MATRIX_CLOSE(e,strain_MM,1e-3);

/// MATRIX
Sfun<real_t> Sfun(gori,materialMatrix,0,pt,z);
Sfun<real_t> Sfun(gori,materialMatrix.get(),0,pt,z);
Sfun.deriv_into(e,resss);
gsMatrix<> C_FD = resss.reshape(3,3); // Finite Differences
gsMatrix<> C_MM = materialMatrix->eval3D_matrix(0,pt,z,MaterialOutput::Generic).reshape(3,3); // implemented
CHECK_MATRIX_CLOSE(C_FD,C_MM,1e-3);

/// dMATRIX
Cfun<real_t> Cfun(gori,materialMatrix,0,pt,z);
Cfun<real_t> Cfun(gori,materialMatrix.get(),0,pt,z);
Cfun.deriv_into(e,resss);
gsMatrix<> dC_FD = resss.reshape(9,3);
gsMatrix<> dC_MM = materialMatrix->eval3D_dmatrix(0,pt,z,MaterialOutput::Generic).reshape(9,3);
dC_MM *= 2; // NOTE: dmatrix returns d(mm)/dC, and dC_FD is d(mm)/dE = 2*d(mm)/dC
CHECK_MATRIX_CLOSE(dC_FD,dC_MM,1e-3);

/// STRESS TFT
STFTfun<real_t> STFT(gori,materialMatrix,0,pt,z);
STFTfun<real_t> STFT(gori,materialMatrix.get(),0,pt,z);
STFT.eval_into(e,resss);
gsMatrix<> STFT_test = resss;
gsMatrix<> STFT_MM = vecTFT.piece(0).eval(pt).reshape(3,1);
Expand All @@ -462,9 +462,6 @@ SUITE(gsMaterialMatrixTFT_test) // The suite should have the sam
gsMatrix<> CTFT_FD = resss.reshape(3,3);
gsMatrix<> CTFT_MM = matTFT.piece(0).eval(pt).reshape(3,3);
CHECK_MATRIX_CLOSE(CTFT_FD,CTFT_MM,1e-3);

delete materialMatrix;
delete materialMatrixTFT;
}


Expand Down
19 changes: 10 additions & 9 deletions unittests/gsThinShellAssembler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@brief Provides unittests for the gsThinShellAssembler class
* Balloon: unit-test based on a hyperelastic balloon inflated by a follower pressure.
* Balloon: unit-test based on a hyperelastic balloon inflated by a follower pressure.
This test allows to test the follower pressure as well as the hyperelastic material models (incompressible)
* UAT: unit-test based on a uni-axial tension test
Expand Down Expand Up @@ -288,7 +288,7 @@ SUITE(gsThinShellAssembler_test) // The suite should have the sa
parameters[0] = &E;
parameters[1] = &nu;
parameters[2] = &ratio;
gsMaterialMatrixBase<real_t>* materialMatrix;
gsMaterialMatrixBase<real_t>::uPtr materialMatrix;

if (material==4)
{
Expand Down Expand Up @@ -396,14 +396,15 @@ SUITE(gsThinShellAssembler_test) // The suite should have the sa
result.first = P;
result.second = r;

delete materialMatrix;
delete assembler;

return result;
}

real_t balloon_analytical(const index_t material, const index_t impl, const real_t r)
{
GISMO_UNUSED(impl);

real_t Pan;
real_t R = 10.;

Expand Down Expand Up @@ -550,7 +551,7 @@ SUITE(gsThinShellAssembler_test) // The suite should have the sa
parameters[0] = &E;
parameters[1] = &nu;
parameters[2] = &ratio;
gsMaterialMatrixBase<real_t>* materialMatrix;
gsMaterialMatrixBase<real_t>::uPtr materialMatrix;

if (material==4)
{
Expand Down Expand Up @@ -661,14 +662,15 @@ SUITE(gsThinShellAssembler_test) // The suite should have the sa
result.first = L;
result.second = S;

delete materialMatrix;
delete assembler;

return result;
}

std::pair<real_t,real_t> UAT_analytical(const index_t material, const index_t impl, const bool Compressibility)
{
GISMO_UNUSED(impl);

real_t PoissonRatio;
real_t Ratio = 7.0;

Expand Down Expand Up @@ -846,13 +848,13 @@ SUITE(gsThinShellAssembler_test) // The suite should have the sa
Ts[0] = Ts[1] = Ts[2] = Ts[3] = Ts[4] = &thicks;

std::vector<gsFunctionSet<>*> parameters;
gsMaterialMatrixBase<real_t>* materialMatrix;
gsMaterialMatrixBase<real_t>::uPtr materialMatrix;

gsOptionList options;

if (composite)
{
materialMatrix = new gsMaterialMatrixComposite<3,real_t>(mp,Ts,Gs,Phis,Rs);
materialMatrix = memory::make_unique(new gsMaterialMatrixComposite<3,real_t>(mp,Ts,Gs,Phis,Rs));
}
else
{
Expand Down Expand Up @@ -884,7 +886,6 @@ SUITE(gsThinShellAssembler_test) // The suite should have the sa
values = values.cwiseSqrt();
values = values.col(0).head(10);

delete materialMatrix;
delete assembler;

return values;
Expand Down Expand Up @@ -914,7 +915,7 @@ SUITE(gsThinShellAssembler_test) // The suite should have the sa
void Modal_CHECK(const bool composite)
{
gsVector<real_t> num = Modal_numerical(composite);

gsVector<real_t> ana = Modal_analytical();

gsVector<real_t> relError = (num - ana).array()/ana.array();
Expand Down

0 comments on commit 62fa7f8

Please sign in to comment.