Skip to content

Commit

Permalink
Add inverse mapping function (idaholab#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schunert committed Jan 7, 2020
1 parent f808511 commit dd815ec
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
7 changes: 7 additions & 0 deletions include/utils/PolyatomicDamageEnergyFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ class PolyatomicDamageEnergyFunction : public PolyatomicDisplacementFunctionBase
Real _taylor_series_threshold = 1e2;

protected:
/// override the mapIndex function: flattens ijl to single index n
unsigned int mapIndex(unsigned int i, unsigned int /*j*/, unsigned int /*l*/) const override
{
return i;
};

/// override the inverseMapIndex function: retrieves n given ijk
void inverseMapIndex(unsigned int n,
unsigned int & i,
unsigned int & j,
unsigned int & l) const override;
};

#endif // GSL_ENABLED
8 changes: 7 additions & 1 deletion include/utils/PolyatomicDisplacementDerivativeFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ class PolyatomicDisplacementDerivativeFunction : public PolyatomicDisplacementFu
Real source(Real energy, unsigned int i, unsigned int j, unsigned int l);

protected:
/// maps triple index theta_ijl to single theta_n; l runs faster than j runs faster than i
/// override the mapIndex function: flattens ijl to single index n
unsigned int mapIndex(unsigned int i, unsigned int j, unsigned int l) const override
{
return i + j * _n_species + l * _n_species * _n_species;
};

/// override the inverseMapIndex function: retrieves n given ijk
void inverseMapIndex(unsigned int n,
unsigned int & i,
unsigned int & j,
unsigned int & l) const override;

/// the source term in the NRT equatons for the derivative requires the solution of the equations themselves
const PolyatomicDisplacementFunction * _net_displacement_function;
};
Expand Down
8 changes: 7 additions & 1 deletion include/utils/PolyatomicDisplacementFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ class PolyatomicDisplacementFunction : public PolyatomicDisplacementFunctionBase
Real integralTypeII(Real energy, unsigned int i, unsigned int j, unsigned int k) const;

protected:
/// maps double index nu_ij to single index nu_n; j runs faster than i
/// override the mapIndex function: flattens ijl to single index n
unsigned int mapIndex(unsigned int i, unsigned int j, unsigned int /*l*/) const override
{
return i + j * _n_species;
};

/// override the inverseMapIndex function: retrieves n given ijk
void inverseMapIndex(unsigned int n,
unsigned int & i,
unsigned int & j,
unsigned int & l) const override;

/// is the total damage function computed
bool _total_displacement_function;
};
Expand Down
8 changes: 6 additions & 2 deletions include/utils/PolyatomicDisplacementFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class PolyatomicDisplacementFunctionBase
///@}

/// linear interpolation of the damage function
Real linearInterpolation(Real energy, unsigned int i, unsigned int j = 0, unsigned int l = 0) const;
Real
linearInterpolation(Real energy, unsigned int i, unsigned int j = 0, unsigned int l = 0) const;

/// gets stopping power for a given species and energy; non-const because it uses _ions so no need to construct ion
Real stoppingPower(unsigned int species, Real energy);
Expand All @@ -72,6 +73,10 @@ class PolyatomicDisplacementFunctionBase
/// this function flattens the arrays i, j, l to a single index
virtual unsigned int mapIndex(unsigned int i, unsigned int j, unsigned int l) const = 0;

/// this function unflattens n to indices i, j, l
virtual void
inverseMapIndex(unsigned int n, unsigned int & i, unsigned int & j, unsigned int & l) const = 0;

/// computes the integral int_0^t dT T * d(sigma_ij) / dT for species combination i, j and small t
Real
weightedScatteringIntegral(Real energy, Real energy_limit, unsigned int i, unsigned int j) const;
Expand All @@ -94,7 +99,6 @@ class PolyatomicDisplacementFunctionBase
Real linearInterpolationHelper(
Real energy, unsigned int index, unsigned int i, unsigned int j, unsigned int l) const;


/// damage function type [nij and gij, respectively in PK JNM 101, 1981; or nu_i JNM 88, (1980)]
nrt_type _damage_function_type;

Expand Down
13 changes: 12 additions & 1 deletion src/utils/PolyatomicDamageEnergyFunction.C
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,21 @@ PolyatomicDamageEnergyFunction::integralTypeII(Real energy, unsigned int i, unsi
{
Real recoil_energy = scale * (_quad_points[qp] + 1) + lower;
integral += scale * _quad_weights[qp] * scatteringCrossSection(i, j, energy, recoil_energy) *
(linearInterpolation( energy - recoil_energy, i) - current_value);
(linearInterpolation(energy - recoil_energy, i) - current_value);
}
}
return integral;
}

void
PolyatomicDamageEnergyFunction::inverseMapIndex(unsigned int n,
unsigned int & i,
unsigned int & j,
unsigned int & l) const
{
i = n;
j = 0;
l = 0;
}

#endif
12 changes: 12 additions & 0 deletions src/utils/PolyatomicDisplacementDerivativeFunction.C
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,16 @@ PolyatomicDisplacementDerivativeFunction::source(Real energy,
d_net_dE * stoppingPowerDerivative(i, l, energy);
}

void
PolyatomicDisplacementDerivativeFunction::inverseMapIndex(unsigned int n,
unsigned int & i,
unsigned int & j,
unsigned int & l) const
{
unsigned int t = n % (_n_species * _n_species);
i = t % _n_species;
j = (t - i) / _n_species;
l = (n - t) / (_n_species * _n_species);
}

#endif
11 changes: 11 additions & 0 deletions src/utils/PolyatomicDisplacementFunction.C
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,15 @@ PolyatomicDisplacementFunction::integralTypeII(Real energy,
return integral;
}

void
PolyatomicDisplacementFunction::inverseMapIndex(unsigned int n,
unsigned int & i,
unsigned int & j,
unsigned int & l) const
{
i = n % _n_species;
j = (n - i) / _n_species;
l = 0;
}

#endif

0 comments on commit dd815ec

Please sign in to comment.