Skip to content

Commit

Permalink
Updated tests for new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
reverendbedford committed Aug 23, 2022
1 parent d87873e commit 5173012
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 67 deletions.
2 changes: 1 addition & 1 deletion include/cp/crystaldamage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SlipPlaneDamage;
class TransformationFunction;

/// Abstract base class for slip plane damage models
class NEML_EXPORT CrystalDamageModel: public NEMLObject {
class NEML_EXPORT CrystalDamageModel: public HistoryNEMLObject {
public:
CrystalDamageModel(ParameterSet & params,
std::vector<std::string> vars);
Expand Down
2 changes: 1 addition & 1 deletion src/cp/crystaldamage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace neml {

CrystalDamageModel::CrystalDamageModel(ParameterSet & params,
std::vector<std::string> vars) :
NEMLObject(params),
HistoryNEMLObject(params),
varnames_(vars)
{

Expand Down
4 changes: 3 additions & 1 deletion src/cp/crystaldamage_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace neml {
PYBIND11_MODULE(crystaldamage, m) {
m.doc() = "Crystal plasticity damage models";

py::class_<CrystalDamageModel, NEMLObject,
py::module::import("neml.history");

py::class_<CrystalDamageModel, HistoryNEMLObject,
std::shared_ptr<CrystalDamageModel>>(m, "CrystalDamageModel")
.def_property_readonly("nvars", &CrystalDamageModel::nvars)
.def_property_readonly("varnames", &CrystalDamageModel::varnames)
Expand Down
4 changes: 3 additions & 1 deletion src/cp/slipharden_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace neml {
PYBIND11_MODULE(slipharden, m) {
m.doc() = "Crystal plasticity slip rate relations";

py::class_<SlipHardening, NEMLObject, std::shared_ptr<SlipHardening>>(m, "SlipHardening")
py::module::import("neml.history");

py::class_<SlipHardening, HistoryNEMLObject, std::shared_ptr<SlipHardening>>(m, "SlipHardening")
.def_property_readonly("varnames", &SlipHardening::varnames)
.def("set_varnames", &SlipHardening::set_varnames)
.def("hist_to_tau", &SlipHardening::hist_to_tau)
Expand Down
4 changes: 3 additions & 1 deletion src/cp/sliprules_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace neml {
PYBIND11_MODULE(sliprules, m) {
m.doc() = "Crystal plasticity slip rate relations";

py::class_<SlipRule, NEMLObject, std::shared_ptr<SlipRule>>(m, "SlipRule")
py::module::import("neml.history");

py::class_<SlipRule, HistoryNEMLObject, std::shared_ptr<SlipRule>>(m, "SlipRule")
.def("strength", &SlipRule::strength)
.def("slip", &SlipRule::slip)
.def("d_slip_d_s", &SlipRule::d_slip_d_s)
Expand Down
1 change: 1 addition & 0 deletions src/damage_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PYBIND11_MODULE(damage, m) {
py::class_<NEMLDamagedModel_sd, NEMLModel_sd, std::shared_ptr<NEMLDamagedModel_sd>>(m, "NEMLDamagedModel_sd")
.def_property_readonly("ndamage", &NEMLDamagedModel_sd::ndamage, "Number of damage variables.")
.def("init_damage", &NEMLDamagedModel_sd::init_damage)
.def("populate_damage", &NEMLDamagedModel_sd::populate_damage)
;

py::class_<SDTrialState, TrialState>(m, "SDTrialState")
Expand Down
1 change: 1 addition & 0 deletions src/general_flow_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
namespace neml {
PYBIND11_MODULE(general_flow, m) {
py::module::import("neml.objects");
py::module::import("neml.history");

m.doc() = "General flow models where subclass functions define everything.";

Expand Down
3 changes: 2 additions & 1 deletion src/hardening_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace neml {

PYBIND11_MODULE(hardening, m) {
py::module::import("neml.objects");
py::module::import("neml.history");

m.doc() = "Various hardening rules.";

Expand Down Expand Up @@ -116,7 +117,7 @@ PYBIND11_MODULE(hardening, m) {
}))
;

py::class_<NonAssociativeHardening, NEMLObject, std::shared_ptr<NonAssociativeHardening>>(m, "NonAssociativeHardening")
py::class_<NonAssociativeHardening, HistoryNEMLObject, std::shared_ptr<NonAssociativeHardening>>(m, "NonAssociativeHardening")
.def_property_readonly("ninter", &NonAssociativeHardening::ninter, "Number of q variables.")

.def("q",
Expand Down
7 changes: 7 additions & 0 deletions src/history_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ PYBIND11_MODULE(history, m) {
"Populate a blank history object with the names/types")
.def("init_hist", &HistoryNEMLObject::init_hist,
"Initialize the history with the initial conditions")
.def("initial_history", [](HistoryNEMLObject & m) -> History
{
History h;
m.populate_hist(h);
m.init_hist(h);
return h;
}, "Return a fully initialized history object")
.def_property_readonly("nhist", &HistoryNEMLObject::nhist,
"Number of internal variables")
;
Expand Down
2 changes: 1 addition & 1 deletion src/ri_flow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void RateIndependentNonAssociativeHardening::populate_hist(History & hist) const

void RateIndependentNonAssociativeHardening::init_hist(History & hist) const
{
hardening_->populate_hist(hist);
hardening_->init_hist(hist);
}

void RateIndependentNonAssociativeHardening::f(const double* const s,
Expand Down
1 change: 1 addition & 0 deletions src/ri_flow_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace neml {

PYBIND11_MODULE(ri_flow, m) {
py::module::import("neml.objects");
py::module::import("neml.history");

m.doc() = "Rate independent flow models.";

Expand Down
1 change: 1 addition & 0 deletions src/visco_flow_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
namespace neml {
PYBIND11_MODULE(visco_flow, m) {
py::module::import("neml.objects");
py::module::import("neml.history");

m.doc() = "Viscoplastic flow models.";

Expand Down
1 change: 1 addition & 0 deletions src/walker_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
namespace neml {
PYBIND11_MODULE(walker, m) {
py::module::import("neml.objects");
py::module::import("neml.history");
py::module::import("neml.general_flow");
py::module::import("neml.visco_flow");

Expand Down
14 changes: 7 additions & 7 deletions test/test_crystaldamage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from neml import history, interpolate
from neml import interpolate
from neml.math import tensors, rotations, matrix, projections
from neml.cp import crystallography, sliprules, crystaldamage, slipharden

Expand Down Expand Up @@ -94,8 +94,8 @@ def setUp(self):
self.nfunc, self.L)

self.huse = history.History()
self.hmodel.populate_history(self.huse)
self.model.populate_history(self.huse)
self.hmodel.populate_hist(self.huse)
self.model.populate_hist(self.huse)

for i in range(12):
self.huse.set_scalar("strength"+str(i), 2.0)
Expand Down Expand Up @@ -162,8 +162,8 @@ def setUp(self):
self.model = crystaldamage.NilDamageModel()

self.huse = history.History()
self.hmodel.populate_history(self.huse)
self.model.populate_history(self.huse)
self.hmodel.populate_hist(self.huse)
self.model.populate_hist(self.huse)

for i in range(12):
self.huse.set_scalar("strength"+str(i), 25.0)
Expand All @@ -177,10 +177,10 @@ def setUp(self):

def test_hist(self):
test = history.History()
self.model.populate_history(test)
self.model.populate_hist(test)
self.assertEqual(test.size, 1)
self.assertEqual(test.items, ["whatever"])
self.model.init_history(test)
self.model.init_hist(test)
self.assertAlmostEqual(test.get_scalar("whatever"), 0.0)

def test_projection(self):
Expand Down
14 changes: 5 additions & 9 deletions test/test_damage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
sys.path.append('..')

from neml import interpolate, solvers, models, elasticity, ri_flow, hardening, surfaces, visco_flow, general_flow, creep, damage, larsonmiller
from neml import interpolate, solvers, models, elasticity, ri_flow, hardening, surfaces, visco_flow, general_flow, creep, damage, larsonmiller, history
from common import *

import unittest
Expand Down Expand Up @@ -76,7 +76,10 @@ def test_ndamage(self):
self.assertEqual(self.model.ndamage, 1)

def test_init_damage(self):
self.assertTrue(np.allclose(self.model.init_damage(), np.zeros((1,))))
h = history.History()
self.model.populate_damage(h)
self.model.init_damage(h)
self.assertTrue(np.allclose(h, np.zeros((1,))))

def test_ddamage_ddamage(self):
dd_model = self.dmodel.ddamage_dd(self.d_np1, self.d_n, self.e_np1, self.e_n,
Expand Down Expand Up @@ -158,13 +161,6 @@ def test_jacobian(self):
class CommonDamagedModel(object):
def test_nstore(self):
self.assertEqual(self.model.nstore, self.bmodel.nstore + self.model.ndamage)

def test_store(self):
base = self.bmodel.init_store()
damg = self.model.init_damage()
comp = list(damg) + list(base)
fromm = self.model.init_store()
self.assertTrue(np.allclose(fromm, comp))

def test_tangent_proportional_strain(self):
t_n = 0.0
Expand Down
2 changes: 1 addition & 1 deletion test/test_general_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_da_de(self):
class CommonTVPFlow(object):
def test_history(self):
self.assertEqual(len(self.h_n), self.model.nhist)
self.assertTrue(np.allclose(self.h_n, self.model.init_hist()))
self.assertTrue(np.allclose(self.h_n, self.model.initial_history()))

def test_srate(self):
t_np1 = self.gen_t()
Expand Down
6 changes: 3 additions & 3 deletions test/test_hardening.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
sys.path.append('..')

from neml import hardening, interpolate
from neml import hardening, interpolate, history
import unittest

from common import *
Expand All @@ -15,7 +15,7 @@ class CommonHardening(object):
"""
def test_history(self):
self.assertEqual(self.model.nhist, len(self.hist0))
self.assertTrue(np.allclose(self.model.init_hist(), self.hist0))
self.assertTrue(np.allclose(self.model.initial_history(), self.hist0))

def test_gradient(self):
dfn = lambda x: self.model.q(x, self.T)
Expand Down Expand Up @@ -175,7 +175,7 @@ class CommonNonAssociative(object):
def test_history(self):
self.assertEqual(self.model.nhist, len(self.hist0))
self.assertEqual(self.model.ninter, self.conform)
self.assertTrue(np.allclose(self.model.init_hist(), self.hist0))
self.assertTrue(np.allclose(self.model.initial_history(), self.hist0))

def gen_stress(self):
s = np.array([-150,200,-50,80,-20,30])
Expand Down
4 changes: 2 additions & 2 deletions test/test_hucocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ def test_history(self):
Paranoid check on the history state, given this is a kinda complicated model
"""
H1 = history.History()
self.model.populate_history(H1)
self.model.init_history(H1)
self.model.populate_hist(H1)
self.model.init_hist(H1)

self.assertEqual(len(np.array(H1)), 12+3+3)

Expand Down
8 changes: 4 additions & 4 deletions test/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ def setUp(self):

def test_setup_history(self):
H1 = history.History()
self.model.populate_history(H1)
self.model.init_history(H1)
self.model.populate_hist(H1)
self.model.init_hist(H1)

H2 = history.History()
self.imodel.populate_history(H2)
self.imodel.init_history(H2)
self.imodel.populate_hist(H2)
self.imodel.init_hist(H2)

self.assertTrue(np.allclose(np.array(H1), np.array(H2)))

Expand Down
2 changes: 1 addition & 1 deletion test/test_ri_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def gen_stress(self):

def test_history(self):
self.assertEqual(self.model.nhist, len(self.hist0))
self.assertTrue(np.allclose(self.model.init_hist(), self.hist0))
self.assertTrue(np.allclose(self.model.initial_history(), self.hist0))

def test_df_ds(self):
stress = self.gen_stress()
Expand Down
22 changes: 11 additions & 11 deletions test/test_slipharden.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from neml import history, interpolate
from neml import interpolate
from neml.math import tensors, rotations, matrix
from neml.cp import crystallography, slipharden, sliprules

Expand Down Expand Up @@ -581,8 +581,8 @@ def setUp(self):

def test_initialize_hist(self):
H = history.History()
self.model.populate_history(H)
self.model.init_history(H)
self.model.populate_hist(H)
self.model.init_hist(H)
self.assertTrue(np.isclose(H.get_scalar('strength'), 0.0))

def test_static_strength(self):
Expand Down Expand Up @@ -644,8 +644,8 @@ def setUp(self):

def test_initialize_hist(self):
H = history.History()
self.model.populate_history(H)
self.model.init_history(H)
self.model.populate_hist(H)
self.model.init_hist(H)
self.assertTrue(np.isclose(H.get_scalar('strength'), 0.0))

def test_static_strength(self):
Expand Down Expand Up @@ -701,8 +701,8 @@ def test_get_vnames(self):

def test_initialize_hist(self):
H = history.History()
self.model.populate_history(H)
self.model.init_history(H)
self.model.populate_hist(H)
self.model.init_hist(H)
self.assertTrue(np.isclose(H.get_scalar(self.vname), 0.0))

def test_static_strength(self):
Expand Down Expand Up @@ -770,8 +770,8 @@ def setUp(self):

def test_initialize_hist(self):
H = history.History()
self.model.populate_history(H)
self.model.init_history(H)
self.model.populate_hist(H)
self.model.init_hist(H)
self.assertTrue(np.isclose(H.get_scalar('strength0'), 0.0))
self.assertTrue(np.isclose(H.get_scalar('strength1'), 0.0))

Expand Down Expand Up @@ -831,8 +831,8 @@ def setUp(self):

def test_initialize_hist(self):
H = history.History()
self.model.populate_history(H)
self.model.init_history(H)
self.model.populate_hist(H)
self.model.init_hist(H)
self.assertTrue(np.isclose(H.get_scalar('strength'), 0.0))

def test_static_strength(self):
Expand Down
22 changes: 11 additions & 11 deletions test/test_sliprules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from neml import history, interpolate
from neml import interpolate
from neml.math import tensors, rotations, matrix
from neml.cp import crystallography, slipharden, sliprules

Expand Down Expand Up @@ -43,14 +43,14 @@ def test_d_hist_rate_d_hist(self):
class CommonSlipMultiStrengthSlipRule(object):
def test_setup_history(self):
model_hist = history.History()
self.model.populate_history(model_hist)
self.model.init_history(model_hist)
self.model.populate_hist(model_hist)
self.model.init_hist(model_hist)

manual_hist = history.History()
for strength in self.strengths:
Hs = history.History()
strength.populate_history(Hs)
strength.init_history(Hs)
strength.populate_hist(Hs)
strength.init_hist(Hs)
manual_hist.add_union(Hs)

self.assertTrue(np.allclose(np.array(model_hist),
Expand Down Expand Up @@ -194,8 +194,8 @@ def setUp(self):

self.model = sliprules.KinematicPowerLawSlipRule(self.backstrength, self.isostrength, self.flowresistance, self.g0, self.n)

self.model.populate_history(self.H)
self.model.init_history(self.H)
self.model.populate_hist(self.H)
self.model.init_hist(self.H)

self.strength_values = np.linspace(0,10,36) + 5.0
self.H.copy_data(self.strength_values)
Expand All @@ -205,12 +205,12 @@ def setUp(self):
class CommonSlipStrengthSlipRule(CommonSlipMultiStrengthSlipRule):
def test_init_hist(self):
H1 = history.History()
self.model.populate_history(H1)
self.model.init_history(H1)
self.model.populate_hist(H1)
self.model.init_hist(H1)

H2 = history.History()
self.strengthmodel.populate_history(H2)
self.strengthmodel.init_history(H2)
self.strengthmodel.populate_hist(H2)
self.strengthmodel.init_hist(H2)

self.assertTrue(np.allclose(np.array(H1),
np.array(H2)))
Expand Down
Loading

0 comments on commit 5173012

Please sign in to comment.