[Insight-users] itk::fem::MaterialLinearElasticity::Read

Tessa Sundaram tessa at oasis . rad . upenn . edu
Fri, 23 May 2003 15:03:10 -0400 (EDT)


Dear Lara,

You can also specify your material properties in a .fem file, as is done
in the examples under Insight/Testing/Data/Input/FEM.  You can then use
the FEM solver to read in the material (given ifstream f connected to
your file):

Solver S;
S.Read(f);

Make sure that the first four lines of Solver::Read() (lines 101-104) in
itkFEMSolver.cxx are commented out.  Otherwise they will erase whatever
you read in from the .fem file.  The other thing to note is that you have
to include the "<END>" tags for the sections of the .fem file that you are
not specifying (nodes, elements and loads).  Otherwise your code might
throw exceptions.

Hope this helps,
-ts

> Dear all,
> 
> I use the itk::fem::MaterialLinearElasticity class. And I want to set
> the public attributes (E, A, I, nu, h, RhoC) of an object of this class
> to different values than the default ones.
> 
> If I write for instance these code lines, the code works without
> problem:
> 
>  itk::fem::MaterialLinearElasticity::Pointer mat_1;
>  mat_1 = itk::fem::MaterialLinearElasticity::New();
>  mat_1->GN=0;
>  mat_1->E = 5;
>  mat_1->A = 5;
>  mat_1->I = 5;
>  mat_1->nu = 5;
>  mat_1->h = 5;
>  mat_1->RhoC = 5;
> 
> But I would like to use the itk::fem::MaterialLinearElasticity::Read
> (std::istream & f, void * info) member function.
> So I create a text file  (mat1.txt) wherein I write:
> 
> E : 5.0
> A : 5.0
>  I : 5.0
> nu : 5.0
> h : 5.0
> RhoC : 5.0
> 
> Then, I write in my program the following code lines:
> 
> itk::fem::MaterialLinearElasticity::Pointer mat_1;
> mat_1 = itk::fem::MaterialLinearElasticity::New();
> 
> // open the file mat1.txt associated before with matfilename1
>  filebuf fb;
>  if (fb.open(matfilename1.c_str(), ios::in) == 0) {
>     throw_error("Unable to open input file");
>   }
>   std::istream istr(&fb);
> 
>  mat_1->GN=0;
>  mat_1->Read((std::istream&) istr,(void*) NULL);
> 
> // I try also:
> // void *ptr;
> // mat_1->Read((std::istream&) istr,(void*) ptr);
> 
> 
> This code compiles but when I execute it, it aborts at the appeal of
> Read
> method.
> 
> Remarks:
> (1) I use a NULL pointer because I don't need more information for the
> MaterialLinearElasticity class.
> 
> (2) In the first case, I try also to keep values of E, A, ... from the
> text file to see if problems could be due to the opening of the file but
> it
> works correctly.
> 
> Does anyone know what's wrong with my code?
> 
> Thanks a lot,
> 
> Lara
> 
> 
> 
> 
> 
> --
> Lara VIGNERON
> 
> Signal Processing Group
> 
> University of Liege
> Institut Montefiore
> Sart-Tilman, Batiment B28
> B-4000 Liege
> BELGIUM
> 
> Tel: +32-(0)4-366.26.42
> Fax: +32-(0)4-366.29.84
> Lara . Vigneron at ulg . ac . be
> 
> 
>