Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Gas Profile: Free Formula #96

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace fieldSolver = fieldSolverYee;
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasGaussianCloud;
Expand Down
31 changes: 31 additions & 0 deletions examples/Bunch/include/simulation_defines/param/gasConfig.param
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,37 @@ namespace picongpu

}

namespace gasFreeFormula
{
namespace SI
{
struct GasProfile
{
/** Normalized Gas Profile [0.0:1.0]
*
* This formula should use SI quantities only!
* The normalized profile will be multiplied by GAS_DENSITY.
*
* @param pos vector with offset to the global (left top front) cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_64 operator()( float3_64 pos )
{
const float_64 y = pos.y() * 1000.0; // m -> mm

/* triangle function example
* for a density profile from 0 to 400 microns */
float_64 s = 1.0 - 5.0 * math::abs( y - 0.2 );

/* all parts of the function MUST be > 0 */
s *= float_64( s >= 0.0 );

return s;
}
};
}
}

namespace gasNone
{
/** Do not initialize a gas, stay with vacuum */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace picongpu
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasHomogenous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,37 @@ namespace picongpu

}

namespace gasFreeFormula
{
namespace SI
{
struct GasProfile
{
/** Normalized Gas Profile [0.0:1.0]
*
* This formula should use SI quantities only!
* The normalized profile will be multiplied by GAS_DENSITY.
*
* @param pos vector with offset to the global (left top front) cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_64 operator()( float3_64 pos )
{
const float_64 y = pos.y() * 1000.0; // m -> mm

/* triangle function example
* for a density profile from 0 to 400 microns */
float_64 s = 1.0 - 5.0 * math::abs( y - 0.2 );

/* all parts of the function MUST be > 0 */
s *= float_64( s >= 0.0 );

return s;
}
};
}
}

namespace gasNone
{
/** Do not initialize a gas, stay with vacuum */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace fieldSolver = PARAM_FIELDSOLVER;
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
#ifndef PARAM_GASPROFILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,37 @@ namespace picongpu

}

namespace gasFreeFormula
{
namespace SI
{
struct GasProfile
{
/** Normalized Gas Profile [0.0:1.0]
*
* This formula should use SI quantities only!
* The normalized profile will be multiplied by GAS_DENSITY.
*
* @param pos vector with offset to the global (left top front) cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_64 operator()( float3_64 pos )
{
const float_64 y = pos.y() * 1000.0; // m -> mm

/* triangle function example
* for a density profile from 0 to 400 microns */
float_64 s = 1.0 - 5.0 * math::abs( y - 0.2 );

/* all parts of the function MUST be > 0 */
s *= float_64( s >= 0.0 );

return s;
}
};
}
}

namespace gasNone
{
/** Do not initialize a gas, stay with vacuum */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace fieldSolver = fieldSolverNone;
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasNone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace fieldSolver = fieldSolverYee;
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasNone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace fieldSolver = fieldSolverNone;
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasNone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace fieldSolver = fieldSolverYee;
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasHomogenous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,37 @@ namespace picongpu

}

namespace gasFreeFormula
{
namespace SI
{
struct GasProfile
{
/** Normalized Gas Profile [0.0:1.0]
*
* This formula should use SI quantities only!
* The normalized profile will be multiplied by GAS_DENSITY.
*
* @param pos vector with offset to the global (left top front) cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_64 operator()( float3_64 pos )
{
const float_64 y = pos.y() * 1000.0; // m -> mm

/* triangle function example
* for a density profile from 0 to 400 microns */
float_64 s = 1.0 - 5.0 * math::abs( y - 0.2 );

/* all parts of the function MUST be > 0 */
s *= float_64( s >= 0.0 );

return s;
}
};
}
}

namespace gasNone
{
/** Do not initialize a gas, stay with vacuum */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace picongpu
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasHomogenous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,37 @@ namespace picongpu

}

namespace gasFreeFormula
{
namespace SI
{
struct GasProfile
{
/** Normalized Gas Profile [0.0:1.0]
*
* This formula should use SI quantities only!
* The normalized profile will be multiplied by GAS_DENSITY.
*
* @param pos vector with offset to the global (left top front) cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_64 operator()( float3_64 pos )
{
const float_64 y = pos.y() * 1000.0; // m -> mm

/* triangle function example
* for a density profile from 0 to 400 microns */
float_64 s = 1.0 - 5.0 * math::abs( y - 0.2 );

/* all parts of the function MUST be > 0 */
s *= float_64( s >= 0.0 );

return s;
}
};
}
}

namespace gasNone
{
/** Do not initialize a gas, stay with vacuum */
Expand Down
9 changes: 4 additions & 5 deletions src/picongpu/include/particles/ParticlesInit.kernel
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ using namespace PMacc;
template<unsigned int Dim>
DINLINE float_X calcRealDensity(const DataSpace<Dim>& offset, const DataSpace<Dim>& cellIdx)
{
float_X value = gasProfile::calcNormedDensitiy(
float3_X((cellIdx.x() + offset.x()) * CELL_WIDTH,
(cellIdx.y() + offset.y()) * CELL_HEIGHT,
(cellIdx.z() + offset.z()) * CELL_DEPTH))
* GAS_DENSITY;
float_X value = gasProfile::calcNormedDensitiy( float3_X((cellIdx.x() + offset.x()) * CELL_WIDTH,
(cellIdx.y() + offset.y()) * CELL_HEIGHT,
(cellIdx.z() + offset.z()) * CELL_DEPTH),
UNIT_LENGTH ) * GAS_DENSITY;
return value;
}

Expand Down
56 changes: 56 additions & 0 deletions src/picongpu/include/particles/gasProfiles/gasFreeFormula.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2013 Axel Huebl
*
* This file is part of PIConGPU.
*
* PIConGPU is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PIConGPU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PIConGPU.
* If not, see <http://www.gnu.org/licenses/>.
*/


#pragma once

#include "types.h"
#include "simulation_defines.hpp"

namespace picongpu
{
namespace gasFreeFormula
{

/** Calculate the gas density, divided by the maximum density GAS_DENSITY
Copy link
Member

Choose a reason for hiding this comment

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

should we call this GAS_DENSITY_MAX than?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like calling it "MAX" since it's a redundant information for a scalar value. one always speaks about the maximum density, when one is referring to density.
everything below that is given by the profile.

*
* @param pos as 3D length vector offset to global left top front cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_X calcNormedDensitiy( float3_X pos, float_64 _unit_length )
{
if (pos.y() < VACUUM_Y) return float_X(0.0);

const float3_64 pos_SI = typeCast<float_64>( pos ) * _unit_length;

/* expected return value of the profile: [0.0:1.0] */
SI::GasProfile gasProfile;
const float_64 density_dbl = gasProfile( pos_SI );

float_X density = typeCast<float_X>( density_dbl );

/* validate formula and clip to [0.0:1.0] */
density *= typeCast<float_X>( density >= 0.0 );
if( density > 1.0 ) density = 1.0;

return density;
}
}
}
2 changes: 1 addition & 1 deletion src/picongpu/include/particles/gasProfiles/gasGaussian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace picongpu
* @param pos as 3D length vector offset to global left top front cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_X calcNormedDensitiy( float3_X pos )
DINLINE float_X calcNormedDensitiy( float3_X pos, float_64 )
{
if (pos.y() < VACUUM_Y) return float_X(0.0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace picongpu
* @param y as distance in propagation direction (unit: meters / UNIT_LENGTH)
* @return float_X between 0.0 and 1.0
*/
DINLINE float_X calcNormedDensitiy( float3_X pos )
DINLINE float_X calcNormedDensitiy( float3_X pos, float_64 )
{
if (pos.y() < VACUUM_Y) return float_X(0.0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace picongpu
* @param pos as 3D length vector offset to global left top front cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_X calcNormedDensitiy( float3_X pos )
DINLINE float_X calcNormedDensitiy( float3_X pos, float_64 )
{
if (pos.y() < VACUUM_Y
|| pos.y() >= (GAS_LENGTH + VACUUM_Y)) return float_X(0.0);
Expand Down
2 changes: 1 addition & 1 deletion src/picongpu/include/particles/gasProfiles/gasLinExp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace picongpu
* @param pos as 3D length vector offset to global left top front cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_X calcNormedDensitiy( float3_X pos )
DINLINE float_X calcNormedDensitiy( float3_X pos, float_64 )
{
if (pos.y() < VACUUM_Y) return float_X(0.0);

Expand Down
2 changes: 1 addition & 1 deletion src/picongpu/include/particles/gasProfiles/gasNone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace picongpu
*
* @return float_X between 0.0 and 1.0
*/
DINLINE float_X calcNormedDensitiy( float3_X )
DINLINE float_X calcNormedDensitiy( float3_X pos, float_64 )
{

return float_X(0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace picongpu
* @param pos as 3D length vector offset to global left top front cell
* @return float_X between 0.0 and 1.0
*/
DINLINE float_X calcNormedDensitiy( float3_X pos )
DINLINE float_X calcNormedDensitiy( float3_X pos, float_64 )
{
if( pos.y() < VACUUM_Y ) return float_X(0.0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace fieldSolver = fieldSolverYee;
* - gasLinExp : piecewise linear-exponential profile (linear first)
* - gasHomogenous : constant gas density with a certain length
* - gasSphereFlanks : constant sphere droplet with exponential decr envelope
* - gasFreeFormula: use a custom formula (slower)
* - gasNone : just stay with a vacuum
*/
namespace gasProfile = gasNone;
Expand Down
Loading