Example #1
0
void
MultiPlasticityDebugger::fddyieldFunction_dintnl(const RankTwoTensor & stress, const std::vector<Real> & intnl, std::vector<Real> & df_dintnl)
{
  df_dintnl.resize(_num_surfaces);

  std::vector<bool> act;
  act.assign(_num_surfaces, true);

  std::vector<Real> origf;
  yieldFunction(stress, intnl, act, origf);

  std::vector<Real> intnlep;
  intnlep.resize(_num_models);
  for (unsigned model = 0; model < _num_models; ++model)
    intnlep[model] = intnl[model];
  Real ep;
  std::vector<Real> fep;
  unsigned int model;
  for (unsigned surface = 0; surface < _num_surfaces; ++surface)
  {
    model = modelNumber(surface);
    ep = _fspb_debug_intnl_change[model];
    intnlep[model] += ep;
    yieldFunction(stress, intnlep, act, fep);
    df_dintnl[surface] = (fep[surface] - origf[surface])/ep;
    intnlep[model] -= ep;
  }
}
void
MultiPlasticityDebugger::fddflowPotential_dintnl(const RankTwoTensor & stress, const std::vector<Real> & intnl, std::vector<RankTwoTensor> & dr_dintnl)
{
  dr_dintnl.resize(_num_surfaces);

  std::vector<bool> act;
  act.assign(_num_surfaces, true);

  std::vector<RankTwoTensor> origr;
  flowPotential(stress, intnl, act, origr);

  std::vector<Real> intnlep;
  intnlep.resize(_num_models);
  for (unsigned model = 0; model < _num_models; ++model)
    intnlep[model] = intnl[model];
  Real ep;
  std::vector<RankTwoTensor> rep;
  unsigned int model;
  for (unsigned surface = 0; surface < _num_surfaces; ++surface)
  {
    model = modelNumber(surface);
    ep = _fspb_debug_intnl_change[model];
    intnlep[model] += ep;
    flowPotential(stress, intnlep, act, rep);
    dr_dintnl[surface] = (rep[surface] - origr[surface])/ep;
    intnlep[model] -= ep;
  }
}
void
MultiPlasticityLinearSystem::calculateJacobian(const RankTwoTensor & stress, const std::vector<Real> & intnl, const std::vector<Real> & pm, const RankFourTensor & E_inv, const std::vector<bool> & active, const std::vector<bool> & deactivated_due_to_ld, std::vector<std::vector<Real> > & jac)
{
  // see comments at the start of .h file

  mooseAssert(intnl.size() == _num_models, "Size of intnl is " << intnl.size() << " which is incorrect in calculateJacobian");
  mooseAssert(pm.size() == _num_surfaces, "Size of pm is " << pm.size() << " which is incorrect in calculateJacobian");
  mooseAssert(active.size() == _num_surfaces, "Size of active is " << active.size() << " which is incorrect in calculateJacobian");
  mooseAssert(deactivated_due_to_ld.size() == _num_surfaces, "Size of deactivated_due_to_ld is " << deactivated_due_to_ld.size() << " which is incorrect in calculateJacobian");


  unsigned ind = 0;
  unsigned active_surface_ind = 0;


  std::vector<bool> active_surface(_num_surfaces); // active and not deactivated_due_to_ld
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
    active_surface[surface] = (active[surface] && !deactivated_due_to_ld[surface]);
  unsigned num_active_surface = 0;
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
    if (active_surface[surface])
      num_active_surface++;

  std::vector<bool> active_model(_num_models); // whether a model has surfaces that are active and not deactivated_due_to_ld
  for (unsigned model = 0 ; model < _num_models ; ++model)
    active_model[model] = anyActiveSurfaces(model, active_surface);

  unsigned num_active_model = 0;
  for (unsigned model = 0 ; model < _num_models ; ++model)
    if (active_model[model])
      num_active_model++;

  ind = 0;
  std::vector<unsigned int> active_model_index(_num_models);
  for (unsigned model = 0 ; model < _num_models ; ++model)
    if (active_model[model])
      active_model_index[model] = ind++;
    else
      active_model_index[model] = _num_models+1; // just a dummy, that will probably cause a crash if something goes wrong



  std::vector<RankTwoTensor> df_dstress;
  dyieldFunction_dstress(stress, intnl, active_surface, df_dstress);

  std::vector<Real> df_dintnl;
  dyieldFunction_dintnl(stress, intnl, active_surface, df_dintnl);

  std::vector<RankTwoTensor> r;
  flowPotential(stress, intnl, active, r);

  std::vector<RankFourTensor> dr_dstress;
  dflowPotential_dstress(stress, intnl, active, dr_dstress);

  std::vector<RankTwoTensor> dr_dintnl;
  dflowPotential_dintnl(stress, intnl, active, dr_dintnl);

  std::vector<Real> h;
  hardPotential(stress, intnl, active, h);

  std::vector<RankTwoTensor> dh_dstress;
  dhardPotential_dstress(stress, intnl, active, dh_dstress);

  std::vector<Real> dh_dintnl;
  dhardPotential_dintnl(stress, intnl, active, dh_dintnl);




  // d(epp)/dstress = sum_{active alpha} pm[alpha]*dr_dstress
  RankFourTensor depp_dstress;
  ind = 0;
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
    if (active[surface]) // includes deactivated_due_to_ld
      depp_dstress += pm[surface]*dr_dstress[ind++];
  depp_dstress += E_inv;

  // d(epp)/dpm_{active_surface_index} = r_{active_surface_index}
  std::vector<RankTwoTensor> depp_dpm;
  depp_dpm.resize(num_active_surface);
  ind = 0;
  active_surface_ind = 0;
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
  {
    if (active[surface])
    {
      if (active_surface[surface]) // do not include the deactived_due_to_ld, since their pm are not dofs in the NR
        depp_dpm[active_surface_ind++] = r[ind];
      ind++;
    }
  }

  // d(epp)/dintnl_{active_model_index} = sum(pm[asdf]*dr_dintnl[fdsa])
  std::vector<RankTwoTensor> depp_dintnl;
  depp_dintnl.assign(num_active_model, RankTwoTensor());
  ind = 0;
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
  {
    if (active[surface])
    {
      unsigned int model_num = modelNumber(surface);
      if (active_model[model_num]) // only include models with surfaces which are still active after deactivated_due_to_ld
        depp_dintnl[active_model_index[model_num]] += pm[surface]*dr_dintnl[ind];
      ind++;
    }
  }


  // df_dstress has been calculated above
  // df_dpm is always zero
  // df_dintnl has been calculated above, but only the active_surface+active_model stuff needs to be included in Jacobian: see below

  std::vector<RankTwoTensor> dic_dstress;
  dic_dstress.assign(num_active_model, RankTwoTensor());
  ind = 0;
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
  {
    if (active[surface])
    {
      unsigned int model_num = modelNumber(surface);
      if (active_model[model_num]) // only include ic for models with active_surface (ie, if model only contains deactivated_due_to_ld don't include it)
        dic_dstress[active_model_index[model_num]] += pm[surface]*dh_dstress[ind];
      ind++;
    }
  }


  std::vector<std::vector<Real> > dic_dpm;
  dic_dpm.resize(num_active_model);
  ind = 0;
  active_surface_ind = 0;
  for (unsigned model = 0 ; model < num_active_model ; ++model)
    dic_dpm[model].assign(num_active_surface, 0);
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
  {
    if (active[surface])
    {
      if (active_surface[surface]) // only take derivs wrt active-but-not-deactivated_due_to_ld pm
      {
        unsigned int model_num = modelNumber(surface);
        // if (active_model[model_num]) // do not need this check as if the surface has active_surface, the model must be deemed active!
          dic_dpm[active_model_index[model_num]][active_surface_ind] = h[ind];
        active_surface_ind++;
      }
      ind++;
    }
  }


  std::vector<std::vector<Real> > dic_dintnl;
  dic_dintnl.resize(num_active_model);
  for (unsigned model = 0 ; model < num_active_model ; ++model)
  {
    dic_dintnl[model].assign(num_active_model, 0);
    dic_dintnl[model][model] = 1; // deriv wrt internal parameter
  }
  ind = 0;
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
  {
    if (active[surface])
    {
      unsigned int model_num = modelNumber(surface);
      if (active_model[model_num]) // only the models that contain surfaces that are still active after deactivation_due_to_ld
        dic_dintnl[active_model_index[model_num]][active_model_index[model_num]] += pm[surface]*dh_dintnl[ind];
      ind++;
    }
  }



  unsigned int dim = 3;
  unsigned int system_size = 6 + num_active_surface + num_active_model; // "6" comes from symmeterizing epp
  jac.resize(system_size);
  for (unsigned i = 0 ; i < system_size ; ++i)
    jac[i].assign(system_size, 0);

  unsigned int row_num = 0;
  unsigned int col_num = 0;
  for (unsigned i = 0 ; i < dim ; ++i)
    for (unsigned j = 0 ; j <= i ; ++j)
    {
      for (unsigned k = 0 ; k < dim ; ++k)
        for (unsigned l = 0 ; l <= k ; ++l)
          jac[col_num][row_num++] = depp_dstress(i, j, k, l) + (k != l ? depp_dstress(i, j, l, k) : 0); // extra part is needed because i assume dstress(i, j) = dstress(j, i)
      for (unsigned surface = 0 ; surface < num_active_surface ; ++surface)
        jac[col_num][row_num++] = depp_dpm[surface](i, j);
      for (unsigned a = 0 ; a < num_active_model ; ++a)
        jac[col_num][row_num++] = depp_dintnl[a](i, j);
      row_num = 0;
      col_num++;
    }

  ind = 0;
  for (unsigned surface = 0 ; surface < _num_surfaces ; ++surface)
    if (active_surface[surface])
    {
      for (unsigned k = 0 ; k < dim ; ++k)
        for (unsigned l = 0 ; l <= k ; ++l)
        jac[col_num][row_num++] = df_dstress[ind](k, l) + (k != l ? df_dstress[ind](l, k) : 0); // extra part is needed because i assume dstress(i, j) = dstress(j, i)
      for (unsigned beta = 0 ; beta < num_active_surface ; ++beta)
        jac[col_num][row_num++] = 0; // df_dpm
      for (unsigned model = 0 ; model < _num_models ; ++model)
        if (active_model[model]) // only use df_dintnl for models in active_model
        {
          if (modelNumber(surface) == model)
            jac[col_num][row_num++] = df_dintnl[ind];
          else
            jac[col_num][row_num++] = 0;
        }
      ind++;
      row_num = 0;
      col_num++;
    }

  for (unsigned a = 0 ; a < num_active_model ; ++a)
  {
    for (unsigned k = 0 ; k < dim ; ++k)
      for (unsigned l = 0 ; l <= k ; ++l)
        jac[col_num][row_num++] = dic_dstress[a](k, l) + (k != l ? dic_dstress[a](l, k) : 0); // extra part is needed because i assume dstress(i, j) = dstress(j, i)
    for (unsigned alpha = 0 ; alpha < num_active_surface ; ++alpha)
      jac[col_num][row_num++] = dic_dpm[a][alpha];
    for (unsigned b = 0 ; b < num_active_model ; ++b)
      jac[col_num][row_num++] = dic_dintnl[a][b];
    row_num = 0;
    col_num++;
  }

  mooseAssert(col_num == system_size, "Incorrect filling of cols in Jacobian");
}
Example #4
0
int main(int argc, char** argv)
{
	int x,y,z;
	std::string serial("");
	std::string desc("");
	std::string info = "";
	std::string modelNumber("");
	char filename[256];
	const char *dir = "/tmp";
	const char	*extension = "tiff";
	bool canSetTemp;
	bool hasFilters;
	short binX;
	short binY;
	long xsize;
	long ysize;
	long startX;
	long startY;
	int iNumFound;
	bool	tiffoutput = false;
	bool	fitsoutput = false;

	int	c;
	while (EOF != (c = getopt(argc, argv, "tfd:")))
		switch (c) {
		case 't':
#if HAVE_TIFFIO_H
			tiffoutput = true;
#else
			std::cerr << "no TIFF support" << std::endl;
			exit(EXIT_FAILURE);
#endif
			break;
		case 'f':
#if HAVE_FITSIO_H
			fitsoutput = true;
#else
			std::cerr << "no FITS support" << std::endl;
			exit(EXIT_FAILURE);
#endif
			break;
		case 'd':
			dir = optarg;
			break;
		}

	// for compatibility, of no option was present, and we have TIFF
	// support, then we use tiff output
#if HAVE_TIFFIO_H
	if ((!tiffoutput) && (!fitsoutput)) {
		tiffoutput = true;
	}
#endif

	if ((tiffoutput) && (fitsoutput)) {
		std::cerr << "you cannot request both TIFF and FITS." << std::endl;
		exit(EXIT_FAILURE);
	}
	if (fitsoutput) {
		extension = "fits";
	}

	QSICamera cam;

	cam.put_UseStructuredExceptions(true);
	try
	{
		cam.get_DriverInfo(info);
		std::cout << "qsiapi version: " << info << "\n";
		//Discover the connected cameras
		std::string camSerial[QSICamera::MAXCAMERAS];
		std::string camDesc[QSICamera::MAXCAMERAS];
		cam.get_AvailableCameras(camSerial, camDesc, iNumFound);

		if (iNumFound < 1)
		{
			std::cout << "No cameras found\n";
			exit(1);
		}

		for (int i = 0; i < iNumFound; i++)
		{
			std::cout << camSerial[i] << ":" << camDesc[i] << "\n";
		}

		cam.put_SelectCamera(camSerial[0]);

		cam.put_IsMainCamera(true);
		// Connect to the selected camera and retrieve camera parameters
		cam.put_Connected(true);
		std::cout << "Camera connected. \n";
		// Get Model Number
		cam.get_ModelNumber(modelNumber);
		std::cout << modelNumber << "\n";
		// Get Camera Description
		cam.get_Description(desc);
		std:: cout << desc << "\n";

		// Enable the beeper
		cam.put_SoundEnabled(true);
		// Enable the indicator LED
		cam.put_LEDEnabled(true);
		// Set the fan mode
		cam.put_FanMode(QSICamera::fanQuiet);
		// Query the current flush mode setting
		cam.put_PreExposureFlush(QSICamera::FlushNormal);

		// Query if the camera can control the CCD temp
		cam.get_CanSetCCDTemperature(&canSetTemp);
		if (canSetTemp)
		{
			// Set the CCD temp setpoint to 10.0C
			cam.put_SetCCDTemperature(10.0);
			// Enable the cooler
			cam.put_CoolerOn(true);
		}

		if (modelNumber.substr(0,1) == "6")
		{
			cam.put_ReadoutSpeed(QSICamera::FastReadout);
		}

		// Does the camera have a filer wheel?
		cam.get_HasFilterWheel(&hasFilters);
		if ( hasFilters)
		{
			// Set the filter wheel to position 1 (0 based position)
			cam.put_Position(0);
		} 

		if (modelNumber.substr(0,3) == "520" || modelNumber.substr(0,3) == "540")
		{
			cam.put_CameraGain(QSICamera::CameraGainHigh);
			cam.put_PreExposureFlush(QSICamera::FlushNormal);
		}
		//
		//////////////////////////////////////////////////////////////
		// Set image size
		//
		cam.put_BinX(1);
		cam.put_BinY(1);
		// Get the dimensions of the CCD
		cam.get_CameraXSize(&xsize);
		cam.get_CameraYSize(&ysize);
		// Set the exposure to a full frame
		cam.put_StartX(0);
		cam.put_StartY(0);
		cam.put_NumX(xsize);
		cam.put_NumY(ysize);
	
		// take 10 test images
		for (int i = 0; i < 10; i++)
		{
			bool imageReady = false;
			// Start an exposure, 0 milliseconds long (bias frame), with shutter open
			cam.StartExposure(0.000, true);
			// Poll for image completed
			cam.get_ImageReady(&imageReady);
			while(!imageReady)
			{
				usleep(100);
				cam.get_ImageReady(&imageReady);
			}
			// Get the image dimensions to allocate an image array
			cam.get_ImageArraySize(x, y, z);
			unsigned short* image = new unsigned short[x * y];
			// Retrieve the pending image from the camera
			cam.get_ImageArray(image);
			std::cout << "exposure #" << i;

			sprintf(filename, "%s/qsiimage%d.%s", dir, i, extension);
			if (tiffoutput) {
	#ifdef HAVE_TIFFIO_H
				WriteTIFF(image, x, y, filename);
	#endif
			} else if (fitsoutput) {
	#ifdef HAVE_FITSIO_H
				WriteFITS(image, x, y, filename);
	#endif
			}
			std::cout << "\n";	
			std::cout.flush();
			delete [] image;
		}
		cam.put_Connected(false);
		std::cout << "Camera disconnected.\nTest complete.\n";
		std::cout.flush();
		return 0;

	}
	catch (std::runtime_error &err)
	{
		std::string text = err.what();
		std::cout << text << "\n";
		std::string last("");
		cam.get_LastError(last);
		std::cout << last << "\n";
		std::cout << "exiting with errors\n";
		exit(1);
	}
}