// Make patch weighting factors
void Foam::mixingPlaneFvPatch::makeWeights(scalarField& w) const
{
    // Calculation of weighting factors is performed from the master
    // position, using reconstructed shadow cell centres
    if (mixingPlanePolyPatch_.master())
    {
        vectorField n = nf();

        // Note: mag in the dot-product.
        // For all valid meshes, the non-orthogonality will be less that
        // 90 deg and the dot-product will be positive.  For invalid
        // meshes (d & s <= 0), this will stabilise the calculation
        // but the result will be poor.  HJ, 24/Aug/2011
        scalarField nfc =
            mag(n & (mixingPlanePolyPatch_.reconFaceCellCentres() - Cf()));

        w = nfc/(mag(n & (Cf() - Cn())) + nfc);
    }
    else
    {
        // Pick up weights from the master side
        scalarField masterWeights(shadow().size());
        shadow().makeWeights(masterWeights);

        scalarField oneMinusW = 1 - masterWeights;

        w = interpolate(oneMinusW);
    }
}
// Return delta (P to N) vectors across coupled patch
Foam::tmp<Foam::vectorField> Foam::cyclicGgiFvPatch::delta() const
{
    if (cyclicGgiPolyPatch_.master())
    {
        tmp<vectorField> tDelta =
            cyclicGgiPolyPatch_.reconFaceCellCentres() - Cn();

        if (bridgeOverlap())
        {
            vectorField bridgeDeltas = Cf() - Cn();

            bridge(bridgeDeltas, tDelta());
        }

        return tDelta;
    }
    else
    {
        tmp<vectorField> tDelta = interpolate
        (
            shadow().Cn() - cyclicGgiPolyPatch_.shadow().reconFaceCellCentres()
        );

        if (bridgeOverlap())
        {
            vectorField bridgeDeltas = Cf() - Cn();

            bridge(bridgeDeltas, tDelta());
        }

        return tDelta;
    }
}
// Make patch weighting factors
void Foam::regionCoupleFvPatch::makeWeights(scalarField& w) const
{
    if (rcPolyPatch_.coupled())
    {
        if (rcPolyPatch_.master())
        {
            vectorField n = nf();

            // Note: mag in the dot-product.
            // For all valid meshes, the non-orthogonality will be less than
            // 90 deg and the dot-product will be positive.  For invalid
            // meshes (d & s <= 0), this will stabilise the calculation
            // but the result will be poor.  HJ, 24/Aug/2011
            scalarField nfc =
                mag(n & (rcPolyPatch_.reconFaceCellCentres() - Cf()));

            w = nfc/(mag(n & (Cf() - Cn())) + nfc);

            if (bridgeOverlap())
            {
                // Set overlap weights to 0.5 and use mirrored neighbour field
                // for interpolation.  HJ, 21/Jan/2009
                bridge(scalarField(size(), 0.5), w);
            }
        }
        else
        {
            // Pick up weights from the master side
            scalarField masterWeights(shadow().size());
            shadow().makeWeights(masterWeights);

            scalarField oneMinusW = 1 - masterWeights;

            w = interpolate(oneMinusW);

            if (bridgeOverlap())
            {
                // Set overlap weights to 0.5 and use mirrored neighbour field
                // for interpolation.  HJ, 21/Jan/2009
                bridge(scalarField(size(), 0.5), w);
            }
        }
    }
    else
    {
        fvPatch::makeWeights(w);
    }
}
Beispiel #4
0
void Foam::fvMesh::updateGeomNotOldVol()
{
    bool haveV = (VPtr_ != NULL);
    bool haveSf = (SfPtr_ != NULL);
    bool haveMagSf = (magSfPtr_ != NULL);
    bool haveCP = (CPtr_ != NULL);
    bool haveCf = (CfPtr_ != NULL);

    clearGeomNotOldVol();

    // Now recreate the fields
    if (haveV)
    {
        (void)V();
    }
    if (haveSf)
    {
        (void)Sf();
    }
    if (haveMagSf)
    {
        (void)magSf();
    }
    if (haveCP)
    {
        (void)C();
    }
    if (haveCf)
    {
        (void)Cf();
    }
}
int main(int argc, char** argv)
{
    std::vector<std::string> args(argv + 1, argv + argc);
    std::string filename;
    bool preserve_zeros = false;

    for (size_t i = 0; i < args.size(); ++i) {
        if (args[i] == "-z") {
            preserve_zeros = true;
        } else {
            filename = args[i];
        }
    }
    
    if (!filename.size()) std::terminate();

    boost::iostreams::mapped_file_source m(filename);

    std::vector<repair::code_type> C;
    std::vector<std::string> D;
    repair::approximate_repair(std::make_pair(m.data(), m.data() + m.size()), C, D, preserve_zeros);
    
    std::ofstream Df((filename + ".D").c_str(), std::ios::binary);
    std::ofstream Cf((filename + ".C").c_str(), std::ios::binary);
    for (size_t i = 0; i < D.size(); ++i) {
        uint32_t l = uint32_t(D[i].size());
        Df.write(reinterpret_cast<const char*>(&l), 4);
        Df.write(&(D[i])[0], l);
    }

    Cf.write(reinterpret_cast<const char*>(&C[0]), C.size() * sizeof(repair::code_type));
}
const Matrix &
AC3D8HexWithSensitivity::getDamp(void)
{
  C.Zero();
  if (impVals == 0) {
    return C;
  }
  
  int i, nodes_in_face = 8;
  ID face_nodes(nodes_in_face);
  Matrix Cf(nodes_in_face, nodes_in_face);
  
  for(i = 1; i <= 6; i++) {
    if(impVals[i-1] != 0.0) {
      Cf = get_face_impedance(i);
      localFaceMapping(i, face_nodes);
      
      if(impVals[i-1] != 1.0) {
        Cf = Cf*impVals[i-1];
      }
      
      C.Assemble(Cf, face_nodes, face_nodes);
    }
  }
  
  return C;
}
// Make patch weighting factors
void Foam::cyclicGgiFvPatch::makeWeights(scalarField& w) const
{
    // Calculation of weighting factors is performed from the master
    // position, using reconstructed shadow cell centres
    // HJ, 2/Aug/2007
    if (cyclicGgiPolyPatch_.master())
    {
        vectorField n = nf();

        // Note: mag in the dot-product.
        // For all valid meshes, the non-orthogonality will be less that
        // 90 deg and the dot-product will be positive.  For invalid
        // meshes (d & s <= 0), this will stabilise the calculation
        // but the result will be poor.  HJ, 24/Aug/2011
        scalarField nfc =
            mag
            (
                n & (cyclicGgiPolyPatch_.reconFaceCellCentres() - Cf())
            );

        w = nfc/(mag(n & (Cf() - Cn())) + nfc);

        if (bridgeOverlap())
        {
            // Set overlap weights to 0.5 and use mirrored neighbour field
            // for interpolation.  HJ, 21/Jan/2009
            bridge(scalarField(size(), 0.5), w);
        }
    }
    else
    {
        // Pick up weights from the master side
        scalarField masterWeights(shadow().size());
        shadow().makeWeights(masterWeights);

        w = interpolate(1 - masterWeights);

        if (bridgeOverlap())
        {
            // Set overlap weights to 0.5 and use mirrored neighbour field
            // for interpolation.  HJ, 21/Jan/2009
            bridge(scalarField(size(), 0.5), w);
        }
    }
}
// Return delta (P to N) vectors across coupled patch
Foam::tmp<Foam::vectorField> Foam::regionCoupleFvPatch::delta() const
{
    if (rcPolyPatch_.coupled())
    {
        if (rcPolyPatch_.master())
        {
            tmp<vectorField> tDelta =
                rcPolyPatch_.reconFaceCellCentres() - Cn();

            if (bridgeOverlap())
            {
                vectorField bridgeDeltas = Cf() - Cn();

                bridge(bridgeDeltas, tDelta());
            }

            return tDelta;
        }
        else
        {
            tmp<vectorField> tDelta = interpolate
            (
                shadow().Cn() - rcPolyPatch_.shadow().reconFaceCellCentres()
            );

            if (bridgeOverlap())
            {
                vectorField bridgeDeltas = Cf() - Cn();

                bridge(bridgeDeltas, tDelta());
            }

            return tDelta;
        }
    }
    else
    {
        return fvPatch::delta();
    }
}
Beispiel #9
0
void LaserBeam::preRender(){
	int timelived = Video::ElapsedTime() - fireTime;
	if(timelived >= ttl){
		done = true;
		return;
	}
	MaterialHandle lm;
	if(timelived < 0.33*ttl){
		//Fade in
		float alpha = ((1.0/ttl)/0.33)*timelived;
		lm = TwinMaterial(LineMaterial(1),
				ShadedMaterial(Cf(0.2,0.8,0.2,alpha), //Ambient
							   Cf(0.2,0.8,0.2,alpha), //Diffuse
							   Cf(0.2,0.8,0.2,alpha), //Specular
							   Cf(0.8,1,0,alpha),     //Emissive
							   100.0));           //Shininess
	}else if(timelived < 0.66*ttl){
		lm = TwinMaterial(LineMaterial(2),
				ShadedMaterial(Cf(0.2,0.8,0.2,1), //Ambient
							   Cf(0.2,0.8,0.2,1), //Diffuse
							   Cf(0.2,0.8,0.2,1), //Specular
							   Cf(0.8,1,0,1),     //Emissive
							   100.0));           //Shininess
	}else{
		//Fade out
		float alpha = ((-1*(1.0/ttl)/0.33)*timelived + 3);
		lm = TwinMaterial(LineMaterial(1),
				ShadedMaterial(Cf(0.2,0.8,0.2,alpha), //Ambient
							   Cf(0.2,0.8,0.2,alpha), //Diffuse
							   Cf(0.2,0.8,0.2,alpha), //Specular
							   Cf(0.8,1,0,alpha),     //Emissive
							   100.0));           //Shininess
	}

	material = lm;

	Object::preRender();
}
Matrix 
AC3D8HexWithSensitivity::get_face_impedance(int face_num)
{
  double r  = 0.0;
  double rw = 0.0;
  double s  = 0.0;
  double sw = 0.0;

  double weight;
  double RHO, Kf, cs;
  double x1,y1,z1,area;
  
  int nodes_in_face = 8;
  Matrix Cf(nodes_in_face, nodes_in_face);
  Matrix Jacobian(2,3);
  Matrix dh(2,nodes_in_face);
  Matrix h(1,nodes_in_face);
  
  Matrix N_coord = getFaceNodalCoords(face_num);
  
  // Get mass density of fluid
  RHO = theMaterial[0]->getRho();
  if(RHO == 0.0){
    opserr << "ERROR: The mass density is zero!\n";
    exit(-1);
  }
  Kf = (theMaterial[0]->getTangent())(0,0);
  cs = sqrt(Kf/RHO);
  
  // zero matrix first
  Cf.Zero();
  
  for(short GP_c_r = 1; GP_c_r <= r_integration_order; GP_c_r++) {
    r = get_Gauss_p_c(r_integration_order, GP_c_r);
    rw = get_Gauss_p_w(r_integration_order, GP_c_r);
    for(short GP_c_s = 1; GP_c_s <= s_integration_order; GP_c_s++) {
      s = get_Gauss_p_c(s_integration_order, GP_c_s);
      sw = get_Gauss_p_w(s_integration_order, GP_c_s);
      
      dh = diff_interp_fun_face(r, s);
      Jacobian = dh*N_coord;
      
      // pointer to the fluid
      x1 = Jacobian(0,1)*Jacobian(1,2) - Jacobian(0,2)*Jacobian(1,1);
      y1 = Jacobian(0,2)*Jacobian(1,0) - Jacobian(0,0)*Jacobian(1,2);
      z1 = Jacobian(0,0)*Jacobian(1,1) - Jacobian(0,1)*Jacobian(1,0);
      
      // length of the bar tangent
      area = sqrt(x1*x1 + y1*y1 + z1*z1);
      if(area == 0.0){
        opserr <<"The length of tangent should not be 0!\n";
        exit(-1);
      }
      
      h = interp_fun_face(r, s);
      weight = rw * sw* area / RHO /cs;
      Cf.addMatrixTransposeProduct(1.0, h, h, weight);
    }
  }
  
  return Cf;
}
Beispiel #11
0
Foam::tmp<Foam::vectorField> Foam::wedgeFvPatch::delta() const
{
    const vectorField nHat(nf());
    return nHat*(nHat & (Cf() - Cn()));
}