Skip to content

Conversation

@jmartfrut
Copy link
Collaborator

Introduces a more explicit kinematic description and associates it directly with the physics of the solid material, thus decoupling the kinematic model from the specific electrical or magnetic model.

This change simplifies the model definitions and usage in weak forms and post-processors, improving overall code clarity and maintainability.

Introduces a more explicit kinematic description and associates
it directly with the physics of the solid material, thus decoupling
the kinematic model from the specific electrical or magnetic model.

This change simplifies the model definitions and usage in weak forms
and post-processors, improving overall code clarity and maintainability.
@jmartfrut jmartfrut requested a review from Copilot November 5, 2025 18:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the kinematic model architecture by removing the Kinematic field from physical models and introducing an explicit KinematicDescription type hierarchy. The key changes include:

  • Introducing Solid and SolidShell as concrete kinematic descriptions
  • Refactoring Kinematics constructor to require both physics type and description type
  • Removing Kinematic fields from all physical model structs
  • Passing kinematic models explicitly to residual and jacobian functions
  • Converting KinematicDescription{:SecondPiola} from a parameterized type to a new function SecondPiola
  • Updating state variable update functions to accept deformation gradients directly

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
src/PhysicalModels/KinematicModels.jl Introduces Solid/SolidShell abstract types and refactors Kinematics constructor to require kinematic description type
src/PhysicalModels/MechanicalModels.jl Removes Kinematic fields from mechanical models; inlines kinematic functions (J, H) in model definitions; converts KinematicDescription{:SecondPiola} to SecondPiola function
src/PhysicalModels/ViscousModels.jl Removes Kinematic field; changes updateStateVariables! signature to accept F and Fn directly; replaces KinematicDescription{:SecondPiola} with SecondPiola function call
src/PhysicalModels/ElectricalModels.jl Removes Kinematic field from IdealDielectric
src/PhysicalModels/MagneticModels.jl Removes Kinematic field from magnetic models
src/PhysicalModels/ElectroMechanicalModels.jl Inlines kinematic functions (J, H) in coupling functions
src/PhysicalModels/ThermoMechanicalModels.jl Inlines kinematic functions (J, H) in coupling and entropy models
src/PhysicalModels/ThermoElectroMechanicalModels.jl Inlines kinematic functions (J, H) in thermo-electro-mechanical coupling
src/PhysicalModels/MagnetoMechanicalModels.jl Inlines kinematic functions (J, H) in magneto-mechanical coupling
src/PhysicalModels/PINNs.jl Updates Kinematics calls to include Solid description
src/PhysicalModels/PhysicalModels.jl Exports SecondPiola and Solid; moves KinematicDescription export
src/WeakForms/WeakForms.jl Adds KinematicModel parameter to residual/jacobian functions; removes internal kinematic creation
src/WeakForms/ElectroMechanics.jl Adds kine::NTuple{2,KinematicModel} parameter to residual/jacobian functions
src/ComputationalModels/PostProcessors.jl Adds kinematic parameter to Jacobian, Cauchy, Entropy, and D0 functions
src/Exports.jl Exports Solid
test/data/ViscoElasticSimulation.jl Creates kinematic models explicitly and passes to residual/jacobian; updates updateStateVariables! calls
test/TestWeakForms/WeakForms.jl Creates kinematic tuples and passes to jacobian functions
test/TestConstitutiveModels/*.jl Creates kinematic models explicitly; updates all test function signatures; removes using HyperFEM: jacobian
README.md Updates example to show explicit kinematic model creation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

function (obj::IncompressibleNeoHookean3D)(::KinematicDescription{:SecondPiola}, Λ::Float64=1.0)
end

function SecondPiola(obj::IncompressibleNeoHookean3D::Float64=1.0)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SecondPiola function is defined outside the struct definition but should be inside or immediately following the struct's closing end. This breaks Julia convention where methods are typically defined within the struct's method block or clearly separated from it. Consider moving this function definition to be immediately after line 823 or reorganizing the code structure.

Copilot uses AI. Check for mistakes.
function residual(physicalmodel::ThermoElectroMechano, kine::NTuple{3,KinematicModel}, (u, φ, θ), (v, vφ, vθ), dΩ, Λ=1.0)
residual(physicalmodel, Mechano, kine, (u, φ, θ), v, dΩ, Λ) +
residual(physicalmodel, Electro, kine, (u, φ, θ), vφ, dΩ, Λ) +
residual(physicalmodel, Thermo, kine,(u, φ, θ), vθ, dΩ, Λ)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around function arguments. Line 162 has kine,(u, φ, θ) without a space after the comma, while lines 160-161 have proper spacing. This should be kine, (u, φ, θ) for consistency.

Suggested change
residual(physicalmodel, Thermo, kine,(u, φ, θ), vθ, dΩ, Λ)
residual(physicalmodel, Thermo, kine, (u, φ, θ), vθ, dΩ, Λ)

Copilot uses AI. Check for mistakes.
end
function jac_mech(uh, θh)
jac(du, v) = jacobian(modelTM, Mechano, (uh, θh), du, v, dΩ)
jac(du, v) = jacobian(modelTM, Mechano, k,(uh, θh), du, v, dΩ)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma between k and (uh, θh). Should be k, (uh, θh) for consistency with Julia style conventions.

Suggested change
jac(du, v) = jacobian(modelTM, Mechano, k,(uh, θh), du, v, dΩ)
jac(du, v) = jacobian(modelTM, Mechano, k, (uh, θh), du, v, dΩ)

Copilot uses AI. Check for mistakes.
end
function jac_termoh(uh, θh)
jac(dθ, vθ) = jacobian(modelTM, Thermo, dθ, vθ, dΩ)
jac(dθ, vθ) = jacobian(modelTM, Thermo,k, dθ, vθ, dΩ)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma between Thermo and k. Should be Thermo, k for consistency with Julia style conventions.

Suggested change
jac(dθ, vθ) = jacobian(modelTM, Thermo,k, dθ, vθ, dΩ)
jac(dθ, vθ) = jacobian(modelTM, Thermo, k, dθ, vθ, dΩ)

Copilot uses AI. Check for mistakes.
end
function jac_mech(uh, φh)
jac(du, v) = jacobian(modelelectro, Mechano, (uh, φh), du, v, dΩ)
jac(du, v) = jacobian(modelelectro, Mechano, k,(uh, φh), du, v, dΩ)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma between k and (uh, φh). Should be k, (uh, φh) for consistency with Julia style conventions.

Suggested change
jac(du, v) = jacobian(modelelectro, Mechano, k,(uh, φh), du, v, dΩ)
jac(du, v) = jacobian(modelelectro, Mechano, k, (uh, φh), du, v, dΩ)

Copilot uses AI. Check for mistakes.
Comment on lines +100 to +101
res(Λ) = ((u, φ), (v, vφ)) -> residual(physmodel, (km,ke),(u, φ), (v, vφ), dΩ)
jac(Λ) = ((u, φ), (du, dφ), (v, vφ)) -> jacobian(physmodel, (km,ke), (u, φ), (du, dφ), (v,vφ),dΩ)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces after commas in kinematic tuple (km,ke) and before the next argument (u, φ). Should be (km, ke), (u, φ) for consistency with Julia style conventions.

Suggested change
res(Λ) = ((u, φ), (v, vφ)) -> residual(physmodel, (km,ke),(u, φ), (v, vφ), dΩ)
jac(Λ) = ((u, φ), (du, dφ), (v, vφ)) -> jacobian(physmodel, (km,ke), (u, φ), (du, dφ), (v,vφ),dΩ)
res(Λ) = ((u, φ), (v, vφ)) -> residual(physmodel, (km, ke), (u, φ), (v, vφ), dΩ)
jac(Λ) = ((u, φ), (du, dφ), (v, vφ)) -> jacobian(physmodel, (km, ke), (u, φ), (du, dφ), (v, vφ), dΩ)

Copilot uses AI. Check for mistakes.
Comment on lines +100 to +101
res(Λ) = ((u, φ), (v, vφ)) -> residual(physmodel, (km,ke),(u, φ), (v, vφ), dΩ)
jac(Λ) = ((u, φ), (du, dφ), (v, vφ)) -> jacobian(physmodel, (km,ke), (u, φ), (du, dφ), (v,vφ),dΩ)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces after commas in multiple places: (km,ke) should be (km, ke), (v,vφ) should be (v, vφ), and (v,vφ),dΩ should be (v, vφ), dΩ for consistency with Julia style conventions.

Suggested change
res(Λ) = ((u, φ), (v, vφ)) -> residual(physmodel, (km,ke),(u, φ), (v, vφ), dΩ)
jac(Λ) = ((u, φ), (du, dφ), (v, vφ)) -> jacobian(physmodel, (km,ke), (u, φ), (du, dφ), (v,vφ),dΩ)
res(Λ) = ((u, φ), (v, vφ)) -> residual(physmodel, (km, ke), (u, φ), (v, vφ), dΩ)
jac(Λ) = ((u, φ), (du, dφ), (v, vφ)) -> jacobian(physmodel, (km, ke), (u, φ), (du, dφ), (v, vφ), dΩ)

Copilot uses AI. Check for mistakes.
end

function jacobian(physicalmodel::ThermoElectroMech_PINNs, ::Type{Thermo}, dθ, vθ, dΩ, Λ=1.0)
function jacobian(physicalmodel::ThermoElectroMech_PINNs, ::Type{Thermo}, kine::NTuple{2,KinematicModel},dθ, vθ, dΩ, Λ=1.0)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing: double space after ::Type{Thermo}, and missing space after kine::NTuple{2,KinematicModel},. Should be single spaces throughout.

Copilot uses AI. Check for mistakes.
jacobian(physicalmodel, ThermoMechano, (u, θ), (du, dθ), v, dΩ, Λ)
function jacobian(physicalmodel::ThermoMechano, kine::NTuple{2,KinematicModel}, (u, θ), (du, dθ), (v, vθ), dΩ, Λ=1.0)
jacobian(physicalmodel, Mechano, kine, (u, θ), du, v, dΩ, Λ)+
jacobian(physicalmodel, Thermo, kine,dθ, vθ, dΩ, Λ)+
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma between kine and . Should be kine, dθ for consistency with Julia style conventions.

Suggested change
jacobian(physicalmodel, Thermo, kine,dθ, vθ, dΩ, Λ)+
jacobian(physicalmodel, Thermo, kine, dθ, vθ, dΩ, Λ)+

Copilot uses AI. Check for mistakes.
Comment on lines +135 to +137
jacobian(physicalmodel, Mechano, kine,(u, φ), du, v, dΩ, Λ, Δt, un, A) +
jacobian(physicalmodel, Electro, kine,(u, φ), dφ, vφ, dΩ, Λ, Δt, un, A) +
jacobian(physicalmodel, ElectroMechano, kine,(u, φ), (du, dφ), (v, vφ), dΩ, Λ, Δt, un, A)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces after commas between kine and (u, φ) on all three lines. Should be kine, (u, φ) for consistency with Julia style conventions.

Suggested change
jacobian(physicalmodel, Mechano, kine,(u, φ), du, v, dΩ, Λ, Δt, un, A) +
jacobian(physicalmodel, Electro, kine,(u, φ), dφ, vφ, dΩ, Λ, Δt, un, A) +
jacobian(physicalmodel, ElectroMechano, kine,(u, φ), (du, dφ), (v, vφ), dΩ, Λ, Δt, un, A)
jacobian(physicalmodel, Mechano, kine, (u, φ), du, v, dΩ, Λ, Δt, un, A) +
jacobian(physicalmodel, Electro, kine, (u, φ), dφ, vφ, dΩ, Λ, Δt, un, A) +
jacobian(physicalmodel, ElectroMechano, kine, (u, φ), (du, dφ), (v, vφ), dΩ, Λ, Δt, un, A)

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Benchmark Results (Julia v1)

Time benchmarks
main 3444f00... main / 3444f00...
Constitutive models/Visco-elastic Ψ 0.0472 ± 0.027 ms 0.0478 ± 0.027 ms 0.988 ± 0.8
Constitutive models/Visco-elastic ∂Ψu 0.0617 ± 0.0033 ms 0.0625 ± 0.0032 ms 0.988 ± 0.074
Constitutive models/Visco-elastic ∂Ψuu 0.109 ± 0.015 ms 0.111 ± 0.015 ms 0.98 ± 0.19
Simulations/ViscoElastic 0.0476 h 0.0489 h 0.973
Tensor algebra/δδ_λ_2d 30 ± 0 ns 30 ± 0 ns 1 ± 0
Tensor algebra/δδ_μ_2d 30 ± 0 ns 30 ± 0 ns 1 ± 0
time_to_load 2.52 ± 0.025 s 2.57 ± 0.024 s 0.981 ± 0.013
Memory benchmarks
main 3444f00... main / 3444f00...
Constitutive models/Visco-elastic Ψ 1.24 k allocs: 0.0782 MB 1.24 k allocs: 0.0782 MB 1
Constitutive models/Visco-elastic ∂Ψu 1.36 k allocs: 0.0904 MB 1.36 k allocs: 0.0904 MB 1
Constitutive models/Visco-elastic ∂Ψuu 2.31 k allocs: 0.155 MB 2.31 k allocs: 0.155 MB 1
Simulations/ViscoElastic 2.72 G allocs: 192 GB 2.72 G allocs: 192 GB 1
Tensor algebra/δδ_λ_2d 0 allocs: 0 B 0 allocs: 0 B
Tensor algebra/δδ_μ_2d 0 allocs: 0 B 0 allocs: 0 B
time_to_load 0.149 k allocs: 11.1 kB 0.149 k allocs: 11.1 kB 1

@jmartfrut jmartfrut merged commit d2bb3ce into main Nov 5, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants