Implementing Pressure Vessel Wall Sizing Calculations

Added by J. Simmons almost 9 years ago

This thread contains the reference material and discussions for a PBI from the Yavin Thruster Sprint 1 development work.

The chamber for the Yavin Thruster is modeled structurally as a thick walled pressure vessel as it must contain the cold gas at a pressure greater than the ambient environment. I implemented these calculations in my dissertation research according to material from:

Shigley, J. and Mischke, C., Mechanical Engineering Design, McGraw-Hill, fifth edition ed., 1989.

The attached PDF is the excerpt from my dissertation covering the related calculations (Section A.4.2). I will post the relevant source code in a reply below. Note, the dissertation includes a switch to compute the stress for pressure vessels under tension or under compression. We only need to worry about a pressure vessel under tension for Yavin as it is containing high pressure from within (versus withstanding high pressure from outside which would be a compression case).

The objective of this PBI is to replicate these calculations (without the complexity of switching between tension and compression) in a Python library, verifying and validating the new Python library in MTK, then using the Python library to drive CAD in CadQuery to render a model of a chamber.


Replies (16)

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by J. Simmons almost 9 years ago

Here is the source code (in JavaScript) for the thick walled cylinder wall sizing calculations. Note, I have removed some of the complexity shown in the documentation (for example the tension flag since we are not switching between tension and compression in the Yavin calculations) and I have not had a chance to test those changes, so it is very likely that there are some bugs in this code. Should make it good for testing.

// calculate chamber wall thickness
var ri;               // inner radius, needs a value assigned
var t;                // initial guess for thickness, needs value assigned
var P_c;              // chamber pressure, needs value assigned
var P_amb;            // ambient pressure, needs value assigned
var materialStrength; // target maximum allowable strength (for example yield or ultimate), needs value assigned
var fs;               // factor of safety

// call the calculate wall thickness function for our chamber conditions
var chamberThickness = calculateWallThickness(ri, ri + t, t, P_c, P_amb, materialStrength, fs);

// calculate wall thickness function, uses simple additive solver (may want to look into a smarter solver in new library)
function calculateWallThickness(ri, ro, t, Pi, Po, stressLimit, fs) {
  // initialize variables
  var r = 0.0;
  var stepSize = 0.001;
  if (tension == 1) {
    r = ri;
  }
  else {
    r = ro;
  }

  var maxStress = 0.0;
  maxStress = fs.value * Math.max(sigma_tan(ri, ro, r, Pi, Po), sigma_rad(ri, ro, r, Pi, Po)) / 1000;

  if (maxStress < stressLimit) {  
    while (maxStress < stressLimit) {
      t = t - stepSize;
      ro = ri + t;
      maxStress = fs * Math.max(sigma_tan(ri, ro, r, Pi, Po), sigma_rad(ri, ro, r, Pi, Po)) / 1000;
    }
  }
  else {
    while (maxStress > stressLimit) {
      t = t + stepSize;
      ro = ri + t;
      maxStress = fs * Math.max(sigma_tan(ri, ro, r, Pi, Po), sigma_rad(ri, ro, r, Pi, Po)) / 1000;
    }
  }

  return t;
}

// calculate the tangential stress in thick walled cylinder
function sigma_tan(ri, ro, r, Pi, Po) {
return (Pi*Math.pow(ri,2)-Po*Math.pow(ro,2)-Math.pow(ri,2)*Math.pow(ro,2)*(Po-Pi)/Math.pow(r,2))/(Math.pow(ro,2)-Math.pow(ri,2));
}

// calculate the radial stress in thick walled cylinder
function sigma_rad(ri, ro, r, Pi, Po) {
return (Pi*Math.pow(ri,2)-Po*Math.pow(ro,2)+Math.pow(ri,2)*Math.pow(ro,2)*(Po-Pi)/Math.pow(r,2))/(Math.pow(ro,2)-Math.pow(ri,2));
}

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

The Python port of the Javascript code above is in the repo: trunk/chamber/pressure_vessel_calcs.py

I have added TODO comments to denote questions or needed improvements.

To use this module, cd into the chamber directory, start a Python console, and enter the following.

>>> from pressure_vessel_calcs import PressureVessel
>>> pv = PressureVessel(10, 1, 100, 10, 800)
>>> pv.calculate_wall_thickness()
0.001999999999999119

The numbers I've used in the instantiation of the PressureVessel are pseudo-random.

Let the debugging and refactoring begin.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

I've roughed out a hello_world_chamber.py CadQuery model. The math for the inside radius of the taper is a little off, but it revolves the chamber as expected. The next steps will be to straighten the math for the inside of the taper out, clean the code up, and integrate Pint units. I also want to run through the code with the rocket scientists in the room to get the terminology in the code right.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

I was thinking this morning that it would be interesting to try to wrap a CadQuery solid so that it could hold things like material type, yield strength, BOM info, etc. It would be trivial after that to generate CSV output of a BOM, material data sheet, and so forth.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by J. Simmons almost 9 years ago

Finished the implementation section in the MTK document (current draft of PDF attached) and resolved code formatting block by upgrading local MTK install to use minted v2.0. Minted 2.0 has a linebreaks option.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

Thanks J. It should be pretty easy to reformat the code to give you cleaner line breaks without the line continuation symbol.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by J. Simmons almost 9 years ago

No problem. It seemed like a useful upgrade to MTK in general. Speaking of which, we should add installing minted 2.0 to the MTK Linux installer script. I will go post a feature request over in that project so we don't lose track of it.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

I think that we should get in the habit early on of implementing unit tests with libraries like this. That's going to become increasingly important as we scale this project, and other projects, up. We can't afford to break the library and have the widget make it all the way through manufacturing or (worst case) operations before we realize it. Even subtle errors can lead to mode 2 operation (boom) when dealing with rockets.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by J. Simmons almost 9 years ago

Agreed. In general, I would strongly urge us to demonstrate completed test results before going anywhere near manufacture, let alone test and operation.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

If you can give me some established inputs and outputs, I should be able to implement tests for what we've done on Yavin so far in about 15 or 20 minutes.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by J. Simmons almost 9 years ago

The source code for the MTK document includes all of inputs and the expected outputs for ten test cases (including units). There are the nine test cases from my dissertation plus the inputs for the hello world design point (its output is known to be 3.8 mm). The test cases are declared in a sagesilent block so the repetitive code doesn't take up space in the report.

We should figure out a way to put the unit tests into the MTK document to drive the test results table in Section 4 so we don't have the tests multiply defined.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

I've stubbed in a unit test structure, and added a few test cases for the pressure vessel calculations. The test cases came directly out of the Sage source code.

https://opendesignengine.net/projects/yavin-thruster/repository/show/trunk/chamber

The main source file of interest will be chamber/tests/test_math.py. I haven't added a readme yet, but the current set of tests can be run by changing into the chamber directory and running:

python runtests.py

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by J. Simmons almost 9 years ago

Added an abstract to the MTK report for PressureVessel class per YVN-09. See attached PDF for updated report.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by J. Simmons almost 9 years ago

Glad you like and thanks for reviewing it so quickly.

RE: Implementing Pressure Vessel Wall Sizing Calculations - Added by Jeremy Wright almost 9 years ago

One question that just occurred to me. Should "class" be defined for the layreader, or should it be implicitly understood since it's an MTK document?

(1-16/16)