BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Material_Alloy.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California, through
4 * Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_MATERIAL_ALLOY_HPP
13#define BELFEM_CL_MATERIAL_ALLOY_HPP
14
16
17#include "cl_Material_Metal.hpp"
18#include "cl_Tensor.hpp"
19
20namespace belfem
21{
22 namespace material
23 {
24
25 class Alloy : public SplineLookupTable
26 {
27 Vector< real > mMolarMasses ;
28 Vector< real > mMolarFractions ;
29 Vector< real > mVolumeFractions ;
30 Vector< real > mMassFractions ;
31
32 Cell< Metal * > mComponents ;
33
34 Database * mRhoData = nullptr ;
35
36 real mDatabaseTmin = BELFEM_QUIET_NAN ;
37 real mDatabaseTmax = BELFEM_QUIET_NAN ;
38 real mDatabaseBmin = BELFEM_QUIET_NAN ;
39 real mDatabaseBmax = BELFEM_QUIET_NAN ;
40
41 const real mInvLog10 = 1.0 / std::log(10.0);
42
43 bool mComputeTables = true ;
44 public:
45
46 Alloy( const string & aName,
47 const bool aBuildTables = true );
48
49 Alloy( const string & aName,
50 const Cell< std::pair< string, real > > & aComponents,
51 const real aRRR = BELFEM_QUIET_NAN,
52 const bool aBuildTables = true );
53
54 ~Alloy() override;
55
56 void
58 const Cell< string > & aComponents,
59 const Vector< real > & aMassFractions,
60 const real RRR = BELFEM_QUIET_NAN );
61
62 // Bring base class single-parameter versions into scope
63 // (needed because C++ name hiding hides Material::rho(T) when we override rho(T,B,beta))
64 using Material::rho;
65 using Material::lambda;
66 using Material::drhodT;
68
79 real
80 rho( const real T, const real B, const real beta ) const override ;
81
82 real
83 drhodT( const real T, const real B, const real beta ) const override ;
84
85 real
86 drhodB( const real T, const real B, const real beta ) const override ;
87
88 real
89 drhodbeta( const real T, const real B, const real beta ) const override ;
90
101 real
102 lambda( const real T, const real B, const real beta ) const override ;
103
104 real
105 dlambdadT( const real T, const real B, const real beta ) const override ;
106
107 private:
108
109 void
110 set_components( const Cell< std::pair< string, real > > & aComponents );
111
112 void
113 update_volume_fractions( const real T );
114
115 Metal *
116 create_component( const string & aName );
117
118 void
119 delete_components();
120
121 void
122 create_tables();
123
124 void
125 self_consistent_KG( real & Km, real & Gm, Cell< Tensor< real > * > & Tensors, Vector< real > & Work, Vector< int_t > & Pivot );
126
127 void
128 populate_rho_database();
129
130 void
131 populate_rho_database( Mesh * aMesh, Vector< real > & aRho );
132
133 void
134 populate_rho_database_serial() ;
135
136 void
137 save_rho_database( const std::string & aPath );
138
139 void
140 load_rho_database( const std::string & aPath );
141
142 };
143
144 inline real
145 Alloy::rho( const real T, const real B, const real beta ) const
146 {
147 BELFEM_ASSERT( mRhoData != nullptr, "lookup table for rho is not initialized" ) ;
148
149 real theta = std::clamp( T, mDatabaseTmin, mDatabaseTmax );
150 real log10B = std::log(std::clamp( B, mDatabaseBmin, mDatabaseBmax ) )*mInvLog10 ;
151 real angle = beta < 0 ? beta + constant::pi : beta > constant::pi ? beta - constant::pi : beta;
152
153 return std::exp(mRhoData->evaluate( theta, log10B, angle )) ;
154 }
155
156 inline real
157 Alloy::drhodT( const real T, const real B, const real beta ) const
158 {
159 BELFEM_ASSERT( mRhoData != nullptr, "lookup table for rho is not initialized" ) ;
160
161 real theta = std::clamp( T, mDatabaseTmin, mDatabaseTmax );
162 real log10B = std::log(std::clamp( B, mDatabaseBmin, mDatabaseBmax ) )*mInvLog10 ;
163 real angle = beta < 0 ? beta + constant::pi : beta > constant::pi ? beta - constant::pi : beta;
164
165 real y = mRhoData->evaluate( theta, log10B, angle ) ;
166 real dydT = mRhoData->evaluate_derivx( theta, log10B, angle ) ;
167 return std::exp( y ) * dydT ;
168 }
169
170 // field derivatives: same table chain rules as Metal::drhodB_table /
171 // drhodbeta_table ( rho = exp(y), y on the (T, log10B, angle) grid )
172 inline real
173 Alloy::drhodB( const real T, const real B, const real beta ) const
174 {
175 BELFEM_ASSERT( mRhoData != nullptr, "lookup table for rho is not initialized" ) ;
176
177 real theta = std::clamp( T, mDatabaseTmin, mDatabaseTmax );
178 real Bc = std::clamp( B, mDatabaseBmin, mDatabaseBmax ) ;
179
180 real log10B = std::log( Bc )*mInvLog10 ;
181 real angle = beta < 0 ? beta + constant::pi : beta > constant::pi ? beta - constant::pi : beta;
182
183 real y = mRhoData->evaluate( theta, log10B, angle ) ;
184 real dydlogB = mRhoData->evaluate_derivy( theta, log10B, angle ) ;
185
186 return std::exp( y ) * dydlogB * mInvLog10 / Bc ;
187 }
188
189 inline real
190 Alloy::drhodbeta( const real T, const real B, const real beta ) const
191 {
192 BELFEM_ASSERT( mRhoData != nullptr, "lookup table for rho is not initialized" ) ;
193
194 real theta = std::clamp( T, mDatabaseTmin, mDatabaseTmax );
195 real Bc = std::clamp( B, mDatabaseBmin, mDatabaseBmax ) ;
196
197 real log10B = std::log( Bc )*mInvLog10 ;
198 real angle = beta < 0 ? beta + constant::pi : beta > constant::pi ? beta - constant::pi : beta;
199
200 real y = mRhoData->evaluate( theta, log10B, angle ) ;
201 real dydbeta = mRhoData->evaluate_derivz( theta, log10B, angle ) ;
202
203 return std::exp( y ) * dydbeta ;
204 }
205
206 inline real
207 Alloy::lambda( real T, const real B, const real beta ) const
208 {
209 return this->lambda( T ) * this->rho( T ) / this->rho( T, B, beta );
210 }
211
212 inline real
213 Alloy::dlambdadT( real T, const real B, const real beta ) const
214 {
215 real a = this->lambda( T ) ;
216 real b = this->rho( T ) ;
217 real c = this->rho( T, B, beta );
218
219 real da = this->dlambdadT( T );
220 real db = this->drhodT( T );
221 real dc = this->drhodT( T, B, beta );
222
223 return ( c * ( da*b + a * db ) - a * b * dc ) /( c * c );
224 }
225
226 }
227}
228#endif //BELFEM_CL_MATERIAL_ALLOY_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
Precomputed lookup table on a tensor grid; evaluation, derivatives and HDF5 persistence.
Definition cl_Database.hpp:30
virtual real rho(const real T) const
Electrical resistivity (isotropic).
Definition cl_Material.hpp:2038
virtual real lambda(const real T=gTroom) const
Thermal conductivity (isotropic).
Definition cl_Material.hpp:1912
virtual real drhodT(const real T) const
Definition cl_Material.hpp:2049
virtual real dlambdadT(const real T=gTroom) const
Definition cl_Material.hpp:1927
Top-level container for all mesh entities.
Definition cl_Mesh.hpp:60
Third- or fourth-order tensor container; the constitutive helpers (contraction, rotation,...
Definition cl_Tensor.hpp:43
Alloy(const string &aName, const bool aBuildTables=true)
Definition cl_Material_Alloy.cpp:35
real drhodB(const real T, const real B, const real beta) const override
Definition cl_Material_Alloy.hpp:173
real dlambdadT(const real T, const real B, const real beta) const override
Definition cl_Material_Alloy.hpp:213
real lambda(const real T, const real B, const real beta) const override
Thermal conductivity with magnetoresistance.
Definition cl_Material_Alloy.hpp:207
void set_components(const Cell< string > &aComponents, const Vector< real > &aMassFractions, const real RRR=BELFEM_QUIET_NAN)
Definition cl_Material_Alloy.cpp:126
real drhodT(const real T, const real B, const real beta) const override
Definition cl_Material_Alloy.hpp:157
real drhodbeta(const real T, const real B, const real beta) const override
Definition cl_Material_Alloy.hpp:190
real rho(const real T, const real B, const real beta) const override
Electrical resistivity with magnetoresistance (Kohler's rule).
Definition cl_Material_Alloy.hpp:145
Base class for metallic materials (pure metals and alloys).
Definition cl_Material_Metal.hpp:47
SplineLookupTable(const MaterialType aType, const bool aIsIsotropic=true)
Definition cl_Material_SplineLookupTable.cpp:17
const real pi
circle number
Definition constants.hpp:41
Definition cl_BhCurve.cpp:19
USER GUIDES:
Definition cl_Capacitor.cpp:16
@ RRR
Definition cl_Material.hpp:182
double real
Definition typedefs.hpp:36
#define BELFEM_QUIET_NAN
Definition typedefs.hpp:87