Thursday, November 26, 2015

Leak protection system prototype

Leak protection system prototype:

I built my first version of my leak protection system with arduino. When a leak is detected, it will ultimately shut off the water to the house.


Monday, August 17, 2015

Arduino controlled yogurt incubator

I finally completed my first project that is somewhat useful. I made a yogurt incubator by controlling the temperature in the oven with a heating element (in this case a worklight).

Yogurt incubator setup. Arduino chip is on bottom right, thermocouple reader is on top right,
relay is on bottom left and outlet controlled by relay is on top left

Here is a plot of the temperature as a function of time. The arduino is programmed to maintain a temperature of 110 +/- 4.5 degrees F.



Here's a video showing the relay turning on the light when the temperature dropped too low.



Monday, July 20, 2015

How to install CalculiX binaries cgx and ccx for Ubuntu 15.04

Install CalculiX binaries cgx and ccx for Ubuntu 15.04 (Incomplete)

 
uncompress files
bunzip2 cgx_2.8.bz2
move file
sudo mv cgx_2.8  /usr/local/bin/cgx
change permission

chmod ao+rx /usr/local/bin/cgx

Here I need to add modified steps from these two links.


Helpful links where I got my info.
http://www.dhondt.de/ccx_2.8.README.INSTALL
http://www.libremechanics.com/?q=node/9

https://launchpad.net/~freecad-maintainers/+archive/ubuntu/freecad-daily

Friday, July 17, 2015

Power law velocity profile given average velocity with groovyBC or swak4FOAM

Power law velocity profile given average velocity with groovyBC or swak4FOAM for use in OpenFOAM


circular pipe aligned in the x-dir

   inlet
    {

    type    groovyBC;
      value   uniform (1 0 0);
      variables (
        "Uavg=1;"

        "r=sqrt(pos().y*pos().y+pos().z*pos().z);"
        "R=(max(pts().y)-min(pts().y))/2;"
        "Re=Uavg*R*2/nu;"
        "n=-1.7+1.8*log10(Re);"
        "Uc=Uavg*(n+1)*(2*n+1)/(2*pow(n,2));"
        );
      valueExpression "-Uc*pow((1-r/R),1/n)*normal()";
}

in controlDict

libs (
    "libsimpleFunctionObjects.so"
    "libsimpleSwakFunctionObjects.so"      
    "libswakFunctionObjects.so"
    "libgroovyBC.so"
);


see https://openfoamwiki.net/index.php/Contrib/groovyBC#Download

Wednesday, July 15, 2015

Arduino with relay to control fan


Calculate inlet conditions for k-epsilon

How to estimate k and epsilon for inlet

k=1.5*(I*U)^2
where I is turbulence intensity and U is velocity, k is turbulent kinetic energy

epsilon=C_mu^0.75*k^1.5/L
where C_mu=0.09, epsilon is dissipation rate, L is the mixing length

for OpenFOAM easy conditions to specify are

turbulentIntensityKineticEnergyInlet for k

inlet
    {
        type            turbulentIntensityKineticEnergyInlet;
        intensity            0.05 ;
        value           uniform .05; //dummy value
    }

turbulentMixingLengthDissipationRateInlet for epsilon

  inlet
    {
        type            turbulentMixingLengthDissipationRateInlet;
        mixingLength            0.01; //m
        value          uniform 0.01; // dummy
    }

see description by ESI
or https://en.wikipedia.org/wiki/Turbulence_kinetic_energy
http://www.cfd-online.com/Wiki/Turbulence_free-stream_boundary_conditions

Friday, July 10, 2015

How to use topoSet to generate a circular inlet patch with OpenFOAM

Allrun script


#!/bin/sh
cd ${0%/*} || exit 1    # run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

   rm log.*
   rm 0 -r
   cp 0.org 0 -r
    # And execute
    runApplication blockMesh
 
    runApplication topoSet
    runApplication createPatch -overwrite
  
    runApplication decomposePar -force
    runParallel `getApplication` 4
    runApplication reconstructPar

# ----------------------------------------------------------------- end-of-file


topoSetDict


/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.1                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      topoSetDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

actions
(
    {
        name    jetCells;
        type    cellSet;
        action  new;
         source cylinderToCell;
    sourceInfo
    {
       p1       (0 0 0); // start point on cylinder axis
       p2       (0 .051 0);   // end point on cylinder axis
       radius   .008;
    }


    }

{
        name    f0;
        type    faceSet;
        action  new;
        source  cellToFace;
        sourceInfo
        {
            set     jetCells;
            option  all;
        }
    }

{
        name    f0;
        type    faceSet;
        action  subset;
      source boxToFace;
     sourceInfo
     {
        box  (-.1 0.024 -.1) (.1 .026 .1);
       //boxes   ((0 0 0) (1 1 1) (10 10 10)(11 11 11));
     }
}
);

// ************************************************************************* //


createPatchDict


/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.1                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      createPatchDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// This application/dictionary controls:
// - optional: create new patches from boundary faces (either given as
//   a set of patches or as a faceSet)
// - always: order faces on coupled patches such that they are opposite. This
//   is done for all coupled faces, not just for any patches created.
// - optional: synchronise points on coupled patches.

// 1. Create cyclic:
// - specify where the faces should come from
// - specify the type of cyclic. If a rotational specify the rotationAxis
//   and centre to make matching easier
// - always create both halves in one invocation with correct 'neighbourPatch'
//   setting.
// - optionally pointSync true to guarantee points to line up.

// 2. Correct incorrect cyclic:
// This will usually fail upon loading:
//  "face 0 area does not match neighbour 2 by 0.0100005%"
//  " -- possible face ordering problem."
// - in polyMesh/boundary file:
//      - loosen matchTolerance of all cyclics to get case to load
//      - or change patch type from 'cyclic' to 'patch'
//        and regenerate cyclic as above


// Do a synchronisation of coupled points after creation of any patches.
// Note: this does not work with points that are on multiple coupled patches
//       with transformations (i.e. cyclics).
pointSync false;

// Patches to create.
patches
(
    {
        // Name of new patch
        name inlet;

        // Type of new patch
        patchInfo
        {
            type patch;
        }

        // How to construct: either from 'patches' or 'set'
        constructFrom set;

        // If constructFrom = patches : names of patches. Wildcards allowed.
        patches ("periodic.*");

        // If constructFrom = set : name of faceSet
        set f0;
    }
);

// ************************************************************************* //

How to automate renaming of STL patches without Salome using only OpenFOAM surface utilities and a script

This describes how to automate naming of patches of the stl file without using Salome or other software but with native OpenFOAM tools and a bash script. This is for use with cfMesh but a similar approach could be used with snappyHexMesh.

Allmesh Script

#!/bin/sh
cd ${0%/*} || exit 1    # run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions


rm log.*
rm -r input
rm -r output
mkdir input
mkdir output

# split stl into inlet and walls
runApplication surfaceSubset system/surfaceSubsetDictInlet constant/triSurface/input.stl input/inlet.stl

mv log.surfaceSubset log.surfaceSubsetInlet

runApplication surfaceSubset system/surfaceSubsetDictRInlet constant/triSurface/input.stl input/walls.stl

mv log.surfaceSubset log.surfaceSubsetInletR

# split walls into outlet and walls
runApplication surfaceSubset system/surfaceSubsetDictOutlet input/walls.stl input/outlet.stl

mv log.surfaceSubset log.surfaceSubsetInletROutlet

runApplication surfaceSubset system/surfaceSubsetDictROutlet input/walls.stl input/walls.stl

mv log.surfaceSubset log.surfaceSubsetInletROutletR

# combine files
../../scripts/./stlCombine input output

#generate fms file with edges but retaining patches
runApplication surfaceFeatureEdges output/mergedStl.stl output/elbow.fms -angle 45

#generate mesh
runApplication cartesianMesh

#change definitions of patches
runApplication changeDictionary

surfaceSubsetDictInlet file

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.4.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      surfaceSubsetDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Select triangles by label
faces ();//#include "badFaces";

// Select triangles using given points (local point numbering)
localPoints ( );

// Select triangles using given edges
edges ();

// Select triangles (with face centre) inside box
zone
(
    (.507  .25  -.101)
    (.509 .36 .101)
);

// Select triangles (with face centre) inside or outside of another surface.
// (always selects triangles that are 'on' other surface)
/*
surface
{
    name "sphere.stl";
    outside     yes;
}

// Select triangles on plane
plane
{
    planeType embeddedPoints;
    embeddedPointsDict
    {
        //point1 (-937.259845440205 160.865349115986 240.738791238078);
        //point2 (-934.767379895778 9.63875523747379 14.412359671298);
        //point3 (44.4744688899417 121.852927962709 182.352485273106);
        point1 (-957.895294591874 242.865936478961 162.286611511875);
        point2 (-961.43140327772 4.53895551562943 3.04159982093444);
        point3 (91.2414146173805 72.1504381996692 48.2181961945329);
    }

    // Distance from plane
    distance 0.1;
    // Normal difference to plane
    cosAngle 0.99;
}
*/

// Extend selection with edge neighbours
addFaceNeighbours no;

// Invert selection
invertSelection false;

// ************************************************************************* //

surfaceSubsetDictInletR  change  invertSelection true;

surfaceSubsetDictOutlet  change coordinates of 

box;surfaceSubsetDictOutletR  change  invertSelection true;


stlCombine code from Kruno at

https://openfoamwiki.net/index.php/Thread:Talk:Sig_Numerical_Optimization/Salome_and_cfMesh_parametrization

meshDict for cfMesh


/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                |
| \\      /  F ield         | cfMesh: A library for mesh generation          |
|  \\    /   O peration     |                                                |
|   \\  /    A nd           | Author: Franjo Juretic                         |
|    \\/     M anipulation  | E-mail: franjo.juretic@c-fields.com            |
\*---------------------------------------------------------------------------*/

FoamFile
{
    version   2.0;
    format    ascii;
    class     dictionary;
    location  "system";
    object    meshDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

surfaceFile "output/elbow.fms";

maxCellSize .05;

boundaryCellSize .0049;

minCellSize .0049;

localRefinement
{
    walls
    {
        cellSize 0.0025;
    }
}


boundaryLayers
{
    nLayers 1;

    thicknessRatio 1.1;

    maxFirstLayerThickness 0.003;

    patchBoundaryLayers
    {
      "walls.*"
        {
            nLayers           3;

            thicknessRatio    1.2;

            maxFirstLayerThickness .005;

            allowDiscontinuity 0;
        }

    }
}



/*
renameBoundary
{
    defaultName        junk;
    defaultType        wall;

    newPatchNames
    {
        "inl.*"
        {
            newName     testo;
            newType     patch;
        }

    }
}*/
              
    
// ************************************************************************* //


changeDictionaryDict


/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      changeDictionaryDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dictionaryReplacement
{
    boundary
    {
        "inlet"
        {
            type            patch;
        }
        "outlet"
        {
            type            patch;
        }
        "walls"
        {
                name                 walls;
            type            wall;
          
        }
    }

}

// ************************************************************************* //

Wednesday, July 8, 2015