NAME

Nastran - basic access to nastran models

SYNOPSIS

    use CAE::Nastranmodel;

    # create object of a nastran model
    my $model = new Nastranmodel();

	# import content from a nastran file
	$model->import("file.inc");

	# import content from a second nastran file, merges with existing content
	# but this time only import the entities of type GRID or CQUAD4
	$model->import("file2.inc", {cards => ["GRID", "CQUAD4"]});

	# import content from a third nastran file and merge with existing content
	# only import the entities of type GRID or CTRIA
	# filter for row2=5
	my @filter = ("", "", "5");
	$model->import("file3.inc", {cards => ["GRID", "CTRIA"], filter => \@filter});

	# create a new model, that contains all the grids of the model
	# only entities that match "" for the comment entry
	# only entities that match "GRID" for row1 
	my $newModel1 = $model->filter(["", "GRID"]);

	# create a new model, that contains all the grids of the model with 99 < NID < 200
	# only entities that match "" for the comment entry
	# only entities that match "GRID" for row1 
	# only entities that match "1\d\d" for row2 
	my $newModel2 = $model->filter(["", "GRID", "1\d\d"]);

	# create a new model, that contains all the grids of the model with 99 < NID < 200 AND 299 < NID < 400
	# only entities that match "" for the comment entry
	# only entities that match "GRID" for row1 
	# only entities that match "1\d\d" OR "3\d\d" for row2 
	my $newModel3 = $model->filter(["", "GRID", ["1\d\d", "3\d\d"]]);

	# create a new model, that contains all 
	# only entities that match "CTRIA.+" OR "CQUAD.*" for row1 (all shell Elements) 
	my $newModel4 = $model->filter(["", ["CTRIA.+", "CQUAD.*"]);

	# prints a model to stdout (in nastran format)
	$newModel4->print();

	# get the row2 of all entities, in this case all Element-Ids
	my @row2ofAllEntities = $newModel3->getrow(2);

	# get all entities
	my @allEntities = $newModel4->getEntities();

	foreach my $entity (@allEntities)
	{
		# set row2 to the value "17" (col2 of shells: EID)
		$entity->setCol(2, 17);
		# offset the value of row3 (col3 of shells: PID)
		$entity->setCol(3, $entity->getCol(2)+100); 
	}

	# merges $newModel3 into $newModel2
	$newModel2->merge($newModel3);

	# $newModel2 contains how many entities?
	$newModel2->count();

DESCRIPTION

import a nastran model from files, filter content, extract data, overwrite data, write content to file.

API

  • import()

    imports a Nastran model from file. it only imports nastran bulk data. no sanity checks will be performed - duplicate ids or the like are possible.

    # define options and filter
    my %OPTIONS = (
        cards => ["GRID", "CTRIA"],          # fastest way to reduce data while importing. only mentioned cardnames will be imported. the values in 'cards' match
                                            # without anchors "TRIA" matches "CTRIA3" and "CTRIA6"
        filter => ["", "", 10],             # filter. only the content passing this filter will be imported. use the same dataformat as in filter().
        maxoccur => 5                       # stops the import if this amount of entities is reached in current import.
    )
    
    # create object of a nastran model
    my $model = new Nastranmodel();
    
    # adds all bulk data of a file
    $model->import("file.inc");
    
    # adds only the bulk data of the file, that passes the filter
    $model->import("file2.inc", \%OPTIONS);
  • filter()

    returns a new Nastranmodel with only the entities that pass the whole filter. A filter is an array of regexes. $filter[0] is the regex for the comment, $filter[1] is the regex for column 1 of the nastran cards, $filter[2] is the regex for column 2 ... A nastran card passes a filter if every filter-entry matches the correspondent column or comment. Everything passes an empty filter-entry. The filter-entry for the comment matches without anchors. filter-entries for data columns will always match with anchors (^$). A filter-entry for a column may be an array with alternatives - in this case only one alternative has to match.

    # filter for GRID (NID=1000)
    my @filter = (
        "",                   # pos 0 filters comment:  entities pass which match // in the comment. (comment/empty => no anchors in the regex)
        "GRID",               # pos 1 filters column 1: only entities pass which match /^GRID$/ in column 1. (note the anchors in the regex)
        "1000"                # pos 2 filters column 2: entities pass which match /^1000$/ in column 2. (note the anchors in the regex)
        ""                    # pos 3 filters column 3: entities pass which match // in column 3. (empty => no anchors in the regex)
    )
    
    my $filteredModel = $model->filter(\@filter);
    
    # filter for GRIDs (999 < NID < 2000)
    my @filter2 = (
        "lulu",               # pos 0 filters comment:  only entities pass which match /lulu/ somewhere in the comment (comment = no anchors in the regex)
        "GRID",               # pos 1 filters column 1: only entities pass which match /^GRID$/ in column 1.
        "1\d\d\d"             # pos 2 filters column 2: entities pass which match /^1\d\d\d$/ in column 2.
    )
    
    my $filteredModel2 = $model->filter(\@filter2);
    
    # filter for GRIDs ( (999 < NID < 2000) and (49999 < NID < 60000) and (69999 < NID < 80000))
    my @filter3 = (
        "",                   # pos 0 filters comment:  all entities match empty filter
        "GRID",               # pos 1 filters column 1: only entities pass which match /^GRID$/ in column 1.
        [
            "1\d\d\d",        # pos 2 filters column 2: entities pass which match /^1\d\d\d$/ in column 2.
            "5\d\d\d\d",      # pos 2 filters column 2: or which match /^5\d\d\d\d$/ in column 2.
            "7\d\d\d\d"       # pos 2 filters column 2: or which match /^7\d\d\d\d$/ in column 2.
        ]
    )
    
    my $filteredModel3 = $model->filter(\@filter3);
  • addEntity()

    adds entities to a model.

    # create new Entities
    my $entity = Entity->new();
    
    $entity->setComment("just a test"); # comment
    $entity->setCol(1, "GRID");         # column 1: cardname
    $entity->setCol(2, 1000);           # column 2: id
    $entity->setCol(4, 17);             # column 4: x
    $entity->setCol(5, 120);            # column 5: y
    $entity->setCol(6, 88);             # column 6: z
    
    my $entity2 = Entity->new(); 
    $entity2->setComment("another test", "this is the second line of the comment");
    $entity2->setCol(1, "GRID");
    $entity2->setCol(2, 1001);
    $entity2->setCol(4, 203);
    $entity2->setCol(5, 77);
    $entity2->setCol(6, 87);
    
    # adds the entities to the model
    $model->addEntity($entity, $entity2);
  • getEntity()

    returns all entities or only entities that pass a filter.

    my @allEntities = $model->getEntitiy();
    
    my @certainEntities = $model->getEntity(\@filter);
  • merge()

    merges two models.

    $model1->merge($model2);    # $model2 is beeing merged into model1
  • getCol()

    returns the amount of entities defined in the model

    my $model2 = $model->filter(["", "GRID"]);     # returns a Nastranmodel $model2 that contains only the GRIDs of $model
    $model2->getCol(2);                            # returns an array with all GRID-IDs (column 2) of $model2
  • count()

    returns the amount of all entities stored in the model

    $model1->count();
  • print()

    prints the whole model in nastran format to STDOUT or to a file if a valid path is given.

    $model->print();              # prints to STDOUT
    $model->print("myModel.nas")  # prints to file 'myModel.nas'

LIMITATIONS

only bulk data is supported. only 8-field nastran format supported. if you use it with very large models (millions of cards) filtering gets slow -> no form of indexing is implemented.

AUTHOR

Alexander Vogel <avoge@cpan.org>

COPYRIGHT AND LICENSE

Copyright (c) 2012-2014, Alexander Vogel, All Rights Reserved. You may redistribute this under the same terms as Perl itself.