Skip to content

Switch solver to in-memory API and adjust examples - #113

Open
chemiskyy wants to merge 20 commits into
masterfrom
feature/micro
Open

chemiskyy wants to merge 20 commits into
masterfrom
feature/micro

Conversation

@chemiskyy

Copy link
Copy Markdown
Member

Replace legacy file-driven workflow with the in-memory solver API and update examples, benchmarks, tests and docs accordingly. CMakeLists now compiles test/support file readers into test executables; new solver_assembly sources and headers added. Benchmarks and benchmark README now use sim.solver.from_file + sim.solver.solve (and parse the path outside timed regions) so timings isolate the path-file round-trip. Many example scripts were converted to call sim.solver.from_file/sim.solver.solve and to consume in-memory numpy results; several example data/output files and legacy micromechanics input files were removed. Documentation updated to explain that the C++ engine reads no files, mean-field micromechanics phases are passed in memory, and test-support file helpers live in test/support. Tests and python wrapper additions for micromechanics and L_eff phases were also added.

Replace legacy file-driven workflow with the in-memory solver API and update examples, benchmarks, tests and docs accordingly. CMakeLists now compiles test/support file readers into test executables; new solver_assembly sources and headers added. Benchmarks and benchmark README now use sim.solver.from_file + sim.solver.solve (and parse the path outside timed regions) so timings isolate the path-file round-trip. Many example scripts were converted to call sim.solver.from_file/sim.solver.solve and to consume in-memory numpy results; several example data/output files and legacy micromechanics input files were removed. Documentation updated to explain that the C++ engine reads no files, mean-field micromechanics phases are passed in memory, and test-support file helpers live in test/support. Tests and python wrapper additions for micromechanics and L_eff phases were also added.
Prevent spurious full-relaxation of viscoelastic branches when the solver probes tangents with zero time increments. Set Phi = 0 and dPhidv = -1 in zero-time branches across Prony/Zener implementations (mechanical and thermomechanical) so the stationary probe does not force EV = eps and commit a relaxed branch at block boundaries.

Also:
- Add a unit test (test_viscoelastic_survives_a_block_boundary) to ensure equivalent stress whether a ramp is provided as one block or cut into blocks.
- Change umat_L_elastic convergence check to use Frobenius norm ("fro") instead of norm(...,2) to avoid an expensive/full SVD that caused out-of-bounds reads on the Windows CLAPACK build.
- Update the chaboche identification example to return only the experiment block from solver outputs and adjust the cost/runner callsites accordingly.
- Add generated test result files and test binaries for various UMAT cases.
Prevent viscoelastic branches from being spuriously relaxed at block boundaries by treating the zero-time tangent probe as no-flow: set Phi=0 and dPhidv=-1 in Prony/Zener (mechanical & thermomechanical) and combined Prony+plastic kernels. Add a regression test (test_viscoelastic_survives_a_block_boundary) that ensures splitting a ramp into blocks does not change the stress response. Update the identification example to return only the experiment block (remove SIGMA11_COL and unused results path/dir) and adjust function signatures/calls accordingly. Also switch a matrix norm to the Frobenius norm in umat_L_elastic to avoid an SVD read-out-of-bounds on Windows CLAPACK builds.
Add strict validation and indexing for phase data and fix an accumulation bug in the mechanical tangent. Python: to_phase_dict gains an optional number argument and to_phase_dicts now enumerates phases so their 'number' matches their position (avoids accidental Voigt averaging when all dataclass numbers default to 0). C++ (phases.cpp): add dict_string helper, check for empty 'props', enforce that phase.number == position, forbid nested mean-field phases via umat_name shape check, validate 'coatingof' range, and use the validated umat_name when updating material properties; better error messages prevent out-of-bounds/indexing surprises. Misc: include <stdexcept> in multiphase.cpp. Prony_Nfast_Plastic: stop accumulating kappa_j and K across Newton iterations by using assignment instead of +=, preventing incorrect tangent scaling. These changes tighten input validation and fix correctness issues that could lead to silent, hard-to-debug errors.
Multiple fixes and enhancements across Python, C++ and tests:

Python (micromechanics):
- Robust JSON I/O for phases/layers/ellipsoids/cylinders/sections: accept positional lists or name->value mappings, expose and persist prop_names, and warn when reading unordered dicts.  Added _props_from_json helper and propagate prop_names in save_*_json.
- Change Layer defaults: layerup/layerdown default to 0 to preserve stacking state.
- Import warnings where needed.

Examples:
- Use LogStrain instead of Green-Lagrange in objective_rates example to match output choice.
- Restore reinforcement semi-axes after sweep to avoid mutating next runs.
- Remove unused imports (pylab, os) in several examples.

Python wrappers & tests:
- Strengthen phases parsing and validation in pybind wrapper (phases.hpp/.cpp): clearer comments, ensure phases numbered by position, reject nested/misnumbered phases, fix ARMA allocator include ordering.
- Tests adapted and extended: make test probes robust to different built bindings, add path-file parsing unit test that pins grammar fields, update Windows probe and l_eff/solver phases skips to detect whether the in-memory 'phases' argument is accepted.

C++ solver and constitutive code:
- Add doxygen-style docs to solver_assembly.hpp for Lt_2_K, Lth_2_K and check_path_output.
- Ensure sub_phases must be provided by caller (multiphase) and attach them before block loop (solver.cpp).
- Use Frobenius norm for convergence check to avoid Windows LAPACK SVD out-of-bounds issue.
- Clarify comments about viscoelastic branches: no-time branches are INACTIVE; tighten wording in multiple viscoelastic/plastic files.

Miscellaneous:
- Small cleanups and comment improvements across source to clarify intent and avoid subtle cross-platform issues.

These changes fix JSON round-trips, avoid silent misordering of material properties, improve cross-platform robustness (Windows LAPACK), and add/adjust tests to catch regressions.
Rework the tests probing sim._core.solver_run for Windows crashes. Replaced the legacy file-based probe and the final master solve test with four focused probes that escalate deeper into the engine: engine entry (tangent_mode validation), first UMAT call, kernel construction (nstatev=0), and a minimal valid run. Use a numpy array for ELISO_PROPS, remove the unused Path/DATA_DIR import, add record_tangent flags where appropriate, and rename tests/descriptions to reflect their intent. The minimal run still asserts a successful status.
Ensure Armadillo allocations use NumPy's allocator in every translation unit to avoid heap corruption when buffers are stolen into numpy arrays (Windows DLL boundary issues). Adds simcoon-python-builder/include/simcoon/python_wrappers/numpy_alloc.hpp and numpy_alloc.cpp (owner TU) and wires them into CMake: force-includes the header and compiles/exports the owner CPP for libsimcoon and sets the owner TU for _core. python_module.cpp now imports the NumPy C-API at module init and calls into libsimcoon on Windows to ensure a single, eagerly-initialized API table (avoids lazy import without the GIL). Removes the old temporary Windows probe test and adds an integration test that spawns a fresh interpreter to verify the solver is safe as the first call of a process.
Rework micromechanics JSON I/O and related APIs; unify orientation types; and centralize numpy allocator handling. Python: introduce EulerAngles and coerce dict/list inputs, simplify Phase/Layer/Ellipsoid/Cylinder/Section dataclasses, consolidate JSON load/save via generic _load_json/_save_json and layouts, accept dicts in to_phase_dicts, and adjust solver API to accept pre-parsed loading programmes (avoid re-parsing files during identification). C++/CMake: add simcoon_use_numpy_allocator helper to force-include numpy_alloc.hpp and ensure a single numpy C-API owner across libsimcoon and the Python module; update simcoon-python-builder to call that helper and set SIMCOON_NUMPY_ALLOC_IN_LIB when appropriate. Headers: add sub_phase_shape/check_sub_phases declarations and update phases.hpp signature/docs for sub-phase construction. Update examples and tests to use the new programme-based interfaces and the refactored micromechanics I/O.
Replace legacy plain-text path/material fixtures with JSON equivalents across examples, tests and test binaries. Update benchmarking and bench scripts to use save_path_json/load_path_json (path.json) and adjust docs accordingly. Remove test-time compilation of legacy file_readers/file_driver and delete deprecated read/write headers/sources. Add a legacy_to_json.py conversion script and numerous JSON fixture files; update Python wrappers, solver loading calls, and tests to use the new JSON-based IO. This centralizes IO on JSON and removes support for the old text-format fixtures.
Normalize loading-path JSON across examples, tests and docs: replace numeric control_type/mode codes with descriptive strings (e.g. "small_strain", "F", "linear"), ensure step entries include explicit "mode", "thermomechanical" and "T_final" where appropriate, and standardize "control" to explicit arrays. Update docs (solver.rst), io code (solver/io.py) and tests to read/write the new format and adjust example/test JSON files accordingly for consistent serialization/parsing.
Replace file-driven result output with in-memory SolverResults and update examples/docs; tidy bench script formatting.

- sim.solver.solve now returns a SolverResults object holding full histories (no output.dat file). docs updated (output.rst, python_solver.rst, identification.rst) to document keys, shapes, saving, to_dataframe and thermomechanical fields. Notes added about deprecation of output.dat and guidance for mean-field composites and sim_input_files.
- Bench script (bench_legacy_vs_modular.py) reformatted (PEP8-style imports/args/printing), numeric literals normalized to floats, and small call-site formatting fixes.
- Many Python/C++ wrappers, solver core, micromechanics, tests and builder sources updated to match the API changes (various include/src/python-setup/simcoon and simcoon-python-builder files).
Introduce a selectable volumetric term for hyperelastic laws: add VolumetricPotential enum, volumetric_potential_of and volumetric_derivatives in C++, and wire them into hyper_potential_derivatives and the generic UMAT so the volumetric term can be chosen per-law (LOG_J default or QUADRATIC). Update Python API (simcoon.modular) to expose VolumetricPotential, accept a volumetric keyword in hyperelastic dataclasses, include it in to_props and validate inputs. Extend tests to cover both volumetric options and validation, and update documentation to describe the new "volumetric" selector and the two supported U(J) forms.
Add a new example (examples/mechanical/MODUL_hyper_visco.py) demonstrating a Yeoh hyperelastic block combined with Prony branches under finite-strain (NLGEOM) viscoelastic loading, plus README/docs updates to reference it. Clarify and expand the Prony (generalized Maxwell) and Zener (generalized Kelvin chain) kernel headers: author/version bumps, richer rheological descriptions, explicit props/statev layouts, notes on instantaneous vs long-term stiffness, integration details, and new/renamed parameters (including an output instantaneous stiffness matrix L and tangent_mode). Fix example PRONY_N.py to reflect the instantaneous-modulus convention and correct nstatev layout. Several modular UMAT headers/sources and thermomechanical variants were updated to align with the revised viscoelastic mechanism and modular composition; tests updated accordingly.
Implement abaqus_jacobian to convert a corotated kernel tangent to Abaqus DDSDDE by adding the symmetric sigma ⊗ I term; use it in smart2abaqus_M, smart2abaqus_M_full and smart2abaqus_T. Update function signatures/locals to accept kernel tangents and compute the Abaqus material Jacobian. Clarify Abaqus and Ansys documentation about the material Jacobian / corotated-frame conventions and rework the statev layout docs (work quantities first, then model-specific variables). Add a unit test ensuring DDSDDE matches the expected Abaqus Jacobian behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant